Skip to content

Commit

Permalink
Merge pull request #117 from chrisrapson/keypoints
Browse files Browse the repository at this point in the history
Add capability to convert keypoints from COCO to YOLOv5 format
  • Loading branch information
alexheat committed Jul 17, 2023
2 parents fbea4f5 + badfabf commit 893253a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pylabel/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,20 @@ def ExportToCoco(self, output_path=None, cat_id_index=None):
}
]

# include keypoints, if available
if "ann_keypoints" in df.keys() and (not np.isnan(df["ann_keypoints"][i]).all()):
keypoints = df["ann_keypoints"][i]
if isinstance(keypoints, list):
n_keypoints = int(len(keypoints) / 3) # 3 numbers per keypoint: x,y,visibility
elif isinstance(keypoints, np.ndarray):
n_keypoints = int(keypoints.size / 3) # 3 numbers per keypoint: x,y,visibility
else:
raise TypeError('The keypoints array is expected to be either a list or a numpy array')
annotations[0]["num_keypoints"] = n_keypoints
annotations[0]["keypoints"] = keypoints
else:
pass

categories = [
{
"id": int(df["cat_id"][i]),
Expand Down

0 comments on commit 893253a

Please sign in to comment.