def _convert_bbox_manifest()

in gt_converter/convert_coco.py [0:0]


    def _convert_bbox_manifest(self, manifest_path, job_name, output_coco_json_path):
        """
        Converts a single bounding box manifest file into COCO format.
        :param manifest_path: Path of the GT manifest file
        :param job_name: Name of the GT job
        :param output_coco_json_path: Output path for converted COCO json.
        """
        image_id = 0
        annotation_id = 0
        annotations = []
        images = []
        category_ids = {}

        for annotation in self.manifest_reader(manifest_path):
            w = annotation[job_name]["image_size"][0]["width"]
            h = annotation[job_name]["image_size"][0]["height"]
            images.append(
                {
                    "file_name": annotation["source-ref"],
                    "height": h,
                    "width": w,
                    "id": image_id,
                }
            )

            for bbox in annotation[job_name]["annotations"]:
                coco_bbox = {
                    "iscrowd": 0,
                    "image_id": image_id,
                    "category_id": bbox["class_id"],
                    "id": annotation_id,
                    "bbox": (bbox["left"], bbox["top"], bbox["width"], bbox["height"]),
                    "area": bbox["width"] * bbox["height"],
                }
                annotations.append(coco_bbox)
                annotation_id += 1
                category_ids.update(
                    annotation[job_name + "-metadata"]["class-map"]
                )  # TODO: Write as COCO format

            image_id += 1

        coco_json = {
            "type": "instances",
            "images": images,
            "categories": category_ids,
            "annotations": annotations,
        }

        with open(output_coco_json_path, "w") as f:
            json.dump(coco_json, f)