Home > front end >  expected shape=(None, 784), found shape=(None, 28, 28)
expected shape=(None, 784), found shape=(None, 28, 28)

Time:04-18

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)

when I run the above code, I get this Error. this model predicts characters based on their images. How shall i correct this error?

CodePudding user response:

It's pretty much what the error says. Every image is a matrix, right? The model expected a matrix with 784 rows, instead you gave it a matrix with 28 columns and 28 rows. It's the same data, since 28*28=784. So make sure you do:

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

Try this and let me know if it works.

  • Related