NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Contrastive Test-Time Adaptation

Dian Chen, Dequan Wang, Trevor Darrell, Sayna Ebrahimi

Abstract

Test-time adaptation is a special setting of unsupervised domain adaptation where a trained model on the source domain has to adapt to the target domain without accessing source data. We propose a novel way to leverage self-supervised contrastive learning to facilitate target feature learning, along with an online pseudo labeling scheme with refinement that significantly denoises pseudo labels. The contrastive learning task is applied jointly with pseudo labeling, contrasting positive and negative pairs constructed similarly as MoCo but with source-initialized encoder, and excluding same-class negative pairs indicated by pseudo labels. Meanwhile, we produce pseudo labels online and refine them via soft voting among their nearest neighbors in the target feature space, enabled by maintaining a memory queue. Our method, AdaContrast, achieves state-of-the-art performance on major benchmarks while having several desirable properties compared to existing works, including memory efficiency, insensitivity to hyper-parameters, and better model calibration. Code is released at https://github.com/DianCh/AdaContrast.

Introduction

Deep learning models are notoriously brittle when they encounter "domain shift"—the gap between the data they were trained on (source) and the data they see in the real world (target). Test-time adaptation (TTA) aims to fix this by updating the model using only the unlabeled test data it encounters. This is particularly challenging because models often make "best guesses" (pseudo-labels) that are wrong, leading to a feedback loop of errors. Furthermore, many TTA methods make the model "over-confident" even when it's wrong, which is dangerous for real-world deployment.

The AdaContrast Framework

To address these issues, we introduce AdaContrast, which uses three main pillars to adapt models robustly without source data access:

Overview of the AdaContrast framework, illustrating the joint contrastive learning and online pseudo-label refinement process.
  • Online Pseudo-label Refinement: Instead of blindly trusting the model's top prediction, AdaContrast looks at the image's "neighborhood" in feature space. It maintains a memory queue of recently seen features and performs $k$-nearest neighbor ($k$-NN) soft voting: the final pseudo-label is an average of the predictions of the most similar images in the queue. This significantly denoises the labels.
  • Joint Contrastive Learning: Borrowing from self-supervised learning, the model learns to pull different views of the same image together while pushing different images apart. Crucially, refined pseudo-labels are used to exclude same-class negative pairs. If the model thinks two different images belong to the same class, it won't try to push them apart, helping the model learn better semantic clusters.
  • Weak-Strong Consistency: The model is trained to ensure that a "strongly" augmented version of an image produces the same prediction as the "weakly" augmented version, using the refined pseudo-label as the target.

Experimental Evaluation

We evaluated AdaContrast on two major domain adaptation benchmarks: VisDA-C (synthetic-to-real shift) and DomainNet-126 (shifts across Real, Sketch, Clipart, and Painting domains).

AdaContrast achieved state-of-the-art accuracy, reaching 86.8% on VisDA-C (a +3.8% improvement over the previous best method, SHOT) and 67.8% on DomainNet-126. Unlike prior methods that require "offline" passes over the entire dataset, AdaContrast works "online" at a per-batch level, making it suitable for streaming data.

Calibration and Reliability

One of the most striking findings is that joint contrastive learning makes the adaptation process incredibly robust. Most TTA methods use "entropy minimization," which forces the model to be certain, often ruining model calibration—the relationship between a model's confidence and its actual accuracy.

Reliability diagrams comparing SHOT and AdaContrast. AdaContrast shows significantly lower Expected Calibration Error (ECE) and Maximum Calibration Error (MCE).

As shown in the reliability diagrams, AdaContrast reduced the Expected Calibration Error (ECE) to just 0.65%, compared to 2.97% for SHOT. This means its confidence scores are much more trustworthy, which is vital for safety-critical applications like robotics.

Conclusion

AdaContrast demonstrates that contrastive learning acts as a powerful stabilizer during test-time adaptation. By combining neighbor-based label refinement with semantic-aware contrastive tasks, it achieves superior accuracy and calibration. While currently focused on closed-set adaptation, future work will explore extending this approach to open-world settings and more complex tasks like object detection.

Summary updated

BibTeX
@inproceedings{chen2022contrastive,
  author = {Dian Chen and Dequan Wang and Trevor Darrell and Sayna Ebrahimi},
  title = {{Contrastive Test-Time Adaptation}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2022},
  url = {https://openreview.net/forum?id=oXry4xObPJa},
}
Figure