Skip to content

Update error condition for 'max_size' in '_compute_resized_output_size' #7984

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/test_transforms_v2_refactored.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ def test_functional_pil_antialias_warning(self):
def test_max_size_error(self, size, make_input):
if isinstance(size, int) or len(size) == 1:
max_size = (size if isinstance(size, int) else size[0]) - 1
match = "must be strictly greater than the requested size"
match = "must be strictly greater than or equal to the requested size"
else:
# value can be anything other than None
max_size = -1
Expand Down
4 changes: 2 additions & 2 deletions torchvision/transforms/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,9 @@ def _compute_resized_output_size(
new_short, new_long = requested_new_short, int(requested_new_short * long / short)

if max_size is not None:
if max_size <= requested_new_short:
if max_size < requested_new_short:
raise ValueError(
f"max_size = {max_size} must be strictly greater than the requested "
f"max_size = {max_size} must be strictly greater than or equal to the requested "
f"size for the smaller edge size = {size}"
)
if new_long > max_size:
Expand Down