This repository contains the code for the seminar paper "Denoising Diffusion Probabilistic Models" that was implemented as part of the course "Project Machine Learning" in WS23/24. The reports for the three milestones can be found in the docs/reports directory.
Train the denoising module on one of the provided datasets, i.e.
CIFAR-10, MNIST, FGVC-Aircraft, Flowers102 or CelebA. The dataset is split into a training set, which is used to train the denoiser, and a test set, which is used to validate the model at end of each epoch. After the training is complete, the training results (metadata, losses, etc.) are stored together with the model weights in a directory named after the experiment.
Generate images using a trained denoiser. The routine takes the path of a run created by train_denoiser.py and the number of images to generate. The resulting images are saved to the specified output directory.
Parameters
Parameter
Description
Type
Annotations
run_dir
The directory containing the trained model.
Path
image_count
The number of images to generate.
int
Options
Parameter
Description
Type
Default
Annotations
--batch-size
The batch size for generating images. Must be a divisor of num_images.
int
None
--time-steps
The number of time steps for the diffusion process. If not specified, number of time steps from the training will be used.
int | None
None
--seed
The random seed to use. If not specified, the randomized calculations will be non-deterministic.
int | None
None
--out-dir
The directory to save the results to. If not specified, the images are saved to <run_dir>/samples.
pathlib.Path
None
--device
The device to use.
"cpu" | "cuda" | None
"cuda"
If not specified, "cuda" will be used if it is available.
Image Evaluation
python3 evaluate_images.py <image_dir> [options]
Calculate the Inception Score to evaluate the quality of generated images using the InceptionV3 model. The routine takes the path of a directory containing the generated images and saves their resulting score to inception_score.txt in the same directory.
Positional Parameters
Parameter
Description
Type
Annotations
image_dir
The directory containing the generated images.
Path
Options
Parameter
Description
Type
Default
Annotations
--out-file
The file to save the inception score to. If not specified, the score is saved to <image_dir>/inception_score.txt.
pathlib.Path
None
--device
The device to use.
"cpu" | "cuda" | None
"cuda"
If not specified, "cuda" will be used if it is available.
--verbose
Enable verbose logging.
bool
False
Noise Schedule Visualization
python3 apply_noise.py <image_path> [options]
This routine visualizes the forward diffusion process. It takes an image as parameter (e.g. one of the example images in data/images) and applies gradual noise according to the pre-configured schedule.
Positional Parameters
Options
Parameter
Description
Type
Default
Annotations
--schedule
The schedule to use
linear, polynomial, cosine, sigmoid
linear
--schedule-steps
The number of time steps for the diffusion process
int
10
--schedule-start
The starting value for the schedule
float
0.0
--schedule-end
The ending value for the schedule
float
1.0
--schedule-tau
The tau value for the schedule
float
None
Only applicable for polynimial, cosine and sigmoid schedules
--image-size
The (quadratic) size to scale the image to
int
128
--outdir
The directory to save the results to
pathlib.Path
./out/forward/<schedule>
--device
The device to use
torch.Device
"cpu"
If not specified, "cuda" will be used if it is available.