Repository navigation
[models] Improve line grouping and reading order for skewed pages, multi-column layouts and receipts - #2167
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2167 +/- ##
========================================
Coverage 97.69% 97.69%
========================================
Files 170 170
Lines 10744 10922 +178
========================================
+ Hits 10496 10670 +174
- Misses 248 252 +4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
felixdittrich92
force-pushed
the
order-improvements
branch
from
October 26, 2026 09:21
595786f to
e25d487
Compare
felixdittrich92
marked this pull request as ready for review
October 26, 2026 10:23
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does
Improves how words are grouped into lines and how lines are put in reading order, mainly for skewed scans, multi-column pages (with and without the layout model) and receipts.
Line grouping (
DocumentBuilder)_resolve_rows): a word joins the row whose horizontally closest words are best aligned with it, instead of comparing against the running mean of the whole row. This follows slanted lines (skew, perspective), keeps the rows of columns with offset baselines apart, and stops a label stacked under another (e.g. figure labels) from joining a row further right.paragraph_breakis scaled up for large type.Reading order (
doctr.models.reading_order)resolve_reading_segments: segments respect layout regions, and the fragments of a line split at a wide word gap rejoin their paragraph (new optionalrow_gapargument).Exports
Benchmark
The models ran once per page and the same raw predictions were replayed through the base (
434145c) and this branch, so every difference comes from this PR. All rows usedetect_layout=True.Datasets:
Reading-order edit distance: 0 = perfect order.
page.render()vs ground truth (original / held-out)Edit distance per dataset:
Without the layout model the edit distance drops from 0.313 to 0.167 (original) and from 0.527 to 0.222 (held-out). On SROIE and XFUND-de the results are unchanged within ±0.2 points.
Builder, reading order and exports take about 10 ms per page in both versions.
Tests
test_resolve_lines: offset columns, perspective, ±2° skew, nested boxes, stacked figure labels, table rows, large type.Known limitations
detect_layout=True.