PP-LCNet document orientation detection model adapted for Huawei Ascend NPU inference. Classifies document images into 4 orientation angles: 0°, 90°, 180°, 270°.
This model has been adapted to run on Huawei Ascend NPU (Atlas 800 A2/A3) using:
# 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")| Metric | Value | Status |
|---|---|---|
| Test samples | 60 | - |
| Max absolute error | 0.000682 | PASS |
| Mean absolute error | 0.000104 | PASS |
| Max relative error | 0.300% | PASS (< 1%) |
| Label match rate | 100.00% | PASS |
| Metric | Value |
|---|---|
| Min latency | 5.23 ms |
| Median latency | 5.98 ms |
| Mean latency | ~5.6 ms (steady state) |
| Throughput (bs=1) | ~172 samples/s |
| Batch Size | Latency (ms) | Throughput (samples/s) | Speedup |
|---|---|---|---|
| 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 is a lightweight CNN architecture from PaddleClas designed for efficient image classification. This specific model is trained for document orientation detection, classifying input images into 4 orientation categories (0°, 90°, 180°, 270°).
Key architecture features:
@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}},
}