Abstract
Test-time adaptation (TTA) offers a path to robustify models against domain shifts without the prohibitive cost of retraining. While successful for CNNs, TTA has been challenging for Vision Transformers (ViTs) due to their reliance on Layer Normalization. This paper presents Class-Conditional Feature Alignment (CFA), a method that aligns internal feature distributions with source statistics during inference. CFA achieves state-of-the-art performance on ImageNet-C and demonstrates superior stability across hyperparameters compared to existing methods.
Introduction
Vision Transformers (ViTs) have demonstrated exceptional performance in computer vision, often surpassing traditional Convolutional Neural Networks (CNNs). However, their performance degrades significantly under distribution shifts, such as common image corruptions or domain variations. Traditional robustification strategies often involve data augmentation during training, which is computationally expensive for large-scale ViTs and requires access to the original training data—data that is frequently proprietary or unavailable.
Test-Time Adaptation (TTA) provides an alternative by modifying the model during inference using only unlabeled test data. While methods like Tent have been effective for CNNs by leveraging Batch Normalization (BN) statistics, ViTs utilize Layer Normalization (LN), making them less amenable to standard TTA techniques. This work addresses this gap by introducing Class-Conditional Feature Alignment (CFA).
Methodology: Class-Conditional Feature Alignment (CFA)
CFA aims to align the feature distributions of noisy test data with the statistics of the clean source training data. The method operates on three levels:
- Feature Normalization and Stabilization: To prevent optimization instability, hidden representations are processed through a non-learnable Layer Norm followed by a Tanh activation. This bounding of feature values is critical for stable moment matching.
- Global Distribution Alignment: CFA minimizes the Central Moment Discrepancy (CMD) between source and target features. Unlike simple mean matching, CMD aligns higher-order moments including variance, skewness, and kurtosis, providing a more comprehensive distributional match.
- Class-Conditional Alignment: By utilizing pseudo-labels generated from the model's current predictions, CFA aligns class-specific centroids. This ensures that features for a specific class (e.g., "cat") are moved toward the corresponding source distribution rather than shifting the entire feature space uniformly.
Importantly, CFA only requires pre-computed source statistics, preserving data privacy and minimizing storage requirements.
Experimental Evaluation
The authors evaluated CFA across several benchmarks, including common corruptions (CIFAR-10-C, CIFAR-100-C, and ImageNet-C) and domain adaptation tasks (SVHN to MNIST and ImageNet to ImageNet-Sketch). CFA was tested across various architectures, including ResNet, MLP-Mixer, and multiple ViT variants such as DeiT and BeiT.
Results and Discussion
CFA achieved a state-of-the-art top-1 error rate of 19.8% on ImageNet-C using a BeiT-L16 backbone, a significant improvement over the previous best TTA baseline of 44.0%.
A key advantage of CFA is its robustness to hyperparameter selection. Unlike entropy-minimization methods like Tent, which can be highly sensitive to learning rates and batch sizes, CFA maintains stable performance across a wide range of settings.
The study also debunked the notion that updating all model parameters during TTA necessarily leads to collapse. While updating only Layer Norm parameters is efficient, CFA's robust loss function allows for broader updates without catastrophic failure.
Conclusion
Class-Conditional Feature Alignment (CFA) effectively bridges the gap in test-time adaptation for Vision Transformers. By focusing on higher-order moment matching and class-conditional alignment, CFA provides a stable, privacy-preserving, and high-performance solution for deploying robust ViTs in real-world, dynamic environments.
Summary updated