ValueError.无法为形状为'(?, 50, 50, 1)'的张量'inputX:0'输入形状(1, 50, 50, 3)的值。不能为形状为'(?, 50, 50, 3)'的张量'inputX:0'输入形状为'(?, 50, 50, 1)'的值。

问题描述 投票:0回答: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)'
python numpy tensorflow machine-learning cv2
1个回答
0
投票

下面的代码应该可以解决你的错误

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]

假设您在灰度图像上进行训练

© www.soinside.com 2019 - 2024. All rights reserved.