我是深度学习的新手。我正在尝试将mnist图像从28*28更改为224 * 224。
所以我决定使用调整大小的方法。导入MNIST数据集后,我尝试调整它的大小:
(X_train, y_train), (X_test, y_test) = mnist.load_data()
x_train_small = tf.image.resize(X_train, (224,224)).numpy()
但是我得到了这个错误
MemoryError: Unable to allocate 11.2 GiB for an array with shape (60000, 224, 224, 1) and data type float32
我的电脑是旧的,我只有16gram。如何调整Mnist数据集的大小?
考虑使用tf.data.Dataset
并在批处理通过时动态调整图像大小:
import tensorflow as tf
(X_train, y_train), (X_test, y_test) = tf.keras.datasets.mnist.load_data()
resize = lambda x, y: (tf.image.resize(tf.expand_dims(x, -1), (224, 224)), y)
train_ds = tf.data.Dataset.from_tensor_slices((X_train, y_train)).map(resize)
for image, label in train_ds.take(5):
print(image.shape)
(224, 224, 1)
(224, 224, 1)
(224, 224, 1)
(224, 224, 1)
(224, 224, 1)
你可以直接将这个数据集传递给model.fit(train_ds)