PaddleOCR服务端部署

准备环境

参考Paddle Serving 服务部署官网流程
本机环境:ubuntu16.04 python3.7
目标:部署CPU端PaddleOCR服务

安装流程

  1. 首先git clone PaddleOCR库下来。
git clone https://github.com/PaddlePaddle/PaddleOCR.git
cd ./PaddleOCR
  1. 安装包
  • 安装服务器端、客户端和App包,CPU、GPU通用
python3 -m pip install -U https://paddle-serving.bj.bcebos.com/whl/paddle_serving_server-0.0.0-py3-none-any.whl
python3 -m pip install -U https://paddle-serving.bj.bcebos.com/whl/paddle_serving_client-0.0.0-cp37-none-any.whl https://paddle-serving.bj.bcebos.com/whl/paddle_serving_app-0.0.0-py3-none-any.whl

可能报错:

ERROR: Command errored out with exit status 1:
     command: /root/anaconda3/envs/cv/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-k7d5jrxh/shapely/setup.py'"'"'; __file__='"'"'/tmp/pip-install-k7d5jrxh/shapely/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-eycaofz0
         cwd: /tmp/pip-install-k7d5jrxh/shapely/
    Complete output (11 lines):
    Failed `CDLL(libgeos_c.so.1)`
    Failed `CDLL(libgeos_c.so)`
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-k7d5jrxh/shapely/setup.py", line 80, in <module>
        from shapely._buildcfg import geos_version_string, geos_version, \
      File "/tmp/pip-install-k7d5jrxh/shapely/shapely/_buildcfg.py", line 167, in <module>
        fallbacks=['libgeos_c.so.1', 'libgeos_c.so'])
      File "/tmp/pip-install-k7d5jrxh/shapely/shapely/_buildcfg.py", line 161, in load_dll
        libname, fallbacks or []))
    OSError: Could not find library geos_c or load any of its variants ['libgeos_c.so.1', 'libgeos_c.so']
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.['libgeos_c.so.1', 'libgeos_c.so']

参考解决方案,该包安装完成后即可正常安装客户端。

sudo apt-get install libgeos-dev
  • 安装依赖
pip install func-timeout
  1. 转换模型
wget -P ./inference/ https://paddleocr.bj.bcebos.com/20-09-22/mobile/det/ch_ppocr_mobile_v1.1_det_infer.tar && tar xf ./inference/ch_ppocr_mobile_v1.1_det_infer.tar -C ./inference/
wget -P ./inference/ https://paddleocr.bj.bcebos.com/20-09-22/cls/ch_ppocr_mobile_v1.1_cls_infer.tar && tar xf ./inference/ch_ppocr_mobile_v1.1_cls_infer.tar -C ./inference/
wget -P ./inference/ https://paddleocr.bj.bcebos.com/20-09-22/mobile/rec/ch_ppocr_mobile_v1.1_rec_infer.tar && tar xf ./inference/ch_ppocr_mobile_v1.1_rec_infer.tar -C ./inference/
python3 deploy/pdserving/inference_to_serving.py --model_dir ./inference/ch_ppocr_mobile_v1.1_det_infer
python3 deploy/pdserving/inference_to_serving.py --model_dir ./inference/ch_ppocr_mobile_v1.1_cls_infer
python3 deploy/pdserving/inference_to_serving.py --model_dir ./inference/ch_ppocr_mobile_v1.1_rec_infer

可能出现报错如下:

  File "/root/anaconda3/envs/cv/lib/python3.7/site-packages/paddle/incubate/hapi/vision/transforms/transforms.py", line 18, in <module>
    import cv2
  File "/root/anaconda3/envs/cv/lib/python3.7/site-packages/cv2/__init__.py", line 3, in <module>
    from .cv2 import *
ImportError: libSM.so.6: cannot open shared object file: No such file or directory

解决方案:

# ubuntu
# https://blog.csdn.net/qq_35037684/article/details/106590685
apt-get install libsm6
apt-get install libxrender1
apt-get install libxext-dev
# centos
# https://blog.csdn.net/weixin_42784553/article/details/86506342
sudo yum install libXext libSM libXrender

再次运行转换模型程序即可

  1. 启动服务
# 以下两步的顺序不能反
export PYTHONPATH=$PWD:$PYTHONPATH
cd deploy/pdserving
python -m det_rpc_server --model ../../inference/ch_ppocr_mobile_v1.1_det_infer/serving_server_dir/ --port 9293
python -m rec_rpc_server --model ../../inference/ch_ppocr_mobile_v1.1_cls_infer/serving_server_dir/ --port 9294
python ocr_rpc_server.py  # 报错
This API will be deprecated later. Please do not use it
Traceback (most recent call last):
  File "ocr_rpc_server.py", line 120, in <module>
    ocr_service.init_rec()
  File "ocr_rpc_server.py", line 90, in init_rec
    self.text_system = TextSystemHelper(global_args)
  File "ocr_rpc_server.py", line 43, in __init__
    self.clas_client = Client()
  File "/root/anaconda3/envs/cv/lib/python3.7/site-packages/paddle_serving_client/__init__.py", line 136, in __init__
    from .serving_client import PredictorRes
ImportError: libcrypto.so.10: cannot open shared object file: No such file or directory

该问题未解决。
故直接使用

python3 ocr_local_server.py  # 默认端口9292

调用OCR接口

python3 pdserving_client.py image_path
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值