gnp.dataset module
gnp.dataset.patch
- class gnp.dataset.patch.PatchData(x: Tensor | None = None, **kwargs)[source]
Bases:
DataA PyTorch Geometric Data object specialized for patch-based point cloud data.
This class extends the base Data object to include patch-specific attributes and a utility for iterating over batches of patches.
- batch_iterator(batch_size: int)[source]
Create a generator to iterate over batches of patches.
This method yields smaller PatchData objects, each containing a subset of the patches. It assumes that the patch data is sorted by patch_number.
- Parameters:
batch_size (int) -- The maximum number of patches in each batch.
- Yields:
PatchData -- A new PatchData object representing a batch of patches.
- property num_patches
Returns the number of patches in the dataset.
- class gnp.dataset.patch.PatchTensor(data: dict, k: int = 30, mode: str = 'test', pca: bool = True, scale: bool = True, min_z_scale: float = 0.005, basis: str = 'legendre', basis_degree: int = 3, num_training_patches: int = 1024, device: str = 'cpu')[source]
Bases:
objectProcesses a point cloud into a collection of overlapping patches.
This class handles the entire pipeline of patchifying a point cloud. It selects patch centers, finds neighboring points for each patch, computes local coordinate systems using PCA, and scales the coordinates. The final output is a PatchData object ready for use in a model.
- Parameters:
data (dict) -- A dictionary containing the point cloud data, requires at least an 'x' key with a tensor of shape (N, 3).
k (int, optional) -- Number of nearest neighbors to consider for various calculations, by default 30.
mode (str, optional) -- The mode for center selection ('train', 'test', or 'gmls'), by default "test".
pca (bool, optional) -- Whether to use PCA to determine local coordinate systems, by default True.
scale (bool, optional) -- Whether to scale the local coordinates, by default True.
min_z_scale (float, optional) -- The minimum value for z-scaling, by default 5e-3.
basis (str, optional) -- The basis to use, by default "legendre".
basis_degree (int, optional) -- The degree of the basis, by default 3.
num_training_patches (int, optional) -- Number of patches to sample in 'train' mode, by default 1024.
device (str, optional) -- The device to perform computations on, by default "cpu".
- as_patch_data() PatchData[source]
Assemble and return the final PatchData object.
This method collects all computed attributes (patch indices, local coordinates, PCA vectors, etc.) and any additional data from the input dictionary into a single PatchData object.
- Returns:
The fully processed patch data object.
- Return type:
- get_centers() tuple[Tensor, Tensor, Tensor][source]
Dispatch method to get patch centers based on the current mode.
- Returns:
A tuple containing: - The indices of the center points. - The cluster assignment for each point in the cloud. - The k-NN distance for each center, used to determine patch radius.
- Return type:
tuple[torch.Tensor, torch.Tensor, torch.Tensor]
- get_gmls_centers() tuple[Tensor, Tensor, Tensor][source]
Select every point as a patch center for GMLS.
In GMLS mode, a patch is centered at every single point in the cloud.
- Returns:
Center indices, cluster assignments, and k-NN distances.
- Return type:
tuple[torch.Tensor, torch.Tensor, torch.Tensor]
- get_test_centers() tuple[Tensor, Tensor, Tensor][source]
Select patch centers using a greedy covering strategy for testing.
This method iterates through shuffled points and selects a point as a center if it's not already covered by an existing patch, effectively creating a set of patches that cover the entire point cloud.
- Returns:
Center indices, cluster assignments, and k-NN distances.
- Return type:
tuple[torch.Tensor, torch.Tensor, torch.Tensor]
- get_train_centers() tuple[Tensor, Tensor, Tensor][source]
Select patch centers by random sampling for training.
- Returns:
Center indices, cluster assignments (dummy), and k-NN distances.
- Return type:
tuple[torch.Tensor, torch.Tensor, torch.Tensor
- property local_coordinates
The scaled local coordinates of points within their respective patches.
- property local_coordinates_original
The scaled local coordinates of the 'original' points.
- property pca_vectors
The PCA vectors (local basis) for each patch.
- property scaling
The combined (x, y, z) scaling vector for each patch.
- property tensor_centered[source]
Dense tensor of patch points, centered by subtracting the patch mean.
- Returns:
A tensor of shape (num_patches, max_points_in_patch, 3).
- Return type:
torch.Tensor
- property x_local[source]
All points transformed into the local coordinate system of their assigned patch.
- property xy_scale
The xy-plane scaling factor for each patch.
- property z_scale
The z-axis scaling factor for each patch.