Profile

Settings

Loading…

← Papers

Help

FAQ

Which features require signing in?

You can read the commentary, paper info, Model Structure and related papers of public papers without signing in. Sign in to manage your account or contact us about your inquiries.

Can I upload a PDF file?

Upload papers with an arXiv or DOI link; the commentary is public to everyone. Papers whose source and terms of use can't be verified, so the commentary can't be made public, can't be uploaded. Uploading PDF files and keeping papers private are for subscribers only, and a paper uploaded as a file is saved as private only. Searching for official info by title runs only when you press the button.

Are the figures and AI commentary accurate?

Figures come only from the original paper, and only those whose terms of use are verified are shown. The commentary is written by AI and may be wrong. Check important claims, numbers and figure context against the evidence in the original paper.

I want to report a copyright issue.

Terms of use and the source of the original paper are on the Paper info tab. If there's a problem, choose "Paper content, figures and copyright" under Contact us and send the paper link, the part in question, and evidence that you hold the rights. Receiving your report doesn't confirm any rights or remove anything right away. You can see the result of the review under My inquiries.

I forgot my password.

If you signed up with email, use Forgot password in the sign-in window to reset it with your verified email. If you signed up with Google, Naver or Kakao, change your password with that service.

What should I include in an inquiry?

Tell us which screen you were on and what you were doing when the problem happened, along with the paper link. Don't include personal information such as passwords, API keys, verification codes or phone numbers. Inquiries and replies are stored in Refivu and you can see them under My inquiries.

How do I delete my account?

In Settings, under My account, press Delete account. Review what will be deleted and complete identity verification to delete your account. For other requests, choose "Account" under Contact us.

Paper commentary

Prompt-to-Prompt Image Editing with Cross Attention Control

Prompt-to-prompt editing changes images by rewriting only the text prompt

  • Problem Text-conditioned generators change the whole picture when a prompt changes slightly. Existing text-driven editors need a user-drawn mask, which discards the structure inside it.
  • Method Prompt-to-prompt editing runs the source and edited prompts with the same seed. It injects the source cross-attention maps into the edited run, instead of asking for a spatial mask.
  • Results Injecting the source maps keeps the lemon cake layout when lemon is replaced by pumpkin. Regenerating with the same seed and the new prompt gives a different geometry.

Why text edits break generated images

A text-conditioned generator can produce a completely different picture when only a few words of the prompt change, yet an editing tool is expected to keep most of the original image. Existing approaches sidestep this by asking the user for a spatial mask around the region to change, so the content inside the mask is discarded and the editor works only on the masked area.

Inpainting-based methods of this kind keep the background of the original image while altering the masked region, but the mask has to be drawn by hand and the masked content no longer informs the result. Edits that depend on the internal structure of an object, such as changing its texture, fall outside what inpainting can express.

This work instead edits an image through the prompt alone, with no mask, no model training and no extra data. The approach relies on the internal attention of the generator, so the user changes words rather than pixels.

Cross-attention as the handle on layout

The internal cross-attention maps are high-dimensional tensors that link pixels to the tokens of the prompt, and they carry rich semantic relations that strongly affect the generated image. The central observation is that the composition and geometry of an image depend on these maps, not only on the random seed.

Keeping the seed fixed and changing the prompt is not sufficient: the regenerated image has a different structure and composition from the original. This points to the pixel-to-text interaction inside the cross-attention layers as the place where layout is decided.

Averaged over timesteps, the maps for the words "bear" and "bird" light up the pixels that show those objects, so each pixel attends most to the words that describe it. The averaging is only a visualization; the method keeps the maps separate for each head. The overall structure of the image is already settled in the early diffusion steps, which is why the maps of early steps matter most for editing.

How the attention maps are computed in Imagen

The backbone is Imagen, a text-guided synthesis model. The method adapts only the text-to-image diffusion stage, because composition and geometry are mostly fixed at the 64× 64 resolution, and the super-resolution stages are used as they are. At each diffusion step, a U-shaped network predicts the noise from the noisy image and the text embedding, and the visual and textual features are fused inside cross-attention layers.

The deep spatial features of the noisy image give the queries, while the text embedding gives the keys and the values, all through learned linear projections. The attention map is a softmax over the scaled product of queries and keys, as the following formula gives, and each entry is the weight that a pixel places on the value of one token.

\[ M = \mathrm{Softmax}\left(\frac{QK^{T}}{\sqrt{d}}\right) \] Here \(d\) is the projection dimension of the keys and queries, and the cross-attention output is \(MV\), which updates the spatial features.

The model also uses hybrid attention, which concatenates the text embedding to the keys and values of self-attention layers. The method modifies only the channels that correspond to text tokens inside these hybrid layers, so the same treatment as ordinary cross-attention applies.

Running two prompts through one denoising loop

One diffusion step takes a noisy latent and a prompt and returns the latent of the next step together with the attention map of that step; the method can also override that map with a supplied one while keeping the values taken from the prompt. An edit function receives the map of the source run and the map of the edited run at the same step and returns the map that the edited run will use.

The two generations run together from the same initial noise, which must be held fixed, since even the same prompt with two different seeds yields very different images. At every step the source map and the edited map are computed, the edit function combines them, and the edited latent is advanced with the combined map. The edit function can be applied inside the diffusion forward call, and both latents can be processed as one batch, so the overhead is about one extra step.

Because the loop itself is shared, switching between editing tasks only changes the edit function. The next section gives the edit function for each of the three tasks.

Word swap, new phrases and re-weighting

For a word swap, the source maps are injected into the run with the modified prompt, so the layout of the original is kept while the new word fills the content. Injecting throughout all steps can over-constrain the geometry when the swap is structural, for example car to bicycle, so the injection is limited to the steps before a timestamp τ.

Tokens that span a different number of subword tokens in the two prompts have their maps duplicated or averaged through an alignment step.

When a phrase is added, an alignment function maps each token index of the edited prompt to a matching index of the source prompt, or to nothing when no match exists. Matched tokens take the source map at their aligned index, while unmatched new tokens keep the map of the edited run, so the added words can add new content.

For re-weighting, the attention map of one chosen token is multiplied by a scalar c, and all other maps stay unchanged. The scalar is taken from the range [−2, 2], so the effect of that word can be strengthened or weakened.

Replacing words and the number of injection steps

In the lemon cake example, replacing lemon with pumpkin keeps the spatial layout and background, and the lemons at the top left turn into pumpkins. Regenerating with the prompt pumpkin cake and the same seed gives a completely different geometry.

Injecting only the attention of the word butterfly keeps that object while the rest of the scene changes, and the butterfly sits on each new object in a plausible manner.

Without injection, changing one word leads to an entirely different outcome, and the fidelity to the source image increases with the number of steps that receive injection. The authors observe that the best result is not necessarily obtained with injection in all steps, so the number of injected steps gives the user a further control. Injection in every step over-constrains the car-to-bicycle case, where the car becomes a bicycle.

Adding specifications, styles and fader control

When a specification is added, the attention of the original prompt is kept and the new words are free to act, so the car gains details such as being crushed while the background stays. Global edits affect every part of the image but keep its composition, as when snow is added or the lighting changes. Stylization applies the same logic: a style description added to the prompt, with the source maps injected, changes the look while the structure of the original image is kept.

Some controls are hard to express in words, such as how much snow a mountain carries, so re-scaling the attention of the specified word offers a fader. Reducing or increasing the cross-attention of a marked word changes the extent to which that word influences the generated image.

Extending the loop to real images through inversion

Editing a real photograph requires an initial noise vector that reproduces the input when fed to the diffusion process, a step called inversion. A naive inversion adds Gaussian noise to the input and runs a set number of denoising steps, but this produces significant distortions.

This often gives satisfying results, but in other cases the inversion is not accurate enough.

To restore the unedited regions, a mask is extracted from the attention maps, with no guidance from the user. In the cat example, this works even with the naive DDPM inversion scheme, and the cat's identity is kept under various editing operations.

Limitations

The current inversion of real images shows visible distortion on some test images. The user also has to come up with a suitable prompt for the image, which may be hard for complicated compositions.

Lowering the classifier-free guidance parameter improves reconstruction, but it also reduces the prompt's influence and limits significant manipulations, which the authors describe as a distortion-editability tradeoff.

Cross-attention sits in the network's bottleneck, so the attention maps are of low resolution, which bounds how precise localized editing can be. The authors suggest adding cross-attention to higher-resolution layers as a future step, which they did not test. The method cannot spatially move existing objects across the image, and this control is left for future work.

Showing these edits relies on example images, and the text reports no quantitative metric for edit quality.

Paper info

Authors
Amir Hertz, Ron Mokady, Jay Tenenbaum, Kfir Aberman, Yael Pritch, Daniel Cohen-Or
Venue
arXiv · Preprint
First published
2022-8-2
Added
2026-11-12
Updated
2022-8-2
Version
v1
arXiv
2208.01626
Category
cs.CV · cs.CL · cs.GR · cs.LG
Original paper terms
arXiv non-exclusive 1.0
What we show
Paper info and commentary

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

Quote from the paper

Amir Hertz, Ron Mokady, Jay Tenenbaum, Kfir Aberman, Yael Pritch, Daniel Cohen-Or (2022). Prompt-to-Prompt Image Editing with Cross Attention Control. arXiv:2208.01626v1. https://arxiv.org/abs/2208.01626v1

BibTeX
@misc{hertz2022prompt,
  title = {{Prompt-to-Prompt Image Editing with Cross Attention Control}},
  author = {Amir Hertz and Ron Mokady and Jay Tenenbaum and Kfir Aberman and Yael Pritch and Daniel Cohen-Or},
  year = {2022},
  eprint = {2208.01626},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2208.01626v1}
}

See related papersBrowse other papers

Paper preview
Account security

Connect Google account

If you connect a Google account, you can sign in with it too.

Refivu

Delete account

Refivu
Refivu

Sign up