waxmorph.torch.losses.chamfer_distance

waxmorph.torch.losses.chamfer_distance#

waxmorph.torch.losses.chamfer_distance(X_pred, X_target)[source]#

Sum of directional mean nearest-neighbor distances.

\[\mathcal{L} = \frac{1}{N}\sum_i \min_j \lVert X^f_i - X^T_j \rVert + \frac{1}{M}\sum_j \min_i \lVert X^f_i - X^T_j \rVert\]

The loss is permutation-invariant, permits unequal cloud sizes, and uses Euclidean distances. Nearest-neighbor ties are nonsmooth; torch.min routes the derivative through its selected index. Inputs must be nonempty rank-2 arrays with equal feature width.

Examples

>>> x = torch.tensor([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0]])
>>> y = torch.tensor([[0.0, 0.0, 0.0], [2.0, 0.0, 0.0]])
>>> print(chamfer_distance(x, y))
tensor(1.)
Parameters:
Return type:

Tensor