Domain Generalization via Contrastive Causal Learning

Qiaowei Miao, Junkun Yuan, Kun KuangarXiv 2022

Abstract

Domain Generalization (DG) aims to learn a model that can generalize well to unseen target domains from a set of source domains. With the idea of invariant causal mechanism, a lot of efforts have been put into learning robust causal effects which are determined by the object yet insensitive to the domain changes. Despite the invariance of causal effects, they are difficult to be quantified and optimized. Inspired by the ability that humans adapt to new environments by prior knowledge, we develop a novel Contrastive Causal Model (CCM) to transfer unseen images to taught knowledge which are the features of seen images, and quantify the causal effects based on taught knowledge. CCM controls the domain factor to cut off excess causal paths and uses the remaining part to calculate the causal effects of images to labels via the front-door criterion. Specifically, CCM is composed of three components: (i) domain-conditioned supervised learning, (ii) causal effect learning, and (iii) contrastive similarity learning. Extensive experiments on datasets including PACS, OfficeHome, and TerraIncognita demonstrate that CCM surpasses previous DG methods with clear margins.

Introduction

Deep learning models are notoriously "brittle" when faced with out-of-distribution data. A common failure mode is the reliance on spurious correlations—for instance, a model might identify a cow based on a background of green grass rather than the animal's features. Domain Generalization (DG) seeks to address this by training models on multiple source domains (e.g., photos, sketches, cartoons) to ensure robust performance on unseen target domains.

While many researchers attempt to find "invariant" features, quantifying and optimizing these causal relationships is mathematically challenging. This paper introduces the Contrastive Causal Model (CCM), which explicitly measures and maximizes the true causal effect of an image on its label by leveraging causal inference and contrastive learning.

Methodology

The CCM framework is built upon three primary pillars designed to isolate the causal relationship between objects and labels from environmental noise.

1. Causal Graph and the Front-Door Criterion

The authors propose a causal graph where the Domain ($D$) acts as a confounder influencing both the Environment ($E$) (backgrounds) and the Object ($O$). To block the influence of the domain without direct intervention, CCM utilizes the front-door criterion. By introducing an intermediate variable ($Z$)—the extracted image features—the model can mathematically calculate the causal effect of the image on the label while ignoring domain-driven spurious correlations.

2. Model Architecture

CCM implements this causal logic through a teacher-student framework. It maintains a "knowledge queue" of features from previous training steps, forcing the model to cluster similar objects regardless of their domain of origin.

The architecture of the Contrastive Causal Model (CCM), highlighting the front-door adjustment path and the contrastive similarity learning components.

3. Loss Functions

The model is optimized using a composite loss function:

  • $L_{teach}$: Domain-conditioned supervised learning that establishes basic correlations.
  • $L_{learn}$: Causal effect learning based on the front-door criterion.
  • $L_{CS}$: Contrastive similarity learning to cluster features of the same class across domains.

Experimental Results and Analysis

CCM was evaluated on three standard DG benchmarks: PACS, OfficeHome, and TerraIncognita.

Performance Metrics

CCM achieved state-of-the-art (SOTA) performance across all benchmarks:

  • PACS: 87.0% average accuracy (surpassing SagNet's 86.3%).
  • OfficeHome: 69.7% (a 1.0% improvement over CORAL/Mixup).
  • TerraIncognita: 48.6% (outperforming SagNet by 0.9%).

Notably, CCM was the only model to exceed 80% accuracy across every test domain in the PACS dataset, demonstrating exceptional stability.

Feature Manifold Visualization

T-SNE visualizations reveal that CCM learns a more structured representation compared to standard Empirical Risk Minimization (ERM). Instead of simple clusters, CCM arranges features into distinct manifolds or "stripes," suggesting it captures a continuous representation of object identity that is invariant to style or domain shifts.

T-SNE visualizations comparing standard Empirical Risk Minimization (ERM) with the proposed CCM across different domains in the PACS dataset.

Conclusion

The Contrastive Causal Model (CCM) represents a significant step forward in Domain Generalization by moving from simple correlation to explicit causal inference. By applying the front-door criterion, the model successfully strips away domain-specific noise to focus on the stable relationship between objects and their labels. While the method relies on the accuracy of the underlying causal graph and introduces some computational overhead, its superior performance on out-of-distribution benchmarks highlights the potential of causal modeling in building robust AI systems.

Summary updated

BibTeX
@misc{miao2022domain,
  author = {Qiaowei Miao and Junkun Yuan and Kun Kuang},
  title = {{Domain Generalization via Contrastive Causal Learning}},
  year = {2022},
  eprint = {2210.02655},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2210.02655},
}
Figure