Improving Entropy-Based Test-Time Adaptation from a Clustering View

Guoliang Lin, Hanjiang Lai, Yan Pan, Jian Yin · OpenReview

Abstract

Domain shift is a common problem in the realistic world, where training data and test data follow different data distributions. To deal with this problem, fully test-time adaptation (TTA) leverages the unlabeled data encountered during test time to adapt the model. In particular, Entropy-Based TTA (EBTTA) methods, which minimize the prediction's entropy on test samples, have shown great success. In this paper, we introduce a new perspective on the EBTTA, which interprets these methods from a view of clustering. It is an iterative algorithm: 1) in the assignment step, the forward process of the EBTTA models is the assignment of labels for these test samples, and 2) in the updating step, the backward process is the update of the model via the assigned samples. Based on the interpretation, we can gain a deeper understanding of EBTTA, where we show that the entropy loss would further increase the largest probability. Accordingly, we offer an alternative explanation that why existing EBTTA methods are sensitive to initial assignments, outliers, and batch size. This observation can guide us to put forward the improvement of EBTTA. We propose robust label assignment, weight adjustment, and gradient accumulation to alleviate the above problems. Experimental results demonstrate that our method can achieve consistent improvements on various datasets.

Introduction: The Challenge of Domain Shift

Deep learning models often struggle when encountering "domain shift"—discrepancies between training data and real-world deployment conditions, such as a model trained on clear-day images attempting to process foggy or noisy scenes. Test-Time Adaptation (TTA) addresses this by allowing models to adapt to new conditions using only the unlabeled data encountered during inference.

A popular approach, TENT, minimizes the entropy of model predictions to increase certainty. However, TENT is notoriously sensitive to batch sizes; in low-batch scenarios (e.g., batch size = 1), performance often collapses, sometimes falling below the original unadapted model. This research seeks to understand the mechanics of this failure and proposes a more reliable framework.

The Clustering Perspective

This paper reinterprets entropy-based TTA through the lens of unsupervised clustering. The authors demonstrate that the adaptation process functions as an iterative algorithm:

  1. The Assignment Step (Forward Pass): The model assigns labels to test samples based on current weights.
  2. The Updating Step (Backward Pass): The model updates its weights (effectively moving "cluster centers") based on these assignments.

Mathematical analysis (Lemma 1) reveals that minimizing entropy implicitly increases the probability of the most likely class, driving the model toward "one-hot" overconfidence. As shown in the figure below, this process forces the model to converge on a single class assignment over iterations.

Evolution of class probabilities under entropy minimization for different numbers of classes K, illustrating the convergence toward a single dominant class.

This view explains why small batches fail: a batch size of 1 forces the "cluster center" to update based on a single, potentially noisy point without the stabilizing effect of averaging, leading to rapid model drift.

Test-Time Clustering (TTC)

To address these vulnerabilities, the authors propose Test-Time Clustering (TTC), incorporating several robust components:

  • Robust Label Assignment (RLA): The model averages predictions from the original image and a weakly augmented version (e.g., horizontal flip) to create a stable pseudo-label.
  • Similarity-Preserving Constraint (SPC): This forces the model to maintain similar predictions for similar inputs, ensuring feature-space coherence.
  • Sample Selection (SS): The framework dynamically filters out "outliers"—samples with high entropy—to prevent unreliable data from corrupting the update.
  • Gradient Accumulation (GA): By accumulating gradients over multiple steps, TTC simulates larger batch sizes, providing stability even in stream-based applications with small real-time batches.

Key Results

TTC was evaluated on standard benchmarks including CIFAR-10-C, CIFAR-100-C, and ImageNet-C. It consistently outperformed TENT and other state-of-the-art methods. On CIFAR-10-C, TTC achieved an average accuracy of 82.5%, significantly higher than the source model's 56.5% and TENT's 81.5%.

Comparison of accuracy (%) on CIFAR-10-C at severity level 5 across various corruption types. TTC (ours) consistently achieves the highest average performance.

Notably, TTC maintains high performance in small-batch scenarios where TENT typically fails. For instance, while TENT's accuracy on CIFAR-10-C drops sharply at a batch size of 1, TTC’s use of gradient accumulation ensures robustness, making it suitable for practical, real-time deployment.

Conclusion

By framing entropy minimization as implicit clustering, this work provides a theoretical foundation for the instabilities observed in existing TTA methods. The resulting TTC framework offers a more robust, stable, and accurate solution for adapting models to new domains on the fly, particularly in challenging, low-data-density environments.

Summary updated

Abstract

Domain shift is a common problem in the realistic world, where training data and test data follow different data distributions. To deal with this problem, fully test-time adaptation (TTA) leverages the unlabeled data encountered during test time to adapt the model. In particular, Entropy-Based TTA (EBTTA) methods, which minimize the prediction's entropy on test samples, have shown great success. In this paper, we introduce a new perspective on the EBTTA, which interprets these methods from a view of clustering. It is an iterative algorithm: 1) in the assignment step, the forward process of the EBTTA models is the assignment of labels for these test samples, and 2) in the updating step, the backward process is the update of the model via the assigned samples. Based on the interpretation, we can gain a deeper understanding of EBTTA, where we show that the entropy loss would further increase the largest probability. Accordingly, we offer an alternative explanation that why existing EBTTA methods are sensitive to initial assignments, outliers, and batch size. This observation can guide us to put forward the improvement of EBTTA. We propose robust label assignment, weight adjustment, and gradient accumulation to alleviate the above problems. Experimental results demonstrate that our method can achieve consistent improvements on various datasets. Code is provided in the supplementary material.

Empirical ResultsBrowse all benchmarks →

BenchmarkMethodMetricScoreProtocol / Evidence
CIFAR-10-CTTCaverage accuracy83.1\%test-time-adaptation · backbone=WideResNet28-10 · optimizer=Adam · batch-size=100 · learning-rate=0.001
Source quote
L291: The results are shown in Table~\ref{c10}. We can see that our method achieves the best average accuracy 83.1%, which is 1.6% superior to the second best method TENT. Besides, TTC performs better TENT on all corruption types.
CIFAR-100-CTTC (HorFlip augmentation)average accuracy51.8test-time-adaptation · backbone=WideResNet28-10 · optimizer=Adam · batch-size=100 · augmentation=horizontal-flip · learning-rate=0.001
Source quote
L362: \multicolumn{1}{l|}{ HorFlip } │ 83.1 │ 51.8 │ 45.0
ImageNet-CTTCaverage accuracy45.0\%test-time-adaptation · backbone=ResNet50 · optimizer=SGD · batch-size=100 · learning-rate=0.002
Source quote
L296: ImageNet-C. The results of Table~\ref{ima} show that our method achieves the best average accuracy 45.0%, and the ACC of second best model ETA is 43.6%. Note that previous entropy-based methods achieve excellent performance, even so, our method performs better than them.
Reported baseline / comparator measurements (2)
BenchmarkMethodMetricScoreProtocol / Evidence
CIFAR-10-CTENT baselineaverage accuracy81.5test-time-adaptation
Source quote
L345: \multicolumn{1}{l|}{ TENT } │ 81.5 │ 48.8 │ 42.3
ImageNet-CETA baselineaccuracy (ACC)43.6\%test-time-adaptation · backbone=ResNet50 · optimizer=SGD · batch-size=100 · learning-rate=0.002
Source quote
L296: ImageNet-C. The results of Table~\ref{ima} show that our method achieves the best average accuracy 45.0%, and the ACC of second best model ETA is 43.6%. Note that previous entropy-based methods achieve excellent performance, even so, our method performs better than them.
BibTeX
@misc{lin2023improving,
  author = {Guoliang Lin and Hanjiang Lai and Yan Pan and Jian Yin},
  title = {{Improving Entropy-Based Test-Time Adaptation from a Clustering View}},
  year = {2023},
  eprint = {2310.20327},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2310.20327},
}
Figure