diff --git a/.vscode/settings.json b/.vscode/settings.json index 97043f84..717ed1b2 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,30 +1,51 @@ { - "files.exclude": { - "**/__pycache__": true, - "build": true, - "supervisely.egg-info": true, - ".venv": true - }, - "python.defaultInterpreterPath": ".venv/bin/python", - "editor.formatOnSave": true, - "editor.formatOnPaste": true, - "editor.formatOnType": true, - "black-formatter.args": ["--line-length", "100"], - "[html]": { - "editor.defaultFormatter": "esbenp.prettier-vscode" - }, - "[json]": { - "editor.defaultFormatter": "esbenp.prettier-vscode" - }, - "[python]": { - "editor.defaultFormatter": "ms-python.black-formatter" - }, - "debug.inlineValues": "off", - "python.analysis.typeCheckingMode": "off", - "python.analysis.autoImportCompletions": false, - "autoDocstring.docstringFormat": "sphinx", - "autoDocstring.customTemplatePath": "docs/.mustache", - "python.testing.pytestArgs": ["tests/inference_cache"], - "python.testing.unittestEnabled": false, - "python.testing.pytestEnabled": true -} + "files.exclude": { + "**/__pycache__": true, + "build": true, + "supervisely.egg-info": true, + ".venv": true + }, + "python.defaultInterpreterPath": ".venv/bin/python", + "editor.formatOnSave": true, + "editor.formatOnPaste": true, + "editor.formatOnType": true, + "black-formatter.args": [ + "--line-length", + "100" + ], + "[html]": { + "editor.defaultFormatter": "vscode.html-language-features" + }, + "[json]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + }, + "[python]": { + "editor.defaultFormatter": "ms-python.black-formatter", + "editor.formatOnSave": true, + "editor.codeActionsOnSave": { + "source.organizeImports": "explicit" + }, + }, + "isort.args": [ + "--profile", + "black" + ], + "debug.inlineValues": "off", + "python.analysis.typeCheckingMode": "off", + "python.analysis.autoImportCompletions": false, + "autoDocstring.docstringFormat": "sphinx", + "autoDocstring.customTemplatePath": "docs/.mustache", + "python.testing.pytestArgs": [ + "tests/inference_cache" + ], + "python.testing.unittestEnabled": false, + "python.testing.pytestEnabled": true, + "workbench.colorCustomizations": { + "minimap.errorHighlight": "#ff0000", + "editorOverviewRuler.errorForeground": "#ff0000", + "editorOverviewRuler.warningForeground": "#ff9900", + "minimap.warningHighlight": "#ff9900", + "minimap.infoHighlight": "#00a8aa", + "editorOverviewRuler.infoForeground": "#00a8aa" + } +} \ No newline at end of file diff --git a/README.md b/README.md index e06c91d7..6ebdcd6d 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,7 @@ This application is a versatile tool designed for data transformation tasks (lik | [Deploy MMDetection](https://github.com/supervisely-ecosystem/data-nodes/blob/master/src/ui/dtl/actions/neural_networks/deploy/mmdetection.md) | Deploy pretrained or custom MMDetection model. | + | - | | [Deploy MMSegmentation](https://github.com/supervisely-ecosystem/data-nodes/blob/master/src/ui/dtl/actions/neural_networks/deploy/mmsegmentation.md) | Deploy pretrained or custom MMSegmentation model. | + | - | | [Deploy RT-DETR](https://github.com/supervisely-ecosystem/data-nodes/blob/master/src/ui/dtl/actions/neural_networks/deploy/rtdetr.md) | Deploy pretrained or custom RT-DETR model. | + | - | +| [Deploy RT-DETRv2](https://github.com/supervisely-ecosystem/data-nodes/blob/master/src/ui/dtl/actions/neural_networks/deploy/rtdetrv2.md) | Deploy pretrained or custom RT-DETRv2 model. | + | - | | **Other** | | | | | [Dummy](https://github.com/supervisely-ecosystem/data-nodes/blob/master/src/ui/dtl/actions/other/dummy/README.md#dummy) | Dummy node. Do nothing. Can be used to merge layers. | + | - | | [Dataset](https://github.com/supervisely-ecosystem/data-nodes/blob/master/src/ui/dtl/actions/other/dataset/README.md#dataset) | All data will be put into a single dataset. | + | - | diff --git a/config.json b/config.json index e8fa1392..7e27f02f 100644 --- a/config.json +++ b/config.json @@ -4,7 +4,7 @@ "description": "[Beta] Drag and drop interface for building custom DataOps pipelines", "entrypoint": "python -m uvicorn src.main:app --host 0.0.0.0 --port 8000", "headless": false, - "docker_image": "supervisely/data-nodes:1.0.26", + "docker_image": "supervisely/data-nodes:1.0.27", "modal_template": "src/modal.html", "modal_template_state": { "modalityType": "images" diff --git a/src/compute/layers/processing/DeployLayer.py b/src/compute/layers/processing/DeployLayer.py index 311d1a79..29bbc525 100644 --- a/src/compute/layers/processing/DeployLayer.py +++ b/src/compute/layers/processing/DeployLayer.py @@ -237,3 +237,38 @@ class DeployRTDETRLayer(DeployLayer): }, }, } + + +class DeployRTDETRv2Layer(DeployLayer): + action = "deploy_rtdetrv2" + title = "Deploy RT-DETRv2" + + layer_settings = { + "required": ["settings"], + "properties": { + "settings": { + "type": "object", + "required": [ + "session_id", + "agent_id", + "device", + "model_source", + "checkpoint_name", + "task_type", + "checkpoint_url", + "stop_model_session", + ], + "properties": { + "session_id": {"type": "integer"}, + "agent_id": {"type": "integer"}, + "device": {"type": "string"}, + "model_source": {"type": "string"}, + "task_type": {"type": "string"}, + "checkpoint_name": {"type": "string"}, + "checkpoint_url": {"oneOf": [{"type": "string"}, {"type": "null"}]}, + "runtime": {"type": "string"}, + "stop_model_session": {"type": "boolean"}, + }, + }, + }, + } diff --git a/src/ui/dtl/__init__.py b/src/ui/dtl/__init__.py index e314f03b..2280c014 100644 --- a/src/ui/dtl/__init__.py +++ b/src/ui/dtl/__init__.py @@ -83,7 +83,8 @@ DeployYOLOV8Action, DeployMMDetectionAction, DeployMMSegmentationAction, - DeployRTETRAction, + DeployRTDETRAction, + DeployRTDETRv2Action, ) from .actions.neural_networks.apply_nn_inference.apply_nn_inference import ApplyNNInferenceAction @@ -224,7 +225,8 @@ DeployYOLOV8Action.name, DeployMMDetectionAction.name, DeployMMSegmentationAction.name, - DeployRTETRAction.name, + DeployRTDETRAction.name, + DeployRTDETRv2Action.name, ApplyNNInferenceAction.name, ], OTHER: [ @@ -307,7 +309,8 @@ DeployYOLOV8Action.name: DeployYOLOV8Action, DeployMMDetectionAction.name: DeployMMDetectionAction, DeployMMSegmentationAction.name: DeployMMSegmentationAction, - DeployRTETRAction.name: DeployRTETRAction, + DeployRTDETRAction.name: DeployRTDETRAction, + DeployRTDETRv2Action.name: DeployRTDETRv2Action, ApplyNNInferenceAction.name: ApplyNNInferenceAction, # Other layers DatasetAction.name: DatasetAction, diff --git a/src/ui/dtl/actions/neural_networks/deploy/deploy.py b/src/ui/dtl/actions/neural_networks/deploy/deploy.py index 852506f3..e14115dc 100644 --- a/src/ui/dtl/actions/neural_networks/deploy/deploy.py +++ b/src/ui/dtl/actions/neural_networks/deploy/deploy.py @@ -2,6 +2,7 @@ from os.path import realpath, dirname from supervisely import logger from supervisely.nn.inference.session import Session +from supervisely.nn.experiments import get_experiment_infos from src.ui.dtl.Layer import Layer @@ -39,6 +40,10 @@ rtdetr as pretrained_rtdetr, ) +from src.ui.dtl.actions.neural_networks.deploy.layout.pretrained_models import ( + rtdetrv2 as pretrained_rtdetrv2, +) + class DeployBaseAction(DeployNNAction): name = "deploy_base" @@ -124,7 +129,11 @@ def agent_selector_sidebar_save_btn_cb(): # ----------------------------- # MODEL SELECTOR - custom_models = cls.artifacts.get_list() + + if cls.train_version == "v2": + custom_models = get_experiment_infos(g.api, g.TEAM_ID, cls.framework_name) + else: + custom_models = cls.artifacts.get_list_experiment_info() ( # sidebar # custom options @@ -146,7 +155,9 @@ def agent_selector_sidebar_save_btn_cb(): model_selector_layout_container, model_selector_stop_model_after_pipeline_checkbox, ) = create_model_selector_widgets( - cls.framework_name, cls.pretrained_models, custom_models, cls.custom_task_types + cls.framework_name, + cls.pretrained_models, + custom_models, ) if cls.need_runtime_selector is False: model_selector_runtime_field.hide() @@ -163,9 +174,13 @@ def model_selector_sidebar_save_btn_cb(): model_selector_runtime_selector_sidebar, model_selector_sidebar_custom_model_table, model_selector_stop_model_after_pipeline_checkbox, + cls.train_version, ) utils.set_model_selector_preview( - saved_settings, model_selector_preview, model_selector_preview_type + saved_settings, + model_selector_preview, + model_selector_preview_type, + cls.train_version, ) # ----------------------------- @@ -211,8 +226,7 @@ def model_serve_btn_cb(): utils.set_model_serve_preview("", model_serve_preview) # add validation success = utils.validate_settings( - saved_settings, - model_serve_preview, + saved_settings, model_serve_preview, cls.train_version ) if not success: agent_selector_layout_edit_btn.enable() @@ -228,7 +242,7 @@ def model_serve_btn_cb(): g.api.app.wait_until_ready_for_api_calls(session.task_id, 10, 10) try: utils.set_model_serve_preview("Deploying model...", model_serve_preview) - utils.deploy_model(g.api, session.task_id, saved_settings) + utils.deploy_model(g.api, session.task_id, saved_settings, cls.train_version) logger.info(f"Session ID: {session.task_id} has been deployed") app_link_message = ( @@ -274,6 +288,7 @@ def _save_settings() -> dict: model_selector_runtime_selector_sidebar, model_selector_sidebar_custom_model_table, model_selector_stop_model_after_pipeline_checkbox, + cls.train_version, ) def get_settings(options_json: dict) -> dict: @@ -342,13 +357,13 @@ class DeployYOLOV5Action(DeployBaseAction): title = "Deploy YOLOv5" description = "Deploy YOLOv5 models." md_description = DeployBaseAction.read_md_file(dirname(realpath(__file__)) + "/yolov5.md") + train_version = "v1" # Framework settings framework = "yolov5" framework_name = "YOLOv5" slug = "supervisely-ecosystem/yolov5_2.0/serve" artifacts = YOLOv5v2(g.TEAM_ID) - custom_task_types = ["object detection"] pretrained_models = pretrained_yolov5 @@ -358,13 +373,13 @@ class DeployYOLOV8Action(DeployBaseAction): description = "Deploy YOLO v8 | v9 | v10 | v11 models." md_description = DeployBaseAction.read_md_file(dirname(realpath(__file__)) + "/yolov8.md") need_runtime_selector = True + train_version = "v1" # Framework settings framework = "yolov8" framework_name = "YOLOv8" slug = "supervisely-ecosystem/yolov8/serve" artifacts = YOLOv8(g.TEAM_ID) - custom_task_types = ["object detection", "instance segmentation", "pose estimation"] pretrained_models = pretrained_yolov8 @@ -373,13 +388,13 @@ class DeployMMDetectionAction(DeployBaseAction): title = "Deploy MMDetection" description = "Deploy MMDetection models." md_description = DeployBaseAction.read_md_file(dirname(realpath(__file__)) + "/mmdetection.md") + train_version = "v1" # Framework settings framework = "mmdetection3" framework_name = "MMDetection" slug = "supervisely-ecosystem/serve-mmdetection-v3" artifacts = MMDetection3(g.TEAM_ID) - custom_task_types = ["object detection", "instance segmentation"] pretrained_models = pretrained_mmdetection3 @@ -390,27 +405,43 @@ class DeployMMSegmentationAction(DeployBaseAction): md_description = DeployBaseAction.read_md_file( dirname(realpath(__file__)) + "/mmsegmentation.md" ) + train_version = "v1" # Framework settings framework = "mmsegmentation" framework_name = "MMSegmentation" slug = "supervisely-ecosystem/mmsegmentation/serve" artifacts = MMSegmentation(g.TEAM_ID) - custom_task_types = ["semantic segmentation"] pretrained_models = pretrained_mmsegmentation -class DeployRTETRAction(DeployBaseAction): +class DeployRTDETRAction(DeployBaseAction): name = "deploy_rtdetr" title = "Deploy RT-DETR" description = "Deploy RT-DETR models." md_description = DeployBaseAction.read_md_file(dirname(realpath(__file__)) + "/rtdetr.md") + train_version = "v1" # Framework settings framework = "rtdetr" framework_name = "RT-DETR" slug = "supervisely-ecosystem/rt-detr/supervisely_integration/serve" artifacts = RTDETR(g.TEAM_ID) - custom_task_types = ["object detection"] pretrained_models = pretrained_rtdetr need_runtime_selector = True + + +class DeployRTDETRv2Action(DeployBaseAction): + name = "deploy_rtdetrv2" + title = "Deploy RT-DETRv2" + description = "Deploy RT-DETRv2 models." + md_description = DeployBaseAction.read_md_file(dirname(realpath(__file__)) + "/rtdetrv2.md") + train_version = "v2" + + # Framework settings + framework = "rtdetrv2" + framework_name = "RT-DETRv2" + slug = "supervisely-ecosystem/rt-detrv2/supervisely_integration/serve" + artifacts = None + pretrained_models = pretrained_rtdetrv2 + need_runtime_selector = True diff --git a/src/ui/dtl/actions/neural_networks/deploy/layout/model_selector.py b/src/ui/dtl/actions/neural_networks/deploy/layout/model_selector.py index e106d222..6945c9f1 100644 --- a/src/ui/dtl/actions/neural_networks/deploy/layout/model_selector.py +++ b/src/ui/dtl/actions/neural_networks/deploy/layout/model_selector.py @@ -3,13 +3,14 @@ Button, Container, RadioTabs, - CustomModelsSelector, + ExperimentSelector, PretrainedModelsSelector, Checkbox, Select, Field, ) from supervisely.nn.inference import RuntimeType +from supervisely.nn.utils import ModelSource import src.globals as g from src.ui.dtl.utils import ( get_text_font_size, @@ -25,23 +26,14 @@ def get_available_runtimes(): def create_model_selector_widgets( - framework_name: str, pretrained_models: list, custom_models: list, custom_task_types: list = [] + framework_name: str, + pretrained_models: list, + custom_models: list, ): # SIDEBAR # CUSTOM MODEL OPTION SUPERVISELY - need_custom_task_types = len(custom_task_types) > 0 - - model_selector_sidebar_custom_model_table = CustomModelsSelector( - g.TEAM_ID, - custom_models, - need_custom_task_types, - custom_task_types, - ) - - custom_models_task_types = model_selector_sidebar_custom_model_table.get_available_task_types() - if "object detection" in custom_models_task_types: - model_selector_sidebar_custom_model_table.set_active_task_type("object detection") + model_selector_sidebar_custom_model_table = ExperimentSelector(g.TEAM_ID, custom_models) # ------------------------------ # PUBLIC MODEL OPTIONS @@ -66,7 +58,7 @@ def create_model_selector_widgets( # CUSTOM /PUBLIC TABS model_selector_sidebar_model_source_tabs = RadioTabs( - titles=["Custom models", "Pretrained public models"], + titles=[ModelSource.CUSTOM, ModelSource.PRETRAINED], descriptions=["Models trained by you", f"Models trained by {framework_name} team"], contents=[ model_selector_sidebar_custom_model_table, diff --git a/src/ui/dtl/actions/neural_networks/deploy/layout/pretrained_models.py b/src/ui/dtl/actions/neural_networks/deploy/layout/pretrained_models.py index 18fa75db..83610f5d 100644 --- a/src/ui/dtl/actions/neural_networks/deploy/layout/pretrained_models.py +++ b/src/ui/dtl/actions/neural_networks/deploy/layout/pretrained_models.py @@ -13923,3 +13923,81 @@ }, }, ] + +rtdetrv2 = [ + { + "Model": "RT-DETRv2-S", + "dataset": "COCO", + "AP_val": 48.1, + "Params(M)": 20, + "FPS(T4)": 217, + "meta": { + "task_type": "object detection", + "model_name": "RT-DETRv2-S", + "model_files": { + "checkpoint": "https://github.com/lyuwenyu/storage/releases/download/v0.2/rtdetrv2_r18vd_120e_coco_rerun_48.1.pth", + "config": "rtdetrv2_r18vd_120e_coco.yml", + }, + }, + }, + { + "Model": "RT-DETRv2-M*", + "dataset": "COCO", + "AP_val": 49.9, + "Params(M)": 31, + "FPS(T4)": 161, + "meta": { + "task_type": "object detection", + "model_name": "RT-DETRv2-M*", + "model_files": { + "checkpoint": "https://github.com/lyuwenyu/storage/releases/download/v0.1/rtdetrv2_r34vd_120e_coco_ema.pth", + "config": "rtdetrv2_r34vd_120e_coco.yml", + }, + }, + }, + { + "Model": "RT-DETRv2-M", + "dataset": "COCO", + "AP_val": 51.9, + "Params(M)": 36, + "FPS(T4)": 145, + "meta": { + "task_type": "object detection", + "model_name": "RT-DETRv2-M", + "model_files": { + "checkpoint": "https://github.com/lyuwenyu/storage/releases/download/v0.1/rtdetrv2_r50vd_m_7x_coco_ema.pth", + "config": "rtdetrv2_r50vd_m_7x_coco.yml", + }, + }, + }, + { + "Model": "RT-DETRv2-L", + "dataset": "COCO", + "AP_val": 53.4, + "Params(M)": 42, + "FPS(T4)": 108, + "meta": { + "task_type": "object detection", + "model_name": "RT-DETRv2-L", + "model_files": { + "checkpoint": "https://github.com/lyuwenyu/storage/releases/download/v0.1/rtdetrv2_r50vd_6x_coco_ema.pth", + "config": "rtdetrv2_r50vd_6x_coco.yml", + }, + }, + }, + { + "Model": "RT-DETRv2-X", + "dataset": "COCO", + "AP_val": 54.3, + "Params(M)": 76, + "FPS(T4)": 74, + "meta": { + "task_type": "object detection", + "model_name": "RT-DETRv2-X", + "model_files": { + "checkpoint": "https://github.com/lyuwenyu/storage/releases/download/v0.1/rtdetrv2_r101vd_6x_coco_from_paddle.pth", + "config": "rtdetrv2_r101vd_6x_coco.yml", + }, + }, + }, +] diff --git a/src/ui/dtl/actions/neural_networks/deploy/layout/utils.py b/src/ui/dtl/actions/neural_networks/deploy/layout/utils.py index d3f0bf7e..8eb52777 100644 --- a/src/ui/dtl/actions/neural_networks/deploy/layout/utils.py +++ b/src/ui/dtl/actions/neural_networks/deploy/layout/utils.py @@ -1,3 +1,4 @@ +from os.path import join from typing import List from supervisely.api.api import Api from supervisely.app.widgets import ( @@ -7,14 +8,16 @@ Select, RadioTabs, RadioGroup, - CustomModelsSelector, + ExperimentSelector, PretrainedModelsSelector, Checkbox, ) from supervisely.api.agent_api import AgentInfo from supervisely.api.app_api import SessionInfo +from supervisely.nn.utils import ModelSource import src.globals as g +from supervisely.io.fs import get_file_name_with_ext def set_agent_selector_preview( @@ -34,13 +37,21 @@ def set_model_selector_preview( settings: dict, model_selector_preview: Text, model_selector_preview_type: Text, + train_version: str = "v1", ): - if settings["model_source"] == "Pretrained models": + if settings["model_source"] == ModelSource.PRETRAINED: model_source = "Pretrained" - elif settings["model_source"] == "Custom models": + elif settings["model_source"] == ModelSource.CUSTOM: model_source = "Custom" - model_selector_preview.set(f"Checkpoint: {settings['checkpoint_name']}", "text") + if train_version == "v1": + checkpoint_name = settings["checkpoint_name"] + elif train_version == "v2": + checkpoint_name = get_file_name_with_ext( + settings["model_params"]["model_files"]["checkpoint"] + ) + + model_selector_preview.set(f"Checkpoint: {checkpoint_name}", "text") model_selector_preview_type.set(f"Type: {model_source}", "text") model_selector_preview.show() model_selector_preview_type.show() @@ -65,20 +76,38 @@ def save_model_settings( model_selector_sidebar_model_source_tabs: RadioGroup, model_selector_sidebar_public_model_table: PretrainedModelsSelector, model_selector_runtime_selector_sidebar: Select, - model_selector_sidebar_custom_model_table: CustomModelsSelector, + model_selector_sidebar_custom_model_table: ExperimentSelector, model_selector_stop_model_after_pipeline_checkbox: Checkbox, + train_version: str = "v1", ): # MODEL SELECTOR model_source = model_selector_sidebar_model_source_tabs.get_active_tab() - if model_source == "Pretrained public models": - model_source = "Pretrained models" - model_params = model_selector_sidebar_public_model_table.get_selected_model_params() + if model_source == ModelSource.PRETRAINED: + model_params = model_selector_sidebar_public_model_table.get_selected_model_params( + train_version=train_version + ) - elif model_source == "Custom models": - model_source = "Custom models" + elif model_source == ModelSource.CUSTOM: if model_selector_sidebar_custom_model_table.get_selected_row() is None: raise RuntimeError("Please, select a model before saving it.") - model_params = model_selector_sidebar_custom_model_table.get_selected_model_params() + experiment_info = model_selector_sidebar_custom_model_table.get_selected_experiment_info() + selected_checkpoint = ( + model_selector_sidebar_custom_model_table.get_selected_checkpoint_path() + ) + if train_version == "v1": + model_params = { + "task_type": experiment_info["task_type"], + "checkpoint_name": get_file_name_with_ext(selected_checkpoint), + "checkpoint_url": selected_checkpoint, + } + model_files = experiment_info["model_files"] + config = model_files.get("config") + if config is not None: + model_params["config_url"] = join( + experiment_info["artifacts_dir"], config.strip("/") + ) + elif train_version == "v2": + model_params = model_selector_sidebar_custom_model_table.get_deploy_params() stop_model_session = model_selector_stop_model_after_pipeline_checkbox.is_checked() @@ -99,7 +128,8 @@ def save_model_settings( runtime = model_selector_runtime_selector_sidebar.get_value() if runtime is not None: settings["runtime"] = runtime - + if train_version == "v2": + settings["model_params"] = model_params return settings @@ -115,8 +145,9 @@ def save_settings( model_selector_sidebar_model_source_tabs: RadioTabs, model_selector_sidebar_public_model_table: PretrainedModelsSelector, model_selector_runtime_selector_sidebar: Select, - model_selector_sidebar_custom_model_table: CustomModelsSelector, + model_selector_sidebar_custom_model_table: ExperimentSelector, model_selector_stop_model_after_pipeline_checkbox: Checkbox, + train_version: str = "v1", ): settings = save_agent_settings( settings, agent_selector_sidebar_selector, agent_selector_sidebar_device_selector @@ -128,6 +159,7 @@ def save_settings( model_selector_runtime_selector_sidebar, model_selector_sidebar_custom_model_table, model_selector_stop_model_after_pipeline_checkbox, + train_version, ) return settings @@ -135,20 +167,27 @@ def save_settings( def validate_settings( settings: dict, model_serve_preview: Text, + train_version: str = "v2", ) -> bool: - if settings.get("agent_id", None) is None: - set_model_serve_preview("Please select agent", model_serve_preview, "warning") - return False - if settings.get("device", None) is None: - set_model_serve_preview("Please select device", model_serve_preview, "warning") - return False - if ( - settings.get("model_source", None) is None - or settings.get("checkpoint_name", None) is None - or settings.get("task_type", None) is None - ): - set_model_serve_preview("Please select model", model_serve_preview, "warning") - return False + if train_version == "v1": + if settings.get("agent_id", None) is None: + set_model_serve_preview("Please select agent", model_serve_preview, "warning") + return False + if settings.get("device", None) is None: + set_model_serve_preview("Please select device", model_serve_preview, "warning") + return False + if ( + settings.get("model_source", None) is None + or settings.get("checkpoint_name", None) is None + or settings.get("task_type", None) is None + ): + set_model_serve_preview("Please select model", model_serve_preview, "warning") + return False + elif train_version == "v2": + model_params = settings.get("model_params", None) + if model_params is None: + set_model_serve_preview("Please select model", model_serve_preview, "warning") + return False return True @@ -188,21 +227,27 @@ def start_app( return session_info -def deploy_model(api: Api, session_id: int, saved_settings: dict): +def deploy_model(api: Api, session_id: int, saved_settings: dict, train_version: str = "v1"): deploy_params = {} # common - deploy_params["device"] = saved_settings["device"] - deploy_params["model_source"] = saved_settings["model_source"] - deploy_params["checkpoint_name"] = saved_settings["checkpoint_name"] - deploy_params["checkpoint_url"] = saved_settings["checkpoint_url"] - deploy_params["task_type"] = saved_settings["task_type"] - # specific - config_url = saved_settings.get("config_url", None) - if config_url is not None: - deploy_params["config_url"] = config_url - arch_type = saved_settings.get("arch_type", None) - if arch_type is not None: - deploy_params["arch_type"] = arch_type + if train_version == "v1": + deploy_params["device"] = saved_settings["device"] + deploy_params["model_source"] = saved_settings["model_source"] + deploy_params["checkpoint_name"] = saved_settings["checkpoint_name"] + deploy_params["checkpoint_url"] = saved_settings["checkpoint_url"] + deploy_params["task_type"] = saved_settings["task_type"] + # specific + config_url = saved_settings.get("config_url", None) + if config_url is not None: + deploy_params["config_url"] = config_url + arch_type = saved_settings.get("arch_type", None) + if arch_type is not None: + deploy_params["arch_type"] = arch_type + + elif train_version == "v2": + deploy_params = saved_settings["model_params"] + deploy_params["device"] = saved_settings["device"] + runtime = saved_settings.get("runtime", None) if runtime is not None: deploy_params["runtime"] = runtime @@ -211,10 +256,8 @@ def deploy_model(api: Api, session_id: int, saved_settings: dict): # Check model - - def check_model_avaliability_by_task_type( - model_selector_sidebar_custom_model_table: CustomModelsSelector, + model_selector_sidebar_custom_model_table: ExperimentSelector, model_selector_sidebar_save_btn: Button, ): if len(model_selector_sidebar_custom_model_table.rows) == 0: @@ -226,12 +269,12 @@ def check_model_avaliability_by_task_type( def check_model_avaliability_by_model_source( model_source: str, model_selector_sidebar_custom_model_option_selector: Select, - model_selector_sidebar_custom_model_table_segmentation: CustomModelsSelector, - model_selector_sidebar_custom_model_table_detection: CustomModelsSelector, - model_selector_sidebar_custom_model_table_pose_estimation: CustomModelsSelector, + model_selector_sidebar_custom_model_table_segmentation: ExperimentSelector, + model_selector_sidebar_custom_model_table_detection: ExperimentSelector, + model_selector_sidebar_custom_model_table_pose_estimation: ExperimentSelector, model_selector_sidebar_save_btn: Button, ): - if model_source == "Custom models": + if model_source == ModelSource.CUSTOM: if model_selector_sidebar_custom_model_option_selector.get_value() == "table": if ( len(model_selector_sidebar_custom_model_table_detection.rows) == 0 diff --git a/src/ui/dtl/actions/neural_networks/deploy/rtdetrv2.md b/src/ui/dtl/actions/neural_networks/deploy/rtdetrv2.md new file mode 100644 index 00000000..d7629683 --- /dev/null +++ b/src/ui/dtl/actions/neural_networks/deploy/rtdetrv2.md @@ -0,0 +1,48 @@ +# Deploy RT-DETRv2 + +`Deploy RT-DETRv2` using [Serve RT-DETRv2](https://ecosystem.supervisely.com/apps/rt-detrv2/supervisely_integration/serve) app to serve models and can be used to deploy custom and pretrained models that you can use via `Apply NN` layer. Custom models will appear in the custom tab of the table only if you have any trained RT-DETRv2 models in your Team Files. You can train your own model using [Train RT-DETRv2](https://ecosystem.supervisely.com/apps/rt-detrv2/supervisely_integration/train) app. If you want to use pretrained models, simply select "Pretrained public models" tab in model selector. + +### Settings: + +### How to use: + +1. Add `Deploy RT-DETRv2` layer +2. Open agent settings and select agent and device +3. Open models selector and select one of the available models +4. Press `SERVE` +5. Wait until model is deployed, you will see "Model deployed" message in the bottom of the layer card +6. Connect this layer to `Apply NN Inference` layer's `Deployed model (optional)` socket +7. If you want to deploy another model, press `STOP` and repeat steps 3, 4, 5 and 6 + +### Settings: + +- **Select agent** - select agent and device that will be used for deployment: + - `Agent` - select agent + - `Device` - select CPU or GPU (faster) device if available +- **Select model** - select custom or pretrained model + - `Model type` - custom or pretrained + - `Checkpoint` - select checkpoint +- **Auto stop model session** - automatically stop model session when pipeline is finished + +### JSON view + +
+ JSON view +
+{
+  "action": "deploy_rtdetrv2",
+  "src": [],
+  "dst": "$deploy_rtdetrv2_1",
+  "settings": {
+    "agent_id": 348,
+    "device": "cuda:0",
+    "model_type": "Pretrained models",
+    "model_name": "RT-DETRv2-S",
+    "task_type": "object detection",
+    "model_path": null,
+    "stop_model_session": true,
+    "session_id": 74355
+  }
+}
+
+