【问题标题】:Reshape image to [-1, 1] with ImageDataGenerator使用 ImageDataGenerator 将图像重塑为 [-1, 1]
【发布时间】:2020-07-17 12:06:03
【问题描述】:

是否可以使用ImageDataGenerator[0, 255] 中的图像重塑为[-1, 1]

我发现我可以使用 reshape 参数将图像与一个值相乘,但这只能让我将其重塑为 [0, 1]

【问题讨论】:

    标签: tensorflow artificial-intelligence reshape tensorflow2.0


    【解决方案1】:

    您可以使用 Keras ImageDataGenerator 类中的 preprocessing_function。

    preprocessing_function:将应用于每个输入的函数。该函数将在图像调整大小和增强后运行。该函数应采用一个参数:一张图像(等级为 3 的 Numpy 张量),并应输出具有相同形状的 Numpy 张量。

    #preprocessing_function function
    def changeRange(image):
    
       image[:, :, 0] = [(i/128.0)-1 for i in image[:, :, 0]]
       image[:, :, 1] = [(i/128.0)-1 for i in image[:, :, 1]]
       image[:, :, 2] = [(i/128.0)-1 for i in image[:, :, 2]]
    
       return image
    
    #data augementation
    train_datagen = ImageDataGenerator(
       rescale = None,
       preprocessing_function=changeRange)
    

    `

    【讨论】:

    • 我认为函数可以表示为return [(i/128.0)-1 for i in image[:, :, :]]
    • 是的,这可能会更好 =)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-21
    • 2022-01-11
    • 1970-01-01
    • 2016-05-12
    • 1970-01-01
    • 2016-06-30
    • 1970-01-01
    相关资源
    最近更新 更多