使用 ImageDataGenerator 将图像重塑为 [-1, 1]
Reshape image to [-1, 1] with ImageDataGenerator
是否可以使用 ImageDataGenerator
将 [0, 255]
中的图像重塑为 [-1, 1]
?
我已经看到我可以使用重塑参数将图像与一个值相乘,但这只让我有可能将它重塑为 [0, 1]
您可以在 Keras ImageDataGenerator class 中使用 preprocessing_function。
preprocessing_function: function that will be applied on each input. The function will run after the image is resized and augmented. The function should take one argument: one image (Numpy tensor with rank 3), and should output a Numpy tensor with the same shape.
#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)
`
是否可以使用 ImageDataGenerator
将 [0, 255]
中的图像重塑为 [-1, 1]
?
我已经看到我可以使用重塑参数将图像与一个值相乘,但这只让我有可能将它重塑为 [0, 1]
您可以在 Keras ImageDataGenerator class 中使用 preprocessing_function。
preprocessing_function: function that will be applied on each input. The function will run after the image is resized and augmented. The function should take one argument: one image (Numpy tensor with rank 3), and should output a Numpy tensor with the same shape.
#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)
`