utils
Transforms that rename, copy, convert or combine the entries of a sample dict, and element-wise arithmetic.
Classes:
-
SetValueβSet values for keys in the dictionary, creating or overwriting them.
-
ToFloatβCast dictionary tensor entries to float32.
-
ToDeviceβConvert dictionary tensor entries to the given device.
-
RelabelβRemap integer labels in dictionary entries via a lookup table.
-
RenameItemsβRename keys in the dictionary.
-
CopyItemsβCopy values from source keys to new destination keys.
-
ToTensorβConvert dictionary entries to tensors.
-
OnesLikeβAdds a tensor of ones shaped like existing dictionary entries.
-
CatβConcatenates tensors from multiple keys into a single feature tensor.
-
OneHotβOne-hot encode integer-class tensors.
-
ReduceβReduce a tensor along a dimension and store the scalar/vector result.
-
KeepItemsβKeep only items in the data dictionary that are in the keys list.
-
ScaleβMultiply dictionary tensor entries by a scale factor.
-
DivideβDivide dictionary tensor entries by a divisor.
-
DivideItemsβDivide target keys by the value of a reference key element-wise.
-
SubtractItemsβSubtract the value of a reference key from target keys element-wise.
-
AbsβMake dictionary tensor entries absolute.
-
ClampβClamp tensor entries to a range (a thin wrapper over
torch.clamp).
ReduceOp module-attribute ΒΆ
Allowed values for Reduce.op (per-key reduction operator).
SetValue [source] ΒΆ
Bases: DictTransform
Set values for keys in the dictionary, creating or overwriting them.
Unlike most DictTransform subclasses, SetValue does not read existing values, so allow_missing_keys has no meaning and is not accepted.

Parameters:
-
keys(KeyCollection) βThe keys to set.
-
values(Any) βThe values to set. Either a single value broadcast to every key, or a sequence of values the same length as
keys.
ToFloat [source] ΒΆ
Bases: DictTransform
Cast dictionary tensor entries to float32.
Useful when tensors are stored in integer formats (e.g. uint8 for colors) and need to be promoted to floating point before arithmetic transforms like Divide or Normalize.

Parameters:
-
keys(KeyCollection) βThe keys to cast.
-
allow_missing_keys(bool, default:False) βIf
True, missing keys are silently ignored.
ToDevice [source] ΒΆ
ToDevice(
keys: KeyCollection,
device: ValueCollection[str | device],
non_blocking: ValueCollection[bool] = False,
copy: ValueCollection[bool] = True,
memory_format: ValueCollection[
memory_format | None
] = None,
dst_keys: Optional[KeyCollection] = None,
allow_missing_keys: bool = False,
)
Bases: DictTransform
Convert dictionary tensor entries to the given device.

Parameters:
-
keys(KeyCollection) βThe keys to convert the tensors to the given device.
-
device(ValueCollection[str | device]) βThe device to convert the tensors to.
-
non_blocking(ValueCollection[bool], default:False) βIf
True, the transfer will be done asynchronously. -
copy(ValueCollection[bool], default:True) βIf
True, the tensor will be copied to the new device. -
memory_format(ValueCollection[memory_format | None], default:None) βThe memory format to use for the tensor.
-
dst_keys(Optional[KeyCollection], default:None) βThe keys to store the converted tensors in.
-
allow_missing_keys(bool, default:False) βIf
True, the transform will not raise an error if the keys are not present in the data.
Relabel [source] ΒΆ
Relabel(
keys: KeyCollection,
labels: Sequence[int] | Dict[int, int],
default: int = 0,
allow_missing_keys: bool = False,
)
Bases: DictTransform
Remap integer labels in dictionary entries via a lookup table.
labels can be either:
- a sequence of source values (1:1) - each value at index
iis mapped toi; - a
dict[int, int](general source β target) - supports N-to-1 merges (e.g. SemanticKITTI'smoving-carandcarboth β 0).
Source values not listed in labels are set to default.

Parameters:
-
keys(KeyCollection) βKeys holding label tensors to remap.
-
labels(Sequence[int] | Dict[int, int]) βSource-value listing (1:1) or explicit
{source: target}dict (N:1). -
default(int, default:0) βValue assigned to source values not listed in
labels. -
allow_missing_keys(bool, default:False) βIf
True, skip missing keys instead of raising.
Example
import torch
import torch_pointcloud.transforms as T
# 1:1 - keep raw NYU40 ids 1, 2, 3, 4, 5 and remap them to 0..4
relabel = T.Relabel(keys="segment", labels=[1, 2, 3, 4, 5], default=255)
relabel({"segment": torch.tensor([1, 3, 5, 7])})["segment"] # tensor([0, 2, 4, 255])
# N:1 - SemanticKITTI 19-class benchmark (merges moving-* into static)
relabel = T.Relabel(
keys="segment",
labels={
10: 0, 252: 0, # car (+ moving-car)
11: 1, # bicycle
15: 2, # motorcycle
18: 3, 258: 3, # truck (+ moving-truck)
# ...
},
default=255,
)
relabel({"segment": torch.tensor([10, 252, 11, 99])})["segment"] # tensor([0, 0, 1, 255])
RenameItems [source] ΒΆ
Bases: DictTransform
Rename keys in the dictionary.

Parameters:
-
keys(KeyCollection) βSource keys to rename.
-
dst_keys(KeyCollection) βNew key names (same length as
keys). -
allow_missing_keys(bool, default:False) βIf
True, silently skip absent source keys.
CopyItems [source] ΒΆ
Bases: DictTransform
Copy values from source keys to new destination keys.

Parameters:
-
keys(KeyCollection) βSource keys to copy from.
-
dst_keys(KeyCollection) βDestination keys to copy to (same length as
keys). -
allow_missing_keys(bool, default:False) βIf
True, silently skip absent source keys.
ToTensor [source] ΒΆ
ToTensor(
keys: KeyCollection,
dtype: ValueCollection[str | dtype] | None = None,
device: ValueCollection[str | device] | None = None,
allow_missing_keys: bool = False,
)
Bases: DictTransform
Convert dictionary entries to tensors.

Parameters:
-
keys(KeyCollection) βThe keys to convert.
-
dtype(ValueCollection[str | dtype] | None, default:None) βTarget dtype(s).
-
device(ValueCollection[str | device] | None, default:None) βTarget device(s).
-
allow_missing_keys(bool, default:False) βIf
True, the transform will not raise an error if the keys are not present in the data.
OnesLike [source] ΒΆ
OnesLike(
keys: KeyCollection,
memory_format: ValueCollection[memory_format]
| None = None,
dtype: ValueCollection[dtype] | None = None,
layout: ValueCollection[layout] | None = None,
device: ValueCollection[device] | None = None,
pin_memory: ValueCollection[bool] | None = False,
requires_grad: ValueCollection[bool] | None = False,
dst_keys: KeyCollection | None = None,
allow_missing_keys: bool = False,
)
Bases: DictTransform
Adds a tensor of ones shaped like existing dictionary entries.

Parameters:
-
keys(KeyCollection) βReference keys used to determine tensor shape.
-
dst_keys(KeyCollection | None, default:None) βKeys under which the ones tensors are stored.
Cat [source] ΒΆ
Bases: DictTransform
Concatenates tensors from multiple keys into a single feature tensor.
Note
This transform is mostly used to concatenate multiple features into a single tensor to feed into your model.
Integer inputs are cast to float32; floating inputs keep their dtype. When the inputs mix floating dtypes, the result uses the widest one (so float64 is preserved, never downcast).

Parameters:
-
keys(KeyCollection) βKeys whose tensors are concatenated (in order).
-
dst_key(str) βKey under which the result is stored.
-
dim(int, default:-1) βDimension along which to concatenate.
-
allow_missing_keys(bool, default:False) βIf
True, silently skip absent keys.
Example
If you have a point cloud data containing position, color and normal and want to concatenate them into a single feature tensor (to feed into your model), you can do the following:
import torch
from torch_pointcloud.transforms import Cat
data = {
"pos": torch.randn(10, 3),
"color": torch.randn(10, 3),
"normal": torch.randn(10, 3),
}
transform = Cat(keys=["pos", "color", "normal"], dst_key="x", dim=1)
data = transform(data)
Now, the data dictionary will contain the key x with the shape \((10, 9)\).
OneHot [source] ΒΆ
OneHot(
keys: KeyCollection,
num_classes: ValueCollection[int],
dst_keys: Optional[KeyCollection] = None,
allow_missing_keys: bool = False,
)
Bases: DictTransform
One-hot encode integer-class tensors.
Wraps torch.nn.functional.one_hot and casts the result to float so the output is ready to feed into a model.

Parameters:
-
keys(KeyCollection) βKeys holding integer (long) class indices.
-
num_classes(ValueCollection[int]) βNumber of classes \(C\) in the one-hot encoding.
-
dst_keys(Optional[KeyCollection], default:None) βWhere to store the one-hot tensors. Defaults to
keys. -
allow_missing_keys(bool, default:False) βIf
True, silently skip absent keys.
Shape
Input class tensor of shape \((N,)\) becomes \((N, C)\). A scalar input becomes shape \((C,)\), which after batched collate stacks to \((B, C)\).
Reduce [source] ΒΆ
Reduce(
keys: KeyCollection,
op: ValueCollection[ReduceOp],
dim: ValueCollection[int] = 0,
keepdim: bool = False,
dst_keys: Optional[KeyCollection] = None,
allow_missing_keys: bool = False,
)
Bases: DictTransform
Reduce a tensor along a dimension and store the scalar/vector result.
Useful for capturing per-sample statistics (e.g. axis-wise scene maxima or centroids) as standalone keys that downstream transforms can reference.

Parameters:
-
keys(KeyCollection) βKeys to reduce.
-
op(ValueCollection[ReduceOp]) βReduction operator:
"min","max","mean", or"sum"(matches the vocabulary used byVoxelize)."mean"keeps the input's floating dtype (float64included); integer inputs are cast tofloat32. -
dim(ValueCollection[int], default:0) βDimension to reduce. Defaults to
0. -
keepdim(bool, default:False) βPass
keepdim=Trueto keep the reduced axis as size \(1\). This is helpful when the result is meant to broadcast against a \((N, D)\) tensor (e.g. per-sample bbox stats) and to survive the packed-batch collate - a \((1, D)\) tensor collates to \((B, D)\) viatorch.cat, whereas a \((D,)\) tensor would concatenate to \((B \cdot D,)\). -
dst_keys(Optional[KeyCollection], default:None) βOutput keys. Defaults to
keys(in-place overwrite). -
allow_missing_keys(bool, default:False) βIf
True, silently skip absent keys.
KeepItems [source] ΒΆ
Bases: DictTransform
Keep only items in the data dictionary that are in the keys list.
Note
This transform is useful if during augmentation process you constructed multiple tensors and want to drop intermediate tensors for memory efficiency.

Parameters:
-
keys(KeyCollection) βThe keys to keep in the data dictionary.
-
allow_missing_keys(bool, default:False) βIf
True, the transform will not raise an error if the keys are not present in the data.
Example
If you have a data dictionary containing position, color and normal and want to keep only the position and color, you can do the following:
import torch
from torch_pointcloud.transforms import KeepItems
data = {
"pos": torch.randn(10, 3),
"color": torch.randn(10, 3),
"normal": torch.randn(10, 3),
}
transform = KeepItems(keys=["pos", "color"])
data = transform(data)
Now, the data dictionary will contain only the keys pos and color. The key normal will be removed.
Scale [source] ΒΆ
Bases: DictTransform
Multiply dictionary tensor entries by a scale factor.


Parameters:
-
keys(KeyCollection) βThe keys to scale.
-
scale(float | Sequence[float]) βThe scale factor(s).
-
allow_missing_keys(bool, default:False) βIf
True, the transform will not raise an error if the keys are not present in the data.
Divide [source] ΒΆ
Bases: DictTransform
Divide dictionary tensor entries by a divisor.


Parameters:
-
keys(KeyCollection) βThe keys to divide.
-
divisor(float | Sequence[float]) βThe divisor(s).
-
allow_missing_keys(bool, default:False) βIf
True, the transform will not raise an error if the keys are not present in the data.
DivideItems [source] ΒΆ
DivideItems(
keys: KeyCollection,
div_keys: KeyCollection,
dst_keys: Optional[KeyCollection] = None,
allow_missing_keys: bool = False,
)
Bases: DictTransform
Divide target keys by the value of a reference key element-wise.
Computes data[key] = data[key] / data[div_key] for each key.

Parameters:
-
keys(KeyCollection) βKeys whose tensors are divided.
-
div_keys(KeyCollection) βKeys whose values are used as the divisors.
-
dst_keys(Optional[KeyCollection], default:None) βWhere to store results. Defaults to
keys. -
allow_missing_keys(bool, default:False) βIf
True, silently skip absent target keys.
SubtractItems [source] ΒΆ
SubtractItems(
keys: KeyCollection,
sub_keys: KeyCollection,
dst_keys: Optional[KeyCollection] = None,
axes: Optional[Sequence[int]] = None,
allow_missing_keys: bool = False,
)
Bases: DictTransform
Subtract the value of a reference key from target keys element-wise.
Computes data[key] = data[key] - data[sub_key] for each key. With axes set, only the listed last-dim indices are subtracted; the other components pass through unchanged (useful to shift only XY while keeping Z absolute).


Parameters:
-
keys(KeyCollection) βKeys whose tensors are modified (subtracted from).
-
sub_keys(KeyCollection) βKeys whose values are subtracted from each target key.
-
dst_keys(Optional[KeyCollection], default:None) βWhere to store results. Defaults to
keys. -
axes(Optional[Sequence[int]], default:None) βOptional indices into the last dim restricting which components are subtracted.
None(default) subtracts every component. -
allow_missing_keys(bool, default:False) βIf
True, silently skip absent target keys.
Abs [source] ΒΆ
Bases: DictTransform
Make dictionary tensor entries absolute.
See Also
torch_pointcloud.transforms.functional.absolute


Parameters:
-
keys(KeyCollection) βThe keys to make absolute.
-
allow_missing_keys(bool, default:False) βIf
True, the transform will not raise an error if the keys are not present in the data.
Clamp [source] ΒΆ
Clamp(
keys: KeyCollection,
min: Union[float, Sequence[float], None] = None,
max: Union[float, Sequence[float], None] = None,
dst_keys: Optional[KeyCollection] = None,
allow_missing_keys: bool = False,
)
Bases: DictTransform
Clamp tensor entries to a range (a thin wrapper over torch.clamp).


Parameters:
-
keys(KeyCollection) βKeys to clamp.
-
min(Union[float, Sequence[float], None], default:None) βLower bound, one value or one per channel of the last dim.
Nonedisables the lower clamp. -
max(Union[float, Sequence[float], None], default:None) βUpper bound, one value or one per channel of the last dim.
Nonedisables the upper clamp. -
dst_keys(Optional[KeyCollection], default:None) βWhere to store the result. Defaults to
keys(in-place overwrite). -
allow_missing_keys(bool, default:False) βIf
True, silently skip absent keys.
relabel [source] ΒΆ
relabel(
labels: Tensor,
mapping: Union[Sequence[int], Dict[int, int]],
default: int = 0,
) -> Tensor
Remap integer labels via a lookup table.
mapping can be either:
- a sequence of source values (1:1): each value at index \(i\) is mapped to \(i\);
- a
dict[int, int](general source β target): supports N-to-1 merges (e.g. SemanticKITTI'smoving-carandcarboth β 0).
Source values not listed in mapping are set to default.
Parameters:
-
labels(Tensor) βInteger label tensor (any integer dtype). Output preserves dtype.
-
mapping(Union[Sequence[int], Dict[int, int]]) βSource-value listing (1:1) or explicit
{source: target}dict (N:1). -
default(int, default:0) βValue assigned to source values not listed in
mapping.
Returns:
-
TensorβRemapped tensor with the same shape and dtype as
labels.
Raises:
-
ValueErrorβIf
mappingis empty.