aboutsummaryrefslogtreecommitdiff
path: root/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'utils.py')
-rw-r--r--utils.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/utils.py b/utils.py
new file mode 100644
index 0000000..19a0426
--- /dev/null
+++ b/utils.py
@@ -0,0 +1,25 @@
+import numpy as np
+
+
+def fid(reals, fakes):
+ """FID score calculation.
+
+ Args:
+ reals (numpy.array): Real images.
+ fakes (numpy.array): Fake images.
+ """
+ print(reals.shape, fakes.shape)
+ reals = reals.reshape(reals.shape[0], -1)
+ fakes = fakes.reshape(fakes.shape[0], -1)
+
+ mu_real = np.mean(reals, axis=0)
+ mu_fake = np.mean(fakes, axis=0)
+ sigma_real = np.cov(reals, rowvar=False)
+ sigma_fake = np.cov(fakes, rowvar=False)
+
+ diff = mu_real - mu_fake
+ covmean = np.dot(sigma_real, sigma_fake.T)
+ covmean = np.sqrt(covmean * (covmean > 0))
+ print(np.trace(covmean))
+
+ return diff @ diff + np.trace(sigma_real) + np.trace(sigma_fake) - 2 * np.trace(covmean)