Zac Boussaid
Zac Boussaid

Reputation: 45

map bilinear sampled features to voxel back

I am developing a class specifically for bilinear sampling. My goal is to map the features extracted from the bilinear sampling process to the appropriate locations within a created voxel grid.

Implementation steps:

B = batch

C = Channel

S = number of views 

D = depth 

H = height

W = width

3 = x,y,z

2 = x,y

i created a voxel with this shape [B,D,H,W,3] and i have 360 image view sample with dimesnion [B,S,C,H,W]

First step i projected the voxel points(point cloud) to each image using the extinsic and intrinsic. Then i filtered the points that are outside of the images.

As a results i got valid_points = [B,S,H,W,2]

i normalized my points from the valid_points and i created grids with size [B,S,H,W,2] please here notice that W is the number of valid points and H = 1

then what i did is i applied bilinear sampling as shown in the code :

valid_points = cur_coords[:, on_img[1]]
 
        ######### Normalize Valid Points Between [-1, 1] ########
        normalized_points = torch.zeros_like(valid_points)
        normalized_points[:,:, 0] = 2.0 * (valid_points[:, :, 0] / (H_img - 1)) - 1.0  # Normalize y-coordinates
        normalized_points[:,:, 1] = 2.0 * (valid_points[:, :, 1] / (W_img - 1)) - 1.0 # [N, M',2]

        grid = normalized_points.unsqueeze(1).cuda()  # Shape [S, H_out, W_out, 2]
        sampled_features_with_location_list  = []
        for i in range(0,N):
            img_s =camera_view_tensor[i].unsqueeze(0).permute(0, 3, 1, 2) #[B, C, H_in, W_in]
            grid_s = grid[i].unsqueeze(0)
            sampled_points = F.grid_sample(img_s, grid_s,mode='bilinear',
                                          align_corners=None) # (B,N,C,H_out,W_out)
            sampled_features_list.append(sampled_pointson)
sampled_points = torch.stack(sampled_features_list, dim=1) #[B = 1,S = 6,C= 3,H= 1,W =22965]

now i want to apply the inverse mapping to extract the bev feature. How to do it?

Upvotes: 1

Views: 32

Answers (0)

Related Questions