LION/third_party/ChamferDistancePytorch
2023-01-23 00:14:49 -05:00
..
chamfer2D init 2023-01-23 00:14:49 -05:00
chamfer3D init 2023-01-23 00:14:49 -05:00
chamfer5D init 2023-01-23 00:14:49 -05:00
chamfer6D init 2023-01-23 00:14:49 -05:00
.gitignore init 2023-01-23 00:14:49 -05:00
chamfer_python.py init 2023-01-23 00:14:49 -05:00
fscore.py init 2023-01-23 00:14:49 -05:00
LICENSE init 2023-01-23 00:14:49 -05:00
README.md init 2023-01-23 00:14:49 -05:00
unit_test.py init 2023-01-23 00:14:49 -05:00


Pytorch Chamfer Distance.

Include a CUDA version, and a PYTHON version with pytorch standard operations. NB : In this depo, dist1 and dist2 are squared pointcloud euclidean distances, so you should adapt thresholds accordingly.

  • F - Score

CUDA VERSION

  • JIT compilation
  • Supports multi-gpu
  • 2D point clouds.
  • 3D point clouds.
  • 5D point clouds.
  • Contiguous() safe.

Python Version

  • Supports any dimension

Usage

import torch, chamfer3D.dist_chamfer_3D, fscore
chamLoss = chamfer3D.dist_chamfer_3D.chamfer_3DDist()
points1 = torch.rand(32, 1000, 3).cuda()
points2 = torch.rand(32, 2000, 3, requires_grad=True).cuda()
dist1, dist2, idx1, idx2 = chamLoss(points1, points2)
f_score, precision, recall = fscore.fscore(dist1, dist2)

Add it to your project as a submodule

git submodule add https://github.com/ThibaultGROUEIX/ChamferDistancePytorch

Benchmark: [forward + backward] pass

  • CUDA 10.1, NVIDIA 435, Pytorch 1.4
  • p1 : 32 x 2000 x dim
  • p2 : 32 x 1000 x dim
Timing (sec * 1000) 2D 3D 5D
Cuda Compiled 1.2 1.4 1.8
Cuda JIT 1.3 1.4 1.5
Python 37 37 37
Memory (MB) 2D 3D 5D
Cuda Compiled 529 529 549
Cuda JIT 520 529 549
Python 2495 2495 2495

What is the chamfer distance ?

Stanford course on 3D deep Learning

Aknowledgment

Original backbone from Fei Xia.

JIT cool trick from Christian Diller

Troubleshoot

  • Undefined symbol: Zxxxxxxxxxxxxxxxxx :

--> Fix: Make sure to import torch before you import chamfer. --> Use pytorch.version >= 1.1.0

wget https://github.com/ninja-build/ninja/releases/download/v1.8.2/ninja-linux.zip
sudo unzip ninja-linux.zip -d /usr/local/bin/
sudo update-alternatives --install /usr/bin/ninja ninja /usr/local/bin/ninja 1 --force 

TODO:

  • Discuss behaviour of torch.min() and tensor.min() which causes issues in some pytorch versions