Abstract
Text-to-image diffusion models have achieved remarkable success in generating high-quality images, yet they often lack precise spatial control. We introduce BoxDiff, a training-free approach that enables fine-grained control over object placement using bounding boxes or scribbles. By incorporating three novel spatial constraints into the cross-attention maps during the denoising process, BoxDiff guides the generation toward user-defined layouts without requiring expensive fine-tuning or specialized datasets.
Introduction
The ability to specify "what" to generate has been largely solved by large-scale diffusion models, but specifying "where" remains a significant hurdle. Vanilla models often ignore spatial cues in prompts or suffer from attribute leakage. While supervised Layout-to-Image (L2I) models offer a solution, they are limited by their training data and computational costs. BoxDiff provides a "plug-and-play" alternative that maintains the open-world creativity of the base model while granting users structural control.
Methodology: Spatial Constraints on Attention
BoxDiff operates by modifying the internal cross-attention maps of the diffusion model's UNet. These maps represent the spatial distribution of attention for each text token. The method introduces three key constraints applied at each denoising step:
- Inner-Box Constraint ($L_{IB}$): Ensures the highest attention responses occur within the target box, effectively anchoring the object.
- Outer-Box Constraint ($L_{OB}$): Minimizes attention outside the box to prevent object "bleeding" into unintended regions.
- Corner Constraint ($L_{CC}$): Uses projection-based geometric penalties to ensure objects reach the corners of the box, providing control over scale.
To preserve visual fidelity, these constraints are applied via Representative Sampling (top-k and uniform sampling) rather than pixel-wise enforcement. This allows the model to satisfy spatial requirements while retaining its natural generative priors. Additionally, the framework is flexible enough to convert rough user scribbles into bounding boxes for intuitive interaction.
Evaluation and Results
The authors evaluated BoxDiff using a custom benchmark of 189 prompts and over 4,000 instances. Performance was measured using YOLOv4 as an automated spatial judge. BoxDiff improved the Average Precision (AP) from 2.8 in vanilla Stable Diffusion to 22.3, a nearly eight-fold increase in spatial accuracy.
Qualitative results demonstrate its ability to handle complex, multi-object scenes—such as placing a castle precisely within a lake or coordinating multiple animals—where standard models often fail. Crucially, the T2I-Sim score (0.3513) remained stable, proving that spatial constraints do not degrade the semantic alignment of the generated images.
Discussion and Limitations
BoxDiff's training-free nature makes it highly adaptable. It can even be used to enhance existing supervised models like GLIGEN as a "booster" for spatial accuracy. However, it is not without limitations. The method can struggle when user-defined layouts conflict with the model's learned physical priors (e.g., "a giraffe flying in the sky"). Furthermore, the resolution of the attention maps (typically 16x16) limits the precision of control for extremely small or intricate objects.
Conclusion
BoxDiff represents a significant step toward more controllable and intuitive text-to-image synthesis. By leveraging the latent structure of attention maps, it provides a powerful, zero-shot mechanism for spatial grounding that is both effective and easy to integrate into existing generative workflows.
Summary updated