关于PaddleOCR项目的实战

PaddleOCR实现的是OCR的技术,使用的是百度的框架PaddlePaddle

PaddleOCR aims to create multilingual, awesome, leading, and practical OCR tools that help users train better models and apply them into practice.

对于这个项目的比较厉害的地方在于,可以对于竖向的文字识别且识别率较高

github项目地址:github.com/PaddlePaddl…

项目的简介(主要是从项目的Readme获得):

我们可以从主页中快速的找到这个区域Tutorials,在教程的这个部分,我们可以快速找到Installation、Quick Start这两个部分,对于我们的测试和使用这两个部分就已经足够了,在深入的理解代码的部分,我们可以看看下面的算法的部分、模型的部分、推断的部分、数据的部分等。

090.PNG

Requirements

  • PaddleOCR working environment:
    • PaddlePaddle 2.0.0
    • python3.7
    • glibc 2.23(在我的测试的过程中,使用的是glibc 2.27)

安装说明github.com/PaddlePaddl…

  • 在网站上说明最好按照docker的方式进行安装(我没用)
  • 直接按照安装库环境的形式进行安装

测试

python3 tools/infer/predict_system.py --image_dir="./doc/imgs/007.png" --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
复制代码

实战步骤

首先gpu版本需要安装CUDA 10.1以及cuDNN 7.6.5的环境,这里我们采用现成的环境(易学智能平台),可以免去安装的环境的各种问题,快速的实现项目的搭建,缺点:费钱

1.环境的配置

1.0 跳过前面的易学智能机器的购买的过程

这个部分在我之前的blog中有详细的记录:juejin.cn/post/696575…

1.1 打开终端,切换到指定环境

我们需要的环境是py37-cuda101,切换命令是

conda activate py37-cuda101
复制代码

1008.PNG

1.2 安装PaddlePaddle

在Installation.md中可以找到安装命令

python3 -m pip install paddlepaddle-gpu==2.0.0 -i https://mirror.baidu.com/pypi/simple
复制代码

1.3 下载PaddleOCR项目

这个下载速度很快,可以直接使用git克隆的方式完成

git clone https://github.com/PaddlePaddle/PaddleOCR
复制代码

1.4 进入到项目中,安装环境

在安装requirements.txt的时候,会因为网络波动的原因,多次安装失败,多次尝试几次就好了

cd PaddleOCR
pip3 install -r requirements.txt
复制代码

2.模型的下载

这个部分我们可以阅读Quick Start的部分

091.PNG

我们从上图中可以看到有两个模型的列表,一个比较小,轻量级,这个较小的部分是手机端;另外一个比较大,较为笨重,是服务器端的。

2.1 按照指示下载模型

2.1.1 创建文件夹并进入文件夹
mkdir inference && cd inference
复制代码
2.1.2 下载模型并解压

092.PNG

点击右键,获得下载链接,使用wget下载
wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_server_v2.0_det_infer.tar

下载完成后,使用tar命令进行解压
tar -xvf ch_ppocr_server_v2.0_det_infer.tar
复制代码
2.1.3 下载完成后的目录树结构
├── 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
复制代码

对模型进行测试

The following code implements text detection、angle class and recognition process.

将参数改成自己项目的对应的路径

  • parameter
    • image_dir:the path of a single image or image set
    • det_model_dir:the path to the detection inference model
    • rec_model_dir:the path to the recognition inference model
    • use_angle_cls: whether to use the direction classifier
    • cls_model_dir:the path to the direction classifier model
    • use_space_char: whether to predict the space char
  • result
    • saved to the ./inference_results folder by default
# Predict a single image specified by image_dir
python3 tools/infer/predict_system.py --image_dir="./doc/imgs/007.png" --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

# Predict imageset specified by image_dir
python3 tools/infer/predict_system.py --image_dir="./doc/imgs/" --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

# If you want to use the CPU for prediction, you need to set the use_gpu parameter to False
python3 tools/infer/predict_system.py --image_dir="./doc/imgs/007.png" --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_gpu=False
复制代码

效果展示

第一组(基本全对)

002.jpg
0999.PNG

第二组(基本全对)

007.png

0996.PNG

第三组(对于竖向文字的识别,效果已经很好了)

006.jpg

0997.PNG

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享