From a95cd20ee8b2f9edeb9a1f406da6749acdc9f631 Mon Sep 17 00:00:00 2001 From: RunningLeon Date: Fri, 2 Sep 2022 18:55:20 +0800 Subject: [PATCH 1/3] skip tests if codebase not installed --- tests/test_codebase/test_mmcls/test_classification.py | 5 ++++- .../test_mmcls/test_classification_model.py | 5 ++++- tests/test_codebase/test_mmcls/test_mmcls_models.py | 5 ++++- tests/test_codebase/test_mmdet/test_mmdet_core.py | 5 ++++- tests/test_codebase/test_mmdet/test_mmdet_models.py | 5 ++++- tests/test_codebase/test_mmdet/test_mmdet_utils.py | 6 +++++- tests/test_codebase/test_mmdet/test_object_detection.py | 5 ++++- .../test_mmdet/test_object_detection_model.py | 5 ++++- tests/test_codebase/test_mmedit/test_mmedit_models.py | 9 +++++++-- tests/test_codebase/test_mmedit/test_super_resolution.py | 6 +++++- .../test_mmedit/test_super_resolution_model.py | 7 ++++++- tests/test_codebase/test_mmocr/test_mmocr_models.py | 8 ++++++-- tests/test_codebase/test_mmocr/test_text_detection.py | 5 ++++- .../test_mmocr/test_text_detection_models.py | 5 ++++- tests/test_codebase/test_mmocr/test_text_recognition.py | 5 ++++- .../test_mmocr/test_text_recognition_models.py | 5 ++++- tests/test_codebase/test_mmseg/test_mmseg_models.py | 5 ++++- tests/test_codebase/test_mmseg/test_segmentation.py | 5 ++++- .../test_codebase/test_mmseg/test_segmentation_model.py | 5 ++++- 19 files changed, 85 insertions(+), 21 deletions(-) diff --git a/tests/test_codebase/test_mmcls/test_classification.py b/tests/test_codebase/test_mmcls/test_classification.py index de8698be65..599a8da1de 100644 --- a/tests/test_codebase/test_mmcls/test_classification.py +++ b/tests/test_codebase/test_mmcls/test_classification.py @@ -15,7 +15,10 @@ from mmdeploy.utils import Codebase, load_config from mmdeploy.utils.test import DummyModel, SwitchBackendWrapper -import_codebase(Codebase.MMCLS) +try: + import_codebase(Codebase.MMCLS) +except ImportError: + pytest.skip(f'{Codebase.MMCLS} is not installed.', allow_module_level=True) model_cfg_path = 'tests/test_codebase/test_mmcls/data/model.py' model_cfg = load_config(model_cfg_path)[0] diff --git a/tests/test_codebase/test_mmcls/test_classification_model.py b/tests/test_codebase/test_mmcls/test_classification_model.py index af640ce694..fc235c6647 100644 --- a/tests/test_codebase/test_mmcls/test_classification_model.py +++ b/tests/test_codebase/test_mmcls/test_classification_model.py @@ -15,7 +15,10 @@ NUM_CLASS = 1000 IMAGE_SIZE = 64 -import_codebase(Codebase.MMCLS) +try: + import_codebase(Codebase.MMCLS) +except ImportError: + pytest.skip(f'{Codebase.MMCLS} is not installed.', allow_module_level=True) @backend_checker(Backend.ONNXRUNTIME) diff --git a/tests/test_codebase/test_mmcls/test_mmcls_models.py b/tests/test_codebase/test_mmcls/test_mmcls_models.py index 05318369c7..caac79e377 100644 --- a/tests/test_codebase/test_mmcls/test_mmcls_models.py +++ b/tests/test_codebase/test_mmcls/test_mmcls_models.py @@ -9,7 +9,10 @@ from mmdeploy.utils import Backend, Codebase from mmdeploy.utils.test import WrapModel, check_backend, get_rewrite_outputs -import_codebase(Codebase.MMCLS) +try: + import_codebase(Codebase.MMCLS) +except ImportError: + pytest.skip(f'{Codebase.MMCLS} is not installed.', allow_module_level=True) input = torch.rand(1) diff --git a/tests/test_codebase/test_mmdet/test_mmdet_core.py b/tests/test_codebase/test_mmdet/test_mmdet_core.py index 4fd43a06ce..f822ea3336 100644 --- a/tests/test_codebase/test_mmdet/test_mmdet_core.py +++ b/tests/test_codebase/test_mmdet/test_mmdet_core.py @@ -13,7 +13,10 @@ check_backend, get_onnx_model, get_rewrite_outputs) -import_codebase(Codebase.MMDET) +try: + import_codebase(Codebase.MMDET) +except ImportError: + pytest.skip(f'{Codebase.MMDET} is not installed.', allow_module_level=True) @backend_checker(Backend.TENSORRT) diff --git a/tests/test_codebase/test_mmdet/test_mmdet_models.py b/tests/test_codebase/test_mmdet/test_mmdet_models.py index bd4f82e8dd..c855d41561 100644 --- a/tests/test_codebase/test_mmdet/test_mmdet_models.py +++ b/tests/test_codebase/test_mmdet/test_mmdet_models.py @@ -15,7 +15,10 @@ from mmdeploy.utils.test import (WrapModel, check_backend, get_model_outputs, get_rewrite_outputs) -import_codebase(Codebase.MMDET) +try: + import_codebase(Codebase.MMDET) +except ImportError: + pytest.skip(f'{Codebase.MMDET} is not installed.', allow_module_level=True) def seed_everything(seed=1029): diff --git a/tests/test_codebase/test_mmdet/test_mmdet_utils.py b/tests/test_codebase/test_mmdet/test_mmdet_utils.py index 13db44a010..b8452a1afc 100644 --- a/tests/test_codebase/test_mmdet/test_mmdet_utils.py +++ b/tests/test_codebase/test_mmdet/test_mmdet_utils.py @@ -1,6 +1,7 @@ # Copyright (c) OpenMMLab. All rights reserved. import mmcv import numpy as np +import pytest import torch from mmdeploy.codebase import import_codebase @@ -9,7 +10,10 @@ pad_with_value_if_necessary) from mmdeploy.utils import Codebase -import_codebase(Codebase.MMDET) +try: + import_codebase(Codebase.MMDET) +except ImportError: + pytest.skip(f'{Codebase.MMDET} is not installed.', allow_module_level=True) def test_clip_bboxes(): diff --git a/tests/test_codebase/test_mmdet/test_object_detection.py b/tests/test_codebase/test_mmdet/test_object_detection.py index 4fd5c2e175..d67e601164 100644 --- a/tests/test_codebase/test_mmdet/test_object_detection.py +++ b/tests/test_codebase/test_mmdet/test_object_detection.py @@ -17,7 +17,10 @@ from mmdeploy.utils import Codebase, load_config from mmdeploy.utils.test import DummyModel, SwitchBackendWrapper -import_codebase(Codebase.MMDET) +try: + import_codebase(Codebase.MMDET) +except ImportError: + pytest.skip(f'{Codebase.MMDET} is not installed.', allow_module_level=True) model_cfg_path = 'tests/test_codebase/test_mmdet/data/model.py' model_cfg = load_config(model_cfg_path)[0] diff --git a/tests/test_codebase/test_mmdet/test_object_detection_model.py b/tests/test_codebase/test_mmdet/test_object_detection_model.py index edee002441..aee8fe498a 100644 --- a/tests/test_codebase/test_mmdet/test_object_detection_model.py +++ b/tests/test_codebase/test_mmdet/test_object_detection_model.py @@ -14,7 +14,10 @@ from mmdeploy.utils import Backend, Codebase from mmdeploy.utils.test import SwitchBackendWrapper, backend_checker -import_codebase(Codebase.MMDET) +try: + import_codebase(Codebase.MMDET) +except ImportError: + pytest.skip(f'{Codebase.MMDET} is not installed.', allow_module_level=True) def assert_det_results(results, module_name: str = 'model'): diff --git a/tests/test_codebase/test_mmedit/test_mmedit_models.py b/tests/test_codebase/test_mmedit/test_mmedit_models.py index 24bf20b40c..d55e2cf445 100644 --- a/tests/test_codebase/test_mmedit/test_mmedit_models.py +++ b/tests/test_codebase/test_mmedit/test_mmedit_models.py @@ -5,14 +5,18 @@ import mmcv import onnx +import pytest import torch -from mmedit.models.backbones.sr_backbones import SRCNN from mmdeploy.codebase import import_codebase from mmdeploy.core import RewriterContext from mmdeploy.utils import Backend, Codebase, get_onnx_config -import_codebase(Codebase.MMEDIT) +try: + import_codebase(Codebase.MMEDIT) +except ImportError: + pytest.skip( + f'{Codebase.MMEDIT} is not installed.', allow_module_level=True) img = torch.rand(1, 3, 4, 4) model_file = tempfile.NamedTemporaryFile(suffix='.onnx').name @@ -46,6 +50,7 @@ def test_srcnn(): + from mmedit.models.backbones.sr_backbones import SRCNN pytorch_model = SRCNN() model_inputs = {'x': img} diff --git a/tests/test_codebase/test_mmedit/test_super_resolution.py b/tests/test_codebase/test_mmedit/test_super_resolution.py index c9ed7b86d0..0b6f87000f 100644 --- a/tests/test_codebase/test_mmedit/test_super_resolution.py +++ b/tests/test_codebase/test_mmedit/test_super_resolution.py @@ -14,7 +14,11 @@ from mmdeploy.utils import Codebase, load_config from mmdeploy.utils.test import SwitchBackendWrapper -import_codebase(Codebase.MMEDIT) +try: + import_codebase(Codebase.MMEDIT) +except ImportError: + pytest.skip( + f'{Codebase.MMEDIT} is not installed.', allow_module_level=True) model_cfg = 'tests/test_codebase/test_mmedit/data/model.py' model_cfg = load_config(model_cfg)[0] diff --git a/tests/test_codebase/test_mmedit/test_super_resolution_model.py b/tests/test_codebase/test_mmedit/test_super_resolution_model.py index 0d454eae91..aff765f84b 100644 --- a/tests/test_codebase/test_mmedit/test_super_resolution_model.py +++ b/tests/test_codebase/test_mmedit/test_super_resolution_model.py @@ -1,6 +1,7 @@ # Copyright (c) OpenMMLab. All rights reserved. import mmcv import numpy as np +import pytest import torch import mmdeploy.backend.onnxruntime as ort_apis @@ -8,7 +9,11 @@ from mmdeploy.utils import Backend, Codebase, load_config from mmdeploy.utils.test import SwitchBackendWrapper, backend_checker -import_codebase(Codebase.MMEDIT) +try: + import_codebase(Codebase.MMEDIT) +except ImportError: + pytest.skip( + f'{Codebase.MMEDIT} is not installed.', allow_module_level=True) @backend_checker(Backend.ONNXRUNTIME) diff --git a/tests/test_codebase/test_mmocr/test_mmocr_models.py b/tests/test_codebase/test_mmocr/test_mmocr_models.py index b23d472ce0..6dd3049784 100644 --- a/tests/test_codebase/test_mmocr/test_mmocr_models.py +++ b/tests/test_codebase/test_mmocr/test_mmocr_models.py @@ -5,7 +5,6 @@ import numpy as np import pytest import torch -from mmocr.models.textdet.necks import FPNC from mmdeploy.codebase import import_codebase from mmdeploy.core import RewriterContext, patch_model @@ -13,7 +12,12 @@ from mmdeploy.utils.test import (WrapModel, check_backend, get_model_outputs, get_rewrite_outputs) -import_codebase(Codebase.MMOCR) +try: + import_codebase(Codebase.MMOCR) +except ImportError: + pytest.skip(f'{Codebase.MMOCR} is not installed.', allow_module_level=True) + +from mmocr.models.textdet.necks import FPNC class FPNCNeckModel(FPNC): diff --git a/tests/test_codebase/test_mmocr/test_text_detection.py b/tests/test_codebase/test_mmocr/test_text_detection.py index 48377e249b..d894727d91 100644 --- a/tests/test_codebase/test_mmocr/test_text_detection.py +++ b/tests/test_codebase/test_mmocr/test_text_detection.py @@ -14,7 +14,10 @@ from mmdeploy.utils import Codebase, load_config from mmdeploy.utils.test import DummyModel, SwitchBackendWrapper -import_codebase(Codebase.MMOCR) +try: + import_codebase(Codebase.MMOCR) +except ImportError: + pytest.skip(f'{Codebase.MMOCR} is not installed.', allow_module_level=True) model_cfg_path = 'tests/test_codebase/test_mmocr/data/dbnet.py' model_cfg = load_config(model_cfg_path)[0] diff --git a/tests/test_codebase/test_mmocr/test_text_detection_models.py b/tests/test_codebase/test_mmocr/test_text_detection_models.py index f93f3a9f90..819658ba3a 100644 --- a/tests/test_codebase/test_mmocr/test_text_detection_models.py +++ b/tests/test_codebase/test_mmocr/test_text_detection_models.py @@ -12,7 +12,10 @@ from mmdeploy.utils import Backend, Codebase, load_config from mmdeploy.utils.test import SwitchBackendWrapper, backend_checker -import_codebase(Codebase.MMOCR) +try: + import_codebase(Codebase.MMOCR) +except ImportError: + pytest.skip(f'{Codebase.MMOCR} is not installed.', allow_module_level=True) IMAGE_SIZE = 32 diff --git a/tests/test_codebase/test_mmocr/test_text_recognition.py b/tests/test_codebase/test_mmocr/test_text_recognition.py index abff317815..5913ae844e 100644 --- a/tests/test_codebase/test_mmocr/test_text_recognition.py +++ b/tests/test_codebase/test_mmocr/test_text_recognition.py @@ -14,7 +14,10 @@ from mmdeploy.utils import Codebase, load_config from mmdeploy.utils.test import DummyModel, SwitchBackendWrapper -import_codebase(Codebase.MMOCR) +try: + import_codebase(Codebase.MMOCR) +except ImportError: + pytest.skip(f'{Codebase.MMOCR} is not installed.', allow_module_level=True) model_cfg_path = 'tests/test_codebase/test_mmocr/data/crnn.py' model_cfg = load_config(model_cfg_path)[0] diff --git a/tests/test_codebase/test_mmocr/test_text_recognition_models.py b/tests/test_codebase/test_mmocr/test_text_recognition_models.py index 1713a0e18e..572f02dc7a 100644 --- a/tests/test_codebase/test_mmocr/test_text_recognition_models.py +++ b/tests/test_codebase/test_mmocr/test_text_recognition_models.py @@ -12,7 +12,10 @@ from mmdeploy.utils import Backend, Codebase, load_config from mmdeploy.utils.test import SwitchBackendWrapper, backend_checker -import_codebase(Codebase.MMOCR) +try: + import_codebase(Codebase.MMOCR) +except ImportError: + pytest.skip(f'{Codebase.MMOCR} is not installed.', allow_module_level=True) IMAGE_SIZE = 32 diff --git a/tests/test_codebase/test_mmseg/test_mmseg_models.py b/tests/test_codebase/test_mmseg/test_mmseg_models.py index d5f2285939..535a818a87 100644 --- a/tests/test_codebase/test_mmseg/test_mmseg_models.py +++ b/tests/test_codebase/test_mmseg/test_mmseg_models.py @@ -13,7 +13,10 @@ from mmdeploy.utils.test import (WrapModel, check_backend, get_model_outputs, get_rewrite_outputs) -import_codebase(Codebase.MMSEG) +try: + import_codebase(Codebase.MMSEG) +except ImportError: + pytest.skip(f'{Codebase.MMSEG} is not installed.', allow_module_level=True) @BACKBONES.register_module() diff --git a/tests/test_codebase/test_mmseg/test_segmentation.py b/tests/test_codebase/test_mmseg/test_segmentation.py index c1b6769bb2..8e89df869c 100644 --- a/tests/test_codebase/test_mmseg/test_segmentation.py +++ b/tests/test_codebase/test_mmseg/test_segmentation.py @@ -16,7 +16,10 @@ from mmdeploy.utils import Codebase, load_config from mmdeploy.utils.test import DummyModel, SwitchBackendWrapper -import_codebase(Codebase.MMSEG) +try: + import_codebase(Codebase.MMSEG) +except ImportError: + pytest.skip(f'{Codebase.MMSEG} is not installed.', allow_module_level=True) model_cfg_path = 'tests/test_codebase/test_mmseg/data/model.py' model_cfg = load_config(model_cfg_path)[0] diff --git a/tests/test_codebase/test_mmseg/test_segmentation_model.py b/tests/test_codebase/test_mmseg/test_segmentation_model.py index 14eb9ed0ac..dd7e907d35 100644 --- a/tests/test_codebase/test_mmseg/test_segmentation_model.py +++ b/tests/test_codebase/test_mmseg/test_segmentation_model.py @@ -12,7 +12,10 @@ from mmdeploy.utils import Backend, Codebase from mmdeploy.utils.test import SwitchBackendWrapper, backend_checker -import_codebase(Codebase.MMSEG) +try: + import_codebase(Codebase.MMSEG) +except ImportError: + pytest.skip(f'{Codebase.MMSEG} is not installed.', allow_module_level=True) NUM_CLASS = 19 IMAGE_SIZE = 32 From bb1cabdeecf7587da9273634c59ff8c9c414fbf9 Mon Sep 17 00:00:00 2001 From: RunningLeon Date: Fri, 2 Sep 2022 18:56:10 +0800 Subject: [PATCH 2/3] skip ort run test --- tests/regression/mmcls.yml | 3 +-- tests/regression/mmdet.yml | 8 ++++---- tests/regression/mmedit.yml | 2 -- tests/regression/mmocr.yml | 2 -- tests/regression/mmrotate.yml | 2 +- 5 files changed, 6 insertions(+), 11 deletions(-) diff --git a/tests/regression/mmcls.yml b/tests/regression/mmcls.yml index 13ac34cd19..420f29238a 100644 --- a/tests/regression/mmcls.yml +++ b/tests/regression/mmcls.yml @@ -38,8 +38,7 @@ onnxruntime: pipeline_ort_dynamic_fp32: &pipeline_ort_dynamic_fp32 convert_image: *convert_image - backend_test: *default_backend_test - sdk_config: *sdk_dynamic + backend_test: False deploy_config: configs/mmcls/classification_onnxruntime_dynamic.py diff --git a/tests/regression/mmdet.yml b/tests/regression/mmdet.yml index 470a5d7ef1..9b83bc8626 100644 --- a/tests/regression/mmdet.yml +++ b/tests/regression/mmdet.yml @@ -37,8 +37,7 @@ globals: onnxruntime: pipeline_ort_static_fp32: &pipeline_ort_static_fp32 convert_image: *convert_image - backend_test: *default_backend_test - sdk_config: *sdk_dynamic + backend_test: False deploy_config: configs/mmdet/detection/detection_onnxruntime_static.py pipeline_ort_dynamic_fp32: &pipeline_ort_dynamic_fp32 @@ -168,13 +167,13 @@ pplnn: torchscript: pipeline_ts_fp32: &pipeline_ts_fp32 convert_image: *convert_image - backend_test: False + backend_test: *default_backend_test deploy_config: configs/mmdet/detection/detection_torchscript.py # ============= seg ================ pipeline_seg_ts_fp32: &pipeline_seg_ts_fp32 convert_image: *convert_image - backend_test: False + backend_test: *default_backend_test deploy_config: configs/mmdet/instance-seg/instance-seg_torchscript.py models: @@ -206,6 +205,7 @@ models: - deploy_config: configs/mmdet/detection/detection_tensorrt-fp16_dynamic-300x300-512x512.py convert_image: *convert_image backend_test: *default_backend_test + sdk_config: *sdk_dynamic - deploy_config: configs/mmdet/detection/single-stage_ncnn_static-300x300.py convert_image: *convert_image backend_test: False diff --git a/tests/regression/mmedit.yml b/tests/regression/mmedit.yml index fa9117a7a4..84b0e58a5d 100644 --- a/tests/regression/mmedit.yml +++ b/tests/regression/mmedit.yml @@ -27,8 +27,6 @@ globals: onnxruntime: pipeline_ort_static_fp32: &pipeline_ort_static_fp32 convert_image: *convert_image - backend_test: *default_backend_test - sdk_config: *sdk_dynamic deploy_config: configs/mmedit/super-resolution/super-resolution_onnxruntime_static.py pipeline_ort_dynamic_fp32: &pipeline_ort_dynamic_fp32 diff --git a/tests/regression/mmocr.yml b/tests/regression/mmocr.yml index 78b6dd64b9..3f1b27eaf1 100644 --- a/tests/regression/mmocr.yml +++ b/tests/regression/mmocr.yml @@ -34,8 +34,6 @@ onnxruntime: # ======= detection ======= pipeline_ort_detection_static_fp32: &pipeline_ort_detection_static_fp32 convert_image: *convert_image_det - backend_test: *default_backend_test - sdk_config: *sdk_detection_dynamic deploy_config: configs/mmocr/text-detection/text-detection_onnxruntime_static.py pipeline_ort_detection_dynamic_fp32: &pipeline_ort_detection_dynamic_fp32 diff --git a/tests/regression/mmrotate.yml b/tests/regression/mmrotate.yml index d6a9477dc1..51b2548636 100644 --- a/tests/regression/mmrotate.yml +++ b/tests/regression/mmrotate.yml @@ -14,7 +14,7 @@ globals: convert_image_det: &convert_image_det input_img: *img_demo test_img: *img_dota_demo - backend_test: &default_backend_test True + backend_test: &default_backend_test False onnxruntime: # ======= detection ======= From 512fab48363558141128b19feecaf33465ab3c77 Mon Sep 17 00:00:00 2001 From: RunningLeon Date: Fri, 2 Sep 2022 19:03:42 +0800 Subject: [PATCH 3/3] fix mmseg --- tests/test_codebase/test_mmseg/test_mmseg_models.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_codebase/test_mmseg/test_mmseg_models.py b/tests/test_codebase/test_mmseg/test_mmseg_models.py index 535a818a87..8d4f45555c 100644 --- a/tests/test_codebase/test_mmseg/test_mmseg_models.py +++ b/tests/test_codebase/test_mmseg/test_mmseg_models.py @@ -5,8 +5,6 @@ import torch import torch.nn as nn from mmcv import ConfigDict -from mmseg.models import BACKBONES, HEADS -from mmseg.models.decode_heads.decode_head import BaseDecodeHead from mmdeploy.codebase import import_codebase from mmdeploy.utils import Backend, Codebase, Task @@ -18,6 +16,9 @@ except ImportError: pytest.skip(f'{Codebase.MMSEG} is not installed.', allow_module_level=True) +from mmseg.models import BACKBONES, HEADS +from mmseg.models.decode_heads.decode_head import BaseDecodeHead + @BACKBONES.register_module() class ExampleBackbone(nn.Module):