我使用keras ImageDataGenerator对训练图像进行预处理,需要某种颜色变化函数(随机颜色,色调变化)。
我的生成器代码如下所示:
image_generator = tf.keras.preprocessing.image.ImageDataGenerator(
horizontal_flip = True,
brightness_range= [0.7, 1.3],
rotation_range = 10,
zoom_range = [0.8, 1.2],
width_shift_range=0.2,
height_shift_range=0.2,
fill_mode="nearest")我试着看了一下数据采集器的keras手册,我发现最好的是- channel_shift_range,但它的工作原理更像是亮度/对比度。

发布于 2019-07-30 15:10:50
也许this能帮上忙。您可以定义一个自定义函数,以便在ImageDataGenerator中使用它来修改图像颜色。
例如:
import cv2
import numpy as np
from PIL import Image
def myFunc(image):
image = np.array(image)
hsv_image = cv2.cvtColor(image,cv2.COLOR_RGB2HSV)
return Image.fromarray(hsv_image)
train_datagen = ImageDataGenerator(
rescale=1. / 255,
rotation_range=20,
width_shift_range=0.2,
height_shift_range=0.2,
horizontal_flip=True,
preprocessing_function = myFunc
)发布于 2019-07-30 15:09:48
在阅读Medium上的文章时发现了一些东西。它可能会有所帮助:-
import cv2
import numpy as np
from PIL import Image
def myFunc(image):
image = np.array(image)
hsv_image = cv2.cvtColor(image,cv2.COLOR_RGB2HSV)
return Image.fromarray(hsv_image)
train_datagen = ImageDataGenerator(
rescale=1. / 255,
rotation_range=20,
width_shift_range=0.2,
height_shift_range=0.2,
horizontal_flip=True,
preprocessing_function = myFunc
)资料来源:
https://stackoverflow.com/questions/57265893
复制相似问题