Skip to content

Transforms¶

A transform takes one sample dict and returns a new one. Compose chains them (RandomApply chains them under a probability), and a dataset applies the chain to every sample it loads. The API follows MONAI's dict transforms and PyTorch Geometric's Data conventions.

Each transform reads and writes the keys you name, so a sample can carry any extra key (intensity, color, ...) without every transform handling it.

import torch
import torch_pointcloud.transforms as T

pos = torch.randn(2048, 3)
color = torch.rand(2048, 3)

pipeline = T.Compose([
    T.Rescale(keys="pos", method="centroid"),
    T.Shift(keys="pos", method="bbox", axes=[0, 1]),
    T.RandomSample(keys=("pos", "color"), num_samples=1024),
])

scene = pipeline({"pos": pos, "color": color})

Pretrained checkpoints

A pretrained checkpoint carries its own preprocessing in info["transform"], for inference on its dataset.

Sampling and downsampling¶

Transform Description
RandomSample Uniform random subsample with shared indices across keys
FarthestPointSample FPS subsample (well-distributed)
RandomSampleFaceVertices Sample points on a mesh's faces
Voxelize Voxel-grid downsample with per-voxel reduction

Sampling keys¶

A transform that changes the number of points keeps pos, x, segment and batch aligned at the new resolution, and records how to get back when given the dst_* keys: inverse from Voxelize and DivisiblePad (dst_inverse_key), index from the selection samplers (dst_index_key), next to the origin_pos copy the registered pipelines keep. The sampling keys of the data format page define the four keys and how they compose.

Geometry / shifting¶

Transform Description
Shift Subtract a computed offset (bbox, centroid, or min)
AxisMinOffset Per-point offset from axis minimum (height feature)

Scaling / normalization¶

Transform Description
Rescale Center and rescale to unit extent (centroid / bbox / centroid_extent / min_sphere)
Normalize Per-channel \((x - \mu) / \sigma\) standardization
MaxAbsScale Per-channel division by the largest absolute value of the sample

Masking and filtering¶

Transform Geometry
BoxMask Axis-aligned bounding box (AABB)
CubeMask L∞ / Chebyshev ball (hypercube)
SphereMask L2 / Euclidean ball
ApplyMask Apply any precomputed mask to one or more keys
RemoveNearOrigin One-shot L2 filter around origin

Utilities¶

Transform Description
Cat Concatenate multiple keys' tensors along a dim
CopyItems Clone a key's value under a new name
RenameItems Move a key to a new name
KeepItems Drop everything not in a whitelist
SetValue Set keys to literal values
Reduce Reduce a tensor along a dim (min/max/mean/sum)
OneHot One-hot encode integer labels
Relabel Remap integer labels via a lookup table
Scale Multiply by a scalar
Divide Divide by a scalar
DivideItems data[k] / data[div_k] element-wise
SubtractItems data[k] - data[sub_k] element-wise
Abs Element-wise absolute value
ToFloat Cast tensors to float32
ToTensor Convert lists / arrays to tensors
ToDevice Move to a device
OnesLike Add a key whose tensor is torch.ones_like(...)

Octree (optional, requires ocnn)¶

Transform Description
BuildOctree Build an octree from positions
OctreeFeatures Extract per-node features from an octree