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

Class MinkowskiToDenseTensor

MinkowskiEngine/MinkowskiOps.py:414–457  ·  view source on GitHub ↗

r"""Converts a (differentiable) sparse tensor to a torch tensor. The return type has the BxCxD1xD2x....xDN format. Example:: >>> dense_tensor = torch.rand(3, 4, 11, 11, 11, 11) # BxCxD1xD2x....xDN >>> dense_tensor.requires_grad = True >>> # Since the shape is fixed,

Source from the content-addressed store, hash-verified

412
413
414class MinkowskiToDenseTensor(MinkowskiModuleBase):
415 r"""Converts a (differentiable) sparse tensor to a torch tensor.
416
417 The return type has the BxCxD1xD2x....xDN format.
418
419 Example::
420
421 >>> dense_tensor = torch.rand(3, 4, 11, 11, 11, 11) # BxCxD1xD2x....xDN
422 >>> dense_tensor.requires_grad = True
423
424 >>> # Since the shape is fixed, cache the coordinates for faster inference
425 >>> coordinates = dense_coordinates(dense_tensor.shape)
426
427 >>> network = nn.Sequential(
428 >>> # Add layers that can be applied on a regular pytorch tensor
429 >>> nn.ReLU(),
430 >>> MinkowskiToSparseTensor(coordinates=coordinates),
431 >>> MinkowskiConvolution(4, 5, stride=2, kernel_size=3, dimension=4),
432 >>> MinkowskiBatchNorm(5),
433 >>> MinkowskiReLU(),
434 >>> MinkowskiConvolutionTranspose(5, 6, stride=2, kernel_size=3, dimension=4),
435 >>> MinkowskiToDenseTensor(
436 >>> dense_tensor.shape
437 >>> ), # must have the same tensor stride.
438 >>> )
439
440 >>> for i in range(5):
441 >>> print(f"Iteration: {i}")
442 >>> output = network(dense_tensor) # returns a regular pytorch tensor
443 >>> output.sum().backward()
444
445 """
446
447 def __init__(self, shape: torch.Size = None):
448 MinkowskiModuleBase.__init__(self)
449 self.shape = shape
450
451 def forward(self, input: SparseTensor):
452 # dense tensor to sparse tensor conversion
453 dense_tensor, _, _ = input.dense(shape=self.shape)
454 return dense_tensor
455
456 def __repr__(self):
457 return self.__class__.__name__ + "()"
458
459
460class MinkowskiToFeature(MinkowskiModuleBase):

Callers 1

test_networkMethod · 0.90

Calls

no outgoing calls

Tested by 1

test_networkMethod · 0.72