fanq15 / FewX

FewX is an open-source toolbox on top of Detectron2 for data-limited instance-level recognition tasks.
https://github.com/fanq15/FewX
MIT License
346 stars 48 forks source link

__init__() got an unexpected keyword argument 'first_stride' #40

Open Zhang1Sheng opened 3 years ago

Zhang1Sheng commented 3 years ago

Traceback (most recent call last): File "mytest.py", line 253, in model = init() File "mytest.py", line 196, in init predictor = DefaultPredictor(cfg) File "/usr/local/lib/python3.7/dist-packages/detectron2/engine/defaults.py", line 216, in init self.model = build_model(self.cfg) File "/usr/local/lib/python3.7/dist-packages/detectron2/modeling/meta_arch/build.py", line 21, in build_model model = META_ARCH_REGISTRY.get(meta_arch)(cfg) File "mytest.py", line 43, in init self.roi_heads = build_roi_heads(cfg, self.backbone.output_shape()) File "/content/drive/My Drive/FewX/fewx/modeling/fsod/fsod_roi_heads.py", line 44, in build_roi_heads return ROI_HEADS_REGISTRY.get(name)(cfg, input_shape) File "/content/drive/My Drive/FewX/fewx/modeling/fsod/fsod_roi_heads.py", line 75, in init self.res5, out_channels = self._build_res5_block(cfg) File "/content/drive/My Drive/FewX/fewx/modeling/fsod/fsod_roi_heads.py", line 102, in _build_res5_block stride_in_1x1=stride_in_1x1, File "/usr/local/lib/python3.7/dist-packages/detectron2/modeling/backbone/resnet.py", line 609, in make_stage return ResNet.make_stage(*args, kwargs) File "/usr/local/lib/python3.7/dist-packages/detectron2/modeling/backbone/resnet.py", line 541, in make_stage block_class(in_channels=in_channels, out_channels=out_channels, curr_kwargs) TypeError: init() got an unexpected keyword argument 'first_stride'

how to solve this problem?

weihaosky commented 3 years ago

the argument 'first_stride' of make_stage() was removed in new version of detectron2, you can change 'first_stride=2' to 'stride_per_block=[2, 1, 1]'

anna-debug commented 3 years ago

I got the same problem too, but where in the code exactly should we change it?

pranay-ar commented 3 years ago

I got the same problem too, but where in the code exactly should we change it?

I am assuming you might have found wherein the code you have to change the argument, for those who experienced this error too, we have to change it in the 96th line of FEWX/fsod/modelling/fsod_roi_heads.py

CSberlin commented 1 year ago

the argument 'first_stride' of make_stage() was removed in new version of detectron2, you can change 'first_stride=2' to 'stride_per_block=[2, 1, 1]'

i find a problem, when i use old version of detectron2(detectron2-0.3+cu101). 'first_stride=2' in resnet arch means

(res5): Sequential( (0): BottleneckBlock( (shortcut): Conv2d( 1024, 2048, kernel_size=(1, 1), stride=(2, 2), bias=False (norm): FrozenBatchNorm2d(num_features=2048, eps=1e-05) ) (conv1): Conv2d( 1024, 512, kernel_size=(1, 1), stride=(2, 2), bias=False (norm): FrozenBatchNorm2d(num_features=512, eps=1e-05) ) (conv2): Conv2d( 512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False (norm): FrozenBatchNorm2d(num_features=512, eps=1e-05) ) (conv3): Conv2d( 512, 2048, kernel_size=(1, 1), stride=(1, 1), bias=False (norm): FrozenBatchNorm2d(num_features=2048, eps=1e-05) ) ) (1): BottleneckBlock( (conv1): Conv2d( 2048, 512, kernel_size=(1, 1), stride=(2, 2), bias=False (norm): FrozenBatchNorm2d(num_features=512, eps=1e-05) ) (conv2): Conv2d( 512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False (norm): FrozenBatchNorm2d(num_features=512, eps=1e-05) ) (conv3): Conv2d( 512, 2048, kernel_size=(1, 1), stride=(1, 1), bias=False (norm): FrozenBatchNorm2d(num_features=2048, eps=1e-05) ) ) (2): BottleneckBlock( (conv1): Conv2d( 2048, 512, kernel_size=(1, 1), stride=(2, 2), bias=False (norm): FrozenBatchNorm2d(num_features=512, eps=1e-05) ) (conv2): Conv2d( 512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False (norm): FrozenBatchNorm2d(num_features=512, eps=1e-05) ) (conv3): Conv2d( 512, 2048, kernel_size=(1, 1), stride=(1, 1), bias=False (norm): FrozenBatchNorm2d(num_features=2048, eps=1e-05) ) ) )

but when i use 'stride_per_block=[2, 1, 1]' in new version (detectron2 0.6+cu111). i got this arch

(res5): Sequential( (0): BottleneckBlock( (shortcut): Conv2d( 1024, 2048, kernel_size=(1, 1), stride=(2, 2), bias=False (norm): FrozenBatchNorm2d(num_features=2048, eps=1e-05) ) (conv1): Conv2d( 1024, 512, kernel_size=(1, 1), stride=(2, 2), bias=False (norm): FrozenBatchNorm2d(num_features=512, eps=1e-05) ) (conv2): Conv2d( 512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False (norm): FrozenBatchNorm2d(num_features=512, eps=1e-05) ) (conv3): Conv2d( 512, 2048, kernel_size=(1, 1), stride=(1, 1), bias=False (norm): FrozenBatchNorm2d(num_features=2048, eps=1e-05) ) ) (1): BottleneckBlock( (conv1): Conv2d( 2048, 512, kernel_size=(1, 1), stride=(1, 1), bias=False (norm): FrozenBatchNorm2d(num_features=512, eps=1e-05) ) (conv2): Conv2d( 512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False (norm): FrozenBatchNorm2d(num_features=512, eps=1e-05) ) (conv3): Conv2d( 512, 2048, kernel_size=(1, 1), stride=(1, 1), bias=False (norm): FrozenBatchNorm2d(num_features=2048, eps=1e-05) ) ) (2): BottleneckBlock( (conv1): Conv2d( 2048, 512, kernel_size=(1, 1), stride=(1, 1), bias=False (norm): FrozenBatchNorm2d(num_features=512, eps=1e-05) ) (conv2): Conv2d( 512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False (norm): FrozenBatchNorm2d(num_features=512, eps=1e-05) ) (conv3): Conv2d( 512, 2048, kernel_size=(1, 1), stride=(1, 1), bias=False (norm): FrozenBatchNorm2d(num_features=2048, eps=1e-05) ) ) ) you can find that when use 'first_stride=2' each conv1 stride in BottleneckBlock is 2, but only stride=2 in (0) BottleneckBlock when 'stride_per_block=[2, 1, 1]'