https://github.com/sugyan/tensorflow-mnist通过使用Flask并加载预训练模式(还原)显示了一个简单的restAPI示例。
@app.route('/api/mnist', methods=['POST'])
def mnist():
input = ((255 - np.array(request.json, dtype=np.uint8)) / 255.0).reshape(1, 784)
output1 = simple(input)
output2 = convolutional(input)
return jsonify(results=[output1, output2])
另外,请参阅https://tensorflow-mnist.herokuapp.com/上的在线演示。 API似乎足够快。
0
是否有用于通过RESTful API部署Tensorflow模型的示例代码?我看到了命令行程序和移动应用程序的示例。是否有一个用于此的框架,或者人们只是加载模型并通过Web框架(例如Flask)公开预测方法以获取输入(例如通过JSON)并返回响应?所谓框架,是指针对大量预测请求进行扩展。当然,由于模型是不可变的,因此我们可以启动我们的预测服务器的多个实例,并将其放在负载均衡器(如HAProxy)后面。我的问题是,人们是为此使用某种框架还是从头开始执行此操作?或者,也许Tensorflow中已经提供了此功能,但我还没有注意到。