Visual Prompt Selection for In-Context Learning Segmentation

Wei Suo, Lanqing Lai, Mengyang Sun, Hanwang Zhang, Peng Wang, Yanning ZhangarXiv 2024 · DOI

In-Context Learning (ICL) has emerged as a powerful paradigm in computer vision, enabling generalist models like SegGPT and Painter to perform segmentation tasks on novel images using only a few annotated examples (prompts) provided at inference time. However, these models exhibit extreme sensitivity to prompt selection; choosing a sub-optimal example can lead to performance drops of over 5 mIoU points. This paper introduces Stepwise Context Search (SCS), a framework designed to optimize visual prompt selection by prioritizing data diversity and employing reinforcement learning.

The Stepwise Context Search (SCS) Framework

Traditional methods for prompt selection typically rely on random sampling or simple similarity-based retrieval (finding the image most visually similar to the query). SCS challenges this approach by introducing a two-stage pipeline that focuses on building a representative candidate pool and then adaptively searching for the best match.

Comparison between traditional context learning methods and the proposed Stepwise Context Search (SCS) framework.

1. Diverse Candidate Pool Construction

Instead of searching an entire annotated database, SCS uses K-means clustering on unlabeled data (leveraging CLIP features) to identify key semantic clusters. From each cluster, the system selects the two most dissimilar members—the one closest to the center ("nearest") and the one furthest away ("farthest"). This strategy ensures the candidate pool captures the full variance of the dataset with minimal human annotation effort.

2. Adaptive Search Module

To select the optimal prompt from the candidate pool for a specific query, SCS employs a reinforcement learning (RL) search agent. This agent, a lightweight Multi-Layer Perceptron (MLP), predicts which examples will yield the highest accuracy. It is trained using the segmentation model's own Intersection over Union (IoU) scores as a reward signal, effectively learning to identify prompts that fill the model's semantic gaps.

Rethinking Similarity: Diversity Over Proximity

A core contribution of this research is the empirical finding that visual similarity is not a reliable proxy for prompt quality. Analysis across various similarity metrics (such as ViT, CLIP, and SSIM) reveals that in approximately 40% of cases, the "farthest" (least similar) image in a cluster actually produces a better segmentation result than the "nearest" (most similar) one.

Analysis of mIoU performance (a) and the effectiveness of nearest vs. farthest neighbors across different similarity metrics (b).

As shown in Figure 2(b), no single similarity metric consistently identifies the best prompt. By combining diverse examples—specifically pairing a "nearest" and a "farthest" neighbor—the model receives richer semantic information, allowing it to better understand the boundaries of a concept (e.g., recognizing a cat in an unusual pose by seeing both a typical and an atypical example).

Experimental Results and Impact

SCS was evaluated on major benchmarks including PASCAL-5i, COCO-20i, and the remote sensing dataset iSALD-5i. The results demonstrate that SCS acts as a robust "plug-and-play" enhancement for existing ICL models:

  • Performance Gains: On the COCO-20i 1-shot task, SCS improved SegGPT's performance from 48.6 mIoU to 57.2 mIoU, an 8.6-point increase.
  • Efficiency: The method outperforms traditional retrieval strategies by 4-9 points while requiring significantly fewer annotations due to its cluster-based sampling.
  • Generalization: The framework proved effective across diverse domains, including standard object segmentation and specialized aerial imagery, highlighting its versatility.

Conclusion

Stepwise Context Search shifts the focus of visual prompt selection from simple similarity to strategic diversity. By using a reinforcement learning agent to navigate a curated, diverse candidate pool, SCS significantly enhances the accuracy and reliability of generalist segmentation models. Future work will explore the impact of different visual encoders on prompt selection and aim to reduce the computational overhead of the search agent for real-time applications.

Summary updated

BibTeX
@misc{suo2024visual,
  author = {Wei Suo and Lanqing Lai and Mengyang Sun and Hanwang Zhang and Peng Wang and Yanning Zhang},
  title = {{Visual Prompt Selection for In-Context Learning Segmentation}},
  year = {2024},
  eprint = {2407.10233},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2407.10233},
}
Figure