TL;DR
Editing a photo usually means a mask, a second example image, or a long description of both the before and after pictures. InstructPix2Pix takes one photo and one sentence, such as "make it winter", and returns the edited photo in a few seconds. The authors got training data without human editors: a fine-tuned language model wrote more than 450,000 edit instructions with captions, and a text-to-image model rendered before-and-after image pairs for them. A latent diffusion model trained on those triplets then follows new instructions on real photos.
Builds on: Latent Diffusion Model, Classifier-Free Guidance, Fine-Tuning, Language Model · Leads to: instruction-following image editors that were trained the same way, from synthetic pairs
Why it mattered
The paper showed that a model can learn a task that has almost no labelled data by chaining two large pretrained models, one for language and one for images, and using the pair to make the training set. The language model supplies the instructions and the image model supplies the matching pictures. The editor it trains works on real photos and on instructions no one wrote into the training set.
The approach is simple to copy. Later instruction-based image editors have used the same pattern of synthetic before-and-after data. The paper's ideas, especially a diffusion model with two separate guidance knobs, one for the image and one for the instruction, have been reused in other conditional editing systems. Editing a 512 by 512 image takes roughly 9 seconds on one NVIDIA A100 GPU, which made the method usable interactively in the setting the authors tested.
The problem
Before this work, text-based editing tools needed the model to know what the picture should look like, not what to do to it. Methods such as SDEdit need a full description of the output, and Text2Live needs a description of the input and an extra layer. Prompt-to-Prompt edits generated images but only for images it created itself. A real photo has no caption that describes the edited result, so a user who wants to change the season has to describe the whole scene.
Two things were missing. The first was a model that takes an image and a short instruction and performs the edit in one forward pass, without inverting the image into a latent code and fine-tuning on it. The second was training data: nobody had a large set of real photos paired with their edited versions and the instruction that links them. The paper's answer to both is the same move, building the data from generative models and then training a conditional diffusion model on it.
How it works
Take one tiny example through the whole pipeline. A caption is "photograph of a girl riding a horse". The pipeline has four stages.
- Write an instruction and a new caption. A language model fine-tuned on 700 human-written triplets sees the input caption and produces an instruction such as "have her ride a dragon" and an edited caption "photograph of a girl riding a dragon".
- Render a before image and an after image. A text-to-image diffusion model renders both captions. A method called Prompt-to-Prompt, which shares attention weights between the two generations, keeps the pair consistent so that the two pictures differ mainly by the edit. The authors render 100 candidate pairs for each caption pair, each with a random share of shared steps, and filter them with CLIP scores. They keep up to 4 that pass all three thresholds.
- Train the editor on triplets. Each training example is (before image, instruction, after image). The editor is a diffusion model that receives the before image and the instruction as conditions and learns to produce the after image from noise.
- Edit a real photo. Given a new real photo and a new instruction, the trained model denoises a random latent while attending to both conditions, then decodes the result. No extra training is done for that photo.
To see the guidance step concretely, suppose three scalar noise predictions at one denoising step are , and , with and . The combined prediction is . The numbers are illustrative, not from the paper, but the shape is the paper's: each knob pushes the output harder toward one condition.
flowchart LR A["Caption"] --> B["Fine-tuned GPT-3 writes instruction and edited caption"] B --> C["Stable Diffusion with Prompt-to-Prompt renders before and after"] C --> D["CLIP filters the pairs"] D --> E["Triplets: image, instruction, edited image"] E --> F["Diffusion editor trained on triplets"] F --> G["Real photo plus new instruction gives edited photo"]
The math
Step 1 in symbols: the training objective
The paper uses the latent diffusion loss from latent diffusion. Each image is encoded to a latent by a pretrained autoencoder (see Variational Autoencoder for the encoder idea). A noisy latent is produced at a random step , and a network is trained to predict the noise that was added, given both conditions: Here is the input image, is the instruction, and the expectation is over images, noise, and step. The input image enters by concatenation: its latent is stacked onto along the channel axis of the first U-Net layer, and the weights for those new channels start at zero, so training begins from the pretrained text-to-image model's behaviour.
Step 2 in symbols: the two conditions
The network sees two conditions. The image condition and the instruction condition are dropped at random during training, so the same network learns conditional and unconditional prediction. Following the paper, alone is dropped for 5 percent of examples, alone for 5 percent, and both for 5 percent.
Step 3 in symbols: guidance with two scales
Classifier-free guidance extrapolates from the unconditional prediction toward the conditional one. With two conditions and two scales and , the guided prediction is The first difference is the push toward keeping the input image, scaled by . The second is the push toward the instruction, scaled by . The worked numbers above use exactly this formula.
Step 4 in symbols: why the decomposition
Appendix B writes the posterior as . Taking the gradient of its logarithm gives one term for each factor, and each guidance term is an estimate of one of them.
Step 5 in symbols: the paired data filter
A generated pair is kept if all three CLIP checks pass: image-to-image similarity of at least 0.75, image-to-caption similarity of at least 0.2, and directional similarity of at least 0.2. Directional similarity compares the change between the two images in CLIP space with the change between the two captions, so it tests that the picture changed the way the text changed.
Results
The paper reports results mostly as images and trade-off plots rather than one headline score. The authors show edits to real photographs and artworks, including replacing objects, changing seasons and weather, changing the artistic medium, and changing the setting. They compare with SDEdit and Text2Live on the same inputs. SDEdit does well when the content stays the same and the style changes, but it struggles to keep the identity of objects and needs a full output description. Text2Live works for additive layer edits but is limited in which edits it can express.
The quantitative comparison with SDEdit (Figure 8) plots CLIP image similarity against directional similarity. At the same directional similarity, InstructPix2Pix keeps higher image consistency, which means it changes what the instruction asks and leaves the rest of the picture alone. The ablations (Figure 10) show that a smaller training set mostly loses the ability to make large edits, and that removing the CLIP filter lowers image consistency.
The limits are stated plainly. The model is limited by the quality of the synthetic images from Stable Diffusion, and by the human-written instructions, GPT-3, and Prompt-to-Prompt that produced the data. It struggles with counting numbers of objects and with spatial reasoning, such as "move it to the left of the image" or "swap their positions". Figure 13 also shows failures with viewpoint changes and with excessive edits. The authors also note that biases in the data and the pretrained models carry into the edits.
Reading guide
- Section 1, Introduction and Figure 1: the task, in one picture. No prerequisites beyond the abstract.
- Section 2, Prior work: the older editing methods. Read Diffusion Model first if the phrase "diffusion-based" is new.
- Section 3.1, Generating a multi-modal training dataset: needs Language Model and Fine-Tuning for 3.1.1, and Latent Diffusion Model for the rendering in 3.1.2. The CLIP filter uses the scores from CLIP.
- Section 3.2, InstructPix2Pix: needs Latent Diffusion Model and U-Net for the network, and Variational Autoencoder for the latent encoder.
- Section 3.2.1, Classifier-free guidance for two conditionings: needs Classifier-Free Guidance. Figure 4 is the easiest place to see the two scales at work.
- Section 4, Results and 4.1 comparisons: the trade-off plot uses Cosine Similarity between CLIP embeddings, so read that first.
- Appendix A and B: implementation settings and the guidance derivation. Read after the body.
Check yourself
QuestionWhy does the paper generate training data with two pretrained models instead of collecting real before-and-after photos?Show answer
Real photo pairs that differ by exactly one described edit are very hard to find at scale. The authors use a language model to write instructions and edited captions, and a text-to-image model to render the matching images, so they get over 450,000 examples. Prompt-to-Prompt and the CLIP filter then make the pairs consistent enough to supervise an editor.
QuestionUsing the guidance numbers from How it works, but with s_I = 1.0 and s_T = 7.5, what is the combined prediction?Show answer
Start from . The image term is , and the instruction term is . The total is .
QuestionThe paper drops each condition at random during training. Why does a single network then support guidance with both conditions?Show answer
Because the same network has seen conditional, image-only, instruction-only and fully unconditional inputs, it can estimate each of the needed predictions separately. At inference the differences between those estimates give the two guidance terms, so one trained model supports both scales.
QuestionA user asks the editor to 'put two cups on the table and one on the chair' and gets three cups on the table. Which limit in the paper explains this, and what would you change?Show answer
The paper says the model struggles with counting objects and with spatial reasoning, both inherited from the image model and the prompt-editing method. A fix would need better counting and spatial supervision in the training data, or a different conditioning mechanism; more guidance scale alone does not address counting.
Sources
- InstructPix2Pix: Learning to Follow Image Editing Instructions, arXiv:2211.09800: https://arxiv.org/abs/2211.09800
- Brooks, Holynski and Efros, CVPR 2023: https://doi.org/10.1109/CVPR52729.2023.01764