basicsr.metrics.fid

basicsr.metrics.fid.calculate_fid(mu1, sigma1, mu2, sigma2, eps=1e-06)[source]

Numpy implementation of the Frechet Distance.

The Frechet distance between two multivariate Gaussians X_1 ~ N(mu_1, C_1) and X_2 ~ N(mu_2, C_2) is: d^2 = ||mu_1 - mu_2||^2 + Tr(C_1 + C_2 - 2*sqrt(C_1*C_2)). Stable version by Dougal J. Sutherland.

Parameters:
  • mu1 (np.array) – The sample mean over activations.

  • sigma1 (np.array) – The covariance matrix over activations for generated samples.

  • mu2 (np.array) – The sample mean over activations, precalculated on an representative data set.

  • sigma2 (np.array) – The covariance matrix over activations, precalculated on an representative data set.

Returns:

The Frechet Distance.

Return type:

float

basicsr.metrics.fid.extract_inception_features(data_generator, inception, len_generator=None, device='cuda')[source]

Extract inception features.

Parameters:
  • data_generator (generator) – A data generator.

  • inception (nn.Module) – Inception model.

  • len_generator (int) – Length of the data_generator to show the progressbar. Default: None.

  • device (str) – Device. Default: cuda.

Returns:

Extracted features.

Return type:

Tensor

basicsr.metrics.fid.load_patched_inception_v3(device='cuda', resize_input=True, normalize_input=False)[source]