Precision and recall for generative models
How to split the fidelity of samples from their diversity — precision and recall via nearest-neighbour balls, density and coverage, and where these metrics break.
One number, two failures
The topic Fréchet Inception Distance warned that FID mixes two failures in one number. Here is how completely it can mix them.
Let the real features be a 2-D standard Gaussian, , and let a model draw from . The means agree, and , so the FID formula reduces to
Take and . Both give . Yet the two models fail in opposite ways.
The collapsed model, , puts about 99% of its samples within radius of the center. Each of them is a perfectly plausible real point. But that disc holds only a third of the real data, and the rest is never drawn. High fidelity, poor diversity.
The spread-out model, , reaches every region of the data. But half of its samples land beyond radius , where only 14% of the real data lives. Good diversity, poor fidelity.
We want two numbers instead of one, one for each failure.
Where the mass lands
The names come from search engines. Precision: of the results you returned, how many are relevant? Recall: of the relevant documents, how many did you return?
For distributions, Sajjadi et al. (2018) ask the same two questions about supports. The support is the region where puts its mass. Then
Precision is the share of the model's samples that land where real data occurs. Recall is the share of the real data that lands where the model generates.
For our Gaussians we must read "support" loosely, as the region that holds most of the mass. A Gaussian's literal support is the whole plane, and both numbers would be for every model. Read loosely, the collapsed model has precision near and recall near a third.
The definitions become exact in a discrete picture. Split the images into clusters, and each distribution turns into a vector of cluster probabilities. Sajjadi et al. cluster the features into 20 clusters with k-means and work in exactly this picture.
Balls around neighbours
Features have 2048 dimensions, and we know neither support. Kynkäänniemi et al. (2019) estimate them from the samples themselves, as the topic Fréchet Inception Distance briefly sketched. Here are the details.
Write for the real features and for the generated ones. For a real point, let be the distance to its -th nearest neighbour among the other real points. The union of balls
is the estimated real manifold, a stand-in for . The radius adapts to the data: crowded regions get small balls, sparse regions get large ones. The generated manifold is built the same way from the .
Precision counts samples inside the real manifold. Recall counts real points inside the generated one:
The paper uses , images per side and features of VGG-16, another frozen ImageNet classifier. Any fixed feature network works, as with FID. The number is a knob: it decides how generously the balls bridge the gaps between samples.
Precision and recall by hand
Let us compute both numbers by hand. One dimension, , four points per side:
Precision. Every real point's nearest real neighbour is away, so each real ball has radius . Together they cover . The samples , and fall inside; does not. Precision is .
Recall. Now the balls sit around the generated points, with radii from the generated set:
| Sample | Nearest other sample | Radius | Ball |
|---|---|---|---|
Recall is the share of real points that fall into at least one of these balls. Count them yourself.
Density and coverage
In the example, is the worst sample, yet it raised recall from to . Its huge ball swallowed the real points and . It works the other way too: a real outlier gets a huge ball, and bad samples inside it count toward precision. Unions of balls trust every point, outliers included.
Naeem et al. (2020) keep only the real balls. We choose the real set, so we can trust it more than the model's output. Write .
Density counts how many real balls contain each sample:
A sample in a crowded real region counts several times; an isolated one counts zero times. For a perfect model, density is on average in any dimension. A fresh sample lands in when it is closer to than 's -th real neighbour, which happens with probability . Density can exceed when samples pile up in dense regions.
Coverage asks, for every real point, whether its own ball caught at least one sample:
A sample far from the data lands in no real ball, so it cannot raise coverage. In the example the ball of the real point is , it catches nothing, and coverage is .
Even a perfect model does not reach coverage . Pool the other real points with the samples and sort them by distance to . Then stays uncovered exactly when its nearest pooled points are all real. For a perfect model every point comes from the same distribution, so every order is equally likely. With large, each nearest point is real with probability about , and coverage is about . The paper takes , which gives about .
The knob between precision and recall
Back to the two Gaussians. We take points per side, for precision and recall, for density and coverage, and average 20 runs:
| Model | FID | Precision | Recall | Density | Coverage |
|---|---|---|---|---|---|
| Collapsed, | |||||
| Matched, | |||||
| Spread out, |
The pairs separate the two models that FID could not. Even the matched model scores a bit below on precision, recall and coverage: the samples are finite.
Many generators have a knob that slides along this table. In Latent diffusion, a larger guidance scale traded diversity for fidelity. A VAE can sample with temperature , drawing . Large GANs use the truncation trick: draw , but redraw every coordinate whose magnitude exceeds a threshold. Turned toward "safe", each knob moves the model from toward .
So report the pair, or a curve along the knob, never one average of the two. Which end matters depends on the use. A tool that makes stock photos needs precision. A generator of training data for another model needs recall.
Where the balls fail
Now take a perfect model, , with points per side and . Precision and recall come out at about for , for and for . Density and coverage stay near and . Real features have hundreds or thousands of dimensions.
The cause is distance concentration. For two independent points of , is a sum of independent terms, with mean and standard deviation . Its relative spread is
It equals for and for . All distances crowd around one value. Expand . The term is the same for every ball. A sample a little farther from the center than usual is a little too far from every real point and misses all balls at once. A sample a little closer lands in many. Precision counts each sample once, so the misses cost it. Density counts every ball, so the extra hits make up for the misses.
The fine print from FID applies here too. All four numbers depend on , on the sample size and on the feature network, so compare them only under the same settings. The cost is quadratic: points per side means distances.
Every metric so far scores whole sets of images. None says whether one reconstruction is close to its original, or whether two samples for the same prompt really differ. For that we need a distance between two single images that agrees with a human eye. Pixels fail, as a one-pixel shift showed in Fréchet Inception Distance. The next topic builds such a distance from deep features and calibrates it on human judgements: LPIPS.
Check your understanding
The same questions as in Pulse. Answers are shared between modes.
Answers are saved on the server and tied to this browser until you sign in.