Expand description
Layout detection via the RT-DETR (docling-layout-heron) model exported to
ONNX, run with ort. A port of docling-ibm-models’ LayoutPredictor:
resize the page image to 640×640 and rescale to [0,1] (the heron processor
has do_normalize=false), run the model, then RT-DETR
post_process_object_detection (sigmoid → top-k over query×class →
center-to-corners boxes scaled to the page).
Structs§
- Layout
Model - Region
- One detected region, in page points (top-left origin).
Constants§
- LABELS
- The 17 canonical layout classes, indexed by the model’s class id
(
config.jsonid2label). - SIDE
- RT-DETR’s fixed square input side.
Functions§
- decode_
layout - Decode one page’s raw RT-DETR outputs into scored
Regions in page points — sigmoid over every (query, class), top-num_querieskept, boxes converted center→corners and scaled. Shared with the browser build; the native batch path calls it per page, so both decode identically. - label_
threshold - Per-label confidence threshold, ported from docling’s
LayoutPostprocessor.CONFIDENCE_THRESHOLDS. The raw predictor keeps every detection above the 0.3 base; the postprocessor then drops a cluster whose score is below its label’s threshold. Applying it here (equivalent, since every per-label threshold is ≥ the 0.3 base) keeps low-confidence pictures / tables / list-items out of the assembly, matching docling. - layout_
input - Pack one page image into the model’s
(1, 3, SIDE, SIDE)input: resize (aspect ignored, RT-DETR convention), rescale to[0,1], CHW. Shared with the browser build (#157), which delegates only the session call.