Be Yourself: Bounded Attention for Multi-subject Text-to-Image Generation

Omer Dahary, Or Patashnik, Kfir Aberman, Daniel Cohen-Or

Introduction: The Challenge of Multi-Subject Generation

While modern text-to-image (T2I) diffusion models like Stable Diffusion excel at generating high-quality single objects, they frequently falter when tasked with complex scenes containing multiple subjects. When a prompt specifies several distinct entities—for instance, "a ginger kitten and a gray puppy"—the resulting image often suffers from "semantic leakage." This phenomenon manifests in three primary ways:

  1. Catastrophic Neglect: One or more requested subjects are entirely omitted from the final image.
  2. Incorrect Attribute Binding: Visual characteristics intended for one subject (e.g., the color "ginger") are incorrectly applied to another (the "gray" puppy).
  3. Subject Fusion: Distinct subjects merge into a single hybrid entity, losing their individual identities.
Common failure modes in multi-subject generation: catastrophic neglect, incorrect attribute binding, and subject fusion.

Researchers have identified the standard attention mechanism as the root cause. In typical diffusion architectures, every pixel can attend to every word in the prompt and every other pixel in the image. While this global context aids scene cohesion, it also allows features to bleed across boundaries, particularly when subjects share semantic or visual similarities.

The Bounded Attention Framework

To address these issues, this paper introduces Bounded Attention, a training-free method that restricts information flow within the model's attention layers. The approach operates in two distinct phases during the denoising process:

1. Bounded Guidance (The Setup Phase)

In the initial steps of generation, the model performs a lightweight optimization. It calculates a loss based on the degree to which each subject's attention is concentrated within its assigned bounding box. By nudging the latent noise early on, the method ensures that subjects begin to form in their correct spatial locations.

2. Bounded Denoising (The Maintenance Phase)

This core innovation modifies the attention calculation throughout the generation process. By introducing a mask ($M_t$) into the softmax operation—$\text{Attention} = \text{softmax}(QK^T + M_t)$—the model effectively "blinds" pixels to irrelevant data. A pixel within a "kitten" box is prevented from attending to the "puppy" text token (cross-attention) or to pixels belonging to the puppy (self-attention). As the image evolves, the system transitions from coarse bounding boxes to fine-grained Mask Refinement, using the model's own self-attention maps to define precise subject silhouettes.

Key Insights and Results

A critical finding of this research is that self-attention is just as responsible for feature leakage as cross-attention. By managing how pixels relate to one another, Bounded Attention prevents the textures of one object from contaminating another. Furthermore, because it is a "plug-and-play" modification to the sampling math, it requires no expensive retraining and works across various architectures like SD v1.5 and SDXL.

Bounded Attention successfully generating five distinct kittens with specific colors and positions on stairs.

Quantitative evaluations on the DrawBench benchmark demonstrate significant improvements:

  • Spatial Accuracy: Bounded Attention achieved a score of 0.43, notably higher than the 0.35 reached by previous layout-guidance methods.
  • Counting Recall: The method reached a recall of 0.91, a substantial leap over vanilla Stable Diffusion's 0.78.

These results are most visible in high-complexity tasks, such as generating five distinct kittens with different colors in specific positions—a scenario where standard models typically "average" the colors across all subjects.

Limitations and Future Work

Despite its success, Bounded Attention faces some hurdles. Residual leakage can still occur if the initial random seed is fundamentally incompatible with the requested layout. Additionally, errors in the early mask refinement stage can lead to subjects being partially cut off. Future research may focus on "layout-aware seeds" to initialize the generation process with noise that better aligns with the intended scene geometry.

Summary updated

BibTeX
@inproceedings{dahary2024be,
  author = {Omer Dahary and Or Patashnik and Kfir Aberman and Daniel Cohen-Or},
  title = {{Be Yourself: Bounded Attention for Multi-subject Text-to-Image Generation}},
  booktitle = {European Conference on Computer Vision},
  year = {2024},
  doi = {10.1007/978-3-031-72630-9\_25},
}
Figure