在上一篇文章中,我们学习了在Mac机器上搭建TensorFlow-Serving的示例,并提供了使用Http接口访问的方法。本文中,我们将尝试使用Grpc接口访问TensorFlow-Serving服务。
启动服务
nohup sudo docker run -p 8502:8500 -p 8501:8501 --name tfserving_testnet --mount type=bind,source=/home/tensorflow/xception,target=/models/xception -e MODEL_NAME=xception -t tensorflow/serving &
其中,本机的8502端口对应Docker的8500端口(GRPC端口),本机8501端口对应Docker的8501端口(HTTP端口)。
模型信息
在写Gprc服务之前,需要明确模型的名字、输入、输出等。我们使用curl http://localhost:8501/v1/models/xception/metadata可以看到Docker中模型的基本信息。
![6f034465dc6f81ae1f972e14a53d9e8a.png](https://i-blog.csdnimg.cn/blog_migrate/f30df29b14826942a41e913744da6956.jpeg)
其中,方框内的内容要在下面Client的代码中用到。
Python Grpc Client
下面代码是python的客户端代码,输入一张图片