• Stars
    star
    290
  • Rank 142,981 (Top 3 %)
  • Language Cuda
  • License
    Other
  • Created about 5 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Pytorch package to compute Chamfer distance between point sets (pointclouds).

chamferdist: PyTorch Chamfer distance

NOTE: This implementation was stolen from the pytorch3d repo, and all I did was to simply repackage it.

krrish94

A simple example Pytorch module to compute Chamfer distance between two pointclouds.

Installation

You can install the package using pip.

pip install chamferdist

Building from source

In your favourite python/conda virtual environment, execute the following commands.

NOTE: This assumes you have PyTorch installed already (preferably, >= 1.5.0; untested for earlier releases).

python setup.py install

Running (example)

That's it! You're now ready to go. Here's a quick guide to using the package. Fire up a terminal. Import the package.

>>> import torch
>>> from chamferdist import ChamferDistance

Create two random pointclouds. Each pointcloud is a 3D tensor with dimensions batchsize x number of points x number of dimensions.

>>> source_cloud = torch.randn(1, 100, 3).cuda()
>>> target_cloud = torch.randn(1, 50, 3).cuda()

Initialize a ChamferDistance object.

>>> chamferDist = ChamferDistance()

Now, compute Chamfer distance.

>>> dist_forward = chamferDist(source_cloud, target_cloud)
>>> print(dist_forward.detach().cpu().item())

Here, dist is the Chamfer distance between source_cloud and target_cloud. Note that Chamfer distance is not bidirectional (and, in stricter parlance, it is not a distance metric).

The Chamfer distance in the backward direction, i.e., target_cloud to source_cloud can be computed in two ways. The naive way is to simply flip the order of the arguments, i.e.,

>>> dist_backward = chamferDist(target_cloud, source_cloud)

Another way is to use the reverse flag provided by the ChamferDistance module, i.e.,

>>> dist_backward = chamferDist(source_cloud, target_cloud, reverse=True)
>>> print(dist_backward.detach().cpu().item())

Typically, a symmetric version of the Chamfer distance is obtained, by summing the "forward" and the "backward" Chamfer distances. This is supported by the bidirectional flag.

>>> dist_bidirectional = chamferDist(source_cloud, target_cloud, bidirectional=True)
>>> print(dist_bidirectional.detach().cpu().item())

Look at the example script for more details: example.py

Citing (the original implementation, PyTorch3D)

If you find this work useful, you might want to cite the original implementation from which this codebase was borrowed (stolen!) - PyTorch3D.

@article{ravi2020pytorch3d,
    author = {Nikhila Ravi and Jeremy Reizenstein and David Novotny and Taylor Gordon
                  and Wan-Yen Lo and Justin Johnson and Georgia Gkioxari},
    title = {Accelerating 3D Deep Learning with PyTorch3D},
    journal = {arXiv:2007.08501},
    year = {2020},
}

More Repositories

1

nerf-pytorch

A PyTorch re-implementation of Neural Radiance Fields
Python
879
star
2

DeepVO

Implementation of DeepVO (ICRA 2017)
Python
67
star
3

dvo_python

Coding dense visual odometry in a little more than a night (yikes)!
Python
48
star
4

ComputerVisionReadingList

My reading list for topics in Computer Vision
45
star
5

ICRA2017

Code release for the ICRA 2017 paper "Reconstructing vehicles from a single image: shape priors for road scene understanding"
C++
38
star
6

sniffle-workshop

An easy-to-use jekyll theme for creating a workshop webpage (useful for AI / ML / CV / robotics folks)
SCSS
25
star
7

ENet-ScanNet

ENet for 2D semantic segmentation in ScanNet
Python
25
star
8

lseg-minimal

Minimal version of LSeg, based on https://github.com/isl-org/lang-seg
Python
20
star
9

CarKeypoints

Inference code for keypoint detection on cars
Lua
19
star
10

CTCNet-release

[DEPRECATED] Code release for the CVPR 2018 workshop paper titled "Geometric consistency for self-supervised end-to-end visual odometry"
Python
18
star
11

ToySfM

Simple tutorial scripts for learning Structure from Motion by implementation
MATLAB
12
star
12

DeepLearningResources

[DEPRECATED] My collection of Deep Learning Resources
12
star
13

OptimizationReadingList

10
star
14

MapLiteSeg-Devel

A w"hacky" road-segmentation network
Python
6
star
15

torch-self-intersection

A "minimal" package to compute self-intersections among various faces within a triangle-mesh.
Python
5
star
16

learn-cuda

A collection of scripts I wrote when learning CUDA C++ programming
Cuda
5
star
17

stacked-hourglass

Our modification of the stacked-hourglass architecture for car keypoint localization
Lua
4
star
18

Depth-Anything

Tiny tweak to depth-anything for Colab
Python
4
star
19

krrish94.github.io

My homepage
HTML
3
star
20

ASPnP_IRLS

MATLAB
3
star
21

dino-minimal

Python
2
star
22

ssc

Forked from sscnet https://github.com/shurans/sscnet
Jupyter Notebook
2
star
23

shapeAdjustment

Code release for the paper "Reconstructing Vehicles from a Single Image: Shape Priors for Road Scene Understanding" [yet-to-appear]
2
star
24

gaussian-splatting

My fork of gaussian splatting + expts
Python
2
star
25

bandu_planning

Python
2
star
26

RLReadingList

Reinforcement Learning Reading List
2
star
27

MotionAveraging

Implementation of variants of motion averaging methods.
1
star
28

ViewpointsAndKeypoints

My experiments with Shubham Tulsiani's work - Viewpoints and Keypoints [CVPR 2015]
MATLAB
1
star
29

caffe-keypoint

C++
1
star
30

SpinUp

Stuff I wrote when following the "Spinning Up in Deep RL" series by OpenAI
1
star
31

learn_tensorflow

Code I wrote when I was learning tensorflow
Python
1
star
32

PyTorch-experiments

My experiments with PyTorch
Python
1
star
33

commExplore

An implementation of the paper "Multi-Robot Exploration Under the Constraints of Wireless Networking" in Python
Python
1
star