[英]How to simultaneously apply augmentation to X_train and y_train
I am facing this problem of creating a dataset from a very few images.我面临着从很少的图像创建数据集的问题。
Both input ( X_train
) and output ( y_train
) contains (28x28) size images such as MNIST.输入 (
X_train
) 和输出 ( y_train
) 都包含 (28x28) 大小的图像,例如 MNIST。 For example in my code:例如在我的代码中:
(X_train, y_train), (X_test, y_test) = mnist.load_data()
X_train = X_train.reshape((X_train.shape[0], 28, 28, 1))
X_train = X_train.astype('float32')
y_train=X_train
datagen = ImageDataGenerator(zca_whitening=True)
How can I fit this datagen
to both X_train
and y_train
simultaneously and save them in a dataset array.我怎样才能同时将这个
datagen
到X_train
和y_train
并将它们保存在数据集数组中。 Don't want to pass it to training.不想把它传递给训练。
Thank you for the help感谢您的帮助
Beware that augmentation per se is not applied on the target variable y_train
but only on the input variables X_train
.请注意,增强本身并不应用于目标变量
y_train
而仅应用于输入变量X_train
。 The generator is only going to reproduce the same ground truth labels y
for the newly generated X
.生成器只会为新生成的
X
重现相同的真实标签y
。
Hence fitting the generator is only using X_train
:因此拟合生成器仅使用
X_train
:
datagen.fit(X_train)
If you do not want to pass the augmented data to training, you can loop over the generator after fitting to get the generated samples:如果不想将增强数据传递给训练,可以在拟合后循环生成器以获取生成的样本:
for X_batch, y_batch in datagen.flow(X_train, y_train, batch_size=32):
# Do whatever you want with the generated X_batch and y_batch.
I understand that is what you are willing to do.我明白这是你愿意做的。 See examples on keras doc .
请参阅keras doc上的示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.