Towards Understanding Cross and Self-Attention in Stable Diffusion for Text-Guided Image Editing

Bingyan Liu, Chengyu Wang, Tingfeng Cao, Kui Jia, Jun Huang

arXiv:2403.03431 · 2026-07-27 공개 · arXiv · PDF

diffusion-models image-editing cross-attention self-attention stable-diffusion denoising-process tuning-free attention-maps

Abstract

Deep Text-to-Image Synthesis (TIS) models such as Stable Diffusion have recently gained significant popularity for creative text-to-image generation. However, for domain-specific scenarios, tuning-free Text-guided Image Editing (TIE) is of greater importance for application developers. This approach modifies objects or object properties in images by manipulating feature components in attention layers during the generation process. Nevertheless, little is known about the semantic meanings that these attention layers have learned and which parts of the attention maps contribute to the success of image editing. In this paper, we conduct an in-depth probing analysis and demonstrate that cross-attention maps in Stable Diffusion often contain object attribution information, which can result in editing failures. In contrast, self-attention maps play a crucial role in preserving the geometric and shape details of the source image during the transformation to the target image. Our analysis offers valuable insights into understanding cross and self-attention mechanisms in diffusion models. Furthermore, based on our findings, we propose a simplified, yet more stable and efficient, tuning-free procedure that modifies only the self-attention maps of specified attention layers during the denoising process. Experimental results show that our simplified method consistently surpasses the performance of popular approaches on multiple datasets. 11Source code and datasets are available at https://github.com/alibaba/EasyNLP/tree/master/diffusion/FreePromptEditing.

한국어 요약

한 줄 요약

Stable Diffusion에서의 Cross-Attention과 Self-Attention 분석을 통해 텍스트 유도 이미지 편집 성능을 개선한 Free-Prompt-Editing(FPE) 방법을 제안한다.

핵심 기여도

핵심 아이디어

기존 텍스트 유도 이미지 편집(TIE) 방법은 Stable Diffusion의 Cross-Attention 맵을 수정하여 편집을 수행하지만, 이는 텍스트 프롬프트의 의미 정보를 포함하고 있어 불안정한 결과를 초래할 수 있다. 본 연구는 Cross-Attention 맵 대신 Self-Attention 맵을 수정하는 새로운 접근법을 제안한다. Self-Attention 맵은 이미지 내부의 공간 구조와 형상 정보를 유지하는 데 중요한 역할을 하며, 이를 수정함으로써 편집된 이미지가 원본 이미지의 레이아웃을 보존할 수 있다. 연구자들은 Probe Analysis를 통해 Cross-Attention 맵이 편집 실패의 주요 원인임을 밝히고, Self-Attention 맵이 편집 성공에 필수적임을 입증하였다.

기술적 접근법

주요 결과

의의 및 한계

본 연구는 Stable Diffusion 모델 내 Cross-Attention과 Self-Attention의 역할을 체계적으로 분석하여, 텍스트 유도 이미지 편집 분야의 학술적 이해를 확장하였다. 특히, Self-Attention 맵이 편집 성공에 필수적임을 밝히며, 기존 편집 방법의 단순화와 안정성 향상을 제안하였다. 그러나, FPE는 Cross-Attention 맵을 수정하지 않으므로, 텍스트 프롬프트의 의미 정보를 반영하는 편집에는 한계가 있을 수 있다. 또한, 하이퍼파라미터나 특정 Attention Layer 선택 기준은 명시되지 않아 재현성 측면에서 개선이 필요할 수 있다.

실용적 활용

FPE는 소스 프롬프트 없이도 편집이 가능하므로, 실제 이미지 편집 시나리오에서 유용하게 활용될 수 있다. 예를 들어, 인터넷 콘텐츠 제작, 디지털 마케팅, 게임 캐릭터 디자인 등에서 사용자 맞춤형 이미지 편집을 간단하게 수행할 수 있다. 또한, 다양한 TIS 모델에 적용 가능하므로, 산업 현장에서의 모델 전이 및 활용 범위 확장을 지원한다.