【问题标题】:preprocessing_function in ImageDataGenerator tensorflow.keras.preprocessing.image not applliedImageDataGenerator tensorflow.keras.preprocessing.image 中的 preprocessing_function 未应用
【发布时间】:2021-03-21 13:21:06
【问题描述】:

我试图使用 ImageDataGenerator 并应用 prepossing 函数来应用一些随机色调。当我通过 ImageDataGenerator 对单张图片运行转换时,我没有看到它已应用。

def hue_change(image):
new_img = tf.image.random_hue(np.array(image), 0.2)
return new_img

IMG_gen = ImageDataGenerator(rotation_range=30,height_shift_range=0.05, width_shift_range=0.05,fill_mode='nearest',
                         zoom_range=0.03, rescale=1./255,preprocessing_function=hue_change)

当我将这个函数直接应用到图片中时,它可以工作。

plt.imshow(hue_change(imread('Train//Apple Granny Smith//179_100.jpg')))

但是当我通过 random_transform 生成它时

plt.imshow(IMG_gen.random_transform(imread(('Train//Apple Granny Smith//179_100.jpg'))))

我没有看到任何变化。

您能告诉我为什么会这样吗?

【问题讨论】:

    标签: tensorflow machine-learning conv-neural-network imagedata


    【解决方案1】:

    我使用 ImageDataGenerator.flow_from_directory 尝试了 hue_change 预处理功能,并显示了正确的结果。色调随机变化。我还在图片上尝试了您的代码

    dgen=ImageDataGenerator(preprocessing_function=hue_change)
    nimage=dgen.random_transform(image)
    plt.imshow(nimage)
    

    正如您所注意到的,这不会修改色调。 random_transform 本身应该对图像应用随机变换。我不知道为什么它没有。也许here 的答案可能会有所帮助。

    【讨论】:

    • 这不应该是一个问题,因为我会错误地收到数组不匹配的错误。看起来,它甚至没有尝试将其转换为 hsv。在将 IMG_gen 应用为不同方法的形式后,我可能会尝试应用它。
    猜你喜欢
    • 1970-01-01
    • 2019-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-06
    • 1970-01-01
    • 1970-01-01
    • 2016-12-26
    相关资源
    最近更新 更多