Skip to content

allow integer parameters in ColorJitter #7255

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

Merged
merged 1 commit into from
Feb 15, 2023
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
8 changes: 5 additions & 3 deletions torchvision/prototype/transforms/_color.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,16 @@ def _check_input(
if value is None:
return None

if isinstance(value, float):
if isinstance(value, (int, float)):
if value < 0:
raise ValueError(f"If {name} is a single number, it must be non negative.")
value = [center - value, center + value]
if clip_first_on_zero:
value[0] = max(value[0], 0.0)
elif not (isinstance(value, collections.abc.Sequence) and len(value) == 2):
raise TypeError(f"{name} should be a single number or a sequence with length 2.")
elif isinstance(value, collections.abc.Sequence) and len(value) == 2:
value = [float(v) for v in value]
else:
raise TypeError(f"{name}={value} should be a single number or a sequence with length 2.")

if not bound[0] <= value[0] <= value[1] <= bound[1]:
raise ValueError(f"{name} values should be between {bound}, but got {value}.")
Expand Down