3

我试图使用我对 Keras 文档中示例代码的修改,该文档显示了在使用图像掩码代替标签的情况下如何设置 image_datagen.flow_from_directory()(对于图像分割,我们正在预测一个类每个像素)。

顺便说一句,我设置 featurewise_center = True 试图从每个图像的颜色通道中减去所有训练图像的每个颜色通道的平均值,这样在整个训练集中,每个颜色通道的平均值将为 0。我希望这个不是实现这一目标的方法。

无论如何,这是我产生错误的代码:

image_datagen = ImageDataGenerator(featurewise_center = True)
mask_datagen = ImageDataGenerator()

image_generator = image_datagen.flow_from_directory(
    '/home/icg/Martin/train_data_graz/images_rect_r640x360',
    class_mode = None,
    batch_size = 1,
    seed = 123)

mask_generator = mask_datagen.flow_from_directory(
    '/home/icg/Martin/train_data_graz/labels_rect_r640x360',
    class_mode = None,
    batch_size = 1,
    seed = 123)

# combine generators into one which yields image and masks
train_generator = zip(image_generator, mask_generator)

model.fit_generator(
    train_generator,
    steps_per_epoch = 1000,
    epochs = 100)

这是错误消息:

Found 0 images belonging to 0 classes.
Found 0 images belonging to 0 classes.
Traceback (most recent call last):
  File "FCN_VGG16.py", line 178, in <module>
    train_generator = zip(image_generator, mask_generator)
  File "/home/icg/rafa/local/lib/python2.7/site-packages/keras/preprocessing/image.py", line 1026, in next
    index_array, current_index, current_batch_size = next(self.index_generator)
  File "/home/icg/rafa/local/lib/python2.7/site-packages/keras/preprocessing/image.py", line 720, in _flow_index
    current_index = (self.batch_index * batch_size) % n
ZeroDivisionError: integer division or modulo by zero

由于某种原因n = 0。任何想法为什么会发生这种情况?

4

1 回答 1

5

您需要将图像放入每个类的子文件夹flow_from_directory()中,放入函数的目录中。

在你的情况下:

/home/icg/Martin/train_data_graz/images_rect_r640x360/images_class01
/home/icg/Martin/train_data_graz/images_rect_r640x360/images_class02
…

编辑:

由于您已设置class_modeNone进行语义分割(请参阅评论和帖子):

/home/icg/Martin/train_data_graz/images_rect_r640x360/all_images
于 2017-08-04T17:50:41.550 回答