gpt4 book ai didi

python - 数据增强期间的 Keras CONV 训练似乎显示错误的批量大小和训练示例数量

转载 作者:行者123 更新时间:2023-12-01 02:49:37 25 4
gpt4 key购买 nike

我正在学习如何使用 Keras 和 CIFAR-10 数据集实现数据增强。我正在在线教程和这本书的帮助下学习Deep learning with Keras.

代码具体详情为here .

这是我的问题,我确信它与我的一些误解有关:

这是我的 CONV 设置。

 IMG_CHANNELS = 3
IMG_ROWS = 32
IMG_COLS = 32
BATCH_SIZE = 128
NB_EPOCH = 50
NB_CLASSES = 10
VERBOSE = 1
VALIDATION_SPLIT = 0.2
OPTIM = RMSprop()

加载数据集,转换为分类、 float 并标准化:

(X_train, y_train), (X_test, y_test) = cifar10.load_data()
Y_train = np_utils.to_categorical(y_train, NB_CLASSES)
Y_test = np_utils.to_categorical(y_test, NB_CLASSES)
X_train = X_train.astype('float32')
X_test = X_test.astype('float32')
X_train /= 255
X_test /= 255

创建生成器

datagen = ImageDataGenerator(
featurewise_center=False, # set input mean to 0 over the dataset
samplewise_center=False, # set each sample mean to 0
featurewise_std_normalization=False, # divide inputs by std of the dataset
samplewise_std_normalization=False, # divide each input by its std
zca_whitening=False, # apply ZCA whitening
rotation_range=0, # randomly rotate images in the range (degrees, 0 to 180)
width_shift_range=0.1, # randomly shift images horizontally (fraction of total width)
height_shift_range=0.1, # randomly shift images vertically (fraction of total height)
horizontal_flip=True, # randomly flip images
vertical_flip=False) # randomly flip images
datagen.fit(X_train)

训练模型(我没有列出模型)

model.fit_generator(datagen.flow(X_train, Y_train,
batch_size=BATCH_SIZE),
samples_per_epoch=X_train.shape[0],
nb_epoch=NB_EPOCH,
verbose=VERBOSE)

我的问题是,当我训练时,会显示以下内容:

 Epoch 1/40
390/390 [==============================] - 199s - loss: 0.9751 - acc: 0.6588

我不明白为什么我会得到 390 个示例。 Samples_per_epoch 等于 X_train.shape[0],即 50000,批处理大小为 128,因此我认为它应该以 128 为批处理,达到 50000。

最佳答案

进度条不显示样本数,而是显示步骤数或批处理数(当您使用 model.fit 而不是 model.fit_generator 时,它会自动显示显示样本)。每批处理包含128个 sample ,总共50,000个 sample 。 50,000/128 = 390.625。这就是为什么您看到的是 390 而不是 50,000。

由于您正在使用model.fit_generator,因此无法显示样本总数。除非您将 batch_size 设置为 1。原因是生成器预计会无限循环其数据,直到 steps_per_epochssamples_per_epoch 达到阈值 (*) .

顺便说一句,您可以在 model.fit 中使用回调 ProgbarLogger 更改此设置,请查看 here .

关于python - 数据增强期间的 Keras CONV 训练似乎显示错误的批量大小和训练示例数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44923831/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com