caffe下py-Faster RCNN end2end模式修改anchor的scale大小
最近在使用Faster RCNN进行目标检测,因为自己的数据样本目标较小,原始的scale下训练结果不够,所以想着修改anchor的proposal大小来提高精度,这里记录下来。以下是Faster RCNN的论文和源码:
Faster RCNN论文:点这里
Faster RCNN源码Github地址:点这里
需要修改的总共有5个文件,分别修改如下:
1.源目录/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', (8, 16, 32))
self._anchors = generate_anchors(scales=np.array(anchor_scales))
self._num_anchors = self._anchors.shape[0]
if DEBUG:
print 'feat_stride: {}'.format(self._feat_stride)
print 'anchors:'
print self._anchors
# rois blob: holds R regions of interest, each is a 5-tuple
# (n, x1, y1, x2, y2) specifying an image batch index n and a
# rectangle (x1, y1, x2, y2)
top[0].reshape(1, 5)
# scores blob: holds scores for R regions of interest
if len(top) > 1:
top[1].reshape(1