Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about chamfer distance formulation #20

Closed
bearprin opened this issue May 26, 2022 · 3 comments
Closed

Question about chamfer distance formulation #20

bearprin opened this issue May 26, 2022 · 3 comments

Comments

@bearprin
Copy link

Hi,

I have noticed your CD formulation in the main paper has the mean operator, but in the implementation without that. The formulation of implementation seems like # http://graphics.stanford.edu/courses/cs468-17-spring/LectureSlides/L14%20-%203d%20deep%20learning%20on%20point%20cloud%20representation%20(analysis).pdf that directly sum distance.

def _chamfer_distance_single_file(file_in, file_ref, samples_per_model, num_processes=1):
# http://graphics.stanford.edu/courses/cs468-17-spring/LectureSlides/L14%20-%203d%20deep%20learning%20on%20point%20cloud%20representation%20(analysis).pdf
import trimesh
import trimesh.sample
import sys
import scipy.spatial as spatial
def sample_mesh(mesh_file, num_samples):
try:
mesh = trimesh.load(mesh_file)
except:
return np.zeros((0, 3))
samples, face_indices = trimesh.sample.sample_surface_even(mesh, num_samples)
return samples
new_mesh_samples = sample_mesh(file_in, samples_per_model)
ref_mesh_samples = sample_mesh(file_ref, samples_per_model)
if new_mesh_samples.shape[0] == 0 or ref_mesh_samples.shape[0] == 0:
return file_in, file_ref, -1.0
leaf_size = 100
sys.setrecursionlimit(int(max(1000, round(new_mesh_samples.shape[0] / leaf_size))))
kdtree_new_mesh_samples = spatial.cKDTree(new_mesh_samples, leaf_size)
kdtree_ref_mesh_samples = spatial.cKDTree(ref_mesh_samples, leaf_size)
ref_new_dist, corr_new_ids = kdtree_new_mesh_samples.query(ref_mesh_samples, 1, n_jobs=num_processes)
new_ref_dist, corr_ref_ids = kdtree_ref_mesh_samples.query(new_mesh_samples, 1, n_jobs=num_processes)
ref_new_dist_sum = np.sum(ref_new_dist)
new_ref_dist_sum = np.sum(new_ref_dist)
chamfer_dist = ref_new_dist_sum + new_ref_dist_sum
return file_in, file_ref, chamfer_dist

Am I right?

Best

@bearprin bearprin changed the title Question about chamfer distance distance formulation Question about chamfer distance formulation May 26, 2022
@ErlerPhilipp
Copy link
Owner

@bearprin yes, you're right. The mean is essentially a normalization by number of points in the subsamples. Looks like i forgot it in the code. Also note that the shapes are asumed to be normalized to unit cube size to get comparable results.

If the number of points in the subsamples is always the same, the error will be off by a constant factor (10000) here. Because of the default optimization in trimesh's surface sampling, which rejects too close samples, the correct CD might be ~5% lower than stated in the paper. However, this should apply to all methods very similarly. I'm sorry for this inaccuracy. A PR would be very welcome.

@bearprin
Copy link
Author

bearprin commented May 26, 2022

Thanks for your reply!

The mean operator seems to have an important influence on the results because of the different formulations of CD.

I have noticed that since Neural-Pull claimed they could get 0.48 CD (Points2Surf gets 1.41 CD) under the FAMOUS no-noise dataset, which in contrast to my re-train results. And the new CVPR22 paper POCO gets 1.34 CD, which is still the same magnitude as Points2Surf. I am confused about what happened leading to 0.48 CD.

After that, I found Neural-Pull exploited the CD formulation of ConvONet with the additional mean operator, which significantly reduces the distance and makes the comparison seems unfair.

https://github.com/mabaorui/NeuralPull/blob/master/NeuralPull.py##L92-L138

@mabaorui

@ErlerPhilipp
Copy link
Owner

will improve this in the follow-up work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants