Mmdetection: Cyclic depedency causes KeyError: 'ConvWS is already registered in conv layer'

Created on 9 Jul 2020  Â·  3Comments  Â·  Source: open-mmlab/mmdetection

Thanks for your error report and we appreciate it a lot.

Checklist

  1. I have searched related issues but cannot get the expected help. ✅
  2. The bug has not been fixed in the latest version. ✅

Describe the bug
Any script using import statements with mdet.apis raises KeyError in mmcv's registry.py, which safeguards against duplicate custom PyTorch modules from being registered. Essentially, ConvWS and ConvAWS modules are being registered more than once.

Reproduction

  1. What command or script did you run?
python demo/image_demo.py
  1. Did you make any modifications on the code or config? Did you understand what you have modified?
    No
  2. What dataset did you use?
    N/A

Environment

  1. Please run python mmdet/utils/collect_env.py to collect necessary environment infomation and paste it here.

Does not run due to error.

  1. You may add addition that may be helpful for locating the problem, such as

    • How you installed PyTorch [e.g., pip, conda, source]

    • Other environment variables that may be related (such as $PATH, $LD_LIBRARY_PATH, $PYTHONPATH, etc.)

Error traceback

Traceback (most recent call last):
  File "demo/image_demo.py", line 3, in <module>
    from mmdet.apis import inference_detector, init_detector, show_result_pyplot
  File "/home/ubuntu/workspace/mmdetection/mmdet/apis/__init__.py", line 1, in <module>
    from .inference import (async_inference_detector, inference_detector,
  File "/home/ubuntu/workspace/mmdetection/mmdet/apis/inference.py", line 9, in <module>
    from mmdet.core import get_classes
  File "/home/ubuntu/workspace/mmdetection/mmdet/core/__init__.py", line 2, in <module>
    from .bbox import *  # noqa: F401, F403
  File "/home/ubuntu/workspace/mmdetection/mmdet/core/bbox/__init__.py", line 7, in <module>
    from .samplers import (BaseSampler, CombinedSampler,
  File "/home/ubuntu/workspace/mmdetection/mmdet/core/bbox/samplers/__init__.py", line 9, in <module>
    from .score_hlr_sampler import ScoreHLRSampler
  File "/home/ubuntu/workspace/mmdetection/mmdet/core/bbox/samplers/score_hlr_sampler.py", line 3, in <module>
    from mmdet.ops import nms_match
  File "/home/ubuntu/workspace/mmdetection/mmdet/ops/__init__.py", line 2, in <module>
    from .conv_ws import ConvWS2d, conv_ws_2d
  File "/home/ubuntu/workspace/mmdetection/mmdet/ops/conv_ws.py", line 24, in <module>
    class ConvWS2d(nn.Conv2d):
  File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/mmcv/utils/registry.py", line 122, in _register
    module_class=cls, module_name=name, force=force)
  File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/mmcv/utils/registry.py", line 58, in _register_module
    raise KeyError(f'{module_name} is already registered '
KeyError: 'ConvWS is already registered in conv layer'

Most helpful comment

Temporary fix: modify mmdet/ops/conv_ws.py and add force=True to the decorator arguments, i.e.

@CONV_LAYERS.register_module(name='ConvWS', force=True)
@CONV_LAYERS.register_module(name='ConvAWS', force=True)

All 3 comments

Temporary fix: modify mmdet/ops/conv_ws.py and add force=True to the decorator arguments, i.e.

@CONV_LAYERS.register_module(name='ConvWS', force=True)
@CONV_LAYERS.register_module(name='ConvAWS', force=True)

Hi @namheegordonkim
As #3232 is merged, there basically are two workarounds.

  1. Install latest mmcv and mmdet
  2. Install mmcv==0.6.2 and mmdet==2.2.1

The issue seems to be resolved. Feel free to reopen it if you have any further questions.

Was this page helpful?
0 / 5 - 0 ratings