예제 #1
0
def accumulate(
    dt_root_fpath: Path, gt_fpath: Path, cfg: DetectionCfg
) -> Tuple[DefaultDict[str, np.ndarray], DefaultDict[str, int]]:
    """Accumulate the true/false positives (boolean flags) and true positive errors for each class.

    Args:
        dt_root_fpath: Detections root folder file path.
        gt_fpath: Ground truth file path.
        cfg: Detection configuration.

    Returns:
        cls_to_accum: Class to accumulated statistics dictionary of shape |C| -> (N, K + S) where C
            is the number of detection classes, K is the number of true positive thresholds used for
            AP computation, and S is the number of true positive errors.
        cls_to_ninst: Mapping of shape |C| -> (1,) the class names to the number of instances in the ground
            truth dataset.
    """
    log_id = gt_fpath.parents[1].stem
    logger.info(f"log_id = {log_id}")
    ts = gt_fpath.stem.split("_")[-1]

    dt_fpath = dt_root_fpath / f"{log_id}/per_sweep_annotations_amodal/" f"tracked_object_labels_{ts}.json"

    dts = np.array(read_label(str(dt_fpath)))
    gts = np.array(read_label(str(gt_fpath)))

    cls_to_accum = defaultdict(list)
    cls_to_ninst = defaultdict(int)
    for class_name in cfg.dt_classes:
        dt_filtered = filter_instances(
            dts,
            class_name,
            filter_metric=cfg.dt_metric,
            max_detection_range=cfg.max_dt_range,
        )
        gt_filtered = filter_instances(
            gts,
            class_name,
            filter_metric=cfg.dt_metric,
            max_detection_range=cfg.max_dt_range,
        )
        gt_filtered = remove_duplicate_instances(gt_filtered, cfg)

        logger.info(f"{dt_filtered.shape[0]} detections")
        logger.info(f"{gt_filtered.shape[0]} ground truth")
        if dt_filtered.shape[0] > 0:
            ranked_detections, scores = rank(dt_filtered)
            metrics = assign(ranked_detections, gt_filtered, cfg)
            cls_to_accum[class_name] = np.hstack((metrics, scores))

        cls_to_ninst[class_name] = gt_filtered.shape[0]
    return cls_to_accum, cls_to_ninst
    def __str__(self) -> str:
        frame_lidar = self.num_lidar_frame
        frame_image_ring = self.num_ring_camera_frame
        frame_image_stereo = self.num_stereo_camera_frame

        num_images = [len(self.image_list[cam]) for cam in CAMERA_LIST]

        num_annotations = [len(object_label.read_label(label)) for label in self.label_list]

        start_time = self.lidar_timestamp_list[0]
        end_time = self.lidar_timestamp_list[-1]

        time_in_sec = (end_time - start_time) * 10 ** (-9)
        return f"""
    def get_label_object(self, idx: int, log_id: Optional[str] = None) -> List[ObjectLabelRecord]:
        """Get label corresponding to frame index idx (in lidar frame).

        Args:
            idx: Lidar frame index
            log_id: ID of log to search (default: current log)

        Returns:
            List of ObjectLabelRecord info for a particular index
        """
        assert self.lidar_timestamp_list is not None
        assert self._lidar_timestamp_list is not None
        assert self.label_list is not None
        assert self._label_list is not None

        if log_id is None:
            log_id = self.current_log

        assert idx < len(self._lidar_timestamp_list[log_id])

        return object_label.read_label(self._label_list[log_id][idx])
예제 #4
0
def accumulate(
    dt_root_fpath: Path, gt_fpath: Path, cfg: DetectionCfg,
    avm: Optional[ArgoverseMap]
) -> Tuple[DefaultDict[str, np.ndarray], DefaultDict[str, int]]:
    """Accumulate the true/false positives (boolean flags) and true positive errors for each class.

    Args:
        dt_root_fpath: Detections root folder file path.
        gt_fpath: Ground truth file path.
        cfg: Detection configuration.

    Returns:
        cls_to_accum: Class to accumulated statistics dictionary of shape |C| -> (N, K + S) where C
            is the number of detection classes, K is the number of true positive thresholds used for
            AP computation, and S is the number of true positive errors.
        cls_to_ninst: Mapping of shape |C| -> (1,) the class names to the number of instances in the ground
            truth dataset.
    """
    log_id = gt_fpath.parents[1].stem
    logger.info(f"log_id = {log_id}")
    ts = int(gt_fpath.stem.split("_")[-1])

    dt_fpath = dt_root_fpath / f"{log_id}/per_sweep_annotations_amodal/" f"tracked_object_labels_{ts}.json"

    dts = np.array(read_label(str(dt_fpath)))
    gts = np.array(read_label(str(gt_fpath)))

    if cfg.eval_only_roi_instances and avm is not None:
        # go up 3 levels, because hierarchy is as follows:
        # {gt_root_fpath}/{log_id}/per_sweep_annotations_amodal/{gt_root_fname}
        gt_root_fpath = Path(gt_fpath).parents[2]
        city_SE3_egovehicle = get_city_SE3_egovehicle_at_sensor_t(
            ts, str(gt_root_fpath), log_id)
        if city_SE3_egovehicle is not None:
            log_city_name = read_city_name(
                os.path.join(gt_root_fpath, log_id, "city_info.json"))
            dts = filter_objs_to_roi(dts, avm, city_SE3_egovehicle,
                                     log_city_name)
            gts = filter_objs_to_roi(gts, avm, city_SE3_egovehicle,
                                     log_city_name)

    cls_to_accum = defaultdict(list)
    cls_to_ninst = defaultdict(int)
    for class_name in cfg.dt_classes:
        dt_filtered = filter_instances(
            dts,
            class_name,
            filter_metric=cfg.dt_metric,
            max_detection_range=cfg.max_dt_range,
        )
        gt_filtered = filter_instances(
            gts,
            class_name,
            filter_metric=cfg.dt_metric,
            max_detection_range=cfg.max_dt_range,
        )
        gt_filtered = remove_duplicate_instances(gt_filtered, cfg)

        logger.info(f"{dt_filtered.shape[0]} detections")
        logger.info(f"{gt_filtered.shape[0]} ground truth")
        if dt_filtered.shape[0] > 0:
            ranked_detections, scores = rank(dt_filtered)
            metrics = assign(ranked_detections, gt_filtered, cfg)
            cls_to_accum[class_name] = np.hstack((metrics, scores))

        cls_to_ninst[class_name] = gt_filtered.shape[0]
    return cls_to_accum, cls_to_ninst