Task: Compute the Frechet Inception Distance Between Two Feature Sets
When evaluating generative image models, we compare the distribution of features extracted from real images against the distribution extracted from generated images. A widely used summary statistic fits both sets with multivariate Gaussians and measures the distance between them.
Implement fid_score(real_features, generated_features) that:
- Takes two arrays of shape
(N1, D) and (N2, D) containing feature vectors for real and generated samples.
- Fits a multivariate Gaussian to each set by computing its sample mean vector and sample covariance matrix (use the unbiased estimator, i.e. divide by
N - 1).
- Returns the scalar distance between the two Gaussians as a Python
float.
Notes
- The covariance of each set should be treated as a 2D matrix even when
D = 1.
- Because of floating-point noise, matrix eigenvalues that should be non-negative may come out slightly negative; clip them at zero before taking square roots.
- Do not round inside your function; the test harness handles rounding.
Input
real_features: array-like of shape (N1, D)
generated_features: array-like of shape (N2, D)
Output