《Python 深度学习》第5章 P114 在运行以下代码有个报错:
history = model.fit_generator(
train_generator,
steps_per_epoch=100,
epochs=100,
validation_data=validation_generator,
validation_steps=50)
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, 10000 batches). You may need to use the repeat() function when building your dataset.
翻译:您的输入数据不足;中断训练。确保您的数据集或生成器至少可以生成“steps_per_epoch*epochs”批。(在本例中为10000批)。在构建数据集时,可能需要使用repeat()函数。
报错产生原因:
我们训练图像有2000张,验证图像1000张,和1000张测试图像。
steps_per_epoch=100,batch_size=32,如此数据应该是3200张,很明显输入训练数据不够。
validation_steps=50,batch_size=32,如此数据应该是1600张,很明显验证数据不够。
因此,改为steps_per_epoch=2000/32≈63,validation_steps=1000/32≈32。
history = model.fit_generator(
train_generator,
steps_per_epoch=63,
epochs=100,
validation_data=validation_generator,
validation_steps=32)
可以运行!但是可能还是有些纰漏。
参考链接:
WARNING:tensorflow:Your input ran out of data; interrupting training. Make sure that your dataset or
Your input ran out of data; interrupting training. Make sure that your dataset or generat