rageyu/platen2-pdf-doclayout
PP-DocLayoutV2 (detection half) — Core ML
Baidu's PP-DocLayoutV2 document-layout detector, converted to Core ML. One RT-DETR forward pass over a page image returns 300 candidate regions across 25 classes — including algorithm, reference_content, abstract and display_formula, which is why it is useful where a coarser vocabulary is not.
Detection only. PP-DocLayoutV2 also carries a reading-order head; it is not included here, and reading order should come from the document's own text layer.
Provenance and changes
Converted from PaddlePaddle/PP-DocLayoutV2, the publisher's own release. The weights are unmodified. That repo publishes a Paddle inference export rather than a checkpoint, so the deploy form was carried across as-is: RepVGG blocks stay folded, q/k/v stays one fused projection, and the auxiliary classification heads are pruned to the one the detection path reads.
Two rewrites were needed for Core ML, neither touching a weight:
- shape values folded to constants, since the 800×800 input makes them constant
- multi-scale deformable attention rewritten to stay at rank 5 by slicing the level before
sampling_locationsis built rather than after
Notes for implementers
- Outputs are padded to a 64-byte row. Read by stride.
- Per-class score thresholds, not one global floor:
text,paragraph_title,doc_titleand the formula classes clear at 0.4,sealat 0.45, everything else at 0.5. - Some high-scoring queries decode to zero-area boxes. Drop them.
Licence
Apache License 2.0, inherited from PaddlePaddle. Copyright (c) PaddlePaddle Authors. Converted to Core ML by tekl; weights unmodified, serialisation and graph form changed as described above.
