Skip to content

Commit

Permalink
Merge pull request #6 from supervisely-ecosystem/label_id-hotfix
Browse files Browse the repository at this point in the history
label_id hotfix in main
  • Loading branch information
qanelph authored Sep 1, 2021
2 parents 92d8531 + c7ae629 commit f42e6fc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def create_coco_annotation(meta, categories_mapping, dataset, user_name, image_i
id=label_id, # Each annotation also has an id (unique to all other annotations in the dataset)
))
progress.iter_done_report()
return coco_ann
return coco_ann, label_id


def upload_coco_project(full_archive_name, result_archive, app_logger):
Expand Down
5 changes: 3 additions & 2 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ def export_to_coco(api: sly.Api, task_id, context, state, app_logger):
meta = convert_geometry.prepare_meta(g.meta)
categories_mapping = f.get_categories_map_from_meta(meta)
datasets = [ds for ds in api.dataset.get_list(g.project_id)]
label_id = 0

for dataset in datasets:
coco_dataset_dir = os.path.join(g.coco_base_dir, dataset.name)
img_dir, ann_dir = f.create_coco_dataset(coco_dataset_dir)

coco_ann = {}
label_id = 0
images = api.image.get_list(dataset.id)
ds_progress = sly.Progress('Converting dataset: {}'.format(dataset.name), total_cnt=len(images), min_report_percent=5)
for batch in sly.batched(images):
Expand All @@ -28,7 +29,7 @@ def export_to_coco(api: sly.Api, task_id, context, state, app_logger):
ann_infos = api.annotation.download_batch(dataset.id, image_ids)
anns = [sly.Annotation.from_json(x.annotation, g.meta) for x in ann_infos]
anns = [convert_geometry.convert_annotation(ann, meta) for ann in anns]
coco_ann = f.create_coco_annotation(meta, categories_mapping, dataset, g.user_name, batch, anns, label_id, coco_ann, ds_progress)
coco_ann, label_id = f.create_coco_annotation(meta, categories_mapping, dataset, g.user_name, batch, anns, label_id, coco_ann, ds_progress)
with open(os.path.join(ann_dir, f"instances.json"), 'w') as file:
json.dump(coco_ann, file)

Expand Down

0 comments on commit f42e6fc

Please sign in to comment.