A PyTorch, MONAI, and NVFlare framework for privacy-preserving federated learning on the EMBED digital mammography dataset, supporting both breast lesion classification and conditional diffusion-based image synthesis.
The repository was developed to investigate whether locally generated synthetic mammograms can improve federated classification performance without requiring institutions to share patient data.
- π₯ Federated learning using NVFlare
- π©» Binary mammography classification (benign vs. malignant)
- π€ Conditional diffusion model for synthetic mammogram generation
- π§ Multiple classification architectures
- ConvNeXt Tiny
- ConvNeXt Small
- ConvNeXt Base
- Vision Transformer (ViT)
- Simple CNN baseline
- π Classifier-Free Guidance (CFG)
- π Composite diffusion loss combining
- Mean Squared Error (MSE)
- Structural Similarity (SSIM/MS-SSIM)
- High-frequency reconstruction loss
- π Automatic evaluation using
- Balanced Accuracy
- Sensitivity
- Specificity
- ROC AUC
- Frechet Inception Distance (FID)
- Structural Similarity Index (SSIM)
- π§ͺ Synthetic image generation for local data augmentation
.
βββ src/
β βββ client_classification.py # Federated classification client
β βββ client_synthesis.py # Conditional diffusion training client
β βββ generate_samples.py # Generate synthetic mammograms
β βββ job.py # Launch NVFlare experiments
β βββ model.py # Classification and diffusion models
β βββ losses.py # Composite diffusion losses
β βββ utils.py # Utility functions
β
βββ config.yml
βββ client_config_classification.yml
βββ client_config_synthesis.yml
βββ environment.yml
βββ submit_job.sh
βββ README.md
This repository contains two complementary learning pipelines.
Each participating institution trains a classification model using only its own mammograms while exchanging model parameters with a central server.
No patient images are shared during training.
The framework currently supports the FedAvg aggregation algorithm through NVFlare.
Global Model
β
βΌ
βββββββββββββββββββββββββββ
β NVFlare Server β
βββββββββββββββββββββββββββ
β β
βΌ βΌ
Client 1 Client 2 ...
β β
Local Training Local Training
β β
ββββββββ¬ββββ
βΌ
Federated Averaging
β
βΌ
Updated Global Model
Each client
- receives the latest global model
- trains locally
- evaluates on its own validation set
- returns updated model parameters
The repository also includes a conditional diffusion model capable of generating realistic 2D mammography images conditioned on lesion class.
The diffusion model can be trained independently from the classifier and later used to generate synthetic mammograms for local augmentation.
Features include
- DDPM training
- classifier-free guidance
- conditional generation
- configurable conditioning strength
- automatic image sampling during training
Generated mammograms can be incorporated into the federated classification pipeline.
Selected clients automatically load synthetic images from disk and merge them with their local training datasets.
This allows experiments investigating whether locally generated synthetic data improves classification performance without sharing real patient data across institutions.
The framework is designed for the EMBED digital mammography dataset.
Images are expected to be organized into benign and malignant directories, for example
train/
benign/
malignant/
test/
benign/
malignant/
Each client receives only the subset of studies belonging to its institution.
Institution assignments are determined automatically using the metadata file specified in config.yml.
Implemented in
src/model.py
Supported architectures
| Model | Description |
|---|---|
| ConvNeXt Tiny | Default classification model |
| ConvNeXt Small | Larger ConvNeXt variant |
| ConvNeXt Base | Highest-capacity ConvNeXt model |
| Vision Transformer | MONAI Vision Transformer |
| SimpleNetwork | Small CNN baseline |
All ConvNeXt models are automatically adapted from RGB ImageNet weights to accept single-channel mammograms.
Image synthesis uses
- MONAI
DiffusionModelUNet - DDPM scheduler
- classifier-free guidance
The model learns to predict the diffusion noise added during forward diffusion and reconstruct clean mammograms through iterative denoising.
The synthesis model is optimized using a weighted composite objective
[ L = w_{MSE}L_{MSE} + w_{SSIM}L_{SSIM} + w_{HF}L_{HF} ]
where
- MSE supervises predicted diffusion noise
- SSIM/MS-SSIM preserves structural similarity
- High-frequency loss encourages preservation of fine anatomical detail
Loss weights are fully configurable through client_config_synthesis.yml.
Defines the overall federated experiment
- aggregation algorithm
- participating institutions
- communication rounds
- client training script
- model architecture
- dataset locations
- metadata file
Configures
- preprocessing
- augmentation
- optimizer
- loss
- model
- validation frequency
- personalization / fine-tuning
Configures
- diffusion scheduler
- optimizer
- composite loss
- classifier-free guidance
- sampling interval
- validation interval
- diffusion architecture
Configure
client_script: client_classification.pyand
model:
task: classificationThen launch
python src/job.py -c config.ymlThe launcher
- reads the experiment configuration,
- partitions the EMBED dataset according to institution,
- launches one NVFlare client per site,
- performs federated training using FedAvg.
Configure
client_script: client_synthesis.pyand
model:
task: synthesisThen run
python src/job.py -c config.ymlAlthough the same NVFlare infrastructure is used, diffusion experiments are typically trained on a single institution for one communication round.
After training a diffusion model
python src/generate_samples.py \
--client_site 1 \
--num_samples 500The script
- loads a trained diffusion checkpoint
- generates synthetic mammograms
- saves images as NIfTI files
- stores corresponding labels
- computes image quality metrics
Generated images are written to
generated_nifti-for-training/
These images can subsequently be used for federated classification experiments.
During federated training each client reports
- Balanced Accuracy
- Sensitivity
- Specificity
- ROC AUC
Generated images are evaluated using
Measures the similarity between the distribution of generated and real mammograms.
Lower values indicate better image quality.
Measures structural similarity between generated and real images.
Higher values indicate better reconstruction quality.
| File | Description |
|---|---|
src/job.py |
Launches federated learning simulations |
src/client_classification.py |
Federated classification client |
src/client_synthesis.py |
Conditional diffusion training client |
src/generate_samples.py |
Generates synthetic mammograms and evaluates image quality |
src/model.py |
Classification and diffusion architectures |
src/losses.py |
Composite diffusion loss functions |
src/utils.py |
Utility functions and preprocessing helpers |
Create the conda environment
conda env create -f environment.yml
conda activate <environment_name>Major packages include
- Python
- PyTorch
- MONAI
- NVFlare
- Torchvision
- TorchMetrics
- NumPy
- Pandas
- NiBabel
- Matplotlib
If you use this repository in your research, please cite the associated publication once available.
This project builds upon
- NVFlare for federated learning
- MONAI for medical imaging and diffusion models
- PyTorch for deep learning
- TorchMetrics for image quality evaluation
- Torchvision for pretrained classification backbones