Test-time Controllable Image Generation by Explicit Spatial Constraint Enforcement

Zhihui Zhang, Bingbing Liu, Ji Bao, Lei Chen, Siyu Zhu, Jian YuarXiv 2025 · DOI

Abstract

Recent text-to-image generation favors various forms of spatial conditions, e.g., masks, bounding boxes, and key points. However, the majority of the prior art requires form-specific annotations to fine-tune the original model, leading to poor test-time generalizability. Meanwhile, existing training-free methods work well only with simplified prompts and spatial conditions. In this work, we propose a novel yet generic test-time controllable generation method that aims at natural text prompts and complex conditions. Specifically, we decouple spatial conditions into semantic and geometric conditions and then enforce their consistency during the image-generation process individually. Experiments on Coco-stuff dataset showcase 30% relative boost compared to SOTA training-free methods on layout consistency evaluation metrics.

Introduction

While text-to-image models like Stable Diffusion are incredibly powerful, achieving precise spatial control—such as placing a specific object in a specific corner—is notoriously difficult. Current solutions generally fall into two camps: computationally expensive fine-tuning on massive annotated datasets, or training-free methods that "nudge" internal attention maps. However, these often break down when faced with complex, natural language prompts or layouts containing multiple instances of the same object.

Overview of the proposed method decoupling spatial conditions into semantic and geometric consistency.

The authors identify a core "semantic mismatch" as a primary failure mode: a user might provide a bounding box for a "person," but the prompt describes a "man wearing a wet suit." The model may associate visual features with the word "suit" rather than "person," causing spatial control to fail. This paper proposes Explicit Spatial Constraint Enforcement to resolve these issues without requiring any fine-tuning.

Methodology

The proposed method decouples the problem into two distinct stages: Semantic Consistency and Geometric Consistency.

1. Semantic Consistency (The "What")

To bridge the gap between prompts and layouts, the system introduces:

  • Prompt Editing: If a layout includes an object (e.g., "apple") missing from the text prompt, the system automatically appends it to ensure the model attempts to generate it.
  • Attention Map Matching: Instead of blindly linking a bounding box to a label, the system analyzes word-vector space and internal activation statistics. It identifies which prompt token is actually responsible for features in a given region, ensuring constraints are applied to the correct latent data.

2. Geometric Consistency (The "Where")

Rather than relying on implicit loss functions, this method takes a direct approach to spatial manipulation:

  • Latents Relocalization: The system identifies the "Region of Interest" (RoI) for an object in the latent space and explicitly translates (moves) those latents to the target coordinates.
  • Diffusion-based Latents-Refill: Moving latents leaves a "hole" in the original location. The authors use a lightweight diffusion process to "refill" this vacated space with natural-looking background textures, preventing visual artifacts.
Detailed pipeline showing Semantic Consistency (Prompt Editing, Attention map matching) and Geometric Consistency (RoI identification, Latents relocalization, Latents refill).

Key Results and Insights

The method was evaluated on the COCO-Stuff dataset, focusing on complex validation images with 3 to 8 objects.

  • Layout Consistency: The approach achieved a 30% relative boost in Average Precision (AP) compared to BoxDiff, the previous state-of-the-art training-free method.
  • Efficiency and Generalization: Operating on a consumer-grade RTX 3090, the system generates images in approximately 20 seconds. Because it is training-free, it works out of the box with standard models like Stable Diffusion v1.4.
  • Explicit vs. Implicit Control: A major insight is that "explicit" manipulation—physically moving latent data—is more effective than "implicit" guidance (shouting directions at the model via loss functions).

Conclusion

By decoupling spatial constraints and enforcing them through explicit latent manipulation and automated prompt alignment, this research provides a robust framework for "surgical" control in image generation. While challenges remain for highly overlapping objects or extreme aspect ratios, the significant performance gains on standard benchmarks demonstrate the power of explicit constraint enforcement in training-free workflows.

Summary updated

BibTeX
@misc{zhang2025test,
  author = {Zhihui Zhang and Bingbing Liu and Ji Bao and Lei Chen and Siyu Zhu and Jian Yu},
  title = {{Test-time Controllable Image Generation by Explicit Spatial Constraint Enforcement}},
  year = {2025},
  eprint = {2501.01368},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2501.01368},
}
Figure