25Gb RAM中的Mnist Digits崩溃的FID分数Google Colab

时间:2020-06-11 18:03:52

标签: keras ram mnist

我正在尝试为Variational Autoencoder(在Keras中)计算FID分数,以测量生成的MNIST数字的质量。我有10.000个维度为(28、28、1)的样本,我需要在(299、299、3)中重塑形状,以将它们输入Inception_v3中以计算FID。这是我执行此操作的代码:

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)

但是当我用xpgen和X_real生成时

X_gen = np.zeros(shape=(sample_size, 299, 299, 3))

Colab会话崩溃,因为此操作似乎可以填充25Gb的RAM。为什么会这样呢?有没有更好的方法来计算MNIST数字的FID分数?

0 个答案:

没有答案