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.
- 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.
- Summarise each set as a Gaussian. The real set has mean and spread . The generated set has mean and spread . A Gaussian is fully described by these two numbers.
- Compare the centres. The difference of the means is , and its square is 1. This is the cost of the two sets sitting in different places.
- Compare the spreads. The spread term is . This is the cost of one set being wider than the other.
- Add them up. FID . 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
Let the real features have mean and covariance matrix , and the generated features have mean and covariance matrix . Then where is the length of a vector, is the trace (the sum of diagonal entries), and is a matrix square root.
Step 1 in symbols: the features
Each image becomes a feature vector from the network's last pooling layer, with 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 images, the mean is , and the covariance is . In the toy example , so is just a variance , and , , , give the variances and .
Step 3 in symbols: the mean term
The first term is the squared distance between the two centres, . In the toy example it is .
Step 4 in symbols: the spread term
When the trace term reduces to , which gives as in step 4 of the walkthrough. In general the trace term is zero exactly when the two covariance matrices are equal, since then .
Swapping the real and generated sets gives the same value, because the trace of equals the trace of .
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.
- FID for means a distance x apart, equal spreads
Worked examples
Real features: mean 0, standard deviation 1. Generated features: mean 3, standard deviation 1.
- Mean term: .
- Spread term: , because the spreads are equal.
- Add: FID .
- 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.
Real features: and . Generated features: and .
- Mean difference: . Its squared length is .
- Product of covariances: .
- Square root: , since and .
- Inside the trace: .
- Trace of : .
- Add the two terms: FID .
- Check per axis: the first axis contributes and the second , which sum to 5 as in step 5.
Real images are summarised by three features (say sharpness, colour balance and texture). Real features: mean and . Generated features: mean and .
- Mean term: .
- Per-axis products under the square root: , , . Their square roots are , and .
- Axis 1 of the trace term: .
- Axis 2: .
- Axis 3: .
- Trace term: .
- FID .
- 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 , so the trace term is , and the FID is .
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 . The spread term is 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 . 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
- GANs Trained by a Two Time-Scale Update Rule Converge to a Local Nash Equilibrium (Heusel et al., 2017): https://arxiv.org/abs/1706.08500
- Rethinking the Inception Architecture for Computer Vision (Szegedy et al., 2015): https://arxiv.org/abs/1512.00567