Context-Aware Self-Adaptation for Domain Generalization

Hao Yan, Yuhong Guo · DOI

TL;DR

This paper introduces Context-Aware Self-Adaptation (CASA), a novel two-stage method for domain generalization. CASA adapts pre-trained models to new domains using contextual information from mini-batches, while simultaneously preserving performance on original domains, and then ensembles these adapted models for improved generalization.

What Problem Does This Paper Address?

Deep learning models excel when training and testing data share the same distribution. However, in real-world scenarios, this is rarely the case, leading to performance degradation on unseen data. Domain generalization (DG) aims to train models that can generalize to new, unseen domains without requiring any data or fine-tuning from those target domains during training. This is a challenging problem because access to target domain data is often limited or unavailable, making it difficult to adapt models effectively. Existing DG methods often rely on data augmentation, learning domain-invariant features, or meta-learning, but there's still room for improvement, especially in how models adapt to new contexts while retaining knowledge from the source domains.

Methods

CASA employs a two-stage training approach:

  1. Meta-Source Model Training: In the first stage, models are trained on various "meta-source" domains derived from the available training data. This stage focuses on learning generalizable features.
  2. Context-Aware Self-Adaptation: The second stage introduces a novel "self-adaptation module" that sits between the feature extractor and classifier. This module is designed to adapt the pre-trained meta-source models to "meta-target" domains (also derived from the training data).
  3. Contextual Information: The key innovation here is the use of "contextual information," specifically the mean of mini-batch features, as a proxy for domain knowledge. This information helps the module understand the current domain context.
  4. CaFiLM Mechanism: To adapt features without drastically changing their representation space (which could harm generalization), CASA uses a "Context-Aware Feature-wise Linear Modulation" (CaFiLM) mechanism. CaFiLM learns dimension-specific weights and biases from the feature vector and the mini-batch mean to modulate the features.
  5. Dual Objective: The adaptation module is trained with two objectives: one to adapt to the meta-target domain (L_adapt) and another to preserve performance on the meta-source domain (L_preserve). This dual objective is crucial for maintaining generalization capabilities.
  6. Ensemble Inference: Finally, for testing, CASA enlists an ensemble of multiple adapted meta-source models. The predictions from these models are combined (e.g., by averaging probabilities) to produce the final output.

Datasets

The paper evaluates CASA on five standard domain generalization benchmarks:

  • PACS: Art, cartoons, photos, sketches.
  • VLCS: Caltech101, LabelMe, SUN09, VOC2007.
  • OfficeHome: Art, clipart, product, real-world images.
  • TerraIncognita: Wild animal images from different camera locations.
  • DomainNet: A large-scale dataset with diverse image domains.

Key Insights and Ideas

  • Context is King (for Adaptation): The paper strongly suggests that leveraging simple, readily available contextual information like mini-batch feature means is highly effective for adapting models to new domains. This is a more direct way to inform adaptation than just learning domain-invariant features.
  • Preserving Source Knowledge is Crucial: Simply adapting to a new domain can lead to "catastrophic forgetting" of what was learned from the source domains. CASA's dual objective (adapting to target, preserving source) is key to its success.
  • Feature Space Preservation Matters: The CaFiLM mechanism's ability to modulate features while keeping them in a similar vector space is highlighted as a critical factor for effective adaptation and generalization, distinguishing it from simpler MLP-based adaptation.
  • Ensembling Adds Robustness: While the self-adaptation module provides significant gains, the paper shows that ensembling multiple adapted models further boosts performance, leveraging the diversity of models trained on different meta-source domain combinations.

Key Results

  • CASA achieves state-of-the-art performance on several standard DG benchmarks, particularly on smaller datasets.
  • On average, CASA improves performance by 5.5 percentage points compared to the baseline ERM (Empirical Risk Minimization) approach.
  • The "Ensemble (Ours)" row shows that even a simple ensemble of meta-source models (without the adaptation module) provides a significant gain of 3.5 pp over ERM, highlighting the benefit of ensemble methods.
  • The self-adaptation module itself contributes an additional 2 pp improvement over the ensemble baseline.
  • Ablation studies confirm that both the adaptation training process and the use of context information are essential for CASA's performance. Replacing CaFiLM with a simple MLP leads to a performance decrease.

Limitations and Future Work

  • Computational Cost: While the CaFiLM module itself is lightweight (only 6 parameters), the overall two-stage training and ensemble inference can increase computational demands. The paper mentions fine-tuning the meta-source classifier for complex datasets, which adds to this.
  • Limited Source Domains: The paper notes that the approach works well with a limited number of ensemble entities, implying it's robust to fewer source domains than some ensemble methods. However, performance might still be sensitive to the diversity and representativeness of the initial source domains.
  • Future Directions: The paper doesn't explicitly detail future work, but potential avenues include exploring more sophisticated context representations beyond mini-batch means, investigating different ensemble strategies, and applying CASA to more complex real-world DG problems.

Summary updated

BibTeX
@misc{yan2023context,
  author = {Hao Yan and Yuhong Guo},
  title = {{Context-Aware Self-Adaptation for Domain Generalization}},
  year = {2023},
  eprint = {2504.03064},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2504.03064},
}
Figure