Skip to content

Tensor

Classes for transferring point cloud (NumPy) -> PyTorch Tensor

ToTensor

Recursively convert NumPy arrays, scalars, and container structures to PyTorch tensors.

This transform is designed to work on:

  • Individual values:
  • torch.Tensor: returned as-is.
  • intLongTensor([value]).
  • floatFloatTensor([value]).
  • str: returned as-is (strings are not converted).
  • np.ndarray with:
    • boolean dtype → torch.from_numpy(arr) (bool tensor),
    • integer dtype → torch.from_numpy(arr).long(),
    • float dtype → torch.from_numpy(arr).float().
  • Containers:
  • Mapping (e.g. dict): converts each value recursively, preserving keys.
  • Sequence (e.g. list, tuple): converts each element recursively and returns a Python list of tensors/converted items.

Any unsupported type will raise a TypeError.

Typical usage is at the end of a preprocessing pipeline, to convert a nested sample dictionary (coords, features, labels) from NumPy to tensors.

__call__(data)

Convert input data (and nested contents) to PyTorch tensors. Args: data: Arbitrary input to convert. Can be a scalar, NumPy array, tensor, mapping (e.g. dict), or sequence (e.g. list/tuple).

Returns:

Type Description
Any

Converted object where all supported leaves are PyTorch tensors,

Any

and the original container structure (dict/list) is preserved.

Raises:

Type Description
TypeError

If data (or some nested leaf) has a type that cannot be converted to a tensor.

FinalFeatures

Assemble a final feature tensor and manage bookkeeping fields in a sample dict.

This transform is typically used at the end of a preprocessing pipeline to:

  1. Build a unified feature array under the key "feat" by selecting and concatenating one or more existing fields from data_dict.
  2. Optionally remove some intermediate fields (e.g., "norm", auxiliary features) to save memory.
  3. Optionally add offset fields ("offset", "fps_offset") that are useful when batching variable-length point clouds.

Behavior:

  • Feature construction:
  • If feat is a string, data_dict["feat"] is set to data_dict[feat].
  • If feat is a list/tuple of strings, the corresponding arrays are concatenated along the last dimension:
    feat = np.concatenate([data_dict[name] for name in feat], axis=-1)
    

All specified feature names must exist in data_dict.

  • Field removal:
  • If remove is a string, that key is deleted from data_dict.
  • If remove is a list/tuple of strings, each corresponding key is deleted.
  • All specified keys must exist in data_dict.

  • Offsets:

  • If add_offset is True and "offset" is not already present, then:

    data_dict["offset"] = len(data_dict["coord"])
    

    This is often interpreted as the number of points in this sample. - If add_fps_offset is True and "fps_offset" is not present but "fps_index" exists, then:

    data_dict["fps_offset"] = len(data_dict["fps_index"])
    

    This is typically the number of FPS (farthest-point sampling) indices for this sample.

Parameters:

Name Type Description Default
feat str or sequence of str

Name(s) of fields in data_dict to be used as final features. If a sequence, the corresponding arrays are concatenated along the last dimension and stored in data_dict["feat"]. If None, no feature tensor is constructed. Defaults to "coord".

'coord'
remove str or sequence of str

Name(s) of fields to delete from data_dict after (optional) feature construction. This is useful to drop intermediate fields (e.g., "norm") that are no longer needed. If None, no keys are removed. Defaults to "norm".

'norm'
add_offset bool

If True and "offset" is not already present, add an integer offset equal to len(data_dict["coord"]). Defaults to True.

True
add_fps_offset bool

If True, "fps_offset" is not present, and "fps_index" exists, add an integer offset equal to len(data_dict["fps_index"]). Defaults to True.

True

__call__(data_dict)

Construct the final feature array and update bookkeeping fields.

Parameters:

Name Type Description Default
data_dict dict

Sample dictionary containing at least the keys referenced by self.feat (if not None), plus "coord" (used for offset) and optionally "fps_index" (used for fps_offset).

required

Returns:

Name Type Description
dict dict

The same dictionary, with: * a new "feat" field (if requested), * selected keys removed, * and optional "offset" / "fps_offset" fields added.