ma-xu / pointMLP-pytorch

[ICLR 2022 poster] Official PyTorch implementation of "Rethinking Network Design and Local Geometry in Point Cloud: A Simple Residual MLP Framework"

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Farthest point sampling torch implementation

plpplp opened this issue · comments

Farthest point sampling torch implementation

`` @mahaotian-io Hi, they are the same, but the self-defined function defined farthest_point_sample is in python and .furthest_point_sample is in cuda. We use the cuda version for fast training and inference.

Originally posted by @ma-xu in #47 (comment)

Hi, I just checked the function farthest_point_sample and I think it works a little bit different than one might expect. I wonder if farthest_point_sample works as intended. The difference in my quick numpy implementation of fps (furthest_point_sampling) is that I keep track of which points have already been sampled when calculating distances.

I just tested the code of this repo with the below lines and the sampled points of this repo seem to cover the point set not that good.

import torch
xyz = torch.randint(0, 30000, (10, 1000, 3)).contiguous()

num_samples = 50

fps = farthest_point_sample(xyz, num_samples)
fps = index_points(xyz, fps).numpy()

red, green, blue = [1., 0., 0.], [0., 1., 0.], [0., 0., 1.]

# only plot first sample of batch
plt.scatter(xyz[0, :, 0], xyz[0, :, 1], c=blue)
plt.scatter(fps[0, :, 0], fps[0, :, 1], c=red, label='fps, pointMLP')

nfps = furthest_point_sampling(xyz[0, :, :2].numpy(), num_samples)
plt.scatter(nfps[:, 0], nfps[:, 1], c=green, label='fps')
plt.legend()

I will add a plot later, github seems to have trouble accepting my file upload currently.

commented

@plpplp Hi, thanks for the detailed information.

The python function farthest_point_sample is from https://github.com/yanx27/Pointnet_Pointnet2_pytorch/blob/eb64fe0b4c24055559cea26299cb485dcb43d8dd/models/pointnet2_utils.py#L63

The cuda function furthest_point_sample is from https://github.com/erikwijmans/Pointnet2_PyTorch

We use the cuda function furthest_point_sample for our implementation (the python function farthest_point_sample is used for debug and development in local Mac).

Feel free to add a plot later (you can copy a link to the figure and codes) and that would be much helpful to check if any issues.

Hey, thankts for the quick response. Here is the code for the numpy version of fps.
And this if the plot that compares the sampling on random points in 2d:
fps
In red are the sampled points using the implementation of this repository. In green the quick implementation from above of fps that covers the randomly generated point set somewhat better. It probably is fine though if the function is meant for debugging purposes only. I thought I could use it for a rather small dataset so that I do not have to compile those kernels for my initial tests.

Algo seems to work fine, my bad, I made the mistake to calculate the 3d distance of the points and projected them onto the 2d plane in my plot to compare the two implementations. Thanks :).

commented

Thanks, very interesting and also very helpful to see the selected points.