Skip to content

Commit

Permalink
improve logging and clean dir
Browse files Browse the repository at this point in the history
  • Loading branch information
almazgimaev committed Dec 21, 2023
1 parent 77ac202 commit c80fc7b
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import os
from distutils.util import strtobool
from supervisely.io.exception_handlers import handle_exception

import supervisely as sly
from dotenv import load_dotenv
Expand All @@ -28,18 +29,14 @@ def process(self, context: sly.app.Export.Context):
if context.dataset_id is not None:
datasets = [api.dataset.get_info_by_id(context.dataset_id)]
elif len(selected_datasets) > 0 and not all_datasets:
datasets = [
api.dataset.get_info_by_id(dataset_id)
for dataset_id in selected_datasets
]
datasets = [api.dataset.get_info_by_id(dataset_id) for dataset_id in selected_datasets]
else:
datasets = api.dataset.get_list(project.id)

project_meta = sly.ProjectMeta.from_json(api.project.get_meta(project.id))
categories_mapping = f.get_categories_map_from_meta(project_meta)

result_dir = f.create_project_dir(project)

label_id = 0
for dataset in datasets:
img_dir, ann_dir = f.create_coco_dataset(result_dir, dataset.name)
Expand All @@ -48,9 +45,7 @@ def process(self, context: sly.app.Export.Context):

if selected_filter == "annotated":
images = [
image
for image in images
if image.labels_count > 0 or len(image.tags) > 0
image for image in images if image.labels_count > 0 or len(image.tags) > 0
]

coco_ann = {}
Expand Down Expand Up @@ -87,5 +82,21 @@ def process(self, context: sly.app.Export.Context):
return result_dir


app = MyExport()
app.run()
def main():
try:
app = MyExport()
app.run()
except Exception as e:
exception_handler = handle_exception(e)
if exception_handler:
raise Exception(exception_handler.get_message_for_modal_window()) from e
else:
raise e
finally:
if not sly.is_development():
sly.logger.info(f"Remove temp directory: {sly.app.get_data_dir()}")
sly.fs.remove_dir(sly.app.get_data_dir())


if __name__ == "__main__":
sly.main_wrapper("main", main)

0 comments on commit c80fc7b

Please sign in to comment.