ConDiSR: Contrastive Disentanglement and Style Regularization for Single Domain Generalization

Aleksandr Matsun, Numan Saeed, Fadillah Adamsyah Maani, Mohammad Yaqub

TL;DR

ConDiSR introduces a novel Single Domain Generalization (SDG) framework for medical image classification that effectively separates an image's structural content from its style (such as staining or scanner variations). By combining channel-wise contrastive disentanglement with low-resolution image reconstruction as a style regularizer, it achieves state-of-the-art generalization performance on unseen medical centers without requiring dense segmentation masks.

What Problem Does This Paper Address?

Deep learning models deployed in clinical settings frequently suffer from performance drops due to distribution shifts. A model trained on histopathology slides or fundus images from one hospital often fails when tested at another because of variations in scanner equipment, staining protocols, and patient demographics.

Domain Generalization (DG) techniques attempt to mitigate this, but they typically require training data from multiple institutions. In the real world, strict medical privacy regulations make aggregating multi-center datasets incredibly difficult. This leaves us with Single Domain Generalization (SDG)—training a model on data from just one source domain so that it generalizes to any unseen target domain.

While recent SDG methods successfully disentangle "style" from "structure" for image segmentation tasks, they fail when applied to classification. Segmentation provides dense, pixel-level ground truth masks that naturally guide structural learning. Classification, by contrast, provides only a single scalar label per image, giving the model far less structural information to work with and causing standard disentanglement methods to fall short.

Methods

To bridge this gap, the authors propose ConDiSR (Contrastive Disentanglement and Style Regularization). The architecture consists of three main components:

  1. Feature Disentanglement Module (FDM): This module takes an input image and extracts shallow-level feature maps. It introduces a learnable parameter ($\theta_d$) that acts as a switchboard, routing specific feature channels into either "structure-rich" ($f_{str}$) or "style-rich" ($f_{sty}$) pathways using a low-temperature channel-wise softmax.
  2. Contrastive Disentanglement Loss: During training, the original image undergoes two distinct style-altering augmentations (Bezier curve transformations and low-frequency component replacement) that preserve the underlying anatomy. A contrastive loss forces the structure features ($f_{str}$) of all three views to remain identical, while driving the style features ($f_{sty}$) apart.
  3. Reconstruction-Based Style Regularization: To ensure the style pathway doesn't accidentally capture structural details, $f_{sty}$ is fed into a decoder network tasked with reconstructing a downsampled version of the input image.
Figure 1. Overview of the proposed method. The feature disentanglement module (FDM) processes the original and augmented images to produce structure-related features (fstr) and style-related features (fsty). The structure-related features (fstr) are passed further to the classification network (FC) for computing the classification loss, while the style-related ones (fsty) go through the reconstruction network (FR) for further computation of the reconstruction loss. Additionally a contrastive loss is applied to minimize the distance between similar structure-related components and maximize the distance between different style-related components.
Figure 2. Overview of the feature disentanglement module of the network. Here σ represents the softmax operator, applied across the channel-related dimension of the parameter θd

Datasets

The authors evaluated ConDiSR on two distinct medical imaging modalities:

  • Camelyon17-WILDS: A binary classification dataset containing breast cancer whole-slide histopathology patches collected from five distinct medical centers.
  • Diabetic Retinopathy (DR) Grading: A multi-class classification task evaluated using a combination of four independent fundus image datasets: Aptos, EyePACS, Messidor, and Messidor2.

Key Insights and Ideas

  • The Downsampling Trick: Reconstructing a full-resolution image forces the style encoder to retain high-frequency structural details to minimize pixel loss. By forcing the network to reconstruct a downscaled target, the task acts as a natural low-pass filter, ensuring $f_{sty}$ discards fine structural lines and focuses purely on global style/texture.
  • Classification Needs Explicit Regularization: In classification tasks, extensive data augmentation alone drives a lot of baseline performance. However, ConDiSR proves that explicitly regularizing the latent space to separate style from structure yields significantly more stable and robust representations across completely unseen domains.

Key Results

ConDiSR consistently outperformed Empirical Risk Minimization (ERM) and the previous state-of-the-art baseline ($C^2$SDG) across both datasets:

  • Camelyon17-WILDS (SDG): ConDiSR improved target domain accuracy by 1–2% on average while demonstrating much lower performance variance across runs. Notably, when Center 3 was the source domain, target accuracy on the notoriously difficult Center 4 jumped from 59.8% ($C^2$SDG) to 71.2%.
  • Multi-Source Domain Generalization (MSDG): Even though it was designed for single-source scenarios, ConDiSR excelled when evaluated in a multi-source setting, achieving an average accuracy of 92.8% on Camelyon17, which corresponds to an approximate 20% classification error reduction over baselines.
  • Qualitative Interpretability: Grad-CAM visualizations confirmed that ConDiSR pays significantly more attention to semantically relevant tumor regions, closely matching the actual tumor presence masks, whereas competing methods often got distracted by background tissue styles.
Grad-CAM activation maps demonstrating that ConDiSR focuses more accurately on semantically important tumor regions compared to C2SDG.

Limitations and Future Work

The primary limitation highlighted in the paper is the sensitivity to the target reconstruction resolution. The authors found a "Goldilocks zone" at $48 \times 48$ pixels. Reconstructing at full resolution ($96 \times 96$) leaks structural data into the style features, while downsampling too far ($24 \times 24$) makes the decoder network too shallow to provide meaningful gradients for feature learning.

For future work, the authors suggest exploring the generalizability of ConDiSR on non-medical image classification benchmarks and expanding the framework to handle more diverse imaging modalities.

Summary updated

BibTeX
@inproceedings{matsun2025condisr,
  author = {Aleksandr Matsun and Numan Saeed and Fadillah Adamsyah Maani and Mohammad Yaqub},
  title = {{ConDiSR: Contrastive Disentanglement and Style Regularization for Single Domain Generalization}},
  booktitle = {IEEE/CVF Winter Conference on Applications of Computer Vision},
  year = {2025},
  doi = {10.1109/wacv61041.2025.00285},
}
Figure