π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
Finish testig
Pau Riba31909356acca
diff --git a/kornia/augmentation/augmentations.py b/kornia/augmentation/augmentations.pyindex e0628369d..122141845 100644--- a/kornia/augmentation/augmentations.py+++ b/kornia/augmentation/augmentations.py@@ -179,7 +179,7 @@ def color_jitter(input: torch.Tensor, brightness: FloatUnionType = 0., contrast:r"""Check inputs and compute the corresponding factor bounds"""- if isinstance(factor, float) or (isinstance(factor, torch.Tensor) and factor.size() == 0):+ if isinstance(factor, float) or (isinstance(factor, torch.Tensor) and factor.size() == torch.Size([])):if factor < 0:raise ValueError(f"If {name} is a single number number, it must be non negative. Got {factor}")factor_bound = [center - factor, center + factor]diff --git a/test/augmentation/test_augmentation.py b/test/augmentation/test_augmentation.pyindex 2557e2bc0..0c5922f39 100644--- a/test/augmentation/test_augmentation.py+++ b/test/augmentation/test_augmentation.py@@ -368,6 +368,50 @@ class TestColorJitter:assert_allclose(f(input), expected)+ def test_random_saturation_tensor(self):+ torch.manual_seed(42)+ f = ColorJitter(saturation=torch.tensor(0.2))++ input = torch.tensor([[[[0.1, 0.2, 0.3],+ [0.6, 0.5, 0.4],+ [0.7, 0.8, 1.]],++ [[1.0, 0.5, 0.6],+ [0.6, 0.3, 0.2],+ [0.8, 0.1, 0.2]],++ [[0.6, 0.8, 0.7],+ [0.9, 0.3, 0.2],+ [0.8, 0.4, .5]]]]) # 1 x 1 x 3 x 3+ input = input.repeat(2, 1, 1, 1) # 2 x 3 x 3++ expected = torch.tensor([[[[1.8763e-01, 2.5842e-01, 3.3895e-01],+ [6.2921e-01, 5.0000e-01, 4.0000e-01],+ [7.0974e-01, 8.0000e-01, 1.0000e+00]],++ [[1.0000e+00, 5.2921e-01, 6.0974e-01],+ [6.2921e-01, 3.1947e-01, 2.1947e-01],+ [8.0000e-01, 1.6816e-01, 2.7790e-01]],++ [[6.3895e-01, 8.0000e-01, 7.0000e-01],+ [9.0000e-01, 3.1947e-01, 2.1947e-01],+ [8.0000e-01, 4.3895e-01, 5.4869e-01]]],+++ [[[1.1921e-07, 1.2953e-01, 2.5302e-01],+ [5.6476e-01, 5.0000e-01, 4.0000e-01],+ [6.8825e-01, 8.0000e-01, 1.0000e+00]],++ [[1.0000e+00, 4.6476e-01, 5.8825e-01],+ [5.6476e-01, 2.7651e-01, 1.7651e-01],+ [8.0000e-01, 1.7781e-02, 1.0603e-01]],++ [[5.5556e-01, 8.0000e-01, 7.0000e-01],+ [9.0000e-01, 2.7651e-01, 1.7651e-01],+ [8.0000e-01, 3.5302e-01, 4.4127e-01]]]])++ assert_allclose(f(input), expected)+def test_random_saturation_tuple(self):torch.manual_seed(42)f = ColorJitter(saturation=(0.8,1.2))@@ -456,7 +500,6 @@ class TestColorJitter:assert_allclose(f(input), expected)-def test_random_hue_list(self):torch.manual_seed(42)f = ColorJitter(hue=[-0.2,0.2])@@ -501,6 +544,50 @@ class TestColorJitter:assert_allclose(f(input), expected)+ def test_random_hue_tensor(self):+ torch.manual_seed(42)+ f = ColorJitter(hue=torch.tensor([-0.2,0.2]))++ input = torch.tensor([[[[0.1, 0.2, 0.3],+ [0.6, 0.5, 0.4],+ [0.7, 0.8, 1.]],++ [[1.0, 0.5, 0.6],+ [0.6, 0.3, 0.2],+ [0.8, 0.1, 0.2]],++ [[0.6, 0.8, 0.7],+ [0.9, 0.3, 0.2],+ [0.8, 0.4, .5]]]]) # 1 x 1 x 3 x 3+ input = input.repeat(2, 1, 1, 1) # 2 x 3 x 3++ expected = torch.tensor([[[[0.1000, 0.2000, 0.3000],+ [0.6000, 0.5000, 0.4000],+ [0.7000, 0.8000, 1.0000]],++ [[1.0000, 0.6578, 0.7000],+ [0.6789, 0.3000, 0.2000],+ [0.8000, 0.1000, 0.2000]],++ [[0.3634, 0.8000, 0.6948],+ [0.9000, 0.3526, 0.2526],+ [0.7737, 0.5840, 0.7103]]],+++ [[[0.1000, 0.2000, 0.3000],+ [0.6726, 0.5000, 0.4000],+ [0.7000, 0.8000, 1.0000]],++ [[1.0000, 0.3547, 0.5031],+ [0.6000, 0.3484, 0.2484],+ [0.7758, 0.1000, 0.2000]],++ [[0.8179, 0.8000, 0.7000],+ [0.9000, 0.3000, 0.2000],+ [0.8000, 0.2305, 0.3063]]]])++ assert_allclose(f(input), expected)+def test_gradcheck(self):input = torch.rand((3, 5, 5)).double() # 3 x 3