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

Implementation of 2 downsampling methods for Point Cloud - random_downsample; voxel_filter #334

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

YuqingLi-hub
Copy link

@YuqingLi-hub YuqingLi-hub commented Jan 29, 2024

The downsampling method is used to unify data size and reduce computational cost. Here, we implement two commonly used methods.

Random_downsample:
This function takes two arguments: a point cloud and the desired number of points after downsampling. It outputs a randomly selected downsampled point cloud.

Voxel_filter:
This function conducts voxel filtering on a provided point cloud. It has three arguments: the given point cloud, voxel size in three dimensions, and an optional boolean value that indicates whether to randomly select a point from each voxel as a representative or use the mean of all points in each voxel. The output is the downsampled point cloud, where each point serves as the representative point in its corresponding voxel.

@wang-chen
Copy link
Member

I can see the status of this PR is still in progress, if you are ready for review, please let me know.

@YuqingLi-hub YuqingLi-hub marked this pull request as ready for review February 2, 2024 02:15
@YuqingLi-hub
Copy link
Author

I can see the status of this PR is still in progress, if you are ready for review, please let me know.

Hi Wang Chen,
It's ready to review now.

pypose/function/geometry.py Outdated Show resolved Hide resolved
pypose/function/geometry.py Outdated Show resolved Hide resolved
pypose/function/geometry.py Outdated Show resolved Hide resolved
pypose/function/geometry.py Outdated Show resolved Hide resolved
pypose/function/geometry.py Outdated Show resolved Hide resolved
pypose/function/geometry.py Outdated Show resolved Hide resolved
pypose/function/geometry.py Show resolved Hide resolved
pypose/function/geometry.py Outdated Show resolved Hide resolved
pypose/function/geometry.py Outdated Show resolved Hide resolved
pypose/function/geometry.py Outdated Show resolved Hide resolved
@wang-chen
Copy link
Member

Hi, I renamed some names and tried to make these functions work for arbitrary dimensional space such 2D.
You also need to add auto tests for those functions, such as this test.

@wang-chen
Copy link
Member

Hi @YuqingLi-hub , Thank you so much for this update. The provided testing codes are to be working fine.
I tried the following test codes, it seems that they cannot run for batched tensors.

points = torch.randn(2, 10, 3)
num = 5
result = pp.geometry.random_filter(points, num)
result = pp.geometry.voxel_filter(points, [1., 1., 1.])

For random_filter, I changed to the following code, it seems working.

def random_filter(points, num):
    assert points.size(-1) >= 1, "The last dim of the points should not less than 1."
    assert num <= points.size(-2), "Number of points to sample must not larger than " \
        "the number of input points."
    
    indices = torch.randperm(points.size(-2))[:num]
    return points[..., indices, :]

I am not sure how to change voxel_filter, as we may need to change multiple places to make it to be compatible with batched operations.

@wang-chen
Copy link
Member

Until now, I have tried:
Change this line to

minp = torch.min(points[..., :dim], dim=-2, keepdim=True).values

this line to

voxel_counts = torch.zeros(unique_indices.shape[:-1], dtype=points.dtype)

You may want to access a specific dimension with negative numbers, as we may have multiple batches, e.g., points can be a shape of [... ,5,3], where ... can be any dimensions.

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

Successfully merging this pull request may close these issues.

None yet

3 participants