Enhancing Semantic Fidelity in Text-to-Image Synthesis: Attention Regulation in Diffusion Models

Yang Zhang, Teoh Tze Tzun, Lim Wei Hern, Tiviatis Sim, Kenji Kawaguchi

Abstract: Recent advancements in diffusion models have notably improved the perceptual quality of generated images in text-to-image synthesis tasks. However, diffusion models often struggle to produce images that accurately reflect the intended semantics of the associated text prompts. We examine cross-attention layers in diffusion models and observe a propensity for these layers to disproportionately focus on certain tokens during the generation process, thereby undermining semantic fidelity. To address the issue of dominant attention, we introduce attention regulation, a computation-efficient on-the-fly optimization approach at inference time to align attention maps with the input text prompt. Notably, our method requires no additional training or fine-tuning and serves as a plug-in module on a model. Hence, the generation capacity of the original model is fully preserved. We compare our approach with alternative approaches across various datasets, evaluation metrics, and diffusion models. Experiment results show that our method consistently outperforms other baselines, yielding images that more faithfully reflect the desired concepts with reduced computation overhead.

Introduction: The Semantic Fidelity Gap

While modern diffusion models like Stable Diffusion produce visually stunning images, they frequently struggle with "semantic fidelity"—the ability to accurately render all components of a text prompt. A common failure mode is the omission of specific objects or attributes requested by the user. For instance, a prompt for a "dog in a cage with a bed and bowl" might result in an image of just a dog in a cage, neglecting the bed and bowl.

Comparison of Stable Diffusion and Attention Regulation across various prompts showing improved object detection.

The authors identify this issue as a result of attention dominance, where certain tokens (like "dog") monopolize the attention values in the cross-attention layers, effectively "crowding out" other tokens (like "bowl").

Methodology: Attention Regulation

To combat this, the researchers introduce Attention Regulation, a training-free, plug-in optimization method applied during inference. Unlike previous methods that require expensive fine-tuning or slow optimization loops at every generation step, Attention Regulation treats the process as a constrained optimization problem focused on two goals:

  1. High-Quantile Thresholding: Ensuring the most attentive regions for every token reach a minimum intensity.
  2. Balanced Distribution: Preventing any single token from hogging the "attention budget."

To maintain efficiency and image quality, the method uses Smooth Parameterization. Instead of optimizing individual pixels, it optimizes a small weight matrix controlling a 2D Gaussian kernel. This ensures edits are spatially smooth and computationally light. Furthermore, regulation is only applied to specific "bottleneck" layers and stopped after the 25th step, once the global layout is established.

Key Insights: Visualizing Attention Dominance

The core "Aha!" moment of the research comes from analyzing the statistical distribution of attention values. By using violin plots to track attention for specific tokens over time, the authors demonstrated that in failed generations, the attention for missing objects drops toward zero very early in the process.

Attention statistics (violin plots) showing how Attention Regulation recovers the "glasses" token compared to the baseline.

As shown in the figure above, the baseline model (top) loses focus on the "glasses" token by step 24. Attention Regulation (bottom) acts as a safety net, boosting the attention for marginalized tokens to ensure they are physically manifested in the final image.

Results and Efficiency

Experimental results across datasets like MS-COCO and the A&E benchmark show significant improvements. On the A&E dataset, Attention Regulation achieved a 66.2% Detection Success Rate (Det.Rate), a substantial leap from Stable Diffusion's 46.7%.

Crucially, this performance does not come at the cost of extreme latency. Attention Regulation is approximately 8x faster than previous state-of-the-art methods like Attend-and-Excite, adding only a ~49% overhead to the standard generation time. It also maintains high image quality, as evidenced by competitive FID scores.

Conclusion and Limitations

Attention Regulation provides a robust, efficient way to improve the reliability of text-to-image models without retraining. While it significantly reduces "missing object" errors, challenges remain in resolving "feature fusion" (where two objects merge into one) and handling semantic biases in the underlying model's training data. Future work aims to incorporate human-centric common sense to further refine these conceptual boundaries.

Summary updated

Abstract

Recent advancements in diffusion models have notably improved the perceptual quality of generated images in text-to-image synthesis tasks. However, diffusion models often struggle to produce images that accurately reflect the intended semantics of the associated text prompts. We examine cross-attention layers in diffusion models and observe a propensity for these layers to disproportionately focus on certain tokens during the generation process, thereby undermining semantic fidelity. To address the issue of dominant attention, we introduce attention regulation, a computation-efficient on-the-fly optimization approach at inference time to align attention maps with the input text prompt. Notably, our method requires no additional training or fine-tuning and serves as a plug-in module on a model. Hence, the generation capacity of the original model is fully preserved. We compare our approach with alternative approaches across various datasets, evaluation metrics, and diffusion models. Experiment results show that our method consistently outperforms other baselines, yielding images that more faithfully reflect the desired concepts with reduced computation overhead. Code is available at https://github.com/YaNgZhAnG-V5/attention_regulation.
BibTeX
@inproceedings{zhang2024enhancing,
  author = {Yang Zhang and Teoh Tze Tzun and Lim Wei Hern and Tiviatis Sim and Kenji Kawaguchi},
  title = {{Enhancing Semantic Fidelity in Text-to-Image Synthesis: Attention Regulation in Diffusion Models}},
  booktitle = {European Conference on Computer Vision},
  year = {2024},
  doi = {10.1007/978-3-031-73016-0\_5},
}
Figure