一.代码准备
下载2.0版本以上的paddleocr:paddleocr
2.0以上的在训练自己模型的时候有参数:
复制代码
1
2load_static_weights: True #是否将预训练模型保存在静态图形模式
所以,只要安装好了tensorrt一般都可以直接使用,Serving也需要2.0版本以上的
二.tensorrt的安装
可以参照以下方法安装tensorrt:
tensorrt安装-1
tensorrt安装-2
tensorrt安装-3
三.paddleocr环境配置
下载对应的使用tensorrt的GPU环境:对应GPU环境
其余的环境都和平时使用的一模一样
使用GPU下载的环境一定要和自己的cuda、cudnn对应
四.设置参数
use_tensorrt=True
每次加载模型的时候设置参数:use_tensorrt=True
五.Serving环境准备
在虚拟环境中安装-可以使用0.7,0.8版本的:其它版本的环境安装
复制代码
1
2
3
4
5
6pip install paddle-serving-server==0.6.1 # for CPU pip install paddle-serving-server-gpu==0.6.1 # for GPU # 其他GPU环境需要确认环境再选择执行如下命令 pip install paddle-serving-server-gpu==0.6.1.post101 # GPU with CUDA10.1 + TensorRT6 pip install paddle-serving-server-gpu==0.6.1.post11 # GPU with CUDA11 + TensorRT7
安装client
复制代码
1
2
3wget https://paddle-serving.bj.bcebos.com/test-dev/whl/paddle_serving_client-0.6.1-cp37-none-any.whl pip install paddle_serving_client-0.6.1-cp37-none-any.whl
安装serving-app
复制代码
1
2
3wget https://paddle-serving.bj.bcebos.com/test-dev/whl/paddle_serving_app-0.6.1-py3-none-any.whl pip install paddle_serving_app-0.6.1-py3-none-any.whl
这几个的版本一定要对应,否则会报错
六.模型转换
如果没有模型,可以下载:PP-OCR
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14# 转换检测模型 python3 -m paddle_serving_client.convert --dirname ./ch_PP-OCRv2_det_infer/ # 使用自己训练好的模型路径 --model_filename inference.pdmodel --params_filename inference.pdiparams --serving_server ./ppocrv2_det_serving/ # 保存位置可以更改为指定位置 --serving_client ./ppocrv2_det_client/ # 保存位置可以更改为指定位置 # 转换识别模型 同上 python3 -m paddle_serving_client.convert --dirname ./ch_PP-OCRv2_rec_infer/ --model_filename inference.pdmodel --params_filename inference.pdiparams --serving_server ./ppocrv2_rec_serving/ --serving_client ./ppocrv2_rec_client/
转换好如图:
七.部署
进入到工作目录PaddleOCR/deploy/pdserving,运行web_service.py文件,一般不会出错,生成这样的日志文件,说明运行成功
根据请求不同,运行不同的py文件:
pipeline_http_client.py
pipeline_rpc_client.py
在web_service.py可以修改:
复制代码
1
2
3
4class RecOp(Op): def init_op(self): self.det_box = []
复制代码
1
2
3
4
5
6
7
8
9
10def preprocess(self, input_dicts, data_id, log_id): self.det_box = [] for i in dt_boxes: b = [] for j in i: x, y = j b.append([int(x), int(y)]) # print("bb:", b) self.det_box.append(b)
复制代码
1
2
3def postprocess(self, input_dicts, fetch_data, data_id, log_id): box = str(self.det_box)
如上代码修改,可以获得坐标信息
最后
以上就是独特草丛最近收集整理的关于paddleocr-tensorrt加速-Serving部署的全部内容,更多相关paddleocr-tensorrt加速-Serving部署内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复