原始模型: ModelScope - ModelBulider/AIDoc 模型架构: PP-OCRv5 Server (文本检测 + 文字识别) 支持设备: CPU (PaddlePaddle) / NPU (ONNX Runtime)
| 文件 | 说明 |
|---|---|
inference.py | 推理脚本,支持 CPU 和 NPU 两种模式 |
compare_cpu_npu.py | CPU vs NPU 精度对比脚本 |
requirements.txt | Python 依赖包 |
README.md | 本文件 |
使用内置测试图像 test_ocr_image.png(800x400,5 行混合中英文文本)进行测试:
检测到 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)检测到 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.pypip install -r requirements.txt主要依赖:PyTorch 2.0+, torch-npu 2.2+, OpenCV, Pillow, ONNX Runtime
det_model.onnx, rec_model.onnx)本仓库提供完整的推理脚本,支持 CPU 和 NPU 双平台推理:
# NPU 推理
python3 inference.py --device npu
# CPU 推理
python3 inference.py --device cpu推理完成后会输出推理结果和耗时,表明模型在 NPU 上推理成功。