Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

Fixed nightly errors (#886)

shijianjianba533e61b946
diff --git a/kornia/augmentation/utils/helpers.py b/kornia/augmentation/utils/helpers.py
index 814249f06..119f7e5e9 100644
--- a/kornia/augmentation/utils/helpers.py
+++ b/kornia/augmentation/utils/helpers.py
@@ -271,7 +271,7 @@ def _adapted_beta(
])
a = torch.as_tensor(a, device=device, dtype=dtype)
b = torch.as_tensor(b, device=device, dtype=dtype)
- dist = Beta(a, b)
+ dist = Beta(a, b, validate_args=False)
return _adapted_rsampling(shape, dist, same_on_batch)
diff --git a/test/augmentation/test_functional.py b/test/augmentation/test_functional.py
index f24bc4751..1aa864380 100644
--- a/test/augmentation/test_functional.py
+++ b/test/augmentation/test_functional.py
@@ -86,7 +86,7 @@ class TestColorJitter:
expected = input
- assert_allclose(F.apply_color_jitter(input[None], jitter_param), expected, atol=1e-4, rtol=1e-5)
+ assert_allclose(F.apply_color_jitter(input[None], jitter_param), expected[None], atol=1e-4, rtol=1e-5)
def test_color_jitter_batch(self):
batch_size = 2
@@ -327,7 +327,7 @@ class TestRandomGrayscale:
[0.6988886, 0.5897652, 0.6532392, 0.7234108, 0.7218805]]])
expected = expected.to(device)
- assert_allclose(F.apply_grayscale(data[None]), expected)
+ assert_allclose(F.apply_grayscale(data[None]), expected[None])
def test_opencv_true_batch(self, device):
batch_size = 4
diff --git a/test/augmentation/test_perspective.py b/test/augmentation/test_perspective.py
index 978fd7a16..0fb3019c3 100644
--- a/test/augmentation/test_perspective.py
+++ b/test/augmentation/test_perspective.py
@@ -96,7 +96,7 @@ class TestRandomPerspective:
assert out_perspective[0].shape == x_data.shape
assert out_perspective[1].shape == (1, 3, 3)
assert_allclose(out_perspective[0], x_data)
- assert_allclose(out_perspective[1], torch.eye(3, device=device))
+ assert_allclose(out_perspective[1], torch.eye(3, device=device)[None])
def test_transform_module_should_return_expected_transform(self, device):
torch.manual_seed(0)
diff --git a/test/augmentation/test_random_generator.py b/test/augmentation/test_random_generator.py
index e08166d74..9588d7349 100644
--- a/test/augmentation/test_random_generator.py
+++ b/test/augmentation/test_random_generator.py
@@ -569,7 +569,7 @@ class TestRandomCropSizeGen(RandomGeneratorBaseTests):
ratio=torch.tensor([1., 1.], device=device, dtype=dtype),
same_on_batch=False)
expected = dict(
- size=torch.tensor([[100, 100]], device=device, dtype=dtype)
+ size=torch.tensor([[100, 100]], device=device, dtype=dtype).repeat(100, 1)
)
assert res.keys() == expected.keys()
assert_allclose(res['size'], expected['size'])
@@ -1005,14 +1005,14 @@ class TestRandomCutMixGen(RandomGeneratorBaseTests):
@pytest.mark.parametrize('p', [0, 0.5, 1.])
@pytest.mark.parametrize('width,height', [(200, 200)])
@pytest.mark.parametrize('num_mix', [1, 3])
- @pytest.mark.parametrize('beta', [None, torch.tensor(0.), torch.tensor(1.)])
+ @pytest.mark.parametrize('beta', [None, torch.tensor(1e-15), torch.tensor(1.)])
@pytest.mark.parametrize('cut_size', [None, torch.tensor([0., 1.]), torch.tensor([0.3, 0.6])])
@pytest.mark.parametrize('same_on_batch', [True, False])
def test_valid_param_combinations(
self, batch_size, p, width, height, num_mix, beta, cut_size, same_on_batch, device, dtype
):
random_cutmix_generator(
- batch_size=batch_size, p=p, width=width, height=height,
+ batch_size=batch_size, p=p, width=width, height=height, num_mix=num_mix,
beta=beta.to(device=device, dtype=dtype) if isinstance(beta, (torch.Tensor)) else beta,
cut_size=cut_size.to(device=device, dtype=dtype) if isinstance(cut_size, (torch.Tensor)) else cut_size,
same_on_batch=same_on_batch)
@@ -1026,10 +1026,11 @@ class TestRandomCutMixGen(RandomGeneratorBaseTests):
(200, 200, 1, None, torch.tensor([-1., 1.])),
(200, 200, 1, None, torch.tensor([0., 2.])),
])
- def test_invalid_param_combinations(self, width, height, num_mix, beta, cut_size, device, dtype):
+ @pytest.mark.parametrize('same_on_batch', [True, False])
+ def test_invalid_param_combinations(self, width, height, num_mix, beta, cut_size, same_on_batch, device, dtype):
with pytest.raises(Exception):
random_cutmix_generator(
- batch_size=8, p=p, width=width, height=height,
+ batch_size=8, p=0.5, width=width, height=height, num_mix=num_mix,
beta=beta.to(device=device, dtype=dtype) if isinstance(beta, (torch.Tensor)) else beta,
cut_size=beta.to(device=device, dtype=dtype) if isinstance(cut_size, (torch.Tensor)) else cut_size,
same_on_batch=same_on_batch)
diff --git a/test/augmentation/test_random_generator_3d.py b/test/augmentation/test_random_generator_3d.py
index c7980e263..73bd1e563 100644
--- a/test/augmentation/test_random_generator_3d.py
+++ b/test/augmentation/test_random_generator_3d.py
@@ -476,7 +476,7 @@ class TestCenterCropGen3D(RandomGeneratorBaseTests):
[50, 25, 159],
[149, 25, 159],
[149, 174, 159],
- [50, 174, 159]]], device=device, dtype=torch.long),
+ [50, 174, 159]]], device=device, dtype=torch.long).repeat(2, 1, 1),
dst=torch.tensor([
[[0, 0, 0],
[99, 0, 0],
@@ -485,7 +485,7 @@ class TestCenterCropGen3D(RandomGeneratorBaseTests):
[0, 0, 119],
[99, 0, 119],
[99, 149, 119],
- [0, 149, 119]]], device=device, dtype=torch.long),
+ [0, 149, 119]]], device=device, dtype=torch.long).repeat(2, 1, 1),
)
assert res.keys() == expected.keys()
assert_allclose(res['src'].to(device=device), expected['src'], atol=1e-4, rtol=1e-4)
diff --git a/test/feature/test_laf.py b/test/feature/test_laf.py
index 5ca7da882..0cff50f45 100644
--- a/test/feature/test_laf.py
+++ b/test/feature/test_laf.py
@@ -215,14 +215,14 @@ class TestMakeUpright:
def test_do_nothing(self, device):
inp = torch.tensor([[1, 0, 0], [0, 1, 0]], device=device).float()
inp = inp.view(1, 1, 2, 3)
- expected = torch.tensor([[1, 0, 0], [0, 1, 0]], device=device).float()
+ expected = torch.tensor([[[[1, 0, 0], [0, 1, 0]]]], device=device).float()
laf = kornia.feature.make_upright(inp)
assert_allclose(laf, expected)
def test_do_nothing_with_scalea(self, device):
inp = torch.tensor([[2, 0, 0], [0, 2, 0]], device=device).float()
inp = inp.view(1, 1, 2, 3)
- expected = torch.tensor([[2, 0, 0], [0, 2, 0]], device=device).float()
+ expected = torch.tensor([[[[2, 0, 0], [0, 2, 0]]]], device=device).float()
laf = kornia.feature.make_upright(inp)
assert_allclose(laf, expected)
@@ -298,7 +298,7 @@ class TestNormalizeLAF:
laf = torch.tensor([[1, 0, 1], [0, 1, 1]]).float()
laf = laf.view(1, 1, 2, 3)
img = torch.rand(1, 3, h, w)
- expected = torch.tensor([[0.2, 0, 0.1], [0, 0.2, 0.2]]).float()
+ expected = torch.tensor([[[[0.2, 0, 0.1], [0, 0.2, 0.2]]]]).float()
lafn = kornia.feature.normalize_laf(laf, img)
assert_allclose(lafn, expected)
diff --git a/test/utils/test_metrics.py b/test/utils/test_metrics.py
index fa41fd7a7..a310693f3 100644
--- a/test/utils/test_metrics.py
+++ b/test/utils/test_metrics.py
@@ -32,7 +32,7 @@ class TestMeanIoU:
mean_iou = kornia.utils.metrics.mean_iou(predicted, actual, num_classes)
mean_iou_real = torch.tensor(
- [[1.0, 1.0]], dtype=torch.float32)
+ [[1.0, 1.0], [1.0, 1.0]], dtype=torch.float32)
assert mean_iou.shape == (batch_size, num_classes)
assert_allclose(mean_iou, mean_iou_real)
@@ -118,8 +118,10 @@ class TestConfusionMatrix:
conf_mat = kornia.utils.metrics.confusion_matrix(
predicted, actual, num_classes)
conf_mat_real = torch.tensor(
- [[[3, 1],
- [0, 4]]], dtype=torch.float32)
+ [
+ [[3, 1], [0, 4]],
+ [[3, 1], [0, 4]]
+ ], dtype=torch.float32)
assert_allclose(conf_mat, conf_mat_real)
def test_three_classes(self):