g
gcw_AVRCax4T/PP-LCNet_x1_0_doc_ori-ONNX
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

PP-LCNet_x1_0_doc_ori - Ascend NPU Adaptation

PP-LCNet document orientation detection model adapted for Huawei Ascend NPU inference. Classifies document images into 4 orientation angles: 0°, 90°, 180°, 270°.

Model Details

  • Model: PP-LCNet_x1_0_doc_ori
  • Source: Liyulingyue/PP-LCNet_x1_0_doc_ori-ONNX
  • Architecture: PP-LCNet (PaddleClas)
  • Input: RGB images, 224x224
  • Output: 4-class softmax (0°, 90°, 180°, 270°)
  • Original Format: ONNX (opset 7)
  • License: Apache 2.0

Ascend NPU Adaptation

This model has been adapted to run on Huawei Ascend NPU (Atlas 800 A2/A3) using:

  • PyTorch 2.9.0 + torch_npu 2.9.0
  • CANN 8.5.1
  • onnx2torch for ONNX to PyTorch conversion
  • onnxruntime for CPU reference validation

Adaptation Workflow

  1. ONNX model (opset 7) → opset 14 version conversion
  2. ONNX → PyTorch model conversion via onnx2torch
  3. PyTorch model → Ascend NPU deployment via torch_npu
  4. Precision validation against CPU reference (onnxruntime)

Quick Start

Environment

  • Huawei Ascend NPU (Atlas 800 A2/A3)
  • CANN 8.5.1+
  • Python 3.11+
  • PyTorch 2.9.0 + torch_npu
  • onnx, onnxruntime, onnx2torch

Installation

# 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

Inference

# 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 100

Python API

from 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")

Evaluation Results

Hardware

  • Device: Ascend910_9362 (Atlas 800 A2)
  • NPU Count: 2
  • CANN: 8.5.1

Precision (NPU vs CPU Reference)

MetricValueStatus
Test samples60-
Max absolute error0.000682PASS
Mean absolute error0.000104PASS
Max relative error0.300%PASS (< 1%)
Label match rate100.00%PASS

Performance (NPU Inference)

MetricValue
Min latency5.23 ms
Median latency5.98 ms
Mean latency~5.6 ms (steady state)
Throughput (bs=1)~172 samples/s

Batch Scaling

Batch SizeLatency (ms)Throughput (samples/s)Speedup
15.82171.931.00x
25.55360.112.09x
45.64708.914.12x
85.661414.808.23x
165.582867.5316.68x

Summary

  • Precision: PASS (< 1% error threshold) - max relative error 0.300%
  • Label Accuracy: 100% (60/60 samples)
  • Performance: ~172 samples/s throughput, ~5.8ms latency per sample
  • Batch Scaling: Near-linear scaling up to 16.68x at batch_size=16

Preprocessing Pipeline

Input Image → Resize(short=256) → CenterCrop(224×224) →
Normalize(mean=[0.485,0.456,0.406], std=[0.229,0.224,0.225]) → CHW → Model

File Structure

pplcnet_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 report

Model Architecture

PP-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:

  • Depthwise separable convolutions
  • HardSwish activation
  • Global average pooling
  • Linear classifier (4-class softmax output)

Citation

@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}},
}