Repository: open-mmlab/mmdetection

Issue:
GCNNet with x101 backbone is not work
I use gcb in x101 backbone，but get this error:
Traceback (most recent call last):
  File "./tools/train.py", line 95, in <module>
    main()
  File "./tools/train.py", line 73, in main
    cfg.model, train_cfg=cfg.train_cfg, test_cfg=cfg.test_cfg)
  File "/home/zhengye/anaconda3/envs/pytorch1.0/lib/python3.6/site-packages/mmdet-0.6.0+unknown-py3.6.egg/mmdet/models/builder.py", line 60, in build_detector
    return build(cfg, DETECTORS, dict(train_cfg=train_cfg, test_cfg=test_cfg))
  File "/home/zhengye/anaconda3/envs/pytorch1.0/lib/python3.6/site-packages/mmdet-0.6.0+unknown-py3.6.egg/mmdet/models/builder.py", line 32, in build
    return _build_module(cfg, registry, default_args)
  File "/home/zhengye/anaconda3/envs/pytorch1.0/lib/python3.6/site-packages/mmdet-0.6.0+unknown-py3.6.egg/mmdet/models/builder.py", line 24, in _build_module
    return obj_type(**args)
  File "/home/zhengye/anaconda3/envs/pytorch1.0/lib/python3.6/site-packages/mmdet-0.6.0+unknown-py3.6.egg/mmdet/models/detectors/cascade_rcnn.py", line 36, in __init__
    self.backbone = builder.build_backbone(backbone)
  File "/home/zhengye/anaconda3/envs/pytorch1.0/lib/python3.6/site-packages/mmdet-0.6.0+unknown-py3.6.egg/mmdet/models/builder.py", line 36, in build_backbone
    return build(cfg, BACKBONES)
  File "/home/zhengye/anaconda3/envs/pytorch1.0/lib/python3.6/site-packages/mmdet-0.6.0+unknown-py3.6.egg/mmdet/models/builder.py", line 32, in build
    return _build_module(cfg, registry, default_args)
  File "/home/zhengye/anaconda3/envs/pytorch1.0/lib/python3.6/site-packages/mmdet-0.6.0+unknown-py3.6.egg/mmdet/models/builder.py", line 24, in _build_module
    return obj_type(**args)
  File "/home/zhengye/anaconda3/envs/pytorch1.0/lib/python3.6/site-packages/mmdet-0.6.0+unknown-py3.6.egg/mmdet/models/backbones/resnext.py", line 191, in __init__
    super(ResNeXt, self).__init__(**kwargs)
  File "/home/zhengye/anaconda3/envs/pytorch1.0/lib/python3.6/site-packages/mmdet-0.6.0+unknown-py3.6.egg/mmdet/models/backbones/resnet.py", line 447, in __init__
    gen_attention_blocks=stage_with_gen_attention[i])
  File "/home/zhengye/anaconda3/envs/pytorch1.0/lib/python3.6/site-packages/mmdet-0.6.0+unknown-py3.6.egg/mmdet/models/backbones/resnet.py", line 317, in make_res_layer
    (0 in gen_attention_blocks) else None))
  File "/home/zhengye/anaconda3/envs/pytorch1.0/lib/python3.6/site-packages/mmdet-0.6.0+unknown-py3.6.egg/mmdet/models/backbones/resnext.py", line 19, in __init__
    super(Bottleneck, self).__init__(*args, **kwargs)
  File "/home/zhengye/anaconda3/envs/pytorch1.0/lib/python3.6/site-packages/mmdet-0.6.0+unknown-py3.6.egg/mmdet/models/backbones/resnet.py", line 205, in __init__
    self.context_block = ContextBlock(inplanes=gcb_inplanes, **gcb)
  File "/home/zhengye/anaconda3/envs/pytorch1.0/lib/python3.6/site-packages/mmdet-0.6.0+unknown-py3.6.egg/mmdet/ops/gcb/context_block.py", line 40, in __init__
    nn.Conv2d(self.inplanes, self.planes, kernel_size=1),
  File "/home/zhengye/anaconda3/envs/pytorch1.0/lib/python3.6/site-packages/torch/nn/modules/conv.py", line 327, in __init__
    False, _pair(0), groups, bias, padding_mode)
  File "/home/zhengye/anaconda3/envs/pytorch1.0/lib/python3.6/site-packages/torch/nn/modules/conv.py", line 45, in __init__
    self.reset_parameters()
  File "/home/zhengye/anaconda3/envs/pytorch1.0/lib/python3.6/site-packages/torch/nn/modules/conv.py", line 48, in reset_parameters
    init.kaiming_uniform_(self.weight, a=math.sqrt(5))
  File "/home/zhengye/anaconda3/envs/pytorch1.0/lib/python3.6/site-packages/torch/nn/init.py", line 323, in kaiming_uniform_
    fan = _calculate_correct_fan(tensor, mode)
  File "/home/zhengye/anaconda3/envs/pytorch1.0/lib/python3.6/site-packages/torch/nn/init.py", line 292, in _calculate_correct_fan
    fan_in, fan_out = _calculate_fan_in_and_fan_out(tensor)
  File "/home/zhengye/anaconda3/envs/pytorch1.0/lib/python3.6/site-packages/torch/nn/init.py", line 222, in _calculate_fan_in_and_fan_out
    receptive_field_size = tensor[0][0].numel()
IndexError: index 0 is out of bounds for dimension 0 with size 0


Discussion:
i meet the same problem. Do you know what's wrong?
you should update your backbone file，because the orfer of parameters is changed to compliance with specificatinos. See pull  #780 
Thanks for reporting! Will fix soon.
@zhengye1995 

i don't know what's your mean? your mean is my hyper parameter have some wrong? but when i run r4,it is ok, i only change gcb 1/4 to 1/16, the problem will appear

my backbone as following:
 backbone=dict(
        type='ResNeXt',
        depth=101,
        groups=32,
        base_width=4,
        num_stages=4,
        out_indices=(0, 1, 2, 3),
        frozen_stages=1,
        style='pytorch',
        gcb = dict(
            ratio=1. / 16.,
        ),
        stage_with_gcb = (False, True, True, True),
        dcn=dict(
            modulated=False,
            groups=32,
            deformable_groups=1,
            fallback_on_stride=False),
        stage_with_dcn=(False, True, True, True),
        norm_cfg=norm_cfg,
        norm_eval=False,
    ),

Resolving patch:
diff --git a/mmdet/models/backbones/resnet.py b/mmdet/models/backbones/resnet.py
--- a/mmdet/models/backbones/resnet.py
+++ b/mmdet/models/backbones/resnet.py
@@ -297,11 +297,11 @@ def make_res_layer(block,
     layers = []
     layers.append(
         block(
-            inplanes,
-            planes,
-            stride,
-            dilation,
-            downsample,
+            inplanes=inplanes,
+            planes=planes,
+            stride=stride,
+            dilation=dilation,
+            downsample=downsample,
             style=style,
             with_cp=with_cp,
             conv_cfg=conv_cfg,
@@ -314,10 +314,10 @@ def make_res_layer(block,
     for i in range(1, blocks):
         layers.append(
             block(
-                inplanes,
-                planes,
-                1,
-                dilation,
+                inplanes=inplanes,
+                planes=planes,
+                stride=1,
+                dilation=dilation,
                 style=style,
                 with_cp=with_cp,
                 conv_cfg=conv_cfg,
diff --git a/mmdet/models/backbones/resnext.py b/mmdet/models/backbones/resnext.py
--- a/mmdet/models/backbones/resnext.py
+++ b/mmdet/models/backbones/resnext.py
@@ -11,12 +11,12 @@
 
 class Bottleneck(_Bottleneck):
 
-    def __init__(self, groups=1, base_width=4, *args, **kwargs):
+    def __init__(self, inplanes, planes, groups=1, base_width=4, **kwargs):
         """Bottleneck block for ResNeXt.
         If style is "pytorch", the stride-two layer is the 3x3 conv layer,
         if it is "caffe", the stride-two layer is the first 1x1 conv layer.
         """
-        super(Bottleneck, self).__init__(*args, **kwargs)
+        super(Bottleneck, self).__init__(inplanes, planes, **kwargs)
 
         if groups == 1:
             width = self.planes


Test patch: