Visual In-Context Prompting

Feng Li, Qing Jiang, Hao Zhang, Tianhe Ren, Shilong Liu, Xueyan Zou, Huaizhe Xu, Hongyang Li, Chunyuan Li, Jianwei Yang, Lei Zhang, Jianfeng Gao

TL;DR

DINOv introduces a universal visual in-context prompting framework capable of tackling both generic segmentation (identifying all objects matching a concept) and referring segmentation (locating a specific object) using arbitrary visual inputs like points, boxes, or scribbles. By unifying single-image and cross-image prompting within a standard encoder-decoder architecture, DINOv achieves competitive in-domain performance and remarkable zero-shot generalization on open-set and video benchmarks without relying on pre-trained language models.

What Problem Does This Paper Address?

While in-context prompting has revolutionized Large Language Models (LLMs), bringing robust zero-shot capabilities to text, it remains vastly underexplored in computer vision. Existing visual prompting models typically suffer from two main limitations:

  1. Task Specialization: Models like SAM or SEEM excel at referring segmentation (isolating a specific object pointed out by a user) but struggle with generic segmentation (finding all instances of that category across an image or dataset).
  2. Representation Gaps: Text-prompted open-set models are flexible but cannot accept segmentation masks as inputs, making them ill-suited for purely visual in-context learning. Conversely, pixel-level in-context models (like SegGPT) treat segmentation as an image-coloring problem, which often fails to generalize well to completely novel semantic concepts.

DINOv bridges this gap by creating a unified framework that handles both referring and generic vision tasks using purely visual, arbitrary in-context prompts.

Comparison of DINOv against existing text and visual prompting frameworks.

Methods

DINOv builds upon the unified detection and segmentation architecture of MaskDINO, extending it with a novel visual prompting mechanism.

1. The Prompt Encoder

Instead of using a separate, frozen model like CLIP to encode cropped image regions—which introduces domain shifts and degrades performance on small objects—DINOv reuses its native vision encoder. It extracts multi-scale features from the reference image and applies a series of Masked Cross-Attention layers. The user's visual prompts (points, boxes, scribbles, or masks) act as spatial masks, forcing the prompt encoder to focus purely on the features of the target object.

2. Dual Query Formulation

To handle different tasks seamlessly, DINOv uses two distinct query types in its shared decoder:

  • Generic Latent Queries: A fixed set of learnable queries used to propose candidate masks across the image.
  • Interactive Point Queries: Queries initialized from specific spatial coordinates (anchors) to handle fine-grained referring tasks.

3. Shared Decoder and Prompt Classifier

The decoder outputs both mask proposals and target visual prompt features. A unified PromptClassifier computes the similarity between the decoded object features and the prompt features. The framework remains completely identical for both generic and referring tasks, save for two distinct linear projection layers ($g$ and $h$) that pivot the loss function depending on the task context.

The general framework of DINOv alongside specific loss formulations for generic and referring segmentation.

Datasets

The model is jointly trained on two major data sources:

  • COCO 2017: Panoptic segmentation dataset (~110K images) providing rich semantic category labels.
  • SA-1B: A 20% subset (~2M images) providing massive-scale, category-agnostic pixel annotations.

For evaluation, the authors test DINOv's zero-shot capabilities across several diverse benchmarks:

  • ADE20K: For out-of-domain open-set panoptic segmentation.
  • SegInW (Segmentation in the Wild): A suite of 25 instance segmentation datasets.
  • ODinW (Object Detection in the Wild): A suite of 35 bounding-box detection datasets.
  • DAVIS2017, DAVIS2016-Interactive, and YouTube-VOS 2018: For zero-shot video object segmentation (VOS).

Key Insights and Ideas

  • Reusing the Vision Encoder Beats CLIP: The authors discovered that using a pre-trained CLIP model to extract features from cropped prompt regions yields poor generalization on open-set datasets like ADE20K. Reusing the native encoder with masked cross-attention preserves crucial fine-grained spatial details.
  • Batch-Wide Prompt Sampling: To teach the model generic segmentation during training, the authors grouped visual prompts of the same semantic category across an entire image batch. This batch-wide aggregation effectively simulates the cross-image in-context scenarios the model encounters during inference.
  • Emergent Zero-Shot VOS: Even though DINOv is trained purely on static images, it naturally extends to video object segmentation. By treating predicted masks from previous video frames as "memory visual prompts" and averaging them with the first frame's prompt, the model tracks objects through time without any video-specific training.

Key Results

  • In-Domain Performance: On COCO panoptic segmentation, DINOv achieves 57.7 PQ, nearly matching its close-set baseline, MaskDINO (58.3 PQ), while drastically outperforming visual prompt generalists like SegGPT (43.4 PQ) and Painter (34.4 PQ).
  • Open-Set Generalization: Evaluated zero-shot on ADE20K, DINOv hits 23.2 PQ, outperforming text-prompted open-set models like OpenSeed-T (19.8 PQ) despite using significantly less semantic training data.
  • Robustness in the Wild: DINOv achieves an Average AP of 40.6 on SegInW and 15.7 on ODinW, demonstrating strong generalization to rare and domain-specific categories.
  • Video Object Segmentation: On the DAVIS2017 benchmark, DINOv achieves a zero-shot 72.3 J&F score, outperforming video-agnostic generalist models like SEEM-L (58.9 J&F).
Qualitative examples of DINOv performing open-set segmentation based on visual prompts.

Limitations and Future Work

The primary limitation noted by the authors is the reliance on a relatively small amount of semantically labeled data (only COCO). Scaling up the training mixture with larger, more diverse semantically labeled datasets is a clear path forward to boost performance. Additionally, the current framework is purely visual; the authors suggest that extending DINOv to support joint text and visual prompts would create a more versatile multi-modal understanding framework.

Summary updated

BibTeX
@misc{li2023visual,
  author = {Feng Li and Qing Jiang and Hao Zhang and Tianhe Ren and Shilong Liu and Xueyan Zou and Huaizhe Xu and Hongyang Li and Chunyuan Li and Jianwei Yang and Lei Zhang and Jianfeng Gao},
  title = {{Visual In-Context Prompting}},
  year = {2023},
  eprint = {2311.13601},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2311.13601},
}
Figure