简体   繁体   中英

Keras ImageDataGenerator method flow_from_directory

I have a question concerning the flow_from_directory method of ImageDataGenerator. My labels are 2D images so I need to generate augmented data with the same transformation for both images and masks. Reading the doc https://keras.io/preprocessing/image/ looks like flow_from_directory accept only images in a few formats (PNG, JPG or BMP). What about .mhd images or directly numpy array? Can I feed them to this module? Thanks

flow_from_directory is going to read the images using PIL ( see here ), so Keras can read all the formats supported by PIL.

However, I didn't see any method to read both masks and images at the same time, and perform the same transformations. I am afraid that you will have to create your own ImageDataGenerator. It's pretty straightforward if you start with the current code.

Also, you can use ImageDataGenerator for any augmentation tools and then use .flow() instead of .flow_from_directory() . this is a cool way for managing images in numpy array format. chek this out:

train_datagen = ImageDataGenerator(rescale=1/255,
                                   rotation_range=40,
                                   width_shift_range=0.2,
                                   height_shift_range=0.2,
                                   shear_range=0.2,
                                   zoom_range=0.2,
                                   horizontal_flip=True,
                                   fill_mode='nearest')
train_generator=train_datagen.flow(training_images, training_labels)

That's because numpy array isn't a kind of directory. So, convert your data set to numpy array format and then try this out. You will get a true result hopefully.

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