代码详解:构建一个简单的Keras+深度学习REST API(18)

请注意输入的图像是如何以99.01%的置信度被正确地分类为“比格犬”的 。 余下的五大预测及其相关概率也包含在Keras API的响应之内 。

以编程方式使用Keras REST API

你很可能会向Keras REST API提交数据 , 然后以某种方式利用反馈的预测——这就要求我们以编程的方式处理来自服务器的响应 。

这是一个使用requests Python程序包的简单过程(http://docs.python-requests.org/en/master/):

# import the necessary packagesimport requests

# initialize the Keras REST API endpoint URL along with the input# image pathKERAS_REST_API_URL = "http://localhost:5000/predict"IMAGE_PATH = "dog.jpg"

# load the input image and construct the payload for the requestimage = open(IMAGE_PATH "rb").read()payload = {"image": image

推荐阅读