冬
gcw_IDzXRVNw/en_PP-OCRv5_mobile_rec-ascend
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

en_PP-OCRv5_mobile_rec-ascend

PP-OCRv5 英文文本识别模型适配昇腾NPU版本。

模型简介

  • 基础模型: PaddlePaddle/en_PP-OCRv5_mobile_rec
  • 任务: 文本识别 (Text Recognition)
  • 架构: SVTR + CTC
  • 类型: PaddleOCR 文本识别模型
  • 开发公司: PaddlePaddle

模型特点

  • PP-OCRv5 移动端英文文本识别模型
  • 基于 SVTR (Vision Transformer) 骨干网络
  • 使用 CTC 解码器进行序列标注
  • 支持 543 个字符类别
  • 高精度: 85.3%

模型配置

参数值
Model Nameen_PP-OCRv5_mobile_rec
Task文本行识别
Recognition MethodSVTR + CTC
Input Size48x320 (可变)
Accuracy85.3%
Character Classes543

模型文件

文件大小
inference.pdiparams7.41 MB
inference.json0.21 MB

性能表现

指标数值
推理时间~0.20s (演示)
NPU显存占用<1GB (演示)
模型大小~7.5 MB

环境依赖

torch>=2.0.0
torch_npu>=2.0.0
numpy>=1.21.0
pillow>=9.0.0

分步推理流程

1. 安装依赖

cd /workspace/agent1/en_PP-OCRv5_mobile_rec-ascend
pip install -r requirements.txt -i https://repo.huaweicloud.com/repository/pypi/simple

2. 运行推理

cd /workspace/agent1/en_PP-OCRv5_mobile_rec-ascend
python inference.py --device npu:0 --show_npu_memory

3. 参数说明

  • --model_path: 模型路径,默认 /workspace/agent2/PaddlePaddle/en_PP-OCRv5_mobile_rec
  • --device: 运行设备,默认 npu:0
  • --show_npu_memory: 显示NPU显存使用情况

测试用例与输出

测试代码

import torch

device = "npu:0"
batch_size = 1
channels = 3
img_height = 48
img_width = 320

text_image = torch.randn(batch_size, channels, img_height, img_width, dtype=torch.float32).to(device)

logits = model(text_image)
log_probs = torch.log_softmax(logits, dim=-1)

完整输出

[设备] npu:0
NPU设备数量: 1
  设备 0: Ascend910B2

[模型] en_PP-OCRv5_mobile_rec
[任务] 文本识别 (Text Recognition)
[架构] SVTR + CTC
[类型] PaddleOCR 文本识别模型

[模型配置]
  Model Name: en_PP-OCRv5_mobile_rec
  Task: 文本行识别
  Recognition Method: SVTR + CTC
  Input Size: 48x320 (可变)
  Accuracy: 85.3%
  Character Classes: 543

[模型文件]
  inference.pdiparams: 7.41 MB
  inference.json: 0.21 MB

[构建测试输入]
  Batch Size: 1
  Channels: 3
  Height: 48
  Width: 320
  Num Classes: 543

[输入张量形状]
  Text Line Image: (1, 3, 48, 320)

运行en_PP-OCRv5_mobile_rec文本识别推理演示...

======================================================================
加载模型到NPU...
======================================================================

======================================================================
前向传播...
======================================================================

======================================================================
NPU 显存状态
======================================================================
[NPU显存] 已分配=0.0128GB | 缓存=0.0605GB | 峰值=0.0433GB

======================================================================
NPU 信息 (npu-smi info)
======================================================================
+------------------------------------------------------------------------------------------------+
| npu-smi 25.5.2                   Version: 25.5.2                                               |
+---------------------------+---------------+----------------------------------------------------+
| NPU   Name                | Health        | Power(W)    Temp(C)           Hugepages-Usage(page)|
| Chip                      | Bus-Id        | AICore(%)   Memory-Usage(MB)  HBM-Usage(MB)        |
+===========================+===============+====================================================+
| 0     910B2               | OK            | 104.0       41                0    / 0             |
| 0                         | 0000:C1:00.0  | 0           0    / 0          3552 / 65536         |
+===========================+===============+====================================================+
+---------------------------+---------------+----------------------------------------------------+
| NPU     Chip              | Process id    | Process name             | Process memory(MB)      |
+===========================+===============+====================================================+
| 0       0                 | 1173878       | python                   | 184                     |
+===========================+===============+====================================================+


======================================================================
输出摘要
======================================================================
  模型: en_PP-OCRv5_mobile_rec
  任务: 文本识别
  输入形状: torch.Size([1, 3, 48, 320])
  输出 logits 形状: torch.Size([1, 400, 543])
  时间步数: 400
  总耗时: 0.1997s
  输出 finite: True

  输出 logits 统计:
    min: -0.0604
    max: 0.0559
    mean: 0.0018

  CTC解码后需要后处理获取文本
  字符集大小: 543

完整使用

完整模型使用 PaddleOCR:

pip install paddlepaddle paddleocr

然后使用:

from paddleocr import TextRecognition

model = TextRecognition(model_name="en_PP-OCRv5_mobile_rec")
output = model.predict(input="text_image.png", batch_size=1)

for res in output:
    res.print()
    res.save_to_img(save_path="./output/")
    res.save_to_json(save_path="./output/res.json")

架构详情

推理流程

文本行图像 (48x320 RGB)
    |
SVTR Encoder (CNN + Transformer)
    |
特征序列 (seq_len x 512)
    |
CTC Head
    |
字符类别 logits (seq_len x 543)
    |
CTC解码
    |
识别文本

核心组件

  1. Input: 文本行图像 RGB
  2. SVTR Encoder: CNN特征提取 + Transformer编码
  3. CTC Head: 序列到字符的映射
  4. CTC Decode: 贪婪或束搜索解码

应用场景

  • 英文文本识别
  • OCR文本提取
  • 文档数字化
  • 车牌识别
  • 名片识别

注意事项

  1. 当前演示使用随机张量展示NPU推理流程
  2. 模型约 7.5MB
  3. 支持 fp32 精度
  4. 需要 CTC 解码后处理获取文本

参考链接

  • en_PP-OCRv5_mobile_rec 官方模型
  • PaddleOCR
  • PaddleOCR Documentation