Repository navigation
[transforms] Crop the whole crop_box region in crop_detection - #2174
Merged
felixdittrich92 merged 1 commit intoOct 19, 2026
Merged
Conversation
crop_detection projected the relative crop box onto (w - 1, h - 1) instead of (w, h), so the image crop lost its last row and column and no longer matched the region the boxes are rescaled to. A full crop of a 4x6 image came out 3x5, and RandomCrop(scale=(1, 1)) shrank a 1024x1024 image to 1023x1023.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2174 +/- ##
=======================================
Coverage 97.61% 97.62%
=======================================
Files 170 170
Lines 10740 10740
=======================================
+ Hits 10484 10485 +1
+ Misses 256 255 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
felixdittrich92
approved these changes
Oct 19, 2026
felixdittrich92
left a comment
Collaborator
There was a problem hiding this comment.
Thanks @MohammadHijjawi97 👍
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
crop_detectionprojected the relativecrop_boxonto(w - 1, h - 1)instead of(w, h). The image crop therefore lost its last row and column and no longer matched the region the boxes are rescaled to: relative boxes are divided by the crop's real size, while the image came out one pixel smaller and slightly shifted. Absolute boxes were also clipped tow - 1.With this PR they return
(1, 4, 6),(1, 2, 3)and(3, 1024, 1024).RandomCropis used in the detection and layout reference training scripts, so their random crops now line up with the boxes and masks.Tests:
test_crop_detection: the expected shapes were(3, 26, 37)for a0.54 x 0.76crop of a 50x50 image; they are now(3, 27, 38). Added exact-pixel checks for a full crop and a quarter crop, with relative and absolute boxes.test_random_crop: a full-sizeRandomCropkeeps the image, the mask and the relative target unchanged.Both fail on
mainand pass with the fix.ruff check,ruff format --checkandmypy doctr/pass.Any feedback is welcome 🤗