def predict():
logger.info('/predict, hostname: ' + str(socket.gethostname()))
if 'image' not in request.files:
logger.info('Missing image parameter')
return Response('Missing image parameter', 400)
# Write image to disk
with open('request.png', 'wb') as f:
f.write(request.files['image'].read())
img = cv2.imread('request.png', 0)
img = np.resize(img, (28, 28, 1))
prediction = mnist_client.predict(np.array([img]))
logger.info('Prediction of length:' + str(len(prediction)))
''' Convert the dict to json and return response '''
return jsonify(
prediction=prediction,
prediction_length=len(prediction),
hostname=str(socket.gethostname())
)
mnist_mock_client_example.py 文件源码
python
阅读 25
收藏 0
点赞 0
评论 0
评论列表
文章目录