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 evaluate_predictions(predictions, dataset, classes, test_dataset, test_classes): ps_list, _, segp_list, center_list, heading_cls_list, heading_res_list, size_cls_list, size_res_list, \ rot_angle_list, score_list, cls_list, file_num_list, _, _ = predictions print('Number of PRED boxes: %d, Number of GT boxes: %d' % (len(segp_list), len(test_dataset))) # For detection evaluation pred_all = {} gt_all = {} ovthresh = 0.25 # A) Get GT boxes # print('Constructing GT boxes...') for i in range(len(test_dataset)): img_id = test_dataset.idx_l[i] if img_id in gt_all: continue # All ready counted.. gt_all[img_id] = [] objects = dataset.get_label_objects(img_id) calib = dataset.get_calibration(img_id) for obj in objects: if obj.classname not in test_classes: 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_flipped = np.copy(box3d_pts_3d) box3d_pts_3d_flipped[0:4,:] = box3d_pts_3d[4:,:] box3d_pts_3d_flipped[4:,:] = box3d_pts_3d[0:4,:] gt_all[img_id].append((obj.classname, box3d_pts_3d_flipped)) # B) Get PRED boxes # print('Constructing PRED boxes...') for i in range(len(ps_list)): img_id = file_num_list[i] classname = classes[cls_list[i]] if classname not in test_classes: raise Exception('Not supposed to have class: %s' % classname) center = center_list[i].squeeze() rot_angle = rot_angle_list[i] # Get heading angle and size heading_angle = roi_seg_box3d_dataset.class2angle(heading_cls_list[i], heading_res_list[i], NUM_HEADING_BIN) 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) corners_3d_pred = rotate_pc_along_y(corners_3d_pred, -rot_angle) if img_id not in pred_all: pred_all[img_id] = [] pred_all[img_id].append((classname, corners_3d_pred, score_list[i])) # Compute AP rec, prec, ap = eval_det(pred_all, gt_all, ovthresh) mean_ap = np.mean([ap[classname] for classname in ap]) return rec, prec, ap, mean_ap
if np.sum(np.abs(obj.box2d - box2d)) < 1e-3: target_obj = obj break assert (target_obj is not None) box3d = TEST_DATASET.get_center_view_box3d(i) ps = ps_list[i] 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
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 vis_seg_box_dataset(filename, number): rotate_to_center = True segbox_dataset = ROISegBoxDataset(WHITE_LIST, npoints=2048, split='training', rotate_to_center=rotate_to_center, random_flip=False, random_shift=False, overwritten_data_path=filename, from_rgb_detection=FLAGS.rgb_detection) classes, file_nums = [], [] vtk_pcs_wo_col, vtk_pcs_w_col, vtk_gt_boxes, vtk_imgs, vtk_texts = [], [], [], [], [] #for idx in range(number): choices = np.random.choice(len(segbox_dataset), number) choices.sort() for idx, choice in enumerate(choices): row, col = idx // COLS, idx % COLS if FLAGS.rgb_detection: point_set, img, rot, prob = segbox_dataset[choice] else: point_set, img, seg_gt, center, angle_class, angle_res, size_cls, size_res, box2d, rtilt, \ k, rot, img_dims = segbox_dataset[choice] file_num = segbox_dataset.idx_l[choice] # Visualize point cloud vtk_pc_wo_col = vis.VtkPointCloud(point_set) vtk_pc_w_col = 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_w_col.vtk_actor, translate=(SEP*col,SEP*row,0)) vtk_pcs_wo_col.append(vtk_pc_wo_col.vtk_actor) vtk_pcs_w_col.append(vtk_pc_w_col.vtk_actor) # Visualize GT 3D box if not FLAGS.rgb_detection: lwh = class2size(size_cls, size_res) ry = class2angle(angle_class, angle_res, 12) box3d = get_3d_box(lwh, ry, center) vtk_box3D = vis.vtk_box_3D(box3d, color=vis.Color.LightGreen) vis.vtk_transform_actor(vtk_box3D, translate=(SEP*col,SEP*row,0)) vtk_gt_boxes.append(vtk_box3D) calib = dataset.get_calibration(file_num) box3d_rot = rotate_pc_along_y(box3d.copy(), -rot) box3d_pts_3d_orig = calib.project_upright_camera_to_upright_depth(box3d_rot) box3d_pts_2d, _ = calib.project_upright_depth_to_image(box3d_pts_3d_orig) # Visualize Images box2d = segbox_dataset.box2d_l[choice] 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], proj_box3Ds_list=[box3d_pts_2d], proj_box3Ds_cols=[vis.Color.LightGreen]) 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) # Text information classes.append(segbox_dataset.cls_type_l[choice]) file_nums.append(str(file_num)) # 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))) return vtk_pcs_w_col, { 'g': vtk_gt_boxes, 'c': vtk_pcs_wo_col, 'i': vtk_imgs, 't': vtk_texts }
for obj in objects: # **Assuming we use GT box2d for 3D box estimation evaluation** if np.sum(np.abs(obj.box2d-box2d))<1e-3: target_obj = obj break assert(target_obj is not None) box3d = TEST_DATASET.get_center_view_box3d(i) ps = ps_list[i] 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
print 'Construct PRED boxes...' for i in range(len(TEST_DATASET)): img_id = TEST_DATASET.id_list[i] classname = TEST_DATASET.type_list[i] center = center_list[i].squeeze() ret = TEST_DATASET[i] if FLAGS.from_rgb_detection: rot_angle = ret[1] else: 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], NUM_HEADING_BIN) 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) corners_3d_pred = rotate_pc_along_y(corners_3d_pred, -rot_angle) if img_id not in pred_all: pred_all[img_id] = [] pred_all[img_id].append((classname, corners_3d_pred, score_list[i])) print pred_all[1] raw_input() import matplotlib.pyplot as plt import matplotlib as mpl
# Get PRED boxes print 'Construct PRED boxes...' for i in range(len(TEST_DATASET)): img_id = TEST_DATASET.id_list[i] classname = TEST_DATASET.type_list[i] center = center_list[i].squeeze() ret = TEST_DATASET[i] if FLAGS.from_rgb_detection: rot_angle = ret[1] else: 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], NUM_HEADING_BIN) 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) corners_3d_pred = rotate_pc_along_y(corners_3d_pred, -rot_angle) if img_id not in pred_all: pred_all[img_id] = [] pred_all[img_id].append((classname, corners_3d_pred, score_list[i])) print pred_all[1] raw_input() import matplotlib.pyplot as plt import matplotlib as mpl mpl.rc('axes', linewidth=2) print 'Computing AP...' rec, prec, ap = eval_det(pred_all, gt_all, ovthresh)