Skip to content

Commit

Permalink
Deploy layer rework #97
Browse files Browse the repository at this point in the history
  • Loading branch information
cxnt authored Dec 20, 2024
2 parents debab45 + 50878d9 commit ba39c3b
Show file tree
Hide file tree
Showing 10 changed files with 358 additions and 106 deletions.
79 changes: 50 additions & 29 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. | + | - |
Expand Down
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
35 changes: 35 additions & 0 deletions src/compute/layers/processing/DeployLayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
},
},
},
}
9 changes: 6 additions & 3 deletions src/ui/dtl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
DeployYOLOV8Action,
DeployMMDetectionAction,
DeployMMSegmentationAction,
DeployRTETRAction,
DeployRTDETRAction,
DeployRTDETRv2Action,
)
from .actions.neural_networks.apply_nn_inference.apply_nn_inference import ApplyNNInferenceAction

Expand Down Expand Up @@ -224,7 +225,8 @@
DeployYOLOV8Action.name,
DeployMMDetectionAction.name,
DeployMMSegmentationAction.name,
DeployRTETRAction.name,
DeployRTDETRAction.name,
DeployRTDETRv2Action.name,
ApplyNNInferenceAction.name,
],
OTHER: [
Expand Down Expand Up @@ -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,
Expand Down
55 changes: 43 additions & 12 deletions src/ui/dtl/actions/neural_networks/deploy/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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,
)

# -----------------------------
Expand Down Expand Up @@ -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()
Expand All @@ -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 = (
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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


Expand All @@ -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


Expand All @@ -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


Expand All @@ -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
22 changes: 7 additions & 15 deletions src/ui/dtl/actions/neural_networks/deploy/layout/model_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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,
Expand Down
Loading

0 comments on commit ba39c3b

Please sign in to comment.