在Keras中拟合生成器和数据增强 [英] Fit generator and data augmentation in keras

查看:85
本文介绍了在Keras中拟合生成器和数据增强的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含5个样本的测试数据集和一个包含2000个样本的训练数据集.我想扩充我的数据集,并遵循 keras

I have a test dataset of 5 samples and a train dataset of 2000 samples. I would like to augment my datasets and I am following the example provided by keras

datagen_test = ImageDataGenerator(
                featurewise_center=True,
                featurewise_std_normalization=True,
                rotation_range=20,
                width_shift_range=0.2,
                height_shift_range=0.2,
                horizontal_flip=True
                )
datagen_train = ImageDataGenerator(
                featurewise_center=True,
                featurewise_std_normalization=True,
                rotation_range=20,
                width_shift_range=0.2,
                height_shift_range=0.2,
                horizontal_flip=True
                )
datagen_train.fit(x_train)
validation_generator = datagen_test.flow(x_test, y_test, batch_size=5)


model.compile(loss=keras.losses.categorical_crossentropy,
          optimizer='rmsprop',
          metrics=['accuracy'])
# fits the model on batches with real-time data augmentation:
model.fit_generator(datagen_train.flow(x_train, y_train, batch_size=50),
                steps_per_epoch=len(x_train) / 10, epochs=epochs, 
                validation_data=validation_generator, validation_steps=800)

我相信 steps_per_epoch 参数是传递给分类器的批次数.我将生成器中的 batch_size 设置为50,但是我只有5个样本.我认为我的问题与 samples_per_epoch 没有关系, samples_per_epoch 是一个纪元中处理的样本数.

What I believe is that the steps_per_epoch parameter is the number of batches passed to the classifier. I set the batch_size in my generator to be 50, however I have only 5 samples. I think my questions has nothing to do with the samples_per_epoch which is the the number of samples processed in one epoch.

我的问题是: 生成器将转换我的图像以创建50个不同样本并将其传递给分类器,还是仅转换5个?

My question is: Will the generator transform my images in order to create 50 different samples and pass them to the classifier or will transform only 5?

推荐答案

不幸的是-当您将batch_size设置为50时,如果只有5个示例,则生成器将每批仅返回5个示例(尽管batch_size).因此,它不会将您的批次扩展到50.

Unfortunately - when you set the batch_size to 50 when you have only 5 examples will make your generator to return only 5 examples in each batch (despite the batch_size). So it will not extend your batch to 50.

这篇关于在Keras中拟合生成器和数据增强的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆