|
|
@ -29,6 +29,11 @@ parser.add_argument('--aspect_ratios', default=[1.0, 2.0, 0.5, 3.0, 0.333], type |
|
|
|
help='Hyper-parameter of ssd_anchor_generator from config file.') |
|
|
|
help='Hyper-parameter of ssd_anchor_generator from config file.') |
|
|
|
parser.add_argument('--image_width', default=300, type=int, help='Training images width.') |
|
|
|
parser.add_argument('--image_width', default=300, type=int, help='Training images width.') |
|
|
|
parser.add_argument('--image_height', default=300, type=int, help='Training images height.') |
|
|
|
parser.add_argument('--image_height', default=300, type=int, help='Training images height.') |
|
|
|
|
|
|
|
parser.add_argument('--not_reduce_boxes_in_lowest_layer', default=False, action='store_true', |
|
|
|
|
|
|
|
help='A boolean to indicate whether the fixed 3 boxes per ' |
|
|
|
|
|
|
|
'location is used in the lowest achors generation layer.') |
|
|
|
|
|
|
|
parser.add_argument('--box_predictor', default='convolutional', type=str, |
|
|
|
|
|
|
|
choices=['convolutional', 'weight_shared_convolutional']) |
|
|
|
args = parser.parse_args() |
|
|
|
args = parser.parse_args() |
|
|
|
|
|
|
|
|
|
|
|
# Nodes that should be kept. |
|
|
|
# Nodes that should be kept. |
|
|
@ -194,12 +199,18 @@ def addConcatNode(name, inputs, axisNodeName): |
|
|
|
addConstNode('concat/axis_flatten', [-1]) |
|
|
|
addConstNode('concat/axis_flatten', [-1]) |
|
|
|
addConstNode('PriorBox/concat/axis', [-2]) |
|
|
|
addConstNode('PriorBox/concat/axis', [-2]) |
|
|
|
|
|
|
|
|
|
|
|
for label in ['ClassPredictor', 'BoxEncodingPredictor']: |
|
|
|
for label in ['ClassPredictor', 'BoxEncodingPredictor' if args.box_predictor is 'convolutional' else 'BoxPredictor']: |
|
|
|
concatInputs = [] |
|
|
|
concatInputs = [] |
|
|
|
for i in range(args.num_layers): |
|
|
|
for i in range(args.num_layers): |
|
|
|
# Flatten predictions |
|
|
|
# Flatten predictions |
|
|
|
flatten = NodeDef() |
|
|
|
flatten = NodeDef() |
|
|
|
|
|
|
|
if args.box_predictor is 'convolutional': |
|
|
|
inpName = 'BoxPredictor_%d/%s/BiasAdd' % (i, label) |
|
|
|
inpName = 'BoxPredictor_%d/%s/BiasAdd' % (i, label) |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
if i == 0: |
|
|
|
|
|
|
|
inpName = 'WeightSharedConvolutionalBoxPredictor/%s/BiasAdd' % label |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
inpName = 'WeightSharedConvolutionalBoxPredictor_%d/%s/BiasAdd' % (i, label) |
|
|
|
flatten.input.append(inpName) |
|
|
|
flatten.input.append(inpName) |
|
|
|
flatten.name = inpName + '/Flatten' |
|
|
|
flatten.name = inpName + '/Flatten' |
|
|
|
flatten.op = 'Flatten' |
|
|
|
flatten.op = 'Flatten' |
|
|
@ -210,7 +221,9 @@ for label in ['ClassPredictor', 'BoxEncodingPredictor']: |
|
|
|
|
|
|
|
|
|
|
|
idx = 0 |
|
|
|
idx = 0 |
|
|
|
for node in graph_def.node: |
|
|
|
for node in graph_def.node: |
|
|
|
if node.name == ('BoxPredictor_%d/BoxEncodingPredictor/Conv2D' % idx): |
|
|
|
if node.name == ('BoxPredictor_%d/BoxEncodingPredictor/Conv2D' % idx) or \ |
|
|
|
|
|
|
|
node.name == ('WeightSharedConvolutionalBoxPredictor_%d/BoxPredictor/Conv2D' % idx) or \ |
|
|
|
|
|
|
|
node.name == 'WeightSharedConvolutionalBoxPredictor/BoxPredictor/Conv2D': |
|
|
|
text_format.Merge('b: true', node.attr["loc_pred_transposed"]) |
|
|
|
text_format.Merge('b: true', node.attr["loc_pred_transposed"]) |
|
|
|
idx += 1 |
|
|
|
idx += 1 |
|
|
|
assert(idx == args.num_layers) |
|
|
|
assert(idx == args.num_layers) |
|
|
@ -224,13 +237,19 @@ for i in range(args.num_layers): |
|
|
|
priorBox = NodeDef() |
|
|
|
priorBox = NodeDef() |
|
|
|
priorBox.name = 'PriorBox_%d' % i |
|
|
|
priorBox.name = 'PriorBox_%d' % i |
|
|
|
priorBox.op = 'PriorBox' |
|
|
|
priorBox.op = 'PriorBox' |
|
|
|
|
|
|
|
if args.box_predictor is 'convolutional': |
|
|
|
priorBox.input.append('BoxPredictor_%d/BoxEncodingPredictor/BiasAdd' % i) |
|
|
|
priorBox.input.append('BoxPredictor_%d/BoxEncodingPredictor/BiasAdd' % i) |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
if i == 0: |
|
|
|
|
|
|
|
priorBox.input.append('WeightSharedConvolutionalBoxPredictor/BoxPredictor/Conv2D') |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
priorBox.input.append('WeightSharedConvolutionalBoxPredictor_%d/BoxPredictor/BiasAdd' % i) |
|
|
|
priorBox.input.append(graph_def.node[0].name) # image_tensor |
|
|
|
priorBox.input.append(graph_def.node[0].name) # image_tensor |
|
|
|
|
|
|
|
|
|
|
|
text_format.Merge('b: false', priorBox.attr["flip"]) |
|
|
|
text_format.Merge('b: false', priorBox.attr["flip"]) |
|
|
|
text_format.Merge('b: false', priorBox.attr["clip"]) |
|
|
|
text_format.Merge('b: false', priorBox.attr["clip"]) |
|
|
|
|
|
|
|
|
|
|
|
if i == 0: |
|
|
|
if i == 0 and not args.not_reduce_boxes_in_lowest_layer: |
|
|
|
widths = [0.1, args.min_scale * sqrt(2.0), args.min_scale * sqrt(0.5)] |
|
|
|
widths = [0.1, args.min_scale * sqrt(2.0), args.min_scale * sqrt(0.5)] |
|
|
|
heights = [0.1, args.min_scale / sqrt(2.0), args.min_scale / sqrt(0.5)] |
|
|
|
heights = [0.1, args.min_scale / sqrt(2.0), args.min_scale / sqrt(0.5)] |
|
|
|
else: |
|
|
|
else: |
|
|
@ -261,7 +280,10 @@ detectionOut = NodeDef() |
|
|
|
detectionOut.name = 'detection_out' |
|
|
|
detectionOut.name = 'detection_out' |
|
|
|
detectionOut.op = 'DetectionOutput' |
|
|
|
detectionOut.op = 'DetectionOutput' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if args.box_predictor == 'convolutional': |
|
|
|
detectionOut.input.append('BoxEncodingPredictor/concat') |
|
|
|
detectionOut.input.append('BoxEncodingPredictor/concat') |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
detectionOut.input.append('BoxPredictor/concat') |
|
|
|
detectionOut.input.append(sigmoid.name) |
|
|
|
detectionOut.input.append(sigmoid.name) |
|
|
|
detectionOut.input.append('PriorBox/concat') |
|
|
|
detectionOut.input.append('PriorBox/concat') |
|
|
|
|
|
|
|
|
|
|
|