def get_group_data(
        self,
        height: int,
        width: int,
        anns: List,
        file_key: str,
        has_keypoints: bool = False,
    ):
        """Generic function to process annotations for any group"""
        n_anns = len(anns)

        masks = np.zeros((height, width, n_anns))
        boxes = np.zeros((n_anns, 4))
        categories = np.zeros((n_anns))
        areas = np.zeros((n_anns))
        iscrowds = np.zeros((n_anns))
        supercats = np.zeros((n_anns))
        keypoints = None

        if has_keypoints:
            keypoints = np.zeros((51, n_anns))

        coco = self.coco_instances[file_key]
        cat_info = self.category_info[file_key]
        cat_names = self.cat_names[file_key]
        supercat_names = self.super_cat_names[file_key]

        for i, ann in enumerate(anns):
            masks[:, :, i] = coco.annToMask(ann)
            boxes[i, :] = ann["bbox"]

            cat_name = next(
                cat_info[j]["name"]
                for j in range(len(cat_info))
                if cat_info[j]["id"] == ann["category_id"]
            )
            supercat_name = next(
                cat_info[j]["supercategory"]
                for j in range(len(cat_info))
                if cat_info[j]["id"] == ann["category_id"]
            )

            categories[i] = cat_names.index(cat_name)
            supercats[i] = supercat_names.index(supercat_name)

            areas[i] = ann.get("area", 0)
            iscrowds[i] = ann.get("iscrowd", 0)

            if keypoints is not None and "keypoints" in ann:
                keypoints[:, i] = np.array(ann["keypoints"])

        result = {
            "masks": masks.astype("bool"),
            "boxes": boxes.astype("float32"),
            "categories": categories.astype("uint32"),
            "super_categories": supercats.astype("uint32"),
            "areas": areas.astype("uint32"),
            "iscrowds": iscrowds.astype("bool"),
        }

        if keypoints is not None:
            result["keypoints"] = keypoints.astype("int32")

        return result
Generic function to process annotations for any group
python/deeplake/ingestion/coco/from_coco.py