MedSymmFlow: Bridging Generative Modeling and Classification in Medical Imaging through Symmetrical Flow Matching

1Eindhoven University of Technology

DGM4MICCAI 2025 Workshop

description of what image is showing.

The top row shows how an image is generated from noise via forward integration, while the bottom row illustrates how semantic labels are predicted through reverse-time integration.

Abstract

Reliable medical image classification requires accurate predictions and well-calibrated uncertainty estimates, especially in high-stakes clinical settings. This work presents MedSymmFlow, a generative-discriminative hybrid model built on Symmetrical Flow Matching, designed to unify classification, generation, and uncertainty quantification in medical imaging.

MedSymmFlow leverages a latent-space formulation that scales to high-resolution inputs and introduces a semantic mask conditioning mechanism to enhance diagnostic relevance. Unlike standard discriminative models, it naturally estimates uncertainty through its generative sampling process. The model is evaluated on four MedMNIST datasets, covering a range of modalities and pathologies. The results show that MedSymmFlow matches or exceeds the performance of established baselines in classification accuracy and AUC, while also delivering reliable uncertainty estimates validated by performance improvements under selective prediction.

MedSymmFlow

MedSymmFlow introduces a symmetrical flow-matching framework for joint semantic image synthesis and classification. It models bidirectional transformations between an image X and its semantic representation Y by learning a joint velocity field that drives both forward (from semantic input to image) and reverse (from image to semantic prediction) flows. This allows the model to treat both generation and prediction as a continuous integration process over time, unifying the tasks within a single dynamic system.


Semantic Conditioning via RGB Masks

Instead of using one-hot or grayscale class labels, MedSymmFlow adopts an RGB encoding scheme, where each class is assigned a unique RGB triplet. During training, these RGB labels are perturbed with small uniform noise to make the conditioning space continuous, allowing for more expressive flow matching. The model learns to transport these RGB-coded semantic targets across time alongside the image.

At inference time, the predicted semantic output lies in a continuous RGB space. To assign a class label, the model compares the output against the set of predefined RGB codes using Euclidean distance and selects the closest match. This process not only yields a hard classification label but also provides a measure of uncertainty based on the distance from the predicted color to the nearest class prototype.


Latent-Space Implementation

To handle high-resolution medical images (up to 224×224 pixels), MedSymmFlow operates in a compressed latent space. It leverages the encoder and decoder from the Stable Diffusion Variational Autoencoder (VAE), reducing the dimensionality of both the input image and its RGB mask. These latent representations are then processed by the model, enabling efficient training and inference while preserving semantic fidelity.

After semantic prediction in latent space, the result is decoded back into the RGB domain using the VAE decoder. This design allows the model to scale to complex medical datasets while maintaining high generation quality and segmentation accuracy.


Quantitative Results

Table 1 presents classification results across four MedMNIST datasets. At a resolution of 28×28 pixels, the original SymmFlow framework—using grayscale masks—performs reasonably well on PneumoniaMNIST and BloodMNIST, but drops significantly in performance on DermaMNIST and RetinaMNIST. This is particularly evident in the AUC scores, and stems from a core limitation: grayscale encoding compresses all semantic class information along a single axis, limiting the model’s ability to capture complex multi-class relationships.

Table 1 – Performance comparison (AUC / Accuracy) across four MedMNIST datasets. MSF and LatMSF are compared with CNN, ViT, and AutoML baselines.
Model PneumMNIST BloodMNIST DermaMNIST RetinaMNIST
AUCACC AUCACC AUCACC AUCACC
ResNet-18 (28)94.485.499.895.891.773.571.752.4
ResNet-50 (28)94.885.499.795.691.373.572.652.8
auto-sklearn (28)94.285.598.487.890.271.969.051.5
AutoKeras (28)94.787.899.896.191.574.971.950.3
ResNet-18 (224)95.686.499.896.392.075.471.049.3
ResNet-50 (224)96.288.499.795.091.273.171.651.1
MedViT-S (224)99.596.199.795.193.778.077.356.1
SymmFlow (28)91.6 ± 0.889.4 ± 0.599.1 ± 0.196.3 ± 0.283.4 ± 0.669.3 ± 0.570.2 ± 1.150.7 ± 0.7
MSF (Ours) (28)95.2 ± 0.488.0 ± 0.699.4 ± 0.197.9 ± 0.289.6 ± 0.578.8 ± 0.873.1 ± 0.451.4 ± 2.1
LatMSF (Ours) (224)94.4 ± 1.789.4 ± 1.199.8 ± 0.099.0 ± 0.192.5 ± 0.481.0 ± 0.678.8 ± 0.454.0 ± 0.9

RGB mask conditioning in MedSymmFlow directly resolves this limitation. By mapping class information into structured RGB vectors, the model can distinguish categories more effectively, which leads to clear gains in both AUC and classification accuracy—especially in datasets like DermaMNIST where fine-grained class separability is critical.

Extending this approach to latent space via LatMSF amplifies these benefits. The model consistently matches or outperforms ViT-based classifiers, while outperforming all CNN and AutoML baselines across multiple tasks. The one exception is PneumoniaMNIST, where performance drops—likely due to the fixed VAE encoder failing to preserve key discriminative cues.

While LatMSF achieves top-tier results, this comes at the cost of increased inference time and memory usage, driven primarily by VAE sampling and decoding overhead. Addressing this trade-off will be a focus of future optimization efforts.

Uncertainty Quantification

Figure below illustrates that for both the low- and high-resolution variants, confidence correlates with accuracy—indicating that the proposed distance-based uncertainty proxy is well calibrated and can be used to reject low-quality predictions. When the most uncertain predictions are removed, classification accuracy improves consistently across datasets, demonstrating that the model is capable of accurately assessing its own prediction reliability.

This behavior is particularly useful in high-stakes settings such as medical imaging, where abstaining from uncertain predictions is preferable to making incorrect confident ones. The effect is most pronounced in PneumoniaMNIST and RetinaMNIST. However, overfiltering begins to harm performance in DermaMNIST at higher resolution, as some confident and correct predictions are also discarded. BloodMNIST shows minimal impact, as accuracy is already high without uncertainty-based filtering.

description of what image is showing.

Filtering uncertain predictions improves accuracy, confirming that the distance-based uncertainty measure is well calibrated.

Qualitative Results

The figure below presents high-resolution samples generated using the latent-space variant of MedSymmFlow. These outputs demonstrate strong visual fidelity across multiple datasets. Notably, the model accurately captures fine-grained semantic features such as skin texture and hair artifacts in DermaMNIST, as well as retinal vessel structure and lesion contrast in RetinaMNIST. This indicates that the model not only classifies effectively, but also learns a semantically grounded, dataset-specific representation capable of producing realistic, diverse samples that reflect both anatomical structure and pathological variation.

description of what image is showing.

Samples generated by the latent models trained on the four selected MedMNIST datasets, using an Euler ODE solver with 25 steps.

BibTeX

@misc{caetano2025medsymmflow,
      title={MedSymmFlow: Bridging Generative Modeling and Classification in Medical Imaging through Symmetrical Flow Matching}, 
      author={Francisco Caetano and Lemar Abdi and Christiaan Viviers and Amaan Valiuddin and Fons van der Sommen},
      year={2025},
      eprint={2507.19098},
      archivePrefix={arXiv},
      primaryClass={cs.CV},
      url={https://arxiv.org/abs/2507.19098},
    }