Skip to content

Commit

Permalink
FPN results
Browse files Browse the repository at this point in the history
  • Loading branch information
unsky committed Jan 4, 2018
1 parent 62f53d2 commit 46576ba
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ Feature Pyramid Network on caffe
This is the unoffical version Feature Pyramid Network for Feature Pyramid Networks for Object Detection https://arxiv.org/abs/1612.03144

# results
`FPN(resnet50) result is implemented without OHEM and train with pascal voc 2007 + 2012 test on 2007`
`FPN(resnet50)-end2end result is implemented without OHEM and train with pascal voc 2007 + 2012 test on 2007`


|[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|

|diningtable|dog |horse|motorbike|person |pottedplant|sheep|sofa|train|tv|
|----------:|:--:|:---:| -------:| -----:| -------:|----:|---:|----:|--:|

|0.7022|0.8891|0.8680| 0.7991| 0.7944| 0.5065|0.7896|0.7707|0.8697|0.7653|
# framework
![](framework.png)
`the red and yellow are shared params`
Expand Down
3 changes: 3 additions & 0 deletions lib/fast_rcnn/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@
__C.TEST.RPN_POST_NMS_TOP_N = 1000
# Proposal height and width both need to be greater than RPN_MIN_SIZE (at orig image scale)
__C.TEST.RPN_MIN_SIZE = 16
# Apply box scoring heuristics
__C.TEST.BBOX_VOTE_N_WEIGHTED_SCORE = 1
__C.TEST.BBOX_VOTE_WEIGHT_EMPTY = 0.5


#
Expand Down
40 changes: 39 additions & 1 deletion lib/fast_rcnn/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import cPickle
from utils.blob import im_list_to_blob
import os
from utils.cython_bbox import bbox_overlaps

def _get_image_blob(im):
"""Converts an image into a network input.
Expand Down Expand Up @@ -174,6 +175,42 @@ def vis_rois_detection(im_array, detections):
plt.cla()

plt. close(0)
def bbox_vote(dets_NMS, dets_all, thresh=0.5):
dets_voted = np.zeros_like(dets_NMS) # Empty matrix with the same shape and type

_overlaps = bbox_overlaps(
np.ascontiguousarray(dets_NMS[:, 0:4], dtype=np.float),
np.ascontiguousarray(dets_all[:, 0:4], dtype=np.float))

# for each survived box
for i, det in enumerate(dets_NMS):
dets_overlapped = dets_all[np.where(_overlaps[i, :] >= thresh)[0]]
assert(len(dets_overlapped) > 0)

boxes = dets_overlapped[:, 0:4]
scores = dets_overlapped[:, 4]

out_box = np.dot(scores, boxes)

dets_voted[i][0:4] = out_box / sum(scores) # Weighted bounding boxes
dets_voted[i][4] = det[4] # Keep the original score

# Weighted scores (if enabled)
if cfg.TEST.BBOX_VOTE_N_WEIGHTED_SCORE > 1:
n_agreement = cfg.TEST.BBOX_VOTE_N_WEIGHTED_SCORE
w_empty = cfg.TEST.BBOX_VOTE_WEIGHT_EMPTY

n_detected = len(scores)

if n_detected >= n_agreement:
top_scores = -np.sort(-scores)[:n_agreement]
new_score = np.average(top_scores)
else:
new_score = np.average(scores) * (n_detected * 1.0 + (n_agreement - n_detected) * w_empty) / n_agreement

dets_voted[i][4] = min(new_score, dets_voted[i][4])

return dets_voted

def im_detect(net, im, boxes=None,num_classes=21):
"""Detect object classes in an image given object proposals.
Expand Down Expand Up @@ -404,7 +441,8 @@ def test_net(net, imdb, max_per_image=100, thresh=0.05, vis=False):
.astype(np.float32, copy=False)
keep = nms(cls_dets, cfg.TEST.NMS)

cls_dets = cls_dets[keep, :]
dets_NMSed = cls_dets[keep, :]
cls_dets = bbox_vote(dets_NMSed, cls_dets)
# print cls_scores
if vis:
vis_detections(im, imdb.classes[j], cls_dets)
Expand Down

0 comments on commit 46576ba

Please sign in to comment.