zhengye1995 / Zero-shot-Instance-Segmentation

code for CVPR paper Zero-shot Instance Segmentation
Apache License 2.0
93 stars 14 forks source link

TypeError: BackgroundAwareRPNHead: 'int' object is not iterable #12

Closed harrytrinh2 closed 3 years ago

harrytrinh2 commented 3 years ago

I got this error: TypeError: BackgroundAwareRPNHead: 'int' object is not iterable

Traceback (most recent call last):
  File "./tools/train.py", line 195, in <module>
    main()
  File "./tools/train.py", line 168, in main
    test_cfg=cfg.get('test_cfg'))
  File "/home/merge/Harry/instance_seg/mmdetection/mmdet/models/builder.py", line 57, in build_detector
    cfg, default_args=dict(train_cfg=train_cfg, test_cfg=test_cfg))
  File "/home/merge/anaconda3/envs/open-mmlab1/lib/python3.7/site-packages/mmcv/utils/registry.py", line 210, in build
    return self.build_func(*args, **kwargs, registry=self)
  File "/home/merge/anaconda3/envs/open-mmlab1/lib/python3.7/site-packages/mmcv/cnn/builder.py", line 26, in build_model_from_cfg
    return build_from_cfg(cfg, registry, default_args)
  File "/home/merge/anaconda3/envs/open-mmlab1/lib/python3.7/site-packages/mmcv/utils/registry.py", line 54, in build_from_cfg
    raise type(e)(f'{obj_cls.__name__}: {e}')
TypeError: ZeroShotMaskRCNN: BackgroundAwareRPNHead: 'int' object is not iterable
Traceback (most recent call last):
  File "/home/merge/anaconda3/envs/open-mmlab1/lib/python3.7/site-packages/mmcv/utils/registry.py", line 51, in build_from_cfg
    return obj_cls(**args)
  File "/home/merge/Harry/instance_seg/mmdetection/mmdet/models/dense_heads/ba_aware_RPN_head.py", line 20, in __init__
    super(BackgroundAwareRPNHead, self).__init__(2, in_channels, **kwargs)
  File "/home/merge/Harry/instance_seg/mmdetection/mmdet/models/dense_heads/ba_anchor_head.py", line 93, in __init__
    AnchorGenerator(anchor_base, anchor_scales, anchor_ratios))
  File "/home/merge/Harry/instance_seg/mmdetection/mmdet/core/anchor/anchor_generator.py", line 83, in __init__
    self.strides = [_pair(stride) for stride in strides]
TypeError: 'int' object is not iterable

Do you know what is the problem?

harrytrinh2 commented 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

zhengye1995 commented 3 years ago

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)
harrytrinh2 commented 3 years ago

Unfortunately, it returned the same error.