PaddleOCR使用笔记之快速使用

第1步,安装环境

安装paddlepaddle-gpu

安装CUDA 10.0对应的飞桨2.0.0,GPU版本:

# 创建虚拟环境
conda create -n paddle_env python=3.7

# 进入虚拟环境
activate paddle_env

# 安装paddlepaddle-gpu
python -m pip install paddlepaddle-gpu==2.0.0rc1.post100 -f https://paddlepaddle.org.cn/whl/stable.html

查看详细安装步骤

下载PaddleOCR

进入GitHub下载PaddleOCR,并解压在指定目录中,如PaddleOCR-dygraph

第2步,下载推理模型

模型简介模型名称推荐场景检测模型方向分类器识别模型
中英文超轻量OCR模型(9.4M)ch_ppocr_mobile_v2.0_xx移动端&服务器端推理模型 / 预训练模型推理模型 / 预训练模型推理模型 / 预训练模型
中英文通用OCR模型(143.4M)ch_ppocr_server_v2.0_xx服务器端推理模型 / 预训练模型推理模型 / 预训练模型推理模型 / 预训练模型

下载上述模型列表中的某一个,如中英文超轻量OCR模型,将其对应的检测模型、方向分类器、识别模型的推理模型,并将其解压至PaddleOCR-dygraph\inference目录下,Windows用户解压上述文件时会出现问题,建议不要使用解压软件解压,使用命令行解压,:

mkdir inference && cd inference
# 解压超轻量级中文OCR模型的检测模型
tar xf ch_ppocr_mobile_v2.0_det_infer.tar
#  解压超轻量级中文OCR模型的识别模型
tar xf ch_ppocr_mobile_v2.0_rec_infer.tar
#  解压超轻量级中文OCR模型的文本方向分类器模型
tar xf ch_ppocr_mobile_v2.0_cls_infer.tar
cd ..

解压完毕后应有如下文件结构:

├── ch_ppocr_mobile_v2.0_cls_infer
│   ├── inference.pdiparams
│   ├── inference.pdiparams.info
│   └── inference.pdmodel
├── ch_ppocr_mobile_v2.0_det_infer
│   ├── inference.pdiparams
│   ├── inference.pdiparams.info
│   └── inference.pdmodel
├── ch_ppocr_mobile_v2.0_rec_infer
    ├── inference.pdiparams
    ├── inference.pdiparams.info
    └── inference.pdmodel

第3步,预测

以下代码实现了文本检测、方向分类器和识别串联推理,在执行预测时,需要通过参数image_dir指定单张图像或者图像集合的路径、参数det_model_dir指定检测inference模型的路径、参数rec_model_dir指定识别inference模型的路径、参数use_angle_cls指定是否使用方向分类器、参数cls_model_dir指定方向分类器inference模型的路径、参数use_space_char指定是否预测空格字符。可视化识别结果默认保存到./inference_results文件夹里面。

# 预测image_dir指定的单张图像
python tools/infer/predict_system.py --image_dir="./doc/imgs/11.jpg" --det_model_dir="./inference/ch_ppocr_mobile_v2.0_det_infer"  --rec_model_dir="./inference/ch_ppocr_mobile_v2.0_rec_infer" --cls_model_dir="./inference/ch_ppocr_mobile_v2.0_cls_infer" --use_angle_cls=True --use_space_char=True

# 预测image_dir指定的图像集合
python tools/infer/predict_system.py --image_dir="./doc/imgs/" --det_model_dir="./inference/ch_ppocr_mobile_v2.0_det_infer/"  --rec_model_dir="./inference/ch_ppocr_mobile_v2.0_rec_infer/" --cls_model_dir="./inference/ch_ppocr_mobile_v2.0_cls_infer/" --use_angle_cls=True --use_space_char=True

# 如果想使用CPU进行预测,需设置use_gpu参数为False
python tools/infer/predict_system.py --image_dir="./doc/imgs/11.jpg" --det_model_dir="./inference/ch_ppocr_mobile_v2.0_det_infer/"  --rec_model_dir="./inference/ch_ppocr_mobile_v2.0_rec_infer/" --cls_model_dir="./inference/ch_ppocr_mobile_v2.0_cls_infer/" --use_angle_cls=True --use_space_char=True --use_gpu=False
  • 通用中文OCR模型

请按照上述步骤下载相应的模型,并且更新相关的参数,示例如下:

# 预测image_dir指定的单张图像
python tools/infer/predict_system.py --image_dir="./doc/imgs/11.jpg" --det_model_dir="./inference/ch_ppocr_server_v2.0_det_infer/"  --rec_model_dir="./inference/ch_ppocr_server_v2.0_rec_infer/" --cls_model_dir="./inference/ch_ppocr_mobile_v2.0_cls_infer/" --use_angle_cls=True --use_space_char=True
  • 注意:
    • 如果希望使用不支持空格的识别模型,在预测的时候需要注意:请将代码更新到最新版本,并添加参数 --use_space_char=False
    • 如果不希望使用方向分类器,在预测的时候需要注意:请将代码更新到最新版本,并添加参数 --use_angle_cls=False
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

great-wind

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值