Skip to content

pointnet2_blocks

PointNet++ grouping convolution, set abstraction and feature propagation blocks.

Classes:

PointNet2Conv [source] ΒΆ

PointNet2Conv(
    local_nn: Module,
    add_self_loops: bool = True,
    use_pos: bool = True,
    pos_first: bool = False,
    pos_scale: Optional[float] = None,
    **kwargs: Unpack[MessagePassingParams],
)

Bases: MessagePassing

PointNet++ grouping convolution on top of PyG's MessagePassing.

Each message combines the neighbor features \(x_j\) with the relative position \(p_j - p_i\) and applies local_nn; the messages of each centroid are then aggregated (aggr, max by default).

Parameters:

  • local_nn (Module) –

    Network applied to each message of shape \((E, C + D)\), or \((E, C)\) when use_pos is false.

  • add_self_loops (bool, default: True ) –

    Whether to add self-loops to the edge index.

  • use_pos (bool, default: True ) –

    Concatenate the relative position \(p_j - p_i\) to the neighbor features.

  • pos_first (bool, default: False ) –

    Concatenate the relative position before the features (cat([p_j - p_i, x_j])) instead of after.

  • pos_scale (Optional[float], default: None ) –

    Divide the relative position by this value, e.g. the ball-query radius to normalize it.

  • **kwargs (Unpack[MessagePassingParams], default: {} ) –

    Additional MessagePassing arguments (aggr defaults to "max").

PointNet2SetAbstraction [source] ΒΆ

PointNet2SetAbstraction(
    in_channels: int,
    channels: Sequence[Union[int, Sequence[int]]],
    *,
    ratio: Optional[float] = None,
    num_points: Optional[int] = None,
    radii: Union[float, Sequence[float]],
    num_neighbors: Union[int, Sequence[int]],
    spatial_dim: int = 3,
    dropout: float = 0.0,
    act: Union[str, Callable, None] = "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,
    use_pos: bool = True,
    normalize_pos: bool = True,
    pos_first: bool = False,
    aggr: AggrType = "max",
    sort_neighbors: bool = False,
)

Bases: Module

Set-abstraction block (PointNet++ SSG / MSG) built from one PointNet2Conv per grouping scale.

Farthest point sampling selects the centroids, a ball query gathers the neighbors of each centroid per scale, and the per-scale outputs are concatenated (Multi-Scale Grouping when channels is a nested sequence).

Parameters:

  • in_channels (int) –

    Number of input feature channels.

  • channels (Sequence[Union[int, Sequence[int]]]) –

    Per-scale MLP channel sizes; a nested sequence enables Multi-Scale Grouping.

  • ratio (Optional[float], default: None ) –

    Fractional farthest-point-sampling rate. Mutually exclusive with num_points.

  • num_points (Optional[int], default: None ) –

    Absolute number of centroids to sample (e.g. VoteNet's fixed \(2048, 1024, \ldots\)). Exactly one of ratio / num_points must be given. A sample with fewer than num_points points yields repeated centroids (FPS samples with replacement to keep shapes stable).

  • radii (Union[float, Sequence[float]]) –

    Ball-query radius per scale.

  • num_neighbors (Union[int, Sequence[int]]) –

    Maximum number of neighbors per scale.

  • spatial_dim (int, default: 3 ) –

    Dimension of point coordinates.

  • dropout (float, default: 0.0 ) –

    Dropout rate inside the per-scale MLPs.

  • bias (bool, default: False ) –

    Whether the MLP linear layers use a bias.

  • use_pos (bool, default: True ) –

    Concatenate the relative position to the grouped features.

  • normalize_pos (bool, default: True ) –

    Divide the relative position by the ball-query radius.

  • pos_first (bool, default: False ) –

    Concatenate the relative position before the grouped features (cat([rel_pos, x])) instead of after. VoteNet and the reference PointNet++ kernels use this order; keeping it a flag lets weights convert as a pure rename without a column swap.

  • aggr (AggrType, default: 'max' ) –

    Aggregation of the messages of each centroid.

  • sort_neighbors (bool, default: False ) –

    Keep the smallest source indices when a ball holds more than num_neighbors points, as the reference query_ball_point does.

PointNet2GlobalSetAbstraction [source] ΒΆ

PointNet2GlobalSetAbstraction(
    in_channels: int,
    channels: Sequence[int],
    spatial_dim: int = 3,
    dropout: float = 0.0,
    act: Union[str, Callable, None] = "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,
    use_pos: bool = False,
    pos_first: bool = False,
    aggr: PoolLike = "max",
)

Bases: Module

Global set-abstraction block: a shared MLP followed by a pool over each batch element.

Parameters:

  • in_channels (int) –

    Number of input feature channels.

  • channels (Sequence[int]) –

    Per-layer channel sizes of the MLP.

  • spatial_dim (int, default: 3 ) –

    Dimension of point coordinates.

  • dropout (float, default: 0.0 ) –

    Dropout rate inside the MLP.

  • bias (bool, default: False ) –

    Whether the MLP linear layers use a bias.

  • use_pos (bool, default: False ) –

    Concatenate the absolute point positions to x before the MLP. Unlike PointNet2SetAbstraction there is no sampled centroid to offset against, so the coordinates enter unnormalized (the reference PointNet++ GroupAll).

  • pos_first (bool, default: False ) –

    Concatenate the positions before the features (cat([pos, x])) instead of after.

  • aggr (PoolLike, default: 'max' ) –

    Pooling operation applied per batch element.

PointNet2FeaturePropagation [source] ΒΆ

PointNet2FeaturePropagation(
    channels: Sequence[int],
    k: int = 3,
    dropout: float = 0.0,
    act: Union[str, Callable, None] = "relu",
    act_first: bool = False,
    act_kwargs: Optional[Dict[str, Any]] = None,
    norm: Union[str, Callable, None] = "batch_norm",
    norm_kwargs: Optional[Dict[str, Any]] = None,
    bias: Union[bool, List[bool]] = True,
    plain_last: bool = True,
    weighting: Literal["squared", "inverse"] = "inverse",
    eps: float = 1e-16,
)

Bases: Module

K-NN interpolation + skip concatenation + MLP, as in PointNet++: Deep Hierarchical Feature Learning on Point Sets in a Metric Space.

The interpolated features are concatenated before the skip features (cat([interp, skip])).

Parameters:

  • channels (Sequence[int]) –

    Per-layer channel sizes of the MLP, starting with its input width (interpolated plus skip channels).

  • k (int, default: 3 ) –

    Number of neighbors for the K-NN interpolation. PointNet++ uses \(k = 3\) with inverse-distance weighting; RandLA-Net uses \(k = 1\) (nearest only).

  • dropout (float, default: 0.0 ) –

    Dropout rate inside the MLP.

  • bias (Union[bool, List[bool]], default: True ) –

    Whether the MLP linear layers use a bias.

  • plain_last (bool, default: True ) –

    Leave the last MLP layer without normalization and activation.

  • weighting (Literal['squared', 'inverse'], default: 'inverse' ) –

    Inverse-distance weighting scheme passed to knn_interpolate. Irrelevant when \(k = 1\).

  • eps (float, default: 1e-16 ) –

    Numerical stability term added to the interpolation distances.