KPConv
KPConv classification and segmentation models.

Classes:
-
KPConvβKernel point convolution over a neighborhood graph.
-
KPConvBlockβKernel point convolution followed by normalization and activation.
-
KPResidualBlockβBottleneck residual block: a channel-reducing MLP, a
KPConvBlock, and a channel-restoring MLP. -
KPFCNNGridPoolβVoxel grid subsampling: points falling in the same cell are reduced to a single point.
-
KPFCNNEncoderBlockβOne encoder stage: an optional grid subsampling followed by
depthKPResidualBlockblocks. -
KPFCNNEncoderβKP-FCNN encoder:
KPFCNNEncoderBlockstages from finest to coarsest, every stage but the first preceded by a -
KPFCNNClassificationβKPConv Network for classification tasks as described in the paper
-
KPFCNNSegmentationβKPConv Network for segmentation tasks as described in the paper
Functions:
-
create_kernel_pointsβBuilds the kernel point positions of a KPConv kernel, randomly rotated and jittered.
KPConv
¶
KPConv(
spatial_dim: int,
in_channels: int,
out_channels: int,
kernel_size: int,
kp_radius: float,
kp_sigma: float,
kp_influence: str = "linear",
fixed_position: Literal[
"none", "center", "vertical"
] = "center",
aggregation_mode: str = "sum",
deformable: bool = False,
modulated: bool = False,
bias: bool = False,
track_running_stats: bool = True,
)
Bases: Module
Kernel point convolution over a neighborhood graph.
Each of the \(K\) kernel points carries its own weight matrix, and a neighbor contributes to a kernel point
with a weight given by their distance through the influence function. When deformable is set, a nested
KPConv predicts a per-point offset for every kernel point.
Parameters:
-
spatial_dim(int) βSpatial dimension of the input point cloud.
-
in_channels(int) βNumber of input channels.
-
out_channels(int) βNumber of output channels.
-
kernel_size(int) βNumber of kernel points \(K\).
-
kp_radius(float) βRadius of the sphere the kernel points are placed on.
-
kp_sigma(float) βKernel extent, the distance over which a kernel point still influences a neighbor.
-
kp_influence(str, default:'linear') βInfluence function:
"constant","linear", or"gaussian". -
fixed_position(Literal['none', 'center', 'vertical'], default:'center') βWhich kernel point is pinned:
"none","center", or"vertical". -
aggregation_mode(str, default:'sum') β"sum"over all kernel points, or"closest"to keep only the nearest one. -
deformable(bool, default:False) βWhether to predict per-point kernel offsets.
-
modulated(bool, default:False) βWhether the deformable branch also predicts a per-kernel-point modulation.
-
bias(bool, default:False) βWhether to add a bias to the output.
-
track_running_stats(bool, default:True) βWhether to keep the deformable activations of the last forward pass, for regularization.
Methods:
-
configure_offsetsβBuilds the rigid
KPConvand the bias predicting the deformable offsets (and modulations). -
configure_kernelβBuilds the fixed kernel point positions registered as the
kernelbuffer.
Attributes:
-
deformable(bool) βWhether the kernel points are shifted by predicted per-point offsets.
KPConvBlock
¶
KPConvBlock(
spatial_dim: int,
in_channels: int,
out_channels: int,
kernel_size: int,
kp_radius: float,
kp_sigma: float,
kp_influence: str = "linear",
fixed_position: Literal[
"none", "center", "vertical"
] = "center",
aggregation_mode: str = "sum",
deformable: bool = False,
modulated: bool = False,
act: Union[str, Callable, None] = "leaky_relu",
act_kwargs: Optional[Dict[str, Any]] = None,
norm: Union[str, Callable, None] = "batch_norm",
norm_kwargs: Optional[Dict[str, Any]] = None,
bias: bool = False,
)
Bases: Module
Kernel point convolution followed by normalization and activation.
KPResidualBlock
¶
KPResidualBlock(
spatial_dim: int,
in_channels: int,
out_channels: int,
kernel_size: int,
kp_radius: float,
kp_sigma: float,
kp_influence: str = "linear",
fixed_position: Literal[
"none", "center", "vertical"
] = "center",
aggregation_mode: str = "sum",
deformable: bool = False,
modulated: bool = False,
strided: bool = False,
act: Union[str, Callable, None] = "leaky_relu",
act_kwargs: Optional[Dict[str, Any]] = None,
act_first: bool = False,
norm: Union[str, Callable, None] = "batch_norm",
norm_kwargs: Optional[Dict[str, Any]] = None,
bias: bool = False,
)
Bases: Module
Bottleneck residual block: a channel-reducing MLP, a KPConvBlock, and a channel-restoring MLP.
Set strided=True when the block maps a support cloud onto a coarser query cloud, so that the skip
connection is max-pooled over the same neighborhoods.
KPFCNNGridPool
¶
Bases: Module
Voxel grid subsampling: points falling in the same cell are reduced to a single point.
Positions are averaged within a cell while features use the reduce operation.
KPFCNNEncoderBlock
¶
KPFCNNEncoderBlock(
*,
depth: int,
radius: float,
pool_radius: Optional[float] = None,
max_num_neighbors: int,
spatial_dim: int,
in_channels: int,
out_channels: int,
kernel_size: int,
kp_radius: Union[float, Sequence[float]],
kp_sigma: Union[float, Sequence[float]],
kp_influence: str = "linear",
fixed_position: Literal[
"none", "center", "vertical"
] = "center",
aggregation_mode: str = "sum",
deformable: Union[bool, Sequence[bool]] = False,
modulated: Union[bool, Sequence[bool]] = False,
bias: bool = False,
act: Union[str, Callable, None] = "leaky_relu",
act_kwargs: Optional[Dict[str, Any]] = None,
act_first: bool = False,
norm: Union[str, Callable, None] = "batch_norm",
norm_kwargs: Optional[Dict[str, Any]] = None,
downsample: Optional[KPFCNNGridPool] = None,
)
Bases: Module
One encoder stage: an optional grid subsampling followed by depth KPResidualBlock blocks.
Neighborhoods are recomputed once at the stage entry, using pool_radius for the strided first block
and radius for the remaining ones.
Parameters:
-
downsample(Optional[KPFCNNGridPool], default:None) βGrid pooling applied before the first block. Makes that block strided.
KPFCNNEncoder
¶
KPFCNNEncoder(
in_channels: int,
*,
depths: Sequence[int],
grid_sizes: Sequence[float],
radii: Sequence[float],
channels: Sequence[int],
max_num_neighbors: Sequence[int],
kernel_size: int,
kp_sigma: Union[float, Sequence[float]],
kp_radius: Union[float, Sequence[float]],
kp_influence: str = "linear",
fixed_position: Literal[
"none", "center", "vertical"
] = "center",
aggregation_mode: str = "sum",
deformable: Union[bool, Sequence] = False,
modulated: Union[bool, Sequence] = False,
act: Union[str, Callable, None] = "leaky_relu",
act_kwargs: Optional[Dict[str, Any]] = None,
act_first: bool = False,
norm: Union[str, Callable, None] = "batch_norm",
norm_kwargs: Optional[Dict[str, Any]] = None,
bias: bool = False,
spatial_dim: int = 3,
)
Bases: Module
KP-FCNN encoder: KPFCNNEncoderBlock stages from finest to coarsest, every stage but the first preceded by a
KPFCNNGridPool subsampling.
Parameters:
-
in_channels(int) βNumber of channels entering the first stage.
-
depths(Sequence[int]) βNumber of residual blocks in each stage.
-
grid_sizes(Sequence[float]) βGrid size of each downsampling step, one per stage transition.
-
radii(Sequence[float]) βNeighborhood search radius of each stage.
-
channels(Sequence[int]) βOutput channels of each stage.
-
max_num_neighbors(Sequence[int]) βMaximum number of neighbors queried at each stage.
-
kernel_size(int) βNumber of kernel points of every KPConv.
-
kp_sigma(Union[float, Sequence[float]]) βKernel extent of each stage.
-
kp_radius(Union[float, Sequence[float]]) βKernel point radius of each stage.
-
kp_influence(str, default:'linear') βInfluence function:
"constant","linear", or"gaussian". -
fixed_position(Literal['none', 'center', 'vertical'], default:'center') βWhich kernel point is pinned:
"none","center", or"vertical". -
aggregation_mode(str, default:'sum') β"sum"over all kernel points, or"closest"to keep only the nearest one. -
deformable(Union[bool, Sequence], default:False) βWhether each stage uses deformable kernels.
-
modulated(Union[bool, Sequence], default:False) βWhether each stage uses modulated deformable kernels.
-
act(Union[str, Callable, None], default:'leaky_relu') βActivation function.
-
act_kwargs(Optional[Dict[str, Any]], default:None) βOptional keyword arguments for the activation factory.
-
act_first(bool, default:False) βWhether the activation comes before the normalization in the MLPs.
-
norm(Union[str, Callable, None], default:'batch_norm') βNormalization layer.
-
norm_kwargs(Optional[Dict[str, Any]], default:None) βOptional keyword arguments for the normalization factory.
-
bias(bool, default:False) βWhether the convolutions and MLPs use a bias.
-
spatial_dim(int, default:3) βSpatial dimension of the input point cloud.
Inputs
x: Point features of shape \((N, \text{in\_channels})\). pos: Point coordinates of shape \((N, D)\). batch: Batch indices of shape \((N,)\).
Outputs
Features, coordinates and batch indices at the coarsest stage. With return_intermediates=True, also one
skip per downsampled stage: the features, coordinates, batch indices and pooling inverse entering that stage.
KPFCNNClassification
¶
KPFCNNClassification(
in_channels: int,
num_classes: int,
*,
spatial_dim: int = 3,
stem_channels: Optional[int] = None,
stem_type: Literal["linear", "kpconv"] = "kpconv",
encoder_depths: Sequence[int],
encoder_channels: Sequence[int],
encoder_num_neighbors: Sequence[int],
grid_sizes: Sequence[float],
radii: Sequence[float],
kernel_size: int,
kp_radius: Union[float, Sequence[float]],
kp_sigma: Union[float, Sequence[float]],
kp_influence: str = "linear",
fixed_position: Literal[
"none", "center", "vertical"
] = "center",
aggregation_mode: str = "sum",
deformable: Union[bool, Sequence] = False,
modulated: Union[bool, Sequence] = False,
act: Union[str, Callable, None] = "leaky_relu",
act_kwargs: Optional[Dict[str, Any]] = None,
act_first: bool = False,
norm: Union[str, Callable, None] = "batch_norm",
norm_kwargs: Optional[Dict[str, Any]] = None,
bias: bool = False,
dropout: float = 0.0,
global_pool: PoolLike = "max",
)
Bases: ClassificationModel
KPConv Network for classification tasks as described in the paper KPConv: Flexible and Efficient Convolution for Point Clouds by Hugues Thomas, Charles R. Qi, Jean-Emmanuel Deschaud, Beatriz Marcotegui, FranΓ§ois Goulette, Leonidas J. Guibas.
KPConv introduces a novel point convolution operator that uses kernel points to define the spatial extent and weights of the convolution. The kernel points are arranged in space to define the convolution pattern, with weights determined by their spatial correlation with input points. This allows for flexible and efficient convolution on irregular point clouds while maintaining permutation invariance and translation invariance. The network uses a hierarchical architecture with strided convolutions for spatial pooling and feature aggregation.
Note
The implementation is based on the original paper and the authors' code KPConv-PyTorch.
Important
This implementation was completely rewritten to be compatible with
torch-geometric library.
Parameters:
-
in_channels(int) βNumber of input channels.
-
num_classes(int) βNumber of output classes.
-
spatial_dim(int, default:3) βSpatial dimension of the input point cloud.
-
stem_channels(Optional[int], default:None) βNumber of channels in the stem layer.
-
stem_type(Literal['linear', 'kpconv'], default:'kpconv') βType of stem layer to use.
-
encoder_depths(Sequence[int]) βList of depths for each encoder block, i.e. corresponds to the number of residual blocks at each level.
-
encoder_channels(Sequence[int]) βList of channels for each encoder block.
-
encoder_num_neighbors(Sequence[int]) βList of maximum number of neighbors for each encoder block.
-
grid_sizes(Sequence[float]) βList of grid sizes for each downsampling block.
-
radii(Sequence[float]) βSearch radius for each downsampling block.
-
kernel_size(int) βSize of the kernel for each KPConv block.
-
kp_radius(Union[float, Sequence[float]]) βList of kernel radius for KPConv blocks, at each level.
-
kp_sigma(Union[float, Sequence[float]]) βList of kernel extent for KPConv blocks, at each level.
-
kp_influence(str, default:'linear') βInfluence function to use for KPConv blocks. Options are "constant", "linear", "gaussian".
-
fixed_position(Literal['none', 'center', 'vertical'], default:'center') βWhether to fix the position of the kernel points in KPConv blocks. Options are "none", "center", "vertical".
-
aggregation_mode(str, default:'sum') βAggregation mode to use for the KPConv blocks. Options are "sum", "mean", "max".
-
deformable(Union[bool, Sequence], default:False) βWhether to use a deformable kernel for the KPConv blocks.
-
modulated(Union[bool, Sequence], default:False) βWhether to use a modulated kernel in KPConv operation.
-
norm(Union[str, Callable, None], default:'batch_norm') βNormalization to use for the KPConv blocks.
-
act(Union[str, Callable, None], default:'leaky_relu') βActivation function to use for the KPConv blocks.
-
bias(bool, default:False) βWhether to use a bias for the KPConv blocks.
-
dropout(float, default:0.0) βDropout rate before the classification head.
-
global_pool(PoolLike, default:'max') βGlobal pooling method to use before the classification head. Options are "max", "mean".
Methods:
-
configure_stemβBuild the stem lifting the input features to
stem_channels, orNonewhenstem_channelsis unset. -
configure_encoderβBuild the
KPFCNNEncoderbackbone. -
reset_classifierβResets the classification head with new parameters.
-
forward_featuresβForward pass of the encoder, returning pre-pooling features.
-
forward_headβForward pass of the classification head from pre-pooling features.
-
forwardβForward pass of the classification model.
Attributes:
-
num_features(int) βFeature dimension \(C\) of the encoder output.
configure_stem
¶
Build the stem lifting the input features to stem_channels, or None when stem_channels is unset.
reset_classifier
¶
reset_classifier(
num_classes: int,
global_pool: Optional[PoolLike] = None,
**kwargs: Any,
) -> None
Resets the classification head with new parameters.
Note
To set an empty classification head, use num_classes=0.
Parameters:
-
num_classes(int) βNumber of output classes.
-
global_pool(Optional[PoolLike], default:None) βPooling method to aggregate point features ("max" or "mean"). If
None, keeps the current pooling. -
**kwargs(Any, default:{}) βAdditional keyword arguments to pass to the classification head.
forward_features
¶
forward_features(
x: OptTensor,
pos: Tensor,
batch: Tensor,
return_intermediates: bool = False,
) -> Any
Forward pass of the encoder, returning pre-pooling features.
Parameters:
-
x(OptTensor) βPoint features of shape \((N, C)\). If
None,posis used as features, which requiresin_channelsto match the dimension ofpos. -
pos(Tensor) βPoint coordinates of shape \((N, D)\).
-
batch(Tensor) βBatch indices for each point of shape \((N,)\).
-
return_intermediates(bool, default:False) βWhether to also return the per-stage intermediates.
Returns:
-
AnyβA tuple
(x, pos, batch)at the coarsest level, wherexhas shape \((N', \text{encoder\_channels}[-1])\) and \(N'\) is the number of downsampled points. Ifreturn_intermediates=True, the per-stage intermediates are appended to the tuple.
forward_head
¶
Forward pass of the classification head from pre-pooling features.
Parameters:
-
x(Tensor) βPre-pooling features of shape \((N', \text{encoder\_channels}[-1])\) where \(N'\) is the number of downsampled points.
-
batch(Tensor) βBatch indices for each downsampled point of shape \((N',)\).
-
pre_logits(bool, default:False) βWhether to return pre-logits. Defaults to False.
Returns:
-
TensorβClassification logits of shape \((B, \text{num\_classes})\).
forward
¶
Forward pass of the classification model.
Parameters:
-
x(OptTensor) βPoint features of shape \((N, C)\). If
None,posis used as features, which requiresin_channelsto match the dimension ofpos. -
pos(Tensor) βPoint coordinates of shape \((N, D)\).
-
batch(Tensor) βBatch indices for each point of shape \((N,)\).
Returns:
-
TensorβClassification logits of shape \((B, \text{num\_classes})\).
KPFCNNSegmentation
¶
KPFCNNSegmentation(
in_channels: int,
num_classes: int,
*,
spatial_dim: int = 3,
stem_channels: Optional[int] = None,
stem_type: Literal["linear", "kpconv"] = "kpconv",
encoder_depths: Sequence[int],
encoder_channels: Sequence[int],
encoder_num_neighbors: Sequence[int],
fp_channels: Sequence[Sequence[int]],
grid_sizes: Sequence[float],
radii: Sequence[float],
kernel_size: int,
kp_radius: Union[float, Sequence[float]],
kp_sigma: Union[float, Sequence[float]],
kp_influence: str = "linear",
fixed_position: Literal[
"none", "center", "vertical"
] = "center",
aggregation_mode: str = "sum",
deformable: Union[bool, Sequence] = False,
modulated: Union[bool, Sequence] = False,
act: Union[str, Callable, None] = "leaky_relu",
act_kwargs: Optional[Dict[str, Any]] = None,
act_first: bool = False,
norm: Union[str, Callable, None] = "batch_norm",
norm_kwargs: Optional[Dict[str, Any]] = None,
bias: bool = False,
dropout: float = 0.0,
head_channels: Optional[Sequence[int]] = None,
)
Bases: SegmentationModel
KPConv Network for segmentation tasks as described in the paper KPConv: Flexible and Efficient Convolution for Point Clouds by Hugues Thomas, Charles R. Qi, Jean-Emmanuel Deschaud, Beatriz Marcotegui, FranΓ§ois Goulette, Leonidas J. Guibas.
KPConv introduces a novel point convolution operator that uses kernel points to define the spatial extent and weights of the convolution. The kernel points are arranged in space to define the convolution pattern, with weights determined by their spatial correlation with input points. This allows for flexible and efficient convolution on irregular point clouds while maintaining permutation invariance and translation invariance. The network uses a hierarchical architecture with strided convolutions for spatial pooling and feature aggregation.
Note
The implementation is based on the original paper and the authors' code KPConv-PyTorch.
Important
This implementation was completely rewritten to be compatible with
torch-geometric library.
Parameters:
-
in_channels(int) βNumber of input channels.
-
num_classes(int) βNumber of output classes.
-
spatial_dim(int, default:3) βSpatial dimension of the input point cloud.
-
stem_channels(Optional[int], default:None) βNumber of channels in the stem layer.
-
stem_type(Literal['linear', 'kpconv'], default:'kpconv') βType of stem layer to use.
-
encoder_depths(Sequence[int]) βList of depths for each encoder block, i.e. corresponds to the number of residual blocks at each level.
-
encoder_channels(Sequence[int]) βList of channels for each encoder block.
-
encoder_num_neighbors(Sequence[int]) βList of maximum number of neighbors for each encoder block.
-
fp_channels(Sequence[Sequence[int]]) βList of channels for each feature propagation block.
-
grid_sizes(Sequence[float]) βList of grid sizes for each downsampling block.
-
radii(Sequence[float]) βSearch radius for each downsampling block.
-
kernel_size(int) βSize of the kernel for each KPConv block.
-
kp_radius(Union[float, Sequence[float]]) βList of kernel radius for KPConv blocks, at each level.
-
kp_sigma(Union[float, Sequence[float]]) βList of kernel extent for KPConv blocks, at each level.
-
kp_influence(str, default:'linear') βInfluence function to use for KPConv blocks. Options are "constant", "linear", "gaussian".
-
fixed_position(Literal['none', 'center', 'vertical'], default:'center') βWhether to fix the position of the kernel points in KPConv blocks. Options are "none", "center", "vertical".
-
aggregation_mode(str, default:'sum') βAggregation mode to use for the KPConv blocks. Options are "sum", "mean", "max".
-
deformable(Union[bool, Sequence], default:False) βWhether to use a deformable kernel for the KPConv blocks.
-
modulated(Union[bool, Sequence], default:False) βWhether to use a modulated kernel in KPConv operation.
-
norm(Union[str, Callable, None], default:'batch_norm') βNormalization to use for the KPConv blocks.
-
act(Union[str, Callable, None], default:'leaky_relu') βActivation function to use for the KPConv blocks.
-
bias(bool, default:False) βWhether to use a bias for the KPConv blocks.
-
dropout(float, default:0.0) βDropout rate before the classification head.
Methods:
-
configure_stemβBuild the stem lifting the input features to
stem_channels, orNonewhenstem_channelsis unset. -
configure_encoderβBuild the
KPFCNNEncoderbackbone. -
configure_decoderβBuild the
PointNet2Decoderupsampling the coarsest features back through the encoder skips.
Attributes:
-
num_features(int) βFeature dimension \(C\) of the decoder output.
configure_stem
¶
Build the stem lifting the input features to stem_channels, or None when stem_channels is unset.
configure_decoder
¶
configure_decoder() -> PointNet2Decoder
Build the PointNet2Decoder upsampling the coarsest features back through the encoder skips.
create_kernel_points
¶
create_kernel_points(
radius: float,
num_points: int,
fixed_position: Literal[
"none", "center", "vertical"
] = "center",
method: Literal["lloyd", "gradient"] = "lloyd",
) -> Tensor
Builds the kernel point positions of a KPConv kernel, randomly rotated and jittered.
Positions are optimized on the unit sphere, cached under CACHE_DIR and reused across calls.
Parameters:
-
radius(float) βRadius of the sphere the kernel points are scaled to.
-
num_points(int) βNumber of kernel points \(K\).
-
fixed_position(Literal['none', 'center', 'vertical'], default:'center') βWhich kernel point is pinned:
"none","center", or"vertical". -
method(Literal['lloyd', 'gradient'], default:'lloyd') βOptimization used to spread the points, either
"lloyd"or"gradient".
Returns:
-
TensorβKernel point positions of shape \((K, 3)\).