Test-Time Adaptation via Self-Training with Nearest Neighbor Information

Minguk Jang, Sae-Young Chung, Hye Won Chung

This post summarizes the paper "Test-Time Adaptation via Self-Training with Nearest Neighbor Information" (TAST), published at ICLR 2023.

The Problem: Domain Shift and Confirmation Bias

Deep learning models are notoriously brittle when the "test" data looks different from the "training" data—a phenomenon known as domain shift. Test-Time Adaptation (TTA) aims to fix this by updating the model "on the fly" using only an unlabeled stream of test data.

The standard approach to TTA is self-training: the model predicts a label for a test image (a "pseudo-label") and then treats that prediction as ground truth to update its own weights. However, this creates a dangerous feedback loop called confirmation bias. If the model is initially confused by the domain shift and predicts "Cat" for a "Dog," it will train itself to be even more certain of that incorrect prediction, leading to performance collapse.

Methods: Introducing TAST

The authors introduce TAST (Test-time Adaptation via Self-Training), which breaks the confirmation bias loop through three key innovations.

TAST Architecture and Comparison
  1. Nearest Neighbor Pseudo-Labeling: Instead of relying solely on the model's raw output for a single image, TAST looks at a "support set" of previously seen test examples. It finds the nearest neighbors of the current image in the feature space and assigns a pseudo-label based on the consensus of those neighbors. This relies on the intuition that even under domain shift, similar objects should cluster together.
  2. Trainable Adaptation Modules: Rather than fine-tuning the entire massive backbone (which is slow and unstable), TAST adds small, randomly initialized "adaptation modules" on top of a frozen feature extractor. These modules are trained to map features to the correct class distributions.
  3. Ensemble Learning (BatchEnsemble): To make the adaptation robust, TAST uses an ensemble of these modules. They use a technique called BatchEnsemble to keep the computational cost low while gaining the stability of multiple "opinions" on the data.

The paper also introduces a variant called TAST-BN, which applies the nearest-neighbor labeling logic to fine-tune the Batch Normalization layers of the backbone instead of adding new modules.

Key Insights

  • Local > Global: Under domain shift, the global decision boundary of a classifier often shifts incorrectly. However, the local neighborhood structure in the embedding space is often preserved. TAST exploits this local consistency to generate more reliable labels.
  • The "Frozen" Advantage: By keeping the feature extractor frozen and only training small adaptation modules, the model retains its core knowledge while learning the specific nuances of the new test domain.
  • Ensembles Mitigate Randomness: Since the adaptation modules start with random weights, a single module might fail. Averaging predictions across an ensemble significantly stabilizes the adaptation process.

Key Results

TAST was evaluated on domain generalization benchmarks (VLCS, PACS, OfficeHome, TerraIncognita) and image corruption datasets (CIFAR-10/100C). It consistently outperformed existing state-of-the-art methods like Tent, T3A, and SHOT.

Domain Generalization Results
  • Domain Generalization: On the PACS benchmark using a ResNet-18 backbone, TAST achieved 81.94% accuracy, outperforming the baseline ERM (79.29%) and the previous best TTA method, T3A (80.83%).
  • Image Corruption: On CIFAR-10C (highest corruption level), TAST-BN achieved an error rate of 13.08%, a significant improvement over Tent (13.95%).
  • Efficiency: TAST is computationally efficient, requiring only a few gradient steps per batch. It runs significantly faster than methods that update the entire feature extractor.

Limitations and Future Work

While highly effective, the authors note that TAST might struggle with very large-scale benchmarks like ImageNet-C. In such cases, the "support set" becomes massive, making it difficult to maintain accurate prototypes for 1,000 different classes within small test batches. Additionally, if the test stream is heavily biased toward one class, the nearest neighbor search might become skewed.

Future research could focus on making support set management more efficient for high-dimensional class spaces and improving prototype update logic for long-tail data distributions.

Summary updated

BibTeX
@inproceedings{jang2023test,
  author = {Minguk Jang and Sae-Young Chung and Hye Won Chung},
  title = {{Test-Time Adaptation via Self-Training with Nearest Neighbor Information}},
  booktitle = {International Conference on Learning Representations},
  year = {2023},
  url = {https://openreview.net/forum?id=EzLtB4M1SbM},
}
Figure