Skip to content

[transforms] Keep at least one pixel per side when RandomResize scales a small image - #2213

Merged
felixdittrich92 merged 1 commit into
mindee:mainfrom
RavSinghChandan:random-resize-tiny-image
Nov 2, 2026
Merged

felixdittrich92 merged 1 commit into
mindee:mainfrom
RavSinghChandan:random-resize-tiny-image

Conversation

@RavSinghChandan

Copy link
Copy Markdown
Contributor

RandomResize computes the new size with int(size * scale), so a side under 4 pixels becomes 0 with the default scale_range=(0.3, 0.9). Resize then raises RuntimeError: Input and output sizes should be greater than 0, or ZeroDivisionError in target_ratio = self.size[0] / self.size[1] when the width is the one that becomes 0. A 1-pixel high crop fails every time, a 3x40 crop (a dash, a dot) about 5% of the time.

Each side is now kept at least at one pixel. Other sizes are resized as before.

Test: test_random_resize_small_image with 1x50, 3x40, 10x3 and 2x2 images, with and without preserve_aspect_ratio. It fails on main

@codecov

codecov Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.78%. Comparing base (b690ba9) to head (28df328).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2213      +/-   ##
==========================================
- Coverage   97.78%   97.78%   -0.01%     
==========================================
  Files         170      170              
  Lines       10993    10993              
==========================================
- Hits        10750    10749       -1     
- Misses        243      244       +1     
Flag Coverage Δ
unittests 97.78% <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 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.

@felixdittrich92 felixdittrich92 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks 👍

@felixdittrich92 felixdittrich92 self-assigned this Nov 2, 2026
@felixdittrich92 felixdittrich92 added type: enhancement Improvement ext: tests Related to tests folder module: transforms Related to doctr.transforms labels Nov 2, 2026
@felixdittrich92 felixdittrich92 added this to the 1.2.0 milestone Nov 2, 2026
@felixdittrich92
felixdittrich92 merged commit 3f2fa35 into mindee:main Nov 2, 2026
56 of 57 checks passed
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: transforms Related to doctr.transforms type: enhancement Improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants