Skip to content

Commit

Permalink
Merge pull request #4 from supervisely-ecosystem/user-name-hotfix
Browse files Browse the repository at this point in the history
annotations processing fix
  • Loading branch information
qanelph authored Aug 25, 2021
2 parents 2bcc963 + ab156fd commit e6e1617
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 28 deletions.
4 changes: 2 additions & 2 deletions debug.env
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ DEBUG_CACHE_DIR="/home/paul/Documents/Work/Applications/in progress/export-to-co

LOG_LEVEL="debug"

TASK_ID=8603
TASK_ID=8637

context.userId=7
context.teamId=8
context.workspaceId=58
modal.state.slyProjectId=1797
modal.state.slyProjectId=6672


SERVER_ADDRESS="put your value here"
Expand Down
51 changes: 27 additions & 24 deletions src/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ def get_categories_from_meta(meta):
return categories


def get_project_contributors():
pass


def coco_segmentation(segmentation): # works only with external vertices for now
segmentation = [coord for sublist in segmentation for coord in sublist]
return segmentation
Expand All @@ -47,30 +51,29 @@ def create_coco_dataset(coco_dataset_dir):
return img_dir, ann_dir


def create_coco_annotation(meta, categories_mapping, dataset, user_name, image_infos, anns, label_id, progress):
coco_ann = dict(
info=dict(
description=dataset.description,
url="None",
version=str(1.0),
year=int(dataset.created_at[:4]),
contributor=user_name,
date_created=dataset.created_at,
),
licenses=[dict(url="None", id=0, name="None")],
images=[
# license, url, file_name, height, width, date_captured, id
],
#type="instances",
annotations=[
# segmentation, area, iscrowd, image_id, bbox, category_id, id
],
categories=get_categories_from_meta(meta) # supercategory, id, name
)
sdfsc = []
for image_info, ann in zip(image_infos, anns):
def create_coco_annotation(meta, categories_mapping, dataset, user_name, image_infos, anns, label_id, coco_ann, progress):
if len(coco_ann) == 0:
coco_ann = dict(
info=dict(
description=dataset.description,
url="None",
version=str(1.0),
year=int(dataset.created_at[:4]),
contributor=user_name,
date_created=dataset.created_at,
),
licenses=[dict(url="None", id=0, name="None")],
images=[
# license, url, file_name, height, width, date_captured, id
],
#type="instances",
annotations=[
# segmentation, area, iscrowd, image_id, bbox, category_id, id
],
categories=get_categories_from_meta(meta) # supercategory, id, name
)

sdfsc.append(image_info.id)
for image_info, ann in zip(image_infos, anns):
coco_ann["images"].append(dict(
license="None",
file_name=image_info.name,
Expand Down Expand Up @@ -98,7 +101,7 @@ def create_coco_annotation(meta, categories_mapping, dataset, user_name, image_i
category_id=categories_mapping[label.obj_class.name], # The category id corresponds to a single category specified in the categories section
id=label_id, # Each annotation also has an id (unique to all other annotations in the dataset)
))
progress.iters_done_report(len(image_infos))
progress.iter_done_report()
return coco_ann


Expand Down
4 changes: 2 additions & 2 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def export_to_coco(api: sly.Api, task_id, context, state, app_logger):
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))
ds_progress = sly.Progress('Converting dataset: {}'.format(dataset.name), total_cnt=len(images), min_report_percent=5)
for batch in sly.batched(images):
image_ids = [image_info.id for image_info in batch]
image_paths = [os.path.join(coco_dataset_dir, img_dir, image_info.name) for image_info in batch]
Expand All @@ -28,7 +28,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, ds_progress)
coco_ann = 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 e6e1617

Please sign in to comment.