def get_batch_stats(self): ori_centers = np.array(self.ori_centers) ori_heading_classes = np.array(self.ori_heading_classes) ori_heading_residuals = np.array(self.ori_heading_residuals) ori_size_classes = np.array(self.ori_size_classes) ori_size_residuals = np.array(self.ori_size_residuals) del_centers = np.array(self.del_centers) del_heading_classes = np.array(self.del_heading_classes) del_heading_residuals = np.array(self.del_heading_residuals) del_size_classes = np.array(self.del_size_classes) del_size_residuals = np.array(self.del_size_residuals) y_centers = np.array(self.y_centers) y_heading_classes = np.array(self.y_heading_classes) y_heading_residuals = np.array(self.y_heading_residuals) y_size_classes = np.array(self.y_size_classes) y_size_residuals = np.array(self.y_size_residuals) y_clses = np.array(self.y_clses) assert(ori_centers.shape == del_centers.shape == y_centers.shape) assert(ori_size_classes.shape == del_size_classes.shape) assert(len(ori_centers) == len(del_centers) == len(y_centers) == len(y_clses)) iou3ds_ori, iou3ds_del = [], [] for i in range(len(ori_centers)): ori_lwh = class2size(ori_size_classes[i], ori_size_residuals[i]) ori_ry = class2angle(ori_heading_classes[i], ori_heading_residuals[i], 12) ori_box3d = get_3d_box(ori_lwh, ori_ry, ori_centers[i]) del_lwh = class2size(del_size_classes[i], del_size_residuals[i]) del_ry = class2angle(del_heading_classes[i], del_heading_residuals[i], 12) del_box3d = get_3d_box(del_lwh, del_ry, del_centers[i]) y_lwh = class2size(y_size_classes[i], y_size_residuals[i]) y_ry = class2angle(y_heading_classes[i], y_heading_residuals[i], 12) y_box3d = get_3d_box(y_lwh, y_ry, y_centers[i]) ori_iou3d, _ = box3d_iou(y_box3d, ori_box3d) del_iou3d, _ = box3d_iou(y_box3d, del_box3d) iou3ds_ori.append(ori_iou3d) iou3ds_del.append(del_iou3d) iou3ds_ori = np.array(iou3ds_ori) iou3ds_del = np.array(iou3ds_del) stats = {} for c in range(self.num_classes): is_curr_class = (y_clses == c) support = np.sum(is_curr_class) if support == 0: continue iou3ds_ori_curr_class = iou3ds_ori[is_curr_class,...] iou3ds_del_curr_class = iou3ds_del[is_curr_class,...] mean_iou3d_ori = np.mean(iou3ds_ori_curr_class) mean_iou3d_del = np.mean(iou3ds_del_curr_class) change_in_iou3d = mean_iou3d_del - mean_iou3d_ori stats[self.classes[c]] = (mean_iou3d_ori, mean_iou3d_del, change_in_iou3d, support) return stats
def compute_proposal_recall(batch_pred_boxes, batch_gt_boxes, nms_indices, iou_threshold=0.5): ''' Inputs: batch_pred_boxes: (B,FG_POINT_NUM,8,3) batch_gt_boxes: (B,?,8,3) nms_indices: (B,FG_POINT_NUM) valid indices are those != -1 Outputs: Average recall of every sample: float ''' total_recall = 0 total_labels = 0 for pred_boxes, gt_boxes, ind in zip(batch_pred_boxes, batch_gt_boxes, nms_indices): ind = ind[ind != -1] pred_boxes = pred_boxes[ind] # pred after nms recall = np.zeros((len(gt_boxes), )) for i, gt_box in enumerate(gt_boxes): for pred_box in pred_boxes: iou_3d, iou_2d = box3d_iou(pred_box, gt_box) if iou_2d > iou_threshold: recall[i] = 1 break total_recall += np.sum(recall) total_labels += len(gt_boxes) if total_labels == 0: return 1.0 return float(total_recall) / total_labels
def get_iou(bb1, bb2): """ Compute IoU of two bounding boxes. ** Define your bod IoU function HERE ** """ #pass iou3d, iou2d = box3d_iou(bb1, bb2) return iou3d
def compute_box3d_iou(center_pred, angle_cls_pred, angle_res_pred, size_res_pred, center_label, angle_cls_label, angle_res_label, size_res_label): batch_size = angle_cls_pred.shape[0] angle_cls = np.argmax(angle_cls_pred, 1) # B angle_res = np.array( [angle_res_pred[i, angle_cls[i]] for i in range(batch_size)]) # B, size_res = np.vstack([size_res_pred[i, :] for i in range(batch_size)]) iou2d_list = [] iou3d_list = [] for i in range(batch_size): heading_angle = class2angle(angle_cls[i], angle_res[i]) box_size = class2size(size_res[i]) corners_3d = get_3d_box(box_size, heading_angle, center_pred[i]) heading_angle_label = class2angle(angle_cls_label[i], angle_res_label[i]) box_size_label = class2size(size_res_label[i]) corners_3d_label = get_3d_box(box_size_label, heading_angle_label, center_label[i]) iou_3d, iou_2d = box3d_iou(corners_3d, corners_3d_label) iou3d_list.append(iou_3d) iou2d_list.append(iou_2d) return np.array(iou2d_list, dtype=np.float32), \ np.array(iou3d_list, dtype=np.float32)
def compute_box3d_iou(center_pred, heading_logits, heading_residuals, size_logits, size_residuals, center_label, heading_class_label, heading_residual_label, size_class_label, size_residual_label): ''' Compute 3D bounding box IoU from network output and labels. All inputs are numpy arrays. Inputs: center_pred: (B,3) heading_logits: (B,NUM_HEADING_BIN) heading_residuals: (B,NUM_HEADING_BIN) size_logits: (B,NUM_SIZE_CLUSTER) size_residuals: (B,3,NUM_SIZE_CLUSTER) !! center_label: (B,3) heading_class_label: (B,) heading_residual_label: (B,) size_class_label: (B,) size_residual_label: (B,3) Output: iou2ds: (B,) birdeye view oriented 2d box ious iou3ds: (B,) 3d box ious ''' # change the dataformat from torch style to tensorflow styleim size_residuals = size_residuals.transpose(0,2,1) # size_residuals = size_residuals.permute(0,2,1) batch_size = heading_logits.shape[0] heading_class = np.argmax(heading_logits, 1) # B heading_residual = np.array([heading_residuals[i,heading_class[i]] \ for i in range(batch_size)]) # B, size_class = np.argmax(size_logits, 1) # B size_residual = np.vstack([size_residuals[i,size_class[i],:] \ for i in range(batch_size)]) iou2d_list = [] iou3d_list = [] for i in range(batch_size): heading_angle = class2angle(heading_class[i], heading_residual[i], NUM_HEADING_BIN) box_size = class2size(size_class[i], size_residual[i]) corners_3d = get_3d_box(box_size, heading_angle, center_pred[i]) heading_angle_label = class2angle(heading_class_label[i], heading_residual_label[i], NUM_HEADING_BIN) box_size_label = class2size(size_class_label[i], size_residual_label[i]) corners_3d_label = get_3d_box(box_size_label, heading_angle_label, center_label[i]) iou_3d, iou_2d = box3d_iou(corners_3d, corners_3d_label) # print(iou_3d) # print(iou_2d) iou3d_list.append(iou_3d) iou2d_list.append(iou_2d) return np.array(iou2d_list, dtype=np.float32), \ np.array(iou3d_list, dtype=np.float32)
def compute_box3d_iou(center_pred, heading_logits, heading_residuals, size_logits, size_residuals, center_label, heading_class_label, heading_residual_label, size_class_label, size_residual_label): ''' Compute 3D bounding box IoU from network output and labels. All inputs are numpy arrays. Inputs: center_pred: (B,3) heading_logits: (B,NUM_HEADING_BIN) heading_residuals: (B,NUM_HEADING_BIN) size_logits: (B,NUM_SIZE_CLUSTER) size_residuals: (B,NUM_SIZE_CLUSTER,3) center_label: (B,3) heading_class_label: (B,) heading_residual_label: (B,) size_class_label: (B,) size_residual_label: (B,3) Output: iou2ds: (B,) birdeye view oriented 2d box ious iou3ds: (B,) 3d box ious ''' batch_size = heading_logits.shape[0] heading_class = np.argmax(heading_logits, 1) # 获得朝向角类别(B,) # 获得朝向角类别对应的残差(B,) heading_residual = np.array( [heading_residuals[i, heading_class[i]] for i in range(batch_size)]) size_class = np.argmax(size_logits, 1) # 尺寸类别(B,) # 获得尺寸类别对应的残差(B,) size_residual = np.vstack( [size_residuals[i, size_class[i], :] for i in range(batch_size)]) iou2d_list = [] iou3d_list = [] for i in range(batch_size): heading_angle = class2angle(heading_class[i], heading_residual[i], NUM_HEADING_BIN) # 还原朝向角(预测值) box_size = class2size(size_class[i], size_residual[i]) # 还原边框尺寸(预测值) corners_3d = get_3d_box(box_size, heading_angle, center_pred[i]) # 计算边框的8个顶点(预测值) # 还原朝向角真值 heading_angle_label = class2angle(heading_class_label[i], heading_residual_label[i], NUM_HEADING_BIN) box_size_label = class2size(size_class_label[i], size_residual_label[i]) # 还原边框尺寸真值 corners_3d_label = get_3d_box(box_size_label, heading_angle_label, center_label[i]) # 计算边框顶点真值 iou_3d, iou_2d = box3d_iou(corners_3d, corners_3d_label) # 根据顶点预测值和真值,计算二维、三维IoU iou3d_list.append(iou_3d) iou2d_list.append(iou_2d) return np.array(iou2d_list, dtype=np.float32), np.array(iou3d_list, dtype=np.float32)
def compute_box3d_iou_with_padding(center_pred, heading_logits, heading_residuals, size_logits, size_residuals, actual_nr_objects, center_label, heading_class_label, heading_residual_label, size_class_label, size_residual_label): ''' Compute 3D bounding box IoU from network output and labels. All inputs are numpy arrays. Inputs: center_pred: (B,3) heading_logits: (B,NUM_HEADING_BIN) heading_residuals: (B,NUM_HEADING_BIN) size_logits: (B,NUM_SIZE_CLUSTER) size_residuals: (B,NUM_SIZE_CLUSTER,3) center_label: (B,3) heading_class_label: (B,) heading_residual_label: (B,) size_class_label: (B,) size_residual_label: (B,3) Output: iou2ds: (B,) birdeye view oriented 2d box ious iou3ds: (B,) 3d box ious ''' batch_size = heading_logits.shape[0] heading_class = np.argmax(heading_logits, 1) # B heading_residual = np.array([ heading_residuals[i, heading_class[i]] for i in range(batch_size) ]) # B, size_class = np.argmax(size_logits, 1) # B size_residual = np.vstack( [size_residuals[i, size_class[i], :] for i in range(batch_size)]) iou2d_list = [] iou3d_list = [] for i in range(actual_nr_objects): heading_angle = class2angle(heading_class[i], heading_residual[i], NUM_HEADING_BIN) box_size = class2size(size_class[i], size_residual[i]) corners_3d = get_3d_box(box_size, heading_angle, center_pred[i]) heading_angle_label = class2angle(heading_class_label[i], heading_residual_label[i], NUM_HEADING_BIN) box_size_label = class2size(size_class_label[i], size_residual_label[i]) corners_3d_label = get_3d_box(box_size_label, heading_angle_label, center_label[i]) iou_3d, iou_2d = box3d_iou(corners_3d, corners_3d_label) iou3d_list.append(iou_3d) iou2d_list.append(iou_2d) return np.array(iou2d_list, dtype=np.float32), np.array(iou3d_list, dtype=np.float32)
def compare_with_anchor_boxes(center_label, heading_class_label, heading_residual_label, size_class_label, size_residual_label): ''' Compute IoUs between GT box and anchor boxes. Compute heading,size,center regression from anchor boxes to GT box: NHxNS of them in the order of heading0: size0,size1,... heading1: size0,size1,... ... Inputs: center_label: (B,3) -- assume this center is already close to (0,0,0) e.g. subtracted stage1_center heading_class_label: (B,) heading_residual_label: (B,) size_class_label: (B,) size_residual_label: (B,3) Output: iou2ds: (B,K) where K = NH*NS iou3ds: (B,K) center_residuals: (B,K,3) heading_residuals: (B,K) size_residuals: (B,K,3) ''' B = len(heading_class_label) K = NUM_HEADING_BIN*NUM_SIZE_CLUSTER iou3ds = np.zeros((B,K), dtype=np.float32) iou2ds = np.zeros((B,K), dtype=np.float32) center_residuals = np.zeros((B,K,3), dtype=np.float32) heading_residuals = np.zeros((B,K), dtype=np.float32) size_residuals = np.zeros((B,K,3), dtype=np.float32) corners_3d_anchor_list = [] heading_anchor_list = [] box_anchor_list = [] for j in range(NUM_HEADING_BIN): for k in range(NUM_SIZE_CLUSTER): heading_angle = class2angle(j,0,NUM_HEADING_BIN) box_size = class2size(k,np.zeros((3,))) corners_3d_anchor = get_3d_box(box_size, heading_angle, np.zeros((3,))) corners_3d_anchor_list.append(corners_3d_anchor) heading_anchor_list.append(heading_angle) box_anchor_list.append(box_size) for i in range(B): heading_angle_label = class2angle(heading_class_label[i], heading_residual_label[i], NUM_HEADING_BIN) box_size_label = class2size(size_class_label[i], size_residual_label[i]) corners_3d_label = get_3d_box(box_size_label, heading_angle_label, center_label[i]) for j in range(K): iou_3d, iou_2d = box3d_iou(corners_3d_anchor_list[j], corners_3d_label) iou3ds[i,j] = iou_3d iou2ds[i,j] = iou_2d center_residuals[i,j,:] = center_label[i] heading_residuals[i,j] = heading_angle_label - heading_anchor_list[j] size_residuals[i,j,:] = box_size_label - box_anchor_list[j] return iou2ds, iou3ds, center_residuals, heading_residuals, size_residuals
def compare_with_anchor_boxes(center_label, heading_class_label, heading_residual_label, size_class_label, size_residual_label): ''' Compute IoUs between GT box and anchor boxes. Compute heading,size,center regression from anchor boxes to GT box: NHxNS of them in the order of heading0: size0,size1,... heading1: size0,size1,... ... Inputs: center_label: (B,3) -- assume this center is already close to (0,0,0) e.g. subtracted stage1_center heading_class_label: (B,) heading_residual_label: (B,) size_class_label: (B,) size_residual_label: (B,3) Output: iou2ds: (B,K) where K = NH*NS iou3ds: (B,K) center_residuals: (B,K,3) heading_residuals: (B,K) size_residuals: (B,K,3) ''' B = len(heading_class_label) K = NUM_HEADING_BIN*NUM_SIZE_CLUSTER iou3ds = np.zeros((B,K), dtype=np.float32) iou2ds = np.zeros((B,K), dtype=np.float32) center_residuals = np.zeros((B,K,3), dtype=np.float32) heading_residuals = np.zeros((B,K), dtype=np.float32) size_residuals = np.zeros((B,K,3), dtype=np.float32) corners_3d_anchor_list = [] heading_anchor_list = [] box_anchor_list = [] for j in range(NUM_HEADING_BIN): for k in range(NUM_SIZE_CLUSTER): heading_angle = class2angle(j,0,NUM_HEADING_BIN) box_size = class2size(k,np.zeros((3,))) corners_3d_anchor = get_3d_box(box_size, heading_angle, np.zeros((3,))) corners_3d_anchor_list.append(corners_3d_anchor) heading_anchor_list.append(heading_angle) box_anchor_list.append(box_size) for i in range(B): heading_angle_label = class2angle(heading_class_label[i], heading_residual_label[i], NUM_HEADING_BIN) box_size_label = class2size(size_class_label[i], size_residual_label[i]) corners_3d_label = get_3d_box(box_size_label, heading_angle_label, center_label[i]) for j in range(K): iou_3d, iou_2d = box3d_iou(corners_3d_anchor_list[j], corners_3d_label) iou3ds[i,j] = iou_3d iou2ds[i,j] = iou_2d center_residuals[i,j,:] = center_label[i] heading_residuals[i,j] = heading_angle_label - heading_anchor_list[j] size_residuals[i,j,:] = box_size_label - box_anchor_list[j] return iou2ds, iou3ds, center_residuals, heading_residuals, size_residuals
def align_predictions_groundtruths(batch_pred_corners_3d, batch_gt_corners_3d, end_points, iou_threshold=0.5): """ Args: batch_pred_corners_3d: ndarray (num_batch, num_proposals, 8, 3) predicted bounding boxes (represented by 8 corner points) in upright_camera coordinate batch_gt_corners_3d: ndarray (num_batch, MAX_NUM_OBJ, 8, 3) ground truth bounding boxes (represented by 8 corner points) in upright_camera coordinate end_points: dict {box_label_mask, ...} Returns: batch_gt_corners_3d_aligned: ndarray (num_batch, num_proposals, 8, 3) clostest ground truth bounding boxes corresponding to each predicted bbox batch_confidence_scores: ndarray (num_batch, num_proposals, 1), value is 0 or 1 the fitness between each predicted bbox and gt bbox, if the overlap larger than threshold, fitness is 1 batch_sem_cls_labels: ndarray (num_batch, num_proposals), value is [0, num_class-1] the semantic class of the aligned ground truth bboxes """ bsize = batch_pred_corners_3d.shape[0] num_proposal = batch_pred_corners_3d.shape[1] box_label_mask = end_points['box_label_mask'].detach().cpu().numpy() sem_cls_label = end_points['sem_cls_label'].detach().cpu().numpy() batch_sem_cls_labels = np.zeros((bsize, num_proposal, 1), dtype=np.int64) batch_confidence_scores = np.zeros((bsize, num_proposal, 1), dtype=np.float32) batch_gt_corners_3d_aligned = np.zeros((bsize, num_proposal, 8, 3), dtype=np.float32) for i in range(bsize): cur_mask = np.nonzero(box_label_mask[i]) gt_corners_3d = batch_gt_corners_3d[i][cur_mask] gt_classes = sem_cls_label[i][cur_mask] for j in range(num_proposal): BB = batch_pred_corners_3d[i, j, :, :] iou_list = [] for BBGT in gt_corners_3d: iou, _ = box3d_iou(BB, BBGT) iou_list.append(iou) if len(iou_list) != 0: iou_list = np.array(iou_list) max_ind = np.argmax(iou_list) batch_gt_corners_3d_aligned[i, j, :, :] = gt_corners_3d[max_ind] batch_sem_cls_labels[i, j] = gt_classes[max_ind] if iou_list.max() >= iou_threshold: batch_confidence_scores[i, j] = 1. return batch_gt_corners_3d_aligned, batch_confidence_scores, batch_sem_cls_labels
def compute_box3d_iou(center_pred, heading_logits, heading_residuals, size_logits, size_residuals, center_label, heading_class_label, heading_residual_label, size_class_label, size_residual_label): ''' Compute 3D bounding box IoU from network output and labels. All inputs are numpy arrays. Inputs: center_pred: (B,3) heading_logits: (B,NUM_HEADING_BIN) heading_residuals: (B,NUM_HEADING_BIN) size_logits: (B,NUM_SIZE_CLUSTER) size_residuals: (B,NUM_SIZE_CLUSTER,3) center_label: (B,3) heading_class_label: (B,) heading_residual_label: (B,) size_class_label: (B,) size_residual_label: (B,3) Output: iou2ds: (B,) birdeye view oriented 2d box ious iou3ds: (B,) 3d box ious ''' batch_size = heading_logits.shape[0] heading_class = np.argmax(heading_logits, 1) # B heading_residual = np.array([heading_residuals[i,heading_class[i]] \ for i in range(batch_size)]) # B, size_class = np.argmax(size_logits, 1) # B size_residual = np.vstack([size_residuals[i,size_class[i],:] \ for i in range(batch_size)]) iou2d_list = [] iou3d_list = [] for i in range(batch_size): heading_angle = class2angle(heading_class[i], heading_residual[i], NUM_HEADING_BIN) box_size = class2size(size_class[i], size_residual[i]) corners_3d = get_3d_box(box_size, heading_angle, center_pred[i]) heading_angle_label = class2angle(heading_class_label[i], heading_residual_label[i], NUM_HEADING_BIN) box_size_label = class2size(size_class_label[i], size_residual_label[i]) corners_3d_label = get_3d_box(box_size_label, heading_angle_label, center_label[i]) iou_3d, iou_2d = box3d_iou(corners_3d, corners_3d_label) iou3d_list.append(iou_3d) iou2d_list.append(iou_2d) return np.array(iou2d_list, dtype=np.float32), \ np.array(iou3d_list, dtype=np.float32)
def compute_box3d_iou(center_pred, heading_logits, heading_residuals, size_logits, size_residuals, center_label, heading_class_label, heading_residual_label, size_class_label, size_residual_label): ''' Used for confidence score supervision.. Inputs: center_pred: (B,3) heading_logits: (B,NUM_HEADING_BIN) heading_residuals: (B,NUM_HEADING_BIN) size_logits: (B,NUM_SIZE_CLUSTER) size_residuals: (B,NUM_SIZE_CLUSTER,3) center_label: (B,3) heading_class_label: (B,) heading_residual_label: (B,) size_class_label: (B,) size_residual_label: (B,3) Output: iou2ds: (B,) birdeye view oriented 2d box ious iou3ds: (B,) 3d box ious ''' batch_size = heading_logits.shape[0] heading_class = np.argmax(heading_logits, 1) # B heading_residual = np.array([ heading_residuals[i, heading_class[i]] for i in range(batch_size) ]) # B, size_class = np.argmax(size_logits, 1) # B size_residual = np.vstack( [size_residuals[i, size_class[i], :] for i in range(batch_size)]) iou2d_list = [] iou3d_list = [] for i in range(batch_size): heading_angle = class2angle(heading_class[i], heading_residual[i], NUM_HEADING_BIN) box_size = class2size(size_class[i], size_residual[i]) corners_3d = get_3d_box(box_size, heading_angle, center_pred[i]) heading_angle_label = class2angle(heading_class_label[i], heading_residual_label[i], NUM_HEADING_BIN) box_size_label = class2size(size_class_label[i], size_residual_label[i]) corners_3d_label = get_3d_box(box_size_label, heading_angle_label, center_label[i]) iou_3d, iou_2d = box3d_iou(corners_3d, corners_3d_label) iou3d_list.append(iou_3d) iou2d_list.append(iou_2d) return np.array(iou2d_list, dtype=np.float32), np.array(iou3d_list, dtype=np.float32)
def compute_box3d_iou_batch(center_pred, heading_class, heading_residual, size_class, size_residual, corners_3d_label): ''' Compute 3D bounding box IoU from network output and labels. All inputs are numpy arrays. Inputs: center_pred: (B,3) heading_logits: (B,NUM_HEADING_BIN) heading_residuals: (B,NUM_HEADING_BIN) size_logits: (B,NUM_SIZE_CLUSTER) size_residuals: (B,NUM_SIZE_CLUSTER,3) center_label: (B,3) heading_class_label: (B,) heading_residual_label: (B,) size_class_label: (B,) size_residual_label: (B,3) Output: iou2ds: (B,) birdeye view oriented 2d box ious iou3ds: (B,) 3d box ious ''' batch_size = heading_class.shape[0] #heading_class = np.argmax(heading_logits, 1) # B #heading_residual = np.array([heading_residuals[i, heading_class[i]] \ # for i in range(batch_size)]) # B, #size_class = np.argmax(size_logits, 1) # B #size_residual = np.vstack([size_residuals[i, size_class[i], :] \ # for i in range(batch_size)]) #print(heading_class_label, heading_residual_label) iou2d_list = [] iou3d_list = [] for i in range(batch_size): heading_angle = class2angle(heading_class[i], heading_residual[i], NUM_HEADING_BIN) box_size = class2size(size_class[i], size_residual[i]) corners_3d = get_3d_box(box_size, heading_angle, center_pred[i]) #heading_angle_label = class2angle(heading_class_label[i], # heading_residual_label[i], NUM_HEADING_BIN) #box_size_label = class2size(size_class_label[i], size_residual_label[i]) #corners_3d_label = get_3d_box(box_size_label, # heading_angle_label, center_label[i]) for j in range(len(corners_3d_label)): iou_3d, iou_2d = box3d_iou(corners_3d, corners_3d_label[j]) print(corners_3d, corners_3d_label[j]) print("iou_3d:", iou_3d, "iou_2d", iou_2d) iou3d_list.append(iou_3d) iou2d_list.append(iou_2d) return np.array(iou2d_list, dtype=np.float32), \ np.array(iou3d_list, dtype=np.float32)
def compute_box3d_iou(pred_boxes, gt_boxes, nms_indices): ''' Compute 3D bounding box IoU from network output and labels. All inputs are numpy arrays. Inputs: pred_boxes: (B,FG_POINT_NUM,8,3) gt_boxes: (B,FG_POINT_NUM,8,3) nms_indices: (B,FG_POINT_NUM) valid indices are those != -1 Output: iou2ds: (B*M,) birdeye view oriented 2d box ious iou3ds: (B*M,) 3d box ious ''' iou2d_list = [] iou3d_list = [] for i in range(len(pred_boxes)): ind = nms_indices[i] ind = ind[ind != -1] for corners_3d, corners_3d_label in zip(pred_boxes[i, ind], gt_boxes[i, ind]): iou_3d, iou_2d = box3d_iou(corners_3d, corners_3d_label) iou3d_list.append(iou_3d) iou2d_list.append(iou_2d) return np.array(iou2d_list, dtype=np.float32), \ np.array(iou3d_list, dtype=np.float32)
def vis_predictions3D(pred_files, gt_file, number_to_show=10, filenums=None): from roi_seg_box3d_dataset import class2type idx = 0 COLS = number_to_show ap_infos = {} classes, file_nums, mean_box_ious, mean_seg_ious, box_ious, seg_ious = [], [], [], [], [], [] vtk_pcs_with_col, vtk_pcs_wo_col, vtk_imgs, vtk_gt_boxes, vtk_pred_boxes, vtk_texts = [], [], [], [], [], [] choices = [] test_dataset = ROISegBoxDataset(WHITE_LIST, npoints=2048, split='val', rotate_to_center=True, overwritten_data_path=gt_file, from_rgb_detection=False) for n, pred_file in enumerate(pred_files): # Lists of different items from predictions predictions = load_zipped_pickle(pred_file) ps_l, seg_gt_l, seg_pred_l, center_l, heading_cls_l, heading_res_l, size_cls_l, size_res_l, rot_angle_l, \ score_l, cls_type_l, file_num_l, box2d_l, box3d_l = predictions if n == 0: # Choosing equal number of objects per class to display cls_types = [] options = {} for i, cls_type in enumerate(cls_type_l): if not class2type[cls_type] in WHITE_LIST: continue if options.get(cls_type) is None: options[cls_type] = [i] cls_types.append(cls_type) else: options[cls_type].append(i) # Make use of array_split to divide into fairly equal groups arr = np.array_split([1] * number_to_show, len(options.keys())) random.shuffle(arr) for i, group in enumerate(arr): cls_type = cls_types[i] choice_list = np.random.choice(options[cls_type], len(group), replace=False) #replace=True) choices.extend(choice_list) print('Number of objects in whitelist: %d' % len(options)) # Compute overall statistics if not FLAGS.rgb_detection: print('==== Computing overall statistics for %s ====' % pred_file) from evaluate import evaluate_predictions, get_ap_info rec, prec, ap, mean_ap = evaluate_predictions(predictions, dataset, CLASSES, test_dataset, WHITE_LIST) ap['Mean AP'] = mean_ap for classname in ap.keys(): if ap_infos.get(classname) is None: ap_infos[classname] = [] ap_infos[classname].append('%11s: [%.1f]' % (classname, 100. * ap[classname])) box_iou_sum, seg_iou_sum = 0, 0 for i in range(len(ps_l)): seg_gt = seg_gt_l[i] box3d = box3d_l[i] seg_pred = seg_pred_l[i] center = center_l[i] heading_cls = heading_cls_l[i] heading_res = heading_res_l[i] size_cls = size_cls_l[i] size_res = size_res_l[i] rot_angle = rot_angle_l[i] gt_box3d = rotate_pc_along_y(np.copy(box3d), rot_angle) heading_angle = class2angle(heading_cls, heading_res, NUM_HEADING_BIN) box_size = class2size(size_cls, size_res) pred_box3d = get_3d_box(box_size, heading_angle, center) # Box IOU shift_arr = np.array([4,5,6,7,0,1,2,3]) box_iou3d, _ = box3d_iou(gt_box3d[shift_arr,:], pred_box3d) # Seg IOU seg_iou = get_seg_iou(seg_gt, seg_pred, 2) box_iou_sum += box_iou3d seg_iou_sum += seg_iou mean_box_iou = box_iou_sum / len(ps_l) mean_seg_iou = seg_iou_sum / len(ps_l) mean_box_ious.append(mean_box_iou) mean_seg_ious.append(mean_seg_iou) for i in choices: row, col = idx // COLS, idx % COLS idx += 1 ps = ps_l[i] seg_pred = seg_pred_l[i] center = center_l[i] heading_cls = heading_cls_l[i] heading_res = heading_res_l[i] size_cls = size_cls_l[i] size_res = size_res_l[i] rot_angle = rot_angle_l[i] score = score_l[i] cls_type = cls_type_l[i] file_num = file_num_l[i] seg_gt = seg_gt_l[i] if not FLAGS.rgb_detection else [] box2d = box2d_l[i] box3d = box3d_l[i] if not FLAGS.rgb_detection else [] # Visualize point cloud (with and without color) vtk_pc_wo_col = vis.VtkPointCloud(ps) vtk_pc = vis.VtkPointCloud(ps, gt_points=seg_gt, pred_points=seg_pred) vis.vtk_transform_actor(vtk_pc_wo_col.vtk_actor, translate=(SEP*col,SEP*row,0)) vis.vtk_transform_actor(vtk_pc.vtk_actor, translate=(SEP*col,SEP*row,0)) vtk_pcs_wo_col.append(vtk_pc_wo_col.vtk_actor) vtk_pcs_with_col.append(vtk_pc.vtk_actor) # Visualize GT 3D box if FLAGS.rgb_detection: objects = dataset.get_label_objects(file_num) calib = dataset.get_calibration(file_num) for obj in objects: if obj.classname not in WHITE_LIST: continue box3d_pts_2d, box3d_pts_3d = compute_box_3d(obj, calib) box3d_pts_3d = calib.project_upright_depth_to_upright_camera(box3d_pts_3d) box3d_pts_3d = rotate_pc_along_y(np.copy(box3d_pts_3d), rot_angle) vtk_box3D = vis.vtk_box_3D(box3d_pts_3d, color=vis.Color.LightGreen) vis.vtk_transform_actor(vtk_box3D, translate=(SEP*col,SEP*row,0)) vtk_gt_boxes.append(vtk_box3D) else: gt_box3d = rotate_pc_along_y(np.copy(box3d), rot_angle) vtk_gt_box3D = vis.vtk_box_3D(gt_box3d, color=vis.Color.LightGreen) vis.vtk_transform_actor(vtk_gt_box3D, translate=(SEP*col,SEP*row,0)) vtk_gt_boxes.append(vtk_gt_box3D) # Visualize Pred 3D box heading_angle = class2angle(heading_cls, heading_res, NUM_HEADING_BIN) box_size = class2size(size_cls, size_res) pred_box3d = get_3d_box(box_size, heading_angle, center) vtk_pred_box3D = vis.vtk_box_3D(pred_box3d, color=vis.Color.White) vis.vtk_transform_actor(vtk_pred_box3D, translate=(SEP*col,SEP*row,0)) vtk_pred_boxes.append(vtk_pred_box3D) # Visualize Images box2d_col = vis.Color.LightGreen if not FLAGS.rgb_detection else vis.Color.Orange img_filename = os.path.join(IMG_DIR, '%06d.jpg' % file_num) vtk_img = vis.vtk_image(img_filename, box2Ds_list=[[box2d]], box2Ds_cols=[box2d_col]) vis.vtk_transform_actor(vtk_img, scale=(IMG_SCALE,IMG_SCALE,IMG_SCALE), rot=(0,180,180), translate=(-2+SEP*col,2+SEP*row,10)) vtk_imgs.append(vtk_img) # Other information classes.append(class2type[cls_type].capitalize()) file_nums.append(str(file_num)) if not FLAGS.rgb_detection: shift_arr = np.array([4,5,6,7,0,1,2,3]) box_iou3d, _ = box3d_iou(gt_box3d[shift_arr,:], pred_box3d) box_ious.append(box_iou3d) seg_iou = get_seg_iou(seg_gt, seg_pred, 2) seg_ious.append(seg_iou) # Visualize overall statistics vtk_texts.extend(vis.vtk_text([('Model: %s' % pred_file.split('/')[-1]) for pred_file in pred_files], arr_type='text', sep=SEP, cols=1, scale=TEXT_SCALE, rot=TEXT_ROT, translate=(-14.5,2.5,2))) vtk_texts.extend(vis.vtk_text(['Mean Box IOU:'] * len(pred_files), arr_type='text', sep=SEP, cols=1, scale=TEXT_SCALE, rot=TEXT_ROT, translate=(-14.5,3,2))) vtk_texts.extend(vis.vtk_text(mean_box_ious, arr_type='float', color=True, sep=SEP, cols=1, scale=TEXT_SCALE, rot=TEXT_ROT, translate=(-10,3,2))) vtk_texts.extend(vis.vtk_text(['Mean Seg IOU:'] * len(pred_files), arr_type='text', sep=SEP, cols=1, scale=TEXT_SCALE, rot=TEXT_ROT, translate=(-14.5,3.5,2))) vtk_texts.extend(vis.vtk_text(mean_seg_ious, arr_type='float', color=True, sep=SEP, cols=1, scale=TEXT_SCALE, rot=TEXT_ROT, translate=(-10,3.5,2))) for i, (cls_name, ap_info) in enumerate(ap_infos.items()): vtk_texts.extend(vis.vtk_text(ap_info, arr_type='text', color=True, sep=SEP, cols=1, scale=TEXT_SCALE, rot=TEXT_ROT, translate=(-14.5,4+i*0.5,2))) # Visualize text information vtk_texts.extend(vis.vtk_text(['Class:'] * len(classes), arr_type='text', sep=SEP, cols=COLS, scale=TEXT_SCALE, rot=TEXT_ROT, translate=(-1.5,3,2))) vtk_texts.extend(vis.vtk_text(classes, arr_type='text', sep=SEP, cols=COLS, scale=TEXT_SCALE, rot=TEXT_ROT, translate=(0.5,3,2))) vtk_texts.extend(vis.vtk_text(['File:'] * len(file_nums), arr_type='text', sep=SEP, cols=COLS, scale=TEXT_SCALE, rot=TEXT_ROT, translate=(-1.5,3.5,2))) vtk_texts.extend(vis.vtk_text(file_nums, arr_type='text', sep=SEP, cols=COLS, scale=TEXT_SCALE, rot=TEXT_ROT, translate=(0.25,3.5,2))) if not FLAGS.rgb_detection: vtk_texts.extend(vis.vtk_text(['Box:'] * len(box_ious), arr_type='text', sep=SEP, cols=COLS, scale=TEXT_SCALE, rot=TEXT_ROT, translate=(-1.5,4,2))) vtk_texts.extend(vis.vtk_text(box_ious, arr_type='float', color=True, sep=SEP, cols=COLS, scale=TEXT_SCALE, rot=TEXT_ROT, translate=(0,4,2))) vtk_texts.extend(vis.vtk_text(['Seg:'] * len(seg_ious), arr_type='text', sep=SEP, cols=COLS, scale=TEXT_SCALE, rot=TEXT_ROT, translate=(-1.5,4.5,2))) vtk_texts.extend(vis.vtk_text(seg_ious, arr_type='float', color=True, sep=SEP, cols=COLS, scale=TEXT_SCALE, rot=TEXT_ROT, translate=(0,4.5,2))) key_to_actors_to_hide = { 'g': vtk_gt_boxes, 'p': vtk_pred_boxes, 'i': vtk_imgs, 'c': vtk_pcs_wo_col, 't': vtk_texts } return vtk_pcs_with_col, key_to_actors_to_hide
def vis_box_pc_dataset(filename, number): boxpc_dataset = BoxPCFitDataset(classes=WHITE_LIST, center_perturbation=0.8, size_perturbation=0.2, angle_perturbation=np.pi, npoints=2048, rotate_to_center=True, random_flip=True, random_shift=True, overwritten_data_path=filename) b_data, b_image, b_label, b_center, b_heading_class, b_heading_residual, b_size_class, \ b_size_residual, b_box2d, b_rilts, b_ks, b_rot_angle, b_img_dims, b_one_hot_vec, \ b_new_center, b_new_heading_class, b_new_heading_residual, b_new_size_class, \ b_new_size_residual, b_box_iou, b_y_center_delta, b_y_size_delta, b_y_angle_delta = \ boxpc_dataset.sample_batch(bsize=number, num_point=2048, num_channel=6, proportion_of_boxpc_fit=0.5, boxpc_nofit_bounds=[0.01,0.25], boxpc_fit_bounds=[0.7,1.0], equal_samples_per_class=True) classes, box_ious = [], [] vtk_pcs_with_col, vtk_gt_boxes, vtk_perb_boxes, vtk_imgs, vtk_pcs_wo_col, vtk_texts = [], [], [], [], [], [] for idx in range(len(b_data)): row, col = idx // COLS, idx % COLS cls_type = np.argmax(b_one_hot_vec[idx]) point_set = b_data[idx] seg_gt = b_label[idx] iou3d = b_box_iou[idx] # GT 3D box center = b_center[idx] angle_class = b_heading_class[idx] angle_res = b_heading_residual[idx] size_cls = b_size_class[idx] size_res = b_size_residual[idx] # Perturbed 3D box new_center = b_new_center[idx] new_angle_class = b_new_heading_class[idx] new_angle_res = b_new_heading_residual[idx] new_size_cls = b_new_size_class[idx] new_size_res = b_new_size_residual[idx] # Visualize point cloud (with and without color) vtk_pc_wo_col = vis.VtkPointCloud(point_set) vtk_pc = vis.VtkPointCloud(point_set, gt_points=seg_gt) vis.vtk_transform_actor(vtk_pc_wo_col.vtk_actor, translate=(SEP*col,SEP*row,0)) vis.vtk_transform_actor(vtk_pc.vtk_actor, translate=(SEP*col,SEP*row,0)) vtk_pcs_wo_col.append(vtk_pc_wo_col.vtk_actor) vtk_pcs_with_col.append(vtk_pc.vtk_actor) # Visualize GT 3D box lwh = class2size(size_cls, size_res) ry = class2angle(angle_class, angle_res, 12) gt_box3d = get_3d_box(lwh, ry, center) vtk_gt_box3D = vis.vtk_box_3D(gt_box3d, color=vis.Color.LightGreen) vis.vtk_transform_actor(vtk_gt_box3D, translate=(SEP*col,SEP*row,0)) vtk_gt_boxes.append(vtk_gt_box3D) # Visualize Perb 3D box new_lwh = class2size(new_size_cls, new_size_res) new_ry = class2angle(new_angle_class, new_angle_res, 12) perb_box3d = get_3d_box(new_lwh, new_ry, new_center) vtk_perb_box3D = vis.vtk_box_3D(perb_box3d, color=vis.Color.Blue) vis.vtk_transform_actor(vtk_perb_box3D, translate=(SEP*col,SEP*row,0)) vtk_perb_boxes.append(vtk_perb_box3D) # Other information classes.append(class2type[cls_type].capitalize()) box_iou3d, _ = box3d_iou(gt_box3d, perb_box3d) print('%d: %.3f, %.3f' % (idx, iou3d, box_iou3d - iou3d)) box_ious.append(iou3d) # Visualize text information vtk_texts.extend(vis.vtk_text(['Class:'] * len(classes), arr_type='text', sep=SEP, cols=COLS, scale=TEXT_SCALE, rot=TEXT_ROT, translate=(-1.5,3,2))) vtk_texts.extend(vis.vtk_text(classes, arr_type='text', sep=SEP, cols=COLS, scale=TEXT_SCALE, rot=TEXT_ROT, translate=(0.5,3,2))) vtk_texts.extend(vis.vtk_text(['Box:'] * len(box_ious), arr_type='text', sep=SEP, cols=COLS, scale=TEXT_SCALE, rot=TEXT_ROT, translate=(-1.5,4,2))) vtk_texts.extend(vis.vtk_text(box_ious, arr_type='float', color=True, sep=SEP, cols=COLS, scale=TEXT_SCALE, rot=TEXT_ROT, translate=(0,4,2))) key_to_actors_to_hide = { 'g': vtk_gt_boxes, 'p': vtk_perb_boxes, 'i': vtk_imgs, 'c': vtk_pcs_wo_col, 't': vtk_texts } return vtk_pcs_with_col, key_to_actors_to_hide
def NMS(result_dir, id_list_frame, center_list_frame, \ heading_cls_list_frame, heading_res_list_frame, \ size_cls_list_frame, size_res_list_frame, \ rot_angle_list_frame, score_list_frame,scores_mask_mean_frames,batch_seg_sum_frames): # estimate corners for all detections in box for j in range(len(id_list_frame[:5])): # estimate 3DIoU for a box with other boxes for a batch print(center_list_frame[j]) corners3d = np.zeros((len(center_list_frame[j]), 8, 3)) for i in range(len(center_list_frame[j])): corners3d[i] = provider.get_3d_box_batch( center_list_frame[j][i], heading_cls_list_frame[j][i], heading_res_list_frame[j][i], size_cls_list_frame[j][i], size_res_list_frame[j][i], rot_angle_list_frame[j][i]) bboxes = [] center_list = [] heading_cls_list = [] heading_res_list = [] size_cls_list = [] size_res_list = [] rot_angle_list = [] score_list = [] #ind_sort = np.argsort(-scores_mask_mean_frames[j]) ind_sort = np.argsort([x * -1.0 for x in scores_mask_mean_frames[j]]) print(ind_sort) for i in range(len(scores_mask_mean_frames[j])): print(scores_mask_mean_frames[j][ind_sort[i]]) #print(scores_mask_mean_frames[j][ind_sort]) for i in range(len(corners3d)): bbox = corners3d[ind_sort[i]] flag = 1 for k in range(i + 1, len(corners3d)): if (batch_seg_sum_frames[j][ind_sort[i]] < 30): flag = -1 break if (np.array_equal(bbox, corners3d[ind_sort[k]])): flag = -1 break print("index ", ind_sort[i], scores_mask_mean_frames[j][ind_sort[i]], "index _comp: ", ind_sort[k], scores_mask_mean_frames[j][ind_sort[k]], "IoU: ", box_util.box3d_iou(bbox, corners3d[ind_sort[k]])) if box_util.box3d_iou(bbox, corners3d[ind_sort[k]])[1] > 0.3: flag = -1 break if flag == 1: bboxes.append(bbox) center_list.append(center_list_frame[j][ind_sort[i]]) heading_cls_list.append(heading_cls_list_frame[j][ind_sort[i]]) heading_res_list.append(heading_res_list_frame[j][ind_sort[i]]) size_cls_list.append(size_cls_list_frame[j][ind_sort[i]]) size_res_list.append(size_res_list_frame[j][ind_sort[i]]) rot_angle_list.append(rot_angle_list_frame[j][ind_sort[i]]) #score_list.append(score_list_frame[j][i]) print("boxes size:", len(bboxes)) center_list_frame[j] = center_list heading_cls_list_frame[j] = heading_cls_list heading_res_list_frame[j] = heading_res_list size_cls_list_frame[j] = size_cls_list size_res_list_frame[j] = size_res_list rot_angle_list_frame[j] = rot_angle_list #score_list_frame[j] = score_list return center_list_frame, \ heading_cls_list_frame, heading_res_list_frame, \ size_cls_list_frame, size_res_list_frame, \ rot_angle_list_frame, score_list_frame
def compute_box3d_iou_batch(logits, center_pred, heading_logits, heading_residuals, size_logits, size_residuals, center_label, heading_class_label, heading_residual_label, size_class_label, size_residual_label): ''' Compute 3D bounding box IoU from network output and labels. All inputs are numpy arrays. Inputs: center_pred: (B,3) heading_logits: (B,NUM_HEADING_BIN) heading_residuals: (B,NUM_HEADING_BIN) size_logits: (B,NUM_SIZE_CLUSTER) size_residuals: (B,NUM_SIZE_CLUSTER,3) center_label: (B,3) heading_class_label: (B,) heading_residual_label: (B,) size_class_label: (B,) size_residual_label: (B,3) Output: iou2ds: (B,) birdeye view oriented 2d box ious iou3ds: (B,) 3d box ious ''' pred_val = np.argmax(logits, 2) batch_size = heading_logits.shape[0] heading_class = np.argmax(heading_logits, 1) # B heading_residual = np.array([heading_residuals[i,heading_class[i]] \ for i in range(batch_size)]) # B, size_class = np.argmax(size_logits, 1) # B size_residual = np.vstack([size_residuals[i,size_class[i],:] \ for i in range(batch_size)]) iou2d_list = [] iou3d_list = [] box_pred_nbr = 0 for i in range(batch_size): # if object has low seg mask break if (np.sum(pred_val[i]) < 50): continue else: heading_angle = class2angle(heading_class[i], heading_residual[i], NUM_HEADING_BIN) box_size = class2size(size_class[i], size_residual[i]) corners_3d = get_3d_box(box_size, heading_angle, center_pred[i]) heading_angle_label = class2angle(heading_class_label[i], heading_residual_label[i], NUM_HEADING_BIN) box_size_label = class2size(size_class_label[i], size_residual_label[i]) if (center_label[i][2] < 0.0): iou3d_list.append(0.0) iou2d_list.append(0.0) else: corners_3d_label = get_3d_box(box_size_label, heading_angle_label, center_label[i]) iou_3d, iou_2d = box3d_iou(corners_3d, corners_3d_label) iou3d_list.append(iou_3d) iou2d_list.append(iou_2d) box_pred_nbr = box_pred_nbr + 1.0 return np.array(iou2d_list, dtype=np.float32), \ np.array(iou3d_list, dtype=np.float32), np.array(box_pred_nbr, dtype=np.float32)
segp = segp_list[i].squeeze() center = center_list[i].squeeze() ret = TEST_DATASET[i] rot_angle = ret[7] # Get heading angle and size print heading_cls_list[i], heading_res_list[i], size_cls_list[i], size_res_list[i] heading_angle = roi_seg_box3d_dataset.class2angle(heading_cls_list[i], heading_res_list[i], 12) box_size = roi_seg_box3d_dataset.class2size(size_cls_list[i], size_res_list[i]) corners_3d_pred = roi_seg_box3d_dataset.get_3d_box(box_size, heading_angle, center) # NOTE: fix this, box3d (projected from upright_depth coord) has flipped ymin,ymax as that in corners_3d_pred box3d_new = np.copy(box3d) box3d_new[0:4,:] = box3d[4:,:] box3d_new[4:,:] = box3d[0:4,:] iou_3d, iou_2d = box3d_iou(corners_3d_pred, box3d_new) print corners_3d_pred print box3d_new print 'Ground/3D IoU: ', iou_2d, iou_3d correct = int(iou_3d >= 0.25) total_cnt += 1 correct_cnt += correct class_total_cnt[classname] += 1 class_correct_cnt[classname] += correct if VISU: #and iou_3d<0.7: img_filename = os.path.join(IMG_DIR, '%06d.jpg'%(img_id)) img = cv2.imread(img_filename) img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) cv2.rectangle(img, (int(box2d[0]),int(box2d[1])), (int(box2d[2]),int(box2d[3])), (0,255,0), 3) Image.fromarray(img).show()
def get_iou_obb(bb1, bb2): iou3d, iou2d = box3d_iou(bb1, bb2) return iou3d
box3d_pred_list = [] viz_gt_box3d_list = [] color_list = [] pred2gt_idx_map = [-1 for _ in range(len(pred_list))] for i,pred in enumerate(pred_list): box2d, segp, center, rot_angle, corners_3d_pred, classname = pred # -------- GREEDY WAY TO MAP PRED TO GT ------------ predbox3d = rotate_pc_along_y(corners_3d_pred, -rot_angle) box3d_pred_list.append(predbox3d) iou3d_max = 0 iou3d_idx = -1 shift_arr = np.array([4,5,6,7,0,1,2,3]) for j,gtbox3d in enumerate(gt_box3d_list): if j in pred2gt_idx_map: continue iou3d, _ = box3d_iou(gtbox3d[shift_arr,:], predbox3d) if iou3d>iou3d_max: iou3d_max = iou3d iou3d_idx = j if iou3d_idx>=0: pred2gt_idx_map[i] = j # ---------- END ---------------- print i,iou3d_idx,iou3d_max #raw_input() if iou3d_max>=0.25: color_list.append((0,1,0)) else: color_list.append((1,0,0)) viz_gt_box3d_list.append(gt_box3d_list[i]) if img_id==403:
box3d_pred_list = [] viz_gt_box3d_list = [] color_list = [] pred2gt_idx_map = [-1 for _ in range(len(pred_list))] for i,pred in enumerate(pred_list): box2d, segp, center, rot_angle, corners_3d_pred, classname = pred # -------- GREEDY WAY TO MAP PRED TO GT ------------ predbox3d = rotate_pc_along_y(corners_3d_pred, -rot_angle) box3d_pred_list.append(predbox3d) iou3d_max = 0 iou3d_idx = -1 shift_arr = np.array([4,5,6,7,0,1,2,3]) for j,gtbox3d in enumerate(gt_box3d_list): if j in pred2gt_idx_map: continue iou3d, _ = box3d_iou(gtbox3d[shift_arr,:], predbox3d) if iou3d>iou3d_max: iou3d_max = iou3d iou3d_idx = j if iou3d_idx>=0: pred2gt_idx_map[i] = j # ---------- END ---------------- print i,iou3d_idx,iou3d_max #raw_input() if iou3d_max>=0.25: color_list.append((0,1,0)) else: color_list.append((1,0,0)) viz_gt_box3d_list.append(gt_box3d_list[i]) if img_id==403:
# Get heading angle and size print heading_cls_list[i], heading_res_list[i], size_cls_list[ i], size_res_list[i] heading_angle = roi_seg_box3d_dataset.class2angle(heading_cls_list[i], heading_res_list[i], 12) box_size = roi_seg_box3d_dataset.class2size(size_cls_list[i], size_res_list[i]) corners_3d_pred = roi_seg_box3d_dataset.get_3d_box(box_size, heading_angle, center) # NOTE: fix this, box3d (projected from upright_depth coord) has flipped ymin,ymax as that in corners_3d_pred box3d_new = np.copy(box3d) box3d_new[0:4, :] = box3d[4:, :] box3d_new[4:, :] = box3d[0:4, :] iou_3d, iou_2d = box3d_iou(corners_3d_pred, box3d_new) print corners_3d_pred print box3d_new print 'Ground/3D IoU: ', iou_2d, iou_3d correct = int(iou_3d >= 0.25) total_cnt += 1 correct_cnt += correct class_total_cnt[classname] += 1 class_correct_cnt[classname] += correct if VISU: #and iou_3d<0.7: img_filename = os.path.join(IMG_DIR, '%06d.jpg' % (img_id)) img = cv2.imread(img_filename) img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) cv2.rectangle(img, (int(box2d[0]), int(box2d[1])), (int(box2d[2]), int(box2d[3])), (0, 255, 0), 3)
def get_box3d_iou(center_A, box_size_A, heading_angle_A, center_B, box_size_B, heading_angle_B): corners_3d_A = get_3d_box(box_size_A, heading_angle_A, center_A) corners_3d_B = get_3d_box(box_size_B, heading_angle_B, center_B) iou_3d, iou_2d = box3d_iou(corners_3d_A, corners_3d_B) return iou_3d, iou_2d