Giter Site home page Giter Site logo

poptree / chamferdist Goto Github PK

View Code? Open in Web Editor NEW

This project forked from krrish94/chamferdist

0.0 0.0 0.0 39 KB

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

License: Other

Python 26.65% Cuda 59.90% C++ 12.90% C 0.55%

chamferdist's Introduction

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},
}

chamferdist's People

Contributors

krrish94 avatar saryazdi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.