paddlehub serving部署后通过client访问,提示Incorrect padding
Created by: suixf0415
-
版本、环境信息 1)PaddleHub和PaddlePaddle版本:paddlehub 1.8.0 paddlepaddle-gpu 1.8.2.post107 2)系统环境:请您描述系统类型,例如Linux/Windows/MacOS/,python版本 NAME="Ubuntu" VERSION="19.10 (Eoan Ermine)" Python 3.6.10 :: Anaconda, Inc.
-
问题描述
- 通过paddleX训练图像分类模型water_recog
- 通过hub convert命令将模型转换为hubserving模型 hub convert --model_dir ./inference_model/ --module_name water_recog --module_version 1.0 --output_dir hubserving_model
- 通过hub install命令安装转化好的模型 hub install ./hubserving_model/water_recog.tar.gz
- 通过hub serving命令启动服务 hub serving start -m water_recog --port 5006 ***以上4部执行过程正确没有任何错误提示。
- 通过client代码访问服务,python serving_client.py -i test2.jpg -p 5006 -n water_recog. 结果服务端提示:Incorrect padding,
######服务端错误信息如下:
suixf@suixf-MS-7B61 ~/p/P0006-T0007_export_model> hub serving start -m water_recog --port 5006 (venvpy36)
water_recog == 1.0
* Serving Flask app "paddlehub.serving.app_single" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
2020-07-31 19:00:14,292-INFO: * Running on http://0.0.0.0:5006/ (Press CTRL+C to quit)
2020-07-31 19:02:46 - Incorrect padding
2020-07-31 19:02:46,886-INFO: 127.0.0.1 - - [31/Jul/2020 19:02:46] "POST /predict/water_recog HTTP/1.1" 200 -
2020-07-31 19:05:33 - Incorrect padding
2020-07-31 19:05:33,303-INFO: 127.0.0.1 - - [31/Jul/2020 19:05:33] "POST /predict/water_recog HTTP/1.1" 200 -
######client代码如下:
import requests
import json
import cv2
import base64
import json
import argparse
import glob
def cv2_to_base64(image):
data = cv2.imencode('.jpg', image)[1]
return base64.b64encode(data.tostring()).decode('utf8')
if __name__ == '__main__':
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image_path", required=True,
help="path to input image")
ap.add_argument("-p", "--port", required=True,
help="serving port")
ap.add_argument("-n", "--module_name", required=True,
help="module_name")
args = vars(ap.parse_args())
data_path = args['image_path']
serving_port = args['port']
module_name = args['module_name']
// 获取图片的base64编码格式
img1 = cv2_to_base64(cv2.imread(data_path))
data = {'images': img1}
// 指定content-type
headers = {"Content-type": "application/json"}
// 发送HTTP请求
url = "http://127.0.0.1:"+serving_port+"/predict/"+module_name
r = requests.post(url=url, headers=headers, data=json.dumps(data))
// 打印预测结果
print(r.json()["results"])