Abstract
Visual In-Context Learning (VICL) enables vision models to adapt to new tasks using a few demonstration examples. Current methods predominantly treat prompt selection as a competition, seeking a single "perfect" example. This paper introduces CONDENSER, a lightweight plugin that shifts this paradigm toward collaboration. By merging multiple candidate prompts into a single high-quality condensed prompt, CONDENSER significantly enhances performance and scalability without the prohibitive computational overhead of traditional ensemble methods.
Introduction
Visual In-Context Learning (VICL) allows models to solve novel tasks—such as segmentation or colorization—by observing a few "demonstration" prompts consisting of an image and its corresponding label. The standard approach, Prompt Selection, involves retrieving the single most similar example from a database. However, this "winner-takes-all" strategy is inherently limited; a single prompt rarely captures all necessary features (e.g., pose, lighting, or object variety) required for a complex query.
Existing multi-prompt methods often suffer from resolution loss due to downsampling or high latency from running the model multiple times. CONDENSER addresses these challenges by efficiently integrating the best components of multiple prompts into a single, high-resolution context.
Methodology: The CONDENSER Plugin
CONDENSER is designed as a lightweight external module that works alongside a frozen vision backbone. It identifies relevant patterns across $K$ candidate prompts and fuses them into a single "condensed" prompt image and label.
Patch-wise Cross-Attention (PCA)
A core innovation of CONDENSER is Patch-wise Cross-Attention (PCA). Unlike standard global attention, PCA employs a spatially constrained mechanism. For each patch in the query image, the model only attends to the corresponding spatial patches across the candidate prompts. This preserves local consistency and prevents the model from being distracted by irrelevant features in disparate image regions.
Learning Objectives
The system is trained using two primary losses:
- Token Prediction Loss ($L_{TP}$): Ensures the condensed prompt effectively assists the backbone in predicting the correct task output.
- Pre-Alignment Loss ($L_{PA}$): A regularization step that aligns the features of the condensed prompt with the query image prior to backbone entry, enhancing stability.
Experimental Evaluation
The model was evaluated on several vision tasks, including foreground segmentation (Pascal-5ⁱ), single-object detection (Pascal VOC 2012), and image colorization (ImageNet-1K). Cross-dataset transferability was also tested using COCO-5ⁱ.
Key Results
- State-of-the-Art Performance: CONDENSER achieved an 8.09% relative improvement over the strongest baselines in segmentation tasks.
- Scalability and Efficiency: Performance consistently improved as the number of prompts ($K$) increased from 1 to 32. Crucially, CONDENSER remains efficient; at $K=16$, it is approximately 15x faster than ensemble-based methods (66ms vs. 989ms per query) because the heavy vision backbone only runs once.
- Robustness: The condensation process effectively extracts useful signals even when the initial retrieval of prompts is weak or random.
Discussion and Insights
The primary insight of this work is that "collaboration outperforms competition": multiple "okay" prompts, when combined, consistently yield better results than the single "best" prompt. Furthermore, spatial consistency is critical; the spatially-constrained PCA outperformed full cross-attention, highlighting the importance of coordinate-to-coordinate relationships in vision tasks.
While CONDENSER is computationally fast, it does increase GPU memory usage by approximately 30MB per additional prompt. Future work may involve adapting this strategy to larger foundational models or exploring higher-level semantic reasoning during the condensation phase.
Summary updated