FrechetInceptionDistance<T>
Models & Types · AiDotNet.Metrics
Fréchet Inception Distance (FID) - A metric for evaluating the quality of generated images.
FID measures how similar generated images are to real images by comparing their statistical properties in a feature space. Lower FID scores indicate better quality.
The algorithm:
- Extract features from images using a pre-trained neural network
- Compute statistics (mean and covariance) for real and generated image features
- Compute the Fréchet distance between the two Gaussian distributions
Formula: FID = ||μ₁ - μ₂||² + Tr(Σ₁ + Σ₂ - 2√(Σ₁Σ₂)) where μ is mean, Σ is covariance, Tr is trace
Typical FID scores:
- FID less than 10: Excellent quality
- FID 10-20: Good quality
- FID 20-50: Moderate quality
- FID greater than 50: Poor quality
Based on “GANs Trained by a Two Time-Scale Update Rule Converge to a Local Nash Equilibrium” by Heusel et al. (2017)
Constructors
| Constructor | Summary |
|---|---|
FrechetInceptionDistance(ConvolutionalNeuralNetwork<T> featureNetwork, int featureDimension) |
Initializes a new instance of FID calculator. |
Properties
| Property | Summary |
|---|---|
ConvolutionalNeuralNetwork<T> FeatureNetwork { get; } |
Gets the feature extraction network used for computing image representations. |
int FeatureDimension { get; } |
Gets the dimensionality of extracted features. |
int FeatureLayer { get; set; } |
Gets or sets the layer index from which to extract features. |
Methods
| Method | Summary |
|---|---|
T ComputeFID(Tensor<T> realImages, Tensor<T> generatedImages) |
Computes the FID score between real and generated images. |
T ComputeFIDWithStats(Vector<T> realMean, Matrix<T> realCov, Tensor<T> generatedImages) |
Computes FID using pre-computed statistics for the real distribution. |
ValueTuple<Vector<T>, Matrix<T>> PrecomputeStatistics(Tensor<T> images) |
Pre-computes statistics for a set of images. |