π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
[Enhance] pytorch nightly fixes (#861)
shijianjian4083837ba8a8
diff --git a/kornia/augmentation/mix_augmentation.py b/kornia/augmentation/mix_augmentation.pyindex b077cccf7..5658f4aba 100644--- a/kornia/augmentation/mix_augmentation.py+++ b/kornia/augmentation/mix_augmentation.py@@ -141,7 +141,7 @@ class RandomCutMix(MixAugmentationBase):probabilities batch-wisely.num_mix (int): cut mix times. Default is 1.beta (float or torch.Tensor, optional): hyperparameter for generating cut size from beta distribution.- If None, it will be set to 1.+ Beta cannot be set to 0 after torch 1.8.0. If None, it will be set to 1.cut_size ((float, float) or torch.Tensor, optional): controlling the minimum and maximum cut ratio from [0, 1].If None, it will be set to [0, 1], which means no restriction.same_on_batch (bool): apply the same transformation across the batch.diff --git a/kornia/augmentation/utils/helpers.py b/kornia/augmentation/utils/helpers.pyindex 2bc1d98ff..814249f06 100644--- a/kornia/augmentation/utils/helpers.py+++ b/kornia/augmentation/utils/helpers.py@@ -228,7 +228,8 @@ def _adapted_uniform(shape: Union[Tuple, torch.Size],low: Union[float, int, torch.Tensor],high: Union[float, int, torch.Tensor],- same_on_batch: bool = False+ same_on_batch: bool = False,+ epsilon: float = 1e-6) -> torch.Tensor:r"""The uniform sampling function that accepts 'same_on_batch'.@@ -244,7 +245,9 @@ def _adapted_uniform(])low = torch.as_tensor(low, device=device, dtype=dtype)high = torch.as_tensor(high, device=device, dtype=dtype)- dist = Uniform(low, high)+ # validate_args=False to fix pytorch 1.7.1 error:+ # ValueError: Uniform is not defined when low>= high.+ dist = Uniform(low, high, validate_args=False)return _adapted_rsampling(shape, dist, same_on_batch)diff --git a/test/augmentation/test_augmentation.py b/test/augmentation/test_augmentation.pyindex d65bbd3f4..a7b7ba3a4 100644--- a/test/augmentation/test_augmentation.py+++ b/test/augmentation/test_augmentation.py@@ -1012,21 +1012,21 @@ class TestRandomVerticalFlip:f2 = RandomVerticalFlip(p=1.)f3 = RandomVerticalFlip(p=0.)- input = torch.tensor([[0., 0., 0.],- [0., 0., 0.],- [0., 1., 1.]], device=device, dtype=dtype) # 3 x 3+ input = torch.tensor([[[[0., 0., 0.],+ [0., 0., 0.],+ [0., 1., 1.]]]], device=device, dtype=dtype) # 1 x 1 x 3 x 3- expected = torch.tensor([[0., 1., 1.],- [0., 0., 0.],- [0., 0., 0.]], device=device, dtype=dtype) # 3 x 3+ expected = torch.tensor([[[[0., 1., 1.],+ [0., 0., 0.],+ [0., 0., 0.]]]], device=device, dtype=dtype) # 1 x 1 x 3 x 3- expected_transform = torch.tensor([[1., 0., 0.],- [0., -1., 2.],- [0., 0., 1.]], device=device, dtype=dtype) # 3 x 3+ expected_transform = torch.tensor([[[1., 0., 0.],+ [0., -1., 2.],+ [0., 0., 1.]]], device=device, dtype=dtype) # 3 x 3- identity = torch.tensor([[1., 0., 0.],- [0., 1., 0.],- [0., 0., 1.]], device=device, dtype=dtype) # 3 x 3+ identity = torch.tensor([[[1., 0., 0.],+ [0., 1., 0.],+ [0., 0., 1.]]], device=device, dtype=dtype) # 3 x 3assert_allclose(f(input)[0], expected, atol=1e-4, rtol=1e-4)assert_allclose(f(input)[1], expected_transform, atol=1e-4, rtol=1e-4)@@ -1093,9 +1093,9 @@ class TestRandomVerticalFlip:expected_transform_1 = expected_transform @ expected_transform- assert_allclose(f(input)[0], input.squeeze(), atol=1e-4, rtol=1e-4)+ assert_allclose(f(input)[0], input, atol=1e-4, rtol=1e-4)assert_allclose(f(input)[1], expected_transform_1, atol=1e-4, rtol=1e-4)- assert_allclose(f1(input)[0], input.squeeze(), atol=1e-4, rtol=1e-4)+ assert_allclose(f1(input)[0], input, atol=1e-4, rtol=1e-4)assert_allclose(f1(input)[1], expected_transform, atol=1e-4, rtol=1e-4)def test_random_vflip_coord_check(self, device, dtype):@@ -1189,7 +1189,7 @@ class TestColorJitter:f = ColorJitter()f1 = ColorJitter(return_transform=True)- input = torch.rand(3, 5, 5, device=device, dtype=dtype) # 3 x 5 x 5+ input = torch.rand(3, 5, 5, device=device, dtype=dtype).unsqueeze(0) # 3 x 5 x 5expected = inputexpected_transform = torch.eye(3, device=device, dtype=dtype).unsqueeze(0) # 3 x 3@@ -1485,7 +1485,7 @@ class TestColorJitter:ColorJitter(return_transform=True),)- input = torch.rand(3, 5, 5, device=device, dtype=dtype) # 3 x 5 x 5+ input = torch.rand(3, 5, 5, device=device, dtype=dtype).unsqueeze(0) # 1 x 3 x 5 x 5expected = input@@ -1510,7 +1510,7 @@ class TestColorJitter:assert_allclose(f(input)[1], expected_transform, atol=1e-4, rtol=1e-5)def test_gradcheck(self, device, dtype):- input = torch.rand((3, 5, 5), device=device, dtype=dtype) # 3 x 3+ input = torch.rand((3, 5, 5), device=device, dtype=dtype).unsqueeze(0) # 3 x 3input = utils.tensor_to_gradcheck_var(input) # to varassert gradcheck(kornia.augmentation.ColorJitter(p=1.), (input, ), raise_exception=True)@@ -1603,64 +1603,65 @@ class TestRandomGrayscale:assert (res[0] == res[1]).all()def test_opencv_true(self, device, dtype):- data = torch.tensor([[[0.3944633, 0.8597369, 0.1670904, 0.2825457, 0.0953912],- [0.1251704, 0.8020709, 0.8933256, 0.9170977, 0.1497008],- [0.2711633, 0.1111478, 0.0783281, 0.2771807, 0.5487481],- [0.0086008, 0.8288748, 0.9647092, 0.8922020, 0.7614344],- [0.2898048, 0.1282895, 0.7621747, 0.5657831, 0.9918593]],-- [[0.5414237, 0.9962701, 0.8947155, 0.5900949, 0.9483274],- [0.0468036, 0.3933847, 0.8046577, 0.3640994, 0.0632100],- [0.6171775, 0.8624780, 0.4126036, 0.7600935, 0.7279997],- [0.4237089, 0.5365476, 0.5591233, 0.1523191, 0.1382165],- [0.8932794, 0.8517839, 0.7152701, 0.8983801, 0.5905426]],-- [[0.2869580, 0.4700376, 0.2743714, 0.8135023, 0.2229074],- [0.9306560, 0.3734594, 0.4566821, 0.7599275, 0.7557513],- [0.7415742, 0.6115875, 0.3317572, 0.0379378, 0.1315770],- [0.8692724, 0.0809556, 0.7767404, 0.8742208, 0.1522012],- [0.7708948, 0.4509611, 0.0481175, 0.2358997, 0.6900532]]], device=device, dtype=dtype)+ data = torch.tensor([[[[0.3944633, 0.8597369, 0.1670904, 0.2825457, 0.0953912],+ [0.1251704, 0.8020709, 0.8933256, 0.9170977, 0.1497008],+ [0.2711633, 0.1111478, 0.0783281, 0.2771807, 0.5487481],+ [0.0086008, 0.8288748, 0.9647092, 0.8922020, 0.7614344],+ [0.2898048, 0.1282895, 0.7621747, 0.5657831, 0.9918593]],++ [[0.5414237, 0.9962701, 0.8947155, 0.5900949, 0.9483274],+ [0.0468036, 0.3933847, 0.8046577, 0.3640994, 0.0632100],+ [0.6171775, 0.8624780, 0.4126036, 0.7600935, 0.7279997],+ [0.4237089, 0.5365476, 0.5591233, 0.1523191, 0.1382165],+ [0.8932794, 0.8517839, 0.7152701, 0.8983801, 0.5905426]],++ [[0.2869580, 0.4700376, 0.2743714, 0.8135023, 0.2229074],+ [0.9306560, 0.3734594, 0.4566821, 0.7599275, 0.7557513],+ [0.7415742, 0.6115875, 0.3317572, 0.0379378, 0.1315770],+ [0.8692724, 0.0809556, 0.7767404, 0.8742208, 0.1522012],+ [0.7708948, 0.4509611, 0.0481175, 0.2358997, 0.6900532]]]], device=device, dtype=dtype)# Output data generated with OpenCV 4.1.1: cv2.cvtColor(img_np, cv2.COLOR_RGB2GRAY)- expected = torch.tensor([[[0.4684734, 0.8954562, 0.6064363, 0.5236061, 0.6106016],- [0.1709944, 0.5133104, 0.7915002, 0.5745703, 0.1680204],- [0.5279005, 0.6092287, 0.3034387, 0.5333768, 0.6064113],- [0.3503858, 0.5720159, 0.7052018, 0.4558409, 0.3261529],- [0.6988886, 0.5897652, 0.6532392, 0.7234108, 0.7218805]],-- [[0.4684734, 0.8954562, 0.6064363, 0.5236061, 0.6106016],- [0.1709944, 0.5133104, 0.7915002, 0.5745703, 0.1680204],- [0.5279005, 0.6092287, 0.3034387, 0.5333768, 0.6064113],- [0.3503858, 0.5720159, 0.7052018, 0.4558409, 0.3261529],- [0.6988886, 0.5897652, 0.6532392, 0.7234108, 0.7218805]],-- [[0.4684734, 0.8954562, 0.6064363, 0.5236061, 0.6106016],- [0.1709944, 0.5133104, 0.7915002, 0.5745703, 0.1680204],- [0.5279005, 0.6092287, 0.3034387, 0.5333768, 0.6064113],- [0.3503858, 0.5720159, 0.7052018, 0.4558409, 0.3261529],- [0.6988886, 0.5897652, 0.6532392, 0.7234108, 0.7218805]]], device=device, dtype=dtype)+ expected = torch.tensor([[[[0.4684734, 0.8954562, 0.6064363, 0.5236061, 0.6106016],+ [0.1709944, 0.5133104, 0.7915002, 0.5745703, 0.1680204],+ [0.5279005, 0.6092287, 0.3034387, 0.5333768, 0.6064113],+ [0.3503858, 0.5720159, 0.7052018, 0.4558409, 0.3261529],+ [0.6988886, 0.5897652, 0.6532392, 0.7234108, 0.7218805]],++ [[0.4684734, 0.8954562, 0.6064363, 0.5236061, 0.6106016],+ [0.1709944, 0.5133104, 0.7915002, 0.5745703, 0.1680204],+ [0.5279005, 0.6092287, 0.3034387, 0.5333768, 0.6064113],+ [0.3503858, 0.5720159, 0.7052018, 0.4558409, 0.3261529],+ [0.6988886, 0.5897652, 0.6532392, 0.7234108, 0.7218805]],++ [[0.4684734, 0.8954562, 0.6064363, 0.5236061, 0.6106016],+ [0.1709944, 0.5133104, 0.7915002, 0.5745703, 0.1680204],+ [0.5279005, 0.6092287, 0.3034387, 0.5333768, 0.6064113],+ [0.3503858, 0.5720159, 0.7052018, 0.4558409, 0.3261529],+ [0.6988886, 0.5897652, 0.6532392, 0.7234108, 0.7218805]]]],+ device=device, dtype=dtype)img_gray = kornia.augmentation.RandomGrayscale(p=1.)(data)assert_allclose(img_gray, expected, atol=1e-4, rtol=1e-4)def test_opencv_false(self, device, dtype):- data = torch.tensor([[[0.3944633, 0.8597369, 0.1670904, 0.2825457, 0.0953912],- [0.1251704, 0.8020709, 0.8933256, 0.9170977, 0.1497008],- [0.2711633, 0.1111478, 0.0783281, 0.2771807, 0.5487481],- [0.0086008, 0.8288748, 0.9647092, 0.8922020, 0.7614344],- [0.2898048, 0.1282895, 0.7621747, 0.5657831, 0.9918593]],-- [[0.5414237, 0.9962701, 0.8947155, 0.5900949, 0.9483274],- [0.0468036, 0.3933847, 0.8046577, 0.3640994, 0.0632100],- [0.6171775, 0.8624780, 0.4126036, 0.7600935, 0.7279997],- [0.4237089, 0.5365476, 0.5591233, 0.1523191, 0.1382165],- [0.8932794, 0.8517839, 0.7152701, 0.8983801, 0.5905426]],-- [[0.2869580, 0.4700376, 0.2743714, 0.8135023, 0.2229074],- [0.9306560, 0.3734594, 0.4566821, 0.7599275, 0.7557513],- [0.7415742, 0.6115875, 0.3317572, 0.0379378, 0.1315770],- [0.8692724, 0.0809556, 0.7767404, 0.8742208, 0.1522012],- [0.7708948, 0.4509611, 0.0481175, 0.2358997, 0.6900532]]], device=device, dtype=dtype)+ data = torch.tensor([[[[0.3944633, 0.8597369, 0.1670904, 0.2825457, 0.0953912],+ [0.1251704, 0.8020709, 0.8933256, 0.9170977, 0.1497008],+ [0.2711633, 0.1111478, 0.0783281, 0.2771807, 0.5487481],+ [0.0086008, 0.8288748, 0.9647092, 0.8922020, 0.7614344],+ [0.2898048, 0.1282895, 0.7621747, 0.5657831, 0.9918593]],++ [[0.5414237, 0.9962701, 0.8947155, 0.5900949, 0.9483274],+ [0.0468036, 0.3933847, 0.8046577, 0.3640994, 0.0632100],+ [0.6171775, 0.8624780, 0.4126036, 0.7600935, 0.7279997],+ [0.4237089, 0.5365476, 0.5591233, 0.1523191, 0.1382165],+ [0.8932794, 0.8517839, 0.7152701, 0.8983801, 0.5905426]],++ [[0.2869580, 0.4700376, 0.2743714, 0.8135023, 0.2229074],+ [0.9306560, 0.3734594, 0.4566821, 0.7599275, 0.7557513],+ [0.7415742, 0.6115875, 0.3317572, 0.0379378, 0.1315770],+ [0.8692724, 0.0809556, 0.7767404, 0.8742208, 0.1522012],+ [0.7708948, 0.4509611, 0.0481175, 0.2358997, 0.6900532]]]], device=device, dtype=dtype)expected = data@@ -2205,7 +2206,7 @@ class TestRandomEqualize:bs, channels, height, width = 1, 3, 20, 20- inputs = self.build_input(channels, height, width, device=device, dtype=dtype).squeeze(dim=0)+ inputs = self.build_input(channels, height, width, bs, device=device, dtype=dtype)row_expected = torch.tensor([0.0000, 0.07843, 0.15686, 0.2353, 0.3137, 0.3922, 0.4706, 0.5490, 0.6275,@@ -2304,7 +2305,7 @@ class TestNormalize:f2 = Normalize(mean=torch.tensor([1.]), std=torch.tensor([.5]), p=1.)f3 = Normalize(mean=torch.tensor([1.]), std=torch.tensor([.5]), p=0.)- inputs = torch.arange(0., 16., step=1, device=device, dtype=dtype).reshape(1, 4, 4)+ inputs = torch.arange(0., 16., step=1, device=device, dtype=dtype).reshape(1, 4, 4).unsqueeze(0)expected = (inputs - 1) * 2@@ -2362,7 +2363,7 @@ class TestDenormalize:f2 = Denormalize(mean=torch.tensor([1.]), std=torch.tensor([.5]), p=1.)f3 = Denormalize(mean=torch.tensor([1.]), std=torch.tensor([.5]), p=0.)- inputs = torch.arange(0., 16., step=1, device=device, dtype=dtype).reshape(1, 4, 4)+ inputs = torch.arange(0., 16., step=1, device=device, dtype=dtype).reshape(1, 4, 4).unsqueeze(0)expected = inputs / 2 + 1diff --git a/test/augmentation/test_augmentation_3d.py b/test/augmentation/test_augmentation_3d.pyindex 65c0ba854..d6a95ede5 100644--- a/test/augmentation/test_augmentation_3d.py+++ b/test/augmentation/test_augmentation_3d.py@@ -2,6 +2,7 @@ from typing import Union, Tupleimport pytestimport torch+from torch._C import dtypeimport torch.nn as nnfrom torch.testing import assert_allclose@@ -197,40 +198,36 @@ class TestRandomVerticalFlip3D:repr = "RandomVerticalFlip3D(p=0.5, p_batch=1.0, same_on_batch=False, return_transform=0.5)"assert str(f) == repr- def test_random_vflip(self, device):+ def test_random_vflip(self, device, dtype):f = RandomVerticalFlip3D(p=1.0, return_transform=True)f1 = RandomVerticalFlip3D(p=0., return_transform=True)f2 = RandomVerticalFlip3D(p=1.)f3 = RandomVerticalFlip3D(p=0.)- input = torch.tensor([[[0., 0., 0.],- [0., 0., 0.],- [0., 1., 1.]],- [[0., 0., 0.],- [0., 0., 0.],- [0., 1., 1.]]]) # 2 x 3 x 3- input = input.to(device)+ input = torch.tensor([[[[[0., 0., 0.],+ [0., 0., 0.],+ [0., 1., 1.]],+ [[0., 0., 0.],+ [0., 0., 0.],+ [0., 1., 1.]]]]], device=device, dtype=dtype) # 1 x 1 x 2 x 3 x 3- expected = torch.tensor([[[0., 1., 1.],- [0., 0., 0.],- [0., 0., 0.]],- [[0., 1., 1.],- [0., 0., 0.],- [0., 0., 0.]]]) # 2 x 3 x 3- expected = expected.to(device)+ expected = torch.tensor([[[[[0., 1., 1.],+ [0., 0., 0.],+ [0., 0., 0.]],+ [[0., 1., 1.],+ [0., 0., 0.],+ [0., 0., 0.]]]]], device=device, dtype=dtype) # 1 x 1 x 2 x 3 x 3- expected_transform = torch.tensor([[1., 0., 0., 0.],- [0., -1., 0., 2.],- [0., 0., 1., 0.],- [0., 0., 0., 1.]]) # 4 x 4- expected_transform = expected_transform.to(device)+ expected_transform = torch.tensor([[[1., 0., 0., 0.],+ [0., -1., 0., 2.],+ [0., 0., 1., 0.],+ [0., 0., 0., 1.]]], device=device, dtype=dtype) # 4 x 4- identity = torch.tensor([[1., 0., 0., 0.],- [0., 1., 0., 0.],- [0., 0., 1., 0.],- [0., 0., 0., 1.]]) # 4 x 4- identity = identity.to(device)+ identity = torch.tensor([[[1., 0., 0., 0.],+ [0., 1., 0., 0.],+ [0., 0., 1., 0.],+ [0., 0., 0., 1.]]], device=device, dtype=dtype) # 1 x 4 x 4assert_allclose(f(input)[0], expected)assert_allclose(f(input)[1], expected_transform)@@ -306,9 +303,9 @@ class TestRandomVerticalFlip3D:expected_transform_1 = expected_transform @ expected_transform- assert_allclose(f(input)[0], input.squeeze())+ assert_allclose(f(input)[0], input)assert_allclose(f(input)[1], expected_transform_1)- assert_allclose(f1(input)[0], input.squeeze())+ assert_allclose(f1(input)[0], input)assert_allclose(f1(input)[1], expected_transform)@pytest.mark.skip(reason="turn off all jit for a while")@@ -357,41 +354,36 @@ class TestRandomDepthicalFlip3D:repr = "RandomDepthicalFlip3D(p=0.5, p_batch=1.0, same_on_batch=False, return_transform=0.5)"assert str(f) == repr- def test_random_dflip(self, device):+ def test_random_dflip(self, device, dtype):f = RandomDepthicalFlip3D(p=1.0, return_transform=True)f1 = RandomDepthicalFlip3D(p=0., return_transform=True)f2 = RandomDepthicalFlip3D(p=1.)f3 = RandomDepthicalFlip3D(p=0.)- input = torch.tensor([[[0., 0., 0., 0.],- [0., 0., 0., 0.],- [0., 0., 0., 1.]],- [[0., 0., 0., 0.],- [0., 0., 0., 0.],- [0., 0., 0., 2.]]]) # 2 x 3 x 4-- input = input.to(device)+ input = torch.tensor([[[[[0., 0., 0., 0.],+ [0., 0., 0., 0.],+ [0., 0., 0., 1.]],+ [[0., 0., 0., 0.],+ [0., 0., 0., 0.],+ [0., 0., 0., 2.]]]]], device=device, dtype=dtype) # 2 x 3 x 4- expected = torch.tensor([[[0., 0., 0., 0.],- [0., 0., 0., 0.],- [0., 0., 0., 2.]],- [[0., 0., 0., 0.],- [0., 0., 0., 0.],- [0., 0., 0., 1.]]]) # 2 x 3 x 4- expected = expected.to(device)+ expected = torch.tensor([[[[[0., 0., 0., 0.],+ [0., 0., 0., 0.],+ [0., 0., 0., 2.]],+ [[0., 0., 0., 0.],+ [0., 0., 0., 0.],+ [0., 0., 0., 1.]]]]], device=device, dtype=dtype) # 2 x 3 x 4- expected_transform = torch.tensor([[1., 0., 0., 0.],- [0., 1., 0., 0.],- [0., 0., -1., 1.],- [0., 0., 0., 1.]]) # 4 x 4- expected_transform = expected_transform.to(device)+ expected_transform = torch.tensor([[[1., 0., 0., 0.],+ [0., 1., 0., 0.],+ [0., 0., -1., 1.],+ [0., 0., 0., 1.]]], device=device, dtype=dtype) # 4 x 4- identity = torch.tensor([[1., 0., 0., 0.],- [0., 1., 0., 0.],- [0., 0., 1., 0.],- [0., 0., 0., 1.]]) # 4 x 4- identity = identity.to(device)+ identity = torch.tensor([[[1., 0., 0., 0.],+ [0., 1., 0., 0.],+ [0., 0., 1., 0.],+ [0., 0., 0., 1.]]], device=device, dtype=dtype) # 4 x 4assert_allclose(f(input)[0], expected)assert_allclose(f(input)[1], expected_transform)@@ -461,12 +453,12 @@ class TestRandomDepthicalFlip3D:RandomDepthicalFlip3D(p=1.0),)- input = torch.tensor([[[0., 0., 0., 0.],- [0., 0., 0., 0.],- [0., 0., 0., 1.]],- [[0., 0., 0., 0.],- [0., 0., 0., 0.],- [0., 0., 0., 2.]]]) # 2 x 3 x 4+ input = torch.tensor([[[[[0., 0., 0., 0.],+ [0., 0., 0., 0.],+ [0., 0., 0., 1.]],+ [[0., 0., 0., 0.],+ [0., 0., 0., 0.],+ [0., 0., 0., 2.]]]]]) # 2 x 3 x 4input = input.to(device)expected_transform = torch.tensor([[[1., 0., 0., 0.],@@ -477,9 +469,9 @@ class TestRandomDepthicalFlip3D:expected_transform_1 = expected_transform @ expected_transform- assert_allclose(f(input)[0], input.squeeze())+ assert_allclose(f(input)[0], input)assert_allclose(f(input)[1], expected_transform_1)- assert_allclose(f1(input)[0], input.squeeze())+ assert_allclose(f1(input)[0], input)assert_allclose(f1(input)[1], expected_transform)@pytest.mark.skip(reason="turn off all jit for a while")@@ -928,7 +920,7 @@ class TestRandomEqualize3D:bs, channels, depth, height, width = 1, 3, 6, 10, 10- inputs3d = self.build_input(channels, depth, height, width, device=device, dtype=dtype).squeeze(dim=0)+ inputs3d = self.build_input(channels, depth, height, width, bs, device=device, dtype=dtype)row_expected = torch.tensor([0.0000, 0.11764, 0.2353, 0.3529, 0.4706, 0.5882, 0.7059, 0.8235, 0.9412, 1.0000diff --git a/test/augmentation/test_augmentation_mix.py b/test/augmentation/test_augmentation_mix.pyindex 80b8c489f..9354af785 100644--- a/test/augmentation/test_augmentation_mix.py+++ b/test/augmentation/test_augmentation_mix.py@@ -1,11 +1,7 @@-from typing import Union, Tuple-import torchfrom torch.testing import assert_allclosefrom torch.autograd import gradcheck-import kornia-import kornia.testing as utils # test utilsfrom kornia.augmentation import (RandomMixUp,RandomCutMix@@ -156,7 +152,8 @@ class TestRandomCutMix:def test_random_mixup_beta0(self, device, dtype):torch.manual_seed(76)# beta 0 => resample 0.5 area- f = RandomCutMix(beta=0., width=4, height=3, p=1.)+ # beta cannot be 0 after torch 1.8.0+ f = RandomCutMix(beta=1e-7, width=4, height=3, p=1.)input = torch.stack([torch.ones(1, 3, 4, device=device, dtype=dtype),diff --git a/test/geometry/subpix/test_spatial_softargmax.py b/test/geometry/subpix/test_spatial_softargmax.pyindex 5a5254768..4a350541e 100644--- a/test/geometry/subpix/test_spatial_softargmax.py+++ b/test/geometry/subpix/test_spatial_softargmax.py@@ -134,7 +134,8 @@ class TestSpatialSoftArgmax2d:std = torch.tensor([1.0, 1.0], device=device, dtype=dtype)hm = kornia.geometry.dsnt.spatial_softmax2d(input)- assert_allclose(hm.sum(-1).sum(-1), torch.tensor(1.0, device=device, dtype=dtype), atol=1e-4, rtol=1e-4)+ assert_allclose(+ hm.sum(-1).sum(-1), torch.tensor([[1.0, 1.0]], device=device, dtype=dtype), atol=1e-4, rtol=1e-4)pred = kornia.geometry.dsnt.spatial_expectation2d(hm)assert_allclose(diff --git a/test/geometry/test_linalg.py b/test/geometry/test_linalg.pyindex 5a68fb1b2..6bd0015ce 100644--- a/test/geometry/test_linalg.py+++ b/test/geometry/test_linalg.py@@ -112,7 +112,7 @@ class TestTransformBoxes:boxes = torch.tensor([[139.2640, 103.0150, 397.3120, 410.5225]], device=device, dtype=dtype)- expected = torch.tensor([372.7360, 103.0150, 114.6880, 410.5225], device=device, dtype=dtype)+ expected = torch.tensor([[372.7360, 103.0150, 114.6880, 410.5225]], device=device, dtype=dtype)trans_mat = torch.tensor([[[-1., 0., 512.],[0., 1., 0.],diff --git a/test/geometry/transform/test_affine.py b/test/geometry/transform/test_affine.pyindex 3ad72ad1c..3c9eadfc4 100644--- a/test/geometry/transform/test_affine.py+++ b/test/geometry/transform/test_affine.py@@ -305,7 +305,7 @@ class TestScale:[0., 1., 1., 0.],[0., 1., 1., 0.],[0., 0., 0., 0.]- ]], device=device, dtype=dtype)+ ]], device=device, dtype=dtype).repeat(2, 1, 1, 1)# prepare transformationscale_factor = torch.tensor([[0.5, 0.5]], device=device, dtype=dtype)transform = kornia.Scale(scale_factor)@@ -324,7 +324,7 @@ class TestScale:[0., 1., 1., 0.],[0., 1., 1., 0.],[0., 0., 0., 0.]- ]], device=device, dtype=dtype)+ ]], device=device, dtype=dtype).repeat(2, 1, 1, 1)# prepare transformationscale_factor = torch.tensor([[0.5, 0.5]], device=device, dtype=dtype)transform = kornia.Scale(scale_factor)@@ -429,7 +429,7 @@ class TestShear:[0.75, 1., 1., 1.],[0.25, 1., 1., 1.],[0., 0.75, 1., 1.],- [0., 0.25, 1., 1.]]]], device=device, dtype=dtype)+ [0., 0.25, 1., 1.]]]], device=device, dtype=dtype).repeat(2, 1, 1, 1)# prepare transformationshear = torch.tensor([[0.5, 0.0]], device=device, dtype=dtype)diff --git a/test/geometry/transform/test_imgwarp.py b/test/geometry/transform/test_imgwarp.pyindex f1044dc88..9a4b2f6bc 100644--- a/test/geometry/transform/test_imgwarp.py+++ b/test/geometry/transform/test_imgwarp.py@@ -174,7 +174,7 @@ class TestWarpPerspective:expected = torch.tensor([[[[0.2500, 0.9167, 1.5833],[2.1667, 5.1667, 6.5000],- [4.8333, 10.5000, 11.8333]]]], device=device, dtype=dtype)+ [4.8333, 10.5000, 11.8333]]]], device=device, dtype=dtype).repeat(batch_size, channels, 1, 1)# warp and assertpatch_warped = kornia.warp_perspective(patch, dst_trans_src,@@ -339,7 +339,7 @@ class TestRemap:[1., 1., 1., 0.],[1., 1., 1., 0.],[0., 0., 0., 0.],- ]]], device=device, dtype=dtype)+ ]]], device=device, dtype=dtype).repeat(2, 1, 1, 1)grid = kornia.utils.create_meshgrid(height, width, normalized_coordinates=False, device=device).to(dtype)@@ -431,7 +431,7 @@ class TestInvertAffineTransform:expected = torch.tensor([[[0., -1., 0.],[1., 0., 0.],- ]], device=device, dtype=dtype)+ ]], device=device, dtype=dtype).repeat(2, 1, 1)matrix = kornia.get_rotation_matrix2d(center, angle, scale).repeat(2, 1, 1)matrix_inv = kornia.invert_affine_transform(matrix)diff --git a/test/geometry/transform/test_projwarp.py b/test/geometry/transform/test_projwarp.pyindex 8f8d3e7fd..09465f3dc 100644--- a/test/geometry/transform/test_projwarp.py+++ b/test/geometry/transform/test_projwarp.py@@ -253,7 +253,7 @@ class TestGetRotationMatrix3d:[1., 0., 0., 0.],[0., 1., 0., 0.],[0., 0., 1., 0.],- ], device=device, dtype=dtype)+ ], device=device, dtype=dtype).unsqueeze(0)assert_allclose(P, P_expected, atol=1e-4, rtol=1e-4)def test_rot90x(self, device, dtype):@@ -265,7 +265,7 @@ class TestGetRotationMatrix3d:[1., 0., 0., 0.],[0., 0., -1., 0.],[0., 1., 0., 0.],- ], device=device, dtype=dtype)+ ], device=device, dtype=dtype).unsqueeze(0)assert_allclose(P, P_expected, atol=1e-4, rtol=1e-4)def test_rot90y(self, device, dtype):@@ -277,7 +277,7 @@ class TestGetRotationMatrix3d:[0., 0., 1., 0.],[0., 1., 0., 0.],[-1., 0., 0., 0.],- ], device=device, dtype=dtype)+ ], device=device, dtype=dtype).unsqueeze(0)assert_allclose(P, P_expected, atol=1e-4, rtol=1e-4)def test_rot90z(self, device, dtype):@@ -289,7 +289,7 @@ class TestGetRotationMatrix3d:[0., -1., 0., 0.],[1., 0., 0., 0.],[0., 0., 1., 0.],- ], device=device, dtype=dtype)+ ], device=device, dtype=dtype).unsqueeze(0)assert_allclose(P, P_expected, atol=1e-4, rtol=1e-4)def test_gradcheck(self, device, dtype):diff --git a/test/geometry/warp/test_depth_warper.py b/test/geometry/warp/test_depth_warper.pyindex e2abcfee4..c169652ac 100644--- a/test/geometry/warp/test_depth_warper.py+++ b/test/geometry/warp/test_depth_warper.py@@ -70,10 +70,10 @@ class TestDepthWarper:# check offset in x-axisassert_allclose(- grid_warped[..., -2, 0], grid_norm[..., -1, 0], atol=1e-4, rtol=1e-4)+ grid_warped[..., -2, 0], grid_norm[..., -1, 0].repeat(batch_size, 1), atol=1e-4, rtol=1e-4)# check that y-axis remain the sameassert_allclose(- grid_warped[..., -1, 1], grid_norm[..., -1, 1], rtol=1e-4, atol=1e-4)+ grid_warped[..., -1, 1], grid_norm[..., -1, 1].repeat(batch_size, 1), rtol=1e-4, atol=1e-4)@pytest.mark.parametrize("batch_size", (1, 2,))def test_warp_grid_offset_x1y1_depth1(self, batch_size, device, dtype):@@ -98,10 +98,10 @@ class TestDepthWarper:# check offset in x-axisassert_allclose(- grid_warped[..., -2, 0], grid_norm[..., -1, 0], atol=1e-4, rtol=1e-4)+ grid_warped[..., -2, 0], grid_norm[..., -1, 0].repeat(batch_size, 1), atol=1e-4, rtol=1e-4)# check that y-axis remain the sameassert_allclose(- grid_warped[..., -2, :, 1], grid_norm[..., -1, :, 1], rtol=1e-4, atol=1e-4)+ grid_warped[..., -2, :, 1], grid_norm[..., -1, :, 1].repeat(batch_size, 1), rtol=1e-4, atol=1e-4)@pytest.mark.parametrize("batch_size", (1, 2,))def test_warp_tensor_offset_x1y1(self, batch_size, device, dtype):diff --git a/test/geometry/warp/test_homography_warper.py b/test/geometry/warp/test_homography_warper.pyindex d9e743efc..9e9bb8b31 100644--- a/test/geometry/warp/test_homography_warper.py+++ b/test/geometry/warp/test_homography_warper.py@@ -50,7 +50,7 @@ class TestHomographyWarper:(height * 2, width // 2))res = torch.tensor([[[4.0, 0.0, 3.0],[0.0, 1 / 3, -2 / 3],- [0.0, 0.0, 1.0]]], device=device, dtype=dtype)+ [0.0, 0.0, 1.0]]], device=device, dtype=dtype).repeat(batch_size, 1, 1)assert_allclose(norm_homo, res, atol=1e-4, rtol=1e-4)@pytest.mark.parametrize("batch_size", [1, 3])@@ -359,7 +359,7 @@ class TestHomographyWarper3D:res = torch.tensor([[[4.0, 0.0, 0.0, 3.0],[0.0, 0.4667, 0.0, -0.5333],[0.0, 0.0, 3.0, 2.0],- [0.0, 0.0, 0.0, 1.0]]], device=device, dtype=dtype)+ [0.0, 0.0, 0.0, 1.0]]], device=device, dtype=dtype).repeat(batch_size, 1, 1)assert_allclose(norm_homo, res, rtol=1e-4, atol=1e-4)@pytest.mark.parametrize("batch_size", [1, 3])