Counterfactual Contrastive Learning: Robust Representations via Causal Image Synthesis

Mélanie Roschewitz, Fabio De Sousa Ribeiro, Tian Xia, Galvin Khara, Ben Glocker

TL;DR

CF-SimCLR improves medical image representation learning by using causal generative models to synthesize "what-if" counterfactual images—such as a chest X-ray re-imagined as if it were taken on a different scanner. By using these counterfactuals as positive pairs in a contrastive learning framework, the model learns to ignore scanner-specific artifacts, significantly boosting robustness to domain shifts and performance on under-represented data.

What Problem Does This Paper Address?

Self-supervised contrastive learning (like SimCLR) has revolutionized medical imaging by allowing models to learn from vast amounts of unlabelled data. However, these models are notoriously sensitive to their "augmentation pipeline"—the set of transformations used to create different views of the same image.

Standard augmentations (like random cropping or color jittering) were designed for natural images (cats, dogs, cars) and often fail to capture the complex "acquisition shifts" found in medicine. In a clinical setting, images of the same patient can look vastly different depending on the scanner manufacturer or settings used. If a model isn't taught to ignore these scanner-specific features, it may overfit to them, leading to poor performance when deployed at a new hospital with different equipment.

Methods

The authors propose CF-SimCLR (Counterfactual SimCLR). The core innovation is replacing or supplementing standard random augmentations with realistic, synthesized domain changes.

  1. Counterfactual Generation: The authors train a Deep Structural Causal Model (DSCM) using Hierarchical Variational Autoencoders (HVAE). This model allows them to perform a "do-intervention" on the scanner variable. Essentially, they take a real image, encode it, and then decode it while specifying a different scanner ID. This produces a counterfactual image that preserves the patient's anatomy (the "semantic information") but changes the acquisition style (the "domain information").
  2. Contrastive Learning Strategy: In standard SimCLR, two random augmentations of the same image form a positive pair. In CF-SimCLR, a real image and its generated counterfactual (from a different scanner) are paired. This forces the encoder to map both images to the same point in representation space, effectively teaching it to be invariant to scanner differences.
Summary of the three contrastive learning strategies: SimCLR, SimCLR+, and the proposed CF-SimCLR.

The authors also compare this to SimCLR+, where counterfactual images are simply added to the training set as independent samples rather than being explicitly paired with their real counterparts.

Datasets

The approach was validated across two major modalities and five datasets:

  • Chest Radiography:
    • PadChest: Used for pretraining and in-distribution (ID) evaluation (contains scans from two different scanners).
  • RSNA Pneumonia & CheXpert: Used for out-of-distribution (OOD) transfer evaluation.
  • Mammography:
    • EMBED: A large dataset from five different scanners used for pretraining.
  • VinDR-Mammo: Used for OOD evaluation, featuring scanners from a completely different geographical region (Vietnam).

Key Insights and Ideas

  • Explicit Pairing is Crucial: The results show that simply having more diverse data (SimCLR+) isn't enough. The "aha moment" is that the model must be explicitly told that the real image and its counterfactual are the same thing via the contrastive loss to achieve true domain invariance.
  • Causal Realism: Unlike simple photometric augmentations (brightness/contrast), the counterfactual model learns to handle complex artifacts. For example, it correctly learns to add or remove imprinted text that only appears on specific scanner brands.
  • Domain Alignment: Visualizing the embeddings via t-SNE (Figure 5) reveals that standard SimCLR creates clusters based on the scanner used. CF-SimCLR embeddings are much more mixed, indicating the model has successfully learned to ignore the acquisition device.
Examples of generated counterfactuals for both mammography (EMBED) and chest X-rays (PadChest).

Key Results

  • Superior Robustness: CF-SimCLR consistently outperformed standard SimCLR and SimCLR+ across all datasets, especially in OOD scenarios.
  • Gains in Data Scarcity: The performance boost was most significant when labeled data was limited (e.g., <20k labels for mammography).
  • Under-represented Scanners: For scanners that made up less than 5% of the training data, CF-SimCLR provided a substantial performance jump, effectively "leveling the playing field" for rare domains.
  • Computational Efficiency: Despite the complexity of the generative model, the authors noted it is relatively lightweight, capable of generating over 1 million images in less than 7 hours on a single consumer-grade GPU (NVIDIA 3090).

Limitations and Future Work

  • Causal Graph Dependency: The method requires a predefined causal graph. While "scanner" is a straightforward variable to intervene on, other domain shifts might be harder to model.
  • Scope of Interventions: This study focused primarily on acquisition shifts. The authors suggest that future work could extend this to other types of dataset shifts, such as enforcing invariance across different patient subgroups to improve algorithmic fairness.
  • Generative Quality: While the HVAE-based DSCM is efficient, the quality of the counterfactuals still limits the upper bound of the encoder's performance. Improvements in high-resolution medical image synthesis will likely translate directly to better CF-SimCLR results.

Summary updated

BibTeX
@inproceedings{roschewitz2024counterfactual,
  author = {Mélanie Roschewitz and Fabio De Sousa Ribeiro and Tian Xia and Galvin Khara and Ben Glocker},
  title = {{Counterfactual Contrastive Learning: Robust Representations via Causal Image Synthesis}},
  booktitle = {DEMI @ MICCAI},
  year = {2024},
  doi = {10.1007/978-3-031-73748-0\_3},
}
Figure