From 7885f46f5362a020962ebd4d760031b5b031e346 Mon Sep 17 00:00:00 2001 From: Kushajveer Singh Date: Thu, 16 Jul 2020 04:43:53 +0530 Subject: [PATCH 1/2] perform cyclic check for hue in test_rgb2hsv Test fails for cases when hue=0 and hue=360. As hue is cyclic in nature, add cyclic logic for checking the max difference by taking the sin of the tensor and then comparing the max values. --- test/test_functional_tensor.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/test_functional_tensor.py b/test/test_functional_tensor.py index d23930e7313..af5346f1f27 100644 --- a/test/test_functional_tensor.py +++ b/test/test_functional_tensor.py @@ -1,6 +1,7 @@ import unittest import random import colorsys +import math from PIL import Image from PIL.Image import NEAREST, BILINEAR, BICUBIC @@ -114,7 +115,13 @@ def test_rgb2hsv(self): colorsys_img = torch.tensor(hsv, dtype=torch.float32) - max_diff = (colorsys_img - ft_hsv_img).abs().max() + ft_hsv_img_h, ft_hsv_img_sv = torch.split(ft_hsv_img, [1,2], dim=1) + colorsys_img_h, colorsys_img_sv = torch.split(colorsys_img, [1,2], dim=1) + + max_diff_h = ((colorsys_img_h*2*math.pi).sin() - (ft_hsv_img_h*2*math.pi).sin()).abs().max() + max_diff_sv = (colorsys_img_sv - ft_hsv_img_sv).abs().max() + max_diff = max(max_diff_h, max_diff_sv) + self.assertLess(max_diff, 1e-5) def test_adjustments(self): From a3066b7900edc810b4f46d29a8f6d329ee9b6de0 Mon Sep 17 00:00:00 2001 From: Kushajveer Singh Date: Thu, 16 Jul 2020 14:42:45 +0530 Subject: [PATCH 2/2] address linter issues --- test/test_functional_tensor.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/test_functional_tensor.py b/test/test_functional_tensor.py index af5346f1f27..c83eefb990c 100644 --- a/test/test_functional_tensor.py +++ b/test/test_functional_tensor.py @@ -1,7 +1,7 @@ import unittest import random import colorsys -import math +import math from PIL import Image from PIL.Image import NEAREST, BILINEAR, BICUBIC @@ -115,10 +115,10 @@ def test_rgb2hsv(self): colorsys_img = torch.tensor(hsv, dtype=torch.float32) - ft_hsv_img_h, ft_hsv_img_sv = torch.split(ft_hsv_img, [1,2], dim=1) - colorsys_img_h, colorsys_img_sv = torch.split(colorsys_img, [1,2], dim=1) - - max_diff_h = ((colorsys_img_h*2*math.pi).sin() - (ft_hsv_img_h*2*math.pi).sin()).abs().max() + ft_hsv_img_h, ft_hsv_img_sv = torch.split(ft_hsv_img, [1, 2], dim=1) + colorsys_img_h, colorsys_img_sv = torch.split(colorsys_img, [1, 2], dim=1) + + max_diff_h = ((colorsys_img_h * 2 * math.pi).sin() - (ft_hsv_img_h * 2 * math.pi).sin()).abs().max() max_diff_sv = (colorsys_img_sv - ft_hsv_img_sv).abs().max() max_diff = max(max_diff_h, max_diff_sv)