Unlocking Spatial Comprehension in Text-to-Image Diffusion Models

Mohammad Mahdi Derakhshani, Menglin Xia, Harkirat Behl, Cees G. M. Snoek, Victor RühlearXiv 2023

Abstract

We propose CompFuser, an image generation pipeline that enhances spatial comprehension and attribute assignment in text-to-image generative models. Our pipeline enables the interpretation of instructions defining spatial relationships between objects in a scene, such as 'An image of a gray cat on the left of an orange dog', and generate corresponding images. This is especially important in order to provide more control to the user. CompFuser overcomes the limitation of existing text-to-image diffusion models by decoding the generation of multiple objects into iterative steps: first generating a single object and then editing the image by placing additional objects in their designated positions. To create training data for spatial comprehension and attribute assignment we introduce a synthetic data generation process, that leverages a frozen large language model and a frozen layout-based diffusion model for object placement. We compare our approach to strong baselines and show that our model outperforms state-of-the-art image generation models in spatial comprehension and attribute assignment, despite being 3x to 5x smaller in parameters.

Introduction

Despite the staggering beauty of modern AI art, diffusion models often fail at basic logic. If you ask for "a red cat to the left of a blue dog," you might get two purple animals, or a red dog and a blue cat, or just a single confused-looking creature. This happens for two primary reasons:

  1. Attribute Assignment: The model struggles to "link" adjectives to the correct nouns (e.g., color bleeding between objects).
  2. Spatial Comprehension: Models often ignore relative positioning (left/right) or bias heavily toward the first object mentioned, effectively "forgetting" the second.

Current solutions often rely on manual user masks or complex layout inputs. CompFuser aims to fix this using only text prompts, making the process more intuitive for the end user.

Methodology

The core philosophy of CompFuser is decomposition. Instead of trying to generate a complex scene in one shot, it treats generation as an iterative editing task.

The CompFuser pipeline decomposes image generation into caption generation, layout generation, and iterative image synthesis.

As shown in the architecture above, the pipeline follows three stages:

  • Caption Generation: A Large Language Model (GPT-3.5) acts as a planner, breaking down a user prompt into a detailed caption.
  • Layout Generation: The LLM generates a layout consisting of bounding boxes and specific "edit instructions" (e.g., "Place a blue boat on the left of a red umbrella").
  • Image Synthesis: The system generates a "draft" image containing a single object and then uses a specialized image-to-image model to "edit" the scene by adding the second object in the correct location.

To ensure consistency, the authors introduced a Background Retention Energy Function that aligns cross-attention maps of the "before" and "after" images. The CompFuser model itself is a finetuned InstructPix2Pix architecture using LoRA (Low-Rank Adaptation), specifically optimized for object placement and spatial reasoning.

Data Generation

To train a model to understand "left" and "right," the authors created a synthetic dataset of 22,000 instruction triplets. They used an MSCOCO co-occurrence matrix to pick object pairs that naturally belong together (e.g., "cat and dog") and then used LLM-grounded diffusion (LMD) to generate the "ground truth" images used for training.

Evaluation and Results

The researchers used the VISOR metric, which measures how often objects are generated correctly and placed in the right relative positions.

  • Object Accuracy (OA): CompFuser achieved 57.32%, nearly doubling the performance of Stable Diffusion 1.5 (30.81%) and significantly beating SDXL (12.25% in a standard T2I setting).
  • Spatial Correctness: On the VISOR_cond metric, CompFuser hit 90.73%. This is a massive leap over baselines like DALL-E 2 and CogView2, which often hover around 50% (essentially a coin flip for left vs. right).
Qualitative comparison of CompFuser against state-of-the-art models in spatial reasoning and attribute binding.

Qualitatively, CompFuser successfully avoids "merging" objects (e.g., a car-clock hybrid) and maintains distinct colors for distinct objects, outperforming significantly larger models.

Conclusion

CompFuser demonstrates that spatial reasoning is a much simpler task for a neural network when framed as an iterative editing task rather than a single-shot generation. Despite being 3x to 5x smaller than giant models like SDXL, it consistently outperforms them in logical tasks. Future work will focus on expanding the model to handle more objects and a wider variety of spatial terms such as "above," "behind," and "inside."

Summary updated

BibTeX
@misc{derakhshani2023unlocking,
  author = {Mohammad Mahdi Derakhshani and Menglin Xia and Harkirat Behl and Cees G. M. Snoek and Victor Rühle},
  title = {{Unlocking Spatial Comprehension in Text-to-Image Diffusion Models}},
  year = {2023},
  eprint = {2311.17937},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2311.17937},
}
Figure