Explore In-Context Segmentation via Latent Diffusion Models

Chaoyang Wang, Xiangtai Li, Henghui Ding, Lu Qi, Jiangning Zhang, Yunhai Tong, Chen Change Loy, Shuicheng Yan

Abstract

In-context segmentation involves identifying objects in a query image based on a few reference examples. Traditional approaches often rely on complex task-specific decoders or textual instructions. This paper introduces LDIS (Latent Diffusion-based In-context Segmentation), a minimalist framework that leverages the generative power of Latent Diffusion Models (LDMs) to perform segmentation using only visual prompts. By treating segmentation as a conditional image mask generation process, LDIS achieves state-of-the-art results on benchmarks like PASCAL and COCO without requiring extra network heads or text-based guidance.

Introduction

Adapting powerful generative models like Stable Diffusion for perceptual tasks typically involves adding auxiliary components, such as textual prompts or task-specific decoder networks. These additions often obscure the inherent capabilities of the underlying model. Furthermore, existing in-context segmentation models like SegGPT rely on masked image modeling (MIM), which necessitates massive datasets to learn visual correspondences.

Comparison of in-context segmentation paradigms: (a) Discriminative Models, (b) Masked Image Modeling, and (c) the proposed LDIS framework.

The authors of LDIS propose a different path: reframing in-context segmentation purely as a conditional image mask generation process. This approach fully utilizes the LDM's generative potential without bolting on extra networks or relying on text, asking if visual prompts alone are sufficient for high-fidelity segmentation.

Methodology

LDIS is built upon Stable Diffusion 1.5, with specific modifications to handle the unique requirements of segmentation.

Visual Guidance and Instruction Extraction

To guide the LDM using only visual prompts, a CLIP vision encoder is employed. A common issue with this setup is "background leakage," where irrelevant information from the reference image's background interferes with the target concept. To mitigate this, LDIS introduces a two-stage masking strategy: pre-masking the input image and post-masking the attention maps. This ensures the extracted tokens strictly represent the foreground target.

The Visual Guidance input format, consisting of a query image and a visual prompt (image + mask).

Output Alignment

Since LDMs generate 3-channel RGB images, LDIS maps 1-channel binary segmentation masks to 3-channel "pseudo masks." An augmented pseudo-masking target is also used, which fuses query image information into the mask to maintain semantic context during the generation process.

Meta-Architectures: LDIS-1 vs. LDIS-n

The framework explores two architectural variants:

  • LDIS-1: A one-step sampling approach that directly optimizes the segmentation mask in pixel or latent space using an L2 loss.
  • LDIS-n: A multi-step sampling approach following the traditional diffusion process, starting from Gaussian noise and gradually denoising to predict the mask.

Experimental Setup

The model was evaluated on a comprehensive benchmark encompassing both image and video datasets:

  • Image Semantic Segmentation: PASCAL (20 categories) and COCO (80 categories).
  • Video Segmentation: DAVIS-16 and VSPW. The model was jointly trained on these datasets for 160K iterations, a significantly smaller training regime compared to foundation models like SegGPT.

Results and Discussion

LDIS-1 demonstrated exceptional performance, achieving 85.3 mIoU on PASCAL and 62.6 mIoU on COCO, outperforming both specialist models and massive generalist foundation models. In video tasks, LDIS-1 remained highly competitive, scoring 67.8 J&F on DAVIS-16.

Key Insights

  • Generative Priors for Segmentation: LDMs are inherently capable segmenters. Visual prompts, when extracted cleanly, provide sufficient guidance for accurate mask generation.
  • Direct Optimization: Surprisingly, the one-step LDIS-1 architecture outperformed the multi-step LDIS-n approach, suggesting that direct optimization in the target space is more effective for masks than iterative noise prediction.
  • Importance of Full Fine-Tuning: Parameter-efficient tuning methods like LoRA resulted in performance drops, indicating that the spatial requirements of segmentation necessitate full model fine-tuning to bridge the gap from generative training.

Conclusion

LDIS demonstrates that Latent Diffusion Models can be transformed into powerful in-context segmenters with minimal architectural changes. While the model excels in image-based tasks, future work will focus on incorporating explicit spatial priors and scaling training data to further improve performance in complex video segmentation scenarios.

Summary updated

BibTeX
@inproceedings{wang2025explore,
  author = {Chaoyang Wang and Xiangtai Li and Henghui Ding and Lu Qi and Jiangning Zhang and Yunhai Tong and Chen Change Loy and Shuicheng Yan},
  title = {{Explore In-Context Segmentation via Latent Diffusion Models}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2025},
  doi = {10.1609/aaai.v39i7.32812},
}
Figure