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
- 2.2.1 将推理包放入inference文件夹中
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