[英]ValueError: Cannot feed value of shape (1, 50, 50, 3) for Tensor 'input/X:0', which has shape '(?, 50, 50, 1)'
my model input shape is (50,50,1) I am getting the frame by:我的 model 输入形状是 (50,50,1) 我通过以下方式获取框架:
cv2.VideoCapture(0).read()
When I'm using np.reshape() function it does not reshape it the desired shape.当我使用 np.reshape() function 时,它不会将其重塑为所需的形状。
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
This is the error I'm getting:这是我得到的错误:
ValueError: Cannot feed value of shape (1, 50, 50, 3) for Tensor 'input/X:0', which has shape '(?, 50, 50, 1)'
The following code should solve your error以下代码应该可以解决您的错误
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]
Under the assumption that you trained on Grayscale images假设您在灰度图像上进行过训练
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.