PP-DocLayoutV3 for Core ML (ZenOCR build)

Core ML (mlprogram) conversion of PaddlePaddle/PP-DocLayoutV3_safetensors (revision e4f489dc536556fc1be02b973ba06756e0d4a2ac), used by the ZenOCR macOS app for on-device layout detection.

  • Precision: float32
  • Minimum deployment target: macOS 14
  • Detections verified identical to the unpatched PyTorch model on 31 test images (27 document pages plus blank, black, gray and noise images) on all compute units (.cpuOnly, .cpuAndGPU, .cpuAndNeuralEngine, .all), tested on macOS 27 / Apple M2

Files

File Description
PP-DocLayoutV3-ZenOCR-fp32.mlpackage.aar Core ML model package (Apple Archive, LZFSE; extract with aa extract -i <file> -d <dir> or the AppleArchive framework). Used by the app.
PP-DocLayoutV3-ZenOCR-fp32.mlpackage.zip Same package as zip (identical contents)
convert.py Conversion script used to produce it
LICENSE Apache License 2.0

Input / output

Tensor Shape Notes
pixel_values (in) [1, 3, 800, 800] float32 RGB, resized to 800Γ—800 with bicubic interpolation (aspect ratio not kept), divided by 255, CHW
logits (out) [1, 300, 25] per-query class logits (apply sigmoid)
pred_boxes (out) [1, 300, 4] normalized cx, cy, w, h
order_logits (out) [1, 300, 300] reading-order logits

Post-processing (sigmoid, score threshold, reading order) is not included in the model; see PPDocLayoutV3ImageProcessor.post_process_object_detection in Transformers.

Class index β†’ label

Use this table (from the official inference.yml). Note that the Transformers id2label merges some of these (5/15 β†’ formula, 8/9 β†’ footer, 12/13 β†’ header, 22/23 β†’ text).

id label id label id label
0 abstract 9 footer_image 18 reference
1 algorithm 10 footnote 19 reference_content
2 aside_text 11 formula_number 20 seal
3 chart 12 header 21 table
4 content 13 header_image 22 text
5 display_formula 14 image 23 vertical_text
6 doc_title 15 inline_formula 24 vision_footnote
7 figure_title 16 number
8 footer 17 paragraph_title

Modifications from the original model

The weights are unchanged. To make the network convertible and correct under Core ML, the conversion applies four rewrites, each numerically equivalent to the original PyTorch code:

  1. The 2D sinusoidal position embedding is precomputed as a constant.
  2. Anchor generation avoids in-place slice assignment.
  3. Multi-scale deformable attention is rewritten for batch size 1 with tensors of rank ≀ 5.
  4. mask_to_box_coordinate computes min/max over the 200Γ—200 mask as two reductions (over width, then height) instead of select β†’ flatten β†’ reduce. On macOS 27 the Core ML CPU backend returned wrong results (mostly 0) for the select β†’ flatten β†’ reduce_min pattern while the GPU was correct; the root cause was not identified. The two-step form gives correct results on all compute units in our tests.

The patched functions are adapted from Transformers' modeling_pp_doclayout_v3.py (Apache-2.0). Running convert.py with the pinned environment reproduces the published model (identical compiled program and weights; only conversion metadata differs).

Conversion environment: torch 2.15.0, transformers 5.26.0, coremltools 9.0, numpy 2.3.5, Python 3.12.

License

Apache License 2.0, same as the original PP-DocLayoutV3 weights by PaddlePaddle. This repository contains a modified (converted) form of that work; the modifications are listed above.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Model tree for Taoo425/zenocr-pp-doclayoutv3-coreml

Finetuned
(7)
this model