Keras fit_generator StopIteration:图块无法扩展到图像外部

时间:2019-03-28 19:55:47

标签: python-3.x keras python-imaging-library

我目前正在尝试使用来自两个目录的训练和测试数据生成器来拟合模型。

train_datagen = ImageDataGenerator(rescale = 1./255, horizontal_flip = True)
# output: Found 440 images belonging to 2 classes.
test_datagen = ImageDataGenerator(rescale=1./255)
# output: Found 554 images belonging to 2 classes.

training_generator = train_datagen.flow_from_directory('dir', batch_size=20, class_mode='categorical')
testing_generator = test_datagen.flow_from_directory('dir', batch_size=30, class_mode='categorical')

当我尝试运行时:

history = model.fit_generator(training_generator, epochs=150, validation_data=testing_generator, callbacks= [early_stopping_monitor, model_checkpoint])

我到达最后一批并收到两个StopIteration错误之一。

对于batch_size为20,我得到:

Epoch 1/150
21/22 [==================>..] - ETA: 0s - loss: 0.8482 - acc: 0.5619
Traceback (mostrecent call last):
...
File "...\keras\engine\\training_generator.py", line 309, in evaluate_generator
    generator_output=next(output_generator)

File "..\keras\utils\data_utils.py", line 583, in get
    six.raise_from(StopIteration(e), e)

StopIteration: tile cannot extend outside image

对于batch_size为24,我得到:

Epoch 1/150
18/19 [==================>..] - ETA: 0s - loss: 0.8482 - acc: 0.5619
Traceback (mostrecent call last):
...
File "...\keras\engine\\training_generator.py", line 309, in evaluate_generator
    generator_output=next(output_generator)

File "..\keras\utils\data_utils.py", line 583, in get
    six.raise_from(StopIteration(e), e)

StopIteration: -2

我不明白。我看到了:StopIteration: generator_output = next(output_generator),但这似乎是一个由自己创建数据生成器的人,因此编码器负责使生成器连续地能够提供数据。但是我使用的是flow_from_directory,所以这不足够聪明以找出如何始终提供数据吗?

我还读到,PIL可能试图访问图像的超出范围的问题。我编写了一个脚本来浏览我的图像目录,并根据How to check if a file is a valid image file?用PIL打开并验证它们,但是所有目录都不会引发异常。

我在这里想念什么?

0 个答案:

没有答案