This repository contains the code for "Ordinal Diffusion Models for Fundus Images".
Set up a python environment with a python version 3.11. Then, download the repository, activate the environment and install all other dependencies with
cd OrdinalDiffusionModels
pip install -e .Model weights can be downloaded using the download_model_weights.py script.
python download_model_weights.py --model xxwhere xx is the model variant to be downloaded:
- baseline w/o structure: xx = base
- baseline w/ structure: xx = basestruct
- equidistant w/o structure: xx = equi
- equidistant w/ structure: xx = equistruct
- learned w/o structure: xx = learn
- learned w/ structure: xx = learnstruct
- all models: xx = all
For generating new images, download the model weights and run:
python generate_images.py --model xx --num_images_per_class 100 --out_dir out/where xx is as above and out_dir the directory where the images are saved.
To train a diffusion model, configure the training parameters in configs/diffusion.yaml. The key options are:
- Model type
equi: Trueβ train the equidistant modellearned: Trueβ train the learned model
- Structural information
structure: Trueβ include structural informationstructure: Falseβ exclude structural information
After updating the configuration file, start training by running the training script:
python train_diffusion.py --config configs/diffusion.yamlconfigs/
βββcontains config.yaml for all model training.
src/ori/
βββ models/ # Model architectures
βββ data/ # Data loading and preprocessing
βββ metrics/ # Evaluation metrics
βββ xx_training.py # Training wrapper for different models
βββ criterion.py # Loss functions
βββ optimizers.py # Optimizer
βββ utils.py # Helper functions
evaluation.py # For classifying generated images
generate_images.py # Generate images
calculate_fid.py # Calculate FID
sample.py # Sample Class
xx_train.py # Training script for each model
