简体   繁体   中英

Is there a way to use Keras ImageDataGenerator flow from directory with a mask as the output

I am having trouble setting up flow_from_directory with the Keras 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)

My directory structure is below, where each mask image is a binary image of the class locations, equal to the size of the input image.

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

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

The error that I am getting this:

'AttributeError: 'tuple' object has no attribute 'shape''

I was able to implement the 'flow' type ImageDataGenerator but for some reason, the flow_from_directory is giving me issues.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM