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

return image

这个函数:

· 接受输入图像

· 将模式转换为RGB(如果需要)

· 将大小调整为224x224像素(ResNet的输入空间维度)

· 通过平均减法数组和缩放对阵列进行预处理

此外 , 在通过模型传递输入数据之前 , 应该根据某一预处理、缩放或标准化来修改这个函数 。

现在可以定义predict函数了——该方法会处理对/predict端点的任何请求:

@app.route("/predict" methods=["POST"
)def predict():

# initialize the data dictionary that will be returned from the

# view

data = {"success": False

推荐阅读