Skip to content

voxel_grid_pool

Voxel grid subsampling of packed point clouds.

Classes:

  • VoxelGridPool –

    Voxel grid subsampling: the points falling in the same grid_size cell are reduced to a single point.

VoxelGridPool [source] ΒΆ

VoxelGridPool(
    grid_size: float,
    reduce: str = "max",
    origin: Literal["grid", "min"] = "grid",
)

Bases: Module

Voxel grid subsampling: the points falling in the same grid_size cell are reduced to a single point.

Positions are averaged within a cell and features are reduced with reduce. The grid origin is either aligned to multiples of grid_size (origin="grid", so cell boundaries do not depend on the cloud's extent) or placed at each cloud's minimum corner (origin="min"). Passing return_inverse=True also returns the point-to-cell map.

Parameters:

  • grid_size (float) –

    Cell edge length.

  • reduce (str, default: 'max' ) –

    Feature reduction over a cell: "max", "mean", "sum" or "min".

  • origin (Literal['grid', 'min'], default: 'grid' ) –

    Where the grid starts, "grid" or "min".

Shape
  • Input: \((N, C)\) features, \((N, 3)\) positions and \((N,)\) batch index.
  • Output: \((M, C)\) features, \((M, 3)\) positions, \((M,)\) batch index and, with return_inverse, the \((N,)\) cell index of every input point.
Example
>>> import torch
>>> from torch_pointcloud.layers import VoxelGridPool
>>> pool = VoxelGridPool(grid_size=0.5)
>>> x, pos, batch = torch.randn(100, 8), torch.rand(100, 3), torch.zeros(100, dtype=torch.long)
>>> x_pooled, pos_pooled, batch_pooled = pool(x, pos, batch)  # doctest: +SKIP
>>> x_pooled.shape[1], pos_pooled.shape[1]  # doctest: +SKIP
(8, 3)