Replies: 1 comment
-
I think you were missing the parenthesis after register_module: @MODELS.register_module()
class SpatialAttention(nn.Module): And, for the code snippet & error message, try to quote them inside "```" next time, for better readability and to preserve the indentation: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
在主干网络中插入CBAMBlock模块,在init文中注册
@MODELS.register_module
class SpatialAttention(nn.Module):
@MODELS.register_module
class ChannelAttention(nn.Module):
@MODELS.register_module
class CBAMBlock(nn.Module):
Config:
model = dict(
type='DBNet',
backbone=dict(
type='mmdet.ResNet',
depth=50,
num_stages=4,
out_indices=(0, 1, 2, 3),
frozen_stages=-1,
norm_cfg=dict(type='BN', requires_grad=True),
norm_eval=False,
style='pytorch',
plugins=dict(
cfg=dict(type='CBAMBlock'),
stages=(True, True, True, True),
position='after_conv3'),
dcn=dict(type='DCNv2', deform_groups=1, fallback_on_stride=False),
init_cfg=dict(type='Pretrained', checkpoint='torchvision://resnet50'),
stage_with_dcn=(False, True, True, True)),
报错如下:
Traceback (most recent call last):
File "tools/train.py", line 114, in
main()
File "tools/train.py", line 103, in main
runner = Runner.from_cfg(cfg)
File "/root/mmocr/mmengine/runner/runner.py", line 439, in from_cfg
runner = cls(
File "/root/mmocr/mmengine/runner/runner.py", line 406, in init
self.model = self.build_model(model)
File "/root/mmocr/mmengine/runner/runner.py", line 813, in build_model
model = MODELS.build(model)
File "/root/mmocr/mmengine/registry/registry.py", line 545, in build
return self.build_func(cfg, *args, **kwargs, registry=self)
File "/root/mmocr/mmengine/registry/build_functions.py", line 241, in build_model_from_cfg
return build_from_cfg(cfg, registry, default_args)
File "/root/mmocr/mmengine/registry/build_functions.py", line 98, in build_from_cfg
obj_cls = registry.get(obj_type)
File "/root/mmocr/mmengine/registry/registry.py", line 442, in get
self.import_from_location()
File "/root/mmocr/mmengine/registry/registry.py", line 376, in import_from_location
import_module(loc)
File "/root/miniconda3/lib/python3.8/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1014, in _gcd_import
File "", line 991, in _find_and_load
File "", line 975, in _find_and_load_unlocked
File "", line 671, in _load_unlocked
File "", line 848, in exec_module
File "", line 219, in _call_with_frames_removed
File "/root/mmocr/mmocr/models/init.py", line 2, in
from .common import * # NOQA
File "/root/mmocr/mmocr/models/common/init.py", line 7, in
from .plugins import * # NOQA
File "/root/mmocr/mmocr/models/common/plugins/init.py", line 3, in
from .CommonModules import CBAMBlock
File "/root/mmocr/mmocr/models/common/plugins/CommonModules.py", line 8, in
class ChannelAttention(nn.Module):
File "/root/mmocr/mmengine/registry/registry.py", line 630, in register_module
raise TypeError(
TypeError: name must be None, an instance of str, or a sequence of str, but got <class 'type'>
请问一下报错原因,不太清楚是哪里的问题,参照了其他网络结构的plugins设置
Beta Was this translation helpful? Give feedback.
All reactions