MCPcopy Create free account
hub / github.com/NVIDIA/MinkowskiEngine / test

Method test

tests/python/dense.py:45–95  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

43
44class TestDense(unittest.TestCase):
45 def test(self):
46 print(f"{self.__class__.__name__}: test_dense")
47 in_channels, out_channels, D = 2, 3, 2
48 coords1 = torch.IntTensor([[0, 0], [0, 1], [1, 1]])
49 feats1 = torch.DoubleTensor([[1, 2], [3, 4], [5, 6]])
50
51 coords2 = torch.IntTensor([[1, 1], [1, 2], [2, 1]])
52 feats2 = torch.DoubleTensor([[7, 8], [9, 10], [11, 12]])
53 coords, feats = ME.utils.sparse_collate([coords1, coords2], [feats1, feats2])
54 input = SparseTensor(feats, coords)
55 input.requires_grad_()
56 dinput, min_coord, tensor_stride = input.dense()
57 self.assertTrue(dinput[0, 0, 0, 1] == 3)
58 self.assertTrue(dinput[0, 1, 0, 1] == 4)
59 self.assertTrue(dinput[0, 0, 1, 1] == 5)
60 self.assertTrue(dinput[0, 1, 1, 1] == 6)
61
62 self.assertTrue(dinput[1, 0, 1, 1] == 7)
63 self.assertTrue(dinput[1, 1, 1, 1] == 8)
64 self.assertTrue(dinput[1, 0, 2, 1] == 11)
65 self.assertTrue(dinput[1, 1, 2, 1] == 12)
66
67 # Initialize context
68 conv = MinkowskiConvolution(
69 in_channels, out_channels, kernel_size=3, stride=2, bias=True, dimension=D,
70 )
71 conv = conv.double()
72 output = conv(input)
73 print(input.C, output.C)
74
75 # Convert to a dense tensor
76 dense_output, min_coord, tensor_stride = output.dense()
77 print(dense_output.shape)
78 print(dense_output)
79 print(min_coord)
80 print(tensor_stride)
81
82 dense_output, min_coord, tensor_stride = output.dense(
83 min_coordinate=torch.IntTensor([-2, -2])
84 )
85
86 print(dense_output)
87 print(min_coord)
88 print(tensor_stride)
89
90 print(feats.grad)
91
92 loss = dense_output.sum()
93 loss.backward()
94
95 print(feats.grad)
96
97
98class TestDenseToSparse(unittest.TestCase):

Callers

nothing calls this directly

Calls 7

denseMethod · 0.95
SparseTensorClass · 0.90
convFunction · 0.85
requires_grad_Method · 0.80
doubleMethod · 0.80
backwardMethod · 0.45

Tested by

no test coverage detected