I'm trying to compute the FID score for a Variational Autoencoder (in Keras) to measure the quality of generated MNIST digits. I have 10.000 samples of dimension (28, 28, 1) and I need to reshape in (299, 299, 3) to input them in Inception_v3 to compute FID. This is my code to do this:
from keras.applications.inception_v3 import preprocess_input
from keras.applications.inception_v3 import InceptionV3
sample_size = 4000
z_sample = np.random.normal(0, 1, size=(sample_size, latent_dim))
sample = np.random.randint(0, len(X_test), size=sample_size)
X_gen = decoder.predict(z_sample)
X_real = X_test[sample]
X_gen = scale_images(X_gen, (299, 299, 1))
X_real = scale_images(X_real, (299, 299, 1))
print('Scaled', X_gen.shape, X_real.shape)
X_gen_t = preprocess_input(X_gen)
X_real_t = preprocess_input(X_real)
X_gen = np.zeros(shape=(sample_size, 299, 299, 3))
X_real = np.zeros(shape=(sample_size, 299, 299, 3))
for i in range(3):
X_gen[:, :, :, i] = X_gen_t[:, :, :, 0]
X_real[:, :, :, i] = X_real_t[:, :, :, 0]
print('Final', X_gen.shape, X_real.shape)
but when I generate X_gen and X_real with
X_gen = np.zeros(shape=(sample_size, 299, 299, 3))
the Colab session crash, because this operation seems to fullfil 25Gb of RAM. Why this is happens? There is a better way to compute FID score for MNIST digits?