diff options
| author | gdamms <damguillotin@gmail.com> | 2024-06-19 16:59:43 +0200 |
|---|---|---|
| committer | gdamms <damguillotin@gmail.com> | 2024-06-19 16:59:43 +0200 |
| commit | 577b5708f0a3975083329f05e6e4b118987f9828 (patch) | |
| tree | 4273a0a33b7580fb9e765667bbb6c83d9e8c79cf /utils.py | |
| parent | 3b82ce5f658ab27ed6e6eaddf239c553f9431b3e (diff) | |
| download | diffusion-mnist-577b5708f0a3975083329f05e6e4b118987f9828.tar.gz diffusion-mnist-577b5708f0a3975083329f05e6e4b118987f9828.zip | |
mise en place fid
Diffstat (limited to 'utils.py')
| -rw-r--r-- | utils.py | 25 |
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) |
