Skip to content

fix: handle empty inputs in OrientationPredictor#2069

Merged
felixdittrich92 merged 2 commits into
mindee:mainfrom
badranX:fix-angle-empty
Jun 6, 2026
Merged

fix: handle empty inputs in OrientationPredictor#2069
felixdittrich92 merged 2 commits into
mindee:mainfrom
badranX:fix-angle-empty

Conversation

@badranX
Copy link
Copy Markdown
Contributor

@badranX badranX commented Jun 2, 2026

OrientationPredictor does not handle empty input batches and can raise an exception when orientation detection is enabled and no valid crops/images are passed to the predictor. This PR handles empty inputs similar to the RecognitionPredictor.

Reproduction

import requests

from doctr.io import DocumentFile
from doctr.models import ocr_predictor

receipt = requests.get(
    "https://github.com/mindee/doctr/releases/download/v0.3.0/mock_receipt.jpeg"
).content

predictor = ocr_predictor(
    pretrained=True,
    det_arch="fast_base",
    reco_arch="parseq",
    assume_straight_pages=False,
    detect_orientation=True,
    disable_crop_orientation=False,
    disable_page_orientation=False,
    straighten_pages=True,
)

docs = DocumentFile.from_images([receipt])
docs[0] = docs[0][:10, :10]

result = predictor(docs)

Result:

File "/home/ubuntu/dev/pr/doctr/doctr/models/preprocessor/pytorch.py", line 73, in batch_inputs
    if isinstance(samples[0], tuple):
                  ~~~~~~~^^^
IndexError: list index out of range

@felixdittrich92 felixdittrich92 self-requested a review June 5, 2026 08:53
@felixdittrich92 felixdittrich92 self-assigned this Jun 5, 2026
@felixdittrich92 felixdittrich92 added type: bug Something isn't working module: models Related to doctr.models ext: tests Related to tests folder labels Jun 5, 2026
@felixdittrich92 felixdittrich92 added this to the 1.1.0 milestone Jun 5, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.67%. Comparing base (bc0db21) to head (fc20369).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2069      +/-   ##
==========================================
- Coverage   96.70%   96.67%   -0.03%     
==========================================
  Files         156      156              
  Lines        7276     7405     +129     
==========================================
+ Hits         7036     7159     +123     
- Misses        240      246       +6     
Flag Coverage Δ
unittests 96.67% <100.00%> (-0.03%) ⬇️

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.

Copy link
Copy Markdown
Collaborator

@felixdittrich92 felixdittrich92 left a comment

Choose a reason for hiding this comment

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

Hi @badranX 👋,

Thanks for the fix 👍

Could you please add two small unittests for your change here:

def test_crop_orientation_model(mock_text_box):

and here:

def test_page_orientation_model(mock_payslip):

Afterwards we are good to merge.

Copy link
Copy Markdown
Collaborator

@felixdittrich92 felixdittrich92 left a comment

Choose a reason for hiding this comment

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

Thanks 👍

@felixdittrich92 felixdittrich92 merged commit fcfee08 into mindee:main Jun 6, 2026
58 of 60 checks passed
@badranX badranX deleted the fix-angle-empty branch June 6, 2026 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ext: tests Related to tests folder module: models Related to doctr.models type: bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants