NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

CAFA: Class-Aware Feature Alignment for Test-Time Adaptation

Sanghun Jung, Jungsoo Lee, Nanhee Kim, Amirreza Shaban, Byron Boots, Jaegul Choo

Introduction

Deep learning models often struggle with distribution shifts, where test data (e.g., blurry or weather-affected images) differs from clean training data. Test-Time Adaptation (TTA) addresses this by allowing pre-trained models to fine-tune on unlabeled data during inference. However, conventional TTA methods often rely on "global" alignment, which can inadvertently degrade a model's ability to distinguish between different classes.

CAFA (Class-Aware Feature Alignment) is a novel TTA method that maintains class discriminability by aligning target features with pre-calculated source class distributions. It achieves state-of-the-art results without requiring source data during the adaptation phase.

The Pitfall of Global Alignment

Most existing TTA methods attempt to match the entire target distribution to the source distribution. While this bridges the domain gap, it often reduces inter-class distance, squashing different classes together in the feature space. This makes it harder for the model to differentiate between similar categories.

Comparison of global alignment vs. CAFA and conceptual diagram

As shown in Figure 1, global feature alignment (Global FA) leads to a decrease in inter-class distance and accuracy over time. In contrast, CAFA explicitly maximizes inter-class distance and minimizes intra-class distance, leading to sustained performance improvements as more test samples are processed.

Methodology

CAFA operates in two distinct stages, designed to be computationally efficient and privacy-preserving:

  1. Pre-Stage (Source Statistics): Before deployment, the mean ($\mu_c$) and covariance ($\Sigma_c$) for each class are calculated using the source training data. Research indicates that robust statistics can be obtained using as little as 5% of the training data, making this step highly efficient.
  2. Test-Time Adaptation: When encountering unlabeled target data, the model generates pseudo-labels to assign samples to likely classes. It then applies the CAFA loss, based on the Mahalanobis distance, to pull samples toward their predicted source class center while pushing them away from others.
Overview of the CAFA framework showing pre-stage and test-time adaptation

During adaptation, CAFA only updates the gain and bias parameters of the Batch Normalization layers. This targeted approach prevents catastrophic forgetting of the original model's knowledge while allowing it to adapt to new environments.

Experimental Results

CAFA was evaluated across rigorous benchmarks, including CIFAR-C, TinyImageNet-C, and ImageNet-C, which feature 15 types of corruptions.

  • Superior Accuracy: On CIFAR10-C, CAFA achieved a 12.13% error rate, significantly outperforming the non-adapted source model (29.14%) and established baselines like TENT (13.98%) and EATA (14.72%).
  • Large-Scale Robustness: On ImageNet-C, CAFA reduced the error rate to 55.24%, a substantial improvement over the 81.99% error of the source model.
  • Efficiency and Versatility: The method is hyper-parameter free and remains effective even with a batch size of 1. It also demonstrates resilience to label shift, where the distribution of classes in the test set is highly skewed.

Conclusion and Future Work

CAFA provides a robust, class-aware framework for test-time adaptation that outperforms global alignment strategies. While highly effective, the method currently relies on the accuracy of initial pseudo-labels; severe distribution shifts that cause near-zero initial accuracy remain a challenge. Future work may explore updating a broader set of network parameters without causing forgetting, further enhancing the model's adaptive capabilities.

Summary updated

BibTeX
@inproceedings{jung2022cafa,
  author = {Sanghun Jung and Jungsoo Lee and Nanhee Kim and Amirreza Shaban and Byron Boots and Jaegul Choo},
  title = {{CAFA: Class-Aware Feature Alignment for Test-Time Adaptation}},
  booktitle = {IEEE/CVF International Conference on Computer Vision},
  year = {2022},
  url = {https://openreview.net/forum?id=JmcZRqmaUIh},
}
Figure