Exemplo n.º 1
0
    def loadPredictions(
        self,
        pred_folder   # type: str
    ):
        # type: (...) -> None
        """Loads all predictions from the given folder.

        Args:
            pred_folder (str): Prediction folder
        """

        logger.info("Loading predictions...")
        predictions = getFiles(pred_folder)

        predictions.sort()
        logger.info("Found {} prediction files.".format(len(predictions)))

        for p in predictions:
            preds_for_image = []

            # extract CITY_RECORDID_IMAGE from filepath
            base = os.path.basename(p)
            base = base[:base.rfind("_")]

            # check for valid json file
            try:
                with open(p) as f:
                    data = json.load(f)
            except json.decoder.JSONDecodeError:
                logger.error("Invalid prediction json file: {}".format(base))
                raise

            # check for 'objects'
            if "objects" not in data.keys():
                logger.error("'objects' missing in prediction json file: {}".format(base))
                raise

            for d in data["objects"]:
                if (
                    "label" in d.keys() and
                    d["label"] in self.eval_params.labels_to_evaluate
                ):
                    try:
                        box_data = CsBbox3d()
                        box_data.fromJsonText(d)
                    except Exception:
                        logger.critical("Found incorrect annotation in {}.".format(p))
                        continue

                    preds_for_image.append(box_data)

            self.preds[base] = {
                "objects": preds_for_image
            }
Exemplo n.º 2
0
    def loadGT(
            self,
            gt_folder  # type: str
    ):
        # type: (...) -> None
        """Loads ground truth from the given folder.

        Args:
            gt_folder (str): Ground truth folder
        """

        logger.info("Loading GT...")
        gts = getFiles(gt_folder)

        logger.info("Found {} GT files.".format(len(gts)))

        self._stats["GT_stats"] = OrderedDict(
            (x, 0) for x in self.eval_params.labels_to_evaluate)

        for p in gts:
            gts_for_image = []
            ignores_for_image = []

            # extract CITY_RECORDID_IMAGE from filepath
            base = os.path.basename(p)
            base = base[:base.rfind("_")]

            with open(p) as f:
                data = json.load(f)

            # load 3D boxes
            for d in data["objects"]:
                if d["label"] in self.eval_params.labels_to_evaluate:
                    self._stats["GT_stats"][d["label"]] += 1
                    box_data = CsBbox3d()
                    box_data.fromJsonText(d)
                    gts_for_image.append(box_data)

            # load ignore regions
            for d in data["ignore"]:
                box_data = CsIgnore2d()
                box_data.fromJsonText(d)
                ignores_for_image.append(box_data)

            self.gts[base] = {
                "objects": gts_for_image,
                "ignores": ignores_for_image
            }
Exemplo n.º 3
0
    def loadGT(self, gt_folder: str) -> None:
        """Loads ground truth from the given folder.

        Args:
            gt_folder (str): Ground truth folder
        """

        logger.info("Loading GT...")
        gts = getFiles(gt_folder)

        logger.info("Found %d GT files." % len(gts))

        self._stats["GT_stats"] = {
            x: 0
            for x in self.eval_params.labels_to_evaluate
        }

        for p in gts:
            gts_for_image = []
            ignores_for_image = []

            # extract CITY_RECORDID_IMAGE from filepath
            base = os.path.basename(p)
            base = base[:base.rfind("_")]

            with open(p) as f:
                data = json.load(f)

            # load 3D boxes
            for d in data["annotation"]:
                if d["class_name"] in self.eval_params.labels_to_evaluate:
                    self._stats["GT_stats"][d["class_name"]] += 1
                    box_data = Box3DObject(d)
                    gts_for_image.append(box_data)

            # load ignore regions
            for d in data["ignore"]:
                box_data = IgnoreObject(d)
                ignores_for_image.append(box_data)

            self.gts[base] = {
                "objects": gts_for_image,
                "ignores": ignores_for_image
            }
Exemplo n.º 4
0
    def loadPredictions(self, pred_folder: str) -> None:
        """Loads all predictions from the given folder.

        Args:
            pred_folder (str): Prediction folder
        """

        logger.info("Loading predictions...")
        predictions = getFiles(pred_folder)

        predictions.sort()
        logger.info("Found %d prediction files." % len(predictions))

        for p in predictions:
            preds_for_image = []

            # extract CITY_RECORDID_IMAGE from filepath
            base = os.path.basename(p)

            base = base[:base.rfind("_")]

            with open(p) as f:
                data = json.load(f)

            for d in data["annotation"]:
                if ("class_name" in d.keys() and d["class_name"]
                        in self.eval_params.labels_to_evaluate):
                    try:
                        box_data = Box3DObject(d)
                    except:
                        logger.critical("Found incorrect annotation in %s." %
                                        p)
                        continue

                    preds_for_image.append(box_data)

            self.preds[base] = {"objects": preds_for_image}
Exemplo n.º 5
0
    def loadGT(
            self,
            gt_folder  # type: str
    ):
        # type: (...) -> None
        """Loads ground truth from the given folder.

        Args:
            gt_folder (str): Ground truth folder
        """

        logger.info("Loading GT...")
        gts = getFiles(gt_folder)

        logger.info("Found {} GT files.".format(len(gts)))

        self._stats["GT_stats"] = OrderedDict(
            (x, 0) for x in self.eval_params.labels_to_evaluate)

        for p in gts:
            gts_for_image = []
            ignores_for_image = []

            # extract CITY_RECORDID_IMAGE from filepath
            base = os.path.basename(p)
            base = base[:base.rfind("_")]

            # check for valid json file
            try:
                with open(p) as f:
                    data = json.load(f)
            except json.decoder.JSONDecodeError:
                logger.error("Invalid GT json file: {}".format(base))
                raise

            # check for 'objects' and 'sensor'
            if "objects" not in data.keys():
                msg = "'objects' missing in GT json file: {}".format(base)
                logger.error(msg)
                raise KeyError(msg)
            if "sensor" not in data.keys():
                msg = "'sensor' missing in GT json file: {}".format(base)
                logger.error(msg)
                raise KeyError(msg)

            # load Camera object
            camera = Camera(data["sensor"]["fx"], data["sensor"]["fy"],
                            data["sensor"]["u0"], data["sensor"]["v0"],
                            data["sensor"]["sensor_T_ISO_8855"])

            # load 3D boxes
            for d in data["objects"]:
                if d["label"] in self.eval_params.labels_to_evaluate:
                    self._stats["GT_stats"][d["label"]] += 1
                    box_data = CsBbox3d()
                    box_data.fromJsonText(d)
                    gts_for_image.append(box_data)

            # load ignore regions
            for d in data["ignore"]:
                box_data = CsIgnore2d()
                box_data.fromJsonText(d)
                ignores_for_image.append(box_data)

            self.gts[base] = {
                "objects": gts_for_image,
                "ignores": ignores_for_image
            }

            self.cameras[base] = camera