[reading order] Improve reading order and add exporters - #2116
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2116 +/- ##
==========================================
+ Coverage 96.61% 96.95% +0.33%
==========================================
Files 168 169 +1
Lines 9094 9615 +521
==========================================
+ Hits 8786 9322 +536
+ Misses 308 293 -15
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:
|
There was a problem hiding this comment.
Pull request overview
This PR improves DocTR’s reading-order handling (including memory optimizations), introduces a dedicated doctr.io.exporters module with new Markdown/AsciiDoc/HTML exporters, and updates the builder/predictor paths and docs/tests to support these new export surfaces.
Changes:
- Refactors export logic into
doctr/io/exporters.py, adds Markdown/AsciiDoc/HTML exporters, and wires export mixins into core element classes. - Updates reading-order computation (DAG traversal + overlap ratio memory behavior) and adds extensive regression tests for reading-order and exporters.
- Improves table-region cropping by adding padding and adjusts table word ordering / geometry handling in the builder.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/common/test_models_reading_order.py | Adds regression tests and helpers for reading-order edge cases (columns, key/value rows). |
| tests/common/test_models_builder.py | Extends builder repr expectations and adds tests for keep_reading_order. |
| tests/common/test_io_exporters.py | New test suite covering page/document export to Markdown/AsciiDoc/HTML/XML and reading-order behavior. |
| doctr/models/reading_order/base.py | Optimizes overlap computations and refines topological reading-order traversal (incl. multi-column heuristic). |
| doctr/models/predictor/pytorch.py | Adds padding to table-region crops to improve downstream table recognition. |
| doctr/models/layout/lw_detr/pytorch.py | Updates layout model class list (removes checkbox classes). |
| doctr/models/builder.py | Adds keep_reading_order, improves rotated-page handling in line resolution, and refines table cell word ordering. |
| doctr/io/exporters.py | New module implementing exporters, reading-order caching, and export mixins. |
| doctr/io/elements.py | Moves export/render methods to mixins (delegating to doctr.io.exporters). |
| doctr/io/init.py | Re-exports new exporters in the doctr.io package namespace. |
| docs/source/using_doctr/using_models.rst | Documents new export APIs and keep_reading_order. |
| docs/source/modules/io.rst | Adds API docs for new export methods and exporter classes. |
Comments suppressed due to low confidence (1)
doctr/io/exporters.py:930
- Same issue as
export_as_markdown: document-level calls can reasonably passinclude_furniture, which currently breaks on KIE pages. Accept/ignore it here as well to avoidTypeErrorwhen exporting mixed document types with shared helpers.
def export_as_asciidoc(self, direction: str = "auto", escape: bool = True) -> str:
"""Export the KIE page as AsciiDoc, with the predictions of each class sorted in reading order.
Args:
direction: reading direction, one of 'auto', 'ltr', 'rtl', 'ttb-rtl' or 'ttb-ltr'
escape: whether the characters and line markers carrying a structural meaning in AsciiDoc should
be escaped
Returns:
an AsciiDoc string with one section per detection class
"""
return AsciiDocExporter().export_kie_page(cast("KIEPage", self), direction=direction, escape=escape)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (1)
docs/source/using_doctr/using_models.rst:647
- Same inline-literal issue here: use double backticks for the method name so it renders as code and doesn’t rely on the default Sphinx role resolution.
The `export_as` method is a convenience dispatcher over all the formats above::
This PR:
Closes: #1586 #2085