def test_maxpool(self): coords = torch.IntTensor([[0, 1], [0, 1], [0, 2], [0, 2], [1, 0], [1, 0], [1, 1]]) feats = torch.FloatTensor([[0, 1, 2, 3, 5, 6, 7]]).T sfield = TensorField(feats, coords) # Convert to a sparse tensor stensor = sfield.sparse( quantization_mode=SparseTensorQuantizationMode.MAX_POOL) print(stensor) self.assertTrue( {1, 3, 6, 7} == {a for a in stensor.F.squeeze().detach().numpy()}) # device cuda if not torch.cuda.is_available(): return sfield = TensorField(feats, coords, device="cuda") # Convert to a sparse tensor stensor = sfield.sparse( quantization_mode=SparseTensorQuantizationMode.MAX_POOL) print(stensor) self.assertTrue( {1, 3, 6, 7 } == {a for a in stensor.F.squeeze().detach().cpu().numpy()})
def test_pcd(self): coords, colors, pcd = load_file("1.ply") voxel_size = 0.02 colors = torch.from_numpy(colors) bcoords = batched_coordinates([coords / voxel_size]) tfield = TensorField(colors, bcoords) self.assertTrue(len(tfield) == len(colors)) stensor = tfield.sparse() print(stensor)
def test(self): coords = torch.IntTensor([[0, 1], [0, 1], [0, 2], [0, 2], [1, 0], [1, 0], [1, 1]]) feats = torch.FloatTensor([[0, 1, 2, 3, 5, 6, 7]]).T sfield = TensorField(feats, coords, device=feats.device) # Convert to a sparse tensor stensor = sfield.sparse() print(stensor) self.assertTrue( {0.5, 2.5, 5.5, 7} == {a for a in stensor.F.squeeze().numpy()})
def test(self): coords = torch.IntTensor([[0, 1], [0, 1], [0, 2], [0, 2], [1, 0], [1, 0], [1, 1]]) feats = torch.FloatTensor([[0, 1, 2, 3, 5, 6, 7]]).T sfield = TensorField(feats, coords, device=feats.device) # Convert to a sparse tensor stensor = sfield.sparse( quantization_mode=SparseTensorQuantizationMode.UNWEIGHTED_AVERAGE) print(stensor) self.assertTrue({0.5, 2.5, 5.5, 7} == {a for a in stensor.F.squeeze().detach().numpy()})
def field_to_sparse(self): coords, colors, pcd = load_file("1.ply") voxel_size = 0.02 colors = torch.from_numpy(colors).float() bcoords = batched_coordinates([coords / voxel_size], dtype=torch.float32) tfield = TensorField(colors, bcoords) network = nn.Sequential( MinkowskiToSparseTensor(), MinkowskiConvolution(3, 8, kernel_size=3, stride=4, dimension=3), MinkowskiReLU(), MinkowskiConvolution(8, 16, kernel_size=3, stride=4, dimension=3), ) otensor = network(tfield) field_to_sparse = tfield.sparse( coordinate_map_key=otensor.coordinate_map_key) self.assertTrue(len(field_to_sparse.F) == len(otensor))