TL;DR
Current prompt retrieval methods for Visual In-Context Learning (VICL) focus entirely on image similarity while ignoring the labels, often selecting visually similar prompts with conflicting task contexts. To solve this, the authors introduce LaPR (Label-aware Prompt Retrieval), a framework that explicitly incorporates label consistency using a Mixture-of-Experts (MoE) mechanism to infer implicit query labels at test time. This approach delivers state-of-the-art performance across visual segmentation, object detection, and colorization tasks.
What Problem Does This Paper Address?
Visual In-Context Learning (VICL) allows vision foundation models to solve a variety of tasks (like segmentation or colorization) simply by providing them with a few demonstrative examples (prompts) alongside a query image. Typically, this is framed as a pixel-inpainting problem on a 2×2 grid containing a prompt image, its label, a query image, and a blank space for the predicted query label.
Because performance depends heavily on the quality of the chosen prompts, researchers have developed advanced prompt retrieval algorithms. However, existing retrievers are label-agnostic—they only look at how closely the prompt image resembles the query image.
The authors identify a critical flaw here: a retriever might select a prompt image that looks visually similar to the query but contains a completely different label mapping (e.g., a query image of a cat might retrieve a prompt image containing both a cat and a flower, but where the prompt label specifically highlights the flower). This label inconsistency confuses the backbone model and degrades performance. As shown in the paper's analysis, higher label consistency between the query and the prompt strongly correlates with better downstream performance.
Methods
To bridge this gap, the authors propose LaPR (Label-aware Prompt Retrieval), which re-engineers prompt selection to account for both image similarity and label consistency.
The framework introduces two main components:
- Joint Image-Label Embeddings: For candidate prompts in the database, the prompt image and its corresponding label are fused into a single joint representation.
- Mixture-of-Experts (MoE) for Queries: At test time, the query label is naturally missing. To circumvent this, LaPR passes the query image through a set of $K$ parallel "expert" networks. A query-adaptive router then predicts soft mixture weights over these experts. This allows the system to implicitly guess the latent label mode of the query and dynamically construct a label-aware query embedding.
Decoupled Two-Step Optimization
To train the experts and the router effectively without them interfering with each other, the authors use an alternating two-step optimization scheme per mini-batch:
- Expert Step: The router is fixed, and the experts are trained using a performance-guided contrastive loss ($\mathcal{L}_{PG}$). This loss pushes the embeddings of prompts that actually yield good VICL results closer to the query embedding.
- Router Step: The experts are frozen, and the router is optimized using a label-guided contrastive loss ($\mathcal{L}_{LG}$) alongside a load-balancing loss ($\mathcal{L}_{LB}$) to ensure all experts are evenly utilized. This step calibrates the router to align its predicted weights with the ground-truth query labels.
Datasets
The authors evaluated LaPR across three distinct downstream vision tasks using standard benchmarks:
- Foreground Segmentation: Pascal-5i dataset (20 categories split into 4 folds).
- Object Detection: Pascal VOC 2012 dataset (20 object categories).
- Colorization: A 50k image subset of ImageNet-1K for training, evaluated on the original validation set.
Key Insights and Ideas
- Labels Matter More Than Pure Vision: Visual similarity alone is an unreliable proxy for prompt quality. Label consistency acts as a vital anchor for in-context alignment.
- MoE as a Latent Label Predictor: Using an MoE structure allows the model to handle missing test-time labels gracefully. Instead of explicitly predicting a hard text or mask label, the router maps the query image to a mixture of latent task "modes" (e.g., specific object shapes or semantic concepts).
- Decoupled Training is Essential: Attempting to train the experts and the router simultaneously leads to unstable convergence and lower accuracy. Alternating the optimization steps ensures that expert representations remain distinct and stable while the router learns to navigate them.
Key Results
LaPR achieves substantial performance gains over existing state-of-the-art prompt selection methods:
- Standard Retrieval (Without Voting): LaPR outperforms the strongest baseline (RH-Partial2Global) by 6.00% on foreground segmentation (mIoU) and 3.46% on object detection.
- With Voting: When utilizing a voting ensemble strategy, LaPR achieves the highest overall performance on object detection (34.64% mIoU).
- Cross-Fold Transferability: When trained on one data fold and evaluated on unseen folds, LaPR outperforms standard SupPR by 14.8% and Partial2Global by 13.9%, demonstrating excellent generalization to novel categories.
Limitations and Future Work
While LaPR shows robust performance across different feature extractors (like CLIP and DINOv2), the authors note an interesting quirk: switching to a stronger vision model like DINOv2 does not automatically guarantee better prompt retrieval. This points to a persistent gap between generic self-supervised visual representations and the specific semantic signals required for visual in-context learning. The authors suggest that bridging this representation gap is a promising direction for future VICL retrieval research.
Summary updated