用户可用于评估PP-OCRv4模型在昇腾NPU与CPU上的端到端精度和性能,支持ICDAR2015数据集,能生成精度对比结果,确保NPU与CPU/GPU精度差异小于1%。【此简介由AI生成】
Access rate limit exceeded. Please log in to continue.
RapidOCR Ascend NPU 精度评估项目
基于 PP-OCRv4 模型,在 ICDAR2015 数据集上进行端到端精度与性能评估,支持昇腾 NPU (CANN Execution Provider) 与 CPU 对比。
评估目标
- 不限制 batchsize,让推理引擎自行决定最优 batch
- 端到端时间越少越优
- NPU 与 CPU/GPU 精度差异 < 1%(F1-score 差异在 1 个百分点以内)
环境要求
- 昇腾 NPU 设备(Atlas 800 A2 / A3 等)
- CANN >= 8.0
- Python >= 3.8
- rapidocr >= 3.8
- onnxruntime-cann(ONNX Runtime CANN Execution Provider)
- shapely(用于 IoU 计算)
pip install rapidocr shapely pyyaml
# onnxruntime-cann 请按昇腾官方指引安装
模型说明
本项目使用 PP-OCRv4 官方 ONNX 模型:
| 模块 | 模型文件 |
|---|---|
| 检测 (Det) | ch_PP-OCRv4_det_infer.onnx |
| 分类 (Cls) | ch_ppocr_mobile_v2.0_cls_infer.onnx |
| 识别 (Rec) | ch_PP-OCRv4_rec_infer.onnx |
模型由 rapidocr 首次运行时自动下载,或从 ModelScope / AtomGit 手动下载。
数据集准备
- 下载 ICDAR2015 数据集(可从 ModelScope 获取)
- 解压后得到以下目录结构:
icdar2015/
├── ch4_test_images/
│ ├── img_1.jpg
│ ├── img_2.jpg
│ └── ...
└── gt.zip
- 修改
rapidocr_npu_eval_config.yaml中的Dataset路径:
Dataset:
image_dir: "/actual/path/to/icdar2015/ch4_test_images"
gt_file: "/actual/path/to/icdar2015/gt.zip"
使用方式
1. NPU 推理评估
python eval_icdar15.py \
--image-dir /path/to/icdar2015/ch4_test_images \
--gt-zip /path/to/icdar2015/gt.zip \
--config rapidocr_npu_eval_config.yaml \
--backend npu \
--output-dir ./eval_results
2. CPU 推理评估(用于精度对齐基线)
python eval_icdar15.py \
--image-dir /path/to/icdar2015/ch4_test_images \
--gt-zip /path/to/icdar2015/gt.zip \
--config rapidocr_npu_eval_config.yaml \
--backend cpu \
--output-dir ./eval_results
3. 对比结果
运行完成后,会在 --output-dir 目录下生成:
result_npu.json:NPU 推理的 Precision / Recall / F1 及端到端耗时result_cpu.json:CPU 推理的 Precision / Recall / F1 及端到端耗时
对比两个 JSON 中的 f1 字段,差异应在 1% 以内。
配置说明
rapidocr_npu_eval_config.yaml 关键参数:
| 参数 | 说明 |
|---|---|
EngineConfig.onnxruntime.use_cann |
启用昇腾 NPU(true) |
EngineConfig.onnxruntime.cann_ep_cfg.device_id |
NPU 卡号 |
Det/Cls/Rec.ocr_version |
PP-OCRv4 |
Rec.rec_batch_num |
1024(不限制 batchsize) |
Cls.cls_batch_num |
1024(不限制 batchsize) |
输出示例
========== Evaluation Result ==========
backend: npu
num_images: 500
precision: 0.8234
recall: 0.7912
f1: 0.8069
total_elapse_sec: 45.2301
avg_elapse_per_image_ms: 90.46
=======================================
仓库地址
License
遵循 RapidOCR 原仓库 License。