Skip to content

F_t add factor nonnegativity checks for adjust_* #2356

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 5 commits into from
Jun 30, 2020
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
17 changes: 13 additions & 4 deletions torchvision/transforms/functional_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ def adjust_brightness(img, brightness_factor):
Returns:
Tensor: Brightness adjusted image.
"""
if brightness_factor < 0:
raise ValueError('brightness_factor ({}) is not non-negative.'.format(brightness_factor))

if not _is_tensor_a_torch_image(img):
raise TypeError('tensor is not a torch image.')

Expand All @@ -110,6 +113,9 @@ def adjust_contrast(img, contrast_factor):
Returns:
Tensor: Contrast adjusted image.
"""
if contrast_factor < 0:
raise ValueError('contrast_factor ({}) is not non-negative.'.format(contrast_factor))

if not _is_tensor_a_torch_image(img):
raise TypeError('tensor is not a torch image.')

Expand Down Expand Up @@ -143,7 +149,7 @@ def adjust_hue(img, hue_factor):
Returns:
Tensor: Hue adjusted image.
"""
if not(-0.5 <= hue_factor <= 0.5):
if not (-0.5 <= hue_factor <= 0.5):
raise ValueError('hue_factor ({}) is not in [-0.5, 0.5].'.format(hue_factor))

if not _is_tensor_a_torch_image(img):
Expand Down Expand Up @@ -172,13 +178,16 @@ def adjust_saturation(img, saturation_factor):

Args:
img (Tensor): Image to be adjusted.
saturation_factor (float): How much to adjust the saturation. 0 will
give a black and white image, 1 will give the original image while
2 will enhance the saturation by a factor of 2.
saturation_factor (float): How much to adjust the saturation. Can be any
non negative number. 0 gives a black and white image, 1 gives the
original image while 2 enhances the saturation by a factor of 2.

Returns:
Tensor: Saturation adjusted image.
"""
if saturation_factor < 0:
raise ValueError('saturation_factor ({}) is not non-negative.'.format(saturation_factor))

if not _is_tensor_a_torch_image(img):
raise TypeError('tensor is not a torch image.')

Expand Down