From 2a793b346c5a1eb096f86e7a1aa5195b0075f9f6 Mon Sep 17 00:00:00 2001 From: iwatkot Date: Mon, 5 Feb 2024 17:40:51 +0300 Subject: [PATCH] Inference settings. --- project_dataset/src/globals.py | 3 ++ project_dataset/src/main.py | 5 +- project_dataset/src/ui/connect_nn.py | 7 +++ project_dataset/src/ui/inference_settings.py | 52 ++++++++++++++++++++ 4 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 project_dataset/src/ui/inference_settings.py diff --git a/project_dataset/src/globals.py b/project_dataset/src/globals.py index 5dec097..c78aba9 100644 --- a/project_dataset/src/globals.py +++ b/project_dataset/src/globals.py @@ -29,7 +29,10 @@ # endregion +# region ui-consants deployed_nn_tags = ["deployed_nn"] +inference_modes = ["full image", "sliding window"] +add_predictions_modes = ["merge with existing labels", "replace existing labels"] ann_cache = defaultdict(list) # only one (current) image in cache project_info = None diff --git a/project_dataset/src/main.py b/project_dataset/src/main.py index 38ca056..4d6f65f 100644 --- a/project_dataset/src/main.py +++ b/project_dataset/src/main.py @@ -2,9 +2,12 @@ from supervisely.app.widgets import Container import project_dataset.src.ui.connect_nn as connect_nn +import project_dataset.src.ui.inference_settings as inference_settings import project_dataset.src.ui.input_data as input_data import project_dataset.src.ui.nn_info as nn_info -layout = Container(widgets=[input_data.card, connect_nn.card, nn_info.card]) +layout = Container( + widgets=[input_data.card, connect_nn.card, nn_info.card, inference_settings.card] +) app = sly.Application(layout=layout) diff --git a/project_dataset/src/ui/connect_nn.py b/project_dataset/src/ui/connect_nn.py index 79e0e7e..2a8e776 100644 --- a/project_dataset/src/ui/connect_nn.py +++ b/project_dataset/src/ui/connect_nn.py @@ -2,6 +2,7 @@ from supervisely.app.widgets import Button, Card, Container, ModelInfo, SelectAppSession, Text import project_dataset.src.globals as g +import project_dataset.src.ui.inference_settings as inference_settings import project_dataset.src.ui.nn_info as nn_info select_session = SelectAppSession(g.team_id, g.deployed_nn_tags) @@ -58,6 +59,9 @@ def model_selected(): nn_info.card.unlock() nn_info.card.uncollapse() + inference_settings.card.unlock() + inference_settings.card.uncollapse() + @disconnect_button.click def model_changed(): @@ -72,6 +76,9 @@ def model_changed(): nn_info.card.lock() nn_info.card.collapse() + inference_settings.card.lock() + inference_settings.card.collapse() + def connect_to_model(): try: diff --git a/project_dataset/src/ui/inference_settings.py b/project_dataset/src/ui/inference_settings.py new file mode 100644 index 0000000..2f88e57 --- /dev/null +++ b/project_dataset/src/ui/inference_settings.py @@ -0,0 +1,52 @@ +from supervisely.app.widgets import Card, Checkbox, Container, Editor, Field, Input, Select + +import project_dataset.src.globals as g + +inference_mode = Select(items=[Select.Item(mode) for mode in g.inference_modes]) +inference_mode.set_value(g.inference_modes[0]) +mode_field = Field( + content=inference_mode, + title="Inference mode", + description="Select how to process images: full images or using sliding window.", +) + +class_tag_suffix = Input(value="model", minlength=1) +class_tag_suffix_field = Field( + content=class_tag_suffix, + title="Class and tag suffix", + description="Suffix that will be added to class and tag names.", +) +always_add_suffix = Checkbox("Always add suffix to model predictions") + +add_predictions_mode = Select(items=[Select.Item(mode) for mode in g.add_predictions_modes]) +add_predictions_mode.set_value(g.add_predictions_modes[0]) +add_predictions_mode_field = Field( + content=add_predictions_mode, + title="Add predictions mode", + description="Select how to add predictions to the project: by merging with existing labels or by replacing them.", +) + +additional_settings = Editor() +additional_settings_field = Field( + content=additional_settings, + title="Additional settings", + description="Model specific inference settings in YAML format.", +) + +card = Card( + "4️⃣ Inference settings", + "Choose additional settings for model inference.", + content=Container( + [ + mode_field, + class_tag_suffix_field, + always_add_suffix, + add_predictions_mode_field, + additional_settings_field, + ] + ), + collapsable=True, + lock_message="Connect to the deployed neural network on step 2️⃣.", +) +card.lock() +card.collapse()