ValueError:无法为张量"input/X:0"提供形状 (1, 50, 50, 3) 的值,该张量具有"(?, 50, 50, 1)"



我的模型输入形状是(50,50,1(我通过获取帧

cv2.VideoCapture(0).read()

当我使用np.reshape((函数时,它不会将其重塑为所需的形状。

sized_frame = (cv2.resize(frame, (50,50)))
cv2.waitKey(0)
img_data = np.array(photo)
data = tf.reshape(img_data, (1,50,50,3))
model_out = model.predict([img_data])[0]
print(model_out)
if np.argmax(model_out) == 1:
str_label = 'Dog'
else:
str_label = 'Cat'
return str_label

这是我得到的错误:

ValueError: Cannot feed value of shape (1, 50, 50, 3) for Tensor 'input/X:0', which has shape '(?, 50, 50, 1)'

以下代码应该可以解决错误

gray = cv2.cvtColor(photo, cv2.COLOR_BGR2GRAY)
img_data = np.array(gray)
data = tf.reshape(img_data, (1,50,50,1))
model_out = model.predict(img_data)[0]

假设你在灰度图像上训练

最新更新