Stable Diffusion Models are Secretly Good at Visual In-Context Learning

Trevine Oorloff, Vishwanath Sindagi, Wele Gedara Chaminda Bandara, Ali Shafahi, Amin Ghiasi +2 more
8/13/2025
cs.CVcs.LG

No official code found. Best implementation: rogergheser/SD-VICL (2 stars, last commit 2026-01-20).

Abstract

Large language models (LLM) in natural language processing (NLP) have demonstrated great potential for in-context learning (ICL) -- the ability to leverage a few sets of example prompts to adapt to various tasks without having to explicitly update the model weights. ICL has recently been explored for computer vision tasks with promising early outcomes. These approaches involve specialized training and/or additional data that complicate the process and limit its generalizability. In this work, we show that off-the-shelf Stable Diffusion models can be repurposed for visual in-context learning (V-ICL). Specifically, we formulate an in-place attention re-computation within the self-attention layers of the Stable Diffusion architecture that explicitly incorporates context between the query and example prompts. Without any additional fine-tuning, we show that this repurposed Stable Diffusion model is able to adapt to six different tasks: foreground segmentation, single object detection, semantic segmentation, keypoint detection, edge detection, and colorization. For example, the proposed approach improves the mean intersection over union (mIoU) for the foreground segmentation task on Pascal-5i dataset by 8.9% and 3.2% over recent methods such as Visual Prompting and IMProv, respectively. Additionally, we show that the proposed method is able to effectively leverage multiple prompts through ensembling to infer the task better and further improve the performance.

View on arXivView PDF

Code Implementations(1)

Repo to reproduce the work in https://arxiv.org/pdf/2508.09949

20PythonNov 29, 20259 months ago

Similar Papers

Cite this paper

@article{oorloff2025stable,
  title  = {Stable Diffusion Models are Secretly Good at Visual In-Context Learning},
  author = {Trevine Oorloff and Vishwanath Sindagi and Wele Gedara Chaminda Bandara and Ali Shafahi and Amin Ghiasi and Charan Prakash and Reza Ardekani},
  year   = {2025},
  eprint = {2508.09949},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2508.09949v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2508.09949.svg)](https://codeofpaper.com/paper/2508.09949)

Discussion