我使用以下程序來(lái)預(yù)測(cè)圖像的類別。from tensorflow.keras.preprocessing.image import load_img, img_to_arrayx = load_img("8-SignLanguageMNIST/test1.jpg", target_size = (28, 28))x = img_to_array(x)x = np.expand_dims(x, axis = 0)x = np.vstack([x])classes = model.predict(x)print(classes[0])我用于訓(xùn)練的圖像形狀為 (28, 28, 1)。在這里,我上傳了一個(gè)形狀為 (28, 28, 3) 的 RGB 圖像,我嘗試將該圖像轉(zhuǎn)換為灰度,然后進(jìn)行預(yù)測(cè),但一直出現(xiàn)以下錯(cuò)誤。ValueError: Input 0 of layer sequential is incompatible with the layer: expected axis -1 of input shape to have value 1 but received input with shape [None, 28, 28, 3]誰(shuí)能告訴我我做錯(cuò)了什么,并幫助我解決這個(gè)問(wèn)題。
1 回答
慕沐林林
TA貢獻(xiàn)2016條經(jīng)驗(yàn) 獲得超9個(gè)贊
您需要將轉(zhuǎn)換應(yīng)用到灰度,如下所示:
load_img(path,?color_mode='grayscale')
添加回答
舉報(bào)
0/150
提交
取消
