Shape-Guided Diffusion with Inside-Outside Attention

Dong Huk Park, Grace Luo, Clayton Toste, Samaneh Azadi, Xihui Liu, Maka Karalashvili, Anna Rohrbach, Trevor Darrell

Abstract

Researchers from UC Berkeley and Meta AI have developed Shape-Guided Diffusion, a training-free method that allows text-to-image models to swap objects in an image while strictly adhering to a specific shape or silhouette. By introducing a novel "Inside-Outside Attention" mechanism, the model ensures that edits stay within the lines, outperforming existing methods in shape faithfulness without sacrificing image realism.

The Challenge: Structural Integrity in Diffusion Models

Current AI image editing tools are highly effective at changing the style or texture of an image, but they frequently struggle with maintaining structure. For example, when attempting to replace a dog in a photo with a "lego dog," most models either generate a generic lego block that ignores the original dog's pose or allow the new object to "leak" into the background pixels.

This phenomenon, known as shape drift, stems from "spurious attentions" within diffusion models like Stable Diffusion. During the generation process, the pixels representing the target object and the background often become entangled in the model's internal mathematical representations. Previous attempts to solve this relied on user-provided scribbles or blurry masks, which lack the precision required for professional-grade editing.

Comparison of Shape-Guided Diffusion against existing methods. The proposed method (Ours) maintains the original silhouette while accurately applying the text prompt.

Methodology: Inside-Outside Attention (IOA)

The core of this research is a training-free approach called Inside-Outside Attention (IOA). Rather than retraining the entire model, the authors modify the attention mechanisms during the inference process to enforce geometric constraints:

  1. Spatial Delineation: The image is divided into two distinct zones: "inside" (the object mask) and "outside" (the background).
  2. Cross-Attention Constraints: The model forces words in the prompt (e.g., "lego") to only influence pixels located inside the specified mask.
  3. Self-Attention Constraints: Pixels inside the mask are constrained to only interact with other "inside" pixels. This prevents background information from bleeding into the object's shape and vice versa.
  4. Shape-Aware Inversion: The IOA mechanism is applied during the inversion process (turning the real image into noise). This ensures the starting noise already contains the structural DNA of the original silhouette.

Because this method modifies attention maps at inference time, it works with off-the-shelf pre-trained models without requiring expensive GPU retraining.

Experimental Results and Benchmarking

To evaluate the method, the team introduced ShapePrompts, a new benchmark derived from the MS-COCO dataset containing 1,149 object masks across 10 categories.

  • Shape Faithfulness: On the ShapePrompts benchmark, the method achieved a significant lead in KW-mIoU (a metric for shape accuracy), outperforming the nearest competitor by over 6 points.
  • Human Preference: In head-to-head comparisons, human raters chose Shape-Guided Diffusion as the "best edit" 2.7x more frequently than the most competitive baseline.
  • Versatility: The paper demonstrates that the model can handle complex tasks like "outside edits" (changing the background while keeping the object identical) and "simultaneous edits" (changing both the object and the background with a single prompt).

Conclusion and Future Directions

Shape-Guided Diffusion demonstrates that the silhouette of an object is effectively encoded in its attention maps. By masking these maps, geometry can be "locked" while allowing for radical changes in texture, color, and material. While the quality of the edit remains dependent on the input mask and the underlying model's knowledge, this "Inside-Outside" logic provides a robust framework for structural control. Future work may extend these principles to video editing and 3D generation, where maintaining structural consistency is a primary challenge.

Summary updated

BibTeX
@inproceedings{park2024shape,
  author = {Dong Huk Park and Grace Luo and Clayton Toste and Samaneh Azadi and Xihui Liu and Maka Karalashvili and Anna Rohrbach and Trevor Darrell},
  title = {{Shape-Guided Diffusion with Inside-Outside Attention}},
  booktitle = {IEEE/CVF Winter Conference on Applications of Computer Vision},
  year = {2024},
  doi = {10.1109/wacv57701.2024.00415},
}
Figure