Search

Search papers and lessons

Fréchet Inception Distance

Level 3 · 10 min read

Fréchet Inception Distance scores a generative image model by comparing the mean and spread of a pretrained network's features for real and generated images; lower is closer.

On this page

  • Colour = topic mix
  • Linear algebra
  • Probability
  • Calculus
  • Discrete math
  • Neural network basics
  • Architectures
  • ReadReady to readNot yet

TL;DR

Judging how realistic a set of generated images is requires a number, and checking them one by one does not give one. Fréchet Inception Distance (FID) embeds each real and each generated image as a vector using a fixed pretrained image network, fits a Gaussian to each set of vectors, and measures how far apart the two Gaussians are. A smaller FID means the generated images look more like the real ones.

Builds on: Multivariate Gaussian, Trace of a Matrix, Matrix Square Root, Convolutional Neural Network, Transfer Learning · Leads to: evaluating GANs and diffusion models

Where it's used

Comparing image generators. Papers that propose a GAN or a diffusion model report FID on a standard benchmark, such as ImageNet or CIFAR-10, so that a new model can be ranked against earlier ones on the same number. The usual protocol generates tens of thousands of images and compares them with the real images in the same dataset.

Tracking training. Researchers log FID every few thousand training steps to see whether a model is still improving or has started to collapse, where it produces only a few kinds of image.

Checking a model before release. A team that changes a generator's architecture or training data can rerun the same FID measurement and see whether the change made the outputs closer to the real distribution, without needing a human to rate every image.

How it works

Take a toy version with one feature per image instead of 2048. Imagine a network turns each image into a single number. The real images give numbers with mean 0 and spread 1 (standard deviation). The generated images give numbers with mean 1 and spread 2.

  1. Embed the images. Run every real image and every generated image through the same fixed network and keep the feature vector. Here each image becomes one number.
  2. Summarise each set as a Gaussian. The real set has mean μ1=0\mu_1 = 0 and spread σ1=1\sigma_1 = 1. The generated set has mean μ2=1\mu_2 = 1 and spread σ2=2\sigma_2 = 2. A Gaussian is fully described by these two numbers.
  3. Compare the centres. The difference of the means is 1−0=11 - 0 = 1, and its square is 1. This is the cost of the two sets sitting in different places.
  4. Compare the spreads. The spread term is (σ1−σ2)2=(1−2)2=1(\sigma_1 - \sigma_2)^2 = (1 - 2)^2 = 1. This is the cost of one set being wider than the other.
  5. Add them up. FID =1+1=2= 1 + 1 = 2. Two identical sets would give 0. A generator that matched the centre but not the spread, or the reverse, would still score above 0.
flowchart LR
  A["Real images"] --> C["Fixed image network"]
  B["Generated images"] --> C
  C --> D["Mean and covariance of real features"]
  C --> E["Mean and covariance of generated features"]
  D --> F["Compare means and covariances"]
  E --> F
  F --> G["FID: lower is closer"]

The steps above are the whole idea. Real images are 2048-dimensional features and the spreads are covariance matrices, so the same comparison needs the matrix versions below.

The math

Definition

Definition: Fréchet Inception Distance

Let the real features have mean μ1\boldsymbol{\mu}_1 and covariance matrix Σ1\Sigma_1, and the generated features have mean μ2\boldsymbol{\mu}_2 and covariance matrix Σ2\Sigma_2. Then FID=∥μ1−μ2∥2+Tr ⁣(Σ1+Σ2−2 (Σ1Σ2)1/2),\mathrm{FID} = \lVert \boldsymbol{\mu}_1 - \boldsymbol{\mu}_2 \rVert^2 + \mathrm{Tr}\!\left(\Sigma_1 + \Sigma_2 - 2\,(\Sigma_1 \Sigma_2)^{1/2}\right), where ∥⋅∥\lVert \cdot \rVert is the length of a vector, Tr\mathrm{Tr} is the trace (the sum of diagonal entries), and (Σ1Σ2)1/2(\Sigma_1 \Sigma_2)^{1/2} is a matrix square root.

Step 1 in symbols: the features

Each image xx becomes a feature vector f(x)∈Rdf(x) \in \mathbb{R}^d from the network's last pooling layer, with d=2048d = 2048 in the common setup. The network is an image network trained on a large classification dataset and then frozen, a use of Transfer Learning. Its job is only to give a useful description of an image.

Step 2 in symbols: the means

For a set of NN images, the mean is μ=1N∑i=1Nf(xi)\boldsymbol{\mu} = \frac{1}{N}\sum_{i=1}^{N} f(x_i), and the covariance is Σ=1N−1∑i=1N(f(xi)−μ)(f(xi)−μ)⊤\Sigma = \frac{1}{N-1}\sum_{i=1}^{N} (f(x_i) - \boldsymbol{\mu})(f(x_i) - \boldsymbol{\mu})^{\top}. In the toy example d=1d = 1, so Σ\Sigma is just a variance σ2\sigma^2, and μ1=0\mu_1 = 0, σ1=1\sigma_1 = 1, μ2=1\mu_2 = 1, σ2=2\sigma_2 = 2 give the variances σ12=1\sigma_1^2 = 1 and σ22=4\sigma_2^2 = 4.

Step 3 in symbols: the mean term

The first term is the squared distance between the two centres, ∥μ1−μ2∥2\lVert \boldsymbol{\mu}_1 - \boldsymbol{\mu}_2 \rVert^2. In the toy example it is (0−1)2=1(0 - 1)^2 = 1.

Step 4 in symbols: the spread term

When d=1d = 1 the trace term reduces to σ12+σ22−2σ1σ2=(σ1−σ2)2\sigma_1^2 + \sigma_2^2 - 2\sigma_1\sigma_2 = (\sigma_1 - \sigma_2)^2, which gives (1−2)2=1(1 - 2)^2 = 1 as in step 4 of the walkthrough. In general the trace term is zero exactly when the two covariance matrices are equal, since then (Σ1Σ2)1/2=Σ1(\Sigma_1 \Sigma_2)^{1/2} = \Sigma_1.

Swapping the real and generated sets gives the same value, because the trace of (Σ1Σ2)1/2(\Sigma_1 \Sigma_2)^{1/2} equals the trace of (Σ2Σ1)1/2(\Sigma_2 \Sigma_1)^{1/2}.

Step 5 in symbols: the total

Add the two terms. The result is never negative: the first is a squared length, and the trace term is the squared Bures distance between the two covariance matrices, a standard measure of how far apart two covariance matrices are. It is zero only when they are equal.

00.511.522.5302468distance between meansFID
  • FID for means a distance x apart, equal spreads
With equal spreads the mean term is the squared distance between centres. Moving the generated set twice as far multiplies FID by four.

Worked examples

Example
1. Tiny: one feature, identical spread

Real features: mean 0, standard deviation 1. Generated features: mean 3, standard deviation 1.

  1. Mean term: (0−3)2=9(0 - 3)^2 = 9.
  2. Spread term: (1−1)2=0(1 - 1)^2 = 0, because the spreads are equal.
  3. Add: FID =9+0=9= 9 + 0 = 9.
  4. Interpretation: the generator has the right spread but its outputs sit three units away from the real images. Shifting its centre is the whole fix.
Example
2. Standard: two features, diagonal covariances

Real features: μ1=(0,0)\boldsymbol{\mu}_1 = (0, 0) and Σ1=diag(1,1)\Sigma_1 = \mathrm{diag}(1, 1). Generated features: μ2=(1,2)\boldsymbol{\mu}_2 = (1, 2) and Σ2=diag(4,9)\Sigma_2 = \mathrm{diag}(4, 9).

  1. Mean difference: (0−1,0−2)=(−1,−2)(0 - 1, 0 - 2) = (-1, -2). Its squared length is 1+4=51 + 4 = 5.
  2. Product of covariances: Σ1Σ2=diag(1×4, 1×9)=diag(4,9)\Sigma_1 \Sigma_2 = \mathrm{diag}(1 \times 4,\ 1 \times 9) = \mathrm{diag}(4, 9).
  3. Square root: (Σ1Σ2)1/2=diag(2,3)(\Sigma_1 \Sigma_2)^{1/2} = \mathrm{diag}(2, 3), since 22=42^2 = 4 and 32=93^2 = 9.
  4. Inside the trace: Σ1+Σ2−2(Σ1Σ2)1/2=diag(1+4−4, 1+9−6)=diag(1,4)\Sigma_1 + \Sigma_2 - 2(\Sigma_1\Sigma_2)^{1/2} = \mathrm{diag}(1 + 4 - 4,\ 1 + 9 - 6) = \mathrm{diag}(1, 4).
  5. Trace of diag(1,4)\mathrm{diag}(1, 4): 1+4=51 + 4 = 5.
  6. Add the two terms: FID =5+5=10= 5 + 5 = 10.
  7. Check per axis: the first axis contributes (1−2)2=1(1 - 2)^2 = 1 and the second (1−3)2=4(1 - 3)^2 = 4, which sum to 5 as in step 5.
Example
3. Realistic: three summary features of a generator

Real images are summarised by three features (say sharpness, colour balance and texture). Real features: mean (0,0,0)(0, 0, 0) and Σ1=diag(1,1,1)\Sigma_1 = \mathrm{diag}(1, 1, 1). Generated features: mean (0.5,0,0)(0.5, 0, 0) and Σ2=diag(1,0.25,4)\Sigma_2 = \mathrm{diag}(1, 0.25, 4).

  1. Mean term: 0.52=0.250.5^2 = 0.25.
  2. Per-axis products under the square root: 1×1=11 \times 1 = 1, 1×0.25=0.251 \times 0.25 = 0.25, 1×4=41 \times 4 = 4. Their square roots are 11, 0.50.5 and 22.
  3. Axis 1 of the trace term: 1+1−2×1=01 + 1 - 2 \times 1 = 0.
  4. Axis 2: 1+0.25−2×0.5=0.251 + 0.25 - 2 \times 0.5 = 0.25.
  5. Axis 3: 1+4−2×2=11 + 4 - 2 \times 2 = 1.
  6. Trace term: 0+0.25+1=1.250 + 0.25 + 1 = 1.25.
  7. FID =0.25+1.25=1.5= 0.25 + 1.25 = 1.5.
  8. Reading: the generated images are a little shifted in sharpness and far too varied in texture, the third axis. The third term is the largest, so texture is where the generator differs most.

Try it: suppose the generator's third variance were 1 instead of 4, with the other numbers unchanged. What is the new FID? Answer: the third axis now contributes 1+1−2=01 + 1 - 2 = 0, so the trace term is 0+0.25+0=0.250 + 0.25 + 0 = 0.25, and the FID is 0.25+0.25=0.50.25 + 0.25 = 0.5.

Common mistakes and tradeoffs

It is tempting to think FID compares images pixel by pixel. In fact it compares only the means and covariances of the network's features, so two very different images can give similar statistics. A generator can produce pictures that are individually convincing and still score badly if it misses a whole kind of image, and the reverse can also happen.

It is tempting to think a small FID means the generator is good for every purpose. In fact FID depends on the feature network, the number of samples and the dataset. Two papers that use different networks or sample sizes report numbers that cannot be compared directly, and FID is biased upward when there are few samples.

It is tempting to think FID measures diversity and quality separately. In fact it blends them. A model that copies the training set perfectly scores very well, which is why people also report precision and recall for generative models.

When to use FID: comparing models on the same dataset, with the same network and sample count, and tracking one model over training. When not to use it: judging a single image, comparing numbers from different protocols, or small datasets. Alternatives include human ratings, precision and recall measures, and task-specific metrics.

History

Before FID, the standard score for generated images was the Inception Score, which uses the classifier's confidence on each image and does not compare against real statistics. It was easy to fool and could not see when a model had collapsed to one kind of image.

In 2017 Martin Heusel and colleagues proposed FID. They used the features of the Inception-v3 network, a convolutional network trained on ImageNet, and compared the Gaussian fitted to real features with the one fitted to generated features. Their paper also showed that FID tracks the quality of generated images in training and is sensitive to mode collapse.

FID caught on because it was simple, required no human labels, and could be computed with a fixed network, so papers could report it and others could repeat it. It became the default generative image metric, and researchers have since pointed out its sensitivity to sample size and feature network.

Recap

  • Each image is turned into a vector by a fixed pretrained network, so each set of images becomes a cloud of vectors.
  • Each cloud is summarised by a mean and a covariance matrix, which is a Gaussian fit.
  • FID adds the squared distance between the means to a trace term that measures how different the covariances are.
  • Lower FID means the generated set is closer to the real set in the feature space, under one protocol.
  • Next read generative adversarial networks, diffusion models and generative models, whose outputs FID is used to judge.

Check yourself

QuestionTwo one-feature sets have means 0 and 2, and both have standard deviation 1. What is FID?Show answer

The mean term is (0−2)2=4(0 - 2)^2 = 4. The spread term is (1−1)2=0(1 - 1)^2 = 0 because the spreads are equal. The total is 4.

QuestionReal features have covariance diag(1, 1). Generated features have covariance diag(9, 1). The means are equal. What is FID?Show answer

The product is diag(9, 1) and its square root is diag(3, 1). The trace term is (1+9−6)+(1+1−2)=4+0=4(1 + 9 - 6) + (1 + 1 - 2) = 4 + 0 = 4. With equal means, FID is 4.

QuestionWhy does a fixed image network matter? Why not learn the features during each comparison?Show answer

If the features changed between comparisons, two numbers would not measure the same thing, and a model could be ranked differently just because the feature network moved. A fixed network gives one shared description of images, so FID values are comparable across models and over training.

QuestionA paper reports FID 12 on 1,000 generated images, and another reports FID 9 on 50,000 images with a different feature network. Can you say the second model is better?Show answer

No. FID depends on the sample size and the feature network, and small samples bias it upward. The two numbers come from different protocols, so they cannot be compared directly. The fair comparison is with the same network and the same number of samples.

Sources