Consider using a tf.data.Dataset
and resize images on the fly, as batches pass:
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)
You can pass this dataset directly to model.fit(train_ds)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…