Course contents 10 / 34

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 φ(x)\varphi(x) be the feature vector of an image xx. For the real images x1,…,xNrx_1, \dots, x_{N_r} the summaries are the sample mean and covariance,

μr=1Nr∑i=1Nrφ(xi),Σr=1Nr−1∑i=1Nr(φ(xi)−μr)(φ(xi)−μr)⊤,\begin{aligned} \boldsymbol\mu_r &= \frac{1}{N_r} \sum_{i=1}^{N_r} \varphi(x_i) , \\ \boldsymbol\Sigma_r &= \frac{1}{N_r - 1} \sum_{i=1}^{N_r} \big(\varphi(x_i) - \boldsymbol\mu_r\big)\big(\varphi(x_i) - \boldsymbol\mu_r\big)^{\top} , \end{aligned}

and μg\boldsymbol\mu_g, Σg\boldsymbol\Sigma_g are the same for the generated images. As in the Gaussian note, vectors and matrices are bold. Then

FID=∥μr−μg∥22+Tr⁡(Σr+Σg−2 (ΣrΣg)1/2),\begin{aligned} \mathrm{FID} ={}& \|\boldsymbol\mu_r - \boldsymbol\mu_g\|_2^2 \\ &+ \operatorname{Tr}\Big(\boldsymbol\Sigma_r + \boldsymbol\Sigma_g - 2\,(\boldsymbol\Sigma_r \boldsymbol\Sigma_g)^{1/2}\Big) , \end{aligned}

where (⋅)1/2(\cdot)^{1/2} 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 t\mathbf t and the projection s=t⊤φ(x)s = \mathbf t^\top \varphi(x), a bounded number, ∣s∣≤b\lvert s \rvert \le b. Its moment generating function is a power series in its moments, because the series of eτse^{\tau s} converges uniformly when ss is bounded and may be integrated term by term:

E eτs=∑k=0∞τkk! E sk.\mathbb E\, e^{\tau s} = \sum_{k=0}^\infty \frac{\tau^k}{k!}\, \mathbb E\, s^k .

Each E sk\mathbb E\, s^k is a combination of moments of φ(x)\varphi(x) of order kk. If two feature distributions share all moments, every projection has the same moment generating function under both, finite for every τ\tau. 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 Rd\mathbb R^d 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 τ>0\tau > 0, 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 pp be any density with mean μ\boldsymbol\mu and covariance Σ\boldsymbol\Sigma, and g=N(μ,Σ)g = \mathcal N(\boldsymbol\mu, \boldsymbol\Sigma). The cross-entropy of gg under pp needs only these two moments:

−Eplog⁡g=12log⁡det⁡(2πΣ)+12 Ep(x−μ)⊤Σ−1(x−μ)=12log⁡det⁡(2πΣ)+12Tr⁡(Σ−1Σ)=12log⁡det⁡(2πe Σ).\begin{aligned} -\mathbb E_p \log g &= \tfrac12 \log\det(2\pi\boldsymbol\Sigma) \\ &\quad + \tfrac12\, \mathbb E_p (\mathbf x - \boldsymbol\mu)^\top \boldsymbol\Sigma^{-1} (\mathbf x - \boldsymbol\mu) \\ &= \tfrac12 \log\det(2\pi\boldsymbol\Sigma) + \tfrac12 \operatorname{Tr}(\boldsymbol\Sigma^{-1} \boldsymbol\Sigma) \\ &= \tfrac12 \log\det(2\pi e\, \boldsymbol\Sigma) . \end{aligned}

The second step writes the quadratic form as a trace, a⊤Ba=Tr⁡(Baa⊤)\mathbf a^\top \mathbf B \mathbf a = \operatorname{Tr}(\mathbf B \mathbf a \mathbf a^\top), and moves the expectation inside the trace by linearity. The result is the same for p=gp = g, so it equals H(g)H(g). Then

H(p)=−Eplog⁡g−DKL(p ∥ g)=H(g)−DKL(p ∥ g)≤H(g),\begin{aligned} H(p) &= -\mathbb E_p \log g - D_{\mathrm{KL}}(p \,\|\, g) \\ &= H(g) - D_{\mathrm{KL}}(p \,\|\, g) \le H(g) , \end{aligned}

with equality only for p=gp = g, 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.

Figure

How FID is computed

FID pipelineReal images and generated images both enter one pretrained Inception v3 network. Its pool3 layer, before the softmax classifier, gives a 2048-dimensional embedding per image; the fully connected softmax head is crossed out as not used. The real embeddings form a red point cloud summarised by mean mu r and covariance Sigma r; the generated embeddings form a blue cloud summarised by mu g and Sigma g. Both summaries feed into FID, where lower means closer and zero means equal means and equal covariances.real imagesgenerated imagesInception v3pretrained, frozenpool3FC + softmaxreal featuresgenerated featuresfit a Gaussianμr, Σrμg, ΣgFIDlower = closer0 = same μ, Σtake embeddings here: before softmaxFID pipeline (stacked)Real images and generated images both enter one pretrained Inception v3 network. Its pool3 layer, before the softmax classifier, gives a 2048-dimensional embedding per image; the fully connected softmax head is crossed out as not used. The real embeddings form a red point cloud summarised by mu r and Sigma r; the generated embeddings form a blue cloud summarised by mu g and Sigma g. Both feed into FID, where lower means closer and zero means equal means and equal covariances.real imagesgenerated imagesInception v3pretrained, frozenpool3FC + softmaxembeddingsbefore softmaxfeaturesfit a Gaussianμr, Σrμg, ΣgFIDlower = closer0 = same μ and Σ
Both image sets go through the same frozen Inception network. The activations are taken before the softmax classification head (in the standard implementation, the 2048-dimensional pool3 layer), one Gaussian is fitted to each feature cloud, and FID compares the two Gaussians.

Reading the two terms#

The mean term ∥μr−μg∥22\|\boldsymbol\mu_r - \boldsymbol\mu_g\|_2^2 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 Σr=Σg\boldsymbol\Sigma_r = \boldsymbol\Sigma_g, 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.

Figure

The two terms of FID on a 2-D example

Real and generated feature clouds with their FID termsA red cloud of real features centred at the origin, tilted, and a smaller, rounder blue cloud of generated features centred at (1.2, 0.6). An amber arrow between the two means is labelled squared norm of mu r minus mu g, equal to 1.80. A callout pointing at both ellipse outlines is labelled covariance term, the trace, equal to 0.484. A summary panel adds them: FID equals 2.284.2 of the 2048 feature dimensionsreal, 𝒩(μr, Σr)generated,𝒩(μg, Σg)‖μr − μg‖² = 1.80covariance term Tr(…) = 0.484different spread and tiltThis examplemean term1.800Tr Σr1.800Tr Σg0.800−2 Tr[(ΣrΣg)½]−2.116cov. term0.484FID2.284Real and generated feature clouds with their FID termsA red cloud of real features centred at the origin, tilted, and a smaller, rounder blue cloud of generated features centred at (1.2, 0.6). An amber arrow between the two means is labelled squared norm of mu r minus mu g, equal to 1.80. A callout pointing at both ellipse outlines is labelled covariance term, the trace, equal to 0.484. A summary panel adds them: FID equals 2.284.2 of the 2048 feature dimensionsreal, 𝒩(μr, Σr)generated,𝒩(μg, Σg)‖μr − μg‖² = 1.80covariance term Tr(…) = 0.484different spread and tiltThis examplemean term1.800Tr Σr1.800Tr Σg0.800−2 Tr[(ΣrΣg)½]−2.116covariance term0.484FID2.284
140 seeded samples from each Gaussian, with 2σ ellipses. Real: mean (0, 0), covariance [[1, 0.6], [0.6, 0.8]]; generated: mean (1.2, 0.6), covariance [[0.45, −0.1], [−0.1, 0.35]]. The mean term measures how far apart the clouds sit, the covariance term how differently they are spread and oriented; the numbers use the true parameters.

One dimension#

For scalar features the covariances are variances, the matrix root is an ordinary root, σr2σg2=σrσg\sqrt{\sigma_r^2 \sigma_g^2} = \sigma_r \sigma_g, and the trace disappears:

σr2+σg2−2σrσg=(σr−σg)2,FID1D=(μr−μg)2+(σr−σg)2.\begin{aligned} \sigma_r^2 + \sigma_g^2 - 2\sigma_r \sigma_g &= (\sigma_r - \sigma_g)^2 , \\ \mathrm{FID}_{1\mathrm D} &= (\mu_r - \mu_g)^2 + (\sigma_r - \sigma_g)^2 . \end{aligned}

The covariance term is the squared difference of the standard deviations. Real features N(0,1)\mathcal N(0, 1) against generated features N(0.5,22)\mathcal N(0.5, 2^2) give

FID=0.52+(1−2)2=1.25.\mathrm{FID} = 0.5^2 + (1 - 2)^2 = 1.25 .

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 σg→0\sigma_g \to 0, and the covariance term tends to σr2\sigma_r^2 even when the mean is right.

For isotropic covariances σr2I\sigma_r^2 \mathbf I and σg2I\sigma_g^2 \mathbf I in dd dimensions the root is σrσgI\sigma_r \sigma_g \mathbf I, and the covariance term is d(σr−σg)2d(\sigma_r - \sigma_g)^2. The figure below takes d=2d = 2, σr=1\sigma_r = 1, σg=s\sigma_g = s and shifts the mean by mm, so FID=m2+2(1−s)2\mathrm{FID} = m^2 + 2(1 - s)^2.

Figure

FID as the generated Gaussian shifts and shrinks

Four cases of FID between two isotropic Gaussiansidentical: shift 0, scale 1, mean term 0, covariance term 0, FID 0. shifted: shift 1.5, scale 1, mean term 2.25, covariance term 0, FID 2.25. shrunk: shift 0, scale 0.4, mean term 0, covariance term 0.72, FID 0.72. shifted + shrunk: shift 1.5, scale 0.4, mean term 2.25, covariance term 0.72, FID 2.97.identicalm = 0, s = 10 + 0FID = 0shiftedm = 1.5, s = 12.25 + 0FID = 2.25shrunkm = 0, s = 0.40 + 0.72FID = 0.72shifted + shrunkm = 1.5, s = 0.42.25 + 0.72FID = 2.97Four cases of FID between two isotropic Gaussiansidentical: shift 0, scale 1, mean term 0, covariance term 0, FID 0. shifted: shift 1.5, scale 1, mean term 2.25, covariance term 0, FID 2.25. shrunk: shift 0, scale 0.4, mean term 0, covariance term 0.72, FID 0.72. shifted + shrunk: shift 1.5, scale 0.4, mean term 2.25, covariance term 0.72, FID 2.97.identicalm = 0, s = 10 + 0FID = 0shiftedm = 1.5, s = 12.25 + 0FID = 2.25shrunkm = 0, s = 0.40 + 0.72FID = 0.72shifted + shrunkm = 1.5, s = 0.42.25 + 0.72FID = 2.97
Real features N(0, I) in red, generated features N((m, 0), s²I) in blue (2σ circles), so FID = m² + 2(1 − s)². Under each panel: mean term (amber) + covariance term. A shift moves only the mean term, a narrower, less diverse generator only the covariance term, and the two add up.

Two dimensions, in numbers#

The two Gaussians of the earlier figure have

μr=(0,0)⊤,Σr=(10.60.60.8),μg=(1.2,0.6)⊤,Σg=(0.45−0.1−0.10.35).\begin{aligned} \boldsymbol\mu_r &= (0, 0)^\top , & \boldsymbol\Sigma_r &= \begin{pmatrix} 1 & 0.6 \\ 0.6 & 0.8 \end{pmatrix} , \\ \boldsymbol\mu_g &= (1.2, 0.6)^\top , & \boldsymbol\Sigma_g &= \begin{pmatrix} 0.45 & -0.1 \\ -0.1 & 0.35 \end{pmatrix} . \end{aligned}

The only real work is the trace of the root of M=ΣrΣg\mathbf M = \boldsymbol\Sigma_r \boldsymbol\Sigma_g. This product is not symmetric, but M=Σr1/2(Σr1/2ΣgΣr1/2)Σr−1/2\mathbf M = \boldsymbol\Sigma_r^{1/2} \big(\boldsymbol\Sigma_r^{1/2} \boldsymbol\Sigma_g \boldsymbol\Sigma_r^{1/2}\big) \boldsymbol\Sigma_r^{-1/2} is similar to the symmetric positive-definite matrix in the brackets, so its eigenvalues λ1,λ2\lambda_1, \lambda_2 are positive and Tr⁡M1/2=λ1+λ2\operatorname{Tr} \mathbf M^{1/2} = \sqrt{\lambda_1} + \sqrt{\lambda_2}. Squaring that sum, and using that the eigenvalues add up to the trace and multiply to the determinant,

Tr⁡M1/2=λ1+λ2+2λ1λ2=Tr⁡M+2det⁡M.\begin{aligned} \operatorname{Tr} \mathbf M^{1/2} &= \sqrt{\lambda_1 + \lambda_2 + 2\sqrt{\lambda_1 \lambda_2}} \\ &= \sqrt{\operatorname{Tr} \mathbf M + 2\sqrt{\det \mathbf M}} . \end{aligned}
QuantityValue
mean term 1.22+0.621.2^2 + 0.6^21.801.80
M=ΣrΣg\mathbf M = \boldsymbol\Sigma_r \boldsymbol\Sigma_g(0.390.110.190.22)\begin{pmatrix} 0.39 & 0.11 \\ 0.19 & 0.22 \end{pmatrix}
Tr⁡M\operatorname{Tr} \mathbf M and det⁡M\det \mathbf M0.610.61 and 0.06490.0649
Tr⁡M1/2=0.61+20.0649\operatorname{Tr} \mathbf M^{1/2} = \sqrt{0.61 + 2\sqrt{0.0649}}1.0581.058
covariance term 1.8+0.8−2⋅1.0581.8 + 0.8 - 2 \cdot 1.0580.4840.484
FID2.2842.284

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 εI\varepsilon \mathbf I to both and try again.

FID is a Wasserstein distance between two Gaussians#

The 2-Wasserstein distance between distributions PP and QQ on Rd\mathbb R^d with finite second moments is the cheapest way to move the mass of one onto the other, when moving mass by a distance tt costs t2t^2:

W22(P,Q)=inf⁡γ∈Π(P,Q)E(u,v)∼γ∥u−v∥22.W_2^2(P, Q) = \inf_{\gamma \in \Pi(P, Q)} \mathbb E_{(u, v) \sim \gamma} \|u - v\|_2^2 .

Here Π(P,Q)\Pi(P, Q) is the set of transport plans, joint distributions of (u,v)(u, v) whose marginals are PP and QQ. For two Gaussians the infimum has a closed form, and it is the FID formula (Isachenko, 2025, lecture 6; Конспект курса «Байесовские методы в анализе данных», 2026, лекция 5):

FID=W22(N(μr,Σr), N(μg,Σg)).\mathrm{FID} = W_2^2\Big(\mathcal N(\boldsymbol\mu_r, \boldsymbol\Sigma_r),\ \mathcal N(\boldsymbol\mu_g, \boldsymbol\Sigma_g)\Big) .

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 C\mathbf C of uu and vv, so the best plan is the one that correlates uu and vv as strongly as the two covariances allow.

Derivation of the closed form

Assume both covariances are invertible. Write u=μr+u0u = \boldsymbol\mu_r + u_0 and v=μg+v0v = \boldsymbol\mu_g + v_0 with centred u0,v0u_0, v_0, and let C=E u0v0⊤\mathbf C = \mathbb E\, u_0 v_0^\top. For any plan,

E∥u−v∥2=∥μr−μg∥2+E∥u0−v0∥2=∥μr−μg∥2+Tr⁡Σr+Tr⁡Σg−2Tr⁡C.\begin{aligned} \mathbb E \|u - v\|^2 &= \|\boldsymbol\mu_r - \boldsymbol\mu_g\|^2 + \mathbb E \|u_0 - v_0\|^2 \\ &= \|\boldsymbol\mu_r - \boldsymbol\mu_g\|^2 + \operatorname{Tr} \boldsymbol\Sigma_r \\ &\quad + \operatorname{Tr} \boldsymbol\Sigma_g - 2 \operatorname{Tr} \mathbf C . \end{aligned}

The cross term of the first line vanishes because u0−v0u_0 - v_0 has mean zero; the second line expands the square, E u0⊤v0=Tr⁡C\mathbb E\, u_0^\top v_0 = \operatorname{Tr} \mathbf C. So the best plan maximises Tr⁡C\operatorname{Tr} \mathbf C.

Which C\mathbf C are possible. The joint covariance of (u0,v0)(u_0, v_0) must be positive semidefinite. Conversely, any C\mathbf C that keeps it so is the cross-covariance of a jointly Gaussian pair, whose marginals are the two Gaussians. Substitute C=Σr1/2KΣg1/2\mathbf C = \boldsymbol\Sigma_r^{1/2} \mathbf K \boldsymbol\Sigma_g^{1/2} and the vectors Σr−1/2a\boldsymbol\Sigma_r^{-1/2} \mathbf a, Σg−1/2b\boldsymbol\Sigma_g^{-1/2} \mathbf b into the quadratic form of the joint covariance:

∥a∥2+2 a⊤Kb+∥b∥2≥0for all a,b.\|\mathbf a\|^2 + 2\, \mathbf a^\top \mathbf K \mathbf b + \|\mathbf b\|^2 \ge 0 \quad \text{for all } \mathbf a, \mathbf b .

With a=−Kb\mathbf a = -\mathbf K \mathbf b this reads ∥b∥2≥∥Kb∥2\|\mathbf b\|^2 \ge \|\mathbf K \mathbf b\|^2, so K\mathbf K stretches no vector: its largest singular value is at most 1. Conversely, if it is, Cauchy–Schwarz gives 2 a⊤Kb≥−2∥a∥∥b∥2\, \mathbf a^\top \mathbf K \mathbf b \ge -2 \|\mathbf a\| \|\mathbf b\|, and the form is at least (∥a∥−∥b∥)2≥0(\|\mathbf a\| - \|\mathbf b\|)^2 \ge 0.

The best K\mathbf K. Let B=Σg1/2Σr1/2\mathbf B = \boldsymbol\Sigma_g^{1/2} \boldsymbol\Sigma_r^{1/2} with singular value decomposition B=USV⊤\mathbf B = \mathbf U \mathbf S \mathbf V^\top. With N=V⊤KU\mathbf N = \mathbf V^\top \mathbf K \mathbf U,

Tr⁡C=Tr⁡(KB)=Tr⁡(NS)=∑isiNii≤∑isi.\begin{aligned} \operatorname{Tr} \mathbf C &= \operatorname{Tr}(\mathbf K \mathbf B) = \operatorname{Tr}(\mathbf N \mathbf S) \\ &= \textstyle\sum_i s_i N_{ii} \le \sum_i s_i . \end{aligned}

The first equality moves Σr1/2\boldsymbol\Sigma_r^{1/2} around the trace (cyclic property), the second does the same with V\mathbf V. N\mathbf N stretches no vector either, since U\mathbf U and V\mathbf V are orthogonal, so Nii=ei⊤Nei≤1N_{ii} = \mathbf e_i^\top \mathbf N \mathbf e_i \le 1. The choice K=VU⊤\mathbf K = \mathbf V \mathbf U^\top gives N=I\mathbf N = \mathbf I and reaches the bound.

The value. The singular values of B\mathbf B are the square roots of the eigenvalues of B⊤B=Σr1/2ΣgΣr1/2\mathbf B^\top \mathbf B = \boldsymbol\Sigma_r^{1/2} \boldsymbol\Sigma_g \boldsymbol\Sigma_r^{1/2}, so

max⁡Tr⁡C=Tr⁡(Σr1/2ΣgΣr1/2)1/2,\max \operatorname{Tr} \mathbf C = \operatorname{Tr}\big(\boldsymbol\Sigma_r^{1/2} \boldsymbol\Sigma_g \boldsymbol\Sigma_r^{1/2}\big)^{1/2} ,

which by the callout below equals Tr⁡(ΣrΣg)1/2\operatorname{Tr}(\boldsymbol\Sigma_r \boldsymbol\Sigma_g)^{1/2}. 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 u0u_0 and v0v_0, so it is never negative. It is zero only if the best plan has u0=v0u_0 = v_0 with probability 1, which makes the two centred distributions equal and Σr=Σg\boldsymbol\Sigma_r = \boldsymbol\Sigma_g. The Wasserstein GAN, later in the course, trains with the cost tt instead of t2t^2.

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 ScoreFID
Data usedgenerated images onlyreal and generated images
What is comparedeach p(y∣x)p(y \mid x) with the marginal p(y)p(y)a Gaussian fit to real features with one fit to generated features
DistanceKL divergencesquared Fréchet (W2W_2) distance
Better ishigherlower
Copies of three training imagesscore like a good generatorscore 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 N(0,1)\mathcal N(0, 1) and a generator whose features have two bumps, an equal mixture of N(−0.8,0.62)\mathcal N(-0.8, 0.6^2) and N(0.8,0.62)\mathcal N(0.8, 0.6^2). The mixture has mean 0 and variance 0.62+0.82=10.6^2 + 0.8^2 = 1, so

FID=02+(1−1)2=0.\mathrm{FID} = 0^2 + (1 - 1)^2 = 0 .

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 setMean FID estimate
20010.98
1,0002.19
5,0000.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

2dN+d(d+1)2N=d(d+5)2N,\frac{2d}{N} + \frac{d(d+1)}{2N} = \frac{d(d+5)}{2N} ,

which for d=64d = 64 gives 11.0411.04, 2.212.21 and 0.440.44 against the measured 10.9810.98, 2.192.19 and 0.440.44. 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 μr−μg+e\boldsymbol\mu_r - \boldsymbol\mu_g + \mathbf e, where the noise e\mathbf e has mean zero and, since the two sets are independent, covariance Σr/Nr+Σg/Ng\boldsymbol\Sigma_r / N_r + \boldsymbol\Sigma_g / N_g (the variance of an average). The cross term has mean zero, so

E∥μ^r−μ^g∥2=∥μr−μg∥2+E∥e∥2=∥μr−μg∥2+Tr⁡ΣrNr+Tr⁡ΣgNg.\begin{aligned} \mathbb E \|\hat{\boldsymbol\mu}_r - \hat{\boldsymbol\mu}_g\|^2 &= \|\boldsymbol\mu_r - \boldsymbol\mu_g\|^2 + \mathbb E \|\mathbf e\|^2 \\ &= \|\boldsymbol\mu_r - \boldsymbol\mu_g\|^2 \\ &\quad + \frac{\operatorname{Tr} \boldsymbol\Sigma_r}{N_r} + \frac{\operatorname{Tr} \boldsymbol\Sigma_g}{N_g} . \end{aligned}

The covariance term. The factor 1/(N−1)1/(N - 1) makes each sample covariance unbiased, so Tr⁡(Σ^r+Σ^g)\operatorname{Tr}(\hat{\boldsymbol\Sigma}_r + \hat{\boldsymbol\Sigma}_g) is right on average. The root term F(Σr,Σg)=Tr⁡(ΣrΣg)1/2F(\boldsymbol\Sigma_r, \boldsymbol\Sigma_g) = \operatorname{Tr}(\boldsymbol\Sigma_r \boldsymbol\Sigma_g)^{1/2} is the largest Tr⁡C\operatorname{Tr} \mathbf C over the cross-covariances allowed in the derivation above. If C1\mathbf C_1 is allowed for one pair of covariances and C2\mathbf C_2 for another, their average is allowed for the averaged pair, because an average of positive semidefinite joint covariances is positive semidefinite. So FF is jointly concave, and Jensen’s inequality for a concave function gives

E F(Σ^r,Σ^g)≤F(Σr,Σg).\mathbb E\, F(\hat{\boldsymbol\Sigma}_r, \hat{\boldsymbol\Sigma}_g) \le F(\boldsymbol\Sigma_r, \boldsymbol\Sigma_g) .

The term enters FID with the factor −2-2, so it too can only raise the average.

The size in the test. Take Σr=Σg=I\boldsymbol\Sigma_r = \boldsymbol\Sigma_g = \mathbf I and NN images per set. The mean term adds 2d/N2d/N. Write the estimates as I+X\mathbf I + \mathbf X and I+Y\mathbf I + \mathbf Y with small symmetric X,Y\mathbf X, \mathbf Y, and keep terms up to second order. The Taylor series (I+Z)1/2=I+Z/2−Z2/8+…(\mathbf I + \mathbf Z)^{1/2} = \mathbf I + \mathbf Z/2 - \mathbf Z^2/8 + \dots gives (I+X)1/2=I+X/2−X2/8(\mathbf I + \mathbf X)^{1/2} = \mathbf I + \mathbf X/2 - \mathbf X^2/8, and multiplying out,

(I+X)1/2(I+Y)(I+X)1/2=I+Z,Z=X+Y+12(XY+YX),\begin{aligned} &(\mathbf I + \mathbf X)^{1/2} (\mathbf I + \mathbf Y) (\mathbf I + \mathbf X)^{1/2} = \mathbf I + \mathbf Z , \\ &\mathbf Z = \mathbf X + \mathbf Y + \tfrac12 (\mathbf X \mathbf Y + \mathbf Y \mathbf X) , \end{aligned}

where the two X2/8\mathbf X^2/8 terms cancel the X2/4\mathbf X^2/4 from the product of the halves. The same series once more, with Tr⁡Z2≈Tr⁡(X+Y)2\operatorname{Tr} \mathbf Z^2 \approx \operatorname{Tr}(\mathbf X + \mathbf Y)^2 to second order and Tr⁡(XY+YX)=2Tr⁡XY\operatorname{Tr}(\mathbf X\mathbf Y + \mathbf Y\mathbf X) = 2 \operatorname{Tr} \mathbf X \mathbf Y:

Tr⁡(2I+X+Y)−2Tr⁡(I+Z)1/2≈−Tr⁡XY+14Tr⁡(X+Y)2=14Tr⁡(X−Y)2=14∥X−Y∥F2.\begin{aligned} &\operatorname{Tr}(2\mathbf I + \mathbf X + \mathbf Y) - 2 \operatorname{Tr}(\mathbf I + \mathbf Z)^{1/2} \\ &\quad\approx -\operatorname{Tr} \mathbf X \mathbf Y + \tfrac14 \operatorname{Tr}(\mathbf X + \mathbf Y)^2 \\ &\quad= \tfrac14 \operatorname{Tr}(\mathbf X - \mathbf Y)^2 = \tfrac14 \|\mathbf X - \mathbf Y\|_F^2 . \end{aligned}

The first-order terms Tr⁡(X+Y)\operatorname{Tr}(\mathbf X + \mathbf Y) cancelled, which is why the bias is quadratic in the noise.

Ignoring the estimated mean, each entry of X\mathbf X is an average of NN independent products zizj−δijz_i z_j - \delta_{ij} of standard normal coordinates. For i≠ji \ne j the product has variance Ezi2 Ezj2=1\mathbb E z_i^2\, \mathbb E z_j^2 = 1; for i=ji = j, Ez4−1=3−1=2\mathbb E z^4 - 1 = 3 - 1 = 2. The fourth moment is integration by parts: the standard normal density ϕ\phi has zϕ(z)=−ϕ′(z)z \phi(z) = -\phi'(z), so Ez4=∫z3⋅zϕ(z) dz=∫3z2ϕ(z) dz=3\mathbb E z^4 = \int z^3 \cdot z \phi(z)\, dz = \int 3 z^2 \phi(z)\, dz = 3. Summing over the d2d^2 entries of the independent X\mathbf X and Y\mathbf Y,

14 E∥X−Y∥F2≈14⋅2⋅d(d−1)+2dN=d(d+1)2N.\tfrac14\, \mathbb E \|\mathbf X - \mathbf Y\|_F^2 \approx \tfrac14 \cdot 2 \cdot \frac{d(d - 1) + 2d}{N} = \frac{d(d + 1)}{2N} .

Both terms fall like 1/N1/N, and the covariance term, of order d2/Nd^2/N, 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 NN 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 NN centred feature vectors sum to zero, so they span at most N−1N - 1 dimensions. Chong and Forsyth extrapolate the estimate in 1/N1/N to an effectively unbiased FID∞\mathrm{FID}_\infty; 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 m=0.85m = 0.85 and a shrink to s=0.4s = 0.4 both give FID≈0.72\mathrm{FID} \approx 0.72, 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 K×KK \times K 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 Tr⁡(ΣrΣg)1/2=Tr⁡(ΣgΣr)1/2\operatorname{Tr}(\boldsymbol\Sigma_r \boldsymbol\Sigma_g)^{1/2} = \operatorname{Tr}(\boldsymbol\Sigma_g \boldsymbol\Sigma_r)^{1/2} 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 εI\varepsilon \mathbf I, such as 10−6I10^{-6} \mathbf I, 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 PP and QQ and a kernel kk,

MMD2(P,Q)=E k(u,u′)+E k(v,v′)−2 E k(u,v),\mathrm{MMD}^2(P, Q) = \mathbb E\, k(u, u') + \mathbb E\, k(v, v') - 2\, \mathbb E\, k(u, v) ,

with u,u′∼Pu, u' \sim P and v,v′∼Qv, v' \sim Q 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

k(u,v)=(1d u⊤v+1)3,k(u, v) = \Big(\frac1d\, u^{\top} v + 1\Big)^3 ,

where dd is the feature dimension. Expanding the cube writes kk as a positive combination of (u⊤v)j(u^\top v)^j for j=0,…,3j = 0, \dots, 3, with weights cj=(3j)d−jc_j = \binom 3j d^{-j}. Each power is an inner product of tensor powers, (u⊤v)j=⟨u⊗j,v⊗j⟩(u^\top v)^j = \langle u^{\otimes j}, v^{\otimes j} \rangle, so with the moment tensors mjP=EP u⊗j\mathbf m_j^P = \mathbb E_P\, u^{\otimes j}, linearity of expectation and the independence of uu and u′u', which turns E⟨u⊗j,u′⊗j⟩\mathbb E \langle u^{\otimes j}, u'^{\otimes j} \rangle into ∥mjP∥2\|\mathbf m_j^P\|^2,

MMD2(P,Q)=∑j=13cj∥mjP−mjQ∥2.\mathrm{MMD}^2(P, Q) = \sum_{j=1}^{3} c_j \big\|\mathbf m_j^P - \mathbf m_j^Q\big\|^2 .

The j=0j = 0 term cancels. So MMD2\mathrm{MMD}^2 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 u1,…,umu_1, \dots, u_m and generated features v1,…,vnv_1, \dots, v_n, KID is estimated by

KID^=1m(m−1)∑i≠jk(ui,uj)+1n(n−1)∑i≠jk(vi,vj)−2mn∑i=1m∑j=1nk(ui,vj).\begin{aligned} \widehat{\mathrm{KID}} ={}& \frac{1}{m(m-1)} \sum_{i \ne j} k(u_i, u_j) \\ &+ \frac{1}{n(n-1)} \sum_{i \ne j} k(v_i, v_j) \\ &- \frac{2}{mn} \sum_{i=1}^m \sum_{j=1}^n k(u_i, v_j) . \end{aligned}

Leaving out the terms i=ji = j makes each average an unbiased estimate of its expectation, because uiu_i and uju_j are independent draws from PP when i≠ji \ne j, so KID^\widehat{\mathrm{KID}} is unbiased at every sample size (Gretton et al., 2012). In the 64-dimensional test above it averages +0.0018+0.0018, −0.0009-0.0009 and +0.00001+0.00001 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 (1−α)P0+αP1(1 - \alpha) P_0 + \alpha P_1, the expected value of any estimator from NN samples is a polynomial in α\alpha of degree at most NN, since each of the NN independent draws contributes one factor linear in α\alpha. For one-dimensional Gaussians P0P_0, P1P_1 and a Gaussian target, FID along the family contains the standard deviation of the mixture, the square root of a quadratic in α\alpha, and so is not a polynomial.

The double sums cost O(n2d)O(n^2 d), against O(nd2+d3)O(n d^2 + d^3) 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 10×1010 \times 10 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#