Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Py Faster RCNN Caffe Fix
diff --git a/caffe-fast-rcnn b/caffe-fast-rcnn
index 0dcd397..cdddca3 160000
--- a/caffe-fast-rcnn
+++ b/caffe-fast-rcnn
@@ -1 +1 @@
-Subproject commit 0dcd397b29507b8314e252e850518c5695efbb83
+Subproject commit cdddca3ad7967dbd80cc660b45fd4347c60e380e-dirty
diff --git a/lib/datasets/factory.py b/lib/datasets/factory.py
index 8c3fdb8..56dd3f5 100644
--- a/lib/datasets/factory.py
+++ b/lib/datasets/factory.py
@@ -31,6 +31,12 @@ for year in ['2015']:
name = 'coco_{}_{}'.format(year, split)
__sets[name] = (lambda split=split, year=year: coco(split, year))
+from datasets.basketball import basketball
+basketball_devkit_path = './data/basketball'
+for split in ['train', 'val']:
+ name = '{}_{}'.format('basketball', split)
+ __sets[name] = (lambda split=split: basketball(split, basketball_devkit_path))
+
def get_imdb(name):
"""Get an imdb (image database) by name."""
if not __sets.has_key(name):
diff --git a/lib/datasets/imdb.py b/lib/datasets/imdb.py
index b56bf0a..e576825 100644
--- a/lib/datasets/imdb.py
+++ b/lib/datasets/imdb.py
@@ -99,6 +99,25 @@ class imdb(object):
return [PIL.Image.open(self.image_path_at(i)).size[0]
for i in xrange(self.num_images)]
+ # MATLAB Data - Index Starts at 1
+ # def append_flipped_images(self):
+ # num_images = self.num_images
+ # widths = self._get_widths()
+ # for i in xrange(num_images):
+ # boxes = self.roidb[i]['boxes'].copy()
+ # oldx1 = boxes[:, 0].copy()
+ # oldx2 = boxes[:, 2].copy()
+ # boxes[:, 0] = widths[i] - oldx2 - 1
+ # boxes[:, 2] = widths[i] - oldx1 - 1
+ # assert (boxes[:, 2] >= boxes[:, 0]).all()
+ # entry = {'boxes' : boxes,
+ # 'gt_overlaps' : self.roidb[i]['gt_overlaps'],
+ # 'gt_classes' : self.roidb[i]['gt_classes'],
+ # 'flipped' : True}
+ # self.roidb.append(entry)
+ # self._image_index = self._image_index * 2
+
+ # Python Data - Index Starts at 0
def append_flipped_images(self):
num_images = self.num_images
widths = self._get_widths()
@@ -106,8 +125,11 @@ class imdb(object):
boxes = self.roidb[i]['boxes'].copy()
oldx1 = boxes[:, 0].copy()
oldx2 = boxes[:, 2].copy()
- boxes[:, 0] = widths[i] - oldx2 - 1
- boxes[:, 2] = widths[i] - oldx1 - 1
+ boxes[:, 0] = widths[i] - oldx2
+ boxes[:, 2] = widths[i] - oldx1
+ for b in range(len(boxes)):
+ if boxes[b][2] < boxes[b][0]:
+ boxes[b][0]=0
assert (boxes[:, 2] >= boxes[:, 0]).all()
entry = {'boxes' : boxes,
'gt_overlaps' : self.roidb[i]['gt_overlaps'],
diff --git a/lib/roi_data_layer/layer.py b/lib/roi_data_layer/layer.py
index 9f145fe..04f4172 100644
--- a/lib/roi_data_layer/layer.py
+++ b/lib/roi_data_layer/layer.py
@@ -84,7 +84,7 @@ class RoIDataLayer(caffe.Layer):
"""Setup the RoIDataLayer."""
# parse the layer parameter string, which must be valid YAML
- layer_params = yaml.load(self.param_str_)
+ layer_params = yaml.load(self.param_str)
self._num_classes = layer_params['num_classes']
diff --git a/lib/rpn/anchor_target_layer.py b/lib/rpn/anchor_target_layer.py
index 4563df1..3934cdd 100644
--- a/lib/rpn/anchor_target_layer.py
+++ b/lib/rpn/anchor_target_layer.py
@@ -24,7 +24,7 @@ class AnchorTargetLayer(caffe.Layer):
"""
def setup(self, bottom, top):
- layer_params = yaml.load(self.param_str_)
+ layer_params = yaml.load(self.param_str)
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]
diff --git a/lib/rpn/proposal_layer.py b/lib/rpn/proposal_layer.py
index b157160..6fd2fb9 100644
--- a/lib/rpn/proposal_layer.py
+++ b/lib/rpn/proposal_layer.py
@@ -23,7 +23,7 @@ class ProposalLayer(caffe.Layer):
def setup(self, bottom, top):
# parse the layer parameter string, which must be valid YAML
- layer_params = yaml.load(self.param_str_)
+ layer_params = yaml.load(self.param_str)
self._feat_stride = layer_params['feat_stride']
anchor_scales = layer_params.get('scales', (8, 16, 32))
@@ -61,7 +61,7 @@ class ProposalLayer(caffe.Layer):
assert bottom[0].data.shape[0] == 1, \
'Only single item batches are supported'
- cfg_key = str(self.phase) # either 'TRAIN' or 'TEST'
+ cfg_key = 'TEST' if self.phase == 1 else 'TRAIN'
pre_nms_topN = cfg[cfg_key].RPN_PRE_NMS_TOP_N
post_nms_topN = cfg[cfg_key].RPN_POST_NMS_TOP_N
nms_thresh = cfg[cfg_key].RPN_NMS_THRESH
diff --git a/lib/rpn/proposal_target_layer.py b/lib/rpn/proposal_target_layer.py
index 38e1f2c..89f2c6e 100644
--- a/lib/rpn/proposal_target_layer.py
+++ b/lib/rpn/proposal_target_layer.py
@@ -22,7 +22,7 @@ class ProposalTargetLayer(caffe.Layer):
"""
def setup(self, bottom, top):
- layer_params = yaml.load(self.param_str_)
+ layer_params = yaml.load(self.param_str)
self._num_classes = layer_params['num_classes']
# sampled rois (0, x1, y1, x2, y2)
diff --git a/tools/demo.py b/tools/demo.py
index 631c68a..6e3f149 100755
--- a/tools/demo.py
+++ b/tools/demo.py
@@ -24,17 +24,23 @@ import scipy.io as sio
import caffe, os, sys, cv2
import argparse
+# CLASSES = ('__background__',
+# 'aeroplane', 'bicycle', 'bird', 'boat',
+# 'bottle', 'bus', 'car', 'cat', 'chair',
+# 'cow', 'diningtable', 'dog', 'horse',
+# 'motorbike', 'person', 'pottedplant',
+# 'sheep', 'sofa', 'train', 'tvmonitor')
+
CLASSES = ('__background__',
- 'aeroplane', 'bicycle', 'bird', 'boat',
- 'bottle', 'bus', 'car', 'cat', 'chair',
- 'cow', 'diningtable', 'dog', 'horse',
- 'motorbike', 'person', 'pottedplant',
- 'sheep', 'sofa', 'train', 'tvmonitor')
+ 'n02802426')
NETS = {'vgg16': ('VGG16',
'VGG16_faster_rcnn_final.caffemodel'),
'zf': ('ZF',
- 'ZF_faster_rcnn_final.caffemodel')}
+ 'ZF_faster_rcnn_final.caffemodel'),
+ 'basketball': ('Basketball',
+ 'zf_faster_rcnn_basketball.caffemodel')
+ }
def vis_detections(im, class_name, dets, thresh=0.5):
@@ -117,11 +123,19 @@ if __name__ == '__main__':
args = parse_args()
- prototxt = os.path.join(cfg.MODELS_DIR, NETS[args.demo_net][0],
- 'faster_rcnn_alt_opt', 'faster_rcnn_test.pt')
+ # prototxt = os.path.join(cfg.MODELS_DIR, NETS[args.demo_net][0],
+ # 'faster_rcnn_alt_opt', 'faster_rcnn_test.pt')
+ # caffemodel = os.path.join(cfg.DATA_DIR, 'faster_rcnn_models',
+ # NETS[args.demo_net][1])
+
+ args.demo_net = "basketball"
+ prototxt = "/home/ac2vision/py-faster-rcnn/models/basketball/test.prototxt"
caffemodel = os.path.join(cfg.DATA_DIR, 'faster_rcnn_models',
NETS[args.demo_net][1])
+ print prototxt
+ print caffemodel
+
if not os.path.isfile(caffemodel):
raise IOError(('{:s} not found.\nDid you run ./data/script/'
'fetch_faster_rcnn_models.sh?').format(caffemodel))
@@ -141,8 +155,9 @@ if __name__ == '__main__':
for i in xrange(2):
_, _= im_detect(net, im)
- im_names = ['000456.jpg', '000542.jpg', '001150.jpg',
- '001763.jpg', '004545.jpg']
+ # im_names = ['000456.jpg', '000542.jpg', '001150.jpg',
+ # '001763.jpg', '004545.jpg']
+ im_names = ['bb.jpg']
for im_name in im_names:
print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
print 'Demo for data/demo/{}'.format(im_name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment