Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

fix issue with test_contrib

edgarribab1218b98986a
diff --git a/test/test_contrib.py b/test/test_contrib.py
index 4e9ad8c72..c3e8ec3cd 100644
--- a/test/test_contrib.py
+++ b/test/test_contrib.py
@@ -8,12 +8,12 @@ import utils
class TestExtractTensorPatches:
- def _test_smoke(self):
+ def test_smoke(self):
input = torch.arange(16.).view(1, 1, 4, 4)
m = tgm.contrib.ExtractTensorPatches(3)
assert m(input).shape == (1, 4, 1, 3, 3)
- def _test_b1_ch1_h4w4_ws3(self):
+ def test_b1_ch1_h4w4_ws3(self):
input = torch.arange(16.).view(1, 1, 4, 4)
m = tgm.contrib.ExtractTensorPatches(3)
patches = m(input)
@@ -23,7 +23,7 @@ class TestExtractTensorPatches:
assert utils.check_equal_torch(input[0, :, 1:, :3], patches[0, 2])
assert utils.check_equal_torch(input[0, :, 1:, 1:], patches[0, 3])
- def _test_b1_ch2_h4w4_ws3(self):
+ def test_b1_ch2_h4w4_ws3(self):
input = torch.arange(16.).view(1, 1, 4, 4)
input = input.expand(-1, 2, -1, -1) # copy all channels
m = tgm.contrib.ExtractTensorPatches(3)
@@ -34,7 +34,7 @@ class TestExtractTensorPatches:
assert utils.check_equal_torch(input[0, :, 1:, :3], patches[0, 2])
assert utils.check_equal_torch(input[0, :, 1:, 1:], patches[0, 3])
- def _test_b1_ch1_h4w4_ws2(self):
+ def test_b1_ch1_h4w4_ws2(self):
input = torch.arange(16.).view(1, 1, 4, 4)
m = tgm.contrib.ExtractTensorPatches(2)
patches = m(input)
@@ -44,7 +44,7 @@ class TestExtractTensorPatches:
assert utils.check_equal_torch(input[0, :, 1:3, 1:3], patches[0, 4])
assert utils.check_equal_torch(input[0, :, 2:4, 1:3], patches[0, 7])
- def _test_b1_ch1_h4w4_ws2_stride2(self):
+ def test_b1_ch1_h4w4_ws2_stride2(self):
input = torch.arange(16.).view(1, 1, 4, 4)
m = tgm.contrib.ExtractTensorPatches(2, stride=2)
patches = m(input)
@@ -54,7 +54,7 @@ class TestExtractTensorPatches:
assert utils.check_equal_torch(input[0, :, 2:4, 0:2], patches[0, 2])
assert utils.check_equal_torch(input[0, :, 2:4, 2:4], patches[0, 3])
- def _test_b1_ch1_h4w4_ws2_stride21(self):
+ def test_b1_ch1_h4w4_ws2_stride21(self):
input = torch.arange(16.).view(1, 1, 4, 4)
m = tgm.contrib.ExtractTensorPatches(2, stride=(2, 1))
patches = m(input)
@@ -64,7 +64,7 @@ class TestExtractTensorPatches:
assert utils.check_equal_torch(input[0, :, 2:4, 0:2], patches[0, 3])
assert utils.check_equal_torch(input[0, :, 2:4, 2:4], patches[0, 5])
- def _test_b1_ch1_h3w3_ws2_stride1_padding1(self):
+ def test_b1_ch1_h3w3_ws2_stride1_padding1(self):
input = torch.arange(9.).view(1, 1, 3, 3)
m = tgm.contrib.ExtractTensorPatches(2, stride=1, padding=1)
patches = m(input)
@@ -74,7 +74,7 @@ class TestExtractTensorPatches:
assert utils.check_equal_torch(input[0, :, 1:3, 0:2], patches[0, 9])
assert utils.check_equal_torch(input[0, :, 1:3, 1:3], patches[0, 10])
- def _test_b2_ch1_h3w3_ws2_stride1_padding1(self):
+ def test_b2_ch1_h3w3_ws2_stride1_padding1(self):
batch_size = 2
input = torch.arange(9.).view(1, 1, 3, 3)
input = input.expand(batch_size, -1, -1, -1)
@@ -91,7 +91,7 @@ class TestExtractTensorPatches:
assert utils.check_equal_torch(
input[i, :, 1:3, 1:3], patches[i, 10])
- def _test_b1_ch1_h3w3_ws23(self):
+ def test_b1_ch1_h3w3_ws23(self):
input = torch.arange(9.).view(1, 1, 3, 3)
m = tgm.contrib.ExtractTensorPatches((2, 3))
patches = m(input)
@@ -99,7 +99,7 @@ class TestExtractTensorPatches:
assert utils.check_equal_torch(input[0, :, 0:2, 0:3], patches[0, 0])
assert utils.check_equal_torch(input[0, :, 1:3, 0:3], patches[0, 1])
- def _test_b1_ch1_h3w4_ws23(self):
+ def test_b1_ch1_h3w4_ws23(self):
input = torch.arange(12.).view(1, 1, 3, 4)
m = tgm.contrib.ExtractTensorPatches((2, 3))
patches = m(input)
@@ -110,28 +110,15 @@ class TestExtractTensorPatches:
assert utils.check_equal_torch(input[0, :, 1:3, 1:4], patches[0, 3])
# TODO: implement me
- def _test_jit(self):
+ def test_jit(self):
pass
- def _test_gradcheck(self):
+ def test_gradcheck(self):
input = torch.rand(2, 3, 4, 4)
input = utils.tensor_to_gradcheck_var(input) # to var
assert gradcheck(tgm.contrib.extract_tensor_patches,
(input, 3,), raise_exception=True)
- def test_run_all(self):
- self._test_smoke()
- self._test_b1_ch1_h4w4_ws3()
- self._test_b1_ch2_h4w4_ws3()
- self._test_b1_ch1_h4w4_ws2()
- self._test_b1_ch1_h3w3_ws23()
- self._test_b1_ch1_h3w4_ws23()
- self._test_b1_ch1_h4w4_ws2_stride2()
- self._test_b1_ch1_h4w4_ws2_stride21()
- self._test_b1_ch1_h3w3_ws2_stride1_padding1()
- self._test_b2_ch1_h3w3_ws2_stride1_padding1()
- self._test_gradcheck()
-
class TestSoftArgmax2d:
def _test_smoke(self):