Skip to content

[reading order] Improve reading order and add exporters - #2116

Merged
felixdittrich92 merged 19 commits into
mindee:mainfrom
felixdittrich92:reading-order-and-exporters
Jul 27, 2026
Merged

[reading order] Improve reading order and add exporters#2116
felixdittrich92 merged 19 commits into
mindee:mainfrom
felixdittrich92:reading-order-and-exporters

Conversation

@felixdittrich92

@felixdittrich92 felixdittrich92 commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

This PR:

  • Move export functionality into it's own module
  • Add cor docs
  • Add tests for exporters
  • Update reading order DAG and fix mem leak in overlap_ratios
  • Update table cropping by adding padding

Closes: #1586 #2085

@felixdittrich92 felixdittrich92 self-assigned this Jul 23, 2026
@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.91641% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.95%. Comparing base (703d9e1) to head (18eb960).

Files with missing lines Patch % Lines
doctr/models/predictor/pytorch.py 0.00% 5 Missing ⚠️
doctr/models/builder.py 98.38% 2 Missing ⚠️
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     
Flag Coverage Δ
unittests 96.95% <98.91%> (+0.33%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@felixdittrich92 felixdittrich92 added topic: documentation Improvements or additions to documentation module: models Related to doctr.models module: io Related to doctr.io type: new feature New feature ext: docs Related to docs folder topic: reading order Related to the task of reading order labels Jul 24, 2026
@felixdittrich92 felixdittrich92 added this to the 1.1.0 milestone Jul 24, 2026
@felixdittrich92 felixdittrich92 changed the title [WIP] [reading order] Improve reading order and add exporters [reading order] Improve reading order and add exporters Jul 24, 2026
@felixdittrich92
felixdittrich92 marked this pull request as ready for review July 24, 2026 13:36
@felixdittrich92
felixdittrich92 requested a review from Copilot July 25, 2026 12:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 pass include_furniture, which currently breaks on KIE pages. Accept/ignore it here as well to avoid TypeError when 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.

Comment thread doctr/io/exporters.py
Comment thread doctr/io/exporters.py
Comment thread docs/source/using_doctr/using_models.rst
Comment thread docs/source/modules/io.rst Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

Comment thread docs/source/modules/io.rst Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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::

Comment thread doctr/io/exporters.py
Comment thread docs/source/using_doctr/using_models.rst
Comment thread doctr/io/exporters.py
@felixdittrich92
felixdittrich92 merged commit 6455bf3 into mindee:main Jul 27, 2026
56 of 57 checks passed
@felixdittrich92
felixdittrich92 deleted the reading-order-and-exporters branch July 27, 2026 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ext: docs Related to docs folder module: io Related to doctr.io module: models Related to doctr.models topic: documentation Improvements or additions to documentation topic: reading order Related to the task of reading order type: new feature New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[improvement] .render() isn't that robust - wrong ordered results

2 participants