Thanks for your error report and we appreciate it a lot.
Checklist
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
python demo/image_demo.py
Environment
python mmdet/utils/collect_env.py to collect necessary environment infomation and paste it here.Does not run due to error.
$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'
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.
The issue seems to be resolved. Feel free to reopen it if you have any further questions.
Most helpful comment
Temporary fix: modify mmdet/ops/conv_ws.py and add force=True to the decorator arguments, i.e.