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

Understanding Range Aware Masking? #28

Open
Varatharajan-Raja opened this issue Mar 11, 2023 · 5 comments
Open

Understanding Range Aware Masking? #28

Varatharajan-Raja opened this issue Mar 11, 2023 · 5 comments

Comments

@Varatharajan-Raja
Copy link

Varatharajan-Raja commented Mar 11, 2023

Kindly clarify me few questions about the Range aware masking.

  1. How is the distance calculated with voxel coordinates? If I'm right voxel coordinates should have size N x 4 i.e [Batch, z_idx , y_idx ,x_idx] after the voxelization.
  2. Furthermore, where do you have the center of the point cloud scene which you should consider as origin so that you take it as a reference to do a range aware masking? See here

voxel_coords_distance = (voxel_coords[:,2]**2 + voxel_coords[:,3]**2)**0.5

@serend1p1ty
Copy link

voxel_coords_distance = (
            ((voxel_coords[:, 2] - self.sparse_shape[1] / 2) * self.voxel_size[1])**2 +
            ((voxel_coords[:, 3] - self.sparse_shape[2] / 2) * self.voxel_size[0])**2)**0.5

I think the above is right code.

@Xu2729
Copy link

Xu2729 commented Dec 15, 2023

Perhaps we should consider the impact of point_cloud_range, and I think this is correct

voxel_coords = (voxel_indices[:, 1:] * voxel_size) + point_cloud_range + (voxel_size * 0.5)    # z, y, x
voxel_coords_distance = (voxel_coords[:,1]**2 + voxel_coords[:,2]**2)**0.5

@huixiancheng
Copy link

def __init__():
        self.voxel_size = voxel_size[::-1]
        self.point_cloud_range = point_cloud_range[:3][::-1]

def forward():
        voxel_coords = (voxel_coords[:, 1:] * self.voxel_size) + self.point_cloud_range + (self.voxel_size * 0.5)    # z, y, x
        voxel_coords_distance = (voxel_coords[:,1]**2 + voxel_coords[:,2]**2)**0.5

For all code mentioned above, Like this finally? 😪@serend1p1ty @Xu2729

@Xu2729
Copy link

Xu2729 commented Dec 18, 2023

def __init__():
        self.voxel_size = voxel_size[::-1]
        self.point_cloud_range = point_cloud_range[:3][::-1]

def forward():
        voxel_coords = (voxel_coords[:, 1:] * self.voxel_size) + self.point_cloud_range + (self.voxel_size * 0.5)    # z, y, x
        voxel_coords_distance = (voxel_coords[:,1]**2 + voxel_coords[:,2]**2)**0.5

For all code mentioned above, Like this finally? 😪@serend1p1ty @Xu2729

This looks logically correct, but it will actually cause a TypeError when running. You need to convert these variables to tensors before performing the operation. I solved it using the following code

def forward():
    # ...
    voxel_size_ts = torch.tensor(self.voxel_size[::-1], device=voxel_indices.device)
    point_cloud_range_ts = torch.tensor(list(self.point_cloud_range)[0:3][::-1], device=voxel_indices.device)
    voxel_coords = (voxel_indices[:, 1:] * voxel_size_ts) + point_cloud_range_ts + (voxel_size_ts * 0.5)
    voxel_coords_distance = (voxel_coords[:,1]**2 + voxel_coords[:,2]**2)**0.5
    # ...

I wanted to put voxel_size_ts and point_cloud_range_ts into the __init__ function, but they are tensors on different devices error. I couldn't find a better solution, so I put them in forward function instead.

I print the number of voxels in each range, and it looks correct.

@huixiancheng
Copy link

Thx for your kind reply ~! It's help a lot. @Xu2729
I think our code is consistent. 😂 I thought overriding and updating voxel_coords might have problems.

voxel_size = torch.tensor(self.voxel_size[::-1]).to(voxel_coords.device)
point_cloud_range = torch.tensor(self.point_cloud_range[:3][::-1].copy()).to(voxel_coords.device)
voxel_range = (voxel_coords[:, 1:] * voxel_size) + point_cloud_range + (voxel_size * 0.5)    # z, y, x
voxel_coords_distance = (voxel_range[:,1]**2 + voxel_range[:,2]**2)**0.5

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

4 participants