diffusion_models.evaluation.fid =============================== .. py:module:: diffusion_models.evaluation.fid .. autoapi-nested-parse:: Frechet / Kernel Inception Distance for diffusion models. Module Contents --------------- .. py: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) 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 :meth:`evaluate`, and reused afterwards. FID is biased by the number of samples, so only compare scores that use the same ``number_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). :param real_dataset: The reference images, ideally a held-out split. :param number_of_samples: How many real and generated images to compare. :param batch_size: The batch size used for sampling and feature extraction. :param device: The device used for sampling and the Inception network. :param compute_kid: Whether to also compute the Kernel Inception Distance. :param kid_subset_size: The KID subset size (at most ``number_of_samples``). :param seed: Seed of the sampling noise, so scores are comparable across runs. :param num_workers: Dataloader workers used to read the real images. .. py:attribute:: real_dataset The reference images. .. py:attribute:: number_of_samples The number of real and generated images compared. .. py:attribute:: batch_size :value: 100 The batch size used for sampling and feature extraction. .. py:attribute:: device :value: 'cuda' The device used for sampling and feature extraction. .. py:attribute:: seed :value: 0 The seed of the sampling noise. .. py:attribute:: num_workers :value: 4 Dataloader workers used to read the real images. .. py:attribute:: fid The FID metric. .. py:attribute:: kid :type: Optional[torchmetrics.image.kid.KernelInceptionDistance] :value: None The KID metric, when enabled. .. py:method:: to_unit_range(images) :staticmethod: Map images from ``[-1, 1]`` to ``[0, 1]``. .. py:method:: evaluate(model) Generate images with the model and score them. The model is put in eval mode for sampling and restored afterwards. :param model: The (EMA) model to evaluate, already on ``self.device``. :returns: A dictionary with ``"FID"`` and, when enabled, ``"KID"`` and ``"KID_std"``.