img-cond-diffusion-model-ad
Science Score: 54.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
✓Academic publication links
Links to: arxiv.org, sciencedirect.com, ieee.org -
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (11.2%) to scientific vocabulary
Repository
Basic Info
- Host: GitHub
- Owner: matt-baugh
- Language: Python
- Default Branch: main
- Size: 4.34 MB
Statistics
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
- Releases: 0
Metadata Files
README.md
Image-conditioned Diffusion Models for Medical Anomaly Detection
We integrate our method into the benchmark "Unsupervised Pathology Detection: A Deep Dive Into the State of the Art" to enable future development and comparisons.
Code for our method is inside UPD_study/models/ours/.
Usage
Download this repository by running
bash
git clone https://github.com/img-cond-diffusion-model-ad
in your terminal.
Environment
Create and activate the Anaconda environment:
bash
conda env create -f environment.yml
conda activate anomaly_restoration
Additionally, you need to install the repository as a package:
bash
python3 -m pip install --editable .
To be able to use Weights & Biases for logging follow the instructions at https://docs.wandb.ai/quickstart. <!-- A quick guide on the folder and code structure can be found here. -->
Data
DDR
To download and prepare the DDR dataset, run:
bash
bash UPD_study/data/data_preprocessing/prepare_DDR.sh
MRI: CamCAN, ATLAS, BraTS
To download and preprocess ATLAS and BraTS, first download ROBEX from https://www.nitrc.org/projects/robex and extract it in data/data_preprocessing/ROBEX. Then run:
bash
bash UPD_study/data/data_preprocessing/prepare_ATLAS.sh
bash UPD_study/data/data_preprocessing/prepare_BraTS.sh
For ATLAS you need to apply for the data at https://fcon1000.projects.nitrc.org/indi/retro/atlas.html and receive the encryption password. During the run of prepareATLAS.sh you will be prompted to input the password.
For BraTS, Kaggle's API will be used to download the data. To be able to interact with the API, follow the instructions at https://www.kaggle.com/docs/api.
To download the CamCAN data, you need to apply for it at https://camcan-archive.mrc-cbu.cam.ac.uk/dataaccess/index.php. After you download them, put them in data/datasets/MRI/CamCAN and run:
bash
python UPD_study/data/data_preprocessing/prepare_data.py --dataset CamCAN
Our experiments
We recommend using accellerate to train/evaluate models over multiple GPUs.
For any experiment, to select which image modality you use:
bash
--modality [MRI|RF]
Where MRI is for brain MRI and RF is for DDR.
To select which sequence of MRI you use:
bash
--sequence [t1|t2]
For evaluating the T1 model, on BraTS-T1 use --brats_t1=f while for ATLAS use --brats_t1=t.
In the following script examples I will denote the dataset choice as <DATASET_OPTIONS>
Training
To train a model on fold f \in [0,9], run:
bash
accelerate launch \
--num_processes=$num_processes --mixed_precision=fp16 \
./UPD_study/models/ours/ours_trainer.py \
--fold=$f <DATASET_OPTIONS>
Fold Evaluation
bash
accelerate launch \
--num_processes=$num_processes --mixed_precision=fp16 \
./UPD_study/models/ours/ours_trainer.py \
--fold=$f -ev=t <DATASET_OPTIONS>
Ensemble Evaluation
bash
accelerate launch \
--num_processes=$num_processes --mixed_precision=fp16 \
./UPD_study/models/ours/ours_ensemble.py \
--fold=$f -ev=t <DATASET_OPTIONS>
Original Benchmark Experiments
To generate the "Main Results" from Tables 1 and 3 over all three seeds run:
bash
bash UPD_study/experiments/main.sh
Alternatively, for a single seed run:
bash
bash UPD_study/experiments/main_seed10.sh
To generate the "Self-Supervised Pre-training" results from Tables 2 and 4 over all three seeds run:
bash
bash UPD_study/experiments/pretrained.sh
Alternatively, for a single seed run:
bash
bash UPD_study/experiments/pretrained_seed10.sh
To generate the "Complexity Analysis" results from Table 5 run:
bash
bash UPD_study/experiments/benchmarks.sh
To generate "The Effects of Limited Training Data" results from Fig. 3 run:
bash
bash UPD_study/experiments/percentage.sh
The repository contains PyTorch implementations for VAE, r-VAE, f-AnoGAN, H-TAE-S, FAE, PaDiM, CFLOW-AD, RD, ExpVAE, AMCons, PII, DAE and CutPaste.
Cite this work:
@InProceedings{baugh2024imageconditioned,
author="Baugh, Matthew
and Reynaud, Hadrien
and Marimont, Sergio Naval
and Cechnicka, Sarah
and M{\"u}ller, Johanna P.
and Tarroni, Giacomo
and Kainz, Bernhard",
title="Image-Conditioned Diffusion Models for Medical Anomaly Detection",
booktitle="Uncertainty for Safe Utilization of Machine Learning in Medical Imaging",
editor="Sudre, Carole H.
and Mehta, Raghav
and Ouyang, Cheng
and Qin, Chen
and Rakic, Marianne
and Wells, William M.",
year="2025",
publisher="Springer Nature Switzerland",
address="Cham",
pages="117--127",
isbn="978-3-031-73158-7"
}
Acknowledgements
(Some) HPC resources were provided by the Erlangen National High Performance Computing Center (NHR@FAU) of the Friedrich-Alexander-Universität Erlangen-Nürnberg (FAU) under the NHR projects b143dc and b180dc. NHR funding is provided by federal and Bavarian state authorities. NHR@FAU hardware is partially funded by the German Research Foundation (DFG) – 440719683.
Owner
- Name: Matthew Baugh
- Login: matt-baugh
- Kind: user
- Repositories: 4
- Profile: https://github.com/matt-baugh
Citation (CITATION.bib)
@InProceedings{baugh2024imageconditioned,
author="Baugh, Matthew
and Reynaud, Hadrien
and Marimont, Sergio Naval
and Cechnicka, Sarah
and M{\"u}ller, Johanna P.
and Tarroni, Giacomo
and Kainz, Bernhard",
title="Image-Conditioned Diffusion Models for Medical Anomaly Detection",
booktitle="Uncertainty for Safe Utilization of Machine Learning in Medical Imaging",
editor="Sudre, Carole H.
and Mehta, Raghav
and Ouyang, Cheng
and Qin, Chen
and Rakic, Marianne
and Wells, William M.",
year="2025",
publisher="Springer Nature Switzerland",
address="Cham",
pages="117--127",
isbn="978-3-031-73158-7"
}
GitHub Events
Total
- Watch event: 3
- Push event: 1
- Fork event: 1
Last Year
- Watch event: 3
- Push event: 1
- Fork event: 1
Dependencies
- accelerate ==0.25.0
- antlr4-python3-runtime ==4.9.3
- appdirs ==1.4.4
- austin-dist ==3.6.0
- beautifulsoup4 ==4.12.2
- bleach ==6.1.0
- certifi ==2023.11.17
- charset-normalizer ==3.3.2
- click ==8.1.7
- contourpy ==1.2.0
- cycler ==0.12.1
- diffusers ==0.24.0
- dipy ==1.7.0
- docker-pycreds ==0.4.0
- einops ==0.7.0
- filelock ==3.13.1
- fonttools ==4.46.0
- freia ==0.2
- fsspec ==2023.12.1
- gdown ==4.7.1
- gitdb ==4.0.11
- gitpython ==3.1.40
- h5py ==3.10.0
- huggingface-hub ==0.19.4
- idna ==3.6
- imageio ==2.33.0
- importlib-metadata ==7.0.0
- ipywidgets ==8.1.1
- jinja2 ==3.1.2
- joblib ==1.3.2
- jupyterlab-widgets ==3.0.9
- kaggle ==1.5.16
- kiwisolver ==1.4.5
- lazy-loader ==0.3
- markupsafe ==2.1.3
- matplotlib ==3.8.2
- mpmath ==1.3.0
- networkx ==3.2.1
- nibabel ==5.1.0
- numpy ==1.24.2
- nvidia-cublas-cu12 ==12.1.3.1
- nvidia-cuda-cupti-cu12 ==12.1.105
- nvidia-cuda-nvrtc-cu12 ==12.1.105
- nvidia-cuda-runtime-cu12 ==12.1.105
- nvidia-cudnn-cu12 ==8.9.2.26
- nvidia-cufft-cu12 ==11.0.2.54
- nvidia-curand-cu12 ==10.3.2.106
- nvidia-cusolver-cu12 ==11.4.5.107
- nvidia-cusparse-cu12 ==12.1.0.106
- nvidia-nccl-cu12 ==2.18.1
- nvidia-nvjitlink-cu12 ==12.3.101
- nvidia-nvtx-cu12 ==12.1.105
- omegaconf ==2.3.0
- pie-torch ==0.0.1
- pillow ==10.1.0
- protobuf ==4.25.1
- psutil ==5.9.6
- pycocotools ==2.0.7
- pyparsing ==3.1.1
- pysocks ==1.7.1
- python-slugify ==8.0.1
- pyyaml ==6.0.1
- regex ==2023.10.3
- requests ==2.31.0
- safetensors ==0.4.1
- scikit-image ==0.22.0
- scikit-learn ==1.3.2
- scipy ==1.11.4
- sentry-sdk ==1.38.0
- setproctitle ==1.3.3
- setuptools ==65.6.3
- simpleitk ==2.3.1
- smmap ==5.0.1
- snakeviz ==2.2.0
- soupsieve ==2.5
- sympy ==1.12
- text-unidecode ==1.3
- threadpoolctl ==3.2.0
- tifffile ==2023.9.26
- tokenizers ==0.15.0
- torch ==2.1.1
- torchgeometry ==0.1.2
- torchinfo ==1.8.0
- torchvision ==0.16.1
- tqdm ==4.65.0
- transformers ==4.36.0
- triton ==2.1.0
- typing-extensions ==4.8.0
- urllib3 ==2.1.0
- wandb ==0.16.1
- webencodings ==0.5.1
- widgetsnbextension ==4.0.9
- xformers ==0.0.23
- FrEIA ==0.2
- Pillow ==10.1.0
- dipy ==1.7.0
- einops ==0.7.0
- matplotlib ==3.8.2
- nibabel ==5.1.0
- numpy ==1.24.2
- pie-torch *
- pycocotools ==2.0.7
- scikit-image *
- scikit_learn ==1.3.2
- scipy ==1.11.4
- setuptools ==65.6.3
- simpleitk *
- tifffile ==2023.9.26
- torch ==2.1.1
- torchgeometry ==0.1.2
- torchinfo ==1.8.0
- torchvision ==0.16.1
- tqdm ==4.65.0
- transformers *
- wandb ==0.16.1