Perform Upsampling with Inverse Convolution
masterIn tasks like semantic segmentation, you often need to upsample features back to the original resolution.
Important Distinction: spconv.SparseInverseConv3d is not the same as spconv.SparseConvTranspose3d.
spconv.SparseInverseConv3d: Designed to be the mathematical 'inverse' of a sparse convolution. The output contains the same indices as the input of the correspondingSparseConv3d. To use it, you must provide the sameindice_keyused during the downsampling step and the samekernel_sizeto create the weights.spconv.SparseConvTranspose3d: Standard upsampling (equivalent tonn.ConvTranspose3d). This is very slow and cannot recover the original point cloud structure directly. It should primarily be used in generative models.
class ExampleNet(nn.Module):
def __init__(self, shape):
super().__init__()
self.net = spconv.SparseSequential(
spconv.SparseConv3d(32, 64, 3, 2, indice_key="cp0"),
spconv.SparseInverseConv3d(64, 32, 3, indice_key="cp0"), # Uses saved indices from cp0
)
self.shape = shape
def forward(self, features, coors, batch_size):
coors = coors.int()
x = spconv.SparseConvTensor(features, coors, self.shape, batch_size)
return self.net(x)