Skip to content

Commit 88c6583

Browse files
committed
1. Fix batch_size to 1
2. Specify the rpn channel size in cfg. Merge commit 'b2a31d9923e5a459fdb6d8c9552290e6d8939600' * commit 'b2a31d9923e5a459fdb6d8c9552290e6d8939600': Update config.py remove batch size. Update minibatch.py remove batch size. # Conflicts: # lib/model/test.py # lib/nets/network.py # lib/nets/resnet_v1.py # lib/nets/vgg16.py # tools/convert_from_depre.py
2 parents 0a73203 + b2a31d9 commit 88c6583

File tree

13 files changed

+37
-33
lines changed

13 files changed

+37
-33
lines changed

lib/layer_utils/anchor_target_layer.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ def anchor_target_layer(rpn_cls_score, gt_boxes, im_info, _feat_stride, all_anch
2121
A = num_anchors
2222
total_anchors = all_anchors.shape[0]
2323
K = total_anchors / num_anchors
24-
im_info = im_info[0]
2524

2625
# allow boxes to sit over the edge by a small amount
2726
_allowed_border = 0

lib/layer_utils/proposal_layer.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ def proposal_layer(rpn_cls_prob, rpn_bbox_pred, im_info, cfg_key, _feat_stride,
2626
post_nms_topN = cfg[cfg_key].RPN_POST_NMS_TOP_N
2727
nms_thresh = cfg[cfg_key].RPN_NMS_THRESH
2828

29-
im_info = im_info[0]
3029
# Get the scores and bounding boxes
3130
scores = rpn_cls_prob[:, :, :, num_anchors:]
3231
rpn_bbox_pred = rpn_bbox_pred.view((-1, 4))

lib/layer_utils/proposal_top_layer.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ def proposal_top_layer(rpn_cls_prob, rpn_bbox_pred, im_info, _feat_stride, ancho
2020
For details please see the technical report
2121
"""
2222
rpn_top_n = cfg.TEST.RPN_TOP_N
23-
im_info = im_info[0]
2423

2524
scores = rpn_cls_prob[:, :, :, num_anchors:]
2625

lib/model/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,9 @@
281281
# Anchor ratios for RPN
282282
__C.ANCHOR_RATIOS = [0.5,1,2]
283283

284+
# Number of filters for the RPN layer
285+
__C.RPN_CHANNELS = 512
286+
284287

285288
def get_output_dir(imdb, weights_filename):
286289
"""Return the directory where experimental artifacts are placed.

lib/model/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def im_detect(net, im):
9090
assert len(im_scales) == 1, "Only single-image batch implemented"
9191

9292
im_blob = blobs['data']
93-
blobs['im_info'] = np.array([[im_blob.shape[1], im_blob.shape[2], im_scales[0]]], dtype=np.float32)
93+
blobs['im_info'] = np.array([im_blob.shape[1], im_blob.shape[2], im_scales[0]], dtype=np.float32)
9494

9595
_, scores, bbox_pred, rois = net.test_image(blobs['data'], blobs['im_info'])
9696

lib/model/train_val.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def train_model(self, max_iters):
249249
blobs = self.data_layer.forward()
250250

251251
now = time.time()
252-
if now - last_summary_time > cfg.TRAIN.SUMMARY_INTERVAL:
252+
if iter == 1 or now - last_summary_time > cfg.TRAIN.SUMMARY_INTERVAL:
253253
# Compute the graph with summary
254254
rpn_loss_cls, rpn_loss_box, loss_cls, loss_box, total_loss, summary = \
255255
self.net.train_step_with_summary(blobs, self.optimizer)

lib/nets/mobilenet_v1.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,7 @@ def mobilenet_v1_base(inputs,
173173

174174
# Modified arg_scope to incorporate configs
175175
def mobilenet_v1_arg_scope(is_training=True,
176-
weight_decay=cfg.MOBILENET.WEIGHT_DECAY,
177-
stddev=0.09,
178-
regularize_depthwise=cfg.MOBILENET.REGU_DEPTH):
176+
stddev=0.09):
179177
batch_norm_params = {
180178
'is_training': False,
181179
'center': True,
@@ -187,8 +185,8 @@ def mobilenet_v1_arg_scope(is_training=True,
187185

188186
# Set weight_decay for weights in Conv and DepthSepConv layers.
189187
weights_init = tf.truncated_normal_initializer(stddev=stddev)
190-
regularizer = tf.contrib.layers.l2_regularizer(weight_decay)
191-
if regularize_depthwise:
188+
regularizer = tf.contrib.layers.l2_regularizer(cfg.MOBILENET.WEIGHT_DECAY)
189+
if cfg.MOBILENET.REGU_DEPTH:
192190
depthwise_regularizer = regularizer
193191
else:
194192
depthwise_regularizer = None
@@ -206,8 +204,10 @@ def mobilenet_v1_arg_scope(is_training=True,
206204
return sc
207205

208206
class mobilenetv1(Network):
209-
def __init__(self, batch_size=1):
210-
Network.__init__(self, batch_size=batch_size)
207+
def __init__(self):
208+
Network.__init__(self)
209+
self._feat_stride = [16, ]
210+
self._feat_compress = [1. / float(self._feat_stride[0]), ]
211211
self._depth_multiplier = cfg.MOBILENET.DEPTH_MULTIPLIER
212212
self._scope = 'MobilenetV1'
213213

lib/nets/network.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,11 @@
2929

3030
import tensorboardX as tb
3131

32+
from scipy.misc import imresize
33+
3234
class Network(nn.Module):
33-
def __init__(self, batch_size=1):
35+
def __init__(self):
3436
nn.Module.__init__(self)
35-
self._feat_stride = [16, ]
36-
self._feat_compress = [1. / 16., ]
37-
self._batch_size = batch_size
3837
self._predictions = {}
3938
self._losses = {}
4039
self._anchor_targets = {}
@@ -50,8 +49,9 @@ def __init__(self, batch_size=1):
5049
def _add_gt_image(self):
5150
# add back mean
5251
image = self._image_gt_summaries['image'] + cfg.PIXEL_MEANS
52+
resized = imresize(image, self._im_info[:2] / self._im_info[2])
5353
# BGR to RGB (opencv uses BGR)
54-
self._gt_image = image[:,:,:,::-1].copy(order='C')
54+
self._gt_image = image[:,:,::-1].copy(order='C')
5555

5656
def _add_gt_image_summary(self):
5757
# use a customized visualization function to visualize the boxes

lib/nets/resnet_v1.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,10 @@ def resnet152(pretrained=False):
206206
return model
207207

208208
class resnetv1(Network):
209-
def __init__(self, batch_size=1, num_layers=50):
210-
Network.__init__(self, batch_size=batch_size)
209+
def __init__(self, num_layers=50):
210+
Network.__init__(self)
211+
self._feat_stride = [16, ]
212+
self._feat_compress = [1. / float(self._feat_stride[0]), ]
211213
self._num_layers = num_layers
212214

213215
def _crop_pool_layer(self, bottom, rois):

lib/nets/vgg16.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
import torchvision.models as models
1919

2020
class vgg16(Network):
21-
def __init__(self, batch_size=1):
22-
Network.__init__(self, batch_size=batch_size)
21+
def __init__(self):
22+
Network.__init__(self)
23+
self._feat_stride = [16, ]
24+
self._feat_compress = [1. / float(self._feat_stride[0]), ]
2325

2426
def _init_modules(self):
2527
self.vgg = models.vgg16()

lib/roi_data_layer/minibatch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def get_minibatch(roidb, num_classes):
4646
gt_boxes[:, 4] = roidb[0]['gt_classes'][gt_inds]
4747
blobs['gt_boxes'] = gt_boxes
4848
blobs['im_info'] = np.array(
49-
[[im_blob.shape[1], im_blob.shape[2], im_scales[0]]],
49+
[im_blob.shape[1], im_blob.shape[2], im_scales[0]],
5050
dtype=np.float32)
5151

5252
return blobs

tools/test_net.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def parse_args():
7171
pprint.pprint(cfg)
7272

7373
# if has model, get the name from it
74-
# if does not, then just use the inialization weights
74+
# if does not, then just use the initialization weights
7575
if args.model:
7676
filename = os.path.splitext(os.path.basename(args.model))[0]
7777
else:
@@ -86,15 +86,15 @@ def parse_args():
8686

8787
# load network
8888
if args.net == 'vgg16':
89-
net = vgg16(batch_size=1)
89+
net = vgg16()
9090
elif args.net == 'res50':
91-
net = resnetv1(batch_size=1, num_layers=50)
91+
net = resnetv1(num_layers=50)
9292
elif args.net == 'res101':
93-
net = resnetv1(batch_size=1, num_layers=101)
93+
net = resnetv1(num_layers=101)
9494
elif args.net == 'res152':
95-
net = resnetv1(batch_size=1, num_layers=152)
95+
net = resnetv1(num_layers=152)
9696
elif args.net == 'mobile':
97-
net = mobilenetv1(batch_size=1)
97+
net = mobilenetv1()
9898
else:
9999
raise NotImplementedError
100100

tools/trainval_net.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,15 @@ def get_roidb(imdb_name):
121121

122122
# load network
123123
if args.net == 'vgg16':
124-
net = vgg16(batch_size=cfg.TRAIN.IMS_PER_BATCH)
124+
net = vgg16()
125125
elif args.net == 'res50':
126-
net = resnetv1(batch_size=cfg.TRAIN.IMS_PER_BATCH, num_layers=50)
126+
net = resnetv1(num_layers=50)
127127
elif args.net == 'res101':
128-
net = resnetv1(batch_size=cfg.TRAIN.IMS_PER_BATCH, num_layers=101)
128+
net = resnetv1(num_layers=101)
129129
elif args.net == 'res152':
130-
net = resnetv1(batch_size=cfg.TRAIN.IMS_PER_BATCH, num_layers=152)
130+
net = resnetv1(num_layers=152)
131131
elif args.net == 'mobile':
132-
net = mobilenetv1(batch_size=cfg.TRAIN.IMS_PER_BATCH)
132+
net = mobilenetv1()
133133
else:
134134
raise NotImplementedError
135135

0 commit comments

Comments
 (0)