PP-DocLayoutV4
Document layout analysis with PP-DocLayoutV4 on CPUs and GPUs from several makers: 25 layout classes, a four-point box per region and the reading order of the page. One Python file runs the model on ONNX Runtime, OpenVINO or PaddlePaddle (the official Paddle model); a Rust program runs it on ONNX Runtime. Every path returns the regions of official Paddle inference.
Paper: PP-DocLayoutV4 Everywhere: An ONNX Port with Box-Level Parity across CPUs and GPUs (English; 34 translations) · Models: huggingface.co/omnidoc/PP-DocLayoutV4 · Website: omnidoc.top
One page at a time on one machine, the ONNX model against PaddleX's official Python API: 1.32x on an NVIDIA V100 (14.4 against 10.9 pages/s), 1.42x with ONNX Runtime and 1.36x with OpenVINO on an Intel Xeon (4.61 and 4.80 against 6.53 s/page), with the regions of official Paddle inference (see Results).
| runs | model file | |
|---|---|---|
Python, --device cpu / cuda / dml / migraphx / rocm |
ONNX Runtime: x86-64 CPUs (Intel, AMD), NVIDIA GPUs, any DirectX 12 GPU on Windows, AMD GPUs on Linux | PP-DocLayoutV4.onnx |
Python, --device openvino[:CPU / GPU / NPU] |
OpenVINO: Intel CPUs, integrated and Arc GPUs, NPUs (AMD CPUs too) | PP-DocLayoutV4.onnx |
Python, --device paddle[:gpu] |
PaddlePaddle Inference, CPU or NVIDIA GPU | PP-DocLayoutV4_infer/ (official Paddle model) |
Rust, rust/ |
ONNX Runtime (CPU; CUDA, DirectML, OpenVINO with cargo features) | PP-DocLayoutV4.onnx |
Everything runs in FP32 (OpenVINO is told so: its GPU plugin would otherwise use FP16).
Quick start
git clone https://github.com/omnidocai/PP-DocLayoutV4 && cd PP-DocLayoutV4
python download_model.py # PP-DocLayoutV4.onnx from Hugging Face, SHA-256 checked (paddle / all for the Paddle model)
bash run.sh page.png scans/ paper.pdf -o out --vis # CPU, ONNX Runtime
V4_RUNTIME=openvino bash run.sh scans/ -o out --device openvino # Intel CPU
V4_RUNTIME=openvino bash run.sh scans/ -o out --device openvino:GPU # Intel GPU
V4_RUNTIME=cuda bash run.sh scans/ -o out --device cuda # NVIDIA GPU
V4_RUNTIME=paddle-gpu bash run.sh scans/ -o out --device paddle:gpu # official Paddle model, NVIDIA GPU
Windows:
python download_model.py
run.bat page.png scans\ paper.pdf -o out --vis
set V4_RUNTIME=directml
run.bat scans\ -o out --device dml
The first run creates .venv-<runtime> next to the script and installs requirements.txt (numpy, OpenCV, PyMuPDF)
plus requirements-<runtime>.txt (cpu, cuda, directml, openvino, paddle, paddle-gpu); each runtime keeps
its own environment. Set PIP_INDEX_URL to use a pip mirror and HF_ENDPOINT (e.g. https://hf-mirror.com) for a
Hugging Face mirror. pip install ".[cpu]" (or [cuda], [openvino], [directml], [paddle]) installs the package
with the commands pp-doclayoutv4 and pp-doclayoutv4-download.
Rust:
cd rust && cargo build --release
target/release/pp-doclayoutv4 page.png scans/ -o out --model ../PP-DocLayoutV4.onnx
AMD GPUs (Linux)
ONNX Runtime's AMD builds are published by AMD with ROCm rather than on PyPI. Install ROCm and ONNX Runtime with the
MIGraphX execution provider as AMD's ROCm documentation describes, then pip install -r requirements.txt in the same
environment and run with --device migraphx (older builds: --device rocm). The script checks that the runtime has
the execution provider it needs and says which package to install if not. On Windows, AMD GPUs use --device dml.
In your own code
import v4_layout as v4
model = v4.open_model(device="openvino") # load once; "cpu", "cuda", "dml", "paddle", "paddle:gpu", ...
bgr = v4.load_page("page.png", None, 150)
h, w = bgr.shape[:2]
boxes = v4.postprocess(model.run(v4.preprocess(bgr)[None], [(h, w)]), 0, h, w, conf=0.5)
for b in boxes:
print(b["read_index"], b["class_name"], b["conf"], b["box"])
example.py does the same from the command line: python example.py page.png --device openvino. The Rust library
(pp_doclayoutv4::Model, load_page, detect) is described in rust/README.md.
Output
One JSON per image (out/<name>.json) or PDF page (out/<name>_p0001.json), the same from Python and Rust:
{"source": "paper.pdf", "page": 1, "width": 1275, "height": 1650, "conf_thres": 0.5, "device": "cpu",
"detections": [
{"read_index": 1, "class": 17, "class_name": "paragraph_title", "conf": 0.93,
"box": [150.0, 200.0, 600.0, 230.0], "quad": [[150.2, 199.8], [600.1, 200.0], [600.0, 230.1], [150.1, 230.0]]}
]}
Detections come in reading order; box is the axis-aligned rectangle in page pixels, quad the model's four-point
box. --vis also writes <name>.vis.jpg with the boxes, reading order numbers, classes and scores drawn.
| option | default | |
|---|---|---|
-o / --out |
v4_out |
output folder |
--model |
PP-DocLayoutV4.onnx or PP-DocLayoutV4_infer/ in the current folder, beside the script or in ~/.cache/pp-doclayoutv4 |
model file or Paddle model folder |
--device |
cpu |
see the table above |
--conf |
0.5 | score threshold |
--threads |
0 (the runtime's default) | CPU threads per worker |
--workers |
1 | pages in parallel, one model each |
--dpi |
150 | PDF render resolution |
--vis |
off | draw the boxes |
Pipeline
- Pre-processing: decode, bicubic resize to 800 x 800, BGR to RGB, x / 255, NCHW float32;
im_shape= 800,scale_factor= (800 / h, 800 / w). - Network: the official PP-DocLayoutV4 inference graph, in PaddlePaddle Inference or exported to ONNX with
paddle2onnx 2.1.0 (opset 17, FP32). Inputs
image[N, 3, 800, 800],im_shape[N, 2],scale_factor[N, 2]; outputs: detection rows [M, 10] (class, score, four corners), rows per page [N], query indices [N, 300], relation and successor logits [N, 300, 300], [N, 5]. - Post-processing: score threshold, reading order from the relation and successor logits (PaddleX's V4 decoding), rectangle NMS (0.6 within a class, 0.98 across classes), the official full-page image drop, sort by reading order, +0.5 px shift in the 800 x 800 frame, integer coordinates.
The Rust program does the same in Rust; its resize reproduces OpenCV's default cubic resize (which runs Intel IPP code
on x86) up to 0.0014% of the pixel values, and it decodes JPEG files with the image crate rather than libjpeg-turbo.
Results
Same regions as official Paddle. 470 public pages (arXiv papers and DocLayNet pages), score threshold 0.5, the post-processing above; reference: the official inference graph in Paddle Inference 3.3.1 on an NVIDIA V100, FP32. Regions are matched one to one (same class, IoU >= 0.5).
| ONNX Runtime CPU | OpenVINO CPU | ONNX Runtime CUDA | Rust (ONNX Runtime CPU) | |
|---|---|---|---|---|
| regions (reference 9,845) | 9,845 | 9,845 | 9,845 | 9,845 |
| lost + added + reclassified | 0 | 0 | 0 | 0 |
| identical coordinates | 9,841 | 9,838 | 9,838 | 9,839 |
| off by one pixel | 4 | 7 | 7 | 6 |
| off by more than one pixel | 0 | 0 | 0 | 0 |
| reading-order swaps | 0 | 0 | 0 | 0 |
| pages identical in every region | 466 | 464 | 463 | 464 |
The one-pixel differences are coordinates within float rounding of a half-pixel boundary.
Same accuracy as official Paddle on PaddleX's own demo dataset. det_layout_examples, the layout dataset of the
PaddleX documentation (110 annotated Chinese pages, 1,185 boxes, the 10 CDLA classes; figure and table captions
evaluated together since V4 has one caption class):
| official Paddle (V100) | Python paddle:gpu |
ONNX Runtime CUDA | ONNX Runtime CPU | OpenVINO CPU | Rust | |
|---|---|---|---|---|---|---|
| regions returned | 2,414 | 2,414 | 2,414 | 2,414 | 2,414 | 2,414 |
| lost + added + reclassified / reading-order swaps | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | |
| identical coordinates (off by one pixel) | 2,414 (0) | 2,413 (1) | 2,413 (1) | 2,413 (1) | 2,365 (49) | |
| mAP@0.50:0.95 / mAP@0.50 / recall@0.50 (%) | 36.18 / 65.35 / 83.52 | 36.18 / 65.35 / 83.52 | 36.18 / 65.35 / 83.52 | 36.18 / 65.35 / 83.52 | 36.18 / 65.35 / 83.52 | 36.17 / 65.34 / 83.52 |
The Python Paddle path returns official Paddle's output bit for bit, scores included; the Rust program's one-pixel differences on these JPEG pages come from its JPEG decoder.
Speed. One page at a time, from decoding to regions, medians of three interleaved rounds on one machine (NVIDIA
V100-SXM2 16 GB; Intel Xeon E5-2696 v4). The baseline is PaddleX's official Python API (create_model + predict);
no released PaddleX contains PP-DocLayoutV4 yet, so it runs PP-DocLayoutV3, the same family at the same input size.
| V100 (pages/s) | Xeon, one socket (s/page) | |
|---|---|---|
| PaddleX API, PP-DocLayoutV3 (CPU: its defaults, 10 threads) | 10.9 | 6.53 |
| this package, ONNX Runtime (CPU: 8 threads) | 14.4 | 4.61 |
| this package, OpenVINO (8 threads) | 4.80 |
GPU processes run on the GPU's own CPU socket (numactl --cpunodebind=0 --membind=0 on this two-socket machine):
unpinned, Paddle's threads spread over both sockets and the API ran at 6.1 to 7.1 pages/s. The Python Paddle path runs
at the official Paddle model's own speed (19.9 pages/s on the V100). Speeds on other hardware differ.
Model files
On Hugging Face, huggingface.co/omnidoc/PP-DocLayoutV4;
python download_model.py [onnx|paddle|all] fetches them and checks their SHA-256:
| file | bytes | SHA-256 |
|---|---|---|
PP-DocLayoutV4.onnx |
153,111,775 | 800db25f046af9395f7acde36c51a93fe2fce8019cfbb1bacb5a663d83a4c233 |
PP-DocLayoutV4_infer/inference.json |
1,272,437 | ab841469f943b754d4e93d43bf90899274d266b1f28e439197bc7199dd146d07 |
PP-DocLayoutV4_infer/inference.pdiparams |
132,771,206 | 7d6057d36b99d2f8f8df39e173f10efd5eff512196620c7912b8d29172bc4f88 |
PP-DocLayoutV4_infer/inference.yml |
1,482 | 12073ce49d0f7c96fc5ad5ebda2098267913b6b4a21fe453a9085765034ee408 |
The ONNX file is the official PP-DocLayoutV4 inference graph exported to ONNX (opset 17, FP32) with added operators
that leave every output unchanged (checked bit for bit on 32 pages with ONNX Runtime CPU, OpenVINO CPU and ONNX
Runtime CUDA). PP-DocLayoutV4_infer/ is the official Paddle inference model.
Paper
PP-DocLayoutV4 Everywhere: An ONNX Port with Box-Level Parity across CPUs and GPUs (English, 10 pages). Translations, made with OmniDoc's document translation:
简体中文 · 繁體中文 · 日本語 · 한국어 · Français · Deutsch · Español · Português · Italiano · Русский · العربية · हिन्दी · বাংলা · Bahasa Indonesia · Tiếng Việt · ไทย · Türkçe · Nederlands · Polski · Українська · Svenska · Čeština · Ελληνικά · עברית · فارسی · Bahasa Melayu · Română · Magyar · Dansk · Suomi · Norsk · Slovenčina · Български · Hrvatski
License
Code: Apache License 2.0 (see LICENSE). The reading-order decoding follows PaddleX (Apache-2.0, see NOTICE).
PP-DocLayoutV4 is a model by the PaddlePaddle team; the model files are subject to its upstream terms.
Metadata
Release files for pp-doclayoutv4 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pp_doclayoutv4-0.1.0.tar.gz | 21.9 kB | Without provenance | Details for pp_doclayoutv4-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pp_doclayoutv4-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for pp_doclayoutv4-0.1.0-py3-none-any.whl |
Total release size: 43.8 kB
Release files / pp_doclayoutv4-0.1.0.tar.gz
| Download URL | pp_doclayoutv4-0.1.0.tar.gz |
|---|---|
| Size | 21.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c6facd5ef7c53a9f902be0b8f8ae9d014386eb47fe972b8be4e179af80fc9d9b
|
|
BLAKE2b-256 checksum How to use checksums |
d7c02c2a84043d4c409d416912df9d5c56b54d4cdc74898fbe7b8de2b2e3c7e1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.11
|
Release files / pp_doclayoutv4-0.1.0-py3-none-any.whl
| Download URL | pp_doclayoutv4-0.1.0-py3-none-any.whl |
|---|---|
| Size | 21.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8296436105be6ccc9d76195f90b65404ace15eb611284c02798a3f823f7e1301
|
|
BLAKE2b-256 checksum How to use checksums |
98b3dafe30a3e8c7569d1150a3548609d4035dbe12d4145cb525a7e6bfcd212b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.11
|
Security for pp-doclayoutv4 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.