Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mmdeploy export #2806

Merged
merged 209 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 204 commits
Commits
Show all changes
209 commits
Select commit Hold shift + click to select a range
d27792e
Add export entry point
sovrasov Jan 11, 2024
83748a6
Update onnx export
sovrasov Jan 11, 2024
e62683b
Merge remote-tracking branch 'origin/v2' into vs/v2_export
sovrasov Jan 12, 2024
b895c85
Fix missing export config
sovrasov Jan 12, 2024
f8d887c
Add base metadata
sovrasov Jan 12, 2024
89cca24
Add classification metadata
sovrasov Jan 12, 2024
d29b166
Merge remote-tracking branch 'origin/v2' into vs/v2_export
sovrasov Jan 12, 2024
4f3448a
Add configs for export and custom SegNext head (#2787)
kprokofi Jan 12, 2024
7de7860
Add OV export via ONNX
sovrasov Jan 12, 2024
4db7259
Fix linters
sovrasov Jan 13, 2024
c2e0f2e
Update openvino
sovrasov Jan 13, 2024
a482385
Fix unit tests
sovrasov Jan 13, 2024
656b4ef
Skip CLI unit for old python
sovrasov Jan 13, 2024
85ffa62
Fix linters
sovrasov Jan 13, 2024
0abdf10
add raising an error when metric is None
kprokofi Jan 14, 2024
d22b35e
Merge remote-tracking branch 'origin/v2' into vs/v2_export
sovrasov Jan 15, 2024
1c23f1b
Fix dinov2 configs
sovrasov Jan 16, 2024
aef8961
Add export tests
sovrasov Jan 16, 2024
c893f7e
Add smoke tests for export
sovrasov Jan 16, 2024
69be97d
Add smoke tests for ov infer
sovrasov Jan 16, 2024
ca9fcab
Update export cli tests
sovrasov Jan 16, 2024
c6cb990
Refactored ONNX export, updated configs for segmentation (#2797)
kprokofi Jan 16, 2024
b8e9f31
Update exceptions for tests
sovrasov Jan 16, 2024
6202ab1
Fix multilabel configs
sovrasov Jan 16, 2024
1735a1b
Merge remote-tracking branch 'origin/v2' into vs/v2_export
sovrasov Jan 16, 2024
a7033a3
Remove old export function
sovrasov Jan 16, 2024
e707bdb
Restore classification export
sovrasov Jan 17, 2024
c02ae3f
Restore multiclass export
sovrasov Jan 17, 2024
9083a01
Restore export of multilabel classificaiton
sovrasov Jan 17, 2024
2fe1b0a
Restore cli tests
sovrasov Jan 17, 2024
ae6851e
Add metadata for segmentation
sovrasov Jan 17, 2024
a1c2650
Add common export for segmentation
sovrasov Jan 17, 2024
0baddf3
Fix unit tests
sovrasov Jan 17, 2024
bff4cbc
Add multilabel OV inference
sovrasov Jan 17, 2024
2d25a9d
draft commit
eunwoosh Jan 17, 2024
3eafc4f
support mmdeploy export to detection model
eunwoosh Jan 17, 2024
57ed9bd
support mmdeploy export to instnace segmentation model
eunwoosh Jan 17, 2024
3942b3e
add comment
eunwoosh Jan 17, 2024
7527c8b
make code clean a little bit
eunwoosh Jan 17, 2024
b64d74b
remove debugging code
eunwoosh Jan 17, 2024
cfd9c18
Merge branch 'vs/v2_export' into new_export_mmdeploy
eunwoosh Jan 17, 2024
74092f8
move _get_export_parameters to each model class
eunwoosh Jan 17, 2024
f4057c1
Merge remote-tracking branch 'origin/v2' into vs/v2_export
sovrasov Jan 17, 2024
8844265
Fix snapshot loading in engine
sovrasov Jan 17, 2024
8c00156
Set RGB for OV models
sovrasov Jan 17, 2024
1e7eb88
Added segmentation configuration for export to align new interface (#…
kprokofi Jan 17, 2024
8756968
Merge branch 'v2' of https://github.com/openvinotoolkit/training_exte…
kprokofi Jan 17, 2024
575acf7
added Hlabel class
kprokofi Jan 17, 2024
e93e293
small refactoring
kprokofi Jan 17, 2024
e5c5357
added multilabel
kprokofi Jan 17, 2024
e9ba2bb
Extract exporter to a class
sovrasov Jan 18, 2024
488474a
Minor fixes
sovrasov Jan 18, 2024
32aa59f
Fix linters in exporters
sovrasov Jan 18, 2024
95ee219
Update cli test description
sovrasov Jan 18, 2024
ae33067
pass model weight to mmdeploy
eunwoosh Jan 18, 2024
e171e9d
Merge branch 'v2' of https://github.com/openvinotoolkit/training_exte…
kprokofi Jan 18, 2024
dbf51fe
bugfix
eunwoosh Jan 18, 2024
7277b7d
pre-commit fix
kprokofi Jan 18, 2024
0a860f4
added collate_unstacked_fn for classification
kprokofi Jan 18, 2024
a5496c1
fixed pre-commit tests
kprokofi Jan 18, 2024
e7b17e5
Merge branch 'vs/v2_export' of https://github.com/openvinotoolkit/tra…
sovrasov Jan 18, 2024
0e6c608
Fix missing attributes in cls models
sovrasov Jan 18, 2024
0a62d94
added multilabel inference (#2814)
kprokofi Jan 18, 2024
6f83d2a
Swith to installation of MAPI from master
sovrasov Jan 18, 2024
aad3f79
Add ov inference integration tests
sovrasov Jan 18, 2024
d35cd3e
Update export test output
sovrasov Jan 18, 2024
485e757
Add returning the test metrics
sovrasov Jan 18, 2024
f2abcf3
Fix a type
sovrasov Jan 18, 2024
a57402b
get export params when necessary in ins seg
eunwoosh Jan 19, 2024
f986bbf
add empty label for ins-set while preparing export
eunwoosh Jan 19, 2024
5d9a63d
Merge branch 'vs/v2_export' into new_export_mmdeploy
eunwoosh Jan 19, 2024
68f1fa0
Add a workaround for OVC single-output problem
sovrasov Jan 20, 2024
33c974e
Set MAPI version
sovrasov Jan 20, 2024
fb8bb16
Return checkpoint path from export
sovrasov Jan 20, 2024
6866f94
Fix mapi version
sovrasov Jan 20, 2024
6b8e57b
Merge remote-tracking branch 'origin/v2' into vs/v2_export
sovrasov Jan 20, 2024
4660248
Update inference test
sovrasov Jan 20, 2024
72e115b
change logic
kprokofi Jan 21, 2024
d3d33a6
Merge branch 'vs/v2_export' into new_export_mmdeploy
eunwoosh Jan 22, 2024
cb94555
draft implementation for new design
eunwoosh Jan 22, 2024
efef435
Update src/otx/core/model/entity/classification.py
kprokofi Jan 22, 2024
b255ea0
added doc string
kprokofi Jan 22, 2024
786672b
mmdeploy export w/ det and i-seg
eunwoosh Jan 22, 2024
ad97fbf
apply change to cls and seg
eunwoosh Jan 22, 2024
4e6e21e
Merge branch 'v2' of https://github.com/openvinotoolkit/training_exte…
kprokofi Jan 22, 2024
a9be344
Merge branch 'v2' into kp/cls-ir-infer
kprokofi Jan 22, 2024
dcb9dea
fill in missing part
eunwoosh Jan 22, 2024
4b731b1
Merge remote-tracking branch 'origin/v2' into vs/v2_export
sovrasov Jan 22, 2024
5a38f27
Skip visual_prompting export tests
sovrasov Jan 22, 2024
edb6ffa
add docstring
eunwoosh Jan 23, 2024
5fb9fe2
Merge branch 'vs/v2_export' into new_export_mmdeploy
eunwoosh Jan 23, 2024
f34bf79
make mmdeploy use mmdet pipline module
eunwoosh Jan 23, 2024
ead9995
add docstring and remove unused code
eunwoosh Jan 23, 2024
b7bcbb3
add missing docstring
eunwoosh Jan 23, 2024
f0dd286
refactor mmdeploy files
eunwoosh Jan 23, 2024
d8253f1
onnx_config -> ir_config
eunwoosh Jan 23, 2024
f171feb
remove onnx file after OV export is done
eunwoosh Jan 23, 2024
d15b5ec
align with pre-commit
eunwoosh Jan 23, 2024
e4c2f2a
align with pre-commit
eunwoosh Jan 23, 2024
e59e079
test det models in export integration test
eunwoosh Jan 23, 2024
1f8b0c8
fix typo
eunwoosh Jan 23, 2024
bbc9403
Update src/otx/core/data/dataset/base.py
kprokofi Jan 23, 2024
c0abe24
Merge branch 'v2' of https://github.com/openvinotoolkit/training_exte…
kprokofi Jan 23, 2024
b068558
merge v2. Devide OVModel
kprokofi Jan 23, 2024
6cd5657
fix pre-commit
kprokofi Jan 23, 2024
e5144e6
modified configs
kprokofi Jan 23, 2024
f10e340
fix integration tests
kprokofi Jan 23, 2024
a3b5cef
fix unit test
kprokofi Jan 23, 2024
eae0cb9
Merge remote-tracking branch 'origin/v2' into vs/v2_export
sovrasov Jan 23, 2024
a39a7a9
fix integration for dinov2
kprokofi Jan 23, 2024
4221cb8
Remove obsolette entry points
sovrasov Jan 23, 2024
39c2f19
Adapt engine export to new CLI
sovrasov Jan 23, 2024
a873669
Fix missing label names in model
sovrasov Jan 24, 2024
973fc11
Fix cli tests
sovrasov Jan 24, 2024
a5461de
Disable labels updating in export
sovrasov Jan 24, 2024
6965555
Disable failing cli tests
sovrasov Jan 24, 2024
7483763
Update docstrings in engine
sovrasov Jan 24, 2024
c22601d
revert mm registry default scope after mmdeploy is executed
eunwoosh Jan 24, 2024
7706c02
revert export intg test
eunwoosh Jan 24, 2024
b4fc8ba
Del obsolete configs
sovrasov Jan 24, 2024
24a7d17
support export for atss_r50_fpn and rtmdet_tiny
eunwoosh Jan 24, 2024
37e8023
merge related model calss into the single file
eunwoosh Jan 24, 2024
2c8e310
return inheritance from OTXModel back
kprokofi Jan 24, 2024
1868961
Merge branch 'v2' of https://github.com/openvinotoolkit/training_exte…
kprokofi Jan 24, 2024
4fec2b6
Merge branch 'v2' into kp/cls-ir-infer
kprokofi Jan 24, 2024
debf843
return CLI changes back
kprokofi Jan 24, 2024
935934a
Fix SegNext head (#2835)
kprokofi Jan 24, 2024
bee71c2
Merge remote-tracking branch 'origin/kp/cls-ir-infer' into vs/v2_export
sovrasov Jan 24, 2024
334bdb1
Update cli tests
sovrasov Jan 24, 2024
7b3d48c
Fix dataset type in cls ov configs
sovrasov Jan 24, 2024
8ac4d55
Update export configuration for hrnet
sovrasov Jan 24, 2024
cc222ec
Update device in cli ov inferance
sovrasov Jan 24, 2024
fca44f9
Fix multilabel inferece
sovrasov Jan 24, 2024
0c2d402
Restore accuracy smoke tests
sovrasov Jan 25, 2024
68e7582
Fix docs
sovrasov Jan 25, 2024
29df2ab
Disable tests for dino v2
sovrasov Jan 25, 2024
ee3017e
Updatee the name of the inference test case
sovrasov Jan 25, 2024
b82541d
Fix ssewg task name
sovrasov Jan 25, 2024
9b384ab
Fix pre-commit
sovrasov Jan 25, 2024
96e29d2
Deterministic train in sccuracy tests
sovrasov Jan 25, 2024
d733d21
Merge branch 'vs/v2_export' into new_export_mmdeploy
eunwoosh Jan 25, 2024
8366de5
MMdeployExporter argument test_pipeline is native python obj
eunwoosh Jan 25, 2024
045bb41
align with pre-commit
eunwoosh Jan 25, 2024
2107e63
fix minor bug
eunwoosh Jan 25, 2024
9673816
align export_param implementation
eunwoosh Jan 25, 2024
c21528c
Merge remote-tracking branch 'origin/v2' into vs/v2_export
sovrasov Jan 25, 2024
a51e5fb
Merge remote-tracking branch 'origin/v2' into vs/v2_export
sovrasov Jan 25, 2024
3c55097
Update deterministic mode in tests
sovrasov Jan 25, 2024
991da64
Fix mapi configuration update in multilabel cls
sovrasov Jan 25, 2024
74541f3
Fix linters
sovrasov Jan 25, 2024
74be80b
Load label infor from checkpoint
sovrasov Jan 25, 2024
213e8e4
Merge remote-tracking branch 'origin/v2' into vs/v2_export
sovrasov Jan 26, 2024
72a542e
Fix minor comments
sovrasov Jan 26, 2024
e0e9aa7
Fix mode comments
sovrasov Jan 26, 2024
ac6ea47
Update comment regarding missing label names
sovrasov Jan 26, 2024
2822d24
Add cli usage to docs
sovrasov Jan 26, 2024
e9a35b3
Extract precision to a standalone file
sovrasov Jan 26, 2024
ac268e0
Add model base name to model.export params
sovrasov Jan 26, 2024
a0040de
fix segnext head
kprokofi Jan 24, 2024
1d1afc5
fix pre-commit
kprokofi Jan 24, 2024
80ee9d0
Merge remote-tracking branch 'origin/v2' into vs/v2_export
sovrasov Jan 29, 2024
ae9454f
Fix linters
sovrasov Jan 29, 2024
d2e56ad
Refactor configuration
sovrasov Jan 30, 2024
7a1e53c
Fix linters
sovrasov Jan 30, 2024
3ba6dfd
Merge remote-tracking branch 'origin/v2' into vs/v2_export
sovrasov Jan 30, 2024
dbabeaa
Fix pre-commit
sovrasov Jan 30, 2024
27313e0
Update inference tests
sovrasov Jan 30, 2024
0b39910
Merge remote-tracking branch 'origin/v2' into vs/v2_export
sovrasov Jan 30, 2024
355637d
Extract common fixture in CLI tests
sovrasov Jan 30, 2024
de22bee
Fix missing mean/scale metadata in native exporter
sovrasov Jan 30, 2024
eaa5b4d
Workaround OV failure on ONNX models with metadata
sovrasov Jan 30, 2024
d687214
Simplify checkpoint loading
sovrasov Jan 30, 2024
f86720a
Cleanup
sovrasov Jan 31, 2024
4fd4e3d
Fix cli tests
sovrasov Jan 31, 2024
d29f84e
Fix litehrnet export config
sovrasov Jan 31, 2024
8f62905
Fix import of custom ham seg head
sovrasov Jan 31, 2024
c12075e
Del unused import
sovrasov Jan 31, 2024
451c9ca
Revert "added CUBLAS_WORKSPACE_CONFIG for testing deterministic option"
yunchu Jan 31, 2024
929fb28
Fix typos in docs
sovrasov Jan 31, 2024
4c41650
added CUBLAS_WORKSPACE_CONFIG for testing deterministic option
yunchu Jan 31, 2024
243ba28
Merge branch 'vs/v2_export' into new_export_mmdeploy
eunwoosh Jan 31, 2024
c2f93dc
add CUBLAS_WORKSPACE_CONFIG=:4096:8 for integration test
yunchu Jan 31, 2024
a83c638
align with new export deisgn
eunwoosh Jan 31, 2024
d51f30c
Merge branch 'v2' into vs/v2_export
eunwoosh Jan 31, 2024
62c1ade
refactor code
eunwoosh Jan 31, 2024
ef8e4f3
Merge branch 'vs/v2_export' into new_export_mmdeploy
eunwoosh Jan 31, 2024
f5e4926
fix minor bugs
eunwoosh Jan 31, 2024
47ca58c
fix typo
eunwoosh Jan 31, 2024
e7ffe12
Merge branch 'v2' into new_export_mmdeploy
eunwoosh Jan 31, 2024
de5ffa5
align with pre-commit
eunwoosh Jan 31, 2024
a1ab122
align with torch model test pipeline
eunwoosh Feb 1, 2024
230e727
give more epoch to some models during intg test
eunwoosh Feb 1, 2024
a6fa496
remove commented code
eunwoosh Feb 1, 2024
9b11802
add ins-seg into export intg test
eunwoosh Feb 1, 2024
570733c
set 10eph to atss_resnext101 in intg test
eunwoosh Feb 1, 2024
5ff9c11
exclude i-seg models from comparing scores in intg test
eunwoosh Feb 1, 2024
a5ec24d
move mmdeploy config files
eunwoosh Feb 2, 2024
0175f0c
make test_pipeline in _export_parameters
eunwoosh Feb 2, 2024
4686944
align with pre-commit
eunwoosh Feb 2, 2024
a3a7ec5
Merge branch 'v2' into new_export_mmdeploy
eunwoosh Feb 2, 2024
0ceebdb
revert left thing
eunwoosh Feb 2, 2024
fb759fd
Merge branch 'v2' into new_export_mmdeploy
eunwoosh Feb 2, 2024
49b6fd9
change fit_to_window to resize
eunwoosh Feb 2, 2024
d843660
exclude unstable model
eunwoosh Feb 2, 2024
62886f6
Merge branch 'v2' into new_export_mmdeploy
eunwoosh Feb 5, 2024
d6d27fd
revert integration test
eunwoosh Feb 5, 2024
cf27e94
add integration test
eunwoosh Feb 5, 2024
241980a
update docstring
eunwoosh Feb 6, 2024
7a6ac90
add reference in mmdeploy config
eunwoosh Feb 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ mmlab = [
"mmpretrain==1.1.1",
"mmsegmentation==1.2.1",
"mmaction2==1.2.0",
"mmdeploy==1.3.*",
# Without the pip cache, oss2 will sometimes install to a lower version. This is related to the installation of the mmlab library.
# This causes an error when training the mm model, so fix the version first.
"oss2==2.17.0",
]

Expand Down Expand Up @@ -249,6 +249,7 @@ exclude = [
"node_modules",
"venv",
"tests/assets",
"src/otx/algo/**/mmdeploy/",
eunwoosh marked this conversation as resolved.
Show resolved Hide resolved

# it will be cleaned up later
"src/otx/algo/classification/backbones/*",
Expand Down
37 changes: 36 additions & 1 deletion src/otx/algo/detection/atss.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
#
"""ATSS model implementations."""

from typing import Literal
from __future__ import annotations

from typing import Any, Literal

from otx.algo.utils.mmconfig import read_mmconfig
from otx.algo.utils.support_otx_v1 import OTXv1Helper
Expand All @@ -17,7 +19,40 @@ def __init__(self, num_classes: int, variant: Literal["mobilenetv2", "r50_fpn",
model_name = f"atss_{variant}"
config = read_mmconfig(model_name=model_name)
super().__init__(num_classes=num_classes, config=config)
self.image_size = (1, 3, 736, 992)

@property
def _export_parameters(self) -> dict[str, Any]:
"""Parameters for an exporter."""
export_params = super()._export_parameters
export_params["deploy_cfg"] = "otx.algo.detection.mmdeploy.atss"
export_params["input_size"] = self.image_size
export_params["resize_mode"] = "standard"
export_params["pad_value"] = 0
export_params["swap_rgb"] = False

return export_params

def load_from_otx_v1_ckpt(self, state_dict: dict, add_prefix: str = "model.model.") -> dict:
"""Load the previous OTX ckpt according to OTX2.0."""
return OTXv1Helper.load_det_ckpt(state_dict, add_prefix)


class ATSSR50FPN(ATSS):
"""ATSSR50FPN Model."""

def __init__(self, num_classes: int) -> None:
super().__init__(num_classes=num_classes, variant="r50_fpn")
self.image_size = (1, 3, 800, 1333)

@property
def _export_parameters(self) -> dict[str, Any]:
"""Parameters for an exporter."""
export_params = super()._export_parameters
export_params["deploy_cfg"] = "otx.algo.detection.mmdeploy.atss_r50_fpn"
export_params["input_size"] = self.image_size
export_params["resize_mode"] = "standard" # [TODO](@Eunwoo): need to revert it to fit_to_window after resolving
export_params["pad_value"] = 0
export_params["swap_rgb"] = False

return export_params
4 changes: 4 additions & 0 deletions src/otx/algo/detection/mmdeploy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
#
"""MMDeploy config for detection models."""
11 changes: 11 additions & 0 deletions src/otx/algo/detection/mmdeploy/atss.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""MMDeploy config of ATSS model for Detection Task."""
sungmanc marked this conversation as resolved.
Show resolved Hide resolved

_base_ = ["./base_detection.py"]

ir_config = dict(
output_names=["boxes", "labels"],
)

backend_config = dict(
model_inputs=[dict(opt_shapes=dict(input=[-1, 3, 736, 992]))],
)
11 changes: 11 additions & 0 deletions src/otx/algo/detection/mmdeploy/atss_r50_fpn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""MMDeploy config of ATSS model for Detection Task."""

_base_ = ["./base_detection.py"]

ir_config = dict(
output_names=["boxes", "labels"],
)

backend_config = dict(
model_inputs=[dict(opt_shapes=dict(input=[-1, 3, 800, 1333]))],
)
51 changes: 51 additions & 0 deletions src/otx/algo/detection/mmdeploy/base_detection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""Detection models base deploy config."""

ir_config = dict(
type="onnx",
export_params=True,
keep_initializers_as_inputs=False,
opset_version=11,
save_file="end2end.onnx",
input_names=["image"],
output_names=["boxes", "labels"],
input_shape=None,
# TODO
# optimizing onnx graph mess up NNCF graph at some point
# where we need to look into
optimize=False,
dynamic_axes={
"image": {
0: "batch",
2: "height",
3: "width",
},
"boxes": {
0: "batch",
1: "num_dets",
},
"labels": {
0: "batch",
1: "num_dets",
},
},
)

codebase_config = dict(
type="mmdet",
task="ObjectDetection",
model_type="end2end",
post_processing=dict(
score_threshold=0.05,
confidence_threshold=0.005, # for YOLOv3
iou_threshold=0.5,
max_output_boxes_per_class=200,
pre_top_k=5000,
keep_top_k=100,
background_label_id=-1,
),
)

backend_config = dict(
type="openvino",
mo_options=None,
)
11 changes: 11 additions & 0 deletions src/otx/algo/detection/mmdeploy/rtmdet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""MMDeploy config of RTMdet model for Detection Task."""

_base_ = ["./base_detection.py"]

ir_config = dict(
output_names=["boxes", "labels"],
)

backend_config = dict(
model_inputs=[dict(opt_shapes=dict(input=[-1, 3, 640, 640]))],
)
11 changes: 11 additions & 0 deletions src/otx/algo/detection/mmdeploy/ssd_mobilenetv2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""MMDeploy config of SSD model for Detection Task."""

_base_ = ["./base_detection.py"]

ir_config = dict(
output_names=["boxes", "labels"],
)

backend_config = dict(
model_inputs=[dict(opt_shapes=dict(input=[-1, 3, 864, 864]))],
)
11 changes: 11 additions & 0 deletions src/otx/algo/detection/mmdeploy/yolox.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""MMDeploy config of YOLOX models except YOLOX_tiny for Detection Task."""

_base_ = ["./base_detection.py"]

ir_config = dict(
output_names=["boxes", "labels"],
)

backend_config = dict(
model_inputs=[dict(opt_shapes=dict(input=[-1, 3, 640, 640]))],
)
11 changes: 11 additions & 0 deletions src/otx/algo/detection/mmdeploy/yolox_tiny.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""MMDeploy config of YOLOX Tiny model for Detection Task."""

_base_ = ["./base_detection.py"]

ir_config = dict(
output_names=["boxes", "labels"],
)

backend_config = dict(
model_inputs=[dict(opt_shapes=dict(input=[-1, 3, 416, 416]))],
)
17 changes: 16 additions & 1 deletion src/otx/algo/detection/rtmdet.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
#
"""RTMDetTiny model implementations."""

from typing import Literal
from __future__ import annotations

from typing import Any, Literal

from otx.algo.utils.mmconfig import read_mmconfig
from otx.algo.utils.support_otx_v1 import OTXv1Helper
Expand All @@ -17,6 +19,19 @@ def __init__(self, num_classes: int, variant: Literal["tiny"]) -> None:
model_name = f"rtmdet_{variant}"
config = read_mmconfig(model_name=model_name)
super().__init__(num_classes=num_classes, config=config)
self.image_size = (1, 3, 640, 640)

@property
def _export_parameters(self) -> dict[str, Any]:
"""Parameters for an exporter."""
export_params = super()._export_parameters
export_params["deploy_cfg"] = "otx.algo.detection.mmdeploy.rtmdet"
export_params["input_size"] = self.image_size
export_params["resize_mode"] = "fit_to_window_letterbox"
export_params["pad_value"] = 114
export_params["swap_rgb"] = False

return export_params

def load_from_otx_v1_ckpt(self, state_dict: dict, add_prefix: str = "model.model.") -> dict:
"""Load the previous OTX ckpt according to OTX2.0."""
Expand Down
15 changes: 14 additions & 1 deletion src/otx/algo/detection/ssd.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from __future__ import annotations

from copy import deepcopy
from typing import TYPE_CHECKING, Literal
from typing import TYPE_CHECKING, Any, Literal

from otx.algo.utils.mmconfig import read_mmconfig
from otx.algo.utils.support_otx_v1 import OTXv1Helper
Expand All @@ -27,6 +27,7 @@ def __init__(self, num_classes: int, variant: Literal["mobilenetv2"]) -> None:
model_name = f"ssd_{variant}"
config = read_mmconfig(model_name=model_name)
super().__init__(num_classes=num_classes, config=config)
self.image_size = (1, 3, 864, 864)

def _create_model(self) -> nn.Module:
from mmdet.models.data_preprocessors import (
Expand Down Expand Up @@ -125,6 +126,18 @@ def load_state_dict_pre_hook(self, state_dict: dict[str, torch.Tensor], prefix:
# Replace checkpoint weight by mixed weights
state_dict[prefix + param_name] = model_param

@property
def _export_parameters(self) -> dict[str, Any]:
"""Parameters for an exporter."""
export_params = super()._export_parameters
export_params["deploy_cfg"] = "otx.algo.detection.mmdeploy.ssd_mobilenetv2"
export_params["input_size"] = self.image_size
export_params["resize_mode"] = "standard"
export_params["pad_value"] = 0
export_params["swap_rgb"] = False

return export_params

def load_from_otx_v1_ckpt(self, state_dict: dict, add_prefix: str = "model.model.") -> dict:
"""Load the previous OTX ckpt according to OTX2.0."""
return OTXv1Helper.load_det_ckpt(state_dict, add_prefix)
39 changes: 37 additions & 2 deletions src/otx/algo/detection/yolox.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Copyright (C) 2023 Intel Corporation
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
#
"""YOLOX model implementations."""

from typing import Literal
from __future__ import annotations

from typing import Any, Literal

from otx.algo.utils.mmconfig import read_mmconfig
from otx.algo.utils.support_otx_v1 import OTXv1Helper
Expand All @@ -17,7 +19,40 @@ def __init__(self, num_classes: int, variant: Literal["l", "s", "tiny", "x"]) ->
model_name = f"yolox_{variant}"
config = read_mmconfig(model_name=model_name)
super().__init__(num_classes=num_classes, config=config)
self.image_size = (1, 3, 640, 640)

@property
def _export_parameters(self) -> dict[str, Any]:
"""Parameters for an exporter."""
export_params = super()._export_parameters
export_params["resize_mode"] = "fit_to_window_letterbox"
export_params["pad_value"] = 114
export_params["swap_rgb"] = True
export_params["input_size"] = self.image_size
export_params["deploy_cfg"] = "otx.algo.detection.mmdeploy.yolox"

return export_params

def load_from_otx_v1_ckpt(self, state_dict: dict, add_prefix: str = "model.model.") -> dict:
"""Load the previous OTX ckpt according to OTX2.0."""
return OTXv1Helper.load_det_ckpt(state_dict, add_prefix)


class YoloXTiny(YoloX):
"""YoloX tiny Model."""

def __init__(self, num_classes: int) -> None:
super().__init__(num_classes=num_classes, variant="tiny")
self.image_size = (1, 3, 416, 416)

@property
def _export_parameters(self) -> dict[str, Any]:
"""Parameters for an exporter."""
export_params = super()._export_parameters
export_params["resize_mode"] = "fit_to_window_letterbox"
export_params["pad_value"] = 114
export_params["swap_rgb"] = False
export_params["input_size"] = self.image_size
export_params["deploy_cfg"] = "otx.algo.detection.mmdeploy.yolox_tiny"

return export_params
41 changes: 38 additions & 3 deletions src/otx/algo/instance_segmentation/maskrcnn.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Copyright (C) 2023 Intel Corporation
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
#
"""ATSS model implementations."""
"""MaskRCNN model implementations."""

from typing import Literal
from __future__ import annotations

from typing import Any, Literal

from otx.algo.utils.mmconfig import read_mmconfig
from otx.algo.utils.support_otx_v1 import OTXv1Helper
Expand All @@ -17,7 +19,40 @@ def __init__(self, num_classes: int, variant: Literal["efficientnetb2b", "r50",
model_name = f"maskrcnn_{variant}"
config = read_mmconfig(model_name=model_name)
super().__init__(num_classes=num_classes, config=config)
self.image_size = (1, 3, 1024, 1024)

@property
def _export_parameters(self) -> dict[str, Any]:
"""Parameters for an exporter."""
export_params = super()._export_parameters
export_params["deploy_cfg"] = "otx.algo.instance_segmentation.mmdeploy.maskrcnn"
export_params["input_size"] = self.image_size
export_params["resize_mode"] = "standard" # [TODO](@Eunwoo): need to revert it to fit_to_window after resolving
export_params["pad_value"] = 0
export_params["swap_rgb"] = False

return export_params

def load_from_otx_v1_ckpt(self, state_dict: dict, add_prefix: str = "model.model.") -> dict:
"""Load the previous OTX ckpt according to OTX2.0."""
return OTXv1Helper.load_iseg_ckpt(state_dict, add_prefix)


class MaskRCNNSwinT(MaskRCNN):
"""MaskRCNNSwinT Model."""

def __init__(self, num_classes: int) -> None:
super().__init__(num_classes=num_classes, variant="swint")
self.image_size = (1, 3, 1344, 1344)

@property
def _export_parameters(self) -> dict[str, Any]:
"""Parameters for an exporter."""
export_params = super()._export_parameters
export_params["deploy_cfg"] = "otx.algo.instance_segmentation.mmdeploy.maskrcnn_swint"
export_params["input_size"] = self.image_size
export_params["resize_mode"] = "standard" # [TODO](@Eunwoo): need to revert it to fit_to_window after resolving
export_params["pad_value"] = 0
export_params["swap_rgb"] = False

return export_params
4 changes: 4 additions & 0 deletions src/otx/algo/instance_segmentation/mmdeploy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
#
"""MMDeploy config for instance segmentation models."""
Loading
Loading