Improved Test-Time Adaptation for Domain Generalization

Liang Chen, Yong Zhang, Yibing Song, Ying Shan, Lingqiao Liu

TL;DR

ITTA (Improved Test-Time Adaptation) enhances domain generalization by introducing a learnable consistency loss that aligns auxiliary tasks with the main prediction goal. By updating only a small set of dedicated adaptive parameters during inference, the method avoids the performance degradation common in standard test-time training while achieving state-of-the-art results across major benchmarks.

What Problem Does This Paper Address?

Deep learning models are notoriously brittle when faced with distribution shift—where the data they see at test time (the "target domain") differs from what they were trained on (the "source domain"). Domain Generalization (DG) aims to build models that can handle these unseen environments.

A promising recent approach is Test-Time Training (TTT), where a model performs a quick "self-update" on a test sample before making a final prediction. However, TTT has two major pitfalls:

  1. Task Mismatch: Most TTT methods use heuristic auxiliary tasks (like predicting the rotation of an image). If this task doesn't align with the main classification goal, the update can actually make the model worse.
  2. Parameter Selection: It is unclear which parts of a massive neural network should be updated during a single test step. Updating everything often leads to "catastrophic forgetting" of the general features learned during training.

Methods

The authors propose ITTA, which tackles these issues through two core innovations:

1. Learnable Consistency Loss

Instead of a fixed auxiliary task, ITTA uses a consistency loss between an original feature and its augmented version. Crucially, this loss is passed through a weight subnetwork ($f_w$). During training, the authors use a gradient alignment strategy: they force the gradient of the consistency loss to point in the same direction as the gradient of the main classification loss. This ensures that when the model updates itself at test time to improve consistency, it is also implicitly improving its classification ability.

Figure 2. Training process of ITTA. We use x from the source domain as input for the feature extractor fθ(·) to obtain the repre- sentation z and its augmented version z′, where the augmentation skill from [75] is applied. The classifier fϕ(·) and weight subnet- work fw(·) are used to compute the main loss Lmain and learnable consistency loss Lwcont. Please refer to our text for details.

2. Dedicated Adaptive Parameters ($f_\Theta$)

Rather than risking the integrity of the pretrained backbone, ITTA introduces small, lightweight adaptive blocks after each major block of the feature extractor. During the test phase, the original model weights are frozen. Only these new $f_\Theta$ parameters are updated using the learned consistency loss. This provides a "safe space" for adaptation that doesn't corrupt the base model.

At test time, only the additional adaptive parameters are updated.

Datasets

The authors evaluated ITTA on five widely recognized DG benchmarks:

  • PACS: (Art, Cartoon, Photo, Sketch) - The primary benchmark for style shifts.
  • VLCS: (PASCAL VOC, LabelMe, Caltech, Sun) - Real-world image datasets.
  • OfficeHome: Artistic, Clipart, Product, and Real World office objects.
  • TerraInc: Photos of wild animals taken at different locations/times.
  • DomainNet: A massive dataset spanning 6 different styles and 345 classes.

All experiments followed the rigorous DomainBed evaluation protocol, using 60 trials with different random seeds to ensure statistical significance.

Key Insights and Ideas

  • Alignment is Everything: The authors use Grad-CAM to show that their learnable loss focuses on the same semantic regions (e.g., the head of a giraffe) as the main classification loss. Standard TTT tasks like rotation prediction often focus on irrelevant background features.
  • Isolation Prevents Degradation: By only updating the $f_\Theta$ blocks, the model gains the benefits of adaptation without the risk of "breaking" the well-trained feature extractor.
  • One Step is Enough: The authors found that a single SGD update at test time provides the best balance between accuracy and computational efficiency (~2.4ms per image).

Key Results

ITTA consistently outperformed 21 other state-of-the-art methods.

  • Multi-Source DG: ITTA achieved the highest average accuracy (60.2%) across all five datasets, outperforming strong baselines like ERM (58.1%) and SWAD (SD).
  • Single-Source DG: On the PACS dataset, ITTA reached 68.4% average accuracy, a significant jump over the next best method, MixStyle (66.3%), and the standard ERM (65.0%).
Table 1. Multi sources domain generalization. Experiments are conducted on the DomainBed benchmark [27]. All methods are examined for 60 trials in each unseen domain. Top5 accumulates the number of datasets where a method achieves the top 5 performances. The score here accumulates the numbers of the dataset where a specific art obtains larger accuracy than ERM on account of the variance. Best results are colored as red. Among the 22 methods compared, less than a quarter outperforms ERM in most datasets (Score ≥3).

The ablation study in Figure 1 highlights that both the learnable loss and the adaptive parameters are critical for these gains: Ablation study showing the incremental benefits of the learnable loss and adaptive parameters.

Figure 1. Performance improvements from the proposed two strate- gies (i.e. introducing a learnable consistency loss and including additional adaptive parameters to improve TTT) for the baseline model (i.e. ResNet18 [30] with existing augmentation strategy [75]). Experiments are conducted on the PACS dataset [37] with the leave- one-out setting. Following [27], we use 60 sets of random seeds and hyper-parameters for each target domain. The reported average accuracy and error bars verify the effectiveness of our method.

Limitations and Future Work

  • Training Complexity: Aligning gradients requires calculating second-order derivatives (Hessian-vector products) during the training phase, which increases the computational burden and memory usage during model development.
  • Inference Overhead: While small (2.4ms), the requirement for a forward and backward pass for every test sample might be a bottleneck for extremely high-throughput real-time systems.
  • Future Directions: The authors suggest simplifying the optimization process to reduce training costs and exploring more efficient ways to implement the adaptive blocks.

Summary updated

BibTeX
@misc{chen2023improved,
  author = {Liang Chen and Yong Zhang and Yibing Song and Ying Shan and Lingqiao Liu},
  title = {{Improved Test-Time Adaptation for Domain Generalization}},
  year = {2023},
  eprint = {2304.04494},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2304.04494},
}
Figure