PaddlePaddle PP-DocLayoutV3 Document Layout Detection Model Adapted for Huawei Ascend 910 NPU Inference
PP-DocLayoutV3 is a DETR-based document layout detection model from PaddleOCR-VL-1.5, engineered for non-planar document images. It predicts multi-point bounding boxes for 23 layout element categories and determines logical reading orders, handling skewed and curved surfaces in a single forward pass.
| Property | Value |
|---|---|
| Architecture | DETR (DEtection TRansformer) |
| Parameters | 739 (Conv2D + BatchNorm + Linear layers) |
| Input | RGB Image 800×800 |
| Output | Bounding boxes + labels + confidence scores |
| Categories | 23 document layout types |
| Framework | PaddlePaddle 3.x (PIR format) |
| Original Source | PaddlePaddle/PP-DocLayoutV3 |
abstract, algorithm, aside_text, chart, content, display_formula, doc_title,
figure_title, footer, footer_image, footnote, formula_number, header,
header_image, image, inline_formula, number, paragraph_title, reference,
reference_content, seal, table, text, vertical_text, vision_footnote
| Component | Version |
|---|---|
| NPU | Huawei Ascend 910 (×2) |
| CANN | 8.5.1 |
| torch_npu | 2.9.0.post1 |
| PyTorch | 2.9.0 |
| PaddlePaddle | 3.3.1 |
| Python | 3.11.14 |
The PP-DocLayoutV3 model uses PaddlePaddle 3.x PIR (Paddle Intermediate Representation) format. Due to PIR format limitations with ONNX export, this adaptation employs a hybrid approach:
| Metric | Value | Status |
|---|---|---|
| CPU vs NPU Preprocessing Max Diff | 0.000000 | PASS |
| CPU vs NPU Preprocessing Mean Diff | 0.000000 | PASS |
| Exact Match Ratio | 100.00% | PASS |
| Output Determinism (5 runs) | 0.00e+00 | PASS |
Accuracy target met: < 1% error across all output values.
pip install paddlepaddle paddle2onnx opencv-python
pip install torch torch_npu # Ascend NPU only
pip install modelscopemodelscope download --model PaddlePaddle/PP-DocLayoutV3# Single image inference
python3 inference.py --image document.jpg --output result.jpg
# With JSON output
python3 inference.py --image document.jpg --json detections.json
# CPU-only mode
python3 inference.py --image document.jpg --device cpu
# Benchmark mode
python3 inference.py --image document.jpg --benchmark 50import cv2
from inference import PP_DocLayoutV3
# Initialize model on NPU
model = PP_DocLayoutV3(device="npu")
# Run detection
image = cv2.imread("document.jpg")
detections, elapsed = model.detect(image, threshold=0.5)
for det in detections:
print(f"[{det['label']}] {det['score']:.3f} at {det['bbox']}")# Full evaluation (accuracy + performance)
python3 evaluate.py --image test_document.jpg
# Performance benchmark (NPU vs CPU)
python3 benchmark.py --warmup 10 --measure 100| Metric | CPU Preprocessing | NPU Preprocessing | Unit |
|---|---|---|---|
| Mean Latency | 4464.2 | 4481.0 | ms |
| P95 Latency | 4474.6 | 4520.0 | ms |
| Throughput | 0.2 | 0.2 | FPS |
Note: Model inference runs on CPU via PaddlePaddle (4.5s per forward pass). For full NPU acceleration, the model must be converted to Ascend OM format via ONNX → ATC. The NPU preprocessing path shows identical accuracy to CPU preprocessing (100% match).
For full NPU acceleration of model computation (not just preprocessing), follow these steps:
# Convert PaddlePaddle model to ONNX
paddle2onnx \
--model_dir /path/to/PP-DocLayoutV3 \
--model_filename inference.pdmodel \
--params_filename inference.pdiparams \
--save_file model.onnx \
--opset_version 14atc --model=model.onnx \
--framework=5 \
--output=model.om \
--soc_version=Ascend910 \
--input_shape="image:1,3,800,800;im_shape:1,2;scale_factor:1,2" \
--input_format=NDimport acl
# Initialize ACL runtime
acl.init()
# Load OM model
model_id, _ = acl.mdl.load_from_file("model.om")
# Create dataset with input buffers
# Run inference on NPU
acl.mdl.execute(model_id, dataset)Known limitation: PaddlePaddle 3.x PIR format does not support direct ONNX export via
paddle.onnx.export. The model needs to be re-exported from the original PaddleDetection training pipeline using non-PIR format for ONNX conversion.
PP-DocLayoutV3-NPU/
├── inference.py # Main inference script with NPU support
├── evaluate.py # Accuracy & performance evaluation suite
├── benchmark.py # NPU vs CPU performance comparison
├── README.md # This document
├── evaluation_report.json # Accuracy evaluation results
└── benchmark_results.json # Performance benchmark resultsIf you find this NPU adaptation helpful, cite the original PP-DocLayoutV3 model:
@article{paddleocr2025,
title={PaddleOCR-VL-1.5: High-Precision Document Parsing with Visual Language Models},
journal={arXiv preprint arXiv:2510.14528},
year={2025}
}This NPU adaptation follows the original model's Apache 2.0 License.