IP-Adapter
An adapter model for image prompts
An adapter model for image prompts
IP-Adapter (Image Prompt Adapter) is a lightweight adapter that adds image prompt capability to text-to-image generation models (such as Stable Diffusion). With only 22M parameters, it can reflect the style, composition, and color of a reference image in new image generation, providing functionality similar to Midjourney or DALL-E 3.
IP-Adapter, announced by Tencent AI Lab in August 2023, is built around the "Decoupled Cross-Attention" mechanism. By processing text features and image features through separate cross-attention layers, the two modalities are combined effectively without interfering with each other.
IP-Adapter extracts features from a reference image with an image encoder (CLIP ViT-H) and injects them into the UNet of the diffusion model through an adapted module. When used together with a text prompt, multimodal image generation is possible.
In practice, the influence of the image prompt is adjusted with the ip_adapter_scale parameter (0.0~1.0). 0.5 is suitable for balancing text and image, while 1.0 conditions on the image alone. It is compatible with ControlNet and T2I-Adapter, so it can be used together with poses, depth maps, and so on.
from diffusers import StableDiffusionPipeline
from diffusers.utils import load_image
import torch
# Stable Diffusion 파이프라인 로드
pipe = StableDiffusionPipeline.from_pretrained(
"runwayml/stable-diffusion-v1-5",
torch_dtype=torch.float16
).to("cuda")
# IP-Adapter 로드
pipe.load_ip_adapter(
"h94/IP-Adapter",
subfolder="models",
weight_name="ip-adapter_sd15.bin"
)
# 참조 이미지 로드 (스타일 복사용)
reference_image = load_image("https://example.com/style_reference.jpg")
# IP-Adapter 스케일 설정 (0.5 = 텍스트와 이미지 균형)
pipe.set_ip_adapter_scale(0.6)
# 이미지 생성: 참조 이미지 스타일 + 텍스트 프롬프트
image = pipe(
prompt="a cat sitting on a couch, high quality",
ip_adapter_image=reference_image,
negative_prompt="low quality, blurry",
num_inference_steps=30,
generator=torch.Generator("cuda").manual_seed(42)
).images[0]
image.save("ip_adapter_result.png")
print("스타일 전이 이미지 생성 완료!")
"If you apply a reference image style with IP-Adapter, you can easily reproduce a mood that is hard to describe with a prompt alone. If you set the scale to around 0.6, the style is maintained while the content of the text prompt is also reflected."
"The core of IP-Adapter is Decoupled Cross-Attention. It processes text and image features with separate attention, so the two modalities are combined without interference. With 22M parameters, you can add image prompt capability without fine-tuning the entire model."
"The IP-Adapter Plus version uses patch embeddings, which enables more refined style transfer. The FaceID version is optimized for converting to a different style while preserving facial features."
Take a mock interview on this topic → WIA SOOM AI Interview · Start for free
When the scale is 1.0, the text prompt is almost ignored. In most cases, a range of 0.4~0.7 is suitable for balancing text and image.
Using an IP-Adapter for SD 1.5 with SDXL will not work. Be sure to choose an adapter that matches the base model.
If you control style with IP-Adapter and pose or composition with ControlNet, more precise image generation is possible.