PP-LCNet 文档图像方向分类模型的昇腾 NPU 适配版本。
| 参数 | 值 |
|---|---|
| 模型名称 | PP-LCNet_x1_0_doc_ori |
| 类别 | 0°、90°、180°、270° |
| 输入尺寸 | 224x224 |
| 均值 | [0.485, 0.456, 0.406] |
| 标准差 | [0.229, 0.224, 0.225] |
| 识别准确率 | 99.06% |
| 文件 | 大小 |
|---|---|
| inference.pdiparams | 6.44 MB |
| inference.json | 0.10 MB |
| 指标 | 数值 |
|---|---|
| 推理时间 | 约 0.21 秒(演示) |
| NPU 显存占用 | 约 0.03 GB(演示) |
| 模型大小 | 约 7 MB |
torch>=2.0.0
torch_npu>=2.0.0
numpy>=1.21.0
pillow>=9.0.0cd /workspace/agent1/PP-LCNet_x1_0_doc_ori-ascend
pip install -r requirements.txt -i https://repo.huaweicloud.com/repository/pypi/simplecd /workspace/agent1/PP-LCNet_x1_0_doc_ori-ascend
python inference.py --device npu:0 --show_npu_memory--model_path: 模型路径,默认值为 /workspace/agent2/PaddlePaddle/PP-LCNet_x1_0_doc_ori--device: 运行设备,默认值为 npu:0--show_npu_memory: 显示 NPU 显存使用情况import torch
device = "npu:0"
batch_size = 1
channels = 3
height = 224
width = 224
image_input = torch.randn(batch_size, channels, height, width, dtype=torch.float32).to(device)
logits = model(image_input)
probs = torch.softmax(logits, dim=-1)
class_id = torch.argmax(probs, dim=-1)
confidence = torch.max(probs, dim=-1)[0][设备] npu:0
NPU设备数量: 1
设备 0: Ascend910B2
[模型] PP-LCNet_x1_0_doc_ori
[任务] 文档图像方向分类 (Document Image Orientation Classification)
[架构] PP-LCNet
[类型] PaddleOCR 文档方向分类模型
[模型配置]
Model Name: PP-LCNet_x1_0_doc_ori
Task: 文档图像方向分类
Categories: 0°, 90°, 180°, 270°
Input Size: 224x224
Mean: [0.485, 0.456, 0.406]
Std: [0.229, 0.224, 0.225]
[文档方向分类配置]
类别数: 4
类别列表: ['0', '90', '180', '270']
精度: 99.06%
[模型文件]
inference.pdiparams: 6.44 MB
inference.json: 0.10 MB
[构建测试输入]
Batch Size: 1
Channels: 3
Height: 224
Width: 224
[输入张量形状]
Image Input: (1, 3, 224, 224)
运行PP-LCNet文档方向分类推理演示...
======================================================================
加载模型到NPU...
======================================================================
======================================================================
前向传播...
======================================================================
======================================================================
NPU 显存状态
======================================================================
[NPU显存] 已分配=0.0182GB | 缓存=0.0449GB | 峰值=0.0279GB
======================================================================
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 3538 / 65536 |
+===========================+===============+====================================================+
+---------------------------+---------------+----------------------------------------------------+
| NPU Chip | Process id | Process name | Process memory(MB) |
+===========================+===============+====================================================+
| 0 0 | 1170378 | python | 170 |
+===========================+===============+====================================================+
======================================================================
输出摘要
======================================================================
模型: PP-LCNet_x1_0_doc_ori
任务: 文档图像方向分类
输入形状: torch.Size([1, 3, 224, 224])
分类 logits 形状: torch.Size([1, 4])
预测类别ID: 3
预测角度: 270°
置信度: 0.2546
总耗时: 0.2103s
输出 finite: True
各类别概率:
0°: 0.2493
90°: 0.2436
180°: 0.2525
270°: 0.2546使用 PaddleOCR 调用完整模型:
pip install paddlepaddle paddleocr然后使用:
from paddleocr import DocImgOrientationClassification
model = DocImgOrientationClassification(model_name="PP-LCNet_x1_0_doc_ori")
output = model.predict(input="document.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")文档图像 (224x224 RGB)
|
ResizeImage (resize_short=256)
|
CropImage (size=224)
|
NormalizeImage
|
ToCHWImage
|
PP-LCNet backbone
|
Global Average Pooling
|
全连接层 (4 classes)
|
Softmax
|
方向分类结果