我正在训练一个Keras模型,我有RGB格式的训练图像。我想训练我的模型,但在InceptionV3上的灰度图像,但它以RGB图像作为输入。我的问题是:如何才能首先将RGB图像转换为灰度,然后在三维中复制?我正在使用Keras的TrainDataGenerator.flow_from_directory方法。
发布于 2020-12-07 13:43:19
在ImageDataGenerator中,您可以传递一个预处理函数。使用函数tf.image.rgb_to_grayscale和tf.image.grayscale_to_rgb执行转换:
def to_grayscale_then_rgb(image):
image = tf.image.rgb_to_grayscale(image)
image = tf.image.grayscale_to_rgb(image)
return imagetf.keras.preprocessing.image.ImageDataGenerator(
rescale=1/255,
preprocessing_function=to_grayscale_then_rgb
)发布于 2021-05-07 12:45:10
我认为最简单的方法是使用color_mode ="grayscale“参数的TrainDataGenerator.flow_from_directory方法。
下面是指定如何执行此https://keras.io/api/preprocessing/image/的keras文档
https://stackoverflow.com/questions/65179822
复制相似问题