Abstract
Deep neural networks often suffer the data distribution shift between training and testing, and the batch statistics are observed to reflect the shift. In this paper, targeting of alleviating distribution shift in test time, we revisit the batch normalization (BN) in the training process and reveals two key insights benefiting test-time optimization: (i) preserving the same gradient backpropagation form as training, and (ii) using dataset-level statistics for robust optimization and inference. Based on the two insights, we propose a novel test-time BN layer design, GpreBN, which is optimized during testing by minimizing Entropy loss. We verify the effectiveness of our method on two typical settings with distribution shift, i.e., domain generalization and robustness tasks. Our GpreBN significantly improves the test-time performance and achieves the state of the art results.
Introduction
Machine learning models typically operate under the "i.i.d. assumption," where training and testing data are expected to share the same distribution. However, real-world applications frequently encounter "distribution shift" due to varying environmental factors like lighting, sensor noise, or domain changes. Such shifts often lead to significant performance degradation.
Batch Normalization (BN) is a cornerstone for stabilizing training but remains sensitive to these shifts. While existing test-time adaptation methods like Tent attempt to mitigate this by minimizing entropy, they often struggle with domain generalization (DG) tasks even if they perform well on robustness benchmarks. This research introduces GpreBN (Gradient Preserving Batch Normalization), a universal test-time adaptation strategy designed to handle both robustness and domain generalization effectively.
Methodology
GpreBN is founded on two critical technical insights regarding the behavior of Batch Normalization during test-time optimization:
- Preserving Gradient Flow: In standard training, the shared batch statistics ($\mu, \sigma$) create a "cross-instance" relationship where the gradient of one image is influenced by others in the batch. Many test-time methods inadvertently break this relationship. GpreBN employs a mathematical formulation that ensures the gradient backpropagation during testing mirrors the training phase exactly, maintaining the optimization landscape the model was designed for.
- Dataset-Level Statistics: Small test batches often produce noisy statistics. GpreBN utilizes stable, dataset-level statistics (via running averages or mixtures of source and target statistics) to provide a more robust global view of the data distribution, preventing the volatility that plagues batch-specific adaptation.
Additionally, the authors propose rT3A, a refined version of the Test-Time Classifier Adjustment (T3A) algorithm. While GpreBN adapts the feature extractor, rT3A focuses on the classifier head by updating class centroids using a moving average.
Experimental Evaluation
The effectiveness of GpreBN was evaluated across two primary challenges: Domain Generalization (DG), using the DomainBed benchmark (PACS, VLCS, OfficeHome, TerraIncognita), and Robustness, using corrupted versions of standard datasets (CIFAR-10-C, CIFAR-100-C, and ImageNet-C).
Key Results
GpreBN demonstrates superior performance across both task types. In Domain Generalization, GpreBN significantly improves upon standard Empirical Risk Minimization (ERM). For instance, on the PACS dataset, ERM + GpreBN achieves 88.9% accuracy compared to the 84.7% baseline, while Tent significantly degrades performance in this setting.
On robustness tasks, GpreBN achieves state-of-the-art results. On CIFAR-10-C, it reduces the mean Corruption Error (mCE) to 8.9, outperforming both the baseline (11.2) and Tent (9.2). Similar gains are observed on CIFAR-100-C and ImageNet-C.
Discussion and Conclusion
The success of GpreBN highlights that the form of the computational graph and the stability of statistics are as crucial as the data itself for test-time adaptation. By decoupling normalization statistics from gradient calculation, GpreBN allows for stable inference while maintaining the necessary gradient flow for effective optimization.
A current limitation is GpreBN's dependency on Batch Normalization layers, making it less directly applicable to architectures like Vision Transformers (ViTs) that favor Layer Normalization. Future research will focus on extending these gradient-preserving principles to other normalization techniques and optimizing the computational overhead of test-time forward-backward passes for real-time applications.
Summary updated