Skip to content

PPFConv

PPFConv(
    local_nn: Optional[Callable] = None,
    global_nn: Optional[Callable] = None,
    add_self_loops: bool = True,
    **kwargs,
)

Bases: MessagePassing

The PPFNet operator from the "PPFNet: Global Context Aware Local Features for Robust 3D Point Matching" paper.

\[ \mathbf{x}^{\prime}_i = \gamma_{\mathbf{\Theta}} \left( \max_{j \in \mathcal{N}(i) \cup \{ i \}} h_{\mathbf{\Theta}} ( \mathbf{x}_j, \| \mathbf{d_{j,i}} \|, \angle(\mathbf{n}_i, \mathbf{d_{j,i}}), \angle(\mathbf{n}_j, \mathbf{d_{j,i}}), \angle(\mathbf{n}_i, \mathbf{n}_j) \right) \]

where \(\mathbf{d_{j,i}}\) is the distance vector between the positions of the points, and \(\mathbf{n}\) are their normals.

Parameters:

Name Type Description Default
local_nn Optional[Callable]

Network \(h_{\mathbf{\Theta}}\) applied to each edge, on [x_j, ppf] (the 4 point pair features, after the source node features if any). Default: None

None
global_nn Optional[Callable]

Network \(\gamma_{\mathbf{\Theta}}\) applied to the aggregated features. Default: None

None
add_self_loops bool

If True, removes the self-loops of the graph and adds one for each destination node. Default: True

True
**kwargs

Arguments of MessagePassing (aggr="max" by default).

{}

Example:

import mlx.core as mx
import mlx.nn as nn
from mlx_graphs.nn import PPFConv
from mlx_graphs.utils import knn_graph

pos = mx.random.normal((100, 3))
normal = mx.random.normal((100, 3))
x = mx.random.normal((100, 16))
conv = PPFConv(nn.Sequential(nn.Linear(16 + 4, 32), nn.ReLU()))
>>> conv(knn_graph(pos, k=8), x, pos, normal).shape
(100, 32)

Methods:

Name Description
__call__

Computes the forward pass of PPFConv.

Source code in mlx_graphs/nn/conv/ppf_conv.py
def __init__(
    self,
    local_nn: Optional[Callable] = None,
    global_nn: Optional[Callable] = None,
    add_self_loops: bool = True,
    **kwargs,
):
    kwargs.setdefault("aggr", "max")
    super().__init__(**kwargs)
    self.local_nn = local_nn
    self.global_nn = global_nn
    self.add_self_loops = add_self_loops

__call__

__call__(
    edge_index: array, node_features: OptPair, pos: Pair, normal: Pair
) -> array

Computes the forward pass of PPFConv.

Parameters:

Name Type Description Default
edge_index array

Edges of shape [2, num_edges], from the neighbors (sources) to the center points (destinations).

required
node_features OptPair

Features of the points, a (src_features, dst_features) tuple (only the source features are used), or None.

required
pos Pair

Positions of the points, of shape [N, 3], or a (src_pos, dst_pos) tuple.

required
normal Pair

Normals of the points, of shape [N, 3], or a (src_normal, dst_normal) tuple.

required

Returns:

Type Description
array

The features of the destination points.

Source code in mlx_graphs/nn/conv/ppf_conv.py
def __call__(
    self,
    edge_index: mx.array,
    node_features: OptPair,
    pos: Pair,
    normal: Pair,
) -> mx.array:
    """Computes the forward pass of PPFConv.

    Args:
        edge_index: Edges of shape ``[2, num_edges]``, from the neighbors
            (sources) to the center points (destinations).
        node_features: Features of the points, a ``(src_features,
            dst_features)`` tuple (only the source features are used), or
            ``None``.
        pos: Positions of the points, of shape ``[N, 3]``, or a
            ``(src_pos, dst_pos)`` tuple.
        normal: Normals of the points, of shape ``[N, 3]``, or a
            ``(src_normal, dst_normal)`` tuple.

    Returns:
        The features of the destination points.
    """
    x_src = node_features[0] if isinstance(node_features, tuple) else node_features
    pos_src, pos_dst = _pair(pos)
    normal_src, normal_dst = _pair(normal)
    if self.add_self_loops:
        edge_index = _set_self_loops(edge_index, pos_dst.shape[0])
    src, dst = edge_index[0], edge_index[1]
    msg = point_pair_features(
        pos_dst[dst], pos_src[src], normal_dst[dst], normal_src[src]
    )
    if x_src is not None:
        msg = mx.concatenate([x_src[src], msg], axis=1)
    msg = _run_mlp(self.local_nn, msg)
    self.num_nodes = pos_dst.shape[0]
    out = self.update_nodes(self.aggregate(msg, dst))
    if self.global_nn is not None:
        out = self.global_nn(out)
    return out

from mlx_graphs.nn import PPFConv · mlx_graphs/nn/conv/ppf_conv.py