def __init__(self, nusc: NuScenes, config: TrackingConfig, result_path: str, eval_set: str, output_dir: str = None, verbose: bool = True): """ Initialize a TrackingEval object. :param nusc: A NuScenes object. :param config: A TrackingConfig object. :param result_path: Path of the nuScenes JSON result file. :param eval_set: The dataset split to evaluate on, e.g. train, val or test. :param output_dir: Folder to save plots and results to. :param verbose: Whether to print to stdout. """ self.cfg = config self.result_path = result_path self.eval_set = eval_set self.output_dir = output_dir self.verbose = verbose # Check result file exists. assert os.path.exists( result_path), 'Error: The result file does not exist!' # Make dirs. self.plot_dir = os.path.join(self.output_dir, 'plots') if not os.path.isdir(self.output_dir): os.makedirs(self.output_dir) if not os.path.isdir(self.plot_dir): os.makedirs(self.plot_dir) # Load data. if verbose: print('Initializing nuScenes tracking evaluation') pred_boxes, self.meta = load_prediction(self.result_path, self.cfg.max_boxes_per_sample, TrackingBox, verbose=verbose) gt_boxes = load_gt(nusc, self.eval_set, TrackingBox, verbose=verbose) assert set(pred_boxes.sample_tokens) == set(gt_boxes.sample_tokens), \ "Samples in split don't match samples in predicted tracks." # Add center distances. pred_boxes = add_center_dist(nusc, pred_boxes) gt_boxes = add_center_dist(nusc, gt_boxes) # Filter boxes (distance, points per box, etc.). if verbose: print('Filtering tracks') pred_boxes = filter_eval_boxes(nusc, pred_boxes, self.cfg.class_range, verbose=verbose) if verbose: print('Filtering ground truth tracks') gt_boxes = filter_eval_boxes(nusc, gt_boxes, self.cfg.class_range, verbose=verbose) self.sample_tokens = gt_boxes.sample_tokens # Convert boxes to tracks format. self.tracks_gt = create_tracks(gt_boxes, nusc, self.eval_set, gt=True) self.tracks_pred = create_tracks(pred_boxes, nusc, self.eval_set, gt=False)
nusc = NuScenes(version=version, dataroot=data_root, verbose=True) pred_boxes, _ = load_prediction(detection_file, 10000, DetectionBox) gt_boxes = load_gt(nusc, eval_set_, TrackingBox) assert set(pred_boxes.sample_tokens) == set(gt_boxes.sample_tokens), \ "Samples in split don't match samples in predicted tracks." # Add center distances. pred_boxes = add_center_dist(nusc, pred_boxes) gt_boxes = add_center_dist(nusc, gt_boxes) print('len(pred_boxes.sample_tokens): ', len(pred_boxes.sample_tokens)) print('len(gt_boxes.sample_tokens): ', len(gt_boxes.sample_tokens)) tracks_gt = create_tracks(gt_boxes, nusc, eval_set_, gt=True) mean, std, var = get_mean(tracks_gt) print('GT: Global coordinate system') print( 'h, w, l, x, y, z, a, x_dot, y_dot, z_dot, a_dot, x_dot_dot, y_dot_dot, z_dot_dot, a_dot_dot' ) print('mean: ', mean) print('std: ', std) print('var: ', var) # for observation noise covariance mean, std, var, mean_vel, std_vel, var_vel = matching_and_get_diff_stats( pred_boxes, gt_boxes, tracks_gt, matching_dist) print('Diff: Global coordinate system') print('h, w, l, x, y, z, a')