# Fréchet inception distance

The Fréchet inception distance (FID) is a metric used to assess the quality of images created by a generative model, like a generative adversarial network (GAN) or a diffusion model.
The FID compares the distribution of generated images with the distribution of a set of real images (a "ground truth" set). Rather than comparing individual images, mean and covariance statistics of many images generated by the model are compared with the same statistics generated from images in the ground truth or reference set. A convolutional neural network such as an inception architecture is used to produce higher-level features describing the images, thus leading to the name Fréchet inception distance.
The FID is inspired by the earlier inception score (IS) metric which evaluates only the distribution of generated images. The FID metric does not replace the IS metric; classifiers that achieve the best (lowest) FID score tend to have greater sample variety while classifiers achieving the best (highest) IS score tend to have better quality within individual images.
The FID metric was introduced in 2017, and is the current standard metric for assessing the quality of models that generate synthetic images as of 2024. It has been used to measure the quality of many recent models including the high-resolution StyleGAN1 and StyleGAN2 networks, and diffusion models.
The FID attempts to compare images visually through deep layers of an inception network. More recent works take this further by instead comparing CLIP embeddings of the images.

## Overview

The purpose of the FID score is to measure the diversity of images created by a generative model with images in a reference dataset. The reference dataset could be ImageNet or COCO-2014. Using a large dataset as a reference is important as the reference image set should represent the full diversity of images which the model attempts to create.
Generative models such as diffusion models produce novel images that have features from the reference set, but are themselves quite different from any image in the training set. So the quality of these models cannot be assessed by simply comparing each image to an image in the training set pixel-by-pixel, as done, for example, with the L2 norm.
Instead, the FID models the two sets of images as if they were drawn from two multidimensional Gaussian distributions ${\mathcal {N}}(\mu ,\Sigma )$ and ${\mathcal {N}}(\mu ',\Sigma ')$. The distance between the two distributions is calculated as the earth mover's distance or the Wasserstein distance between the two Gaussian distributions.
Rather than directly comparing images pixel by pixel (for example, as done by the L2 norm), the FID compares the mean and standard deviation of the deepest layer in Inception v3 (the 2048-dimensional activation vector of its last pooling layer.) These layers are closer to output nodes that correspond to real-world objects such as a specific breed of dog or an airplane, and further from the shallow layers near the input image. So the FID compares how often the same high-level features are found within the two sets of images. After every image has been processed through the inception architecture, the means and covariances of the activation of the last layer on the two datasets are compared with the distance$d_{F}({\mathcal {N}}(\mu ,\Sigma ),{\mathcal {N}}(\mu ',\Sigma '))^{2}=\lVert \mu -\mu '\rVert _{2}^{2}+\operatorname {tr} \left(\Sigma +\Sigma '-2\left(\Sigma \Sigma '\right)^{\frac {1}{2}}\right)$Higher distances indicate a poorer generative model. A score of 0 indicates a perfect model.

## Formal definition

For any two probability distributions $\mu ,\nu$ over $\mathbb {R} ^{n}$ having finite mean and variances, their earth-mover's distance or Fréchet distance is$d_{F}(\mu ,\nu ):=\left(\inf _{\gamma \in \Gamma (\mu ,\nu )}\int _{\mathbb {R} ^{n}\times \mathbb {R} ^{n}}\|x-y\|^{2}\,\mathrm {d} \gamma (x,y)\right)^{1/2},$where $\Gamma (\mu ,\nu )$ is the set of all measures on $\mathbb {R} ^{n}\times \mathbb {R} ^{n}$ with marginals $\mu$ and $\nu$ on the first and second factors respectively. (The set $\Gamma (\mu ,\nu )$ is also called the set of all couplings of $\mu$ and $\nu$.).
For two multidimensional Gaussian distributions ${\mathcal {N}}(\mu ,\Sigma )$ and ${\mathcal {N}}(\mu ',\Sigma ')$, it is expressed in closed form as$d_{F}({\mathcal {N}}(\mu ,\Sigma ),{\mathcal {N}}(\mu ',\Sigma '))^{2}=\lVert \mu -\mu '\rVert _{2}^{2}+\operatorname {tr} \left(\Sigma +\Sigma '-2\left(\Sigma \Sigma '\right)^{\frac {1}{2}}\right)$This allows us to define the FID in pseudocode form:
   INPUT a function $f:\Omega _{X}\to \mathbb {R} ^{n}$.
   INPUT two datasets $S,S'\subset \Omega _{X}$.
   Compute $f(S),f(S')\subset \mathbb {R} ^{n}$.
   Fit two gaussian distributions ${\mathcal {N}}(\mu ,\Sigma ),{\mathcal {N}}(\mu ',\Sigma ')$, respectively for $f(S),f(S')$.
   RETURN $d_{F}({\mathcal {N}}(\mu ,\Sigma ),{\mathcal {N}}(\mu ',\Sigma '))^{2}$.
In most practical uses of the FID, $\Omega _{X}$ is the space of images, and $f$ is an Inception v3 model trained on the ImageNet, but without its final classification layer. Technically, it is the 2048-dimensional activation vector of its last pooling layer. Of the two datasets $S,S'$, one of them is a reference dataset, which could be the ImageNet itself, and the other is a set of images generated by a generative model, such as GAN, or diffusion model.

## Variants

Specialized variants of FID have been suggested as evaluation metric for music enhancement algorithms as Fréchet Audio Distance (FAD), for generative models of video as Fréchet Video Distance (FVD), and for AI-generated molecules as Fréchet ChemNet Distance (FCD).

## Limitations

Chong and Forsyth showed FID to be statistically biased, in the sense that their expected value over a finite data is not their true value. Also, because FID measured the Wasserstein distance towards the ground-truth distribution, it is inadequate for evaluating the quality of generators in domain adaptation setups, or in zero-shot generation. Finally, while FID is more consistent with human judgement than previously used inception score, there are cases where FID is inconsistent with human judgment (e.g. Figure 3,5 in Liu et al.).