Abstract: Visual In-Context Learning (VICL) allows generalist models to perform new tasks using a few examples. However, these models often fail under distribution shifts like image corruption. We present Test-Time Visual In-Context Tuning (VICT), a self-supervised method that adapts model parameters to specific test samples using a cycle-consistency loss. VICT significantly improves robustness across diverse vision tasks without requiring additional labeled data.
Introduction
Visual In-Context Learning (VICL) has emerged as a powerful paradigm where a generalist model, such as "Painter," learns a new task by observing a few examples (prompts) provided in a grid format. For instance, given an image and its corresponding segmentation mask, the model can infer how to segment a new, unseen test image.
However, a significant limitation of current VICL models is their lack of robustness to distribution shifts. When encountered with real-world "messy" data—such as images affected by noise, blur, or adverse weather—the performance of these frozen models typically degrades. Interestingly, providing a "one-shot" prompt that shares the same corruption as the test image often fails to improve results, as the model's internal representations are not tuned for the shifted domain. This paper introduces Test-Time Visual In-Context Tuning (VICT) to address these challenges by adapting the model on-the-fly.
Methodology
VICT is a self-supervised test-time adaptation method that "tunes" the model's parameters using the specific test image before generating a final prediction. The core of this approach is a cycle-consistency task designed to align the model with the current data distribution.
The process involves four key steps:
- Forward Inference: The model takes a task prompt $(x, y)$ and a corrupted test image $x_t$ to generate a preliminary prediction $\hat{y}_t$.
- Cycle-Consistency (The "Flip"): The roles are reversed. The model is tasked with using the predicted $\hat{y}_t$ as a prompt to reconstruct the original, known ground-truth prompt label $y$.
- Optimization: A regression loss (Smooth-L1) is calculated between the reconstructed prompt and the original ground truth.
- Parameter Update: The model’s encoder weights are updated via backpropagation to minimize this loss. This forces the model to internalize the distribution shift, enabling more accurate mapping between corrupted inputs and clean outputs.
The authors found that tuning only the encoder is sufficient and computationally more efficient than updating the entire model, as the encoder is primarily responsible for representation extraction from the shifted domain.
Experimental Evaluation
The effectiveness of VICT was evaluated across six diverse vision tasks using datasets modified with 15 common corruptions (noise, blur, weather, and digital artifacts) at various severity levels:
- Depth Estimation: NYUv2-C
- Semantic Segmentation: ADE20K-C
- Panoptic Segmentation: COCO-C
- Image Denoising: SIDD-C
- Image Deraining: Rain-C
- Low-light Enhancement: LoL-C
Results and Discussion
VICT consistently outperformed the baseline Painter model across all evaluated tasks and corruption types.
Quantitative Performance
In semantic segmentation (ADE20K-C), VICT improved the mIoU from 25.8 to 29.3 in the one-shot setting. Similar significant gains were observed in depth estimation (NYUv2-C), where the absolute relative error (A.Rel) was substantially reduced compared to the frozen baseline.
Efficiency vs. Few-Shot Training
A remarkable finding is that performing VICT on a single test sample often yields better results than training the baseline model on 64 labeled few-shot examples from the corrupted distribution. This highlights the efficiency of test-time adaptation over traditional few-shot fine-tuning for handling domain shifts.
Qualitative Improvements
Visualizations indicate that VICT produces cleaner, more accurate outputs with fewer artifacts compared to the baseline, which often "hallucinates" details under heavy corruption. Furthermore, because VICT is task-agnostic, it can adapt to tasks not seen during original training, such as colorization, by learning the specific input-output relationship at test time.
Conclusion and Future Work
VICT provides a robust solution for visual in-context learning under distribution shifts. By leveraging cycle-consistency for self-supervised tuning, it bridges the gap between generalist training and real-world deployment. The primary limitation is inference speed, as per-sample gradient descent is computationally expensive. Future research may explore more efficient architectural designs or optimization strategies to enhance the practical applicability of test-time tuning.
Summary updated