Skip to content

kpconv

Fitting and repulsive regularizer of deformable kernel point convolutions.

Classes:

KPConvDeformRegularizer [source] ΒΆ

KPConvDeformRegularizer(
    fitting_power: float = 1.0, repulse_extent: float = 1.0
)

Bases: Module

Module form of kpconv_deform_regularizer.

Parameters:

  • fitting_power (float, default: 1.0 ) –

    Weight of the whole term.

  • repulse_extent (float, default: 1.0 ) –

    Distance, in units of kp_sigma, below which kernel points repel each other.

Example
import torch
from torch_pointcloud.layers import KPConv
from torch_pointcloud.losses import KPConvDeformRegularizer
conv = KPConv(spatial_dim=3, in_channels=4, out_channels=8, kernel_size=15, kp_radius=1.0, kp_sigma=1.0, deformable=True)
pos = torch.rand(32, 3)
edge_index = torch.stack([torch.arange(32).repeat_interleave(4), torch.randint(0, 32, (128,))])
out = conv(torch.randn(32, 4), pos, edge_index)
KPConvDeformRegularizer(repulse_extent=1.2)(conv).shape  # torch.Size([])

kpconv_deform_regularizer [source] ΒΆ

kpconv_deform_regularizer(
    module: Module,
    fitting_power: float = 1.0,
    repulse_extent: float = 1.0,
) -> Tensor

Regularize the deformed kernel points of every deformable KPConv in module.

The point-to-point regularizer of KPConv: Flexible and Deformable Convolution for Point Clouds (Thomas et al., 2019): a fitting term pulls every deformed kernel point towards its closest input point, a repulsive term keeps the kernel points of one location further apart than repulse_extent. Both read the statistics the layers keep from their last forward pass (running_min_d2, running_deformed_kernel), so call it after the forward and before the backward of the same batch. Distances are expressed in units of each layer's kp_sigma.

Parameters:

  • module (Module) –

    Model holding the KPConv layers.

  • fitting_power (float, default: 1.0 ) –

    Weight of the whole term.

  • repulse_extent (float, default: 1.0 ) –

    Distance, in units of kp_sigma, below which kernel points repel each other.

Returns:

  • Tensor –

    A scalar, fitting_power * (2 * fitting + repulsive) summed over the deformable layers, zero when

  • Tensor –

    module has none.

Example
>>> import torch
>>> from torch_pointcloud.layers import KPConv
>>> from torch_pointcloud.losses import kpconv_deform_regularizer
>>> conv = KPConv(spatial_dim=3, in_channels=4, out_channels=8, kernel_size=15, kp_radius=1.0, kp_sigma=1.0, deformable=True)
>>> pos = torch.rand(32, 3)
>>> edge_index = torch.stack([torch.arange(32).repeat_interleave(4), torch.randint(0, 32, (128,))])
>>> out = conv(torch.randn(32, 4), pos, edge_index)
>>> kpconv_deform_regularizer(conv).shape
torch.Size([])