diff --git a/.circleci/docker/Dockerfile b/.circleci/docker/Dockerfile index 1ab3850bd..1e58427f7 100644 --- a/.circleci/docker/Dockerfile +++ b/.circleci/docker/Dockerfile @@ -26,9 +26,8 @@ RUN curl -fsSL -v -o ~/miniconda.sh -O https://repo.anaconda.com/miniconda/Mini RUN /opt/conda/bin/conda install pytorch==${TORCH_VERSION} torchvision==${TORCHVISION_VERSION} cudatoolkit=${CUDA} -c pytorch -c conda-forge ENV PATH /opt/conda/bin:$PATH -### install mim, mmengine, mmcv +### install mim, mmcv RUN /opt/conda/bin/pip install openmim &&\ - mim install mmengine &&\ mim install 'mmcv>=2.0.0rc1' WORKDIR /workspace diff --git a/.circleci/test.yml b/.circleci/test.yml index 8b737959c..cca08a194 100644 --- a/.circleci/test.yml +++ b/.circleci/test.yml @@ -68,7 +68,7 @@ commands: name: Install mmcv command: | python -m pip install opencv-python==4.5.4.60 openmim - python -m mim install mmengine "mmcv>=2.0.0rc1" + python -m mim install "mmcv>=2.0.0rc1" install_mmdeploy: description: "Install MMDeploy" steps: @@ -83,8 +83,6 @@ commands: name: Install requirements command: | cd mmdeploy - git clone --depth 1 --branch 1.x https://github.com/open-mmlab/mmediting.git ../mmedit - python -m pip install ../mmedit python -m mim install -r requirements/codebases.txt python -m pip install -r requirements/tests.txt python -m pip install -r requirements/runtime.txt diff --git a/.github/workflows/backend-ncnn.yml b/.github/workflows/backend-ncnn.yml index 7cf75022c..884c830bc 100644 --- a/.github/workflows/backend-ncnn.yml +++ b/.github/workflows/backend-ncnn.yml @@ -76,7 +76,7 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install mmdeploy run: | - python tools/scripts/build_ubuntu_x64_ncnn.py python -m pip install torch==1.8.2 torchvision==0.9.2 --extra-index-url https://download.pytorch.org/whl/lts/1.8/cpu - python -m pip install mmcv-lite mmengine + python -m pip install mmcv-lite + python tools/scripts/build_ubuntu_x64_ncnn.py python -c 'import mmdeploy.apis.ncnn as ncnn_api; assert ncnn_api.is_available() and ncnn_api.is_custom_ops_available()' diff --git a/.github/workflows/backend-ort.yml b/.github/workflows/backend-ort.yml index 23b436fbd..ec8dcc589 100644 --- a/.github/workflows/backend-ort.yml +++ b/.github/workflows/backend-ort.yml @@ -33,13 +33,12 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install mmdeploy run: | - python tools/scripts/build_ubuntu_x64_ort.py python -m pip install torch==1.8.2 torchvision==0.9.2 --extra-index-url https://download.pytorch.org/whl/lts/1.8/cpu - python -m pip install mmcv-lite mmengine + python -m pip install mmcv-lite openmim + python tools/scripts/build_ubuntu_x64_ort.py python -c 'import mmdeploy.apis.onnxruntime as ort_api; assert ort_api.is_available() and ort_api.is_custom_ops_available()' - name: test mmcls full pipeline run: | - python -m pip install openmim python -m mim install $(cat requirements/codebases.txt | grep mmcls) export MMDEPLOY_DIR=$(pwd) export ONNXRUNTIME_DIR=$MMDEPLOY_DIR/../mmdeploy-dep/onnxruntime-linux-x64-1.8.1 diff --git a/.github/workflows/backend-pplnn.yml b/.github/workflows/backend-pplnn.yml index c25497de0..a6cda4093 100644 --- a/.github/workflows/backend-pplnn.yml +++ b/.github/workflows/backend-pplnn.yml @@ -33,7 +33,7 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install mmdeploy run: | - python tools/scripts/build_ubuntu_x64_pplnn.py python -m pip install torch==1.8.2 torchvision==0.9.2 --extra-index-url https://download.pytorch.org/whl/lts/1.8/cpu - python -m pip install mmcv-lite mmengine + python -m pip install mmcv-lite + python tools/scripts/build_ubuntu_x64_pplnn.py python -c 'import mmdeploy.apis.pplnn as pplnn_api; assert pplnn_api.is_available()' diff --git a/.github/workflows/backend-torchscript.yml b/.github/workflows/backend-torchscript.yml index d52f372be..2cc149e74 100644 --- a/.github/workflows/backend-torchscript.yml +++ b/.github/workflows/backend-torchscript.yml @@ -33,4 +33,5 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install mmdeploy run: | + python -m pip install mmcv-lite python tools/scripts/build_ubuntu_x64_torchscript.py diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3dcac68b6..dfdf7e59c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -47,7 +47,6 @@ jobs: python -m pip install openmim python -m pip install -r requirements.txt -r requirements/backends.txt python -m mim install "mmcv>=2.0.0rc1" - git clone --depth 1 --branch 1.x https://github.com/open-mmlab/mmediting.git ../mmedit && python -m pip install ../mmedit python -m mim install -r requirements/codebases.txt python -m pip install -U numpy python -m pip list @@ -125,7 +124,6 @@ jobs: python -m pip install openmim python -m pip install -r requirements.txt -r requirements/backends.txt python -m mim install "mmcv>=2.0.0rc1" - git clone --depth 1 --branch 1.x https://github.com/open-mmlab/mmediting.git ../mmedit && python -m pip install ../mmedit CFLAGS=$CFLAGS python -m mim install -r requirements/codebases.txt python -m pip install -U pycuda numpy python -m pip list @@ -174,7 +172,6 @@ jobs: python -m pip install openmim python -m pip install -r requirements.txt -r requirements/backends.txt python -m mim install "mmcv>=2.0.0rc1" - git clone --depth 1 --branch 1.x https://github.com/open-mmlab/mmediting.git ../mmedit && python -m pip install ../mmedit python -m mim install -r requirements/codebases.txt python -m pip install -U pycuda numpy python -m pip list diff --git a/mmdeploy/codebase/__init__.py b/mmdeploy/codebase/__init__.py index 4f3268ce2..f9f915f66 100644 --- a/mmdeploy/codebase/__init__.py +++ b/mmdeploy/codebase/__init__.py @@ -4,6 +4,11 @@ from typing import List from mmdeploy.utils import Codebase from .base import BaseTask, MMCodebase, get_codebase_class +extra_dependent_library = { + Codebase.MMOCR: ['mmdet'], + Codebase.MMROTATE: ['mmdet'] +} + def import_codebase(codebase_type: Codebase, custom_module_list: List = []): """Import a codebase package in `mmdeploy.codebase` @@ -17,11 +22,16 @@ def import_codebase(codebase_type: Codebase, custom_module_list: List = []): codebase (Codebase): The codebase to import. """ import importlib + codebase_name = codebase_type.value + dependent_library = [codebase_name] + \ + extra_dependent_library.get(codebase_type, []) + for lib in dependent_library + custom_module_list: + if not importlib.util.find_spec(lib): + raise ImportError(f'{lib} has not been installed. ' + f'Import {lib} failed.') if len(custom_module_list) > 0: for custom_module in custom_module_list: importlib.import_module(f'{custom_module}') - else: - importlib.import_module(f'mmdeploy.codebase.{codebase_type.value}') codebase = get_codebase_class(codebase_type) codebase.register_all_modules() diff --git a/mmdeploy/codebase/base/mmcodebase.py b/mmdeploy/codebase/base/mmcodebase.py index c2d8c0098..2217aee9b 100644 --- a/mmdeploy/codebase/base/mmcodebase.py +++ b/mmdeploy/codebase/base/mmcodebase.py @@ -68,4 +68,13 @@ def get_codebase_class(codebase: Codebase) -> MMCodebase: Returns: type: The codebase class """ + import importlib + try: + importlib.import_module(f'mmdeploy.codebase.{codebase.value}.deploy') + except ImportError as e: + from mmdeploy.utils import get_root_logger + logger = get_root_logger() + logger.warn(f'Import mmdeploy.codebase.{codebase.value}.deploy failed' + 'Please check whether the module is the custom module.' + f'{e}') return CODEBASE.build({'type': codebase.value}) diff --git a/mmdeploy/codebase/mmcls/deploy/classification.py b/mmdeploy/codebase/mmcls/deploy/classification.py index 54eaa02c9..9badf049a 100644 --- a/mmdeploy/codebase/mmcls/deploy/classification.py +++ b/mmdeploy/codebase/mmcls/deploy/classification.py @@ -23,9 +23,15 @@ class MMClassification(MMCodebase): task_registry = MMCLS_TASK + @classmethod + def register_deploy_modules(cls): + import mmdeploy.codebase.mmcls.models # noqa: F401 + @classmethod def register_all_modules(cls): from mmcls.utils.setup_env import register_all_modules + + cls.register_deploy_modules() register_all_modules(True) diff --git a/mmdeploy/codebase/mmdet/deploy/object_detection.py b/mmdeploy/codebase/mmdet/deploy/object_detection.py index 3c0c833f3..c431ae0f1 100644 --- a/mmdeploy/codebase/mmdet/deploy/object_detection.py +++ b/mmdeploy/codebase/mmdet/deploy/object_detection.py @@ -22,9 +22,17 @@ class MMDetection(MMCodebase): task_registry = MMDET_TASK + @classmethod + def register_deploy_modules(cls): + import mmdeploy.codebase.mmdet.models # noqa: F401 + import mmdeploy.codebase.mmdet.ops + import mmdeploy.codebase.mmdet.structures # noqa: F401 + @classmethod def register_all_modules(cls): from mmdet.utils.setup_env import register_all_modules + + cls.register_deploy_modules() register_all_modules(True) diff --git a/mmdeploy/codebase/mmdet3d/deploy/mmdetection3d.py b/mmdeploy/codebase/mmdet3d/deploy/mmdetection3d.py index 8af6c647d..0ce371d2f 100644 --- a/mmdeploy/codebase/mmdet3d/deploy/mmdetection3d.py +++ b/mmdeploy/codebase/mmdet3d/deploy/mmdetection3d.py @@ -44,9 +44,15 @@ class MMDetection3d(MMCodebase): return MMDET3D_TASK.build(model_cfg, deploy_cfg, device) + @classmethod + def register_deploy_modules(cls): + import mmdeploy.codebase.mmdet3d.models # noqa: F401 + @classmethod def register_all_modules(cls): - from mmdet3d.utils.set_env import register_all_modules + from mmdet3d.utils.setup_env import register_all_modules + + cls.register_deploy_modules() register_all_modules(True) @staticmethod diff --git a/mmdeploy/codebase/mmedit/deploy/mmediting.py b/mmdeploy/codebase/mmedit/deploy/mmediting.py index 59d54ac1d..85d47d196 100644 --- a/mmdeploy/codebase/mmedit/deploy/mmediting.py +++ b/mmdeploy/codebase/mmedit/deploy/mmediting.py @@ -13,7 +13,13 @@ class MMEditing(MMCodebase): task_registry = MMEDIT_TASK + @classmethod + def register_deploy_modules(cls): + import mmdeploy.codebase.mmedit.models # noqa: F401 + @classmethod def register_all_modules(cls): from mmedit.utils.setup_env import register_all_modules + + cls.register_deploy_modules() register_all_modules(True) diff --git a/mmdeploy/codebase/mmocr/deploy/mmocr.py b/mmdeploy/codebase/mmocr/deploy/mmocr.py index f63034cd6..d368ba6f5 100644 --- a/mmdeploy/codebase/mmocr/deploy/mmocr.py +++ b/mmdeploy/codebase/mmocr/deploy/mmocr.py @@ -13,11 +13,19 @@ class MMOCR(MMCodebase): task_registry = MMOCR_TASK + @classmethod + def register_deploy_modules(cls): + import mmdeploy.codebase.mmocr.models # noqa: F401 + @classmethod def register_all_modules(cls): from mmdet.utils.setup_env import \ register_all_modules as register_all_modules_mmdet from mmocr.utils.setup_env import \ register_all_modules as register_all_modules_mmocr + + from mmdeploy.codebase.mmdet.deploy.object_detection import MMDetection + cls.register_deploy_modules() + MMDetection.register_deploy_modules() register_all_modules_mmocr(True) register_all_modules_mmdet(False) diff --git a/mmdeploy/codebase/mmpose/deploy/pose_detection.py b/mmdeploy/codebase/mmpose/deploy/pose_detection.py index 29307943b..144394fe2 100644 --- a/mmdeploy/codebase/mmpose/deploy/pose_detection.py +++ b/mmdeploy/codebase/mmpose/deploy/pose_detection.py @@ -117,9 +117,15 @@ class MMPose(MMCodebase): """mmpose codebase class.""" task_registry = MMPOSE_TASK + @classmethod + def register_deploy_modules(cls): + import mmdeploy.codebase.mmpose.models # noqa: F401 + @classmethod def register_all_modules(cls): from mmpose.utils.setup_env import register_all_modules + + cls.register_deploy_modules() register_all_modules(True) diff --git a/mmdeploy/codebase/mmseg/deploy/segmentation.py b/mmdeploy/codebase/mmseg/deploy/segmentation.py index 016d8a3e9..e52a52496 100644 --- a/mmdeploy/codebase/mmseg/deploy/segmentation.py +++ b/mmdeploy/codebase/mmseg/deploy/segmentation.py @@ -104,9 +104,15 @@ class MMSegmentation(MMCodebase): """mmsegmentation codebase class.""" task_registry = MMSEG_TASK + @classmethod + def register_deploy_modules(cls): + import mmdeploy.codebase.mmseg.models # noqa: F401 + @classmethod def register_all_modules(cls): from mmseg.utils.set_env import register_all_modules + + cls.register_deploy_modules() register_all_modules(True) diff --git a/requirements/codebases.txt b/requirements/codebases.txt index 055c52233..035febdb1 100644 --- a/requirements/codebases.txt +++ b/requirements/codebases.txt @@ -1,6 +1,6 @@ -mmcls>=1.0.0rc0 -mmdet>=3.0.0rc0 -mmedit==1.0.0rc1 -mmocr>=1.0.0rc0 +mmcls>=1.0.0rc2 +mmdet @ git+https://github.com/open-mmlab/mmdetection.git@dev-3.x +mmedit @ git+https://github.com/open-mmlab/mmediting.git@1.x +mmocr @ git+https://github.com/open-mmlab/mmocr.git@dev-1.x mmpose>=1.0.0b0 mmsegmentation>=1.0.0rc0