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

fix: forbid bool value from JPEG's quality argument type. #8995

Merged
merged 3 commits into from
Mar 26, 2025
Merged
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
5 changes: 5 additions & 0 deletions test/test_transforms_v2.py
Original file line number Diff line number Diff line change
@@ -6206,6 +6206,11 @@ def test_transform_invalid_quality_error(self, quality):
with pytest.raises(ValueError, match="quality must be an integer from 1 to 100"):
transforms.JPEG(quality=quality)

@pytest.mark.parametrize("quality", [None, True])
def test_transform_quality_type_error(self, quality):
with pytest.raises(TypeError, match="quality"):
transforms.JPEG(quality=quality)


class TestUtils:
# TODO: Still need to test has_all, has_any, check_type and get_bouding_boxes
2 changes: 2 additions & 0 deletions torchvision/transforms/v2/_augment.py
Original file line number Diff line number Diff line change
@@ -352,6 +352,8 @@ class JPEG(Transform):
def __init__(self, quality: Union[int, Sequence[int]]):
super().__init__()
if isinstance(quality, int):
if isinstance(quality, bool):
raise TypeError("quality can't be bool")
quality = [quality, quality]
else:
_check_sequence_input(quality, "quality", req_sizes=(2,))