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

Restore remap boxes #812

Merged
merged 6 commits into from
Feb 14, 2022
Merged

Conversation

Rob192
Copy link
Contributor

@Rob192 Rob192 commented Jan 25, 2022

This PR is to address #800 as part of #788.

It restores the function remap_boxes from #488 and adds a new functionality test to verify the output of a pretrained predictor on a rotated document.

@codecov
Copy link

codecov bot commented Jan 25, 2022

Codecov Report

Merging #812 (072ee5d) into main (bf2d4ca) will increase coverage by 0.09%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #812      +/-   ##
==========================================
+ Coverage   96.01%   96.10%   +0.09%     
==========================================
  Files         131      131              
  Lines        4941     4955      +14     
==========================================
+ Hits         4744     4762      +18     
+ Misses        197      193       -4     
Flag Coverage Δ
unittests 96.10% <100.00%> (+0.09%) ⬆️

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

Impacted Files Coverage Δ
doctr/models/predictor/pytorch.py 97.22% <100.00%> (+0.07%) ⬆️
doctr/models/predictor/tensorflow.py 100.00% <100.00%> (ø)
doctr/utils/geometry.py 100.00% <100.00%> (+1.11%) ⬆️
doctr/transforms/modules/base.py 94.59% <0.00%> (ø)
doctr/models/builder.py 99.01% <0.00%> (+2.94%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bf2d4ca...072ee5d. Read the comment docs.

Copy link
Collaborator

@charlesmindee charlesmindee left a comment

Choose a reason for hiding this comment

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

Hi @Rob192, thank you for your PR.
I added a few comments because I am not sure I fully understood the purpose of the remap_boxes function since we moved to a new format of boxes where boxes are described by points and not angles. In any case, can you attach in the issue #800 the image of the document where the boxes are misplaced to help us understanding the bug ? 🙏 Thank you!

doctr/utils/geometry.py Outdated Show resolved Hide resolved
doctr/utils/geometry.py Outdated Show resolved Hide resolved
orig_height, orig_width = orig_shape
dest_height, dest_width = dest_shape
mboxes = loc_preds.copy()
mboxes[:, :, 0] = ((loc_preds[:, :, 0] * orig_width) + (dest_width - orig_width) / 2) / dest_width
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not sure I understand well the computation here: If we have relative coordinates [[x1, y1], [x2, y2], [x3, y3], ...] we just need to multiply by dest_width & dest_height to get the absolute points coordinates in dest_shape referential, or am I missing something ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @charlesmindee, no you need to take into account the padding that was introduced by rotate_image. This is the main point of this function remap_boxes that is here to accommodate these differences.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added pictures for reference in #800

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, thanks I see the point

Copy link
Collaborator

@charlesmindee charlesmindee 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 this fix!

orig_height, orig_width = orig_shape
dest_height, dest_width = dest_shape
mboxes = loc_preds.copy()
mboxes[:, :, 0] = ((loc_preds[:, :, 0] * orig_width) + (dest_width - orig_width) / 2) / dest_width
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, thanks I see the point

@charlesmindee charlesmindee merged commit 166001c into mindee:main Feb 14, 2022
@charlesmindee charlesmindee added this to the 0.5.1 milestone Feb 14, 2022
@charlesmindee charlesmindee added framework: pytorch Related to PyTorch backend framework: tensorflow Related to TensorFlow backend topic: text detection Related to the task of text detection type: bug Something isn't working labels Feb 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
framework: pytorch Related to PyTorch backend framework: tensorflow Related to TensorFlow backend 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