当前位置:   article > 正文

paddleocr - 模型效果对比与推理_paddleocr推理模型和训练模型区别

paddleocr推理模型和训练模型区别

模型效果对比

(1)PP-OCR

(2)端对端-PGNet

模型思路对比

1、PP-OCR

参考:doc/doc_ch/PP-OCRv3_introduction.md · PaddlePaddle/PaddleOCR - Gitee.com

(1)PP-OCR:两阶段的OCR系统,其中文本检测算法选用DB,文本识别算法选用CRNN,并在检测和识别模块之间添加文本方向分类器.

(2)PP-OCRv2:基于PP-OCR在5个方面重点优化,检测模型采用CML协同互学习知识蒸馏策略和CopyPaste数据增广策略;识别模型采用LCNet轻量级骨干网络、UDML 改进知识蒸馏策略和Enhanced CTC loss损失函数改进(如上图红框所示),进一步在推理速度和预测效果上取得明显提升。

(3)PP-OCRv3:基于PP-OCRv2在9个方面进行升级。

 2、PGNet

参考:doc/doc_ch/algorithm_e2e_pgnet.md · PaddlePaddle/PaddleOCR - Gitee.com

端对端OCR算法包括MaskTextSpotter系列、TextSnake、TextDragon、PGNet系列等。在这些算法中,PGNet算法具备其他算法不具备的优势,包括:

(1)设计PGNet loss指导训练,不需要字符级别的标注
(2)不需要NMS和ROI相关操作,加速预测
(3)提出预测文本行内的阅读顺序模块;
(4)提出基于图的修正模块(GRM)来进一步提高模型识别性能
(5)精度更高,预测速度更快

模型下载地址与配置文件

1、PP-OCR

doc/doc_ch/models_list.md · PaddlePaddle/PaddleOCR - Gitee.com

训练模型:可作为预训练模型在自己的数据集上训练新模型

推理模型:直接进行推理,观察识别效果

 2、PGNet

预训练模型下载:

  1. cd PaddleOCR/
  2. 下载step1 预训练模型
  3. wget -P ./pretrain_models/ https://paddleocr.bj.bcebos.com/dygraph_v2.0/pgnet/train_step1.tar
  4. 可以得到以下的文件格式
  5. ./pretrain_models/train_step1/
  6. └─ best_accuracy.pdopt
  7. └─ best_accuracy.states
  8. └─ best_accuracy.pdparams

推理模型下载:

  1. mkdir inference && cd inference
  2. # 下载英文端到端模型并解压
  3. wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/pgnet/e2e_server_pgnetA_infer.tar && tar xf e2e_server_pgnetA_infer.tar

配置文件:configs/e2e/e2e_r50_vd_pg.yml

配置文件的参数介绍:doc/doc_ch/config.md · PaddlePaddle/PaddleOCR - Gitee.com

推理模型使用

1、PP-OCR

命令行使用参考:doc/doc_ch/quickstart.md · PaddlePaddle/PaddleOCR - Gitee.com

源码使用参考:PaddleOCR/quickstart.md at static · PaddlePaddle/PaddleOCR · GitHub

git clone https://github.com/PaddlePaddle/PaddleOCR.git

新建inference文件夹,将下载的推理模型放进来并解压:

(1)测试下det推理模型的效果:

python tools/infer/predict_det.py --image_dir doc/imgs/00111002.jpg --det_model_dir inference/ch_ppocr_server_v2.0_det_infer

结果存储在inference_results下:det_res_00111002.jpg和det_results.txt

 (2)测试下cls推理模型的效果:

python tools/infer/predict_cls.py --image_dir doc/imgs_words/ch/word_4.jpg --cls_model_dir inference/ch_ppocr_mobile_v2.0_cls_infer

 结果:Predicts of doc/imgs_words/ch/word_4.jpg:['0', 0.9999982]

第一个是角度,第二个是置信度

(3)测试下rec推理模型的效果:

python tools/infer/predict_rec.py --image_dir doc/imgs_words/ch/word_4.jpg --rec_model_dir inference/ch_ppocr_server_v2.0_rec_infer

 ppocr INFO: Predicts of doc/imgs_words/ch/word_4.jpg:('交自活具', 0.2635100483894348)

第一个是文字结果,第二个是置信度

(4)综合起来

  1. python tools/infer/predict_system.py --image_dir doc/imgs/00111002.jpg \
  2. --det_model_dir inference/ch_ppocr_server_v2.0_det_infer/ \
  3. --rec_model_dir inference/ch_ppocr_server_v2.0_rec_infer/ \
  4. --cls_model_dir inference/ch_ppocr_mobile_v2.0_cls_infer/ \
  5. --use_angle_cls True \
  6. --use_space_char True

结果存储在inference_results下:00111002.jpg和system_results.txt

 2、PGNet

  1. # 预测image_dir指定的单张图像
  2. python3 tools/infer/predict_e2e.py --e2e_algorithm="PGNet" --image_dir="./doc/imgs_en/img623.jpg" --e2e_model_dir="./inference/e2e_server_pgnetA_infer/" --e2e_pgnet_valid_set="totaltext"
  3. # 预测image_dir指定的图像集合
  4. python3 tools/infer/predict_e2e.py --e2e_algorithm="PGNet" --image_dir="./doc/imgs_en/" --e2e_model_dir="./inference/e2e_server_pgnetA_infer/" --e2e_pgnet_valid_set="totaltext"
  5. # 如果想使用CPU进行预测,需设置use_gpu参数为False
  6. python3 tools/infer/predict_e2e.py --e2e_algorithm="PGNet" --image_dir="./doc/imgs_en/img623.jpg" --e2e_model_dir="./inference/e2e_server_pgnetA_infer/" --e2e_pgnet_valid_set="totaltext" --use_gpu=False

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/342672
推荐阅读
相关标签
  

闽ICP备14008679号