有没有一种方法可以使用带有掩码作为输出的目录中的Keras ImageDataGenerator流

时间:2019-04-30 01:31:57

标签: python tensorflow keras

我无法使用Keras flow_from_directory来设置ImageDataGenerator


def get_generators():

    train_image_generator = train_datagen.flow_from_directory(DATA_PATH + '/train_frames',batch_size=batch_size)
    train_mask_generator = train_datagen.flow_from_directory(DATA_PATH + '/train_masks',batch_size=batch_size, class_mode='categorical')

    val_image_generator = val_datagen.flow_from_directory(DATA_PATH + '/val_frames',batch_size=batch_size)
    val_mask_generator = val_datagen.flow_from_directory(DATA_PATH + '/val_masks',batch_size=batch_size, class_mode='categorical')

    train_generator = zip(train_image_generator, train_mask_generator)
    val_generator = zip(val_image_generator, val_mask_generator)

    return train_generator, val_generator;

train_gen, val_gen = generator_objects.get_generators()
results = m.fit_generator(train_gen, epochs=NO_OF_EPOCHS,
                          steps_per_epoch = (NO_OF_TRAINING_IMAGES//BATCH_SIZE),
                          callbacks=callbacks_list)

我的目录结构在下面,其中每个蒙版图像都是类位置的二进制图像,等于输入图像的大小。

/train_frames
     /images
        /1.jpg
        /2.jpg

/train_masks 
     /0
        /1.jpg
        /2.jpg
     /1
        /1.jpg
        /2.jpg
     /2
      ....

我得到这个错误:

  

'AttributeError:'tuple'对象没有属性'shape'

我能够实现'flow'类型的ImageDataGenerator,但是由于某种原因,flow_from_directory给了我很多麻烦。

1 个答案:

答案 0 :(得分:0)

尝试将class_mode='categorical'更改为class_mode=None