预期形状=(None, 784), 发现形状=(None, 28, 28)

expected shape=(None, 784), found shape=(None, 28, 28)

model = keras.models.load_model('model.h5')
image = cv2.imread('letter.png',0)
img = cv2.resize(image,(28,28),3)
img_final = np.reshape(img,(1,28,28))
pred = word_dict[np.argmax(model.predict(img_final))]
print(pred)

当我运行上面的代码时,我得到这个Error。该模型根据图像预测字符。我该如何纠正这个错误?

错误的意思差不多。每个图像都是一个矩阵,对吧?该模型需要一个具有 784 行的矩阵,而不是您给它一个具有 28 列和 28 行的矩阵。这是相同的数据,因为 28*28=784。所以一定要这样做:

img_final = np.reshape(img, (1,784))

试试这个,如果有效请告诉我。