Skip to content

JuliaWolleb/diffusion-anomaly

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Diffusion Models for Medical Anomaly Detection

We provide the Pytorch implementation of our MICCAI 2022 submission "Diffusion Models for Medical Anomaly Detection" (paper 704).

The implementation of Denoising Diffusion Probabilistic Models presented in the paper is based on openai/guided-diffusion.

Data

We evaluated our method on the BRATS2020 dataset, and on the CheXpert dataset. A mini-example how the data needs to be stored can be found in the folder data. To train or evaluate on the desired dataset, set --dataset brats or --dataset chexpert respectively.

Usage

We set the flags as follows:

MODEL_FLAGS="--image_size 256 --num_channels 128 --class_cond True --num_res_blocks 2 --num_heads 1 --learn_sigma True --use_scale_shift_norm False --attention_resolutions 16"
DIFFUSION_FLAGS="--diffusion_steps 1000 --noise_schedule linear --rescale_learned_sigmas False --rescale_timesteps False"
TRAIN_FLAGS="--lr 1e-4 --batch_size 10"
CLASSIFIER_FLAGS="--image_size 256 --classifier_attention_resolutions 32,16,8 --classifier_depth 4 --classifier_width 32 --classifier_pool attention --classifier_resblock_updown True --classifier_use_scale_shift_norm True"
SAMPLE_FLAGS="--batch_size 1 --num_samples 1 --timestep_respacing ddim1000 --use_ddim True"

To train the classification model, run

python scripts/classifier_train.py --data_dir path_to_traindata --dataset brats_or_chexpert $TRAIN_FLAGS $CLASSIFIER_FLAGS

To train the diffusion model, run

python scripts/image_train.py --data_dir --data_dir path_to_traindata --datasaet brats_or_chexpert  $MODEL_FLAGS $DIFFUSION_FLAGS $TRAIN_FLAGS

The model will be saved in the results folder.

For image-to-image translation to a healthy subject on the test set, run

python scripts/classifier_sample_known.py  --data_dir path_to_testdata  --model_path ./results/model.pt --classifier_path ./results/classifier.pt --dataset brats_or_chexpert --classifier_scale 100 --noise_level 500 $MODEL_FLAGS $DIFFUSION_FLAGS $CLASSIFIER_FLAGS  $SAMPLE_FLAGS 

A visualization of the sampling process is done using Visdom.

Comparing Methods

FixedPoint-GAN

We follow the implementation given in this repo. We choose λcls=1, λgpidrec=10, and train our model for 150 epochs. The batch size is set to 10, and the learning rate to 10-4.

VAE

We follow the implementation given in this repo and train the model for 500 epochs. The batch size is set to 10, and the learning rate to 10-4.

DDPM

For sampling using the DDPM approach, run

python scripts/classifier_sample_known.py  --data_dir path_to_testdata  --model_path ./results/model.pt --classifier_path ./results/classifier.pt  --dataset brats_or_chexpert --classifier_scale 100 --noise_level 500 $MODEL_FLAGS $DIFFUSION_FLAGS $CLASSIFIER_FLAGS 

About

Anomaly detection with diffusion models

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages