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

AttributeError: module 'mmcv' has no attribute 'Config'[Bug] #1781

Open
3 tasks done
anshkumar opened this issue Feb 18, 2023 · 15 comments
Open
3 tasks done

AttributeError: module 'mmcv' has no attribute 'Config'[Bug] #1781

anshkumar opened this issue Feb 18, 2023 · 15 comments
Assignees
Labels

Comments

@anshkumar
Copy link

Checklist

  • I have searched related issues but cannot get the expected help.
  • 2. I have read the FAQ documentation but cannot get the expected help.
  • 3. The bug has not been fixed in the latest version.

Describe the bug

I'm trying to export a model to TensorRT using following command:

export LD_LIBRARY_PATH=/usr/local/cuda/lib64:/home/sorter/TensorRT-8.4.1.5/lib:/home/sorter/onnxruntime-linux-x64-1.8.1/lib
export PYTHONPATH=${PYTHONPATH}:/home/sorter/mmdeploy

python /home/sorter/mmdeploy/tools/deploy.py \
    'instance-seg_tensorrt-int8_static.py' \
    'rtmdet-ins_tiny_config.py' \
    'rtmdet-ins_tiny/epoch_300.pth' \
    'data/val/images/970000000001.0.jpg' \
    --test-img 'data/val/images/21.jpg' \
    --work-dir 'rtmdet_export/' \
    --log-level DEBUG\
    --show \
    --device cuda:0 \

But getting following error:

Traceback (most recent call last):
  File "/home/sorter/mmdeploy/tools/deploy.py", line 12, in <module>
    from mmdeploy.apis import (create_calib_input_data, extract_model,
  File "/home/sorter/mmdeploy/mmdeploy/__init__.py", line 4, in <module>
    from mmdeploy.utils import get_root_logger
  File "/home/sorter/mmdeploy/mmdeploy/utils/__init__.py", line 18, in <module>
    from .config_utils import (cfg_apply_marks, get_backend,
  File "/home/sorter/mmdeploy/mmdeploy/utils/config_utils.py", line 10, in <module>
    def load_config(*args) -> List[mmcv.Config]:
AttributeError: module 'mmcv' has no attribute 'Config'

Following instructions griven here.
mmcv=2.0.0rc2

Reproduction

go to the mmdeploy folder

cd ${PATH_TO_MMDEPLOY}

download RTMDet-s checkpoint

wget -P checkpoint https://download.openmmlab.com/mmdetection/v3.0/rtmdet/rtmdet_s_8xb32-300e_coco/rtmdet_s_8xb32-300e_coco_20220905_161602-387a891e.pth

run the command to start model conversion

python tools/deploy.py
configs/mmdet/detection/detection_tensorrt_static-640x640.py
${PATH_TO_MMDET}/configs/rtmdet/rtmdet_s_8xb32-300e_coco.py
checkpoint/rtmdet_s_8xb32-300e_coco_20220905_161602-387a891e.pth
demo/resources/det.jpg
--work-dir ./work_dirs/rtmdet
--device cuda:0
--show

Environment

Traceback (most recent call last):
  File "tools/check_env.py", line 4, in <module>
    from mmcv.utils import get_git_hash
ImportError: cannot import name 'get_git_hash' from 'mmcv.utils' (/home/sorter/miniconda3/envs/openmmlab/lib/python3.8/site-packages/mmcv/utils/__init__.py)

Error traceback

No response

@hanrui1sensetime
Copy link
Collaborator

Hi, @anshkumar: what is your mmdeploy version?

import mmdeploy
print(mmdeploy.__version__)

Your mmdeploy version should be started as v1.0.0

@anshkumar
Copy link
Author

I'm getting following error with import mmdeploy

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/sort/mmdeploy/mmdeploy/__init__.py", line 4, in <module>
    from mmdeploy.utils import get_root_logger
  File "/home/sort/mmdeploy/mmdeploy/utils/__init__.py", line 18, in <module>
    from .config_utils import (cfg_apply_marks, get_backend,
  File "/home/sort/mmdeploy/mmdeploy/utils/config_utils.py", line 10, in <module>
    def load_config(*args) -> List[mmcv.Config]:
AttributeError: module 'mmcv' has no attribute 'Config'

@hanrui1sensetime
Copy link
Collaborator

I'm getting following error with import mmdeploy

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/sort/mmdeploy/mmdeploy/__init__.py", line 4, in <module>
    from mmdeploy.utils import get_root_logger
  File "/home/sort/mmdeploy/mmdeploy/utils/__init__.py", line 18, in <module>
    from .config_utils import (cfg_apply_marks, get_backend,
  File "/home/sort/mmdeploy/mmdeploy/utils/config_utils.py", line 10, in <module>
    def load_config(*args) -> List[mmcv.Config]:
AttributeError: module 'mmcv' has no attribute 'Config'

You can check the content in /home/sort/mmdeploy/mmdeploy/version.py the __version__ must be started as v1.0.0

@anshkumar
Copy link
Author

I was using master branch. Switched to remotes/origin/1.x branch now. Now getting following error:

/home/sorter/mmdetection/mmdet/models/dense_heads/rtmdet_ins_head.py:559: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
  if num_inst < 1:
Process Process-2:
Traceback (most recent call last):
  File "/home/sorter/miniconda3/envs/openmmlab/lib/python3.8/multiprocessing/process.py", line 315, in _bootstrap
    self.run()
  File "/home/sorter/miniconda3/envs/openmmlab/lib/python3.8/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/home/sorter/miniconda3/envs/openmmlab/lib/python3.8/site-packages/mmdeploy/apis/core/pipeline_manager.py", line 107, in __call__
    ret = func(*args, **kwargs)
  File "/home/sorter/miniconda3/envs/openmmlab/lib/python3.8/site-packages/mmdeploy/apis/pytorch2onnx.py", line 96, in torch2onnx
    export(
  File "/home/sorter/miniconda3/envs/openmmlab/lib/python3.8/site-packages/mmdeploy/apis/core/pipeline_manager.py", line 356, in _wrap
    return self.call_function(func_name_, *args, **kwargs)
  File "/home/sorter/miniconda3/envs/openmmlab/lib/python3.8/site-packages/mmdeploy/apis/core/pipeline_manager.py", line 326, in call_function
    return self.call_function_local(func_name, *args, **kwargs)
  File "/home/sorter/miniconda3/envs/openmmlab/lib/python3.8/site-packages/mmdeploy/apis/core/pipeline_manager.py", line 275, in call_function_local
    return pipe_caller(*args, **kwargs)
  File "/home/sorter/miniconda3/envs/openmmlab/lib/python3.8/site-packages/mmdeploy/apis/core/pipeline_manager.py", line 107, in __call__
    ret = func(*args, **kwargs)
  File "/home/sorter/miniconda3/envs/openmmlab/lib/python3.8/site-packages/mmdeploy/apis/onnx/export.py", line 122, in export
    torch.onnx.export(
  File "/home/sorter/miniconda3/envs/openmmlab/lib/python3.8/site-packages/torch/onnx/utils.py", line 504, in export
    _export(
  File "/home/sorter/miniconda3/envs/openmmlab/lib/python3.8/site-packages/torch/onnx/utils.py", line 1529, in _export
    graph, params_dict, torch_out = _model_to_graph(
  File "/home/sorter/miniconda3/envs/openmmlab/lib/python3.8/site-packages/mmdeploy/core/rewriters/rewriter_utils.py", line 379, in wrapper
    return self.func(self, *args, **kwargs)
  File "/home/sorter/miniconda3/envs/openmmlab/lib/python3.8/site-packages/mmdeploy/apis/onnx/optimizer.py", line 10, in model_to_graph__custom_optimizer
    graph, params_dict, torch_out = ctx.origin_func(*args, **kwargs)
  File "/home/sorter/miniconda3/envs/openmmlab/lib/python3.8/site-packages/torch/onnx/utils.py", line 1111, in _model_to_graph
    graph, params, torch_out, module = _create_jit_graph(model, args)
  File "/home/sorter/miniconda3/envs/openmmlab/lib/python3.8/site-packages/torch/onnx/utils.py", line 987, in _create_jit_graph
    graph, torch_out = _trace_and_get_graph_from_model(model, args)
  File "/home/sorter/miniconda3/envs/openmmlab/lib/python3.8/site-packages/torch/onnx/utils.py", line 891, in _trace_and_get_graph_from_model
    trace_graph, torch_out, inputs_states = torch.jit._get_trace_graph(
  File "/home/sorter/miniconda3/envs/openmmlab/lib/python3.8/site-packages/torch/jit/_trace.py", line 1184, in _get_trace_graph
    outs = ONNXTracedModule(f, strict, _force_outplace, return_inputs, _return_inputs_states)(*args, **kwargs)
  File "/home/sorter/miniconda3/envs/openmmlab/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/sorter/miniconda3/envs/openmmlab/lib/python3.8/site-packages/torch/jit/_trace.py", line 127, in forward
    graph, out = torch._C._create_graph_by_tracing(
  File "/home/sorter/miniconda3/envs/openmmlab/lib/python3.8/site-packages/torch/jit/_trace.py", line 121, in wrapper
    out_vars, _ = _flatten(outs)
RuntimeError: Only tuples, lists and Variables are supported as JIT inputs/outputs. Dictionaries and strings are also accepted, but their usage is not recommended. Here, received an input of unsupported type: InstanceData
03/01 11:07:24 - mmengine - ERROR - /home/sorter/miniconda3/envs/openmmlab/lib/python3.8/site-packages/mmdeploy/apis/core/pipeline_manager.py - pop_mp_output - 80 - `mmdeploy.apis.pytorch2onnx.torch2onnx` with Call id: 0 failed. exit.

@hanrui1sensetime
Copy link
Collaborator

I was using master branch. Switched to remotes/origin/1.x branch now. Now getting following error:

/home/sorter/mmdetection/mmdet/models/dense_heads/rtmdet_ins_head.py:559: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
  if num_inst < 1:
Process Process-2:
Traceback (most recent call last):
  File "/home/sorter/miniconda3/envs/openmmlab/lib/python3.8/multiprocessing/process.py", line 315, in _bootstrap
    self.run()
  File "/home/sorter/miniconda3/envs/openmmlab/lib/python3.8/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/home/sorter/miniconda3/envs/openmmlab/lib/python3.8/site-packages/mmdeploy/apis/core/pipeline_manager.py", line 107, in __call__
    ret = func(*args, **kwargs)
  File "/home/sorter/miniconda3/envs/openmmlab/lib/python3.8/site-packages/mmdeploy/apis/pytorch2onnx.py", line 96, in torch2onnx
    export(
  File "/home/sorter/miniconda3/envs/openmmlab/lib/python3.8/site-packages/mmdeploy/apis/core/pipeline_manager.py", line 356, in _wrap
    return self.call_function(func_name_, *args, **kwargs)
  File "/home/sorter/miniconda3/envs/openmmlab/lib/python3.8/site-packages/mmdeploy/apis/core/pipeline_manager.py", line 326, in call_function
    return self.call_function_local(func_name, *args, **kwargs)
  File "/home/sorter/miniconda3/envs/openmmlab/lib/python3.8/site-packages/mmdeploy/apis/core/pipeline_manager.py", line 275, in call_function_local
    return pipe_caller(*args, **kwargs)
  File "/home/sorter/miniconda3/envs/openmmlab/lib/python3.8/site-packages/mmdeploy/apis/core/pipeline_manager.py", line 107, in __call__
    ret = func(*args, **kwargs)
  File "/home/sorter/miniconda3/envs/openmmlab/lib/python3.8/site-packages/mmdeploy/apis/onnx/export.py", line 122, in export
    torch.onnx.export(
  File "/home/sorter/miniconda3/envs/openmmlab/lib/python3.8/site-packages/torch/onnx/utils.py", line 504, in export
    _export(
  File "/home/sorter/miniconda3/envs/openmmlab/lib/python3.8/site-packages/torch/onnx/utils.py", line 1529, in _export
    graph, params_dict, torch_out = _model_to_graph(
  File "/home/sorter/miniconda3/envs/openmmlab/lib/python3.8/site-packages/mmdeploy/core/rewriters/rewriter_utils.py", line 379, in wrapper
    return self.func(self, *args, **kwargs)
  File "/home/sorter/miniconda3/envs/openmmlab/lib/python3.8/site-packages/mmdeploy/apis/onnx/optimizer.py", line 10, in model_to_graph__custom_optimizer
    graph, params_dict, torch_out = ctx.origin_func(*args, **kwargs)
  File "/home/sorter/miniconda3/envs/openmmlab/lib/python3.8/site-packages/torch/onnx/utils.py", line 1111, in _model_to_graph
    graph, params, torch_out, module = _create_jit_graph(model, args)
  File "/home/sorter/miniconda3/envs/openmmlab/lib/python3.8/site-packages/torch/onnx/utils.py", line 987, in _create_jit_graph
    graph, torch_out = _trace_and_get_graph_from_model(model, args)
  File "/home/sorter/miniconda3/envs/openmmlab/lib/python3.8/site-packages/torch/onnx/utils.py", line 891, in _trace_and_get_graph_from_model
    trace_graph, torch_out, inputs_states = torch.jit._get_trace_graph(
  File "/home/sorter/miniconda3/envs/openmmlab/lib/python3.8/site-packages/torch/jit/_trace.py", line 1184, in _get_trace_graph
    outs = ONNXTracedModule(f, strict, _force_outplace, return_inputs, _return_inputs_states)(*args, **kwargs)
  File "/home/sorter/miniconda3/envs/openmmlab/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/sorter/miniconda3/envs/openmmlab/lib/python3.8/site-packages/torch/jit/_trace.py", line 127, in forward
    graph, out = torch._C._create_graph_by_tracing(
  File "/home/sorter/miniconda3/envs/openmmlab/lib/python3.8/site-packages/torch/jit/_trace.py", line 121, in wrapper
    out_vars, _ = _flatten(outs)
RuntimeError: Only tuples, lists and Variables are supported as JIT inputs/outputs. Dictionaries and strings are also accepted, but their usage is not recommended. Here, received an input of unsupported type: InstanceData
03/01 11:07:24 - mmengine - ERROR - /home/sorter/miniconda3/envs/openmmlab/lib/python3.8/site-packages/mmdeploy/apis/core/pipeline_manager.py - pop_mp_output - 80 - `mmdeploy.apis.pytorch2onnx.torch2onnx` with Call id: 0 failed. exit.

Seems the rewriter of RTMDet-ins doesn't work, please check your mmdet version. It is better to check the mmdet branch to the latest.

@anshkumar
Copy link
Author

Using branch 3.x and using latest pull.

@hanrui1sensetime
Copy link
Collaborator

Using branch 3.x and using latest pull.
You can add a breakpoint at here to check whether the code execute into the rtmdet-ins head.

@jediofgever
Copy link

I am facing the same issue

@hhswgww
Copy link

hhswgww commented Apr 20, 2023

i am facing the same issue
image
image

@hhswgww
Copy link

hhswgww commented Apr 20, 2023

@hanrui1sensetime
it seems that mmcv-2 series made some changes to the definition of mmcv member variables? Where can I see the modified usage method or instructions about the modification
image

@hhswgww
Copy link

hhswgww commented Apr 20, 2023

in https://mmcv.readthedocs.io/zh_CN/latest/compatibility.html ,可以看到
mmcv.utils 的所有类(例如 Config 和 Registry)和大部分函数,删除于 PR #2217,只保留少数和 mmcv 相关的函数;大部分相关函数被移入到mmengine中了
so,you can try:

# import mmcv 
# mmcv.Config
import mmengine
mmengine.Config

@sammilei
Copy link

in https://mmcv.readthedocs.io/zh_CN/latest/compatibility.html ,可以看到 mmcv.utils 的所有类(例如 Config 和 Registry)和大部分函数,删除于 PR #2217,只保留少数和 mmcv 相关的函数;大部分相关函数被移入到mmengine中了 so,you can try:

# import mmcv 
# mmcv.Config
import mmengine
mmengine.Config

It worked! Thanks!
I am on mmdeploy==0.2.0 and mmcv==2.0.0. I replaced all mmcv in .local/lib/python3.8/site-packages/mmdeploy/utils/config_utils.py with mmengine since the imported mmcv is for mmcv.Config. The error is gone.

@bedbad
Copy link

bedbad commented May 26, 2023

>>> import mmdeploy
print(mmdeploy.__version__)
>>> print(mmdeploy.__version__)
1.1.0

Still facing the same problem,
Applie M1, pip package mmdeploy

@bobo0810
Copy link

Source code installation, successful installation of the latest version 1.2.0

pip can only be installed to 0.x

git clone https://github.com/open-mmlab/mmdeploy.git
cd mmdeploy
pip install -U openmim && mim install -e .

@bedbad
Copy link

bedbad commented Aug 25, 2023

I need to install it through pip, because we are using it as hermetic dependency through bazel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants