Open Varatharajan-Raja opened 1 year ago
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.
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
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? :sleepy:@serend1p1ty @Xu2729
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.
Thx for your kind reply ~! It's help a lot. @Xu2729 I think our code is consistent. :joy: 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
Kindly clarify me few questions about the Range aware masking.
voxel_coords_distance = (voxel_coords[:,2]**2 + voxel_coords[:,3]**2)**0.5