Skip to content

Commit

Permalink
Add Workflow and upgrade SDK to v6.73.141
Browse files Browse the repository at this point in the history
  • Loading branch information
GoldenAnpu committed Jul 29, 2024
1 parent a7cddd6 commit 366faf9
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 11 deletions.
13 changes: 4 additions & 9 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@
"name": "Convert Supervisely to YOLO v5 format",
"type": "app",
"version": "2.0.0",
"categories": [
"images",
"export"
],
"categories": ["images", "export"],
"description": "Transform project to YOLO v5 format and prepares tar archive for download",
"docker_image": "supervisely/import-export:6.73.93",
"docker_image": "supervisely/import-export:6.73.141",
"instance_version": "6.9.22",
"main_script": "src/convert_sly_to_yolov5.py",
"modal_template": "src/modal.html",
Expand All @@ -21,10 +18,8 @@
"icon": "https://i.imgur.com/pz3eSzx.png",
"icon_background": "#FFFFFF",
"context_menu": {
"target": [
"images_project"
],
"target": ["images_project"],
"context_root": "Download as"
},
"poster": "https://user-images.githubusercontent.com/106374579/183683758-89476d80-de3f-424f-9bfa-f1562703a168.png"
}
}
2 changes: 1 addition & 1 deletion dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
supervisely==6.73.93
supervisely==6.73.141
8 changes: 7 additions & 1 deletion src/convert_sly_to_yolov5.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import List, Tuple
from dotenv import load_dotenv
import supervisely as sly
from workflow import Workflow

# region constants
TRAIN_TAG_NAME = "train"
Expand Down Expand Up @@ -201,10 +202,15 @@ def _add_to_split(image_id, img_name, split_ids, split_image_paths, labels_dir,
sly.logger.info("Number of images in val: {}".format(val_count))

# Archiving and uploading the directory to the TeamFiles.
sly.output.set_download(result_dir)
file_info = sly.output.set_download(result_dir)
sly.logger.info("File uploaded, app stopped.")
# --------------------------------- Add Workflow Input And Output -------------------------------- #
workflow.add_input(project_id)
workflow.add_output(file_info)
# --------------------------------- Add Workflow Input And Output -------------------------------- #


if __name__ == "__main__":
api = sly.Api.from_env()
workflow = Workflow(api)
transform(api)
50 changes: 50 additions & 0 deletions src/workflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import supervisely as sly


def check_compatibility(func):
def wrapper(self, *args, **kwargs):
if self.is_compatible is None:
try:
self.is_compatible = self.check_instance_ver_compatibility()
except Exception as e:
sly.logger.error(
"Can not check compatibility with Supervisely instance. "
f"Workflow features will be disabled. Error: {repr(e)}"
)
self.is_compatible = False
if not self.is_compatible:
return
return func(self, *args, **kwargs)

return wrapper


class Workflow:
def __init__(self, api: sly.Api, min_instance_version: str = None):
self.is_compatible = None
self.api = api
self._min_instance_version = (
"6.9.31" if min_instance_version is None else min_instance_version
)

def check_instance_ver_compatibility(self):
if not self.api.is_version_supported(self._min_instance_version):
sly.logger.info(
f"Supervisely instance version {self.api.instance_version} does not support workflow features."
)
if not sly.is_community():
sly.logger.info(
f"To use them, please update your instance to version {self._min_instance_version} or higher."
)
return False
return True

@check_compatibility
def add_input(self, project_id: int):
self.api.app.workflow.add_input_project(project_id)
sly.logger.debug(f"Workflow: Input project - {project_id}")

@check_compatibility
def add_output(self, file_info: sly.api.file_api.FileInfo):
self.api.app.workflow.add_output_file(file_info)
sly.logger.debug(f"Workflow: Output file - {file_info.id if file_info else None}")

0 comments on commit 366faf9

Please sign in to comment.