Gradient Alignment with Prototype Feature for Fully Test-time Adaptation

Juhyeon Shin, Jonghyun Lee, Saehyung Lee, Minjun Park, Dongjun Lee, Uiwon Hwang, Sungroh Yoon · DOI

Abstract

Test-time adaptation (TTA) allows deep learning models to adapt to distribution shifts—such as noise, weather, or sensor corruptions—using only unlabeled incoming data. However, aggressive updates can lead to "semantic drift," where the model loses its original categorical knowledge. We introduce Structural Test-time Alignment of Gradients (STAG), a lightweight, architecture-agnostic regularizer that stabilizes TTA. By aligning online learning gradients with "structural anchors" derived from the pre-trained classifier's own weights, STAG prevents model collapse. Our method achieves significant accuracy improvements (up to +11%) across CNNs and Transformers with near-zero computational overhead.

Introduction

In real-world deployments, models frequently encounter data that differs from their training distribution. Standard TTA methods, such as TENT, minimize prediction entropy to increase confidence on corrupted data. However, this often leads to confirmation bias: if a model misclassifies a corrupted input, entropy minimization reinforces the error, causing a collapse in accuracy. Existing solutions often require source data or expensive offline computation. STAG addresses these challenges by providing a stable, source-free, and computationally efficient way to maintain semantic integrity during adaptation.

Methodology

STAG leverages the internal geometry of the pre-trained classifier as a stable reference. The method operates in two distinct phases:

  1. Structural Anchor Derivation: Before adaptation, each class weight vector in the classifier is treated as a "virtual input." By calculating self-structural entropy, we derive structural anchors—idealized gradient directions in the weight space that represent perfect class-specific updates.
  2. Online Gradient Alignment: During test-time, the model calculates the gradient of the entropy loss. STAG introduces a regularizer that uses cosine similarity to align this online gradient with the corresponding structural anchor.
Overview of the STAG framework, illustrating Phase 1 (Anchor Derivation) and Phase 2 (Online Alignment).

Both phases utilize closed-form analytical solutions, ensuring that STAG does not require additional backward passes, making it highly efficient for real-time deployment.

Key Insights

  • The Classifier as a Compass: The pre-trained classifier's geometry remains a stable reference point even when input data is noisy. Passing class weights back through the classifier yields 100% "structural accuracy," proving its reliability as a prior.
  • Gradient vs. Feature Alignment: Rather than simply forcing features toward prototypes, STAG ensures the direction of learning is consistent with the model's original logic.
  • Decaying Constraint: A decaying coefficient ($\beta_t$) provides strong guidance initially to prevent early drift, gradually allowing the model to specialize as it adapts to the target domain.

Experimental Results

STAG was evaluated on ImageNet-C, CIFAR-C, and semantic segmentation benchmarks (Cityscapes-to-ACDC).

Performance and Stability

On ImageNet-C, STAG improved TENT's accuracy on a ViT-Base model by 11.21% (from 48.0% to 59.2%). It also showed remarkable robustness in single-sample adaptation ($B=1$), providing a 10.68% boost for EATA on ResNet50-GN. Qualitatively, t-SNE visualizations demonstrate that STAG maintains distinct class clusters, whereas standard TENT leads to feature overlap and semantic collapse.

t-SNE visualization comparing (a) TENT and (b) TENT+STAG, showing how STAG preserves semantic cluster separation.

Efficiency

STAG introduces near-zero overhead. Benchmarks on an Nvidia A40 GPU showed that adding STAG to TENT increased processing time for 50,000 images by only 0.25 seconds (a 0.2% increase), making it ideal for edge devices.

Conclusion

STAG provides a robust and efficient mechanism for test-time adaptation by anchoring online updates to the model's inherent structural knowledge. Its architecture-agnostic nature and minimal computational cost make it a practical "plug-in" for enhancing model reliability in dynamic, real-world environments.

Summary updated

BibTeX
@misc{shin2024gradient,
  author = {Juhyeon Shin and Jonghyun Lee and Saehyung Lee and Minjun Park and Dongjun Lee and Uiwon Hwang and Sungroh Yoon},
  title = {{Gradient Alignment with Prototype Feature for Fully Test-time Adaptation}},
  year = {2024},
  eprint = {2402.09004},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2402.09004},
}
Figure