From c1370d508fb3227b9b9d39ba027eab98cb84b430 Mon Sep 17 00:00:00 2001 From: Sanket Thakur Date: Sat, 27 Feb 2021 11:37:19 +0100 Subject: [PATCH 1/4] fixed origin head --- torchvision/transforms/functional_tensor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/torchvision/transforms/functional_tensor.py b/torchvision/transforms/functional_tensor.py index 69445e6a231..eb416490c4b 100644 --- a/torchvision/transforms/functional_tensor.py +++ b/torchvision/transforms/functional_tensor.py @@ -226,8 +226,8 @@ def adjust_gamma(img: Tensor, gamma: float, gain: float = 1) -> Tensor: result = (gain * result ** gamma).clamp(0, 1) - result = convert_image_dtype(result, dtype) - result = result.to(dtype) + if result.dtype != dtype: + result = convert_image_dtype(result, dtype) return result From c48b460d6518a67df4ec2d53846e7bc0d97ec775 Mon Sep 17 00:00:00 2001 From: Sanket Thakur Date: Sat, 27 Feb 2021 11:45:59 +0100 Subject: [PATCH 2/4] fixed inconsistent casting --- torchvision/transforms/functional_tensor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torchvision/transforms/functional_tensor.py b/torchvision/transforms/functional_tensor.py index eb416490c4b..0d1faa415e4 100644 --- a/torchvision/transforms/functional_tensor.py +++ b/torchvision/transforms/functional_tensor.py @@ -227,7 +227,7 @@ def adjust_gamma(img: Tensor, gamma: float, gain: float = 1) -> Tensor: result = (gain * result ** gamma).clamp(0, 1) if result.dtype != dtype: - result = convert_image_dtype(result, dtype) + result = result.to(dtype) return result From 528161471d6c4ced14d84851fd4ab92ec5d3718e Mon Sep 17 00:00:00 2001 From: Sanket Thakur Date: Tue, 2 Mar 2021 10:39:12 +0100 Subject: [PATCH 3/4] updated functional_tensor.py Modified the .to() method to convert_image_dtype() method. --- torchvision/transforms/functional_tensor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torchvision/transforms/functional_tensor.py b/torchvision/transforms/functional_tensor.py index 0d1faa415e4..eb416490c4b 100644 --- a/torchvision/transforms/functional_tensor.py +++ b/torchvision/transforms/functional_tensor.py @@ -227,7 +227,7 @@ def adjust_gamma(img: Tensor, gamma: float, gain: float = 1) -> Tensor: result = (gain * result ** gamma).clamp(0, 1) if result.dtype != dtype: - result = result.to(dtype) + result = convert_image_dtype(result, dtype) return result From 3938c3e1e997b91fcc54ad4c16fb812f0592e42d Mon Sep 17 00:00:00 2001 From: Vasilis Vryniotis Date: Tue, 2 Mar 2021 21:15:46 +0000 Subject: [PATCH 4/4] Apply suggestions from code review --- torchvision/transforms/functional_tensor.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/torchvision/transforms/functional_tensor.py b/torchvision/transforms/functional_tensor.py index eb416490c4b..d20d24a8413 100644 --- a/torchvision/transforms/functional_tensor.py +++ b/torchvision/transforms/functional_tensor.py @@ -226,8 +226,7 @@ def adjust_gamma(img: Tensor, gamma: float, gain: float = 1) -> Tensor: result = (gain * result ** gamma).clamp(0, 1) - if result.dtype != dtype: - result = convert_image_dtype(result, dtype) + result = convert_image_dtype(result, dtype) return result