最近在研究 tensorflow serving ,按照官方的demo尝试部署resnet模型,
地址:https://medium.com/tensorflow/serving-ml-quickly-with-tensorflow-serving-and-docker-7df7094aa008
docker 安装,resnet模型下载,启动容器均没有问题,唯独再跑 调用例子 resnet_client.py时报错,代码地址:https://raw.githubusercontent.com/tensorflow/serving/master/tensorflow_serving/example/resnet_client.py
,错误信息如下:
使用postman直接访问接口,可以看到详细错误,如下:
从这个错误看,是 base64解码不了。
原来是 python版本问题,例子中代码如下:
predict_request = '{"instances" : [{"b64": "%s"}]}' % base64.b64encode(dl_request.content)
这是在python2.X中的写法,因为我本地安装的是python3.x,所以最终解析出来的base64会在开头添加b,最终在python3.x中得到的是“b’pic code’”,最终导致 serving解析不了,
经各种尝试和google,在python3.x中调整为以下代码即可:
predict_request = '{"instances" : [{"b64": "%s"}]}' % base64.b64encode(dl_request.content).decode()
结果如下
知乎: https://zhuanlan.zhihu.com/albertwang
微信公众号:AI-Research-Studio
下面是赞赏码