edwardzhou130 / PolarSeg

Implementation for PolarNet: An Improved Grid Representation for Online LiDAR Point Clouds Semantic Segmentation (CVPR 2020)
BSD 3-Clause "New" or "Revised" License
369 stars 80 forks source link

def grp_range_torch in ptbev.py #53

Open zoomin-lee opened 2 years ago

zoomin-lee commented 2 years ago

Hi author, thanks you for your great work:)

I am trying to understand your grp_range_torch(random sampling at ptbev.py) through the toy example. But I couldn't understand what process it was. Can you explain it on this toy example? Or is there an equation in which this is implemented?

2022-05-24_10 29 13

Thanks

YangZhang4065 commented 2 years ago

Sorry for the late reply! Before jumping into the details, the idea of grp_range_torch is to generate range indices for points within each grid using vectorized operation. So that we can sample points within each grid/ pillar and make sure each grid has no more than self.max_pt points later easily.

This is equal to using a for loop to loop thru all points and only pick n points within each grid but more efficiently.

Going back to your case, you have grp_ind output grp_ind image

image

and the output of the unique function unq_inv, which is basically the grid index of each point.

image

As you can see, unq_inv[1], unq_inv[5], and unq_inv[12] are all 5. This means these 3 points belong to the same grid (grid index 5). Thus grp_ind[0], grp_ind[5] and grp_ind[12] are 1, 2,3, meaning these 3 points are the 1st, 2nd, and 3rd points in the same cell.

Later on, you can use a[grp_ind < 2] to subsample 2 points from each grid.