Reputation: 99
I am trying to use Keras' ImageDataGenerator
for a UNet autoencoder.
I would like to import and convert RGB images from the Tiny ImageNet dataset into grayscale images which have been rescaled to have values between 0~1.
train_dir = r'D:\tiny-imagenet-200-testing\tiny-imagenet-200\train'
train_datagen = ImageDataGenerator(rescale=1 / 255)
train_generator = train_datagen.flow_from_directory(train_dir, target_size=(64, 64),
color_mode='grayscale', class_mode='input', batch_size=128,
horizontal_flip=True)
I am trying to use the flow_from_directory
with class_mode='input'
in Keras, which says that:
"input" will be images identical to input images (mainly used to work with autoencoders). (See https://keras.io/preprocessing/image/)
However, I don't know whether the "input images" being returned are the rescaled and flipped images or the original data, unmodified by conditions specified in the ImageDataGenerator. Does anyone know the order in which the ImageDataGenerator
and flow_from_directory
interact with one another? Especially when class_mode='input'
?
Upvotes: 2
Views: 4422
Reputation: 33420
The generated images and their corresponding labels are the same in case of using class_mode='input'
. You can confirm this by:
import numpy as np
for tr_im, tr_lb in train_generator:
if np.all(tr_im == tr_lb):
print('They are the same!`)
break
The output of the above code would be They are the same!
.
Upvotes: 3