Skip to content

Commit

Permalink
infer the number of keypoints if this was not added to the json
Browse files Browse the repository at this point in the history
  • Loading branch information
tlpss committed Dec 16, 2024
1 parent 088b101 commit e3f3970
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions airo-dataset-tools/airo_dataset_tools/data_parsers/coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,17 @@ def keypoints_coordinates_must_be_in_pixel_space(cls, v: Keypoints) -> Keypoints

@model_validator(mode="after")
def num_keypoints_matches_amount_of_labeled_keypoints(self) -> "CocoKeypointAnnotation":


labeled_keypoints = 0
for v in self.keypoints[2::3]:
if v > 0:
labeled_keypoints += 1

# if num_keypoints is not set, set it to the number of labeled keypoints
if self.num_keypoints is None:
self.num_keypoints = labeled_keypoints

assert (
labeled_keypoints == self.num_keypoints
), f"num_keypoints {self.num_keypoints} does not match number of labeled of keypoints {labeled_keypoints} for annotation {self.id}"
Expand Down

0 comments on commit e3f3970

Please sign in to comment.