app.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:how_to_deploy_a_keras_model_to_production 作者: llSourcell 项目源码 文件源码
def predict():
    #whenever the predict method is called, we're going
    #to input the user drawn character as an image into the model
    #perform inference, and return the classification
    #get the raw data format of the image
    imgData = request.get_data()
    #encode it into a suitable format
    convertImage(imgData)
    print "debug"
    #read the image into memory
    x = imread('output.png',mode='L')
    #compute a bit-wise inversion so black becomes white and vice versa
    x = np.invert(x)
    #make it the right size
    x = imresize(x,(28,28))
    #imshow(x)
    #convert to a 4D tensor to feed into our model
    x = x.reshape(1,28,28,1)
    print "debug2"
    #in our computation graph
    with graph.as_default():
        #perform the prediction
        out = model.predict(x)
        print(out)
        print(np.argmax(out,axis=1))
        print "debug3"
        #convert the response to a string
        response = np.array_str(np.argmax(out,axis=1))
        return response
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号