我正在尝试使用自定义预处理函数在训练期间将 RGB 图像转换为灰度。因此,我尝试使用tf.image.rbg_to_grayscale它。我的功能如下所示:def prep_data(x): x = tf.image.rgb_to_grayscale(x) return xdatagen = ImageDataGenerator(preprocessing_function=prep_data,validation_split=0.15)的train_generator是使用限定datagen.flow_from_dataframe(...)。没有这个自定义函数的训练效果很好,但是一旦我使用它,我就会收到以下错误:ValueError:使用序列设置数组元素。从这个情况来看答案在这里,我想我需要我的输入改变rgb_to_grayscale,但我不知道什么是合格的正确方法x的功能。关于如何解决这个问题的任何想法?
2 回答

倚天杖
TA贡献1828条经验 获得超3个赞
将 RGB 图像更改为灰度(示例):
img = image.load_img('/kaggle/input/cassava-leaf-disease-classification/train_images/'+train['image_id'][i], target_size=(28,28,1), color_mode="grayscale")
添加回答
举报
0/150
提交
取消