Skip to content

Commit

Permalink
fix coco training issues
Browse files Browse the repository at this point in the history
  • Loading branch information
YuwenXiong committed Nov 8, 2016
1 parent 4e35411 commit 91741f2
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.ipynb_checkpoints
.idea
lib/build
lib/pycocotools/_mask.c
lib/pycocotools/_mask.so
Expand Down
8 changes: 5 additions & 3 deletions lib/rpn/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def imdb_proposals(net, imdb):
def imdb_rpn_compute_stats(net, imdb, anchor_scales=(8,16,32),
feature_stride=16):
raw_anchors = generate_anchors(scales=np.array(anchor_scales))

print raw_anchors.shape
sums = 0
squred_sums = 0
counts = 0
Expand All @@ -146,10 +146,10 @@ def imdb_rpn_compute_stats(net, imdb, anchor_scales=(8,16,32),
map_w[i] = width
map_h[i] = height

for i in xrange(imdb.num_images):
for i in xrange(len(roidb)):
if not i % 5000:
print 'computing %d/%d' % (i, imdb.num_images)
im = cv2.imread(imdb.image_path_at(i))
im = cv2.imread(roidb[i]['image'])
im_data, im_info = _get_image_blob(im)
gt_boxes = roidb[i]['boxes']
gt_boxes = gt_boxes * im_info[0, 2]
Expand Down Expand Up @@ -208,4 +208,6 @@ def imdb_rpn_compute_stats(net, imdb, anchor_scales=(8,16,32),

means = sums / counts
stds = np.sqrt(squred_sums / counts - means ** 2)
print means
print stds
return means, stds
6 changes: 3 additions & 3 deletions models/coco/ResNet-101/rfcn_alt_opt_5step_ohem/rpn_test.pt
Original file line number Diff line number Diff line change
Expand Up @@ -6292,7 +6292,7 @@ layer {
param { lr_mult: 1.0 }
param { lr_mult: 2.0 }
convolution_param {
num_output: 18 # 2(bg/fg) * 9(anchors)
num_output: 24 # 2(bg/fg) * 12(anchors)
kernel_size: 1 pad: 0 stride: 1
weight_filler { type: "gaussian" std: 0.01 }
bias_filler { type: "constant" value: 0 }
Expand All @@ -6306,7 +6306,7 @@ layer {
param { lr_mult: 1.0 }
param { lr_mult: 2.0 }
convolution_param {
num_output: 36 # 4 * 9(anchors)
num_output: 48 # 4 * 12(anchors)
kernel_size: 1 pad: 0 stride: 1
weight_filler { type: "gaussian" std: 0.01 }
bias_filler { type: "constant" value: 0 }
Expand Down Expand Up @@ -6334,7 +6334,7 @@ layer {
type: 'Reshape'
bottom: 'rpn_cls_prob'
top: 'rpn_cls_prob_reshape'
reshape_param { shape { dim: 0 dim: 18 dim: -1 dim: 0 } }
reshape_param { shape { dim: 0 dim: 24 dim: -1 dim: 0 } }
}
layer {
name: 'proposal'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6292,7 +6292,7 @@ layer {
param { lr_mult: 1.0 }
param { lr_mult: 2.0 }
convolution_param {
num_output: 18 # 2(bg/fg) * 9(anchors)
num_output: 24 # 2(bg/fg) * 12(anchors)
kernel_size: 1 pad: 0 stride: 1
weight_filler { type: "gaussian" std: 0.01 }
bias_filler { type: "constant" value: 0 }
Expand All @@ -6306,7 +6306,7 @@ layer {
param { lr_mult: 1.0 }
param { lr_mult: 2.0 }
convolution_param {
num_output: 36 # 4 * 9(anchors)
num_output: 48 # 4 * 12(anchors)
kernel_size: 1 pad: 0 stride: 1
weight_filler { type: "gaussian" std: 0.01 }
bias_filler { type: "constant" value: 0 }
Expand All @@ -6333,7 +6333,7 @@ layer {
python_param {
module: 'rpn.anchor_target_layer'
layer: 'AnchorTargetLayer'
param_str: "'feat_stride': 16"
param_str: "'feat_stride': 16 \n'scales': !!python/tuple [4, 8, 16, 32]"
}
}
layer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6292,7 +6292,7 @@ layer {
param { lr_mult: 1.0 }
param { lr_mult: 2.0 }
convolution_param {
num_output: 18 # 2(bg/fg) * 9(anchors)
num_output: 24 # 2(bg/fg) * 12(anchors)
kernel_size: 1 pad: 0 stride: 1
weight_filler { type: "gaussian" std: 0.01 }
bias_filler { type: "constant" value: 0 }
Expand All @@ -6306,7 +6306,7 @@ layer {
param { lr_mult: 1.0 }
param { lr_mult: 2.0 }
convolution_param {
num_output: 36 # 4 * 9(anchors)
num_output: 48 # 4 * 12(anchors)
kernel_size: 1 pad: 0 stride: 1
weight_filler { type: "gaussian" std: 0.01 }
bias_filler { type: "constant" value: 0 }
Expand All @@ -6333,7 +6333,7 @@ layer {
python_param {
module: 'rpn.anchor_target_layer'
layer: 'AnchorTargetLayer'
param_str: "'feat_stride': 16"
param_str: "'feat_stride': 16 \n'scales': !!python/tuple [4, 8, 16, 32]"
}
}
layer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6292,7 +6292,7 @@ layer {
param { lr_mult: 1.0 }
param { lr_mult: 2.0 }
convolution_param {
num_output: 18 # 2(bg/fg) * 9(anchors)
num_output: 24 # 2(bg/fg) * 12(anchors)
kernel_size: 1 pad: 0 stride: 1
weight_filler { type: "gaussian" std: 0.01 }
bias_filler { type: "constant" value: 0 }
Expand All @@ -6306,7 +6306,7 @@ layer {
param { lr_mult: 1.0 }
param { lr_mult: 2.0 }
convolution_param {
num_output: 36 # 4 * 9(anchors)
num_output: 48 # 4 * 12(anchors)
kernel_size: 1 pad: 0 stride: 1
weight_filler { type: "gaussian" std: 0.01 }
bias_filler { type: "constant" value: 0 }
Expand All @@ -6333,7 +6333,7 @@ layer {
python_param {
module: 'rpn.anchor_target_layer'
layer: 'AnchorTargetLayer'
param_str: "'feat_stride': 16"
param_str: "'feat_stride': 16 \n'scales': !!python/tuple [4, 8, 16, 32]"
}
}
layer {
Expand Down
8 changes: 4 additions & 4 deletions models/coco/ResNet-101/rfcn_end2end/test_agnostic.prototxt
Original file line number Diff line number Diff line change
Expand Up @@ -6954,7 +6954,7 @@ layer {
param { lr_mult: 1.0 decay_mult: 1.0 }
param { lr_mult: 2.0 decay_mult: 0 }
convolution_param {
num_output: 18 # 2(bg/fg) * 9(anchors)
num_output: 24 # 2(bg/fg) * 12(anchors)
kernel_size: 1 pad: 0 stride: 1
weight_filler { type: "gaussian" std: 0.01 }
bias_filler { type: "constant" value: 0 }
Expand All @@ -6968,7 +6968,7 @@ layer {
param { lr_mult: 1.0 decay_mult: 1.0 }
param { lr_mult: 2.0 decay_mult: 0 }
convolution_param {
num_output: 36 # 4 * 9(anchors)
num_output: 48 # 4 * 12(anchors)
kernel_size: 1 pad: 0 stride: 1
weight_filler { type: "gaussian" std: 0.01 }
bias_filler { type: "constant" value: 0 }
Expand All @@ -6995,7 +6995,7 @@ layer {
type: 'Reshape'
bottom: 'rpn_cls_prob'
top: 'rpn_cls_prob_reshape'
reshape_param { shape { dim: 0 dim: 18 dim: -1 dim: 0 } }
reshape_param { shape { dim: 0 dim: 24 dim: -1 dim: 0 } }
}
layer {
name: 'proposal'
Expand All @@ -7007,7 +7007,7 @@ layer {
python_param {
module: 'rpn.proposal_layer'
layer: 'ProposalLayer'
param_str: "'feat_stride': 16"
param_str: "'feat_stride': 16 \n'scales': !!python/tuple [4, 8, 16, 32]"
}
}

Expand Down
10 changes: 5 additions & 5 deletions models/coco/ResNet-101/rfcn_end2end/train_agnostic.prototxt
Original file line number Diff line number Diff line change
Expand Up @@ -6952,7 +6952,7 @@ layer {
param { lr_mult: 1.0 }
param { lr_mult: 2.0 }
convolution_param {
num_output: 18 # 2(bg/fg) * 9(anchors)
num_output: 24 # 2(bg/fg) * 12(anchors)
kernel_size: 1 pad: 0 stride: 1
weight_filler { type: "gaussian" std: 0.01 }
bias_filler { type: "constant" value: 0 }
Expand All @@ -6967,7 +6967,7 @@ layer {
param { lr_mult: 1.0 }
param { lr_mult: 2.0 }
convolution_param {
num_output: 36 # 4 * 9(anchors)
num_output: 48 # 4 * 12(anchors)
kernel_size: 1 pad: 0 stride: 1
weight_filler { type: "gaussian" std: 0.01 }
bias_filler { type: "constant" value: 0 }
Expand Down Expand Up @@ -6996,7 +6996,7 @@ layer {
python_param {
module: 'rpn.anchor_target_layer'
layer: 'AnchorTargetLayer'
param_str: "'feat_stride': 16"
param_str: "'feat_stride': 16 \n'scales': !!python/tuple [4, 8, 16, 32]"
}
}

Expand Down Expand Up @@ -7041,7 +7041,7 @@ layer {
type: 'Reshape'
bottom: 'rpn_cls_prob'
top: 'rpn_cls_prob_reshape'
reshape_param { shape { dim: 0 dim: 18 dim: -1 dim: 0 } }
reshape_param { shape { dim: 0 dim: 24 dim: -1 dim: 0 } }
}

layer {
Expand All @@ -7055,7 +7055,7 @@ layer {
python_param {
module: 'rpn.proposal_layer'
layer: 'ProposalLayer'
param_str: "'feat_stride': 16"
param_str: "'feat_stride': 16 \n'scales': !!python/tuple [4, 8, 16, 32]"
}
}

Expand Down
10 changes: 5 additions & 5 deletions models/coco/ResNet-101/rfcn_end2end/train_agnostic_ohem.prototxt
Original file line number Diff line number Diff line change
Expand Up @@ -6953,7 +6953,7 @@ layer {
param { lr_mult: 1.0 }
param { lr_mult: 2.0 }
convolution_param {
num_output: 18 # 2(bg/fg) * 9(anchors)
num_output: 24 # 2(bg/fg) * 12(anchors)
kernel_size: 1 pad: 0 stride: 1
weight_filler { type: "gaussian" std: 0.01 }
bias_filler { type: "constant" value: 0 }
Expand All @@ -6968,7 +6968,7 @@ layer {
param { lr_mult: 1.0 }
param { lr_mult: 2.0 }
convolution_param {
num_output: 36 # 4 * 9(anchors)
num_output: 48 # 4 * 12(anchors)
kernel_size: 1 pad: 0 stride: 1
weight_filler { type: "gaussian" std: 0.01 }
bias_filler { type: "constant" value: 0 }
Expand Down Expand Up @@ -6997,7 +6997,7 @@ layer {
python_param {
module: 'rpn.anchor_target_layer'
layer: 'AnchorTargetLayer'
param_str: "'feat_stride': 16"
param_str: "'feat_stride': 16 \n'scales': !!python/tuple [4, 8, 16, 32]"
}
}

Expand Down Expand Up @@ -7042,7 +7042,7 @@ layer {
type: 'Reshape'
bottom: 'rpn_cls_prob'
top: 'rpn_cls_prob_reshape'
reshape_param { shape { dim: 0 dim: 18 dim: -1 dim: 0 } }
reshape_param { shape { dim: 0 dim: 24 dim: -1 dim: 0 } }
}

layer {
Expand All @@ -7056,7 +7056,7 @@ layer {
python_param {
module: 'rpn.proposal_layer'
layer: 'ProposalLayer'
param_str: "'feat_stride': 16"
param_str: "'feat_stride': 16 \n'scales': !!python/tuple [4, 8, 16, 32]"
}
}

Expand Down
7 changes: 5 additions & 2 deletions tools/train_rfcn_alt_opt_5stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def get_solvers(imdb_name, net_name, model_name):
[net_name, model_name, 'stage2_rpn_solver360k480k.pt'],
[net_name, model_name, 'stage2_rfcn_ohem_solver360k480k.pt'],
[net_name, model_name, 'stage3_rpn_solver360k480k.pt']]
solvers = [os.path.join(cfg.MODELS_DIR, *s) for s in solvers]
solvers = [os.path.join('.', 'models', 'coco', *s) for s in solvers]
# Iterations for each training stage
max_iters = [480000, 480000, 480000, 480000, 480000]
else:
Expand Down Expand Up @@ -257,7 +257,10 @@ def rpn_compute_stats(queue=None, imdb_name=None, cfg=None, rpn_test_prototxt=No
rpn_net = caffe.Net(rpn_test_prototxt, caffe.TEST)
# Generate proposals on the imdb
print 'start computing means/stds, it may take several minutes...'
means, stds = imdb_rpn_compute_stats(rpn_net, imdb)
if imdb_name.startswith('coco'):
means, stds = imdb_rpn_compute_stats(rpn_net, imdb, anchor_scales=(4, 8, 16, 32))
else:
means, stds = imdb_rpn_compute_stats(rpn_net, imdb, anchor_scales=(8, 16, 32))
np.save(mean_file, means)
np.save(std_file, stds)
queue.put({'means': means, 'stds': stds})
Expand Down

0 comments on commit 91741f2

Please sign in to comment.