topobench.transforms.liftings.pointcloud2hypergraph.pointnet_lifting module#
This module implements the PointNetLifting class.
- class PointCloud2HypergraphLifting(**kwargs)#
Bases:
PointCloudLiftingAbstract class for lifting pointclouds to hypergraphs.
- Parameters:
- **kwargsoptional
Additional arguments for the class.
- __init__(**kwargs)#
- class PointNetLifting(sampling_ratio, cluster_radius, **kwargs)#
Bases:
PointCloud2HypergraphLiftingLift a point cloud to a hypergraph.
This is inspired by Qi et al. “PointNet++: Deep Hierarchical Feature Learning on Point Sets in a Metric Space” (NeurIPS 2027). This means building approximately equidistantly-spaced clusters of points via farthest point sampling and radius queries. Each of these clusters constitutes a hyperedge which is used for set abstraction.
- Parameters:
- sampling_ratiofloat
The sub-sampling ratio for farthest point sampling.
- cluster_radiusfloat
The radius of the clusters w.r.t. the sub-sampled points.
- **kwargsoptional
Additional arguments for the class.
- __init__(sampling_ratio, cluster_radius, **kwargs)#
- lift_topology(data)#
Lift the topology of a graph to an expander hypergraph.
- Parameters:
- datatorch_geometric.data.Data
The input data to be lifted.
- Returns:
- dict
The lifted topology.
- fps(src, batch=None, ratio=None, random_start=True, batch_size=None, ptr=None)#
“A sampling algorithm from the “PointNet++: Deep Hierarchical Feature Learning on Point Sets in a Metric Space” paper, which iteratively samples the most distant point with regard to the rest points.
- Parameters:
src (Tensor) – Point feature matrix \(\mathbf{X} \in \mathbb{R}^{N \times F}\).
batch (LongTensor, optional) – Batch vector \(\mathbf{b} \in {\{ 0, \ldots, B-1\}}^N\), which assigns each node to a specific example. (default:
None)ratio (float or Tensor, optional) – Sampling ratio. (default:
0.5)random_start (bool, optional) – If set to
False, use the first node in \(\mathbf{X}\) as starting node. (default: obj:True)batch_size (int, optional) – The number of examples \(B\). Automatically calculated if not given. (default:
None)ptr (torch.Tensor or [int], optional) – If given, batch assignment will be determined based on boundaries in CSR representation, e.g.,
batch=[0,0,1,1,1,2]translates toptr=[0,2,5,6]. (default:None)
- Return type:
LongTensor
import torch from torch_cluster import fps src = torch.Tensor([[-1, -1], [-1, 1], [1, -1], [1, 1]]) batch = torch.tensor([0, 0, 0, 0]) index = fps(src, batch, ratio=0.5)
- radius(x, y, r, batch_x=None, batch_y=None, max_num_neighbors=32, num_workers=1, batch_size=None)#
Finds for each element in
yall points inxwithin distancer.- Parameters:
x (Tensor) – Node feature matrix \(\mathbf{X} \in \mathbb{R}^{N \times F}\).
y (Tensor) – Node feature matrix \(\mathbf{Y} \in \mathbb{R}^{M \times F}\).
r (float) – The radius.
batch_x (LongTensor, optional) – Batch vector \(\mathbf{b} \in {\{ 0, \ldots, B-1\}}^N\), which assigns each node to a specific example.
batch_xneeds to be sorted. (default:None)batch_y (LongTensor, optional) – Batch vector \(\mathbf{b} \in {\{ 0, \ldots, B-1\}}^M\), which assigns each node to a specific example.
batch_yneeds to be sorted. (default:None)max_num_neighbors (int, optional) – The maximum number of neighbors to return for each element in
y. If the number of actual neighbors is greater thanmax_num_neighbors, returned neighbors are picked randomly. (default:32)num_workers (int) – Number of workers to use for computation. Has no effect in case
batch_xorbatch_yis notNone, or the input lies on the GPU. (default:1)batch_size (int, optional) – The number of examples \(B\). Automatically calculated if not given. (default:
None)
import torch from torch_cluster import radius x = torch.Tensor([[-1, -1], [-1, 1], [1, -1], [1, 1]]) batch_x = torch.tensor([0, 0, 0, 0]) y = torch.Tensor([[-1, 0], [1, 0]]) batch_y = torch.tensor([0, 0]) assign_index = radius(x, y, 1.5, batch_x, batch_y)