Skip to content

Instantly share code, notes, and snippets.

@Tob-iee
Created September 13, 2023 14:00
Show Gist options
  • Save Tob-iee/2a31b6e6d0ab243ac55e2b8359dc37f1 to your computer and use it in GitHub Desktop.
Save Tob-iee/2a31b6e6d0ab243ac55e2b8359dc37f1 to your computer and use it in GitHub Desktop.
Built, write and read annotations in COCO format using the COCO library
def coco_format_loader(train_dataset_version, label_names, coco_annotations_path):
coco_annotation = train_dataset_version.build_coco_file_locally(
enforced_ordered_categories=label_names
)
annotations_dict = coco_annotation.dict()
with open(coco_annotations_path, "w") as f:
f.write(json.dumps(annotations_dict))
annotations_coco = COCO(coco_annotations_path)
return annotations_coco
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment