faster-rcnn 多尺度目标检测

因为项目需要对小物体进行目标检测,首先想到了用densebox训练faster-rcnn

faster-rcnn论文给出的anchor是9个 ,由3(scale:128*128,256*256,512*512)* 3(ratio:1:1,1:2, 2:1)得来

添加一个64*64的scale,和 1.5:1的ratio, anchor数目变为16.


具体为修改lib/rpn/generate_anchors.py:

def generate_anchors(base_size=16, ratios=[0.5, 1,1.5, 2],  #modified
                     scales=2**np.arange(2, 6)):            #modified   


修改lib/rpn/anchor_target_layer.py:

    def setup(self, bottom, top):
        layer_params = yaml.load(self.param_str_)
        anchor_scales = layer_params.get('scales', (4,8, 16, 32))   #modified
        self._anchors = generate_anchors(scales=np.array(anchor_scales))
        self._num_anchors = self._anchors.shape[0]
        self._feat_stride = layer_params['feat_stride']

修改lib/rpn/proposal_layer.py:

def setup(self, bottom, top):
        # parse the layer parameter string, which must be valid YAML
        layer_params = yaml.load(self.param_str_)

        self._feat_stride = layer_params['feat_stride']
        anchor_scales = layer_params.get('scales', (4,8, 16, 32))  #modified
        self._anchors = generate_anchors(scales=np.array(anchor_scales))
        self._num_anchors = self._anchors.shape[0]



最后修改model的train.prototxt,将rpn_cls_score 和 rpn_bbox_pred层里面的num_output做相应修改。

这样就可以训练了,训练之前删掉data/cache/里面的缓存文件

你可能感兴趣的:(深度学习)