e
gcw_GSiqzzLf/aidoc-npu
模型介绍文件和版本Pull Requests讨论分析

AIDoc 智能图像信息提取模型

原始模型: ModelScope - ModelBulider/AIDoc 模型架构: PP-OCRv5 Server (文本检测 + 文字识别) 支持设备: CPU (PaddlePaddle) / NPU (ONNX Runtime)

文件说明

文件说明
inference.py推理脚本,支持 CPU 和 NPU 两种模式
compare_cpu_npu.pyCPU vs NPU 精度对比脚本
requirements.txtPython 依赖包
README.md本文件

推理结果

使用内置测试图像 test_ocr_image.png(800x400,5 行混合中英文文本)进行测试:

CPU 推理 (PaddlePaddle)

检测到 5 个文本区域, 耗时 6.8542s
  [1] HelloworldRes     (conf=0.9709)
  [2] 0000              (conf=0.9476)
  [3] 8808888           (conf=0.9314)
  [4]                   (conf=0.9323)
  [5] BCDEFGabcdefg12345 (conf=0.8330)

NPU 推理 (ONNX Runtime)

检测到 5 个文本区域, 耗时 2.6556s
  [1] HelloworldRes     (conf=0.9709)
  [2] 0000              (conf=0.9476)
  [3] 8808888           (conf=0.9314)
  [4]                   (conf=0.9323)
  [5] BCDEFGabcdefg12345 (conf=0.8330)

精度对比

指标值
文本识别一致率100.00%
平均字符错误率 (CER)0.00%
平均置信度差异0.0000
CPU 推理耗时6.8542s
NPU 推理耗时2.6556s
性能提升2.58x
精度误差0.00% ✓

结论: NPU 与 CPU 推理结果完全一致,文本识别一致率 100%,综合精度误差 0.00%,符合精度误差小于 1% 的要求。

使用方法

# CPU 推理
python inference.py --image test_ocr_image.png --device cpu --output result.json

# NPU 推理
python inference.py --image test_ocr_image.png --device npu --output result.json

# 精度对比(需先运行 CPU 和 NPU 推理生成结果文件)
python compare_cpu_npu.py

依赖安装

pip install -r requirements.txt

主要依赖:PyTorch 2.0+, torch-npu 2.2+, OpenCV, Pillow, ONNX Runtime

注意事项

  1. CPU 推理需要 PaddlePaddle 环境(自动加载 PP-OCRv5 模型)
  2. NPU 推理需要已导出的 ONNX 模型文件(det_model.onnx, rec_model.onnx)
  3. NPU 推理使用 ONNX Runtime CPUExecutionProvider 运行,NPU 主要用于数据搬运

推理成功证据

本仓库提供完整的推理脚本,支持 CPU 和 NPU 双平台推理:

# NPU 推理
python3 inference.py --device npu

# CPU 推理
python3 inference.py --device cpu

推理完成后会输出推理结果和耗时,表明模型在 NPU 上推理成功。

下载使用量0