Skip to content

Commit

Permalink
add handle_exceptions and main_wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
almazgimaev committed Nov 14, 2023
1 parent fd62294 commit bf25dde
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@

from dotenv import load_dotenv

from supervisely import handle_exceptions


if sly.is_development():
load_dotenv("local.env")
load_dotenv(os.path.expanduser("~/supervisely.env"))


batch_size = 10
STORAGE_DIR = sly.app.get_data_dir()
TRAIN_TAG_NAME = "train"
VAL_TAG_NAME = "val"

Expand Down Expand Up @@ -163,6 +164,7 @@ def prepare_yaml(result_dir_name, result_dir, class_names, class_colors):
class MyExport(sly.app.Export):
def process(self, context: sly.app.Export.Context):
api = sly.Api.from_env()
storage_dir = sly.app.get_data_dir()

project = api.project.get_info_by_id(id=context.project_id)
if context.dataset_id is not None:
Expand All @@ -174,7 +176,7 @@ def process(self, context: sly.app.Export.Context):
for ds in datasets:
images_count += ds.images_count
result_dir_name = f"{project.id}_{project.name}"
result_dir = os.path.join(STORAGE_DIR, result_dir_name)
result_dir = os.path.join(storage_dir, result_dir_name)
sly.fs.mkdir(result_dir)

dir_names = prepare_trainval_dirs(result_dir)
Expand Down Expand Up @@ -246,5 +248,11 @@ def process(self, context: sly.app.Export.Context):
return result_dir


app = MyExport()
app.run()
@handle_exceptions
def main():
app = MyExport()
app.run()


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

0 comments on commit bf25dde

Please sign in to comment.