From 78c29fca89bd903a0dc6cf80866d4df6e77039eb Mon Sep 17 00:00:00 2001 From: daquexian Date: Tue, 17 Apr 2018 04:13:39 +0000 Subject: [PATCH] Support fpn --- detectron/modeling/FPN.py | 2 +- tools/convert_pkl_to_pb.py | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/detectron/modeling/FPN.py b/detectron/modeling/FPN.py index 46881e497..21f68133f 100644 --- a/detectron/modeling/FPN.py +++ b/detectron/modeling/FPN.py @@ -293,7 +293,7 @@ def add_topdown_lateral_module( bias_init=const_fill(0.0) ) # Top-down 2x upsampling - td = model.net.UpsampleNearest(fpn_top, fpn_bottom + '_topdown', scale=2) + td = model.net.ResizeNearest(fpn_top, fpn_bottom + '_topdown', width_scale=2., height_scale=2.) # Sum lateral and top-down model.net.Sum([lat, td], fpn_bottom) diff --git a/tools/convert_pkl_to_pb.py b/tools/convert_pkl_to_pb.py index e6146f4cf..f90740046 100644 --- a/tools/convert_pkl_to_pb.py +++ b/tools/convert_pkl_to_pb.py @@ -172,10 +172,17 @@ def convert_gen_proposals( spatial_scale = mutils.get_op_arg_valf(op, 'spatial_scale', None) assert spatial_scale is not None + lvl = int(op.input[0][-1]) if op.input[0][-1].isdigit() else None + inputs = [x for x in op.input] - anchor_name = 'anchor' + anchor_name = 'anchor{}'.format(lvl) if lvl else 'anchor' inputs.append(anchor_name) - blobs[anchor_name] = get_anchors(spatial_scale) + blobs[anchor_name] = \ + get_anchors( + spatial_scale, + (cfg.FPN.RPN_ANCHOR_START_SIZE * 2.**(lvl - cfg.FPN.RPN_MIN_LEVEL),) + ) \ + if lvl else get_anchors(spatial_scale, cfg.RPN.SIZES) print('anchors {}'.format(blobs[anchor_name])) ret = core.CreateOperator( @@ -192,10 +199,10 @@ def convert_gen_proposals( return ret, anchor_name -def get_anchors(spatial_scale): +def get_anchors(spatial_scale, anchor_sizes): anchors = generate_anchors.generate_anchors( stride=1. / spatial_scale, - sizes=cfg.RPN.SIZES, + sizes=anchor_sizes, aspect_ratios=cfg.RPN.ASPECT_RATIOS).astype(np.float32) return anchors