def generate_training_labels(pts_rect, gt_boxes3d): cls_label = np.zeros((pts_rect.shape[0]), dtype=np.int32) gt_corners = kitti_utils.boxes3d_to_corners3d(gt_boxes3d, rotate=True) extend_gt_boxes3d = kitti_utils.enlarge_box3d(gt_boxes3d, extra_width=0.2) extend_gt_corners = kitti_utils.boxes3d_to_corners3d(extend_gt_boxes3d, rotate=True) for k in range(gt_boxes3d.shape[0]): box_corners = gt_corners[k] fg_pt_flag = kitti_utils.in_hull(pts_rect, box_corners) #kasba = 0 #for i in range(len(fg_pt_flag)): # if(fg_pt_flag[i]==True): # kasba = kasba +1 #print("kasba",kasba) cls_label[fg_pt_flag] = 1 # enlarge the bbox3d, ignore nearby points extend_box_corners = extend_gt_corners[k] fg_enlarge_flag = kitti_utils.in_hull(pts_rect, extend_box_corners) ignore_flag = np.logical_xor(fg_pt_flag, fg_enlarge_flag) cls_label[ignore_flag] = -1 return cls_label
def roipool3d_cpu(boxes3d, pts, pts_feature, pts_extra_input, pool_extra_width, sampled_pt_num=512, canonical_transform=True): """ :param boxes3d: (N, 7) :param pts: (N, 3) :param pts_feature: (N, C) :param pts_extra_input: (N, C2) :param pool_extra_width: constant :param sampled_pt_num: constant :return: """ pooled_boxes3d = kitti_utils.enlarge_box3d(boxes3d, pool_extra_width) pts_feature_all = np.concatenate((pts_extra_input, pts_feature), axis=1) # Note: if pooled_empty_flag[i] > 0, the pooled_pts[i], pooled_features[i] will be zero pooled_pts, pooled_features, pooled_empty_flag = \ roipool_pc_cpu(torch.from_numpy(pts), torch.from_numpy(pts_feature_all), torch.from_numpy(pooled_boxes3d), sampled_pt_num) extra_input_len = pts_extra_input.shape[1] sampled_pts_input = torch.cat((pooled_pts, pooled_features[:, :, 0:extra_input_len]), dim=2).numpy() sampled_pts_feature = pooled_features[:, :, extra_input_len:].numpy() if canonical_transform: # Translate to the roi coordinates roi_ry = boxes3d[:, 6] % (2 * np.pi) # 0~2pi roi_center = boxes3d[:, 0:3] # shift to center sampled_pts_input[:, :, 0:3] = sampled_pts_input[:, :, 0:3] - roi_center[:, np.newaxis, :] for k in range(sampled_pts_input.shape[0]): sampled_pts_input[k] = kitti_utils.rotate_pc_along_y(sampled_pts_input[k], roi_ry[k]) return sampled_pts_input, sampled_pts_feature return sampled_pts_input, sampled_pts_feature, pooled_empty_flag.numpy()