Learning to Adapt Frozen CLIP for Few-Shot Test-Time Domain Adaptation

Zhixiang Chi, Li Gu, Huan Liu, Ziqiang Wang, Yanan Wu, Yang Wang, Konstantinos N Plataniotis

TL;DR

Few-shot Test-Time Domain Adaptation (FSTT-DA) aims to adapt models to unseen target domains using only a few unlabeled samples at test time. While foundation models like CLIP offer strong out-of-distribution capabilities, relying solely on their frozen feature space limits adaptation on novel downstream datasets, especially for smaller backbones like ViT-B/16. This paper introduces Learning to Complement (L2C), a framework that trains a lightweight parallel network directly on the input space to capture dataset-specific visual knowledge, while simultaneously optimizing text feature discrimination for robust domain-aware fusion.

What Problem Does This Paper Address?

Deep learning models often fail when deployed in real-world scenarios with domain shifts (e.g., changes in lighting, camera types, or geographic locations). Few-shot Test-Time Domain Adaptation (FSTT-DA) tackles this by adapting a source-trained model to an unseen target domain using just a few unlabeled examples at test time.

State-of-the-art methods leverage vision-language models like CLIP by keeping them frozen and generating domain-specific prompts in the feature space (e.g., VDPG). However, because CLIP hasn't explicitly seen these downstream datasets, its feature space knowledge is inherently constrained by its prior training. As a result, performance plummets on challenging real-world benchmarks when using smaller, less robust backbones like ViT-B/16.

Methods

The authors propose Learning to Complement (L2C), which adapts both visual and text features without modifying the internal weights of CLIP:

  1. Parallel CPNet & Revert Attention: A lightweight side network (CPNet) runs in parallel with the CLIP image encoder, taking raw input space tokens. To ensure it only learns new dataset-specific knowledge missing from CLIP, a parameter-free Revert Attention mechanism calculates the complement of the attention between CLIP and CPNet outputs, forcing CPNet to focus on CLIP's blind spots.
  2. Greedy Text Ensemble & Refinement: To improve downstream adaptation, the authors enhance the discrimination (inter-dispersion) of text features. They use a greedy text ensemble strategy as a pre-processing step to select optimal prompt templates, followed by a lightweight refinement module trained with a uniformity loss to maximize class differentiation.
  3. Domain-Aware Fusion (DAF): At test time, a few unlabeled images are reshaped to compute inter-instance relations, capturing domain-specific cues. This information queries a learnable Key-Value domain cache to generate a domain prompt. This prompt guides the cross-attention-based fusion of the complemented visual features and enhanced text features.
L2C Training Process

Datasets

The method is evaluated on five large-scale benchmarks:

  • DomainNet: A massive dataset containing 569K images across 345 classes and 6 distinct domains (Clip, Info, Paint, Quick, Real, Sketch).
  • WILDS Benchmarks: Real-world datasets with severe domain shifts and data imbalances, including:
  • iWildCam: Wildlife camera trap classification.
  • Camelyon17: Tumor detection in medical imaging.
  • FMoW: Functional Map of the World satellite imagery classification.
  • PovertyMap: A satellite imagery regression task for wealth index estimation.

Key Insights and Ideas

  • Input Space vs. Feature Space: Relying purely on prompting a frozen feature space limits what a model can adapt to. Learning directly from the input space via a parallel branch allows the system to capture dataset-specific nuances that CLIP's generalized pre-training completely missed.
  • Revert Attention as a Filter: Instead of letting the side network learn redundant features, Revert Attention explicitly forces it to focus on the "blind spots" of the foundation model.
  • Text Features Matter in Vision Adaptation: Domain shift doesn't just affect images; it affects how well text prototypes separate classes. Maximizing text feature inter-dispersion (making class text embeddings more distinct) acts as a powerful regularizer that prevents domain bias from muddying classification boundaries.

Key Results

L2C significantly outperforms prior state-of-the-art methods, particularly when using the smaller ViT-B/16 backbone:

  • On iWildCam, L2C achieves a +5.1 gain in Macro F1 score over VDPG using ViT-B/16.
  • On FMoW, it improves Worst-Case Accuracy (WC Acc) by +3.1% for ViT-B/16 and +0.3% for ViT-L/14.
  • On DomainNet, L2C achieves top accuracy in 5 out of 6 domains with a ViT-L/14 backbone, yielding an average accuracy improvement of +2.2%.
  • Efficiency: Crucially, during inference, the text encoder, text refinement module, and K-V cache can be discarded, making the framework highly computationally efficient.
Figure 1: VDPG preserves CLIP’s OOD capabilities by operating in the feature space and relying on pretrained CLIP. However, with a weaker backbone like ViT-B/16, performance drops on benchmarks like iWildCam and FMoW. Learning directly from the image space complements CLIP, improving ViT-B/16 as shown in (b).

Limitations and Future Work

The authors note that if a downstream dataset diverges drastically from CLIP's pre-training data, the burden on the parallel CPNet increases significantly. This scenario might necessitate a larger, more parameter-heavy side network. Future work could explore more adaptive scaling of the side network depending on the severity of the domain/dataset gap.

Summary updated

Abstract

Few-shot Test-Time Domain Adaptation focuses on adapting a model at test time to a specific domain using only a few unlabeled examples, addressing domain shift. Prior methods leverage CLIP's strong out-of-distribution (OOD) abilities by generating domain-specific prompts to guide its generalized, frozen features. However, since downstream datasets are not explicitly seen by CLIP, solely depending on the feature space knowledge is constrained by CLIP's prior knowledge. Notably, when using a less robust backbone like ViT-B/16, performance significantly drops on challenging real-world benchmarks. Departing from the state-of-the-art of inheriting the intrinsic OOD capability of CLIP, this work introduces learning directly on the input space to complement the dataset-specific knowledge for frozen CLIP. Specifically, an independent side branch is attached in parallel with CLIP and enforced to learn exclusive knowledge via revert attention. To better capture the dataset-specific label semantics for downstream adaptation, we propose to enhance the inter-dispersion among text features via greedy text ensemble and refinement. The text and visual features are then progressively fused in a domain-aware manner by a generated domain prompt to adapt toward a specific domain. Extensive experiments show our method's superiority on 5 large-scale benchmarks (WILDS and DomainNet), notably improving over smaller networks like ViT-B/16 with gains of \textbf{+5.1} in F1 for iWildCam and \textbf{+3.1\%} in WC Acc for FMoW.
BibTeX
@inproceedings{chi2025learning,
  author = {Zhixiang Chi and Li Gu and Huan Liu and Ziqiang Wang and Yanan Wu and Yang Wang and Konstantinos N Plataniotis},
  title = {{Learning to Adapt Frozen CLIP for Few-Shot Test-Time Domain Adaptation}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=TD3SGJfBC7},
}
Figure