pointnext_blocks
PointNeXt convolution layer introduced in the PointNeXt: Revisiting PointNet++ with Improved Training and Scaling Strategies by Guocheng Qian et al.
Note
This layer is also referred to as Local Aggregation in different papers and implementations.
This layer implements the torch_geometric.nn.conv.MessagePassing interface from PyTorch Geometric, which allows for local aggregation of features.
Tip
This layer is similar to the torch_geometric.nn.conv.PointNetConv layer from PyTorch Geometric, and introduces relative position normalization.
You can use it as follows:
import torch
from torch_geometric.nn import MLP, radius_graph
from torch_pointcloud.layers import PointNeXtConv
torch.manual_seed(0)
x = torch.randn(10, 10)
pos = torch.randn(10, 3)
batch = torch.zeros(10, dtype=torch.long)
edge_index = radius_graph(pos, r=1.5, batch=batch, max_num_neighbors=16)
conv = PointNeXtConv(MLP([3 + 10, 10]))
# Normalize the relative position by the query radius
out = conv(x, pos, edge_index, pos_divisor=1.5)
# This will be equivalent to the PointNetConv layer
out = conv(x, pos, edge_index)
Classes:
-
PointNeXtConvβPointNeXt grouping convolution on top of PyG's
MessagePassing. -
PointNeXtSetAbstractionβPointNeXt set-abstraction block: FPS centroids, radius-normalized grouping, and optional
-
PointNeXtResidualBlockβPointNeXt inverted-residual MLP block (InvResMLP).
PointNeXtConv [source] ΒΆ
PointNeXtConv(
local_nn: Module,
add_self_loops: bool = True,
**kwargs: Unpack[MessagePassingParams],
)
Bases: MessagePassing
PointNeXt grouping convolution on top of PyG's MessagePassing.
Each message concatenates the relative position with the neighbor features (cat([pos_j - pos_i, x_j])) and applies local_nn; when a pos_divisor is given the relative positions are normalized by it (PointNeXt normalizes by the ball-query radius).
Parameters:
-
local_nn(Module) βNetwork applied to each message of shape \((E, D + C)\).
-
add_self_loops(bool, default:True) βWhether to add self-loops to the edge index.
-
**kwargs(Unpack[MessagePassingParams], default:{}) βAdditional
MessagePassingarguments (aggrdefaults to"max").
PointNeXtSetAbstraction [source] ΒΆ
PointNeXtSetAbstraction(
spatial_dim: int,
in_channels: int,
channels: Sequence[Union[int, Sequence[int]]],
ratio: float,
radius: Union[float, Sequence[float]],
num_neighbors: Union[int, Sequence[int]],
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,
add_self_loops: bool = False,
aggr: AggrType = "max",
use_res: bool = True,
)
Bases: Module
PointNeXt set-abstraction block: FPS centroids, radius-normalized grouping, and optional residual skip connections.
Farthest point sampling selects the centroids, a ball query gathers the neighbors of each centroid per scale (Multi-Scale Grouping when channels is a nested sequence), and the relative positions are normalized by the query radius before the grouping convolution.
Parameters:
-
spatial_dim(int) βDimension of point coordinates.
-
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(float) βFractional farthest-point-sampling rate.
-
radius(Union[float, Sequence[float]]) βBall-query radius per scale, also used to normalize the relative positions.
-
num_neighbors(Union[int, Sequence[int]]) βMaximum number of neighbors per scale.
-
dropout(float, default:0.0) βDropout rate inside the per-scale MLPs.
-
add_self_loops(bool, default:False) βWhether to add self-loops to the grouping edge index.
-
aggr(AggrType, default:'max') βMessage aggregation used by the convolutions.
-
use_res(bool, default:True) βWhether each scale adds a residual skip connection from the sampled centroid features (with a linear projection when the channel counts differ).
PointNeXtResidualBlock [source] ΒΆ
PointNeXtResidualBlock(
spatial_dim: int,
channels: int,
expansion: int,
radius: float,
num_neighbors: int,
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: Union[bool, List[bool]] = True,
add_self_loops: bool = False,
aggr: AggrType = "max",
)
Bases: Module
PointNeXt inverted-residual MLP block (InvResMLP).
A radius-graph grouping convolution followed by an inverted-bottleneck MLP (channels -> channels * expansion -> channels), wrapped in a single residual connection. The resolution is unchanged; downsampling happens in PointNeXtSetAbstraction.
Parameters:
-
spatial_dim(int) βDimension of point coordinates.
-
channels(int) βNumber of input and output feature channels.
-
expansion(int) βExpansion factor of the bottleneck MLP.
-
radius(float) βRadius of the grouping graph, also used to normalize the relative positions.
-
num_neighbors(int) βMaximum number of neighbors in the grouping graph.
-
add_self_loops(bool, default:False) βWhether to add self-loops to the grouping edge index.
-
aggr(AggrType, default:'max') βMessage aggregation used by the convolution.