Skip to content

fix: handle empty inputs in OrientationPredictor#2069

Open
badranX wants to merge 1 commit into
mindee:mainfrom
badranX:fix-angle-empty
Open

fix: handle empty inputs in OrientationPredictor#2069
badranX wants to merge 1 commit into
mindee:mainfrom
badranX:fix-angle-empty

Conversation

@badranX
Copy link
Copy Markdown

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant