Skip to content

Commit

Permalink
merged rcnn results
Browse files Browse the repository at this point in the history
  • Loading branch information
unsky committed Jan 8, 2018
1 parent f9db6d3 commit 245b8ef
Show file tree
Hide file tree
Showing 9 changed files with 7,294 additions and 51 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@ This is the unoffical version Feature Pyramid Network for Feature Pyramid Netwo

# results
`FPN(resnet50)-end2end result is implemented without OHEM and train with pascal voc 2007 + 2012 test on 2007`
merged rcnn
|[email protected]|aeroplane|bicycle|bird|boat|bottle|bus|car|cat|chair|cow|
|:--:|:-------:| -----:| --:| --:|-----:|--:|--:|--:|----:|--:|
|0.788|0.8079| 0.8036| 0.8010| 0.7293|0.6743|0.8680|0.8766|0.8967|0.6122|0.8646|

|diningtable|dog |horse|motorbike|person |pottedplant|sheep|sofa|train|tv|
|----------:|:--:|:---:| -------:| -----:| -------:|----:|---:|----:|--:|
|0.7330|0.8855|0.8760| 0.8063| 0.7999| 0.5138|0.7905|0.7755|0.8637|0.7736|


shared rcnn
|[email protected]|aeroplane|bicycle|bird|boat|bottle|bus|car|cat|chair|cow|
|:--:|:-------:| -----:| --:| --:|-----:|--:|--:|--:|----:|--:|
|0.7833|0.8585| 0.8001| 0.7970| 0.7174|0.6522|0.8668|0.8768|0.8929|0.5842|0.8658|
Expand All @@ -14,6 +23,9 @@ This is the unoffical version Feature Pyramid Network for Feature Pyramid Netwo
|----------:|:--:|:---:| -------:| -----:| -------:|----:|---:|----:|--:|
|0.7022|0.8891|0.8680| 0.7991| 0.7944| 0.5065|0.7896|0.7707|0.8697|0.7653|
# framework
megred rcnn framework
![](merge_rcnn_framework.png)
shared rcnn
![](framework.png)
`the red and yellow are shared params`
# about the anchor size setting
Expand Down Expand Up @@ -46,14 +58,22 @@ cd lib
make
```
### train & test
shared rcnn
```bash
./experiments/scripts/FP_Net_end2end.sh 1 FPN pascal_voc
./test.sh 1 FPN pascal_voc
```
megred rcnn
```bash
./experiments/scripts/FP_Net_end2end_merge_rcnn.sh 0 FPN pascal_voc
./test_mergercnn.sh 0 FPN pascal_voc
```
0 1 is GPU id.

### TODO List
- [x] all tests passed
- [x] evaluate object detection performance on voc
- [x] evaluate merged rcnn version performance on voc

### feature pyramid networks for object detection

Expand Down
52 changes: 1 addition & 51 deletions lib/fast_rcnn/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,48 +61,7 @@ def snapshot(self):
"""
net = self.solver.net

scale_bbox_params = (cfg.TRAIN.BBOX_REG and
cfg.TRAIN.BBOX_NORMALIZE_TARGETS and
net.params.has_key('bbox_pred'))

if scale_bbox_params:
print "------------"
# save original values
orig_0_h2 = net.params['bbox_pred/h2'][0].data.copy()
orig_1_h2 = net.params['bbox_pred/h2'][1].data.copy()

orig_0_h3 = net.params['bbox_pred/h3'][0].data.copy()
orig_1_h3 = net.params['bbox_pred/h3'][1].data.copy()
orig_0_h4 = net.params['bbox_pred/h4'][0].data.copy()
orig_1_h4 = net.params['bbox_pred/h4'][1].data.copy()
orig_0_h5 = net.params['bbox_pred/h5'][0].data.copy()
orig_1_h5 = net.params['bbox_pred/h5'][1].data.copy()

# scale and shift with bbox reg unnormalization; then save snapshot
net.params['bbox_pred/h2'][0].data[...] = \
(net.params['bbox_pred/h2'][0].data *
self.bbox_stds[:, np.newaxis])
net.params['bbox_pred/h2'][1].data[...] = \
(net.params['bbox_pred/h2'][1].data *
self.bbox_stds + self.bbox_means)
net.params['bbox_pred/h3'][0].data[...] = \
(net.params['bbox_pred/h3'][0].data *
self.bbox_stds[:, np.newaxis])
net.params['bbox_pred/h3'][1].data[...] = \
(net.params['bbox_pred/h3'][1].data *
self.bbox_stds + self.bbox_means)
net.params['bbox_pred/h4'][0].data[...] = \
(net.params['bbox_pred/h4'][0].data *
self.bbox_stds[:, np.newaxis])
net.params['bbox_pred/h4'][1].data[...] = \
(net.params['bbox_pred/h4'][1].data *
self.bbox_stds + self.bbox_means)
net.params['bbox_pred/h5'][0].data[...] = \
(net.params['bbox_pred/h5'][0].data *
self.bbox_stds[:, np.newaxis])
net.params['bbox_pred/h5'][1].data[...] = \
(net.params['bbox_pred/h5'][1].data *
self.bbox_stds + self.bbox_means)

infix = ('_' + cfg.TRAIN.SNAPSHOT_INFIX
if cfg.TRAIN.SNAPSHOT_INFIX != '' else '')
Expand All @@ -113,16 +72,7 @@ def snapshot(self):
net.save(str(filename))
print 'Wrote snapshot to: {:s}'.format(filename)

if scale_bbox_params:
# restore net to original state
net.params['bbox_pred/h2'][0].data[...] = orig_0_h2
net.params['bbox_pred/h2'][1].data[...] = orig_1_h2
net.params['bbox_pred/h3'][0].data[...] = orig_0_h3
net.params['bbox_pred/h3'][1].data[...] = orig_1_h3
net.params['bbox_pred/h4'][0].data[...] = orig_0_h4
net.params['bbox_pred/h4'][1].data[...] = orig_1_h4
net.params['bbox_pred/h5'][0].data[...] = orig_0_h5
net.params['bbox_pred/h5'][1].data[...] = orig_1_h5

return filename

def train_model(self, max_iters):
Expand Down
93 changes: 93 additions & 0 deletions lib/rpn/as_rois_mrcnn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# --------------------------------------------------------
# Faster R-CNN
# Copyright (c) 2015 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# Written by Ross Girshick and Sean Bell
# --------------------------------------------------------

import caffe
import yaml
import numpy as np
import numpy.random as npr
from fast_rcnn.config import cfg
from fast_rcnn.bbox_transform import bbox_transform
from utils.cython_bbox import bbox_overlaps

DEBUG = False

class As_rois_MergeRcnnLayer(caffe.Layer):
"""
Assign object detection proposals to ground-truth targets. Produces proposal
classification labels and bounding-box regression targets.
"""

def setup(self, bottom, top):
layer_params = yaml.load(self.param_str_)
self._batch_rois = cfg.TEST.RPN_POST_NMS_TOP_N

# sampled rois (0, x1, y1, x2, y2)
top[0].reshape(1, 5)
top[1].reshape(1, 5)
top[2].reshape(1, 5)
top[3].reshape(1, 5)
top[4].reshape(1, 5)

def forward(self, bottom, top):
# Proposal ROIs (0, x1, y1, x2, y2) coming from RPN
# (i.e., rpn.proposal_layer.ProposalLayer), or any other source
rois = bottom[0].data
w = (rois[:,3]-rois[:,1])
h = (rois[:,4]-rois[:,2])
s = w * h
k0 =4
s[s<=0]=1e-6
layer_indexs = np.floor(k0+np.log2(np.sqrt(s)/224))

layer_indexs[layer_indexs<2]=2
layer_indexs[layer_indexs>5]=5

rois_all =[]

for i in range(4):
index = (layer_indexs == (i + 2))
num_index = sum(index)
if num_index == 0:
rois_ = np.zeros((1*4, 5), dtype=rois.dtype)
else:
rois_ = rois[index, :]
rois_all.append(rois_)


rois = np.concatenate(rois_all,axis= 0)
rois_p2 = rois_all[0]
rois_p3 = rois_all[1]
rois_p4 = rois_all[2]
rois_p5 = rois_all[3]

top[0].reshape(*rois.shape)
top[0].data[...] = rois

top[1].reshape(*rois_p2.shape)
top[1].data[...] = rois_p2

top[2].reshape(*rois_p3.shape)
top[2].data[...] = rois_p3

top[3].reshape(*rois_p4.shape)
top[3].data[...] = rois_p4

top[4].reshape(*rois_p5.shape)
top[4].data[...] = rois_p5



def backward(self, top, propagate_down, bottom):
"""This layer does not propagate gradients."""
pass

def reshape(self, bottom, top):
"""Reshaping happens during the call to forward."""
pass



Loading

0 comments on commit 245b8ef

Please sign in to comment.