diffusion_models.evaluation.fid
Frechet / Kernel Inception Distance for diffusion models.
Module Contents
- class ImageQualityEvaluator(real_dataset, number_of_samples=5000, batch_size=100, device='cuda', compute_kid=True, kid_subset_size=1000, seed=0, num_workers=4)[source]
Scores generated images against real ones with FID (and KID).
The Inception statistics of the real images are computed once, on the first call to
evaluate(), and reused afterwards. FID is biased by the number of samples, so only compare scores that use the samenumber_of_samples. KID is unbiased, which makes it more reliable for small sample sizes.The real dataset must yield
(image, label)pairs whose images are normalized to[-1, 1](the same convention as the training data).- Parameters:
real_dataset (Dataset) – The reference images, ideally a held-out split.
number_of_samples (int) – How many real and generated images to compare.
batch_size (int) – The batch size used for sampling and feature extraction.
device (str) – The device used for sampling and the Inception network.
compute_kid (bool) – Whether to also compute the Kernel Inception Distance.
kid_subset_size (int) – The KID subset size (at most
number_of_samples).seed (int) – Seed of the sampling noise, so scores are comparable across runs.
num_workers (int) – Dataloader workers used to read the real images.
- kid: torchmetrics.image.kid.KernelInceptionDistance | None = None[source]
The KID metric, when enabled.
- evaluate(model)[source]
Generate images with the model and score them.
The model is put in eval mode for sampling and restored afterwards.
- Parameters:
model (BaseDiffusionModel) – The (EMA) model to evaluate, already on
self.device.- Returns:
A dictionary with
"FID"and, when enabled,"KID"and"KID_std".- Return type: