Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed assume_straight_pages for custom models #1681

Merged
merged 1 commit into from
Jul 29, 2024

Conversation

Fabioomega
Copy link
Contributor

When loading a custom model using ocr_predictor with assume_straight_pages = False, the preprocessor will be initialized with assume_straight_pages = True, resulting in a crash. This behavior happens in any custom detection models.
Example with the default db_resnet50:

from doctr.models import ocr_predictor, db_resnet50
from torch import load
from cv2 import imread

det_arch = db_resnet50(pretrained=False, pretrained_backbone=False)
params = load("db_resnet50-79bd7d70.pt", map_location="cpu")
det_arch.load_state_dict(params)

reader = ocr_predictor(det_arch=det_arch, assume_straight_pages=False)

img = imread("<img>")
print(
    reader([img])
)  # => IndexError: too many indices for array: array is 2-dimensional, but 3 were indexed

@felixdittrich92 felixdittrich92 self-assigned this Jul 29, 2024
@felixdittrich92 felixdittrich92 added this to the 0.9.0 milestone Jul 29, 2024
@felixdittrich92 felixdittrich92 added type: bug Something isn't working module: models Related to doctr.models topic: text detection Related to the task of text detection labels Jul 29, 2024
Copy link

codecov bot commented Jul 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.37%. Comparing base (1cea7d8) to head (6ab97f2).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1681      +/-   ##
==========================================
+ Coverage   96.35%   96.37%   +0.01%     
==========================================
  Files         164      164              
  Lines        7773     7774       +1     
==========================================
+ Hits         7490     7492       +2     
+ Misses        283      282       -1     
Flag Coverage Δ
unittests 96.37% <100.00%> (+0.01%) ⬆️

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

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

Copy link
Contributor

@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 for the fix @Fabioomega 👍

@felixdittrich92 felixdittrich92 merged commit a659425 into mindee:main Jul 29, 2024
80 of 81 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: models Related to doctr.models topic: text detection Related to the task of text detection type: bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants