Skip to main content

Module layout

Module layout 

Source
Expand description

Layout detection on the shared ONNX Runtime layer (#641). Off by default. Layout detection on the shared ONNX Runtime layer (#641).

Behind the ort-layout cargo feature (off by default). Turns one PDF page into the layout detector’s boxes, exactly as the Python reference does (Heron-ft ep03, RT-DETRv2, HF transformers 4.57.6 post-processing):

  • LAYOUT_EP03 is the model, loaded through pdf_ocr::runtime::session only.
  • render_page_rgb renders the page at 96 dpi, RGB on white, through the same calls as the render_page_png example. No new renderer.
  • preprocess_to_nchw resizes to 640x640 non-uniform with PIL BILINEAR (triangle support widened on downscale, as PIL does), rescales by 1/255 with no mean/std normalisation, and lays out NCHW f32 1x3x640x640 – the flags in the model’s preprocessor_config.json (RTDetrImageProcessor, do_resize, do_rescale, no do_normalize, no do_pad).
  • layout_boxes runs the graph (input/output names read from the ONNX session metadata, as exported: pixel_values in, logits and pred_boxes out) and post-processes exactly as HF post_process_object_detection for RT-DETR: sigmoid over the logits, top-300 over the flattened scores, label = index % 17, query = index / 17, boxes from normalised cxcywh to xyxy scaled to the render size, keeping score >= 0.05. Label names are the model’s config.json id2label.

Model failures come back as EngineError::Io carrying the typed pdf_ocr::runtime::ModelError – no new EngineError variants. Callers match that variant and find the cause with pdf_ocr::runtime::model_error.

Re-exports§

pub use crate::model::LAYOUT_EP03;

Structs§

LayoutBox
One layout detection: what the region is, where it is on the render.
RgbPage
An 8-bit RGB page render at 96 dpi, row-major, three bytes per pixel.
RuntimeConfig
How the shared layer resolves files and sizes its pools.

Functions§

layout_boxes
The layout detector’s boxes for one page.
preprocess_to_nchw
Preprocess a render into the detector’s NCHW f32 input (1x3x640x640).
render_page_rgb
Render one page at 96 dpi, RGB on white.