Skip to content

Commit

Permalink
only annotations format added
Browse files Browse the repository at this point in the history
  • Loading branch information
qanelph committed Nov 26, 2021
1 parent f42e6fc commit d9a0bb9
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 15 deletions.
8 changes: 7 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@
"description": "Converts Supervisely to COCO format and prepares tar archive for download",
"docker_image": "supervisely/base-py-sdk:6.1.95",
"main_script": "src/main.py",
"modal_template": "src/modal.html",
"task_location": "workspace_tasks",
"icon": "https://i.imgur.com/9uY44aW.png",
"icon_background": "#FFFFFF",
"headless": true,
"modal_template_state": {
"selectedFormat": "annotations"
},
"context_menu": {
"target": ["images_project"],
"target": [
"images_project"
],
"context_root": "Download as"
}
}
19 changes: 8 additions & 11 deletions debug.env
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
PYTHONUNBUFFERED=1

# PB debug
DEBUG_APP_DIR="/home/paul/Documents/Work/Applications/in progress/export-to-coco/src/debug/app_data/"
DEBUG_CACHE_DIR="/home/paul/Documents/Work/Applications/in progress/export-to-coco/src/debug/app_cache"
DEBUG_APP_DIR="/Users/qanelph/Desktop/work/supervisely/app_debug_data"
DEBUG_CACHE_DIR="/Users/qanelph/Desktop/work/supervisely/app_debug_cache"

LOG_LEVEL="debug"

TASK_ID=8637
TASK_ID=11629

context.userId=7
context.teamId=8
context.workspaceId=58
modal.state.slyProjectId=6672
context.userId=283
context.teamId=238
context.workspaceId=340
modal.state.slyProjectId=6653


SERVER_ADDRESS="put your value here"
API_TOKEN="put your value here"
AGENT_TOKEN="put your value here"
modal.state.selectedFormat="annotations"
2 changes: 2 additions & 0 deletions src/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
my_app = sly.AppService()
api: sly.Api = my_app.public_api

selected_format = os.environ['modal.state.selectedFormat']

task_id = os.environ["TASK_ID"]
user_id = os.environ["context.userId"]
team_id = int(os.environ['context.teamId'])
Expand Down
12 changes: 9 additions & 3 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def export_to_coco(api: sly.Api, task_id, context, state, app_logger):
label_id = 0

for dataset in datasets:
sly.logger.info(f"processing {dataset.name}...")
coco_dataset_dir = os.path.join(g.coco_base_dir, dataset.name)
img_dir, ann_dir = f.create_coco_dataset(coco_dataset_dir)

Expand All @@ -23,8 +24,10 @@ def export_to_coco(api: sly.Api, task_id, context, state, app_logger):
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]
api.image.download_paths(dataset.id, image_ids, image_paths)

if g.selected_format == 'images':
image_paths = [os.path.join(coco_dataset_dir, img_dir, image_info.name) for image_info in batch]
api.image.download_paths(dataset.id, image_ids, image_paths)

ann_infos = api.annotation.download_batch(dataset.id, image_ids)
anns = [sly.Annotation.from_json(x.annotation, g.meta) for x in ann_infos]
Expand All @@ -33,6 +36,8 @@ def export_to_coco(api: sly.Api, task_id, context, state, app_logger):
with open(os.path.join(ann_dir, f"instances.json"), 'w') as file:
json.dump(coco_ann, file)

sly.logger.info(f"dataset {dataset.name} processed!")

full_archive_name = f"{task_id}_{g.project.name}.tar"
result_archive = os.path.join(g.storage_dir, full_archive_name)
f.upload_coco_project(full_archive_name, result_archive, app_logger)
Expand All @@ -44,7 +49,8 @@ def main():
"TASK_ID": g.task_id,
"context.teamId": g.team_id,
"context.workspaceId": g.workspace_id,
"context.projectId": g.project_id
"context.projectId": g.project_id,
"selected_format": g.selected_format
})

# Run application service
Expand Down
18 changes: 18 additions & 0 deletions src/modal.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<div>
<div class="fflex mt5"
style="padding: 2px 14px; flex-direction: column; align-items: center; justify-content: center;">
<div class="fflex mb10"
style="flex-direction: column; align-items: flex-end; justify-content: flex-start;">
<div style="padding-top: 2px; font-size: 14px; margin-right: 5px; font-weight: 500">Select format</div>


</div>
<el-radio-group v-model="state.selectedFormat" size="normal" @change="command('solo_mode_changed')">
<el-radio-button label="annotations">
<span>only annotations</span></el-radio-button>
<el-radio-button label="images">images and annotations</el-radio-button>
</el-radio-group>


</div>
</div>

0 comments on commit d9a0bb9

Please sign in to comment.