【发布时间】:2020-07-17 12:06:03
【问题描述】:
是否可以使用ImageDataGenerator 将[0, 255] 中的图像重塑为[-1, 1]?
我发现我可以使用 reshape 参数将图像与一个值相乘,但这只能让我将其重塑为 [0, 1]
【问题讨论】:
标签: tensorflow artificial-intelligence reshape tensorflow2.0
是否可以使用ImageDataGenerator 将[0, 255] 中的图像重塑为[-1, 1]?
我发现我可以使用 reshape 参数将图像与一个值相乘,但这只能让我将其重塑为 [0, 1]
【问题讨论】:
标签: tensorflow artificial-intelligence reshape tensorflow2.0
您可以使用 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[:, :, :]]