我正在嘗試使用自定義預處理函數在訓練期間將 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
提交
取消