paddleOCR linux部署

本文详细介绍了如何在Python中安装PaddlePaddle及其版本选择,包括PaddleOCR的Git克隆、依赖安装,以及在部署过程中遇到的错误如GLIBC缺失、版本不兼容等问题的解决方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值