Keras ImageDataGenerator和flow_from_directory class_mode ='input'

时间:2018-07-26 04:14:23

标签: python machine-learning keras autoencoder unity3d-unet

我正在尝试将Keras的ImageDataGenerator用于UNet自动编码器。 我想将Tiny ImageNet数据集中的RGB图像导入并将其转换为灰度图像,这些图像已重新缩放为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)

我正在Keras中尝试将flow_from_directoryclass_mode='input'一起使用,它表示:

  

“输入”将是与输入图像相同的图像(主要用于   使用自动编码器)。 (请参见https://keras.io/preprocessing/image/

但是,我不知道返回的“输入图像”是重新缩放和翻转的图像还是原始图像,未经ImageDataGenerator中指定的条件修改。是否有人知道ImageDataGeneratorflow_from_directory彼此交互的顺序?特别是当class_mode='input'时?

1 个答案:

答案 0 :(得分:1)

在使用class_mode='input'的情况下,生成的图像及其相应的标签相同。您可以通过以下方式确认这一点:

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

以上代码的输出为They are the same!

相关问题