In order to increase the anchor's scale, I changed the model.rpn_head.anchor_strides = [4, 8, 16, 32, 64] to model.rpn_head.anchor_strides = [4, 6, 8, 16, 20, 32, 48, 64] in config file mask_rcnn_r50_fpn_1x.py, but I met some errors:
Traceback (most recent call last):
File "./tools/train.py", line 82, in
main()
File "./tools/train.py", line 77, in main
logger=logger)
File "/home/jwwangchn/anaconda2/envs/python3.6/lib/python3.6/site-packages/mmdet/apis/train.py", line 57, in train_detector
_dist_train(model, dataset, cfg, validate=validate)
File "/home/jwwangchn/anaconda2/envs/python3.6/lib/python3.6/site-packages/mmdet/apis/train.py", line 92, in _dist_train
runner.run(data_loaders, cfg.workflow, cfg.total_epochs)
File "/home/jwwangchn/anaconda2/envs/python3.6/lib/python3.6/site-packages/mmcv/runner/runner.py", line 349, in run
epoch_runner(data_loaders[i], kwargs)
File "/home/jwwangchn/anaconda2/envs/python3.6/lib/python3.6/site-packages/mmcv/runner/runner.py", line 255, in train
self.model, data_batch, train_mode=True, *kwargs)
File "/home/jwwangchn/anaconda2/envs/python3.6/lib/python3.6/site-packages/mmdet/apis/train.py", line 37, in batch_processor
losses = model(data)
File "/home/jwwangchn/anaconda2/envs/python3.6/lib/python3.6/site-packages/torch/nn/modules/module.py", line 477, in __call__
result = self.forward(input, *kwargs)
File "/home/jwwangchn/anaconda2/envs/python3.6/lib/python3.6/site-packages/mmcv/parallel/distributed.py", line 47, in forward
return self.module(inputs[0], *kwargs[0])
File "/home/jwwangchn/anaconda2/envs/python3.6/lib/python3.6/site-packages/torch/nn/modules/module.py", line 477, in __call__
result = self.forward(input, *kwargs)
File "/home/jwwangchn/anaconda2/envs/python3.6/lib/python3.6/site-packages/mmdet/models/detectors/base.py", line 79, in forward
return self.forward_train(img, img_meta, *kwargs)
File "/home/jwwangchn/anaconda2/envs/python3.6/lib/python3.6/site-packages/mmdet/models/detectors/two_stage.py", line 92, in forward_train
rpn_losses = self.rpn_head.loss(*rpn_loss_inputs)
File "/home/jwwangchn/anaconda2/envs/python3.6/lib/python3.6/site-packages/mmdet/models/rpn_heads/rpn_head.py", line 153, in loss
assert len(featmap_sizes) == len(self.anchor_generators)
AssertionError
What should I do to solve this problem? Thanks.
Current rpn_head force only one anchor scale(stride) on each fpn feature maps. See details in init() and forward() function.
You can rewrite a rpn_head file to support more flexible ways.
Anchor settings are specified with anchor_scales and anchor_ratios, while anchor_strides corresponds to the feature map strides. If you want to use more scales, you can specify anchor_scales=[4, 8, 16] and anchor_ratios=[0.5, 1.0, 2.0], so that 9 anchors will be generated in each location.
@hellock It solved my problem, thanks a lot.
@hellock If I want to halve the anchor scales for mask-rcnn (reset50-fpn), i.e. change [32, 64, 128, 256, 512] to [16, 32, 64, 128, 256], How should I change the configs?
@wangg12 You just need to modify anchor_scales=[8] to anchor_scales=[4].
@hellock I wonder How the scales are calculated based on these configs?
@hellock I wonder How the scales are calculated based on these configs?
metoo
Anchor scale is calculated as anchor_scales * anchor_base_sizes, if anchor_base_sizes is not set, anchor_strides is used by default.
If anchor_scales=[8] and anchor_strides=[4, 8, 16, 32, 64], then anchor scales for each fpn level are calculated as [8*4, 8*8, 8*16, 8*32, 8*64].
The anchor settings is not flexible, i have to change it by myself.....
Anchor scale is calculated as anchor_scales * anchor_base_sizes, if anchor_base_sizes is not set, anchor_strides is used by default.
If anchor_scales=[8] and anchor_strides=[4, 8, 16, 32, 64], then anchor scales for each fpn level are calculated as [84, 88, 816, 832, 8*64].
@hellock it is clear, But I have a question. If the areas of the objects in my dataset range from 40^2 to 150^2,which means these objects are medium and large, should I set the anchor_strides=[4,6, 8,10,12,14 16,] to get better detection rseult? Because anchor_scales=[8] and Anchor scale is anchor_scales * anchor_base_sizes ? Will the network convergence faster use these scheme in theory?
Most helpful comment
Anchor scale is calculated as
anchor_scales*anchor_base_sizes, ifanchor_base_sizesis not set,anchor_stridesis used by default.If
anchor_scales=[8]andanchor_strides=[4, 8, 16, 32, 64], then anchor scales for each fpn level are calculated as[8*4, 8*8, 8*16, 8*32, 8*64].