PP-OCRv5 英文文本识别模型适配昇腾NPU版本。
| 参数 | 值 |
|---|---|
| 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 |
| 指标 | 数值 |
|---|---|
| 推理时间 | ~0.20s (演示) |
| NPU显存占用 | <1GB (演示) |
| 模型大小 | ~7.5 MB |
torch>=2.0.0
torch_npu>=2.0.0
numpy>=1.21.0
pillow>=9.0.0cd /workspace/agent1/en_PP-OCRv5_mobile_rec-ascend
pip install -r requirements.txt -i https://repo.huaweicloud.com/repository/pypi/simplecd /workspace/agent1/en_PP-OCRv5_mobile_rec-ascend
python inference.py --device npu:0 --show_npu_memory--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解码
|
识别文本