open3d.ml.tf.models.voxel_pooling

open3d.ml.tf.models.voxel_pooling(positions, features, voxel_size, position_fn='average', feature_fn='average', debug=False, name=None)

Spatial pooling for point clouds by combining points that fall into the same voxel bin.

The voxel grid used for pooling is always aligned to the origin (0,0,0) to simplify building voxel grid hierarchies. The order of the returned voxels is not defined as can be seen in the following example:

import open3d.ml.tf as ml3d

positions = [
    [0.1,0.1,0.1],
    [0.5,0.5,0.5],
    [1.7,1.7,1.7],
    [1.8,1.8,1.8],
    [0.3,2.4,1.4]]

features = [[1.0,2.0],
            [1.1,2.3],
            [4.2,0.1],
            [1.3,3.4],
            [2.3,1.9]]

ml3d.ops.voxel_pooling(positions, features, 1.0,
                       position_fn='center', feature_fn='max')

# or with pytorch
import torch
import open3d.ml.torch as ml3d

positions = torch.Tensor([
    [0.1,0.1,0.1],
    [0.5,0.5,0.5],
    [1.7,1.7,1.7],
    [1.8,1.8,1.8],
    [0.3,2.4,1.4]])

features = torch.Tensor([
            [1.0,2.0],
            [1.1,2.3],
            [4.2,0.1],
            [1.3,3.4],
            [2.3,1.9]])

ml3d.ops.voxel_pooling(positions, features, 1.0,
                       position_fn='center', feature_fn='max')

# returns the voxel centers  [[0.5, 2.5, 1.5],
#                             [1.5, 1.5, 1.5],
#                             [0.5, 0.5, 0.5]]
# and the max pooled features for each voxel [[2.3, 1.9],
#                                             [4.2, 3.4],
#                                             [1.1, 2.3]]
Parameters
  • positions – A Tensor. Must be one of the following types: float32, float64. The point positions with shape [N,3] with N as the number of points.

  • features – A Tensor. Must be one of the following types: float32, float64, int32, int64. The feature vector with shape [N,channels].

  • voxel_size – A Tensor. Must have the same type as positions. The voxel size.

  • position_fn

    An optional string from: “average”, “nearest_neighbor”, “center”. Defaults to “average”. Defines how the new point positions will be computed. The options are

    • ”average” computes the center of gravity for the points within one voxel.

    • ”nearest_neighbor” selects the point closest to the voxel center.

    • ”center” uses the voxel center for the position of the generated point.

  • feature_fn

    An optional string from: “average”, “nearest_neighbor”, “max”. Defaults to “average”. Defines how the pooled features will be computed. The options are

    • ”average” computes the average feature vector.

    • ”nearest_neighbor” selects the feature vector of the point closest to the voxel center.

    • ”max” uses the maximum feature among all points within the voxel.

  • debug – An optional bool. Defaults to False. If true additional checks for debugging will be enabled.

  • name – A name for the operation (optional).

Returns

A tuple of Tensor objects (pooled_positions, pooled_features).

pooled_positions: A Tensor. Has the same type as positions. The output point positions with shape [M,3] and M <= N. pooled_features: A Tensor. Has the same type as features. The output point features with shape [M,channnels] and M <= N.