From 613c9afe8e5ec9a22acc99c4cdf2aee557b3a174 Mon Sep 17 00:00:00 2001 From: Chihiro Takigawa Date: Wed, 25 Sep 2024 20:18:04 +0900 Subject: [PATCH] =?UTF-8?q?COCO=E5=BD=A2=E5=BC=8F=E3=81=AEnum=5Fkeypoints?= =?UTF-8?q?=E7=AE=97=E5=87=BA=E3=83=AD=E3=82=B8=E3=83=83=E3=82=AF=E3=82=92?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fastlabel/converters.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/fastlabel/converters.py b/fastlabel/converters.py index 9b60598..ac66ede 100644 --- a/fastlabel/converters.py +++ b/fastlabel/converters.py @@ -260,13 +260,30 @@ def __get_coco_annotation_keypoints(keypoints: list, category_keypoints: list) - if keypoint["value"] } for category_key in category_keypoints: - value = keypoint_values.get(category_key, [0, 0, 0]) + value = keypoint_values.get(category_key) + if not value: + coco_annotation_keypoints.extend([0, 0, 0]) + continue # Adjust fastlabel data definition to coco format visibility = 2 if value[2] == 1 else 1 coco_annotation_keypoints.extend([value[0], value[1], visibility]) return coco_annotation_keypoints +COCO_KEYPOINT_V_INDEX = 2 + + +def __get_coco_num_keypoints(keypoints: list) -> int: + # https://cocodataset.org/#format-data + if not keypoints: + return 0 + num_keypoints = 0 + for keypoint in keypoints: + if keypoint["value"]: + num_keypoints += 1 + return num_keypoints + + def __get_coco_annotation( id_: int, points: list, @@ -278,7 +295,7 @@ def __get_coco_annotation( rotation: int, ) -> dict: annotation = {} - annotation["num_keypoints"] = len(keypoints) if keypoints else 0 + annotation["num_keypoints"] = __get_coco_num_keypoints(keypoints) annotation["keypoints"] = ( __get_coco_annotation_keypoints(keypoints, category["keypoints"]) if keypoints