--- license: mit language: - zh base_model: - PP-OCRv6_mobile_det - PP-OCRv6_mobile_rec - PP-LCNet_x0_25_textline_ori pipeline_tag: text-classification tags: - OCR - paddle - PPOCRv6 - axera --- # PPOCR_v6 > [English](./README.md) | 中文 本版本 PPOCR_v6 已转换为可在爱芯 NPU 上运行的模型,采用 **w8a16** 量化。 ## 转换工具链接 如果您对模型转换感兴趣,可以通过以下链接导出 axmodel: - [ax-samples-github](https://github.com/AXERA-TECH/ax-samples),其他好玩的样例 - [Pulsar2 文档,ONNX 转 axmodel 方法](https://pulsar2-docs.readthedocs.io/en/latest/pulsar2/introduction.html) ## 支持平台 - AX650 - [M4N-Dock(爱芯派Pro)](https://wiki.sipeed.com/hardware/zh/maixIV/m4ndock/m4ndock.html) - [M.2 加速卡](https://axcl-docs.readthedocs.io/zh-cn/latest/doc_guide_hardware.html) - AX630C - [爱芯派2](https://axera-pi-2-docs-cn.readthedocs.io/zh-cn/latest/index.html) - [Module-LLM](https://docs.m5stack.com/zh_CN/module/Module-LLM) - [LLM630 Compute Kit](https://docs.m5stack.com/zh_CN/core/LLM630%20Compute%20Kit) - AX615 - [AX615 IPC SoC](https://www.axera-tech.com/zh-hans/product/2956.html) ### 性能测试 | 芯片 | 模型 | npu_mode | 耗时(ms) | | ----- | ------------------------------- | -------- | ------------ | | | PP-OCRv6_small_det | NPU1 | 42.158 | | | PP-OCRv6_small_det | NPU3 | 23.837 | | AX650 | PP-LCNet_x0_25_textline_ori | NPU1 | 0.294 | | | PP-LCNet_x0_25_textline_ori | NPU3 | 0.172 | | | PP-OCRv6_small_rec | NPU1 | 2.473 | | | PP-OCRv6_small_rec | NPU3 | 1.073 | | | - | - | - | | | PP-OCRv6_small_det | NPU1 | \ | | | PP-OCRv6_small_det | NPU2 | 186.738 | | AX630c| PP-LCNet_x0_25_textline_ori | NPU1 | 0.428 | | | PP-LCNet_x0_25_textline_ori | NPU2 | 0.381 | | | PP-OCRv6_small_rec | NPU1 | 25.251 | | | PP-OCRv6_small_rec | NPU2 | 9.535 | | | - | - | - | | | PP-OCRv6_small_det | NPU1 | \ | | | PP-OCRv6_small_det | NPU2 | 198.401 | | AX615 | PP-LCNet_x0_25_textline_ori | NPU1 | 0.851 | | | PP-LCNet_x0_25_textline_ori | NPU2 | 0.728 | | | PP-OCRv6_small_rec | NPU1 | 36.178 | | | PP-OCRv6_small_rec | NPU2 | 8.036 | 测试方案: ``` bash ax_run_model -w 10 -r 100 -m xx.axmodel ``` 识别和检测的onnx模型来源:[PaddlePaddle/PP-OCRv6](https://huggingface.co/collections/PaddlePaddle/pp-ocrv6) 中 [small-det-onnx](https://huggingface.co/PaddlePaddle/PP-OCRv6_small_det_onnx) 和 [small-rec-onnx](https://huggingface.co/PaddlePaddle/PP-OCRv6_small_rec_onnx) 方向分类器:[AXERA-TECH/PPOCR_v5](https://huggingface.co/AXERA-TECH/PPOCR_v5/tree/main/onnx) ## 使用说明 将本仓库所有文件下载到设备中 ``` PPOCR_v6# tree -L 1 . |-- 11.jpg # 测试图 |-- README-zh.md |-- README.md |-- axmodel # 各个版本的axmodel |-- cls.json # 方向分类模型转换axmodel配置文件 |-- dataset # 量化数据集 与 测试数据集 |-- det.json # 检测模型转换axmodel配置文件 |-- fonts # 绘制字体 |-- onnx # 各模型的原始onnx文件 |-- ppocrv6_ax.py # axmodel运行pipeline |-- ppocrv6_onnx.py # onnx运行pipeline |-- rec.json # 识别模型转换axmodel配置文件 |-- res-ax.jpg # axmodel运行结果 |-- res-onnx.jpg # onnx运行结果 |-- run_det_ax.py # 检测axmodel模型准确率测试文件 |-- run_det_onnx.py # 检测onnx模型准确率测试文件 |-- run_rec_ax.py # 识别axmodel模型准确率测试文件 `-- run_rec_onnx.py # 识别onnx模型准确率测试文件 ``` ### 转换 ``` cd dataset sh download_quant_dataset.sh sh download_val_dataset.sh cd .. pulsar2 build --config det.json pulsar2 build --config cls.json pulsar2 build --config rec.json ``` ### 测试 #### 检测 ``` python python3 run_det_onnx.py --resize_mode letterbox # resize_mode可选:letterbox(默认)、stretch(官方) """ Images: 50 GT boxes: 201 DET boxes: 151 Matched: 77 Precision: 0.5099 (50.99%) Recall: 0.3831 (38.31%) Hmean (F1): 0.4375 """ python3 run_det_ax.py --resize_mode letterbox # resize_mode可选:letterbox(默认)、stretch(官方) """ Images: 50 GT boxes: 201 DET boxes: 150 Matched: 75 Precision: 0.5000 (50.00%) Recall: 0.3731 (37.31%) Hmean (F1): 0.4274 """ ``` 注:`resize_mode`为`stretch`时,为官方做法,直接`resize`到模型输入大小;`letterbox`为右下角填充,与动态输入的`onnx`差距较小,在本项测试中指标较优。可下载 [small-det-onnx](https://huggingface.co/PaddlePaddle/PP-OCRv6_small_det_onnx) 中动态输入 `shape` 的 `inference.onnx` 进行对比。 #### 识别 ``` python python3 run_rec_onnx.py """ Total samples: 2077 Correct (exact match): 1563 Accuracy: 0.7525 (75.25%) Norm Edit Distance: 0.8947 """ python3 run_rec_ax.py """ Total samples: 2077 Correct (exact match): 1518 Accuracy: 0.7309 (73.09%) Norm Edit Distance: 0.8781 """ ``` ### 推理 在 AX650 主机上推理,如 M4N-Dock(爱芯派Pro) 输入图片: ![input](./11.jpg) ``` python python3 ppocrv6_onnx.py --use_angle_cls --visualize --image 11.jpg python3 ppocrv6_ax.py --use_angle_cls --visualize --image 11.jpg ``` 输出图片: ![output](./res-ax.jpg) ### 其他 `tiny`的识别模型量化误差较大,指标如下: ``` onnx-preds: Total samples: 2077 Correct (exact match): 1271 Accuracy: 0.6119 (61.19%) Norm Edit Distance: 0.8263 ax-w8a16-preds: Total samples: 2077 Correct (exact match): 1178 Accuracy: 0.5672 (56.72%) Norm Edit Distance: 0.7941 ``` #### TODO - [x] ax630c性能测试 - [x] ax615性能测试