如何实现仅支持HTTP请求的客户端与gRPC协议TensorFlow Serving通信?
解决方案:启用TensorFlow Serving的REST API端口
嘿,这个问题刚好有完美的解决办法!TensorFlow官方在2018年6月12日发布了Serving的REST API支持,刚好能解决你的客户端只能发起HTTP请求、但AWS上的TF Serving仅开启gRPC端口的矛盾——只需要在启动TF Serving时指定REST API端口,就能让服务同时接受HTTP请求,这样你的客户端就能直接通过HTTP和AWS上的服务通信了。
下面是具体的操作步骤,用官方的half_plus_three测试模型为例:
1. 准备模型文件
我们用官方提供的测试模型,模型路径为:$(pwd)/serving/tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_three/
2. 启动支持REST API的TensorFlow Serving服务器
运行以下命令启动服务,重点是加上--rest_api_port参数指定HTTP请求的端口(这里用8501):
$ tensorflow_model_server --rest_api_port=8501 \ --model_name=half_plus_three \ --model_base_path=$(pwd)/serving/tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_three/
3. 客户端发起HTTP请求
你的客户端可以通过POST请求调用模型的预测接口,比如用curl模拟的话:
$ curl -d '{"instances": [1.0,2.0,5.0]}' -X POST http://<你的AWS服务器地址>:8501/v1/models/half_plus_three:predict
返回结果会是:
{ "predictions": [3.5, 4.0, 5.5] }
这样一来,你的客户端就能通过HTTP请求和AWS上的TensorFlow服务顺利通信啦!
内容的提问来源于stack exchange,提问作者Matt Dixie
相关产品推荐
相关产品推荐

