kaolin.metrics.pointcloud

API

kaolin.metrics.pointcloud.chamfer_distance(p1, p2, w1=1.0, w2=1.0, squared=True)

Computes the chamfer distance between two pointclouds, defined as following:

\(\dfrac{w_1}{|P_1|}\sum\limits_{p_{1i} \in P_1}\min\limits_{p_{2j} \in P_2}(||p_{1i} - p_{2j}||_2^2) + \dfrac{w_2}{|P_2|}\sum\limits_{p_{2j} \in P_2}\min\limits_{p_{1i} \in P_1}(||p_{2j} - p_{1i}||_2^2)\)

Parameters
  • p1 (torch.Tensor) – Pointclouds, of shape \((\text{batch_size}, \text{num_points1}, 3)\).

  • p2 (torch.Tensor) – Pointclouds, of shape \((\text{batch_size}, \text{num_points2}, 3)\).

  • w1 (float, optional) – Weighting of forward direction. Default: 1.

  • w2 (float, optional) – Weighting of backward direction. Default: 1.

  • squared (bool, optional) – Use the squared sided distance. Default: True.

Returns

Chamfer distance between two pointclouds p1 and p2, of shape \((\text{batch_size})\).

Return type

(torch.Tensor)

Example

>>> p1 = torch.tensor([[[8.8977, 4.1709, 1.2839],
...                     [8.5640, 7.7767, 9.4214]],
...                    [[0.5431, 6.4495, 11.4914],
...                     [3.2126, 8.0865, 3.1018]]], device='cuda', dtype=torch.float)
>>> p2 = torch.tensor([[[6.9340, 6.1152, 3.4435],
...                     [0.1032, 9.8181, 11.3350]],
...                    [[11.4006, 2.2154, 7.9589],
...                     [4.2586, 1.4133, 7.2606]]], device='cuda', dtype=torch.float)
>>> chamfer_distance(p1, p2)
tensor([ 72.5838, 151.0809], device='cuda:0')
kaolin.metrics.pointcloud.f_score(gt_points, pred_points, radius=0.01, eps=1e-08)

Computes the f-score of two sets of points, with a hit defined by two point existing within a defined radius of each other.

Parameters
  • gt_points (torch.Tensor) – Ground truth pointclouds, of shape \((\text{batch_size}, \text{num_gt_points}, 3)\).

  • pred_points (torch.Tensor) – Predicted points pointclouds, of shape \((\text{batch_size}, \text{num_points}, 3)\).

  • radius (float) – Radius from a point to define a hit. Default: 0.01

  • eps (float) – Epsilon used to calculate f score. Default: 1e-8.

Returns

Computed f-score tensor of shape \((\text{batch_size})\), of same dtype as input pred_points.

Return type

(torch.Tensor)

Example

>>> p1 = torch.tensor([[[8.8977, 4.1709, 1.2839],
...                     [8.5640, 7.7767, 9.4214]],
...                    [[0.5431, 6.4495, 11.4914],
...                     [3.2126, 8.0865, 3.1018]]], device='cuda', dtype=torch.float)
>>> p2 = torch.tensor([[[9.4863, 4.2249, 0.1712],
...                     [8.1783, 8.5310, 8.5119]],
...                    [[-0.0020699, 6.4429, 12.3],
...                     [3.8386, 8.3585, 4.7662]]], device='cuda', dtype=torch.float)
>>> f_score(p1, p2, radius=1)
tensor([0.0000, 0.5000], device='cuda:0')
>>> f_score(p1, p2, radius=1.5)
tensor([1.0000, 0.5000], device='cuda:0')
kaolin.metrics.pointcloud.sided_distance(p1, p2)

For each point in \(p_{1i} \in P_1\) will find the indices and squared euclidean distances of the closest point \(P_2\), as following:

\(\text{sided_distance}(p_{1i}, P_2) = \min\limits_{p_{2j}\in{P_2}}(||p_{1i} - p_{2j}||_2^2)\)

Parameters
  • p1 (torch.Tensor) – Pointclouds, of shape \((\text{batch_size}, \text{num_points1}, 3)\).

  • p2 (torch.Tensor) – Pointclouds, of shape \((\text{batch_size}, \text{num_points2}, 3)\).

Returns

The indices and distances from points in p1 to the corresponding closest points in p2, both have shape of \((\text{batch_size}, \text{num_points1})\).

Return type

(torch.Tensor, torch.Tensor)

Example

>>> p1 = torch.tensor([[[5.9336, 4.9742, 8.1047]],
...                    [[4.1939, 3.3612, 9.5407]]], device='cuda', dtype=torch.float)
>>> p2 = torch.tensor([[[1.6998, 0.7719, 2.9987],
...                     [0.1812, 8.9342, 10.0285]],
...                    [[10.0184, 0.3928, 5.2545],
...                     [4.2934, 11.2127, 4.5247]]], device='cuda', dtype=torch.float)
>>> distance, idx = sided_distance(p1, p2)
>>> distance
tensor([[52.4727],
        [61.1077]], device='cuda:0')
>>> idx
tensor([[1],
        [0]], device='cuda:0')