Brain-MRI anomaly segmentation with diffusion repairs: model checkpoints
Checkpoints for the project Unsupervised brain MRI anomaly segmentation with diffusion repairs: scoring recipe, repair spread and synthetic lesions.
A generative model is trained on healthy brain T1 scans only. At test time a scan is noised and repaired; the voxels where the repair differs from the input are scored as anomalous (SSIM residual, brain mask, 3D median filter). The models here are the generators; the scoring and evaluation code is in the GitHub repository.
- Code, configs, reproduction instructions: https://github.com/Topics-in-AI-for-Healthcare-2K26/Uncertainty-aware-refinement-for-unsupervised-anomaly-detection-in-brain-MRI
- Report: see the GitHub repository (link in its README)
Files
Every model is stored at 1200, 1600 and 2000 training epochs (<model>/<N>ep/). The 1200-epoch files are the best-validation-loss checkpoint of the original 1200-epoch recipe (epoch 1111 for the plain cDDPM, 1182 for cDDPM + lesions, 1197 for the bridges); the 1600 and 2000 files are the checkpoints at the end of those epochs of the continued runs.
| Folder | Model | Parameters | Size per file |
|---|---|---|---|
cddpm_base/ |
conditional DDPM (OpenAI UNet + SparK ResNet-50 condition encoder), plain recipe of the SADM / Mahalanobis-UAD repository | 68.7 M | 275 MB |
cddpm_fake/ |
the same cDDPM trained with synthetic (pasted) lesions as extra supervision | 68.7 M | 275 MB |
sb_fake/ |
small Schroedinger-bridge generator trained with synthetic lesions | 7.3 M | 29 MB |
sb_noise/ |
the same bridge trained without synthetic lesions (control) | 7.3 M | 29 MB |
spark_encoder/ |
SparK masked-modelling ResNet-50, the initialisation of the cDDPM condition encoder (only needed to train a cDDPM) | 38.1 M | 152 MB |
SHA256SUMS lists the checksum of every file; manifest.json has epochs, step counts and sizes.
Training setup
- Data: IXI T1 scans of healthy subjects, fold 0 (
splits/IXI_train_fold0.csvin the GitHub repository). Crop 192x192x100 at 1 mm, resampled to 96x96x50 at 2 mm, intensities rescaled to 0-1 inside the brain mask. - 2D slices, batch 32 (16 x 2 gradient accumulation), Adam, learning rate 1e-4, fp16, seed 3141, 1000 diffusion steps, simplex noise.
- cDDPM: UNet predicts the clean image (L1 loss). Bridges: image-to-image, one or four sampling steps.
- Models marked fake see healthy slices with synthetic lesions pasted in (
src/models/DDPM_2D_Fake.py,SB_2D.pyin the repository). - One training run and one fold per model.
Results (Dice %, threshold chosen on a BraTS validation split)
Mean over test scans; bridges with one sampling step. Dice at 1200 epochs, then at 2000 epochs.
| Model | BraTS21 (1151 scans) | ATLAS v2 (480) | WMH (45) |
|---|---|---|---|
| cDDPM base | 56.9 -> 58.9 | 20.5 -> 24.1 | 17.0 -> 18.1 |
| cDDPM + synthetic lesions | 58.7 -> 60.5 | 34.7 -> 36.0 | 18.9 -> 18.8 |
| SB-fake | 61.9 -> 61.3 | 28.6 -> 34.6 | 11.2 -> 14.9 |
| SB-noise | 46.7 -> 48.6 | 13.4 -> 15.7 | 14.7 -> 16.8 |
Paired per-scan differences with confidence intervals and all other metrics (Best Dice, AUPRC, MSSEG-2016 multi-rater) are in the report. Synthetic-lesion training, not the bridge formulation, is the main driver of the gains.
How to use
The files are plain dictionaries (state_dict, epoch, global_step, pytorch-lightning_version) and load with weights_only=True. Optimizer state and training hyperparameters were removed, so these files are for inference and evaluation, not for resuming training.
import torch
from huggingface_hub import hf_hub_download
path = hf_hub_download("Mohith202/brain-mri-uad-diffusion-repair",
"cddpm_fake/2000ep/epoch-1999_step-23999_loss-0.00_fold-1.ckpt")
state = torch.load(path, map_location="cpu", weights_only=True)["state_dict"]
# build the model with the Hydra config of the GitHub repository, then:
# model.load_state_dict(state, strict=True)
To evaluate with the repository's pipeline, download the models into run folders and call run.py (the helper code/scripts/hf_release/download_checkpoints.py does the layout):
python code/scripts/hf_release/download_checkpoints.py --out $LOG_DIR # four 2000-epoch models
cd code/diffusion_uad
# cDDPM, mean of 10 repairs
python run.py experiment=MHD/cDDPM_MHD load_checkpoint=$LOG_DIR/cddpm_fake_2000ep num_folds=1 \
+model.cfg.num_mc_samples=10 datamodule.cfg.mode=t1 "datamodule.cfg.testsets=[Datamodules_eval.Brats21]" \
+model.cfg.score_mode=ssim +model.cfg.median_final=True model.cfg.saveOutputImages=False
# bridge, one sampling step
python run.py experiment=SB/SB_eval load_checkpoint=$LOG_DIR/sb_fake_2000ep model.cfg.sb_variant=fake \
model.cfg.sb_nfe=1 +model.cfg.num_mc_samples=1 datamodule.cfg.mode=t1 "datamodule.cfg.testsets=[Datamodules_eval.Brats21]" \
+model.cfg.score_mode=ssim +model.cfg.median_final=True model.cfg.saveOutputImages=False
Data
The models were trained on IXI only. Test sets (not redistributed here; obtain them from the original sources):
- IXI (training, healthy T1): https://brain-development.org/ixi-dataset/
- BraTS21 (brain tumours): http://braintumorsegmentation.org/
- ATLAS v2 (stroke): https://fcon_1000.projects.nitrc.org/indi/retro/atlas.html
- MSLUB (multiple sclerosis): https://lit.fe.uni-lj.si/en/research/resources/3D-MR-MS/
- WMH (white-matter hyperintensities): https://dataverse.nl/dataset.xhtml?persistentId=doi:10.34894/AECRSD
- Preprocessed copies used by the upstream code base: see the data section of the GitHub repository.
Limitations and intended use
Research use only; not a medical device and not validated for clinical decisions. T1 only. One training run and one fold per model, so small differences (about 0.3 Dice between seeds of the plain cDDPM) should not be over-read. Scores on MS lesions (MSLUB, MSSEG-2016) are low for every model because T1 images show those lesions poorly. WMH has only 45 scans.
Acknowledgements and licence
The cDDPM pipeline and scoring follow Behrendt et al., Leveraging the Mahalanobis Distance to enhance Unsupervised Brain MRI Anomaly Detection, MICCAI 2024 (https://arxiv.org/abs/2407.12474), whose code base this project extends. The training data (IXI) is released under CC BY-SA 3.0, and the weights are released under the same licence.