def compute_fid(fake_features, real_features):
    """Computes FID based on the features extracted from fake and real data.

    Given the mean and covariance (m_f, C_f) of fake data and (m_r, C_r) of real
    data, the FID metric can be computed by

    d^2 = ||m_f - m_r||_2^2 + Tr(C_f + C_r - 2(C_f C_r)^0.5)

    Args:
        fake_features: The features extracted from fake data.
        real_features: The features extracted from real data.

    Returns:
        A real number, suggesting the FID value.
    """

    m_f = np.mean(fake_features, axis=0)
    C_f = np.cov(fake_features, rowvar=False)
    m_r = np.mean(real_features, axis=0)
    C_r = np.cov(real_features, rowvar=False)

    fid = np.sum((m_f - m_r) ** 2) + np.trace(
        C_f + C_r - 2 * scipy.linalg.sqrtm(np.dot(C_f, C_r)))
    return np.real(fid)
Computes FID based on the features extracted from fake and real data.

    Given the mean and covariance (m_f, C_f) of fake data and (m_r, C_r) of real
    data, the FID metric can be computed by

    d^2 = ||m_f - m_r||_2^2 + Tr(C_f + C_r - 2(C_f C_r)^0.5)

    Args:
        fake_features: The features extracted from fake data.
        real_features: The features extracted from real data.

    Returns:
        A real number, suggesting the FID value.
    
metrics/fid.py