Introduction
Vision Transformers (ViTs) have emerged as powerful alternatives to Convolutional Neural Networks (CNNs) across various computer vision tasks. Despite their superior performance on clean datasets, ViTs remain susceptible to performance degradation when encountering distribution shifts—unseen environmental changes such as fog, snow, or digital noise. Addressing these vulnerabilities typically requires retraining models with extensive data augmentation, a process that is often computationally prohibitive or impossible when original training data is inaccessible.
Test-Time Adaptation (TTA) offers a promising alternative by allowing models to adapt to new distributions during inference using only unlabeled test data. However, existing TTA methods, such as Tent, often exhibit instability when applied to ViTs, leading to "model collapse" under severe corruption. This paper introduces Attent, a novel TTA method designed specifically to stabilize and improve ViT robustness by leveraging internal attention mechanisms.
Methodology: The Attent Framework
Attent shifts the focus of adaptation from final prediction entropy to the internal dynamics of the Transformer architecture. The method is built upon three core pillars:
1. Attention Entropy
Unlike traditional methods that minimize prediction entropy, Attent monitors the "attention entropy" of internal attention maps. This metric serves as a proxy for model health; when a model encounters corrupted data, its attention patterns typically become scattered or anomalous. By quantifying the focus of these maps, Attent identifies deviations from the expected behavior of a well-calibrated model.
2. Distribution Matching via Central Moment Discrepancy (CMD)
The central innovation of Attent is the use of Central Moment Discrepancy (CMD) to align the distribution of attention entropy in corrupted data with that of the original clean training data. Rather than simply sharpening attention (which can be detrimental), Attent forces the mean and higher-order moments of the test-time attention entropy to match the statistics of the source data. This ensures the model maintains a healthy balance of local focus and global context.
3. Parameter-Efficient Updates
To ensure computational efficiency and prevent catastrophic forgetting, Attent does not update the entire model. Instead, it restricts updates to the affine transformation parameters within the Layer Normalization (LN) layers. This targeted approach provides enough flexibility for adaptation while maintaining the structural integrity of the pre-trained weights.
4. Hybrid Adaptation
Empirical results suggest that Attent is most effective when used in conjunction with Tent. In this hybrid configuration, Tent encourages confident final predictions, while Attent acts as a critical stabilizer, grounding the model's internal attention mechanisms in the learned patterns of the source distribution.
Experimental Evaluation
The researchers evaluated Attent across several standard robustness benchmarks:
- CIFAR-10-C & CIFAR-100-C: These datasets include 15 types of common corruptions (e.g., noise, blur, weather) applied to the classic CIFAR sets.
- ImageNet-C: This benchmark serves as the primary evaluation for large-scale robustness, testing models against various corruption types and severities.
The models used for evaluation were pre-trained on clean versions of CIFAR and ImageNet-21K.
Results and Discussion
The experimental results highlight the significant advantages of the Attent + Tent hybrid approach, particularly regarding stability and accuracy.
Enhanced Stability
One of the primary failures of Tent on ViTs is its tendency to collapse under high-severity corruptions. For instance, under severe "snow" corruption on ImageNet-C, Tent's error rate spiked to 75.7%, performing worse than the unadapted source model. In contrast, the Attent + Tent combination maintained an error rate of 62.5%, demonstrating superior resilience to extreme distribution shifts.
Improved Accuracy
On the highest severity level of ImageNet-C, the baseline unadapted ViT-B16 model exhibited a 61.9% error rate. While Tent reduced this to 50.6%, the integrated Attent + Tent approach further lowered the error rate to 47.6%. These gains were consistent across various corruption types.
Robustness to Hyperparameters
A common challenge in TTA is the sensitivity to hyperparameters like learning rate and batch size. Attent proved to be remarkably resilient to these variations. Unlike Tent, which often requires careful gradient clipping to prevent divergence, Attent provides a safer, more "plug-and-play" solution for real-world deployment.
Conclusion and Future Work
Attent demonstrates that internal attention mechanisms are vital indicators of model health during distribution shifts. By matching the distribution of attention entropy rather than merely minimizing it, Attent provides a stable and effective means of robustifying Vision Transformers without the need for expensive retraining.
While highly effective for environmental corruptions, the authors note that Attent is less effective for fundamental "style shifts" (e.g., adapting from SVHN to MNIST). Future research will explore extending attention-based adaptation to broader domain shifts and other Transformer-based domains, including Natural Language Processing and video analysis.
Summary updated