def forward(self, features, num_voxels, coors): device = features.device dtype = features.dtype # Find distance of x, y, and z from cluster center points_mean = features[:, :, :3].sum( dim=1, keepdim=True) / num_voxels.type_as(features).view(-1, 1, 1) f_cluster = features[:, :, :3] - points_mean # Find distance of x, y, and z from pillar center f_center = torch.zeros_like(features[:, :, :2]) f_center[:, :, 0] = features[:, :, 0] - ( coors[:, 3].to(dtype).unsqueeze(1) * self.vx + self.x_offset) f_center[:, :, 1] = features[:, :, 1] - ( coors[:, 2].to(dtype).unsqueeze(1) * self.vy + self.y_offset) # Combine together feature decorations features_ls = [features, f_cluster, f_center] if self._with_distance: points_dist = torch.norm(features[:, :, :3], 2, 2, keepdim=True) features_ls.append(points_dist) features = torch.cat(features_ls, dim=-1) # The feature decorations were calculated without regard to whether pillar was empty. Need to ensure that # empty pillars remain set to zeros. voxel_count = features.shape[1] mask = get_paddings_indicator(num_voxels, voxel_count, axis=0) mask = torch.unsqueeze(mask, -1).type_as(features) features *= mask # Forward pass through PFNLayers for pfn in self.pfn_layers: features = pfn(features) return features.squeeze()
def forward(self, features, num_voxels, coors): # print(coors.shape, num_voxels.shape, features.shape) # print(torch.max(num_voxels), torch.min(num_voxels), torch.mean(num_voxels.float()), num_voxels.shape) # print(torch.sum(num_voxels>=8).float()/num_voxels.shape[0]) device = features.device dtype = features.dtype # print(features.shape, num_voxels.shape, coors.shape) # print(coors[0]) # print(num_voxels[0]) # Find distance of x, y, and z from cluster center points_mean = features[:, :, :3].sum( dim=1, keepdim=True) / num_voxels.type_as(features).view(-1, 1, 1) f_cluster = features[:, :, :3] - points_mean # Find distance of x, y, and z from pillar center f_center = torch.zeros_like(features[:, :, :2]) f_center[:, :, 0] = features[:, :, 0] - ( coors[:, 3].to(dtype).unsqueeze(1) * self.vx + self.x_offset) f_center[:, :, 1] = features[:, :, 1] - ( coors[:, 2].to(dtype).unsqueeze(1) * self.vy + self.y_offset) # Combine together feature decorations features_ls = [features, f_cluster, f_center] if self._with_distance: points_dist = torch.norm(features[:, :, :3], 2, 2, keepdim=True) features_ls.append(points_dist) features_out = torch.cat(features_ls, dim=-1) # The feature decorations were calculated without regard to whether pillar was empty. Need to ensure that # empty pillars remain set to zeros. voxel_count = features_out.shape[1] mask = get_paddings_indicator(num_voxels, voxel_count, axis=0) mask = torch.unsqueeze(mask, -1).type_as(features_out) # print(torch.sum(features[:,:,:3] - (features*mask)[:,:,:3])) features_out = features_out * mask # Forward pass through PFNLayers for pfn in self.pfn_layers: # print(features.shape) # features = batch_process(features, pfn, num_batches=20) features_out = batch_process(features_out, pfn, num_batches=10) # features_out = pfn(features_out) # print(features.grad_fn) # print(mask) features_out = features_out * mask # print(mask.shape, features.shape) features_max = torch.max(features_out, dim=1, keepdim=True)[0] if pfn.last_vfe: features_out = features_max else: # features_max = torch.max(x, dim=1, keepdim=True)[0] features_repeat = features_max.repeat(1, features_out.shape[1], 1) features_out = torch.cat([features_out, features_repeat], dim=2) # print(features.shape) return features_out.squeeze()
def forward(self, features, num_voxels, coors, batch_size): #coors坐标 device = features.device dtype = features.dtype #float32 # Find distance of x, y, and z from cluster center 求x, y, z到聚类中心的距离 points_mean = features[:, :, :3].sum( dim=1, keepdim=True) / num_voxels.type_as(features).view(-1, 1, 1) aa = features[:, :, :3].sum(dim=1, keepdim=True) #每个柱子60个点相加,只加x,y,z bb = num_voxels.type_as(features).view(-1, 1, 1).shape f_cluster = features[:, :, :3] - points_mean # Find distance of x, y, and z from pillar center 求x, y, z到柱子中心的距离 f_center = torch.zeros_like(features[:, :, :2]) f_center[:, :, 0] = features[:, :, 0] - ( coors[:, 3].to(dtype).unsqueeze(1) * self.vx + self.x_offset) f_center[:, :, 1] = features[:, :, 1] - ( coors[:, 2].to(dtype).unsqueeze(1) * self.vy + self.y_offset) # Combine together feature decorations 组合特征装饰 if features.shape[2] == 4: features_ls = [features, f_cluster, f_center] #加上到中心点距离和到底面中心点距离变成9维度 if features.shape[2] == 6: features_ls = [features, f_cluster] if self._with_distance: #false points_dist = torch.norm(features[:, :, :3], 2, 2, keepdim=True) features_ls.append(points_dist) features = torch.cat(features_ls, dim=-1) #feature shape a = features.shape #torch.Size([50929, 60, 9]) #[3444,60,23]radar # The feature decorations were calculated without regard to whether pillar was empty. Need to ensure that # empty pillars remain set to zeros.特征装饰的计算不考虑柱子是否空。需要确保 # 空柱子仍然设置为零 voxel_count = features.shape[1] #一个柱子60的点 mask = get_paddings_indicator(num_voxels, voxel_count, axis=0) #根据voxel的点数设置mask mask = torch.unsqueeze(mask, -1).type_as(features) features *= mask #特征mask掩膜(60,9,41924) # Forward pass through PFNLayers for pfn in self.pfn_layers: features = pfn(features, batch_size) # print(features.shape) #[38093,1,64] return features.squeeze()
def forward(self, features, num_voxels, coors): # Find distance of x, y, and z from cluster center ## ref: https://github.com/traveller59/second.pytorch/issues/144 num_voxels_set_0_to_1 = num_voxels.clone() num_voxels_set_0_to_1[num_voxels_set_0_to_1 == 0] = 1 points_mean = features[:, :, :3].sum( dim=1, keepdim=True) / num_voxels_set_0_to_1.type_as(features).view( -1, 1, 1) #points_mean = features[:, :, :3].sum(dim=1, keepdim=True) / num_voxels.type_as(features).view(-1, 1, 1) f_cluster = features[:, :, :3] - points_mean # Find distance of x, y, and z from pillar center f_center = torch.zeros_like(features[:, :, :2]) f_center[:, :, 0] = features[:, :, 0] - ( coors[:, 3].float().unsqueeze(1) * self.vx + self.x_offset) f_center[:, :, 1] = features[:, :, 1] - ( coors[:, 2].float().unsqueeze(1) * self.vy + self.y_offset) # Combine together feature decorations features_ls = [features, f_cluster, f_center] if self._with_distance: points_dist = torch.norm(features[:, :, :3], 2, 2, keepdim=True) features_ls.append(points_dist) features = torch.cat(features_ls, dim=-1) # The feature decorations were calculated without regard to whether pillar was empty. Need to ensure that # empty pillars remain set to zeros. voxel_count = features.shape[1] mask = get_paddings_indicator(num_voxels, voxel_count, axis=0) mask = torch.unsqueeze(mask, -1).type_as(features) features *= mask ## (N,60,9) ##(N,100,9) features = self.VoxelFeature_TA(points_mean, features) # Forward pass through PFNLayers for pfn in self.pfn_layers: features = pfn(features) return features.squeeze()