keras error on predict

后端 未结 1 985
慢半拍i
慢半拍i 2021-01-11 12:16

I am trying to use a keras neural network to recognize canvas images of drawn digits and output the digit. I have saved the neural network and use django to run the web inte

相关标签:
1条回答
  • 2021-01-11 12:32

    You're asking the neural network to evaluate 784 cases with one input each instead of a single case with 784 inputs. I had the same problem and I solved it having an array with a single element which is an array of the inputs. See the example below, the first one works whereas the second one gives the same error you're experiencing.

    model.predict(np.array([[0.5, 0.0, 0.1, 0.0, 0.0, 0.4, 0.0, 0.0, 0.1, 0.0, 0.0]]))
    model.predict(np.array([0.5, 0.0, 0.1, 0.0, 0.0, 0.4, 0.0, 0.0, 0.1, 0.0, 0.0]))
    

    hope this solves it for you as well :)

    0 讨论(0)
提交回复
热议问题