10 / 34 · Evaluation
Fréchet Inception Distance
FID compares real and generated images through the mean and covariance of their Inception features. It is the squared Wasserstein-2 distance between two fitted Gaussians, and KID is its unbiased kernel cousin.
On this page 10
A generator that outputs three copied training images, one per class, earns the same Inception Score as a good generator. The score never looks at real data, so it cannot notice. The fix is to compare the generated images with real ones.
Comparing two sets of images directly is hopeless in pixel space, so the Fréchet Inception Distance (FID) of Heusel et al. (2017) compares them in the feature space of the same Inception network. It passes both sets through the network, summarises each cloud of features by its mean and covariance, and measures how far apart the two summaries are.
The formula#
Let be the feature vector of an image . For the real images the summaries are the sample mean and covariance,
and , are the same for the generated images. As in the Gaussian note, vectors and matrices are bold. Then
where is the principal matrix square root. Lower is better, and 0 is the minimum.
Why only a mean and a covariance? Two distributions are equal when the expectations of enough test functions agree. For bounded features all polynomials are enough: if every moment agrees, the distributions are the same. Inception features are bounded, because pixel values lie in a bounded range and a continuous network maps a closed bounded set to a bounded one. Heusel et al. keep only the first two moments, the mean and the covariance, and then treat each feature cloud as the Gaussian with those moments.
Why bounded features are fixed by their moments
Take a direction and the projection , a bounded number, . Its moment generating function is a power series in its moments, because the series of converges uniformly when is bounded and may be integrated term by term:
Each is a combination of moments of of order . If two feature distributions share all moments, every projection has the same moment generating function under both, finite for every . A moment generating function that is finite near 0 determines the distribution (Moment and characteristic functions), so every projection has the same distribution under both. A distribution on is fixed by the distributions of all its one-dimensional projections, the Cramér–Wold theorem (Billingsley, 1995), so the two feature distributions are equal.
Without a bound the argument fails at its first step: the moment generating function may be infinite for every , and then equal moments do not force equal distributions.
Among all distributions with a given mean and covariance the Gaussian has the largest entropy, so the fit adds no structure beyond the two moments.
Why the Gaussian has the largest entropy
Let be any density with mean and covariance , and . The cross-entropy of under needs only these two moments:
The second step writes the quadratic form as a trace, , and moves the expectation inside the trace by linearity. The result is the same for , so it equals . Then
with equality only for , since a KL divergence between densities is non-negative and zero only for equal densities.
The features are internal activations: the class probabilities that IS uses would discard most of what the network sees. FID takes the last pooling layer of Inception v3 (Szegedy et al., 2016), the 2048 numbers per image that feed the classification head. The real statistics are computed over the whole training set and the generated ones over 50,000 samples.
How FID is computed
Reading the two terms#
The mean term measures how far apart the centres of the two clouds sit. The covariance term measures how differently they are spread and oriented; it is never negative and vanishes only when , which follows from the Wasserstein view below.
So FID = 0 means equal means and equal covariances of the features, which is weaker than equal feature distributions.
The two terms of FID on a 2-D example
One dimension#
For scalar features the covariances are variances, the matrix root is an ordinary root, , and the trace disappears:
The covariance term is the squared difference of the standard deviations. Real features against generated features give
A generator that is too spread out is penalised just like a shifted one, and so is one that is too narrow. A model that produces nearly the same image every time has , and the covariance term tends to even when the mean is right.
For isotropic covariances and in dimensions the root is , and the covariance term is . The figure below takes , , and shifts the mean by , so .
FID as the generated Gaussian shifts and shrinks
Two dimensions, in numbers#
The two Gaussians of the earlier figure have
The only real work is the trace of the root of . This product is not symmetric, but is similar to the symmetric positive-definite matrix in the brackets, so its eigenvalues are positive and . Squaring that sum, and using that the eigenvalues add up to the trace and multiply to the determinant,
| Quantity | Value |
|---|---|
| mean term | |
| and | and |
| covariance term | |
| FID |
The shift of the means dominates: most of the distance comes from where the clouds sit, a fifth from their shapes.
With 2048 features the root is computed numerically, for example with scipy.linalg.sqrtm. In floating point it can come back with tiny imaginary parts, which implementations drop. When too few images make the covariances nearly singular, they add a small to both and try again.
FID is a Wasserstein distance between two Gaussians#
The 2-Wasserstein distance between distributions and on with finite second moments is the cheapest way to move the mass of one onto the other, when moving mass by a distance costs :
Here is the set of transport plans, joint distributions of whose marginals are and . For two Gaussians the infimum has a closed form, and it is the FID formula (Isachenko, 2025, lecture 6; Конспект курса «Байесовские методы в анализе данных», 2026, лекция 5):
FID is the squared distance, with no outer root. The same distance is also named after Maurice Fréchet, hence the F. The derivation below needs only means, covariances and one matrix inequality. The idea: the cost of a plan depends on it only through the cross-covariance of and , so the best plan is the one that correlates and as strongly as the two covariances allow.
Derivation of the closed form
Assume both covariances are invertible. Write and with centred , and let . For any plan,
The cross term of the first line vanishes because has mean zero; the second line expands the square, . So the best plan maximises .
Which are possible. The joint covariance of must be positive semidefinite. Conversely, any that keeps it so is the cross-covariance of a jointly Gaussian pair, whose marginals are the two Gaussians. Substitute and the vectors , into the quadratic form of the joint covariance:
With this reads , so stretches no vector: its largest singular value is at most 1. Conversely, if it is, Cauchy–Schwarz gives , and the form is at least .
The best . Let with singular value decomposition . With ,
The first equality moves around the trace (cyclic property), the second does the same with . stretches no vector either, since and are orthogonal, so . The choice gives and reaches the bound.
The value. The singular values of are the square roots of the eigenvalues of , so
which by the callout below equals . Putting it into the cost gives the FID formula.
Two facts used earlier follow. The covariance term is the smallest expected squared distance between centred and , so it is never negative. It is zero only if the best plan has with probability 1, which makes the two centred distributions equal and . The Wasserstein GAN, later in the course, trains with the cost instead of .
Compared with the Inception Score#
FID repairs the main blind spot of IS by using real data, and it reads richer features than class probabilities.
| Inception Score | FID | |
|---|---|---|
| Data used | generated images only | real and generated images |
| What is compared | each with the marginal | a Gaussian fit to real features with one fit to generated features |
| Distance | KL divergence | squared Fréchet () distance |
| Better is | higher | lower |
| Copies of three training images | score like a good generator | score badly: the features sit on three points |
Heusel et al. also checked that FID follows visible damage. They corrupted CelebA face images with increasing Gaussian noise, blur, black rectangles, swirls and salt-and-pepper noise, and replaced growing fractions of them with ImageNet images. FID rose steadily with every kind of damage, and it tracked the damage more consistently than IS.
Over which images is FID computed?#
Standard FID is computed once, over all generated and all real images: every real image goes into one feature cloud and every generated image into another. It needs no class labels, and no generated image is paired with a real one. Because it compares distributions, it needs many images, as the next section shows. A comparison of two individual images is a different tool, LPIPS.
Where FID breaks#
Same moments, different shapes#
FID sees only two moments. Take real one-dimensional features and a generator whose features have two bumps, an equal mixture of and . The mixture has mean 0 and variance , so
The two distributions look nothing alike: one peak against two, with a dip where the real data are densest. The Code section confirms the zero on 20,000 samples. Real Inception features are far from Gaussian, with many modes (Jayasumana et al., 2024) and, after the ReLU, about 2% of their components exactly zero (Bińkowski et al., 2018), so two very different feature clouds can share their first two moments.
The estimate is biased#
The estimate of FID from samples is biased upward. Draw both sets from the same 64-dimensional Gaussian, so the true FID is 0:
| Images per set | Mean FID estimate |
|---|---|
| 200 | 10.98 |
| 1,000 | 2.19 |
| 5,000 | 0.44 |
Here the truth is 0 and every estimate is itself a squared distance between two fitted Gaussians, so no estimate can fall below the truth (Bińkowski et al., 2018, footnote 10). For a true FID above 0 a single estimate can land on either side; the bias says that the average over repeated samples lies above the truth. Two arguments, both folded below, show why: the noise in the estimated means and covariances can only raise the average, and in this test the excess is close to
which for gives , and against the measured , and . With 2048 features the effect is larger: comparing the CIFAR-10 training and test sets, two samples of one distribution, Bińkowski et al. still get an FID of about 8.1 with all 10,000 test images.
Why the average estimate lies above the truth
In this fold a hat marks the sample statistics of the formula section, and plain symbols the true mean and covariance of each feature distribution.
The mean term. The difference of sample means is , where the noise has mean zero and, since the two sets are independent, covariance (the variance of an average). The cross term has mean zero, so
The covariance term. The factor makes each sample covariance unbiased, so is right on average. The root term is the largest over the cross-covariances allowed in the derivation above. If is allowed for one pair of covariances and for another, their average is allowed for the averaged pair, because an average of positive semidefinite joint covariances is positive semidefinite. So is jointly concave, and Jensen’s inequality for a concave function gives
The term enters FID with the factor , so it too can only raise the average.
The size in the test. Take and images per set. The mean term adds . Write the estimates as and with small symmetric , and keep terms up to second order. The Taylor series gives , and multiplying out,
where the two terms cancel the from the product of the halves. The same series once more, with to second order and :
The first-order terms cancelled, which is why the bias is quadratic in the noise.
Ignoring the estimated mean, each entry of is an average of independent products of standard normal coordinates. For the product has variance ; for , . The fourth moment is integration by parts: the standard normal density has , so . Summing over the entries of the independent and ,
Both terms fall like , and the covariance term, of order , dominates.
Evaluations therefore fix the number of generated images, typically 5,000 or 50,000 (Конспект курса «Байесовские методы в анализе данных», 2026, лекция 5), and an FID computed at one size cannot be compared with one computed at the other. A fixed size does not cure the problem, though, because the bias depends on the generator. Two generators evaluated with the same can be ranked by their bias instead of their quality (Chong and Forsyth, 2020). Bińkowski et al. construct cases where the ranking flips, even for one-dimensional Gaussians, and one in 2048 dimensions where 50,000 samples still give the wrong order. Below 2049 images the 2048-dimensional covariance is singular outright: the centred feature vectors sum to zero, so they span at most dimensions. Chong and Forsyth extrapolate the estimate in to an effectively unbiased ; KID avoids the bias by construction.
What the features see#
The network was trained to classify ImageNet photographs. Its features are so close to the class predictions that FID can be lowered by matching the generated images’ ImageNet class statistics to the real ones, without any visible improvement (Kynkäänniemi et al., 2023). For data far from ImageNet, such as medical images, sketches or spectrograms, nothing guarantees that the features capture what makes an image good. One remedy is a custom encoder.
One number for two failures#
A worse FID can come from unrealistic samples, which move and reshape the feature cloud, or from too little variety, which shrinks it. In the setting of the shift-and-shrink figure, a shift by and a shrink to both give , so two generators with equal scores can fail in opposite ways. Precision and recall report the two separately.
Copies and preprocessing#
The real statistics come from the training set, so a generator that returns randomly drawn training images reproduces their mean and covariance and gets an FID near 0. Detecting copies needs a per-image comparison, such as a nearest-neighbour search under LPIPS.
Low-level preprocessing also moves the score. The resizing filter, 8-bit quantisation and JPEG compression all change the features, so FIDs computed with different pipelines are not comparable (Parmar, Zhang and Zhu, 2022).
FID with a custom encoder#
Nothing in the formula depends on Inception: it needs one feature vector per image, and any encoder can supply it. For data unlike ImageNet, an encoder trained on the domain is the natural choice, for example the encoder of an autoencoder trained on that data; Bińkowski et al. score MNIST models with the features of a small MNIST classifier. The price is comparability. Strictly, the result is a Fréchet distance in the features of the named encoder and layer. It can be compared only with values computed with the same encoder, layer and preprocessing, never with published FIDs.
Before trusting a new encoder, test it on real images only. Split a labelled dataset by class, fit a Gaussian to the features of each class, and compute the distance between every pair of classes. The matrix should have a zero diagonal up to numerical noise and be symmetric, since the formula does not change when the two sets swap places (the callout above shows the same way). If the features carry meaning, similar classes should be closer than dissimilar ones: on CIFAR-10, airplane should be closer to ship than to frog, and truck closer to automobile than to dog.
The sample size bites harder here. CIFAR-10 has 1,000 test images per class, so each class covariance has rank at most 999, by the same count as above, and an encoder with a code of 1,000 numbers or more gives singular covariances. A small , such as , stabilises the root at the cost of a small bias; a smaller code avoids the problem.
Kernel Inception Distance: an unbiased alternative#
The Kernel Inception Distance (KID) of Bińkowski et al. (2018) keeps the Inception features and drops the Gaussian fit. It is the squared maximum mean discrepancy (MMD) between the real and the generated features. For distributions and and a kernel ,
with and independent. The first two terms measure how similar points are within each set, the last how similar they are across the sets. KID uses the cubic polynomial kernel
where is the feature dimension. Expanding the cube writes as a positive combination of for , with weights . Each power is an inner product of tensor powers, , so with the moment tensors , linearity of expectation and the independence of and , which turns into ,
The term cancels. So is zero exactly when the moments up to order three agree: the mean, the covariance and the third moments, skewness among them. It assumes no parametric form.
With real features and generated features , KID is estimated by
Leaving out the terms makes each average an unbiased estimate of its expectation, because and are independent draws from when , so is unbiased at every sample size (Gretton et al., 2012). In the 64-dimensional test above it averages , and at the three sizes: zero up to noise, and sometimes slightly negative, which an unbiased estimate of a value near 0 must be. No estimator of FID is unbiased for all distributions, at any sample size (Bińkowski et al., 2018, Appendix D.3). The reason: along a mixture , the expected value of any estimator from samples is a polynomial in of degree at most , since each of the independent draws contributes one factor linear in . For one-dimensional Gaussians , and a Gaussian target, FID along the family contains the standard deviation of the mixture, the square root of a quadratic in , and so is not a polynomial.
The double sums cost , against for FID’s covariances and root. Bińkowski et al. therefore average the estimate over many random subsets, 100 subsets of 1,000 images in their experiments. KID inherits FID’s dependence on the ImageNet features, and its cubic kernel has its own blind spot: the two-bump example above is symmetric like the Gaussian, so their third moments agree too, and only a kernel that reaches the fourth moment would separate them.
Code#
The two-dimensional example, the two-bump failure and the bias of FID against KID. It uses NumPy and SciPy and runs in a few seconds.
import numpy as np
from scipy.linalg import sqrtm
def fid(mu1, S1, mu2, S2):
root = sqrtm(S1 @ S2).real # principal root; drop imaginary noise
return float(((mu1 - mu2) ** 2).sum() + np.trace(S1 + S2 - 2 * root))
def fid_from_features(U, V):
cov = lambda A: np.atleast_2d(np.cov(A, rowvar=False))
return fid(U.mean(0), cov(U), V.mean(0), cov(V))
def kid(U, V): # unbiased squared MMD, cubic kernel
d, m, n = U.shape[1], len(U), len(V)
k = lambda A, B: (A @ B.T / d + 1) ** 3
Kuu, Kvv = k(U, U), k(V, V)
return float((Kuu.sum() - np.trace(Kuu)) / (m * (m - 1))
+ (Kvv.sum() - np.trace(Kvv)) / (n * (n - 1)) - 2 * k(U, V).mean())
Sr, Sg = np.array([[1, .6], [.6, .8]]), np.array([[.45, -.1], [-.1, .35]])
print('two Gaussians:', round(fid(np.zeros(2), Sr, np.array([1.2, .6]), Sg), 3))
rng = np.random.default_rng(0)
real = rng.standard_normal((20_000, 1)) # one bump, N(0, 1)
bumps = rng.choice([-0.8, 0.8], (20_000, 1)) + 0.6 * rng.standard_normal((20_000, 1))
print('one bump vs two bumps:', round(fid_from_features(real, bumps), 4))
d = 64 # two samples of the SAME distribution
for n in (200, 1000, 5000):
f = [fid_from_features(rng.standard_normal((n, d)), rng.standard_normal((n, d))) for _ in range(5)]
k = [kid(rng.standard_normal((n, d)), rng.standard_normal((n, d))) for _ in range(5)]
print(f'n = {n:5d}: FID {np.mean(f):.3f} KID {np.mean(k):+.5f}')
two Gaussians: 2.284
one bump vs two bumps: 0.0002
n = 200: FID 10.980 KID +0.00180
n = 1000: FID 2.188 KID -0.00092
n = 5000: FID 0.440 KID +0.00001
The first line is the table above. The second is the two-bump failure: zero up to sampling noise. The rest is the bias table, averaged over five pairs of samples per size, with KID beside it.
Notebook#
The HSE-LAMBDA Deep Generative Models course touches FID in two notebooks. Cell numbers count every cell, markdown included, from 1; quoted numbers come from the run saved with the course.
- The metrics notebook describes FID in text (cell 5): features from a pretrained network, often Inception v3, a Gaussian fitted to each set and the Fréchet distance between them. It does not compute FID; its comparison table of IS, FID and LPIPS (cell 6) is the basis of the table above.
- Homework 1 computes a Fréchet distance in the features of an autoencoder trained on CIFAR-10 (the autoencoder part is in the autoencoder note). The student writes
calculate_fid(repr1, repr2, eps=1e-6), fills the class-to-class matrix from 1,000 validation images per class, and checks the semantic order of the custom-encoder section. The notebook has no saved outputs, so it documents the procedure only. - KID appears in the course only by name, in the closing discussion of the GAN notebook.
Next#
IS, FID and KID score whole sets of images. Sometimes we need a distance between two individual images that agrees with human perception: a generated or restored image against its reference, a sample against its nearest training image, or a loss that does not reward blur. That is LPIPS.
References#
- M. Heusel, H. Ramsauer, T. Unterthiner, B. Nessler, S. Hochreiter. GANs trained by a two time-scale update rule converge to a local Nash equilibrium. NeurIPS, 2017. Experiments section, paragraph “Performance Measure”: the moment argument, Eq. (6) and the disturbance experiments; “Model Selection and Evaluation”: the pooling layer, training-set statistics and 50,000 samples; Appendix A1: FID against IS. Code:
fid.pyin the TTUR repository. - R. Isachenko. Deep Generative Models, MIPT and Yandex School of Data Analysis, 2025. Lecture 6: evaluation of likelihood-free models, the closed form of between Gaussians and FID.
- S. Ermon. CS236 Deep Generative Models, Stanford University, Fall 2023. Lecture 15, Evaluating generative models: FID and KID.
- Конспект курса «Байесовские методы в анализе данных», 2026, github.com/bmml-team/bmml_ftda, лекция 5. Section 5.25 and Eq. (146): FID as the squared distance between Gaussian fits to Inception features, the empirical check of its assumption, and the usual sample sizes.
- C. Szegedy, V. Vanhoucke, S. Ioffe, J. Shlens, Z. Wojna. Rethinking the Inception architecture for computer vision. CVPR, 2016.
- P. Billingsley. Probability and Measure, 3rd ed. Wiley, 1995. The Cramér–Wold theorem: a distribution on is determined by its one-dimensional projections.
- M. Bińkowski, D. J. Sutherland, M. Arbel, A. Gretton. Demystifying MMD GANs. ICLR, 2018. Section 4: the Kernel Inception Distance, its estimator, Figure 1 (the bias of FID on CIFAR-10), footnotes 10 and 12 (a true FID of 0 is never underestimated; cost), LeNet features for MNIST; Section 5: KID over 100 subsets of 1,000 images; Appendix D.1–D.2: rankings that FID estimates get wrong; Appendix D.3: no unbiased FID estimator.
- A. Gretton, K. M. Borgwardt, M. J. Rasch, B. Schölkopf, A. Smola. A kernel two-sample test. JMLR, 13, 723–773, 2012. The squared MMD and its unbiased estimate.
- M. J. Chong, D. Forsyth. Effectively unbiased FID and Inception Score and where to find them. CVPR, 2020. The bias depends on the generator; extrapolation to .
- G. Parmar, R. Zhang, J.-Y. Zhu. On aliased resizing and surprising subtleties in GAN evaluation. CVPR, 2022.
- S. Jayasumana, S. Ramalingam, A. Veit, D. Glasner, A. Chakrabarti, S. Kumar. Rethinking FID: towards a better evaluation metric for image generation. CVPR, 2024. The normality assumption.
- T. Kynkäänniemi, T. Karras, M. Aittala, T. Aila, J. Lehtinen. The role of ImageNet classes in Fréchet Inception Distance. ICLR, 2023.
- HSE-LAMBDA, Deep Generative Models course repository:
metrics.ipynb,GANs.ipynband01_hw_AE-and-FID.ipynb.