Y
YYPGD/en_PP-OCRv5_mobile_rec
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

en_PP-OCRv5_mobile_rec 昇腾NPU部署文档

1. 模型简介

模型名称: en_PP-OCRv5_mobile_rec(PaddlePaddle/en_PP-OCRv5_mobile_rec) 模型链接: https://ai.gitcode.com/paddlepaddle/en_PP-OCRv5_mobile_rec 模型描述: PaddleOCR 团队发布的 PP-OCRv5 英文移动端文本识别模型。PP-OCRv5 是飞桨 OCR 体系第五代识别模型,本权重为其轻量(mobile)版,面向英文及通用符号场景的行级文字识别,兼顾精度与端侧推理速度。输出为 CTC 解码后的文本序列,可直接用于文档数字化、票据识别等下游任务。 模型架构: SVTR 风格轻量卷积/注意力混合骨干(输入 3x48x320)+ 序列建模头 + CTC 解码;字典由 config.json 内置 character_dict 提供(blank=0),支持数字、大小写字母、常用标点与特殊符号。 参数规模: 约 16M 轻量级(inference.pdiparams 约 17MB)

2. 环境依赖

依赖项版本要求说明
Python>= 3.10推荐 3.11
paddlepaddle>= 3.0推理引擎(3.2.2 实测可用),NPU 场景需配套 paddle-custom-npu
numpy / Pillow最新版图像预处理与数组处理
pyyaml / protobuf最新版配置解析
matplotlib最新版结果可视化
昇腾驱动CANN 8.0.RC2+推荐最新版

安装命令:

pip install --target /mnt/workspace/en_PP-OCRv5_mobile_rec/libs -i https://pypi.tuna.tsinghua.edu.cn/simple "paddlepaddle>=3.0" numpy pillow pyyaml matplotlib

3. 推理步骤

3.1 环境准备

# 检查 NPU 设备
npu-smi info
# 权重已就位(Paddle Inference 格式)
ls /home/developer/models/en_PP-OCRv5_mobile_rec/   # inference.json inference.pdiparams config.json inference.yml ...

3.2 运行推理

PYTHONPATH=/mnt/workspace/en_PP-OCRv5_mobile_rec/libs python3 inference.py --model_path /home/developer/models/en_PP-OCRv5_mobile_rec

脚本内置程序化绘制的英文文本行示例图,只传 --model_path 即可跑通;识别结果可视化自动保存到 assets/model_result.png。

3.3 推理参数说明

参数类型默认值说明
--model_pathstr/home/developer/models/en_PP-OCRv5_mobile_rec本地权重目录(离线加载)
--devicestr自动(npu > cuda > cpu)推理设备
--outputstrassets/model_result.png结果可视化保存路径

4. 测试样例及输出结果

样例 1:内置示例图识别文本

输入:

python3 inference.py --model_path /home/developer/models/en_PP-OCRv5_mobile_rec

输出:

[INFO] device = npu
[INFO] 模型加载完成 load_time=x.xxs (en_PP-OCRv5_mobile_rec, inputs=['x'], outputs=['softmax_0.tmp_0'])
[RESULT] 输入张量 shape=(1, 3, 48, 320) dtype=float32
[RESULT] 输出张量 shape=(1, T, C)
[RESULT] 识别文本: '...' (score=0.xxxx)
[INFO] 推理完成 耗时/elapsed=x.xx s (input=(640, 64), device=npu)
[RESULT] status=ok device=npu 耗时/elapsed=x.xx

样例 2:指定设备运行

输入:

python3 inference.py --model_path /home/developer/models/en_PP-OCRv5_mobile_rec --device cpu

输出:

每行输出 [RESULT] 张量/识别文本统计,末行含 耗时/elapsed 字段,status=ok

5. Agent适配截图

5.1 Agent适配全过程截图

Agent 适配流程

5.2 NPU设备调用截图

NPU 设备调用

5.3 模型适配结果截图

模型适配结果

6. 注意事项

  • 权重为 Paddle Inference 格式(inference.json + inference.pdiparams),通过 paddle.inference 加载,设备自动选择 npu > cuda > cpu;
  • NPU 上需安装与 CANN 版本匹配的 paddle-custom-npu 插件;未安装时脚本自动回退 CPU/GPU,不影响流程跑通;
  • 全部权重仅从本地 --model_path 加载,推理全程离线,不联网下载任何文件;
  • 输入张量统一 float32、shape (1, 3, 48, 320),预处理沿用 RecResizeImg 规则(高度 48 等比缩放、右侧补白、(x/255-0.5)/0.5 归一化);
  • 后处理为 CTC 解码(blank=0,去连续重复),字典从 config.json 的 PostProcess.character_dict 读取并按 use_space_char=True 追加空格;
  • 如有精度差异请与官方 pipeline(PaddleOCR PP-OCRv5 en_PP-OCRv5_mobile_rec)输出对比确认。