EdgeSAM icon indicating copy to clipboard operation
EdgeSAM copied to clipboard

ModuleNotFoundError: No module named 'mmdet'

Open f-dilly opened this issue 1 year ago • 6 comments

I created a python environement with venv python3 -m venv <env_name> I activate the environment: source <env_name>/bin/activate Than I cd into folder EdgeSam. I Install the requirements: pip install -r requirements.txt Than I install Edgesam: pip install -e .

I open a python interpreter inside the environment. I import: from edge_sam import SamPredictor, sam_model_registry but get the following error:

from edge_sam import SamPredictor, sam_model_registry Traceback (most recent call last): File "", line 1, in File "/EdgeSAM/edge_sam/init.py", line 7, in from .build_sam import ( File "/EdgeSAM/edge_sam/build_sam.py", line 11, in import edge_sam.modeling as modeling File "/EdgeSAM/edge_sam/modeling/init.py", line 7, in from .sam import Sam File "/EdgeSAM/edge_sam/modeling/sam.py", line 16, in from mmdet.models.dense_heads import RPNHead, CenterNetUpdateHead ModuleNotFoundError: No module named 'mmdet'

When I install mmdet 3.0.0 via pip, I get the following error: Traceback (most recent call last): File "", line 1, in File "/EdgeSAM/edge_sam/init.py", line 7, in from .build_sam import ( File "/EdgeSAM/edge_sam/build_sam.py", line 11, in import edge_sam.modeling as modeling File "/EdgeSAM/edge_sam/modeling/init.py", line 7, in from .sam import Sam File "/EdgeSAM/edge_sam/modeling/sam.py", line 16, in from mmdet.models.dense_heads import RPNHead, CenterNetUpdateHead File "/EdgeSAM/EdgeSamLast/lib/python3.11/site-packages/mmdet/init.py", line 17, in and mmcv_version < digit_version(mmcv_maximum_version)),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AssertionError: MMCV==2.2.0 is used but incompatible. Please install mmcv>=2.0.0rc4, <2.1.0.

When I manually downgradd mmcv to 2.0.0: /EdgeSAM/EdgeSamLast/lib/python3.11/site-packages/mmengine/optim/optimizer/zero_optimizer.py:11: DeprecationWarning: TorchScript support for functional optimizers is deprecated and will be removed in a future PyTorch release. Consider using the torch.compile optimizer instead. from torch.distributed.optim import
Traceback (most recent call last): File "", line 1, in File "/EdgeSAM/edge_sam/init.py", line 7, in from .build_sam import ( File "/EdgeSAM/edge_sam/build_sam.py", line 11, in import edge_sam.modeling as modeling File "/EdgeSAM/edge_sam/modeling/init.py", line 7, in from .sam import Sam File "/EdgeSAM/edge_sam/modeling/sam.py", line 16, in from mmdet.models.dense_heads import RPNHead, CenterNetUpdateHead File "/EdgeSAM/EdgeSamLast/lib/python3.11/site-packages/mmdet/models/init.py", line 2, in from .backbones import * # noqa: F401,F403 ^^^^^^^^^^^^^^^^^^^^^^^^ File "/EdgeSAM/EdgeSamLast/lib/python3.11/site-packages/mmdet/models/backbones/init.py", line 2, in from .csp_darknet import CSPDarknet File "/EdgeSAM/EdgeSamLast/lib/python3.11/site-packages/mmdet/models/backbones/csp_darknet.py", line 11, in from ..layers import CSPLayer File "/EdgeSAM/EdgeSamLast/lib/python3.11/site-packages/mmdet/models/layers/init.py", line 3, in from .bbox_nms import fast_nms, multiclass_nms File "/EdgeSAM/EdgeSamLast/lib/python3.11/site-packages/mmdet/models/layers/bbox_nms.py", line 5, in from mmcv.ops.nms import batched_nms File "/EdgeSAM/EdgeSamLast/lib/python3.11/site-packages/mmcv/ops/init.py", line 2, in from .active_rotated_filter import active_rotated_filter File "/EdgeSAM/EdgeSamLast/lib/python3.11/site-packages/mmcv/ops/active_rotated_filter.py", line 10, in ext_module = ext_loader.load_ext( ^^^^^^^^^^^^^^^^^^^^ File "/EdgeSAM/EdgeSamLast/lib/python3.11/site-packages/mmcv/utils/ext_loader.py", line 13, in load_ext ext = importlib.import_module('mmcv.' + name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/envs/user/lib/python3.11/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ModuleNotFoundError: No module named 'mmcv._ext'

My pip list output: absl-py 2.1.0 addict 2.4.0 aiofiles 23.2.1 annotated-types 0.7.0 anyio 4.4.0 argon2-cffi 23.1.0 argon2-cffi-bindings 21.2.0 arrow 1.3.0 asttokens 2.4.1 async-lru 2.0.4 attrs 24.2.0 babel 2.16.0 beautifulsoup4 4.12.3 bleach 6.1.0 cattrs 24.1.0 certifi 2024.8.30 cffi 1.17.1 charset-normalizer 3.3.2 click 8.1.7 comm 0.2.2 contourpy 1.3.0 coremltools 7.2 cycler 0.12.1 debugpy 1.8.5 decorator 5.1.1 defusedxml 0.7.1 docker-pycreds 0.4.0 edge_sam 1.0 /EdgeSAM executing 2.1.0 fastapi 0.114.1 fastjsonschema 2.20.0 ffmpy 0.4.0 filelock 3.16.0 fonttools 4.53.1 fqdn 1.5.1 fsspec 2024.9.0 gitdb 4.0.11 GitPython 3.1.43 gradio 4.44.0 gradio_client 1.3.0 grpcio 1.66.1 h11 0.14.0 httpcore 1.0.5 httpx 0.27.2 huggingface-hub 0.24.6 idna 3.8 importlib_metadata 8.4.0 importlib_resources 6.4.5 ipykernel 6.29.5 ipython 8.27.0 isoduration 20.11.0 jedi 0.19.1 Jinja2 3.1.4 json5 0.9.25 jsonpointer 3.0.0 jsonschema 4.23.0 jsonschema-specifications 2023.12.1 jupyter_client 8.6.2 jupyter_core 5.7.2 jupyter-events 0.10.0 jupyter-lsp 2.2.5 jupyter_server 2.14.2 jupyter_server_terminals 0.5.3 jupyterlab 4.2.5 jupyterlab_pygments 0.3.0 jupyterlab_server 2.27.3 kiwisolver 1.4.7 kornia 0.7.3 kornia_rs 0.1.5 loralib 0.1.2 Markdown 3.7 markdown-it-py 3.0.0 MarkupSafe 2.1.5 matplotlib 3.9.2 matplotlib-inline 0.1.7 mdurl 0.1.2 mistune 3.0.2 mmcv 2.0.0 mmdet 3.0.0 mmengine 0.10.4 mpmath 1.3.0 nbclient 0.10.0 nbconvert 7.16.4 nbformat 5.10.4 nest-asyncio 1.6.0 networkx 3.3 notebook 7.2.2 notebook_shim 0.2.4 numpy 2.1.1 nvidia-cublas-cu12 12.1.3.1 nvidia-cuda-cupti-cu12 12.1.105 nvidia-cuda-nvrtc-cu12 12.1.105 nvidia-cuda-runtime-cu12 12.1.105 nvidia-cudnn-cu12 9.1.0.70 nvidia-cufft-cu12 11.0.2.54 nvidia-curand-cu12 10.3.2.106 nvidia-cusolver-cu12 11.4.5.107 nvidia-cusparse-cu12 12.1.0.106 nvidia-nccl-cu12 2.20.5 nvidia-nvjitlink-cu12 12.6.68 nvidia-nvtx-cu12 12.1.105 opencv-python 4.10.0.84 orjson 3.10.7 overrides 7.7.0 packaging 24.1 pandas 2.2.2 pandocfilters 1.5.1 parso 0.8.4 pexpect 4.9.0 pillow 10.4.0 pip 23.2.1 platformdirs 4.3.2 prometheus_client 0.20.0 prompt_toolkit 3.0.47 protobuf 3.20.3 psutil 6.0.0 ptyprocess 0.7.0 pure_eval 0.2.3 pyaml 24.7.0 pycocotools 2.0.8 pycparser 2.22 pydantic 2.9.1 pydantic_core 2.23.3 pydub 0.25.1 Pygments 2.18.0 pyparsing 3.1.4 python-dateutil 2.9.0.post0 python-json-logger 2.0.7 python-multipart 0.0.9 pytz 2024.2 PyYAML 6.0.2 pyzmq 26.2.0 referencing 0.35.1 requests 2.32.3 rfc3339-validator 0.1.4 rfc3986-validator 0.1.1 rich 13.8.1 rpds-py 0.20.0 ruff 0.6.4 safetensors 0.4.5 scipy 1.14.1 semantic-version 2.10.0 Send2Trash 1.8.3 sentry-sdk 2.14.0 setproctitle 1.3.3 setuptools 65.5.0 shapely 2.0.6 shellingham 1.5.4 six 1.16.0 smmap 5.0.1 sniffio 1.3.1 soupsieve 2.6 stack-data 0.6.3 starlette 0.38.5 sympy 1.13.2 tensorboard 2.17.1 tensorboard-data-server 0.7.2 termcolor 2.4.0 terminado 0.18.1 terminaltables 3.1.10 timm 1.0.9 tinycss2 1.3.0 tomli 2.0.1 tomlkit 0.12.0 torch 2.4.1 torchvision 0.19.1 tornado 6.4.1 tqdm 4.66.5 traitlets 5.14.3 triton 3.0.0 typer 0.12.5 types-python-dateutil 2.9.0.20240906 typing_extensions 4.12.2 tzdata 2024.1 uri-template 1.3.0 urllib3 2.2.2 uvicorn 0.30.6 wandb 0.17.9 wcwidth 0.2.13 webcolors 24.8.0 webencodings 0.5.1 websocket-client 1.8.0 websockets 12.0 Werkzeug 3.0.4 yacs 0.1.8 yapf 0.40.2 zipp 3.20.1

f-dilly avatar Sep 11 '24 11:09 f-dilly

same error

mindcont avatar Oct 09 '24 05:10 mindcont

请问现在有解决吗?

wowangle97 avatar Dec 10 '24 08:12 wowangle97

请问现在有解决吗?

请问现在有解决吗,哈哈, 我也是这样报错

DingOUCer avatar Dec 11 '24 15:12 DingOUCer

请问现在有解决吗?

使用 pip install -U openmim mim install mmdet 我是这么解决的,但是紧跟着又报了ModuleNotFoundError: No module named 'mmcv._ext'这个错误,然后再使用 pip uninstall mmcv pip install mmcv==2.0.1 -f https://download.openmmlab.com/mmcv/dist/cu117/torch2.0/index.html cuda的版本根据你们自己对应的版本来,希望能帮到你

wowangle97 avatar Dec 12 '24 01:12 wowangle97

请问现在有解决吗?

使用 pip install -U openmim mim install mmdet 我是这么解决的,但是紧跟着又报了ModuleNotFoundError: No module named 'mmcv._ext'这个错误,然后再使用 pip uninstall mmcv pip install mmcv==2.0.1 -f https://download.openmmlab.com/mmcv/dist/cu117/torch2.0/index.html cuda的版本根据你们自己对应的版本来,希望能帮到你

感谢您,成功了!

DingOUCer avatar Dec 12 '24 08:12 DingOUCer

You can train your SAM model without mmdet/mmcv (I did it). Just put the imports into the if-conditions and not at the beginning of the document. The standard configuration doesn't need the mmdet things. The evaluation however does unfortunately.

Regarding mmdet/mmcv installation: In general it is difficult to install mmdet and mmcv. You have to align the cuda and torch installation with it. It should work to adapt the url "https://download.openmmlab.com/mmcv/dist/cu117/torch2.0/index.html" to get the mmcv that aligns with your cuda and torch.

altair199797 avatar Jan 17 '25 12:01 altair199797