[英]input ran out of data; interrupting training
I am trying to train a model with the dataset consisting of 160 images (80 -cars, 80 -planes) using image data-augmentation generators on TensorFlow v2.1.我正在尝试使用 TensorFlow v2.1 上的图像数据增强生成器来训练 model 的数据集,该数据集包含 160 个图像(80 个汽车,80 个飞机)。 I am getting an error when I run the following code:
运行以下代码时出现错误:
classifier.compile(optimizer='adam', loss='binary_crossentropy',
metrics=['accuracy'])
from keras.preprocessing.image import ImageDataGenerator
train_imagedata = ImageDataGenerator(rescale=1. / 255, shear_range=0.2,
zoom_range=0.2, horizontal_flip=True)
test_imagedata = ImageDataGenerator(rescale=1. / 255)
training_set = \
train_imagedata.flow_from_directory('data/training_set'
, target_size=(64, 64), batch_size=32, class_mode='binary')
val_set = \
test_imagedata.flow_from_directory('data/val_set'
, target_size=(64, 64), batch_size=32, class_mode='binary')
history=classifier.fit(training_set, steps_per_epoch=30, epochs=30,
validation_data=val_set,
validation_steps=30)
The error is:错误是:
Found 160 images belonging to 2 classes.
Found 40 images belonging to 2 classes.
Epoch 1/30
5/30 [====>.........................] - ETA: 5s - loss: 0.5002 - accuracy: 0.8313WARNING:tensorflow:Your input ran out of data; interrupting training. Make sure that your dataset or generator can generate at least `steps_per_epoch * epochs` batches (in this case, 900 batches). You may need to use the repeat() function when building your dataset.
WARNING:tensorflow:Your input ran out of data; interrupting training. Make sure that your dataset or generator can generate at least `steps_per_epoch * epochs` batches (in this case, 30 batches). You may need to use the repeat() function when building your dataset.
5/30 [====>.........................] - 2s 416ms/step - loss: 0.5002 - accuracy: 0.8313 - val_loss: 1.6599 - val_accuracy: 0.5000
Please suggest what could be done here to rectify this error?请建议在这里可以做些什么来纠正这个错误? Thanks in Advance!
提前致谢!
ImageDataGenerator has a default batch_size
of 32. you asked to perform 30 steps per epoch, which means 30*32 images per epoch, but you have only 160 images, hence after 5 batches the training collapse. ImageDataGenerator 的默认
batch_size
为 32。您要求每个 epoch 执行 30 个步骤,这意味着每个 epoch 30*32 个图像,但您只有 160 个图像,因此在 5 个批次后训练崩溃。 you need to set steps_per_epoch
to be floor(num_of_images / batch_size)
.您需要将
steps_per_epoch
设置为floor(num_of_images / batch_size)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.