Chamfer Distance (CD) is a evaluation metric for two point clouds. It takes the distance of each points into account. For each point in each cloud, CD finds the nearest point in the other point set, and sums the square of distance up. It is utilized in Shapenet’s shape reconstruction challenge.
The chamfer distance between point cloud S1 and S2 is defined as
This readme is a guidance on how to compile the code for chamfer distance and a tutorial to use chamfer distance api.
GCC
5.4.0CUDA
9.0Python
2.7.12TensorFlow
1.7.0
The folder chamfer-distance
contains tensorflow module for chamfer-distance. To compile them, make sure tensorflow is installed. Then, modify the first 4 lines of chamfer-distance/Makefile
according to your environment. Finally, compile the chamfer-distance code
# From chamfer-distance/
make
To test the code, try
# From chamfer-distance/
python tf_nndistance.py
After compiling code for tensorflow, we can use the Chamfer Distance API now. Note the chamfer distance is defined as the sum of square of euclidean distance in the API. Try
python chamfer_test.py
which will calculate chamfer distance between point (1, 1, 1) and (1, 1, -1) and output [8.].
Generally, to use the api, use cd_api = Chamfer_distance()
to initialize the class, and then use cd_api.get_chamfer_distance(xyz1,xyz2)
to calculate the chamfer distance.
- The .cu and .cpp files are from PointSetGeneration
- The .py file is modified from shapenet iccv 2017
- Makefile is modified from pix3d and tensorflow: build_the_op_library