open3d.ml.torch.layers.SparseConv#
- class open3d.ml.torch.layers.SparseConv(in_channels, filters, kernel_size, activation=None, use_bias=True, kernel_initializer=<function SparseConv.<lambda>>, bias_initializer=<function zeros_>, normalize=False, offset=None, **kwargs)#
Sparse Convolution.
This layer computes a convolution which is only evaluated at the specified output positions. The layer assumes that input and output points lie on a regular grid.
Example
This shows a minimal example of how to use the layer:
import torch import open3d.ml.torch as ml3d # +0.5 to move the points to the voxel center inp_positions = torch.randint(0, 10, [20,3]).to(torch.float32)+0.5 inp_features = torch.randn([20,8]) out_positions = torch.randint(0, 10, [20,3]).to(torch.float32)+0.5 conv = ml3d.layers.SparseConv(in_channels=8, filters=16, kernel_size=[3,3,3]) out_features = conv(inp_features, inp_positions, out_positions, voxel_size=1.0)
- Parameters:
in_channels – The number of input channels.
filters – The number of filters/output channels.
kernel_size – The spatial resolution of the filter, e.g. [3,3,3].
activation – The activation function to use. None means no activation.
use_bias – If True adds an additive bias vector.
kernel_initializer – Initializer for the kernel weights.
bias_initializer – Initializer for the bias vector.
normalize – If true then the result is normalized by the number of input points.
offset – A single 3D vector used in the filter coordinate computation. The shape is [3]. This can be used to control how the filters are centered. It will be set automatically for kernels with even sizes.
- __init__(in_channels, filters, kernel_size, activation=None, use_bias=True, kernel_initializer=<function SparseConv.<lambda>>, bias_initializer=<function zeros_>, normalize=False, offset=None, **kwargs)#
Initializes internal Module state, shared by both nn.Module and ScriptModule.
- forward(inp_features, inp_positions, out_positions, voxel_size, inp_importance=None, fixed_radius_search_hash_table=None)#
This function computes the output features.
- Parameters:
inp_features – A 2D tensor which stores a feature vector for each input point.
inp_positions – A 2D tensor with the 3D point positions of each input point. The coordinates for each point is a vector with format [x,y,z].
out_positions – A 2D tensor with the 3D point positions of each output point. The coordinates for each point is a vector with format [x,y,z].
voxel_size – A scalar float that defines the edge length of a voxel.
inp_importance – Optional scalar importance value for each input point.
fixed_radius_search_hash_table – A precomputed hash table generated with build_spatial_hash_table(). This input can be used to explicitly force the reuse of a hash table in special cases and is usually not needed. Note that the hash table must have been generated with the same ‘points’ array. Note that this parameter is only used if ‘extents’ is a scalar.
- Returns: A tensor of shape [num output points, filters] with the output
features.
- training: bool#