paddleOCR linux部署

1.开始安装

  • 1.1 选择CPU版本的paddlePaddle
python3 -m pip install paddlepaddle==2.6.0 -i https://mirror.baidu.com/pypi/simple
  • 1.2 验证安装
import paddle
paddle.utils.run_check()

安装成功会显示:

Running verify PaddlePaddle program ... 
I0304 15:20:51.457686 10827 program_interpreter.cc:212] New Executor is Running.
I0304 15:20:51.688014 10827 interpreter_util.cc:624] Standalone Executor is Used.
PaddlePaddle works well on 1 CPU.
PaddlePaddle is installed successfully! Let's start deep learning with PaddlePaddle now.

2.从git上导入paddleocr

git clone https://gitee.com/PaddlePaddle/PaddleOCR.git
  • 2.1 切换路径并安装依赖
cd PaddleOCR
pip install -r requirements.txt
  • 2.2.安装推理模型包
    • 2.2.1 将推理包放入inference文件夹中
      官网链接:https://github.com/PaddlePaddle/PaddleOCR?tab=readme-ov-file
mkdir inference
cd inference
wget https://paddleocr.bj.bcebos.com/PP-OCRv4/chinese/ch_PP-OCRv4_det_infer.tar && tar -xf ch_PP-OCRv4_det_infer.tar
wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_cls_infer.tar && tar -xf ch_ppocr_mobile_v2.0_cls_infer.tar
wget https://paddleocr.bj.bcebos.com/PP-OCRv4/chinese/ch_PP-OCRv4_rec_infer.tar && tar -xf 
ch_PP-OCRv4_rec_infer.tar
  • 2.3快速运行
cd ..
python tools/infer/predict_system.py --image_dir='./doc/imgs/11.jpg' --det_model_dir='././inference/ch_PP-OCRv4_det_infer/'  --rec_model_dir='./inference/ch_PP-OCRv4_rec_infer/' --cls_model_dir='./inference/ch_ppocr_mobile_v2.0_cls_infer/' --use_angle_cls=True --use_space_char=True --use_gpu=False
  • use_angle_cls:是否使用角度分类器
  • use_space_char:是否使用空格字符
  • use_gpu:是否使用gpu

问题1:ImportError: libGL.so.1: cannot open shared object file: No such file or directory

# 原因为:opencv-python 需要再有图形化界面上运行
建议导入:
pip uninstall opencv-python
pip install opencv-python-headless

问题2:AttributeError: module ‘paddle’ has no attribute ‘fluid’. Did you mean: ‘flip’?

(paddleocrVenv)

# 版本原因:将paddlepaddle降级为2.3.0
pip uninstall paddlepaddle
pip install paddlepaddle==2.3.0

其他原因:

PaddlePaddle在更新到2.0版本后进行了一些重大的变化。在旧版本的PaddlePaddle中,确实存在名为fluid的模块,但在新版本中,这个模块已被改名为paddle。而我使用的是PaddlePaddle的2.6的版本,则应该使用import paddle而不是import paddle.fluid来导入PaddlePaddle的模块。

修改utility.py

# 改变
if not paddle.fluid.core.is_compiled_with_rocm():

# 改成
if not paddle.is_compiled_with_rocm():

问题3:TypeError: Descriptors cannot be created directly.

If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.
If you cannot immediately regenerate your protos, some other possible workarounds are:

# 问题原因:protoc版本不兼容,设置为3.19.0
pip uninstall protobuf
pip install protobuf==3.20.0

问题4:ImportError: /root/data/tools/paddleocrVenv/lib/python3.10/site-packages/paddle/fluid/core_avx.so: undefined symbol: _dl_sym, version GLIBC_PRIVATE

 建议降低python版本
建议3.9版本

3. 部署服务

  • 3.1安装hub
pip install paddlehub -i https://mirror.baidu.com/pypi/simple
  • 3.2安装检测服务模块
    hub install deploy/hubserving/ocr_det/

问题

TypeError: Descriptors cannot be created directly.

解决办法

pip uninstall protobuf
pip install protobuf==3.20.2
  • 3.3安装识别服务模块
    hub install deploy/hubserving/ocr_rec/

  • 3.4`安装检测+识别串联服务模块:
    hub install deploy/hubserving/ocr_system/

  • 3.5修改配置文件

PddleOCR/deploy/hubserving/ocr_system/config.json
- 修改usegpu为false
- 修改enable_mkldnn:true 加快识别速度

修改同级目录下params.py 修改为你的模型地址

cfg.det_model_dir =
cfg.rec_model_dir =
cfg.cls_model_dir =
  • 3.6启动服务
    在PaddleOCR目录中启动
hub serving start -c deploy/hubserving/ocr_system/config.json

问题,请求时返回

module 'numpy' has no attribute 'int'.
`np.int` was a deprecated alias for the builtin `int`. To avoid this error in existing code, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
    https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations'
pip uninstall numpy 
pip install numpy==1.21.1
  • 3.7停止服务
hub serving stop --port/-p XXXX
Linux部署PaddleOCR有两种方式。一种是使用PaddleHub进行部署,但由于在Windows上设置CUDA_VISIBLE_DEVICES=0可能出现错误,所以推荐将PaddleHub部署Linux上进行使用。另一种方式是使用PaddleServing进行部署,这种方式仅使用CPU进行推理预测,可以在Windows和Linux上都进行部署。具体操作步骤如下: 1. 进入PaddleOCR目录下,可以参考https://github.com/PaddlePaddle/PaddleOCR/blob/develop/deploy/hubserving/readme.md 进行启动参数的修改。 2. 根据PaddleOCR部署文档,按照指示进行环境配置和依赖安装。 3. 确保您的Linux系统已经安装好了必要的软件和库文件,比如Python、PaddlePaddle等。 4. 根据文档中的说明,执行相应的命令来启动PaddleOCR的服务。 5. 在部署完成后,您可以使用PaddleOCR进行图像识别和文字识别等任务。 需要注意的是,以上是一种基本的部署方式,具体的部署步骤可能会因环境和需求的不同而有所差异,您可以根据具体情况进行相应的调整。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [PaddleOCR服务化部署](https://blog.csdn.net/qq_44309220/article/details/127458611)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [Linux服务器部署安装PaddleOCR](https://blog.csdn.net/eqcjx/article/details/109336341)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值