def get_drivable_area_compliance( forecasted_trajectories: Dict[int, List[np.ndarray]], city_names: Dict[int, str], max_n_guesses: int, ) -> float: """Compute drivable area compliance metric. Args: forecasted_trajectories: Predicted top-k trajectory dict with key as seq_id and value as list of trajectories. Each element of the list is of shape (pred_len x 2). city_names: Dict mapping sequence id to city name. max_n_guesses: Maximum number of guesses allowed. Returns: Mean drivable area compliance """ avm = ArgoverseMap() dac_score = [] for seq_id, trajectories in forecasted_trajectories.items(): city_name = city_names[seq_id] num_dac_trajectories = 0 n_guesses = min(max_n_guesses, len(trajectories)) for trajectory in trajectories[:n_guesses]: raster_layer = avm.get_raster_layer_points_boolean(trajectory, city_name, "driveable_area") if np.sum(raster_layer) == raster_layer.shape[0]: num_dac_trajectories += 1 dac_score.append(num_dac_trajectories / n_guesses) return sum(dac_score) / len(dac_score)
def filter_objs_to_roi(instances: np.ndarray, avm: ArgoverseMap, city_SE3_egovehicle: SE3, city_name: str) -> np.ndarray: """Filter objects to the region of interest (5 meter dilation of driveable area). We ignore instances outside of region of interest (ROI) during evaluation. Args: instances: Numpy array of shape (N,) with ObjectLabelRecord entries avm: Argoverse map object city_SE3_egovehicle: pose of egovehicle within city map at time of sweep city_name: name of city where log was captured Returns: instances_roi: objects with any of 4 cuboid corners located within ROI """ # for each cuboid, get its 4 corners in the egovehicle frame corners_egoframe = np.vstack([dt.as_2d_bbox() for dt in instances]) corners_cityframe = city_SE3_egovehicle.transform_point_cloud( corners_egoframe) corner_within_roi = avm.get_raster_layer_points_boolean( corners_cityframe, city_name, "roi") # check for each cuboid if any of its 4 corners lies within the ROI is_within_roi = corner_within_roi.reshape(-1, 4).any(axis=1) instances_roi = instances[is_within_roi] return instances_roi
def get_pruned_guesses( forecasted_trajectories: Dict[int, List[np.ndarray]], city_names: Dict[int, str], gt_trajectories: Dict[int, np.ndarray], ) -> Dict[int, List[np.ndarray]]: """Prune the number of guesses using map. Args: forecasted_trajectories: Trajectories forecasted by the algorithm. city_names: Dict mapping sequence id to city name. gt_trajectories: Ground Truth trajectories. Returns: Pruned number of forecasted trajectories. """ args = parse_arguments() avm = ArgoverseMap() pruned_guesses = {} for seq_id, trajectories in forecasted_trajectories.items(): city_name = city_names[seq_id] da_points = [] for trajectory in trajectories: raster_layer = avm.get_raster_layer_points_boolean( trajectory, city_name, "driveable_area") da_points.append(np.sum(raster_layer)) sorted_idx = np.argsort(da_points)[::-1] pruned_guesses[seq_id] = [ trajectories[i] for i in sorted_idx[:args.prune_n_guesses] ] return pruned_guesses