【发布时间】:2020-09-17 05:50:36
【问题描述】:
我正在尝试使用 tensorflow/serving 图像在 docker 上为 attention_ocr model 提供服务。
首先,我用自己的数据集训练了这个模型,用demo_inference.py得到了很好的结果
所以,我将使用 export_model.pypython export_model.py --checkpoint=model.ckpt-111111 --export_dir=/tmp/mydir 导出训练好的模型
然后,运行 docker 容器为模型提供服务。docker run -it --rm -p 8501:8501 -v /tmp/mydir:/models/aocr -e MODEL_NAME=aocr --gpus all tensorflow/serving
这是我的 python 客户端脚本。
data_dir = '/root/src/models/research/attention_ocr/python/datasets/data/demo/'
data_files = os.listdir(data_dir)
with open(data_dir + "0.jpg", "rb") as image_file:
encoded_string = base64.b64encode(image_file.read())
## Some requests I tried ##
# predict_request = '{"examples": [{"inputs": ["%s"]}]}' % encoded_string
# predict_request = '{"examples": [{"inputs": "%s"}]}' % encoded_string
predict_request = '{"examples": [{"inputs": {"b64": ["%s"]}}]}' % encoded_string
r = requests.post('http://MY_IP_ADDR:8501/v1/models/aocr:classify', data=predict_request)
print(r.text)
结果.."error": "Expected one or two output Tensors, found 17"
这是第一次使用 tensorflow/serving。我无法处理这个错误。
请帮助这个新手.. 提前致谢。
【问题讨论】:
标签: python docker tensorflow tensorflow-serving tensorflow-model-garden