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

data["predictions"
 = [

# loop over the results and add them to the list of

# returned predictions

for (imagenetID label prob) in results[0
:

r = {"label": label "probability": float(prob)

data["predictions"
.append(r)

# indicate that the request was a success

data["success"
 = True

# return the data dictionary as a JSON response

return flask.jsonify(data)

数据字典用于存储希望反馈到客户端的所有数据 。 现在 , 它包含一个布尔值 , 用来表示预测是否成功——还将使用此字典来存储对传入数据进行的所有预测的结果 。

推荐阅读