PDF Layout Detection#
Layout detection is the stage in MinerU's pipeline that identifies and classifies structural regions — text blocks, titles, tables, images, formulas, and more — in each PDF page image before any content extraction occurs. Because all downstream steps (OCR, formula recognition, reading-order assignment) consume the bounding boxes emitted here, any region the layout model misses is permanently lost from the output .
The core model is PP-DocLayoutV2, implemented as PPDocLayoutV2LayoutModel (Transformers backend) and a shared post-processing base in pp_doclayout_v2_base.py. PP-DocLayoutV2 is an RT-DETR-based object detector that also predicts reading order via a transformer decoder.
25-Class Taxonomy#
The model produces predictions across 25 layout classes defined in PP_DOCLAYOUT_V2_LABELS:
| ID | Label | Description |
|---|---|---|
| 0 | abstract | Paper abstract |
| 1 | algorithm | Algorithm block |
| 2 | aside_text | Margin annotation |
| 3 | chart | Chart/figure |
| 4 | content | Table-of-contents block |
| 5 | display_formula | Stand-alone formula |
| 6 | doc_title | Document title |
| 7 | figure_title | Caption for image/chart/table |
| 8 | footer | Page footer text |
| 9 | footer_image | Page footer image |
| 10 | footnote | Page footnote |
| 11 | formula_number | Formula index label |
| 12 | header | Page header text |
| 13 | header_image | Page header image |
| 14 | image | Image |
| 15 | inline_formula | Inline formula |
| 16 | number | Page number |
| 17 | paragraph_title | Section heading |
| 18 | reference | Reference list container |
| 19 | reference_content | Reference list item |
| 20 | seal | Seal/stamp |
| 21 | table | Table |
| 22 | text | General body text |
| 23 | vertical_text | Vertical text |
| 24 | vision_footnote | Image/chart/table footnote |
Detection Pipeline#
The batch_predict method is the main entry point for both Hybrid and Pipeline backends:
- Preprocess — each page image is resized and normalized via
_preprocess_single_image() - Inference —
self.model(pixel_values=batch_tensor)runs the RT-DETR detector - Score filter —
_post_process_object_detectionapplies a globalscore >= self.confcutoff (defaultconf=0.45) - Post-process —
_apply_paddlex_filter_boxes(optional) then_apply_layout_post_processrun sequentially :- IoU deduplication at threshold 0.9
- Nested formula box merging and relabeling
- Formula filtering when an explicit
header,header_image,footer, orfooter_imageparent covers at least 80% of the formula box; page-edge position alone does not remove formulas - Header/footer boundary relabeling (anchored on detected
header/footerboxes), preserving formula labels; footnote relabeling also preserves formulas and formula numbers - Internal caption filtering
- Same-label, fully contained text-box deduplication, keeping the larger box and preserving the surviving boxes' reading order; formulas, formula numbers, and visual/list containers are excluded
These rules are shared by the Torch and ONNX layout backends in _apply_layout_post_process.
The DEFAULT_CLASS_THRESHOLDS list defines per-class floors. The six most sensitive classes (lowest threshold = 0.4) are display_formula, doc_title, inline_formula, paragraph_title, text, and vertical_text. All other classes default to 0.5, except seal at 0.45.
Note:
DEFAULT_CLASS_THRESHOLDSis defined but not applied insidePPDocLayoutV2LayoutModel.batch_predictitself — the active gate is the singleself.confscalar . The per-class list is exported for potential downstream use or ONNX backends.
Backend Comparison#
| Backend | Layout detection | Entry point |
|---|---|---|
Pipeline (pipeline-engine) | Calls PP-DocLayoutV2 in batch | batch_analyze.py |
Hybrid medium (hybrid-engine) | Calls PP-DocLayoutV2; result fed as hint to VLM | hybrid_analyze.py |
Hybrid high (hybrid-engine -e high) | VLM performs two-step layout + extraction | hybrid_analyze.py |
VLM (vlm-engine) | End-to-end VLM; bypasses PP-DocLayoutV2 entirely | vlm_analyze.py |
The VLM backend's immunity to PP-DocLayoutV2 detection failures is architectural: it calls predictor.batch_two_step_extract() where the vision-language model handles structural understanding end-to-end .
Known Issues#
Dense Layout / Chinese PDF Text Block Misses (Issue #5229)#
Symptom: In pages with tightly packed multi-record layouts (e.g., Chinese university admissions documents, military academy sections), the Hybrid backend's Layout Predict phase fails to generate bounding boxes for some text regions. The affected records are completely absent from output; the middle.json para_blocks shows a vertical gap where content should appear .
Root cause: PP-DocLayoutV2 produces confidence scores below its detection floor for certain dense regions. The failure is in the layout model's bbox generation — not OCR — confirmed by --mode txt still reproducing the omission .
Workaround: Use hybrid-engine --effort high or fall back to vlm-engine. The VLM backend correctly detected all missing records in comparative testing, at approximately 40% slower throughput .
docvortex _reattach_cross_lane_short_tails Non-Convergence (Issue #5552)#
Symptom: After Layout Predict and OCR-det complete (both show 100%), the process stalls indefinitely on a single CPU core. py-spy shows 77% of samples in _reattach_cross_lane_short_tails in docvortex/analyzers/native/pdf/line_layout.py .
Root cause: The function uses an unbounded while True loop for lane-assignment. Certain page layouts trigger oscillating lane swaps (A→B→A→B…) with no convergence. A user-proposed fix — tracking moved lines with a moved_line_ids set to allow at most one move per line per call — resolved the stall .
Fix: Update docvortex to ≥ 0.4.18 .
Footer Boundary Swallows Column Body Text#
The _relabel_header_footer_boundary_blocks post-processing step reclassifies eligible non-formula boxes whose top Y-coordinate is ≥ the footer anchor's top Y-coordinate and falls within the footer's horizontal scope. The horizontal scope check (_is_footer_x_scope) uses a full-width threshold of 0.7: if a detected footer spans ≥70% of the page width, eligible content below it is swept into footer classification regardless of column . This can cause body text in an adjacent column to be discarded. Status: Fixed in PR #5219.
Debugging Layout Detection Failures#
- Isolate the page — rerun with
-s <page_index> -e <page_index>. - Inspect
middle.json— look for vertical gaps inpara_blocksbbox coordinates . - Check
paras_of_discarded— footer-misclassified content appears here and can be manually recovered . - Verify the text layer — call
mineru.utils.pdf_text_tool.get_page_chars(). If chars exist in the PDF but are absent frompara_blocks, the layout model is the culprit . - Rule out OCR — rerun with
--mode txt. If records are still missing, the failure is definitively in the Layout Detect phase.
Threshold tuning: Lower conf at model initialization or lower specific entries in DEFAULT_CLASS_THRESHOLDS to recover borderline detections — at the cost of more false positives.
Key Source Files#
| File | Purpose |
|---|---|
mineru/model/layout/pp_doclayoutv2.py | PPDocLayoutV2LayoutModel — Transformers-backed inference + post-processing |
mineru/model/layout/pp_doclayout_v2_base.py | Shared class list, thresholds, and post-processing logic (numpy/PIL only) |