From e2f9d56e4fb81a3abfc6df7665c560a09d60d5f5 Mon Sep 17 00:00:00 2001 From: Almaz <79905215+almazgimaev@users.noreply.github.com> Date: Fri, 30 Aug 2024 18:46:18 +0200 Subject: [PATCH 1/6] test sdk version --- config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.json b/config.json index aac4b03..9973b46 100644 --- a/config.json +++ b/config.json @@ -11,7 +11,7 @@ "task_location": "workspace_tasks", "entrypoint": "python -m uvicorn src.main:app --host 0.0.0.0 --port 8000", "port": 8000, - "docker_image": "supervisely/model-benchmark:0.0.2", + "docker_image": "supervisely/model-benchmark:0.0.3", "instance_version": "6.11.10", "context_menu": { "target": ["images_project"] From d37b40e47a456d77a7cbcaf1be2d5bdd1e2f67d0 Mon Sep 17 00:00:00 2001 From: almaz Date: Fri, 30 Aug 2024 19:03:22 +0200 Subject: [PATCH 2/6] refactoring --- src/functions.py | 8 +--- src/main.py | 108 ++++++++++++----------------------------------- 2 files changed, 30 insertions(+), 86 deletions(-) diff --git a/src/functions.py b/src/functions.py index e038260..c65bdaf 100644 --- a/src/functions.py +++ b/src/functions.py @@ -1,8 +1,9 @@ -import src.globals as g import supervisely as sly from supervisely.nn import TaskType from supervisely.nn.inference import Session +import src.globals as g + geometry_to_task_type = { TaskType.OBJECT_DETECTION: [sly.Rectangle], TaskType.INSTANCE_SEGMENTATION: [sly.Bitmap, sly.Polygon], @@ -45,8 +46,3 @@ def get_classes(): not_matched_model_cls.append(obj_class) return (matched_proj_cls, matched_model_cls), (not_matched_proj_cls, not_matched_model_cls) - - -def get_matched_class_names(): - (cls_collection, _), _ = get_classes() - return [obj_cls.name for obj_cls in cls_collection] diff --git a/src/main.py b/src/main.py index d9e1472..3d86445 100644 --- a/src/main.py +++ b/src/main.py @@ -1,8 +1,5 @@ from typing import Optional -import src.functions as f -import src.globals as g -import src.workflow as w import supervisely as sly import supervisely.app.widgets as widgets from supervisely.nn.benchmark import ( @@ -11,11 +8,15 @@ ) from supervisely.nn.inference.session import SessionJSON +import src.functions as f +import src.globals as g +import src.workflow as w + def main_func(): api = g.api project = api.project.get_info_by_id(g.project_id) - if g.session_id is None: + if g.session is None: g.session = SessionJSON(api, g.session_id) task_type = g.session.get_deploy_info()["task_type"] @@ -26,13 +27,7 @@ def main_func(): pbar.show() report_model_benchmark.hide() - # selected_classes = select_classes.get_selected() - - # matches = [x[1] for x in select_classes.get_stat()["match"]] - # selected_classes = [x[0] for x in selected_classes if x[0] in matches] - if g.selected_classes is None: - g.selected_classes = f.get_matched_class_names() - + set_selected_classes_and_show_info() if task_type == "object detection": bm = ObjectDetectionBenchmark( api, @@ -90,17 +85,6 @@ def main_func(): app.stop() -# select_classes = widgets.MatchObjClasses( -# selectable=True, -# left_name="Model classes", -# right_name="GT project classes", -# ) -# select_classes.hide() -# not_matched_classes = widgets.MatchObjClasses( -# left_name="Model classes", -# right_name="GT project classes", -# ) -# not_matched_classes.hide() no_classes_label = widgets.Text( "Not found any classes in the project that are present in the model", status="error" ) @@ -123,27 +107,10 @@ def main_func(): controls_card = widgets.Card( title="Settings", description="Select Ground Truth project and deployed model session", - content=widgets.Container( - [sel_project, sel_app_session, button, report_model_benchmark, pbar] - ), + content=widgets.Container([sel_project, sel_app_session, button, report_model_benchmark, pbar]), ) -# matched_card = widgets.Card( -# title="✅ Available classes", -# description="Select classes that are present in the model and in the project", -# content=select_classes, -# ) -# matched_card.lock(message="Select project and model session to enable") - -# not_matched_card = widgets.Card( -# title="❌ Not available classes", -# description="List of classes that are not matched between the model and the project", -# content=not_matched_classes, -# ) -# not_matched_card.lock(message="Select project and model session to enable") - - layout = widgets.Container( widgets=[controls_card, widgets.Empty(), widgets.Empty()], # , matched_card, not_matched_card], direction="horizontal", @@ -155,51 +122,32 @@ def main_func(): ) +def set_selected_classes_and_show_info(): + matched, not_matched = f.get_classes() + _, matched_model_classes = matched + _, not_matched_model_classes = not_matched + total_classes_text.text = ( + f"{len(matched_model_classes) + len(not_matched_model_classes)} classes found in the model." + ) + selected_matched_text.text = f"{len(matched_model_classes)} classes can be used for evaluation." + not_matched_text.text = f"{len(not_matched_model_classes)} classes are not available for evaluation (not found in the GT project or have different geometry type)." + if len(matched_model_classes) > 0: + g.selected_classes = [obj_cls.name for obj_cls in matched_model_classes] + selected_matched_text.show() + if len(not_matched_model_classes) > 0: + not_matched_text.show() + else: + no_classes_label.show() + + def handle_selectors(active: bool): no_classes_label.hide() selected_matched_text.hide() not_matched_text.hide() - button.loading = True - # select_classes.hide() - # not_matched_classes.hide() if active: - matched, not_matched = f.get_classes() - _, matched_model_classes = matched - _, not_matched_model_classes = not_matched - - g.selected_classes = [obj_cls.name for obj_cls in matched_model_classes] - not_matched_classes_cnt = len(not_matched_model_classes) - total_classes = len(matched_model_classes) + len(not_matched_model_classes) - - total_classes_text.text = f"{total_classes} classes found in the model." - selected_matched_text.text = f"{len(matched_model_classes)} classes can be used for evaluation." - not_matched_text.text = f"{not_matched_classes_cnt} classes are not available for evaluation (not found in the GT project or have different geometry type)." - - if len(matched_model_classes) > 0: - selected_matched_text.show() - if not_matched_classes_cnt > 0: - not_matched_text.show() - button.enable() - button.loading = False - return - else: - no_classes_label.show() - # select_classes.set(left_collection=model_classes, right_collection=matched_model_classes) - - # matched_model_classes, model_classes = not_matched - # not_matched_classes.set(left_collection=model_classes, right_collection=matched_model_classes) - # stats = select_classes.get_stat() - # if len(stats["match"]) > 0: - # select_classes.show() - # not_matched_classes.show() - # button.enable() - # # matched_card.unlock() - # # not_matched_card.unlock() - # return - # else: - # no_classes_label.show() - button.loading = False - button.disable() + button.enable() + else: + button.disable() @sel_project.value_changed From 86f861c64566a5dc17f039905a0c1f69e1df5bea Mon Sep 17 00:00:00 2001 From: almaz Date: Fri, 30 Aug 2024 19:04:56 +0200 Subject: [PATCH 3/6] upgrade SDK version --- docker/Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 0b83acb..0dae85d 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,5 +1,5 @@ -FROM supervisely/base-py-sdk:6.73.166 +FROM supervisely/base-py-sdk:6.73.173 -RUN python3 -m pip install supervisely[model-benchmark]==6.73.166 +RUN python3 -m pip install supervisely[model-benchmark]==6.73.173 -LABEL python_sdk_version=6.73.166 \ No newline at end of file +LABEL python_sdk_version=6.73.173 \ No newline at end of file From b7a1b5e7d4a2d22616331942dba52adc2663fd79 Mon Sep 17 00:00:00 2001 From: almaz Date: Fri, 30 Aug 2024 19:05:51 +0200 Subject: [PATCH 4/6] upgrade docker image tag --- config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.json b/config.json index 9973b46..25cb89d 100644 --- a/config.json +++ b/config.json @@ -11,7 +11,7 @@ "task_location": "workspace_tasks", "entrypoint": "python -m uvicorn src.main:app --host 0.0.0.0 --port 8000", "port": 8000, - "docker_image": "supervisely/model-benchmark:0.0.3", + "docker_image": "supervisely/model-benchmark:0.0.4", "instance_version": "6.11.10", "context_menu": { "target": ["images_project"] From 6291638fd64bc98fb0df6cbd28f5cd62b18cf1ca Mon Sep 17 00:00:00 2001 From: almaz Date: Fri, 30 Aug 2024 19:20:28 +0200 Subject: [PATCH 5/6] fix init button state --- src/main.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main.py b/src/main.py index 3d86445..7c9f861 100644 --- a/src/main.py +++ b/src/main.py @@ -181,3 +181,6 @@ def start_evaluation(): if g.autostart: start_evaluation() + +if g.project_id and g.session_id: + handle_selectors(True) \ No newline at end of file From 7d2295c83cffb5b12a389fd39e3e5ead3f5ed1eb Mon Sep 17 00:00:00 2001 From: almaz Date: Fri, 30 Aug 2024 19:25:27 +0200 Subject: [PATCH 6/6] stop if no classes found for evaluation --- src/main.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main.py b/src/main.py index 7c9f861..b7a37af 100644 --- a/src/main.py +++ b/src/main.py @@ -24,10 +24,13 @@ def main_func(): w.workflow_input(api, project, g.session_id) # ======================================================= - pbar.show() report_model_benchmark.hide() set_selected_classes_and_show_info() + if g.selected_classes is None or len(g.selected_classes) == 0: + return + + pbar.show() if task_type == "object detection": bm = ObjectDetectionBenchmark( api,