# IP-Adapter: Text Compatible Image Prompt Adapter for Text-to-Image Diffusion Models

Image prompt adapter adds image conditioning to frozen text-to-image diffusion models

Hu Ye, Jun Zhang, Sibo Liu, Xiao Han, Wei Yang · arXiv · 2023-8-13

- **Problem** Text prompts are hard to write and cannot carry every scene detail. Existing image prompt methods need costly fine-tuning that removes text generation, or support only image prompts.
- **Method** IP-Adapter adds a separate cross-attention branch for image features beside each text cross-attention layer. Only these branches are trained while Stable Diffusion stays frozen, and their output is added to the text output.
- **Results** IP-Adapter reaches 0.588 CLIP-T and 0.828 CLIP-I on the COCO validation set with about 22M trainable parameters. SD Image Variations scores 0.548 and 0.760.

## Image prompts for text-only diffusion models

Stable Diffusion (SD) and similar text-to-image diffusion models take their conditioning from a text encoder, so a user who wants a specific look has to describe it in words, often through prompt engineering. Words cannot capture every scene or concept, whereas a reference image carries far more detail, which makes an image prompt an appealing second input.

The open question is whether these pretrained, text-conditioned models can accept an image prompt without being rebuilt for it.

One route fine-tunes a text-conditioned model directly on image embeddings, as SD Image Variations and Stable unCLIP do. That route needs large computing resources, removes the model's ability to generate from text, and yields models that do not carry over to other custom models from the same base or work with ControlNet.

A lighter route replaces the text encoder with an image encoder and leaves the diffusion model untouched, but it supports only image prompts, so text and image cannot be combined. Tuning only the image encoder may also fail to keep image quality and can generalize poorly.

## Why concatenated image features fall short

Several adapters map CLIP image features through a trainable network and concatenate them with the text features, so the merged features take the place of the original text features in the UNet. T2I-Adapter's style adapter and Uni-ControlNet's global control branch both follow this pattern, and their outputs stay only partly faithful to the reference image.

The authors place the cause in the cross-attention layers. Their key and value projections were trained to read text, so pushing image features through them mainly aligns the image with text. Image-specific information is lost along the way, and the resulting control stays coarse, for example limited to image style.

This points toward giving image features their own attention path while the text path stays as it is.

## A parallel attention branch for image tokens

Every cross-attention layer of the UNet receives one extra cross-attention layer that serves only the image features. In the original layer, the query is computed from the latent features and the keys and values come from the text features, so the output is \\\\( Z' = \\\\mathrm{Softmax}(QK^\\\\top/\\\\sqrt{d})V \\\\) with \\\\( Q = ZW\_q \\\\), \\\\( K = c\_t W\_k \\\\) and \\\\( V = c\_t W\_v \\\\).

The image branch reuses the same query \\\\( Q \\\\) but takes its keys and values from the image features \\\\( c\_i \\\\), through the new matrices \\\\( W'\_k \\\\) and \\\\( W'\_v \\\\).

The final layer output adds the softmax-weighted text term and the softmax-weighted image term: \\\\\[ Z^{new} = \\\\mathrm{Softmax}\\\\left(\\\\frac{QK^\\\\top}{\\\\sqrt{d}}\\\\right)V + \\\\mathrm{Softmax}\\\\left(\\\\frac{Q(K')^\\\\top}{\\\\sqrt{d}}\\\\right)V' \\\\\] Here \\\\( K' = c\_i W'\_k \\\\) and \\\\( V' = c\_i W'\_v \\\\), so the image branch contributes on top of the text branch.

Each layer adds only two matrices, \\\\( W'\_k \\\\) and \\\\( W'\_v \\\\), which start from the pretrained \\\\( W\_k \\\\) and \\\\( W\_v \\\\) to speed up convergence. Because the UNet is frozen, these two matrices per layer are the only trainable attention weights in the decoupled design. Concatenating the image and text features into one attention call was tried first and judged insufficiently effective.

The model has 16 cross-attention layers in SD, and each one receives an image cross-attention layer.

## From one global CLIP embedding to four image tokens

The image prompt is encoded by a frozen CLIP image encoder, which is OpenCLIP ViT-H/14 in this study. The global image embedding from this encoder is used because the authors regard it as well aligned with image captions and able to represent the content and style of the image.

A small projection network turns the single global vector into a sequence of N = 4 features, with the same dimension as the pretrained text features. The network consists of one linear layer followed by Layer Normalization. The stated aim of this step is to decompose the global embedding effectively.

The choice of a global embedding is later tested against a variant that uses finer grid features.

## Training only the image branch

Training uses the same noise prediction objective as SD, with the text and image conditions both passed to the noise predictor: \\\\\[ L\_{simple} = \\\\mathbb{E}\_{x\_0,\\\\epsilon,c\_t,c\_i,t}\\\\left\\\\\| \\\\epsilon - \\\\epsilon\_\\\\theta(x\_t, c\_t, c\_i, t)\\\\right\\\\\|^2 \\\\\] Only the IP-Adapter parameters are optimized, while the SD parameters stay fixed, and the CLIP image encoder stays frozen as well.

Image conditions are dropped at random during training, so that classifier-free guidance can be applied at inference, and the CLIP image embedding is set to zero when it is dropped. Guidance then mixes the two noise predictions with the guidance weight \\\\( w \\\\): \\\\\[ \\\\hat{\\\\epsilon}\_\\\\theta(x\_t, c\_t, c\_i, t) = w\\\\,\\\\epsilon\_\\\\theta(x\_t, c\_t, c\_i, t) + (1 - w)\\\\,\\\\epsilon\_\\\\theta(x\_t, t) \\\\\] Text and image are dropped individually with probability 0.05, and both together with probability 0.05.

The training data is about 10 million text-image pairs drawn from LAION-2B and COYO-700M. Images have their shortest side resized to 512 and are center cropped to 512 × 512. The experiments use SD v1.5 as the base model.

## Weighting the image branch at inference

At inference the image cross-attention output is scaled by a weight factor \\\\( \\\\lambda \\\\) and added to the text cross-attention output: \\\\\[ Z^{new} = \\\\mathrm{Attention}(Q,K,V) + \\\\lambda \\\\cdot \\\\mathrm{Attention}(Q,K',V') \\\\\] Setting \\\\( \\\\lambda = 0 \\\\) returns the original text-to-image model.

Because the two branches are separate, the weight can be changed at inference without retraining the adapter. For image-only generation the text prompt is set to empty and \\\\( \\\\lambda = 1.0 \\\\).

Sampling uses the DDIM sampler with 50 steps and a guidance scale of 7.5.

## COCO comparison with fine-tuned and scratch-trained models

The evaluation uses the COCO2017 validation set of 5,000 images with captions. For each sample, 4 images are generated from the image prompt, giving 20,000 generated images per method. CLIP-I measures the similarity between the CLIP image embeddings of generated images and the image prompt, and CLIP-T is the CLIPScore of generated images against the captions of the image prompts.

Open unCLIP (0.608 and 0.858, 893M) and Kandinsky-2-1 (0.599 and 0.855, 1229M) score higher than IP-Adapter on both metrics. Against Versatile Diffusion (0.587 and 0.830, 860M), IP-Adapter's CLIP-T of 0.588 is marginally higher, while its CLIP-I of 0.828 is marginally lower.

Uni-ControlNet's global control (0.506 and 0.736, 47M), T2I-Adapter's style adapter (0.485 and 0.648, 39M) and ControlNet Shuffle (0.421 and 0.616, 361M) score lower than IP-Adapter on both metrics. SeeCoder and ControlNet Reference-only were only evaluated qualitatively, because the first is used with added structural controls and the second runs in a web framework.

In the qualitative comparison, the authors judge IP-Adapter mostly better than the other adapters, slightly better than the fine-tuned models, and comparable to the scratch-trained models in most cases. For each image prompt, four samples were drawn and the best one was kept per method, so the qualitative picture depends on that selection.

## Reuse on custom models and with structural controls

The adapter was trained once on SD v1.5 and was applied without retraining to Realistic Vision V4.0, Anything v4 and ReV Animated, which are all fine-tuned from SD v1.5. It was also applied to SD v1.4, which the authors note is the earlier base of SD v1.5. These custom-model results are visual examples, and no metric is reported for them.

Because the adapter leaves the network structure unchanged, it can be combined with ControlNet and T2I-Adapter to generate from an image prompt and a structure map together. Figure 5 shows such samples, with the first two rows generated by ControlNet models and the last row by T2I-Adapters.

In the structure control comparison, T2I-Adapter and Uni-ControlNet use their default composable multi-conditions, SeeCoder and IP-Adapter use ControlNet, and ControlNet Shuffle and ControlNet Reference-only use multi-ControlNet. The authors report that IP-Adapter gives better image quality and images that align better with the reference image.

Replacing the text prompt with an image prompt also gives image-guided image-to-image and inpainting with SDEdit.

## Image and text prompts together

The authors note that fully fine-tuned image prompt models almost lose the original text-to-image ability. IP-Adapter accepts image and text prompts together, and the authors found this to work particularly well on community models.

With the Realistic Vision V4.0 model, text edits can change attributes of the subject from the image prompt or change the scene around it. The weight factor λ is adjusted in this setting to balance the image prompt against the text prompt.

Figure 9 compares multimodal outputs with Versatile Diffusion, BLIP Diffusion, Uni-ControlNet, T2I-Adapter, ControlNet Shuffle and ControlNet Reference-only, and the authors judge the IP-Adapter results better in image quality and in alignment with the multimodal prompts.

## Decoupled branch and feature granularity ablations

The simple adapter concatenates image and text features and embeds them into the pretrained cross-attention layers, without a decoupled branch. Both adapters were trained for 200,000 steps under the same configuration.

In the visual comparison, the decoupled adapter produces higher-quality images than the simple adapter and images that are more consistent with the image prompts. This comparison is visual, and it uses no metric.

To test whether the global embedding loses detail, the authors build a variant that takes grid features from the penultimate layer of the CLIP image encoder. A query network with 16 learnable tokens extracts information from these grid features with a lightweight transformer, and the resulting token features feed the cross-attention layers.

The finer variant yields images that are more consistent with the image prompt, but the authors note that it can also learn spatial structure and so reduce the diversity of generated images. Additional conditions such as text prompts and structure maps can restore diversity, and human poses are one example.

## Limits on subject consistency and evidence

The authors state that IP-Adapter reproduces the content and style of a reference image but does not synthesize images that stay highly consistent with the subject of that image, as Textual Inversion and DreamBooth do. They aim to develop stronger image prompt adapters for subject consistency.

The quantitative comparison uses only the COCO validation set with CLIP-based metrics. The ablations are visual and trained for 200,000 steps, while the main model was trained for 1M steps. The custom-model and structure-control results are visual examples.

The CLIP-based metrics do not capture the diversity loss of the finer-grained variant, and the qualitative comparisons rely on the best of four samples per method.

## Paper info

- **Authors**: Hu Ye, Jun Zhang, Sibo Liu, Xiao Han, Wei Yang
- **Venue**: arXiv · Preprint
- **First published**: 2023-8-13
- **Added**: 2026-11-12
- **Updated**: 2023-8-13
- **Version**: v1
- **arXiv**: 2308.06721
- **Category**: cs.CV · cs.AI
- **Original paper terms**: [arXiv non-exclusive 1.0](https://arxiv.org/licenses/nonexclusive-distrib/1.0/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://arxiv.org/abs/2308.06721v1) · [PDF ↗](https://arxiv.org/pdf/2308.06721v1)

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

Hu Ye, Jun Zhang, Sibo Liu, Xiao Han, Wei Yang (2023). IP-Adapter: Text Compatible Image Prompt Adapter for Text-to-Image Diffusion Models. arXiv:2308.06721v1. https://arxiv.org/abs/2308.06721v1

**BibTeX**

```
@misc{ye2023adapter,
  title = {{IP-Adapter: Text Compatible Image Prompt Adapter for Text-to-Image Diffusion Models}},
  author = {Hu Ye and Jun Zhang and Sibo Liu and Xiao Han and Wei Yang},
  year = {2023},
  eprint = {2308.06721},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2308.06721v1}
}
```

## Other paper commentary

- [CogVideoX: Text-to-Video Diffusion Models with An Expert Transformer](https://refivu.com/en/papers/d337167e-74d3-423d-ae74-fbe584f8b441-cogvideox-text-to-video-diffusion-models-with-an.md)
- [Adversarial Examples: Attacks and Defenses for Deep Learning](https://refivu.com/en/papers/757e3533-c849-4349-8fbc-e8ea84c0b042-adversarial-examples-attacks-and-defenses-for-deep-learning.md)
- [Generative Adversarial Network in Medical Imaging: A Review](https://refivu.com/en/papers/52fe40f2-c64e-4c29-a115-6564288d69f5-generative-adversarial-network-in-medical-imaging-a-review.md)
- [AttnGAN: Fine-Grained Text to Image Generation with Attentional Generative Adversarial Networks](https://refivu.com/en/papers/a0260608-3d36-436c-af24-a535c7e4e5ef-attngan-fine-grained-text-to-image-generation-with.md)
- [Stochastic Variational Inference](https://refivu.com/en/papers/36c9d62c-308d-476e-8657-7d699cf4658e-stochastic-variational-inference.md)
- [Transferability in Machine Learning: from Phenomena to Black-Box Attacks using Adversarial Samples](https://refivu.com/en/papers/0070f617-bee7-4459-b94e-a20f7c1d2de5-transferability-in-machine-learning-from-phenomena-to-black.md)
- [Sequence Transduction with Recurrent Neural Networks](https://refivu.com/en/papers/882824aa-8ddf-4d40-8608-c68a08ecc168-sequence-transduction-with-recurrent-neural-networks.md)
- [Ups and Downs: Modeling the Visual Evolution of Fashion Trends with One-Class Collaborative Filtering](https://refivu.com/en/papers/c7f79e17-0229-4098-a2b0-1f184335cf4d-ups-and-downs-modeling-the-visual-evolution-of.md)
- [MemGPT: Towards LLMs as Operating Systems](https://refivu.com/en/papers/bee01795-9fbb-4af1-af4c-8b4bff391e4b-memgpt-towards-llms-as-operating-systems.md)
- [Enhanced-alignment Measure for Binary Foreground Map Evaluation](https://refivu.com/en/papers/668b22a3-321a-4e3f-9465-2c7d6fb8ea23-enhanced-alignment-measure-for-binary-foreground-map.md)
- [A Survey on Multimodal Large Language Models](https://refivu.com/en/papers/3b7ae094-f8ab-4e29-a2fd-d41b1efe8cc0-a-survey-on-multimodal-large-language-models.md)
- [ProxylessNAS: Direct Neural Architecture Search on Target Task and Hardware](https://refivu.com/en/papers/40299bf6-79d4-4e50-829c-39acb400238f-proxylessnas-direct-neural-architecture-search-on-target.md)

## Terms in this paper

- [layer normalization](https://refivu.com/en/terms/7af9eccdb60d-layer-normalization)
- [classifier-free guidance](https://refivu.com/en/terms/7f72cec70f8e-classifier-free-guidance)
- [cross-attention](https://refivu.com/en/terms/83e3067f3ffa-cross-attention)
- [ControlNet](https://refivu.com/en/terms/38498f031397-controlnet)
- [DDIM sampler](https://refivu.com/en/terms/cc966719de70-ddim-sampler)
- [CLIP-I](https://refivu.com/en/terms/2c53f49daa94-clip-i)
- [IP-Adapter](https://refivu.com/en/terms/ae916c2cd9ff-ip-adapter)
- [Projection Network](https://refivu.com/en/terms/7aa4628f87d1-projection-network)
- [Text-to-Image Diffusion Models](https://refivu.com/en/terms/6f09420315a8-text-to-image-diffusion-models)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/fd8adfd8-142d-4826-85e2-96e825c8d373-ip-adapter-text-compatible-image-prompt-adapter-for)
