Pointnet_Pointnet2_pytorch icon indicating copy to clipboard operation
Pointnet_Pointnet2_pytorch copied to clipboard

Index out of bounds

Open vienngo opened this issue 2 years ago • 3 comments

https://github.com/yanx27/Pointnet_Pointnet2_pytorch/blob/eb64fe0b4c24055559cea26299cb485dcb43d8dd/models/pointnet2_utils.py#L102

vienngo avatar Jan 02 '23 15:01 vienngo

It would be more correct to assign this index to (N - 1)

vienngo avatar Jan 02 '23 15:01 vienngo

Actually, as your issue's title, N means index out of bounds, or in another word, index not belonging to the specific group, it would be substitued by the nearest point to the centroids with the code below.

   # 升序排序,排序后较大值位于数组最后,将前nsample个点直接取出
   # upper-sorted 
    group_idx = group_idx.sort(dim=-1)[0][:, :, :nsample]   # size(B, S, N)->(B, S, nsample)

    # 考虑可能前nsample个点也有被赋值为N的点(即球形区域内不足nsample个点),这种点first_point需要舍弃,用第一个点(离中心点最近的那个点)
    # substitute the points with index = *N*, which happens when the point-ball group has insufficient  point(less than nsample)
    # Step1. 找出当前group_idx(size:[B, S, nsample]) 值等于N的点,即舍弃点的位置
    mask = group_idx == N
    # Step2. 构造group_first数组->Size[B, S, nsample],其中[b, s, :]存储的是第b个batch,第s组中心点群的first_point(相当于group_idx[:, :, 0]复制nsample份)
    group_first = group_idx[:, :, 0].view(B, S, 1).repeat(1, 1, nsample)
    # Step3. 将group_idx中的舍弃点替换为first_point
    group_idx[mask] = group_first[mask]

So, it would always be right for then sorting and  substituting only if assigning `group_idx[sqrdists > radius ** 2]` with a very big number! Try it!

Jonnoy-Gates avatar Mar 04 '23 09:03 Jonnoy-Gates

See https://github.com/yanx27/Pointnet_Pointnet2_pytorch/issues/178#issuecomment-1587086798

jasonkena avatar Jun 12 '23 10:06 jasonkena