Invalid input shape for input Tensor(“data:0”, shape=(28, 28), dtype=float32). Expected shape (None, 28, 28), but input has incompatible shape (28, 28)
在做手写数字识别的时候训练好了模型,使用预测语句,预测单张图片:
代码如下:
model.predict([[X_test[0]]])
jupyter报错:
Invalid input shape for input Tensor(“data:0”, shape=(28, 28), dtype=float32). Expected shape (None, 28, 28), but input has incompatible shape (28, 28),
Arguments received by Sequential.call():
• inputs=((‘tf.Tensor(shape=(28, 28), dtype=float32)’,),)
• training=False
• mask=((‘None’,),)
使用查到的reshape方法,但仍然报错:
model.predict((X_test[0]).reshape(1,28,28))
解决办法:
model.predict(X_test[0:1])
jupyter输出:
问题解决(_)