voxelization
Dense and sparse voxelization, FNV voxel hashing, the first point per voxel, and trilinear devoxelization.
Functions:
-
dense_voxelizeβPool packed point features into a dense voxel grid, one grid per point cloud.
-
trilinear_dense_devoxelizeβInterpolate a dense voxel grid back to packed point features, trilinearly.
-
sparse_voxelizeβPool packed point features into sparse voxels of a regular grid.
-
hard_voxelizeβHard voxelization of a packed batch of point clouds (
spconvvoxel generator). -
voxel_grid_fnvβFNV-1a 64-bit hash of integer voxel-grid coordinates. \((N, D) \to (N,)\).
-
first_permutationβIndex of the first occurrence of each cluster id in a consecutive cluster tensor.
dense_voxelize [source] ΒΆ
dense_voxelize(
x: Tensor,
pos: Tensor,
batch: Tensor,
resolution: int,
reduce: str = "mean",
) -> Tensor
Pool packed point features into a dense voxel grid, one grid per point cloud.
Parameters:
-
x(Tensor) βPacked point features \((N, C)\).
-
pos(Tensor) βPacked grid coordinates \((N, 3)\), clamped to \([0, \text{resolution} - 1)\).
-
batch(Tensor) βPer-point batch index \((N,)\).
-
resolution(int) βNumber of voxels \(R\) per axis.
-
reduce(str, default:'mean') βScatter reduction applied to the points of a voxel (e.g.
mean,max).
Returns:
-
TensorβThe voxel grid \((B, C, R, R, R)\), zero where a voxel holds no point.
trilinear_dense_devoxelize [source] ΒΆ
trilinear_dense_devoxelize(
x_voxel: Tensor,
pos: Tensor,
batch: Tensor,
resolution: int,
) -> Tensor
Interpolate a dense voxel grid back to packed point features, trilinearly.
Parameters:
-
x_voxel(Tensor) βVoxel grid \((B, C, R, R, R)\).
-
pos(Tensor) βPacked grid coordinates \((N, 3)\), clamped to \([0, \text{resolution} - 1)\).
-
batch(Tensor) βPer-point batch index \((N,)\).
-
resolution(int) βNumber of voxels \(R\) per axis. Must match the grid.
Returns:
-
TensorβThe interpolated point features \((N, C)\).
sparse_voxelize [source] ΒΆ
sparse_voxelize(
x: Tensor,
pos: Tensor,
batch: Tensor,
voxel_size: float,
reduce: str = "mean",
return_inverse: bool = False,
) -> Tuple[Tensor, ...]
Pool packed point features into sparse voxels of a regular grid.
Parameters:
-
x(Tensor) βPacked point features \((N, C)\).
-
pos(Tensor) βPacked point coordinates \((N, 3)\).
-
batch(Tensor) βPer-point batch index \((N,)\).
-
voxel_size(float) βEdge length of a voxel, in the units of
pos. -
reduce(str, default:'mean') βScatter reduction applied to the points of a voxel (e.g.
mean,max). -
return_inverse(bool, default:False) βAlso return the per-point voxel index, to broadcast voxel values back to the points.
Returns:
-
TensorβThe voxel features \((V, C)\), their integer coordinates \((V, 3)\) and batch index \((V,)\), plus the
-
...βper-point voxel index \((N,)\) when
return_inverseisTrue.
hard_voxelize [source] ΒΆ
hard_voxelize(
points: Tensor,
batch: Tensor,
voxel_size: Sequence[float],
point_cloud_range: Sequence[float],
max_num_points: int,
max_num_voxels: int,
) -> Tuple[Tensor, Tensor, Tensor]
Hard voxelization of a packed batch of point clouds (spconv voxel generator).
Reproduces the transform_points_to_voxels step of voxel detectors (PointPillars, SECOND): each scene is voxelized independently (at most max_num_points points per voxel and max_num_voxels voxels per scene), then the per-scene voxels are concatenated with a leading batch index. Points outside point_cloud_range are dropped by the generator.
Parameters:
-
points(Tensor) βPacked point features \((N, C)\) with the first three columns the \(xyz\) coordinates.
-
batch(Tensor) βPer-point batch index \((N,)\).
-
voxel_size(Sequence[float]) βVoxel size \((v_x, v_y, v_z)\).
-
point_cloud_range(Sequence[float]) βRange \((x_\min, y_\min, z_\min, x_\max, y_\max, z_\max)\).
-
max_num_points(int) βMaximum number of points kept per voxel.
-
max_num_voxels(int) βMaximum number of voxels kept per scene.
Returns:
-
TensorβA tuple
(voxels, voxel_indices, num_points)wherevoxelsis \((V, \text{max\_num\_points}, C)\), -
Tensorβvoxel_indicesis \((V, 4)\) with columns \((\text{batch}, z, y, x)\) andnum_pointsis \((V,)\).
voxel_grid_fnv [source] ΒΆ
voxel_grid_fnv(
pos: Tensor,
size: float,
start: Optional[Tensor] = None,
*,
return_inverse: Literal[False] = False,
return_counts: Literal[False] = False,
) -> Tensor
voxel_grid_fnv(
pos: Tensor,
size: float,
start: Optional[Tensor] = None,
*,
return_inverse: Literal[True],
return_counts: Literal[False] = False,
) -> Tuple[Tensor, Tensor]
voxel_grid_fnv(
pos: Tensor,
size: float,
start: Optional[Tensor] = None,
*,
return_inverse: bool = False,
return_counts: bool = False,
) -> Union[Tensor, Tuple[Tensor, ...]]
FNV-1a 64-bit hash of integer voxel-grid coordinates. \((N, D) \to (N,)\).
Parameters:
-
pos(Tensor) βPoint positions of shape \((N, D)\).
-
size(float) βVoxel side length in the same units as
pos. -
start(Optional[Tensor], default:None) βOptional voxel-grid origin. When
None, the grid origin is implicit via the internalpos_grid -= pos_grid.min(0)shift. -
return_inverse(bool, default:False) βIf
True, also return the per-point consecutive voxel index in \([0, V)\), following the semantics oftorch.unique(..., return_inverse=True). -
return_counts(bool, default:False) βIf
True, also return the per-voxel point count of shape \((V,)\).
Returns:
-
Union[Tensor, Tuple[Tensor, ...]]βhashedof shape \((N,)\) when both flags areFalse. Withreturn_inverse=Trueadds -
Union[Tensor, Tuple[Tensor, ...]]βinverseof shape \((N,)\); withreturn_counts=Trueaddscountof shape \((V,)\); both -
Union[Tensor, Tuple[Tensor, ...]]βflags enabled returns
(hashed, inverse, count).
first_permutation [source] ΒΆ
Index of the first occurrence of each cluster id in a consecutive cluster tensor.
The permutation returned by consecutive_cluster picks a backend-dependent representative per cluster (the last occurrence on CPU, a nondeterministic one on CUDA). This helper always picks the first occurrence, so tensor[first_permutation(cluster)] is deterministic across devices.
Parameters:
-
cluster(Tensor) βConsecutive cluster indices of shape \((N,)\) with values in \([0, V)\).
-
num_clusters(Optional[int], default:None) βNumber of clusters \(V\). Inferred as
cluster.max() + 1whenNone.
Returns:
-
TensorβLong tensor of shape \((V,)\) holding, per cluster id, the smallest index in
clusterwith that id.