适用于华为昇腾NPU推理的PP-LCNet文档方向检测模型。 将文档图像分类为4种方向角度:0°、90°、180°、270°。
该模型已适配华为昇腾NPU(Atlas 800 A2/A3),使用以下工具:
# Install dependencies
pip install torch torch_npu onnx onnxruntime onnx2torch pillow numpy
# Download model from ModelScope
pip install modelscope
modelscope download --model Liyulingyue/PP-LCNet_x1_0_doc_ori-ONNX# Quick test (random input)
python3 inference.py
# Single image inference
python3 inference.py --image /path/to/document.jpg
# Accuracy comparison (NPU vs CPU)
python3 inference.py --compare
# Performance benchmark
python3 inference.py --benchmark --num-runs 100from inference import load_pytorch_model, PPImagePreprocessor, run_npu_inference
from PIL import Image
import torch
# Load model
model = load_pytorch_model()
# Preprocess
preprocessor = PPImagePreprocessor()
img = Image.open("document.jpg")
input_arr = preprocessor(img)
input_tensor = torch.from_numpy(input_arr)
# NPU inference
output = run_npu_inference(model, input_tensor)
orientation = ["0", "90", "180", "270"][output.argmax()]
print(f"Document orientation: {orientation} degrees")| 指标 | 数值 | 状态 |
|---|---|---|
| 测试样本数 | 60 | - |
| 最大绝对误差 | 0.000682 | 通过 |
| 平均绝对误差 | 0.000104 | 通过 |
| 最大相对误差 | 0.300% | 通过(< 1%) |
| 标签匹配率 | 100.00% | 通过 |
| 指标 | 数值 |
|---|---|
| 最小延迟 | 5.23 ms |
| 中位延迟 | 5.98 ms |
| 平均延迟 | ~5.6 ms(稳定状态) |
| 吞吐量(bs=1) | ~172 样本/秒 |
| 批处理大小 | 延迟(ms) | 吞吐量(样本/秒) | 加速比 |
|---|---|---|---|
| 1 | 5.82 | 171.93 | 1.00x |
| 2 | 5.55 | 360.11 | 2.09x |
| 4 | 5.64 | 708.91 | 4.12x |
| 8 | 5.66 | 1414.80 | 8.23x |
| 16 | 5.58 | 2867.53 | 16.68x |
Input Image → Resize(short=256) → CenterCrop(224×224) →
Normalize(mean=[0.485,0.456,0.406], std=[0.229,0.224,0.225]) → CHW → Modelpplcnet_npu/
├── inference.py # Main inference script (NPU/CPU)
├── evaluate.py # Precision & performance evaluation
├── README.md # This document
└── evaluation/
├── precision_results.json # Precision evaluation data
├── performance_results.json # Performance benchmark data
├── batch_results.json # Batch scaling data
└── evaluation_report.md # Auto-generated evaluation reportPP-LCNet 是 PaddleClas 推出的一种轻量级 CNN 架构,专为高效图像分类任务设计。 本特定模型经过训练,用于文档方向检测,可将输入图像分为 4 个方向类别(0°、90°、180°、270°)。
主要架构特点:
@misc{pplcnet_ascend_npu,
title={PP-LCNet Document Orientation Detection - Ascend NPU Adaptation},
author={Ascend NPU Adaptation},
year={2026},
howpublished={\url{https://www.modelscope.cn/models/Liyulingyue/PP-LCNet_x1_0_doc_ori-ONNX}},
}