diff --git a/docs/source/guide/reference/mpa/deploy.rst b/docs/source/guide/reference/mpa/deploy.rst deleted file mode 100644 index 7a4d154095a..00000000000 --- a/docs/source/guide/reference/mpa/deploy.rst +++ /dev/null @@ -1,34 +0,0 @@ -Deploy -^^^^^^^ - -.. toctree:: - :maxdepth: 3 - :caption: Contents: - -.. automodule:: otx.mpa.deploy - :members: - :undoc-members: - -.. automodule:: otx.mpa.deploy.apis - :members: - :undoc-members: - -.. automodule:: otx.mpa.deploy.utils - :members: - :undoc-members: - -.. automodule:: otx.mpa.deploy.utils.mmdeploy - :members: - :undoc-members: - -.. automodule:: otx.mpa.deploy.utils.onnx - :members: - :undoc-members: - -.. automodule:: otx.mpa.deploy.utils.operations_domain - :members: - :undoc-members: - -.. automodule:: otx.mpa.deploy.utils.utils - :members: - :undoc-members: \ No newline at end of file diff --git a/docs/source/guide/reference/mpa/index.rst b/docs/source/guide/reference/mpa/index.rst index d1e88cd2ae8..5a17c54b1e5 100644 --- a/docs/source/guide/reference/mpa/index.rst +++ b/docs/source/guide/reference/mpa/index.rst @@ -8,5 +8,4 @@ Model Preparation Algorithm classification detection segmentation - deploy utils diff --git a/otx/algorithms/common/adapters/mmdeploy/__init__.py b/otx/algorithms/common/adapters/mmdeploy/__init__.py new file mode 100644 index 00000000000..01687800428 --- /dev/null +++ b/otx/algorithms/common/adapters/mmdeploy/__init__.py @@ -0,0 +1,10 @@ +"""Adapters for mmdeploy.""" +# Copyright (C) 2023 Intel Corporation +# +# SPDX-License-Identifier: MIT + +from .utils.mmdeploy import is_mmdeploy_enabled + +__all__ = [ + "is_mmdeploy_enabled", +] diff --git a/otx/mpa/deploy/apis.py b/otx/algorithms/common/adapters/mmdeploy/apis.py similarity index 91% rename from otx/mpa/deploy/apis.py rename to otx/algorithms/common/adapters/mmdeploy/apis.py index 4e71e18d8bc..4ba61772449 100644 --- a/otx/mpa/deploy/apis.py +++ b/otx/algorithms/common/adapters/mmdeploy/apis.py @@ -1,3 +1,4 @@ +"""API of otx.algorithms.common.adapters.mmdeploy.""" # Copyright (C) 2022 Intel Corporation # SPDX-License-Identifier: Apache-2.0 # @@ -12,20 +13,23 @@ import mmcv import numpy as np -import onnx import torch from mmcv.parallel import collate, scatter -from .utils import numpy_2_list from .utils.mmdeploy import ( is_mmdeploy_enabled, mmdeploy_init_model_helper, update_deploy_cfg, ) from .utils.onnx import prepare_onnx_for_openvino +from .utils.utils import numpy_2_list + +# pylint: disable=too-many-locals class NaiveExporter: + """NaiveExporter for non-mmdeploy export.""" + @staticmethod def export2openvino( output_dir: str, @@ -38,13 +42,15 @@ def export2openvino( input_names: Optional[List[str]] = None, output_names: Optional[List[str]] = None, opset_version: int = 11, - dynamic_axes: Dict[Any, Any] = {}, + dynamic_axes: Optional[Dict[Any, Any]] = None, mo_transforms: str = "", ): + """Function for exporting to openvino.""" input_data = scatter(collate([input_data], samples_per_gpu=1), [-1])[0] model = model_builder(cfg) model = model.cpu().eval() + dynamic_axes = dynamic_axes if dynamic_axes else dict() onnx_path = NaiveExporter.torch2onnx( output_dir, @@ -108,10 +114,11 @@ def torch2onnx( input_names: Optional[List[str]] = None, output_names: Optional[List[str]] = None, opset_version: int = 11, - dynamic_axes: Dict[Any, Any] = {}, + dynamic_axes: Optional[Dict[Any, Any]] = None, verbose: bool = False, **onnx_options, ) -> str: + """Function for torch to onnx exporting.""" img_metas = input_data.get("img_metas") numpy_2_list(img_metas) @@ -119,6 +126,7 @@ def torch2onnx( model.forward = partial(model.forward, img_metas=img_metas, return_loss=False) onnx_file_name = model_name + ".onnx" + dynamic_axes = dynamic_axes if dynamic_axes else dict() torch.onnx.export( model, imgs, @@ -143,6 +151,7 @@ def onnx2openvino( model_name: str = "model", **openvino_options, ) -> Tuple[str, str]: + """Function for onnx to openvino exporting.""" from otx.mpa.utils import mo_wrapper mo_args = { @@ -163,17 +172,15 @@ def onnx2openvino( if is_mmdeploy_enabled(): import mmdeploy.apis.openvino as openvino_api - from mmdeploy.apis import ( - build_task_processor, - extract_model, - get_predefined_partition_cfg, - torch2onnx, - ) + from mmdeploy.apis import build_task_processor, extract_model, torch2onnx from mmdeploy.apis.openvino import get_input_info_from_cfg, get_mo_options_from_cfg - from mmdeploy.core import FUNCTION_REWRITER - from mmdeploy.utils import get_backend_config, get_ir_config, get_partition_config + + # from mmdeploy.core import FUNCTION_REWRITER + from mmdeploy.utils import get_ir_config, get_partition_config class MMdeployExporter: + """MMdeployExporter for mmdeploy exporting.""" + @staticmethod def export2openvino( output_dir: str, @@ -183,6 +190,7 @@ def export2openvino( *, model_name: str = "model", ): + """Function for exporting to openvino.""" task_processor = build_task_processor(cfg, deploy_cfg, "cpu") @@ -248,6 +256,7 @@ def torch2onnx( *, model_name: str = "model", ) -> str: + """Function for torch to onnx exporting.""" onnx_file_name = model_name + ".onnx" torch2onnx( input_data, @@ -266,6 +275,7 @@ def partition_onnx( onnx_path: str, partition_cfgs: Union[mmcv.ConfigDict, List[mmcv.ConfigDict]], ) -> Tuple[str, ...]: + """Function for parition onnx.""" partitioned_paths = [] if not isinstance(partition_cfgs, list): @@ -290,6 +300,7 @@ def onnx2openvino( *, model_name: Optional[str] = None, ) -> Tuple[str, str]: + """Function for onnx to openvino exporting.""" input_info = get_input_info_from_cfg(deploy_cfg) output_names = get_ir_config(deploy_cfg).output_names diff --git a/otx/mpa/deploy/utils/__init__.py b/otx/algorithms/common/adapters/mmdeploy/utils/__init__.py similarity index 80% rename from otx/mpa/deploy/utils/__init__.py rename to otx/algorithms/common/adapters/mmdeploy/utils/__init__.py index d4800169f5e..5c1f7760edd 100644 --- a/otx/mpa/deploy/utils/__init__.py +++ b/otx/algorithms/common/adapters/mmdeploy/utils/__init__.py @@ -1,3 +1,4 @@ +"""Init file for otx.algorithms.common.adapters.mmdeploy.utils.""" # Copyright (C) 2022 Intel Corporation # SPDX-License-Identifier: Apache-2.0 # diff --git a/otx/mpa/deploy/utils/mmdeploy.py b/otx/algorithms/common/adapters/mmdeploy/utils/mmdeploy.py similarity index 71% rename from otx/mpa/deploy/utils/mmdeploy.py rename to otx/algorithms/common/adapters/mmdeploy/utils/mmdeploy.py index eba7c531b2d..ee33bbd3705 100644 --- a/otx/mpa/deploy/utils/mmdeploy.py +++ b/otx/algorithms/common/adapters/mmdeploy/utils/mmdeploy.py @@ -1,3 +1,4 @@ +"""Functions for mmdeploy adapters.""" # Copyright (C) 2022 Intel Corporation # SPDX-License-Identifier: Apache-2.0 # @@ -5,14 +6,24 @@ import importlib import onnx -from mmcv.utils import ConfigDict def is_mmdeploy_enabled(): + """Checks if the 'mmdeploy' Python module is installed and available for use. + + Returns: + bool: True if 'mmdeploy' is installed, False otherwise. + + Example: + >>> is_mmdeploy_enabled() + True + """ return importlib.util.find_spec("mmdeploy") is not None def mmdeploy_init_model_helper(ctx, model_checkpoint=None, cfg_options=None, **kwargs): + """Helper function for initializing a model for inference using the 'mmdeploy' library.""" + model_builder = kwargs.pop("model_builder") model = model_builder( ctx.model_cfg, @@ -31,12 +42,14 @@ def mmdeploy_init_model_helper(ctx, model_checkpoint=None, cfg_options=None, **k return model -def update_deploy_cfg(onnx_path, deploy_cfg, mo_options={}): +def update_deploy_cfg(onnx_path, deploy_cfg, mo_options=None): + """Update the 'deploy_cfg' configuration file based on the ONNX model specified by 'onnx_path'.""" + from mmdeploy.utils import get_backend_config, get_ir_config onnx_model = onnx.load(onnx_path) ir_config = get_ir_config(deploy_cfg) - backend_config = get_backend_config(deploy_cfg) + get_backend_config(deploy_cfg) # update input input_names = [i.name for i in onnx_model.graph.input] @@ -47,6 +60,7 @@ def update_deploy_cfg(onnx_path, deploy_cfg, mo_options={}): ir_config["output_names"] = output_names # update mo options + mo_options = mo_options if mo_options else dict() deploy_cfg.merge_from_dict({"backend_config": {"mo_options": mo_options}}) diff --git a/otx/mpa/deploy/utils/onnx.py b/otx/algorithms/common/adapters/mmdeploy/utils/onnx.py similarity index 87% rename from otx/mpa/deploy/utils/onnx.py rename to otx/algorithms/common/adapters/mmdeploy/utils/onnx.py index 9ec80579904..b44812324e2 100644 --- a/otx/mpa/deploy/utils/onnx.py +++ b/otx/algorithms/common/adapters/mmdeploy/utils/onnx.py @@ -1,3 +1,4 @@ +"""Functions for onnx adapters.""" # Copyright (C) 2022 Intel Corporation # SPDX-License-Identifier: Apache-2.0 # @@ -6,6 +7,7 @@ def remove_nodes_by_op_type(onnx_model, op_type): + """Remove all nodes of a specified op type from the ONNX model.""" # TODO: support more nodes supported_op_types = ["Mark", "Conv", "Gemm"] @@ -42,6 +44,7 @@ def remove_nodes_by_op_type(onnx_model, op_type): def prepare_onnx_for_openvino(in_path, out_path): + """Modify the specified ONNX model to be compatible with OpenVINO by removing 'Mark' op nodes.""" onnx_model = onnx.load(in_path) onnx_model = remove_nodes_by_op_type(onnx_model, "Mark") onnx.checker.check_model(onnx_model) diff --git a/otx/mpa/deploy/utils/operations_domain.py b/otx/algorithms/common/adapters/mmdeploy/utils/operations_domain.py similarity index 73% rename from otx/mpa/deploy/utils/operations_domain.py rename to otx/algorithms/common/adapters/mmdeploy/utils/operations_domain.py index 11ffdcc48f8..e54af8bf1ab 100644 --- a/otx/mpa/deploy/utils/operations_domain.py +++ b/otx/algorithms/common/adapters/mmdeploy/utils/operations_domain.py @@ -1,3 +1,4 @@ +"""Add domain function.""" # Copyright (C) 2022 Intel Corporation # SPDX-License-Identifier: Apache-2.0 # @@ -6,4 +7,5 @@ def add_domain(name_operator: str) -> str: + """Function for adding to DOMAIN_CUSTOM_OPS_NAME.""" return DOMAIN_CUSTOM_OPS_NAME + "::" + name_operator diff --git a/otx/mpa/deploy/utils/utils.py b/otx/algorithms/common/adapters/mmdeploy/utils/utils.py similarity index 90% rename from otx/mpa/deploy/utils/utils.py rename to otx/algorithms/common/adapters/mmdeploy/utils/utils.py index 9c6148b7062..a0025bc8364 100644 --- a/otx/mpa/deploy/utils/utils.py +++ b/otx/algorithms/common/adapters/mmdeploy/utils/utils.py @@ -1,3 +1,4 @@ +"""Util functions of otx.algorithms.common.adapters.mmdeploy.""" # Copyright (C) 2022 Intel Corporation # SPDX-License-Identifier: Apache-2.0 # @@ -9,6 +10,7 @@ def sync_batchnorm_2_batchnorm(module, dim=2): + """Syncs the BatchNorm layers in a model to use regular BatchNorm layers.""" if dim == 1: bn = torch.nn.BatchNorm1d elif dim == 2: @@ -48,6 +50,7 @@ def sync_batchnorm_2_batchnorm(module, dim=2): def numpy_2_list(data): + """Converts NumPy arrays to Python lists.""" if isinstance(data, np.ndarray): return data.tolist() diff --git a/otx/algorithms/detection/adapters/mmdet/models/detectors/custom_atss_detector.py b/otx/algorithms/detection/adapters/mmdet/models/detectors/custom_atss_detector.py index c27feb43515..04eba1011f9 100644 --- a/otx/algorithms/detection/adapters/mmdet/models/detectors/custom_atss_detector.py +++ b/otx/algorithms/detection/adapters/mmdet/models/detectors/custom_atss_detector.py @@ -9,10 +9,10 @@ from mmdet.models.builder import DETECTORS from mmdet.models.detectors.atss import ATSS +from otx.algorithms.common.adapters.mmdeploy.utils import is_mmdeploy_enabled from otx.algorithms.detection.adapters.mmdet.hooks.det_saliency_map_hook import ( DetSaliencyMapHook, ) -from otx.mpa.deploy.utils import is_mmdeploy_enabled from otx.mpa.modules.hooks.recording_forward_hooks import FeatureVectorHook from otx.mpa.modules.utils.task_adapt import map_class_names from otx.mpa.utils.logger import get_logger diff --git a/otx/algorithms/detection/adapters/mmdet/models/detectors/custom_maskrcnn_detector.py b/otx/algorithms/detection/adapters/mmdet/models/detectors/custom_maskrcnn_detector.py index ed96bf83e51..56b8da87164 100644 --- a/otx/algorithms/detection/adapters/mmdet/models/detectors/custom_maskrcnn_detector.py +++ b/otx/algorithms/detection/adapters/mmdet/models/detectors/custom_maskrcnn_detector.py @@ -9,7 +9,7 @@ from mmdet.models.builder import DETECTORS from mmdet.models.detectors.mask_rcnn import MaskRCNN -from otx.mpa.deploy.utils import is_mmdeploy_enabled +from otx.algorithms.common.adapters.mmdeploy.utils import is_mmdeploy_enabled from otx.mpa.modules.hooks.recording_forward_hooks import ( ActivationMapHook, FeatureVectorHook, diff --git a/otx/algorithms/detection/adapters/mmdet/models/detectors/custom_single_stage_detector.py b/otx/algorithms/detection/adapters/mmdet/models/detectors/custom_single_stage_detector.py index 32f6d9ffe00..1ad6a744819 100644 --- a/otx/algorithms/detection/adapters/mmdet/models/detectors/custom_single_stage_detector.py +++ b/otx/algorithms/detection/adapters/mmdet/models/detectors/custom_single_stage_detector.py @@ -9,10 +9,10 @@ from mmdet.models.builder import DETECTORS from mmdet.models.detectors.single_stage import SingleStageDetector +from otx.algorithms.common.adapters.mmdeploy.utils import is_mmdeploy_enabled from otx.algorithms.detection.adapters.mmdet.hooks.det_saliency_map_hook import ( DetSaliencyMapHook, ) -from otx.mpa.deploy.utils import is_mmdeploy_enabled from otx.mpa.modules.hooks.recording_forward_hooks import FeatureVectorHook from otx.mpa.modules.utils.task_adapt import map_class_names from otx.mpa.utils.logger import get_logger diff --git a/otx/algorithms/detection/adapters/mmdet/models/detectors/custom_yolox_detector.py b/otx/algorithms/detection/adapters/mmdet/models/detectors/custom_yolox_detector.py index 26b4e2712eb..20432c8fb0b 100644 --- a/otx/algorithms/detection/adapters/mmdet/models/detectors/custom_yolox_detector.py +++ b/otx/algorithms/detection/adapters/mmdet/models/detectors/custom_yolox_detector.py @@ -9,10 +9,10 @@ from mmdet.models.builder import DETECTORS from mmdet.models.detectors.yolox import YOLOX +from otx.algorithms.common.adapters.mmdeploy.utils import is_mmdeploy_enabled from otx.algorithms.detection.adapters.mmdet.hooks.det_saliency_map_hook import ( DetSaliencyMapHook, ) -from otx.mpa.deploy.utils import is_mmdeploy_enabled from otx.mpa.modules.hooks.recording_forward_hooks import FeatureVectorHook from otx.mpa.modules.utils.task_adapt import map_class_names from otx.mpa.utils.logger import get_logger diff --git a/otx/algorithms/detection/adapters/mmdet/nncf/patches.py b/otx/algorithms/detection/adapters/mmdet/nncf/patches.py index 5e36c254654..da640d248c9 100644 --- a/otx/algorithms/detection/adapters/mmdet/nncf/patches.py +++ b/otx/algorithms/detection/adapters/mmdet/nncf/patches.py @@ -19,6 +19,7 @@ from mmdet.models.roi_heads.bbox_heads.sabl_head import SABLHead from mmdet.models.roi_heads.mask_heads.fcn_mask_head import FCNMaskHead +from otx.algorithms.common.adapters.mmdeploy.utils import is_mmdeploy_enabled from otx.algorithms.common.adapters.nncf import ( NNCF_PATCHER, is_in_nncf_tracing, @@ -26,7 +27,6 @@ no_nncf_trace_wrapper, ) from otx.algorithms.common.adapters.nncf.patches import nncf_trace_context -from otx.mpa.deploy.utils import is_mmdeploy_enabled HEADS_TARGETS = dict( classes=( diff --git a/otx/mpa/cls/exporter.py b/otx/mpa/cls/exporter.py index 23734d2e055..c49a39f43f6 100644 --- a/otx/mpa/cls/exporter.py +++ b/otx/mpa/cls/exporter.py @@ -5,7 +5,7 @@ import numpy as np from mmcv.runner import wrap_fp16_model -from otx.mpa.deploy.utils import sync_batchnorm_2_batchnorm +from otx.algorithms.common.adapters.mmdeploy.utils import sync_batchnorm_2_batchnorm from otx.mpa.exporter_mixin import ExporterMixin from otx.mpa.registry import STAGES from otx.mpa.utils.logger import get_logger @@ -47,7 +47,7 @@ def model_builder_helper(*args, **kwargs): def naive_export(output_dir, model_builder, precision, cfg, model_name="model"): from mmcls.datasets.pipelines import Compose - from ..deploy.apis import NaiveExporter + from otx.algorithms.common.adapters.mmdeploy.apis import NaiveExporter def get_fake_data(cfg, orig_img_shape=(128, 128, 3)): pipeline = cfg.data.test.pipeline diff --git a/otx/mpa/deploy/__init__.py b/otx/mpa/deploy/__init__.py deleted file mode 100644 index cf2e118cd0e..00000000000 --- a/otx/mpa/deploy/__init__.py +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright (C) 2022 Intel Corporation -# SPDX-License-Identifier: Apache-2.0 -# - -from .utils import is_mmdeploy_enabled - -__all__ = [ - "is_mmdeploy_enabled", -] diff --git a/otx/mpa/det/exporter.py b/otx/mpa/det/exporter.py index 6af24b6801a..b3e08149ff9 100644 --- a/otx/mpa/det/exporter.py +++ b/otx/mpa/det/exporter.py @@ -5,7 +5,7 @@ import numpy as np from mmcv.runner import wrap_fp16_model -from otx.mpa.deploy.utils import sync_batchnorm_2_batchnorm +from otx.algorithms.common.adapters.mmdeploy.utils import sync_batchnorm_2_batchnorm from otx.mpa.exporter_mixin import ExporterMixin from otx.mpa.registry import STAGES from otx.mpa.utils.logger import get_logger @@ -46,7 +46,7 @@ def naive_export(output_dir, model_builder, precision, cfg, model_name="model"): from mmdet.apis.inference import LoadImage from mmdet.datasets.pipelines import Compose - from ..deploy.apis import NaiveExporter + from otx.algorithms.common.adapters.mmdeploy.apis import NaiveExporter def get_fake_data(cfg, orig_img_shape=(128, 128, 3)): pipeline = [LoadImage()] + cfg.data.test.pipeline[1:] diff --git a/otx/mpa/exporter_mixin.py b/otx/mpa/exporter_mixin.py index 9597ec3d25f..905708041eb 100644 --- a/otx/mpa/exporter_mixin.py +++ b/otx/mpa/exporter_mixin.py @@ -91,7 +91,7 @@ def mmdeploy_export( deploy_cfg, model_name="model", ): - from .deploy.apis import MMdeployExporter + from otx.algorithms.common.adapters.mmdeploy.apis import MMdeployExporter if precision == "FP16": deploy_cfg.backend_config.mo_options.flags.append("--compress_to_fp16") diff --git a/otx/mpa/modules/models/classifiers/sam_classifier.py b/otx/mpa/modules/models/classifiers/sam_classifier.py index 8edbffda75e..86bb09edd68 100644 --- a/otx/mpa/modules/models/classifiers/sam_classifier.py +++ b/otx/mpa/modules/models/classifiers/sam_classifier.py @@ -9,7 +9,7 @@ from mmcls.models.classifiers.base import BaseClassifier from mmcls.models.classifiers.image import ImageClassifier -from otx.mpa.deploy.utils import is_mmdeploy_enabled +from otx.algorithms.common.adapters.mmdeploy.utils import is_mmdeploy_enabled from otx.mpa.modules.utils.task_adapt import map_class_names from otx.mpa.utils.logger import get_logger diff --git a/otx/mpa/modules/models/segmentors/otx_encoder_decoder.py b/otx/mpa/modules/models/segmentors/otx_encoder_decoder.py index 4b6085340f8..a5812775259 100644 --- a/otx/mpa/modules/models/segmentors/otx_encoder_decoder.py +++ b/otx/mpa/modules/models/segmentors/otx_encoder_decoder.py @@ -6,7 +6,7 @@ from mmseg.models import SEGMENTORS from mmseg.models.segmentors.encoder_decoder import EncoderDecoder -from otx.mpa.deploy.utils import is_mmdeploy_enabled +from otx.algorithms.common.adapters.mmdeploy.utils import is_mmdeploy_enabled @SEGMENTORS.register_module() diff --git a/otx/mpa/seg/exporter.py b/otx/mpa/seg/exporter.py index de42b7f870b..c64065a666f 100644 --- a/otx/mpa/seg/exporter.py +++ b/otx/mpa/seg/exporter.py @@ -5,7 +5,7 @@ import numpy as np from mmcv.runner import wrap_fp16_model -from otx.mpa.deploy.utils import sync_batchnorm_2_batchnorm +from otx.algorithms.common.adapters.mmdeploy.utils import sync_batchnorm_2_batchnorm from otx.mpa.exporter_mixin import ExporterMixin from otx.mpa.registry import STAGES from otx.mpa.utils.logger import get_logger @@ -46,7 +46,7 @@ def naive_export(output_dir, model_builder, precision, cfg, model_name="model"): from mmseg.apis.inference import LoadImage from mmseg.datasets.pipelines import Compose - from ..deploy.apis import NaiveExporter + from otx.algorithms.common.adapters.mmdeploy.apis import NaiveExporter def get_fake_data(cfg, orig_img_shape=(128, 128, 3)): pipeline = [LoadImage()] + cfg.data.test.pipeline[1:] diff --git a/tests/unit/algorithms/common/adapters/mmdeploy/__init__.py b/tests/unit/algorithms/common/adapters/mmdeploy/__init__.py new file mode 100644 index 00000000000..ff847f01203 --- /dev/null +++ b/tests/unit/algorithms/common/adapters/mmdeploy/__init__.py @@ -0,0 +1,3 @@ +# Copyright (C) 2023 Intel Corporation +# +# SPDX-License-Identifier: MIT diff --git a/tests/unit/mpa/deploy/test_deploy_apis.py b/tests/unit/algorithms/common/adapters/mmdeploy/test_deploy_apis.py similarity index 93% rename from tests/unit/mpa/deploy/test_deploy_apis.py rename to tests/unit/algorithms/common/adapters/mmdeploy/test_deploy_apis.py index 3b72c29fd0b..fb4bfd33b52 100644 --- a/tests/unit/mpa/deploy/test_deploy_apis.py +++ b/tests/unit/algorithms/common/adapters/mmdeploy/test_deploy_apis.py @@ -9,10 +9,13 @@ import torch from mmcv.utils import Config -from otx.mpa.deploy.apis import NaiveExporter -from otx.mpa.deploy.utils import is_mmdeploy_enabled +from otx.algorithms.common.adapters.mmdeploy.apis import NaiveExporter +from otx.algorithms.common.adapters.mmdeploy.utils import is_mmdeploy_enabled from tests.test_suite.e2e_test_system import e2e_pytest_unit -from tests.unit.mpa.deploy.test_helpers import create_config, create_model +from tests.unit.algorithms.common.adapters.mmdeploy.test_helpers import ( + create_config, + create_model, +) class TestNaiveExporter: @@ -58,7 +61,7 @@ def test_export2openvino(self): if is_mmdeploy_enabled(): from mmdeploy.core import FUNCTION_REWRITER, mark - from otx.mpa.deploy.apis import MMdeployExporter + from otx.algorithms.common.adapters.mmdeploy.apis import MMdeployExporter class TestMMdeployExporter: @e2e_pytest_unit @@ -197,7 +200,9 @@ def test_partition(self): ) create_model("mmcls") - @FUNCTION_REWRITER.register_rewriter("tests.unit.mpa.deploy.test_helpers.MockModel.forward") + @FUNCTION_REWRITER.register_rewriter( + "tests.unit.algorithms.common.adapters.mmdeploy.test_helpers.MockModel.forward" + ) @mark("test", inputs=["input"], outputs=["output"]) def forward(ctx, self, *args, **kwargs): return ctx.origin_func(self, *args, **kwargs) diff --git a/tests/unit/mpa/deploy/test_helpers.py b/tests/unit/algorithms/common/adapters/mmdeploy/test_helpers.py similarity index 100% rename from tests/unit/mpa/deploy/test_helpers.py rename to tests/unit/algorithms/common/adapters/mmdeploy/test_helpers.py diff --git a/tests/unit/mpa/deploy/utils/test_deploy_utils_mmdeploy.py b/tests/unit/algorithms/common/adapters/mmdeploy/utils/test_deploy_utils_mmdeploy.py similarity index 83% rename from tests/unit/mpa/deploy/utils/test_deploy_utils_mmdeploy.py rename to tests/unit/algorithms/common/adapters/mmdeploy/utils/test_deploy_utils_mmdeploy.py index 88b86c9a092..b22c8178350 100644 --- a/tests/unit/mpa/deploy/utils/test_deploy_utils_mmdeploy.py +++ b/tests/unit/algorithms/common/adapters/mmdeploy/utils/test_deploy_utils_mmdeploy.py @@ -6,12 +6,15 @@ from mmcv.utils import Config -from otx.mpa.deploy.utils.mmdeploy import ( +from otx.algorithms.common.adapters.mmdeploy.utils.mmdeploy import ( is_mmdeploy_enabled, mmdeploy_init_model_helper, ) from tests.test_suite.e2e_test_system import e2e_pytest_unit -from tests.unit.mpa.deploy.test_helpers import create_config, create_model +from tests.unit.algorithms.common.adapters.mmdeploy.test_helpers import ( + create_config, + create_model, +) @e2e_pytest_unit diff --git a/tests/unit/mpa/deploy/utils/test_deploy_utils_onnx.py b/tests/unit/algorithms/common/adapters/mmdeploy/utils/test_deploy_utils_onnx.py similarity index 85% rename from tests/unit/mpa/deploy/utils/test_deploy_utils_onnx.py rename to tests/unit/algorithms/common/adapters/mmdeploy/utils/test_deploy_utils_onnx.py index 376d9c16664..d6ea85a004c 100644 --- a/tests/unit/mpa/deploy/utils/test_deploy_utils_onnx.py +++ b/tests/unit/algorithms/common/adapters/mmdeploy/utils/test_deploy_utils_onnx.py @@ -8,10 +8,13 @@ import onnx import torch -from otx.mpa.deploy.apis import NaiveExporter -from otx.mpa.deploy.utils.onnx import prepare_onnx_for_openvino, remove_nodes_by_op_type +from otx.algorithms.common.adapters.mmdeploy.apis import NaiveExporter +from otx.algorithms.common.adapters.mmdeploy.utils.onnx import ( + prepare_onnx_for_openvino, + remove_nodes_by_op_type, +) from tests.test_suite.e2e_test_system import e2e_pytest_unit -from tests.unit.mpa.deploy.test_helpers import create_model +from tests.unit.algorithms.common.adapters.mmdeploy.test_helpers import create_model @e2e_pytest_unit diff --git a/tests/unit/mpa/deploy/utils/test_deploy_utils_operations_domain.py b/tests/unit/algorithms/common/adapters/mmdeploy/utils/test_deploy_utils_operations_domain.py similarity index 67% rename from tests/unit/mpa/deploy/utils/test_deploy_utils_operations_domain.py rename to tests/unit/algorithms/common/adapters/mmdeploy/utils/test_deploy_utils_operations_domain.py index d6573075619..6a74f2aed8c 100644 --- a/tests/unit/mpa/deploy/utils/test_deploy_utils_operations_domain.py +++ b/tests/unit/algorithms/common/adapters/mmdeploy/utils/test_deploy_utils_operations_domain.py @@ -2,7 +2,10 @@ # SPDX-License-Identifier: Apache-2.0 # -from otx.mpa.deploy.utils.operations_domain import DOMAIN_CUSTOM_OPS_NAME, add_domain +from otx.algorithms.common.adapters.mmdeploy.utils.operations_domain import ( + DOMAIN_CUSTOM_OPS_NAME, + add_domain, +) from tests.test_suite.e2e_test_system import e2e_pytest_unit diff --git a/tests/unit/mpa/deploy/utils/test_deploy_utils_utils.py b/tests/unit/algorithms/common/adapters/mmdeploy/utils/test_deploy_utils_utils.py similarity index 95% rename from tests/unit/mpa/deploy/utils/test_deploy_utils_utils.py rename to tests/unit/algorithms/common/adapters/mmdeploy/utils/test_deploy_utils_utils.py index 6328cc6bbbd..b4e1dd41ee6 100644 --- a/tests/unit/mpa/deploy/utils/test_deploy_utils_utils.py +++ b/tests/unit/algorithms/common/adapters/mmdeploy/utils/test_deploy_utils_utils.py @@ -5,7 +5,10 @@ import numpy as np import torch -from otx.mpa.deploy.utils.utils import numpy_2_list, sync_batchnorm_2_batchnorm +from otx.algorithms.common.adapters.mmdeploy.utils.utils import ( + numpy_2_list, + sync_batchnorm_2_batchnorm, +) from tests.test_suite.e2e_test_system import e2e_pytest_unit diff --git a/tests/unit/mpa/cls/test_cls_exporter.py b/tests/unit/mpa/cls/test_cls_exporter.py index 427c58281e0..48c6afe3f39 100644 --- a/tests/unit/mpa/cls/test_cls_exporter.py +++ b/tests/unit/mpa/cls/test_cls_exporter.py @@ -1,8 +1,8 @@ import pytest from otx.algorithms.classification.adapters.mmcls.utils.builder import build_classifier +from otx.algorithms.common.adapters.mmdeploy.apis import NaiveExporter from otx.mpa.cls.exporter import ClsExporter -from otx.mpa.deploy.apis import NaiveExporter from otx.mpa.exporter_mixin import ExporterMixin from tests.test_suite.e2e_test_system import e2e_pytest_unit from tests.unit.algorithms.classification.test_helper import setup_mpa_task_parameters diff --git a/tests/unit/mpa/deploy/__init__.py b/tests/unit/mpa/deploy/__init__.py index 2faffbe2b1f..ff847f01203 100644 --- a/tests/unit/mpa/deploy/__init__.py +++ b/tests/unit/mpa/deploy/__init__.py @@ -1,13 +1,3 @@ # Copyright (C) 2023 Intel Corporation # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions -# and limitations under the License. +# SPDX-License-Identifier: MIT diff --git a/tests/unit/mpa/det/test_det_exporter.py b/tests/unit/mpa/det/test_det_exporter.py index 0cc89684254..7e0797799d2 100644 --- a/tests/unit/mpa/det/test_det_exporter.py +++ b/tests/unit/mpa/det/test_det_exporter.py @@ -2,8 +2,8 @@ import pytest +from otx.algorithms.common.adapters.mmdeploy.apis import NaiveExporter from otx.algorithms.detection.adapters.mmdet.utils.builder import build_detector -from otx.mpa.deploy.apis import NaiveExporter from otx.mpa.det.exporter import DetectionExporter from otx.mpa.exporter_mixin import ExporterMixin from otx.mpa.utils.config_utils import MPAConfig diff --git a/tests/unit/mpa/seg/test_seg_exporter.py b/tests/unit/mpa/seg/test_seg_exporter.py index ccfc595be4f..28d35c2f455 100644 --- a/tests/unit/mpa/seg/test_seg_exporter.py +++ b/tests/unit/mpa/seg/test_seg_exporter.py @@ -2,8 +2,8 @@ import pytest +from otx.algorithms.common.adapters.mmdeploy.apis import NaiveExporter from otx.algorithms.segmentation.adapters.mmseg.utils.builder import build_segmentor -from otx.mpa.deploy.apis import NaiveExporter from otx.mpa.exporter_mixin import ExporterMixin from otx.mpa.seg.exporter import SegExporter from otx.mpa.utils.config_utils import MPAConfig diff --git a/tests/unit/mpa/test_export_mixin.py b/tests/unit/mpa/test_export_mixin.py index 6a3d045ca0d..ce5284532ba 100644 --- a/tests/unit/mpa/test_export_mixin.py +++ b/tests/unit/mpa/test_export_mixin.py @@ -62,7 +62,7 @@ def mock_mmdeploy_export(output_dir, model_builder, precision, cfg, deploy_cfg, @e2e_pytest_unit def test_mmdeploy_export(self, mocker): - from otx.mpa.deploy.apis import MMdeployExporter + from otx.algorithms.common.adapters.mmdeploy.apis import MMdeployExporter mock_export_openvino = mocker.patch.object(MMdeployExporter, "export2openvino")