MinkowskiConvolution

All classes defined in this class does not require region_type, region_offset, out_coords_key, and axis_types. If you provide those to the class initialization, make sure that you are providing valid arguments.

MinkowskiConvolution

class MinkowskiEngine.MinkowskiConvolution(in_channels, out_channels, kernel_size=-1, stride=1, dilation=1, bias=False, kernel_generator=None, expand_coordinates=False, convolution_mode=<ConvolutionMode.DEFAULT: 0>, dimension=None)

Convolution layer for a sparse tensor.

\[\mathbf{x}_\mathbf{u} = \sum_{\mathbf{i} \in \mathcal{N}^D(\mathbf{u}, K, \mathcal{C}^\text{in})} W_\mathbf{i} \mathbf{x}_{\mathbf{i} + \mathbf{u}} \;\text{for} \; \mathbf{u} \in \mathcal{C}^\text{out}\]

where \(K\) is the kernel size and \(\mathcal{N}^D(\mathbf{u}, K, \mathcal{C}^\text{in})\) is the set of offsets that are at most \(\left \lceil{\frac{1}{2}(K - 1)} \right \rceil\) away from \(\mathbf{u}\) definied in \(\mathcal{S}^\text{in}\).

Note

For even \(K\), the kernel offset \(\mathcal{N}^D\) implementation is different from the above definition. The offsets range from \(\mathbf{i} \in [0, K)^D, \; \mathbf{i} \in \mathbb{Z}_+^D\).

__init__(in_channels, out_channels, kernel_size=-1, stride=1, dilation=1, bias=False, kernel_generator=None, expand_coordinates=False, convolution_mode=<ConvolutionMode.DEFAULT: 0>, dimension=None)

convolution on a sparse tensor

Args:

in_channels (int): the number of input channels in the input tensor.

out_channels (int): the number of output channels in the output tensor.

kernel_size (int, optional): the size of the kernel in the output tensor. If not provided, region_offset should be RegionType.CUSTOM and region_offset should be a 2D matrix with size \(N\times D\) such that it lists all \(N\) offsets in D-dimension.

stride (int, or list, optional): stride size of the convolution layer. If non-identity is used, the output coordinates will be at least stride \(\times\) tensor_stride away. When a list is given, the length must be D; each element will be used for stride size for the specific axis.

dilation (int, or list, optional): dilation size for the convolution kernel. When a list is given, the length must be D and each element is an axis specific dilation. All elements must be > 0.

bias (bool, optional): if True, the convolution layer has a bias.

kernel_generator (MinkowskiEngine.KernelGenerator, optional): defines custom kernel shape.

expand_coordinates (bool, optional): Force generation of new coordinates. When True, the output coordinates will be the outer product of the kernel shape and the input coordinates. False by default.

dimension (int): the spatial dimension of the space where all the inputs and the network are defined. For example, images are in a 2D space, meshes and 3D shapes are in a 3D space.

cpu() → T

Moves all model parameters and buffers to the CPU.

Returns:

Module: self

cuda(device: Optional[Union[int, torch.device]] = None) → T

Moves all model parameters and buffers to the GPU.

This also makes associated parameters and buffers different objects. So it should be called before constructing optimizer if the module will live on GPU while being optimized.

Arguments:
device (int, optional): if specified, all parameters will be

copied to that device

Returns:

Module: self

double() → T

Casts all floating point parameters and buffers to double datatype.

Returns:

Module: self

float() → T

Casts all floating point parameters and buffers to float datatype.

Returns:

Module: self

forward(input: MinkowskiSparseTensor.SparseTensor, coordinates: Optional[Union[torch.Tensor, MinkowskiEngineBackend._C.CoordinateMapKey, MinkowskiSparseTensor.SparseTensor]] = None)

input (MinkowskiEngine.SparseTensor): Input sparse tensor to apply a convolution on.

coordinates ((torch.IntTensor, MinkowskiEngine.CoordinateMapKey, MinkowskiEngine.SparseTensor), optional): If provided, generate results on the provided coordinates. None by default.

to(*args, **kwargs)

Moves and/or casts the parameters and buffers.

This can be called as

to(device=None, dtype=None, non_blocking=False)
to(dtype, non_blocking=False)
to(tensor, non_blocking=False)
to(memory_format=torch.channels_last)

Its signature is similar to torch.Tensor.to(), but only accepts floating point desired dtype s. In addition, this method will only cast the floating point parameters and buffers to dtype (if given). The integral parameters and buffers will be moved device, if that is given, but with dtypes unchanged. When non_blocking is set, it tries to convert/move asynchronously with respect to the host if possible, e.g., moving CPU Tensors with pinned memory to CUDA devices.

See below for examples.

Note

This method modifies the module in-place.

Args:
device (torch.device): the desired device of the parameters

and buffers in this module

dtype (torch.dtype): the desired floating point type of

the floating point parameters and buffers in this module

tensor (torch.Tensor): Tensor whose dtype and device are the desired

dtype and device for all parameters and buffers in this module

memory_format (torch.memory_format): the desired memory

format for 4D parameters and buffers in this module (keyword only argument)

Returns:

Module: self

Example:

>>> linear = nn.Linear(2, 2)
>>> linear.weight
Parameter containing:
tensor([[ 0.1913, -0.3420],
        [-0.5113, -0.2325]])
>>> linear.to(torch.double)
Linear(in_features=2, out_features=2, bias=True)
>>> linear.weight
Parameter containing:
tensor([[ 0.1913, -0.3420],
        [-0.5113, -0.2325]], dtype=torch.float64)
>>> gpu1 = torch.device("cuda:1")
>>> linear.to(gpu1, dtype=torch.half, non_blocking=True)
Linear(in_features=2, out_features=2, bias=True)
>>> linear.weight
Parameter containing:
tensor([[ 0.1914, -0.3420],
        [-0.5112, -0.2324]], dtype=torch.float16, device='cuda:1')
>>> cpu = torch.device("cpu")
>>> linear.to(cpu)
Linear(in_features=2, out_features=2, bias=True)
>>> linear.weight
Parameter containing:
tensor([[ 0.1914, -0.3420],
        [-0.5112, -0.2324]], dtype=torch.float16)
type(dst_type: Union[torch.dtype, str]) → T

Casts all parameters and buffers to dst_type.

Arguments:

dst_type (type or string): the desired type

Returns:

Module: self

MinkowskiChannelwiseConvolution

class MinkowskiEngine.MinkowskiChannelwiseConvolution(in_channels, kernel_size=- 1, stride=1, dilation=1, bias=False, kernel_generator=None, dimension=- 1)
__init__(in_channels, kernel_size=- 1, stride=1, dilation=1, bias=False, kernel_generator=None, dimension=- 1)

convolution on a sparse tensor

Args:

in_channels (int): the number of input channels in the input tensor.

kernel_size (int, optional): the size of the kernel in the output tensor. If not provided, region_offset should be RegionType.CUSTOM and region_offset should be a 2D matrix with size \(N\times D\) such that it lists all \(N\) offsets in D-dimension.

stride (int, or list, optional): stride size of the convolution layer. If non-identity is used, the output coordinates will be at least stride \(\times\) tensor_stride away. When a list is given, the length must be D; each element will be used for stride size for the specific axis.

dilation (int, or list, optional): dilation size for the convolution kernel. When a list is given, the length must be D and each element is an axis specific dilation. All elements must be > 0.

bias (bool, optional): if True, the convolution layer has a bias.

kernel_generator (MinkowskiEngine.KernelGenerator, optional): defines the custom kernel shape.

dimension (int): the spatial dimension of the space where all the inputs and the network are defined. For example, images are in a 2D space, meshes and 3D shapes are in a 3D space.

cpu() → T

Moves all model parameters and buffers to the CPU.

Returns:

Module: self

cuda(device: Optional[Union[int, torch.device]] = None) → T

Moves all model parameters and buffers to the GPU.

This also makes associated parameters and buffers different objects. So it should be called before constructing optimizer if the module will live on GPU while being optimized.

Arguments:
device (int, optional): if specified, all parameters will be

copied to that device

Returns:

Module: self

double() → T

Casts all floating point parameters and buffers to double datatype.

Returns:

Module: self

float() → T

Casts all floating point parameters and buffers to float datatype.

Returns:

Module: self

forward(input: MinkowskiSparseTensor.SparseTensor, coords: Optional[Union[torch.IntTensor, MinkowskiEngineBackend._C.CoordinateMapKey, MinkowskiSparseTensor.SparseTensor]] = None)

input (MinkowskiEngine.SparseTensor): Input sparse tensor to apply a convolution on.

coords ((torch.IntTensor, MinkowskiEngine.CoordinateMapKey, MinkowskiEngine.SparseTensor), optional): If provided, generate results on the provided coordinates. None by default.

to(*args, **kwargs)

Moves and/or casts the parameters and buffers.

This can be called as

to(device=None, dtype=None, non_blocking=False)
to(dtype, non_blocking=False)
to(tensor, non_blocking=False)
to(memory_format=torch.channels_last)

Its signature is similar to torch.Tensor.to(), but only accepts floating point desired dtype s. In addition, this method will only cast the floating point parameters and buffers to dtype (if given). The integral parameters and buffers will be moved device, if that is given, but with dtypes unchanged. When non_blocking is set, it tries to convert/move asynchronously with respect to the host if possible, e.g., moving CPU Tensors with pinned memory to CUDA devices.

See below for examples.

Note

This method modifies the module in-place.

Args:
device (torch.device): the desired device of the parameters

and buffers in this module

dtype (torch.dtype): the desired floating point type of

the floating point parameters and buffers in this module

tensor (torch.Tensor): Tensor whose dtype and device are the desired

dtype and device for all parameters and buffers in this module

memory_format (torch.memory_format): the desired memory

format for 4D parameters and buffers in this module (keyword only argument)

Returns:

Module: self

Example:

>>> linear = nn.Linear(2, 2)
>>> linear.weight
Parameter containing:
tensor([[ 0.1913, -0.3420],
        [-0.5113, -0.2325]])
>>> linear.to(torch.double)
Linear(in_features=2, out_features=2, bias=True)
>>> linear.weight
Parameter containing:
tensor([[ 0.1913, -0.3420],
        [-0.5113, -0.2325]], dtype=torch.float64)
>>> gpu1 = torch.device("cuda:1")
>>> linear.to(gpu1, dtype=torch.half, non_blocking=True)
Linear(in_features=2, out_features=2, bias=True)
>>> linear.weight
Parameter containing:
tensor([[ 0.1914, -0.3420],
        [-0.5112, -0.2324]], dtype=torch.float16, device='cuda:1')
>>> cpu = torch.device("cpu")
>>> linear.to(cpu)
Linear(in_features=2, out_features=2, bias=True)
>>> linear.weight
Parameter containing:
tensor([[ 0.1914, -0.3420],
        [-0.5112, -0.2324]], dtype=torch.float16)
type(dst_type: Union[torch.dtype, str]) → T

Casts all parameters and buffers to dst_type.

Arguments:

dst_type (type or string): the desired type

Returns:

Module: self

MinkowskiConvolutionTranspose

class MinkowskiEngine.MinkowskiConvolutionTranspose(in_channels, out_channels, kernel_size=-1, stride=1, dilation=1, bias=False, kernel_generator=None, expand_coordinates=False, convolution_mode=<ConvolutionMode.DEFAULT: 0>, dimension=None)

A generalized sparse transposed convolution or deconvolution layer.

__init__(in_channels, out_channels, kernel_size=-1, stride=1, dilation=1, bias=False, kernel_generator=None, expand_coordinates=False, convolution_mode=<ConvolutionMode.DEFAULT: 0>, dimension=None)

a generalized sparse transposed convolution layer.

Args:

in_channels (int): the number of input channels in the input tensor.

out_channels (int): the number of output channels in the output tensor.

kernel_size (int, optional): the size of the kernel in the output tensor. If not provided, region_offset should be RegionType.CUSTOM and region_offset should be a 2D matrix with size \(N\times D\) such that it lists all \(N\) offsets in D-dimension.

stride (int, or list, optional): stride size that defines upsampling rate. If non-identity is used, the output coordinates will be tensor_stride / stride apart. When a list is given, the length must be D; each element will be used for stride size for the specific axis.

dilation (int, or list, optional): dilation size for the convolution kernel. When a list is given, the length must be D and each element is an axis specific dilation. All elements must be > 0.

bias (bool, optional): if True, the convolution layer has a bias.

kernel_generator (MinkowskiEngine.KernelGenerator, optional): defines custom kernel shape.

expand_coordinates (bool, optional): Force generation of new coordinates. When True, the output coordinates will be the outer product of the kernel shape and the input coordinates. False by default.

dimension (int): the spatial dimension of the space where all the inputs and the network are defined. For example, images are in a 2D space, meshes and 3D shapes are in a 3D space.

cpu() → T

Moves all model parameters and buffers to the CPU.

Returns:

Module: self

cuda(device: Optional[Union[int, torch.device]] = None) → T

Moves all model parameters and buffers to the GPU.

This also makes associated parameters and buffers different objects. So it should be called before constructing optimizer if the module will live on GPU while being optimized.

Arguments:
device (int, optional): if specified, all parameters will be

copied to that device

Returns:

Module: self

double() → T

Casts all floating point parameters and buffers to double datatype.

Returns:

Module: self

float() → T

Casts all floating point parameters and buffers to float datatype.

Returns:

Module: self

forward(input: MinkowskiSparseTensor.SparseTensor, coordinates: Optional[Union[torch.Tensor, MinkowskiEngineBackend._C.CoordinateMapKey, MinkowskiSparseTensor.SparseTensor]] = None)

input (MinkowskiEngine.SparseTensor): Input sparse tensor to apply a convolution on.

coordinates ((torch.IntTensor, MinkowskiEngine.CoordinateMapKey, MinkowskiEngine.SparseTensor), optional): If provided, generate results on the provided coordinates. None by default.

to(*args, **kwargs)

Moves and/or casts the parameters and buffers.

This can be called as

to(device=None, dtype=None, non_blocking=False)
to(dtype, non_blocking=False)
to(tensor, non_blocking=False)
to(memory_format=torch.channels_last)

Its signature is similar to torch.Tensor.to(), but only accepts floating point desired dtype s. In addition, this method will only cast the floating point parameters and buffers to dtype (if given). The integral parameters and buffers will be moved device, if that is given, but with dtypes unchanged. When non_blocking is set, it tries to convert/move asynchronously with respect to the host if possible, e.g., moving CPU Tensors with pinned memory to CUDA devices.

See below for examples.

Note

This method modifies the module in-place.

Args:
device (torch.device): the desired device of the parameters

and buffers in this module

dtype (torch.dtype): the desired floating point type of

the floating point parameters and buffers in this module

tensor (torch.Tensor): Tensor whose dtype and device are the desired

dtype and device for all parameters and buffers in this module

memory_format (torch.memory_format): the desired memory

format for 4D parameters and buffers in this module (keyword only argument)

Returns:

Module: self

Example:

>>> linear = nn.Linear(2, 2)
>>> linear.weight
Parameter containing:
tensor([[ 0.1913, -0.3420],
        [-0.5113, -0.2325]])
>>> linear.to(torch.double)
Linear(in_features=2, out_features=2, bias=True)
>>> linear.weight
Parameter containing:
tensor([[ 0.1913, -0.3420],
        [-0.5113, -0.2325]], dtype=torch.float64)
>>> gpu1 = torch.device("cuda:1")
>>> linear.to(gpu1, dtype=torch.half, non_blocking=True)
Linear(in_features=2, out_features=2, bias=True)
>>> linear.weight
Parameter containing:
tensor([[ 0.1914, -0.3420],
        [-0.5112, -0.2324]], dtype=torch.float16, device='cuda:1')
>>> cpu = torch.device("cpu")
>>> linear.to(cpu)
Linear(in_features=2, out_features=2, bias=True)
>>> linear.weight
Parameter containing:
tensor([[ 0.1914, -0.3420],
        [-0.5112, -0.2324]], dtype=torch.float16)
type(dst_type: Union[torch.dtype, str]) → T

Casts all parameters and buffers to dst_type.

Arguments:

dst_type (type or string): the desired type

Returns:

Module: self

MinkowskiGenerativeConvolutionTranspose

class MinkowskiEngine.MinkowskiGenerativeConvolutionTranspose(in_channels, out_channels, kernel_size=-1, stride=1, dilation=1, bias=False, kernel_generator=None, convolution_mode=<ConvolutionMode.DEFAULT: 0>, dimension=None)

A generalized sparse transposed convolution or deconvolution layer that generates new coordinates.

__init__(in_channels, out_channels, kernel_size=-1, stride=1, dilation=1, bias=False, kernel_generator=None, convolution_mode=<ConvolutionMode.DEFAULT: 0>, dimension=None)

a generalized sparse transposed convolution layer that creates new coordinates.

Please refer to Generative Sparse Detection Networks for 3D Single-shot Object Detection for more detail. Also, please cite the following paper if you use this function.

>> @inproceedings{gwak2020gsdn, >> title={Generative Sparse Detection Networks for 3D Single-shot Object Detection}, >> author={Gwak, JunYoung and Choy, Christopher B and Savarese, Silvio}, >> booktitle={European conference on computer vision}, >> year={2020} >> }

Args:

in_channels (int): the number of input channels in the input tensor.

out_channels (int): the number of output channels in the output tensor.

kernel_size (int, optional): the size of the kernel in the output tensor. If not provided, region_offset should be RegionType.CUSTOM and region_offset should be a 2D matrix with size \(N\times D\) such that it lists all \(N\) offsets in D-dimension.

stride (int, or list, optional): stride size that defines upsampling rate. If non-identity is used, the output coordinates will be tensor_stride / stride apart. When a list is given, the length must be D; each element will be used for stride size for the specific axis.

dilation (int, or list, optional): dilation size for the convolution kernel. When a list is given, the length must be D and each element is an axis specific dilation. All elements must be > 0.

bias (bool, optional): if True, the convolution layer has a bias.

kernel_generator (MinkowskiEngine.KernelGenerator, optional): defines custom kernel shape.

expand_coordinates (bool, optional): Force generation of new coordinates. When True, the output coordinates will be the outer product of the kernel shape and the input coordinates. False by defaul.

dimension (int): the spatial dimension of the space where all the inputs and the network are defined. For example, images are in a 2D space, meshes and 3D shapes are in a 3D space.

cpu() → T

Moves all model parameters and buffers to the CPU.

Returns:

Module: self

cuda(device: Optional[Union[int, torch.device]] = None) → T

Moves all model parameters and buffers to the GPU.

This also makes associated parameters and buffers different objects. So it should be called before constructing optimizer if the module will live on GPU while being optimized.

Arguments:
device (int, optional): if specified, all parameters will be

copied to that device

Returns:

Module: self

double() → T

Casts all floating point parameters and buffers to double datatype.

Returns:

Module: self

float() → T

Casts all floating point parameters and buffers to float datatype.

Returns:

Module: self

forward(input: MinkowskiSparseTensor.SparseTensor, coordinates: Optional[Union[torch.Tensor, MinkowskiEngineBackend._C.CoordinateMapKey, MinkowskiSparseTensor.SparseTensor]] = None)

input (MinkowskiEngine.SparseTensor): Input sparse tensor to apply a convolution on.

coordinates ((torch.IntTensor, MinkowskiEngine.CoordinateMapKey, MinkowskiEngine.SparseTensor), optional): If provided, generate results on the provided coordinates. None by default.

to(*args, **kwargs)

Moves and/or casts the parameters and buffers.

This can be called as

to(device=None, dtype=None, non_blocking=False)
to(dtype, non_blocking=False)
to(tensor, non_blocking=False)
to(memory_format=torch.channels_last)

Its signature is similar to torch.Tensor.to(), but only accepts floating point desired dtype s. In addition, this method will only cast the floating point parameters and buffers to dtype (if given). The integral parameters and buffers will be moved device, if that is given, but with dtypes unchanged. When non_blocking is set, it tries to convert/move asynchronously with respect to the host if possible, e.g., moving CPU Tensors with pinned memory to CUDA devices.

See below for examples.

Note

This method modifies the module in-place.

Args:
device (torch.device): the desired device of the parameters

and buffers in this module

dtype (torch.dtype): the desired floating point type of

the floating point parameters and buffers in this module

tensor (torch.Tensor): Tensor whose dtype and device are the desired

dtype and device for all parameters and buffers in this module

memory_format (torch.memory_format): the desired memory

format for 4D parameters and buffers in this module (keyword only argument)

Returns:

Module: self

Example:

>>> linear = nn.Linear(2, 2)
>>> linear.weight
Parameter containing:
tensor([[ 0.1913, -0.3420],
        [-0.5113, -0.2325]])
>>> linear.to(torch.double)
Linear(in_features=2, out_features=2, bias=True)
>>> linear.weight
Parameter containing:
tensor([[ 0.1913, -0.3420],
        [-0.5113, -0.2325]], dtype=torch.float64)
>>> gpu1 = torch.device("cuda:1")
>>> linear.to(gpu1, dtype=torch.half, non_blocking=True)
Linear(in_features=2, out_features=2, bias=True)
>>> linear.weight
Parameter containing:
tensor([[ 0.1914, -0.3420],
        [-0.5112, -0.2324]], dtype=torch.float16, device='cuda:1')
>>> cpu = torch.device("cpu")
>>> linear.to(cpu)
Linear(in_features=2, out_features=2, bias=True)
>>> linear.weight
Parameter containing:
tensor([[ 0.1914, -0.3420],
        [-0.5112, -0.2324]], dtype=torch.float16)
type(dst_type: Union[torch.dtype, str]) → T

Casts all parameters and buffers to dst_type.

Arguments:

dst_type (type or string): the desired type

Returns:

Module: self