facebookresearch / pytorch3d

PyTorch3D is FAIR's library of reusable components for deep learning with 3D data
https://pytorch3d.org/
Other
8.81k stars 1.32k forks source link

chamfer_distance off by a factor 2 #1548

Closed alecjacobson closed 1 year ago

alecjacobson commented 1 year ago

🐛 Bugs / Unexpected behaviors

Squared distance between (0,0) and (3,0) should be 9 not 18.

Instructions To Reproduce the Issue:

from pytorch3d.loss import chamfer_distance 
import torch 
print(chamfer_distance(torch.tensor([[0.0,0.0]]).unsqueeze(1), torch.tensor([[3.0,0.0]]).unsqueeze(1)))

produces

(tensor(18.), None)

In general, chamfer_distance appears to be computing 2*mean-squared-distance.

bottler commented 1 year ago

The chamfer distance op calculates two-sided / symmetrical / bidirectional chamfer distance, so it's looking at the distance from each point in each cloud to its nearest point in the other cloud. If the two clouds each have one point, then yes, you'll get their distance twice.