Closed harrytrinh2 closed 3 years ago
@zhengye1995 I think the reason I got this error because of my builder.py
file inside mmdet/models
.
import warnings
from mmcv.cnn import MODELS as MMCV_MODELS
from mmcv.utils import Registry
MODELS = Registry('models', parent=MMCV_MODELS)
BACKBONES = MODELS
NECKS = MODELS
ROI_EXTRACTORS = MODELS
SHARED_HEADS = MODELS
HEADS = MODELS
LOSSES = MODELS
#DETECTORS = MODELS
def build_backbone(cfg):
"""Build backbone."""
return BACKBONES.build(cfg)
def build_neck(cfg):
"""Build neck."""
return NECKS.build(cfg)
def build_roi_extractor(cfg):
"""Build roi extractor."""
return ROI_EXTRACTORS.build(cfg)
def build_shared_head(cfg):
"""Build shared head."""
return SHARED_HEADS.build(cfg)
def build_head(cfg):
"""Build head."""
return HEADS.build(cfg)
def build_loss(cfg):
"""Build loss."""
return LOSSES.build(cfg)
from torch import nn
from mmcv.utils import build_from_cfg
def build(cfg, registry, default_args=None):
print("registry.name: ", registry.name)
print(registry)
print("--------------------------------------------------------------------------")
if isinstance(cfg, list):
modules = [
build_from_cfg(cfg_, registry, default_args) for cfg_ in cfg
]
return nn.Sequential(*modules)
else:
return build_from_cfg(cfg, registry, default_args)
DETECTORS = Registry('detector', build_func=build)
def build_detector(cfg, train_cfg=None, test_cfg=None):
return build(cfg, DETECTORS, dict(train_cfg=train_cfg, test_cfg=test_cfg))
Also, in ba_aware_RPN_head.py
, instead of importing from registry.py
file like yours, I imported HEADS from ..builder
# from ..registry import HEADS
from ..builder import HEADS
Since you're more familiar with mmcv
, may be you know what I did wrong.
@zhengye1995
I think this error may be caused by the build_from_cfg when the cfg is list, try to replace the 'build_from_cfg' with 'build_model_from_cfg' as below:
def build(cfg, registry, default_args=None):
print("registry.name: ", registry.name)
print(registry)
print("--------------------------------------------------------------------------")
if isinstance(cfg, list):
modules = [
build_model_from_cfg(cfg_, registry, default_args) for cfg_ in cfg
]
return nn.Sequential(*modules)
else:
return build_from_cfg(cfg, registry, default_args)
Unfortunately, it returned the same error.
I got this error:
TypeError: BackgroundAwareRPNHead: 'int' object is not iterable
Do you know what is the problem?