from tensorflow import keras from tensorflow.keras import layers import keras.backend as K import json import pickle import matplotlib.pyplot as plt import tensorflow_probability as tfp import Datasets IMG_SHAPE = (32, 32, 3) BATCH_SIZE = 64 # Size of the noise vector noise_dim = 100 dataset = Datasets.CelebA(zip_file_path='files/32x32.pickle') train_images = dataset.X def conv_block( x, filters, activation, kernel_size=(3, 3), strides=(1, 1), padding="same", use_bias=True, use_bn=False, use_dropout=False, drop_value=0.5, ):
self.samples = samples self.batch_size = batch_size self.name = 'FID' def calculate(self, model, dataset): noise = np.random.normal(0, 1, (self.samples, model.latent_dim)) images = model.generator.predict(noise) gan_fid = self.fd(images, batch_size=self.batch_size) return float(gan_fid) if __name__ == '__main__': import sys sys.path.append('../') sys.path.append('./') import Datasets import pickle dataset = Datasets.CelebA(size=64) fd = FrechetInceptionDistance(None, None, (-1, 1), 75) mean, cov = fd.stats(dataset.X, batch_size=32) print(mean, cov) save = {'mean': mean, 'cov': cov} with open('celeba_64_stats.pickle', 'wb') as handle: pickle.dump(save, handle)