mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 15:53:03 +04:00
Merge pull request #12125 from dkurt:dnn_mobilenet_ppn
This commit is contained in:
@@ -30,6 +30,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.')
|
||||
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('--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()
|
||||
|
||||
# Nodes that should be kept.
|
||||
@@ -173,12 +178,18 @@ def addConcatNode(name, inputs, axisNodeName):
|
||||
addConstNode('concat/axis_flatten', [-1])
|
||||
addConstNode('PriorBox/concat/axis', [-2])
|
||||
|
||||
for label in ['ClassPredictor', 'BoxEncodingPredictor']:
|
||||
for label in ['ClassPredictor', 'BoxEncodingPredictor' if args.box_predictor is 'convolutional' else 'BoxPredictor']:
|
||||
concatInputs = []
|
||||
for i in range(args.num_layers):
|
||||
# Flatten predictions
|
||||
flatten = NodeDef()
|
||||
inpName = 'BoxPredictor_%d/%s/BiasAdd' % (i, label)
|
||||
if args.box_predictor is 'convolutional':
|
||||
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.name = inpName + '/Flatten'
|
||||
flatten.op = 'Flatten'
|
||||
@@ -189,7 +200,9 @@ for label in ['ClassPredictor', 'BoxEncodingPredictor']:
|
||||
|
||||
idx = 0
|
||||
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"])
|
||||
idx += 1
|
||||
assert(idx == args.num_layers)
|
||||
@@ -203,13 +216,19 @@ for i in range(args.num_layers):
|
||||
priorBox = NodeDef()
|
||||
priorBox.name = 'PriorBox_%d' % i
|
||||
priorBox.op = 'PriorBox'
|
||||
priorBox.input.append('BoxPredictor_%d/BoxEncodingPredictor/BiasAdd' % i)
|
||||
if args.box_predictor is 'convolutional':
|
||||
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
|
||||
|
||||
text_format.Merge('b: false', priorBox.attr["flip"])
|
||||
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)]
|
||||
heights = [0.1, args.min_scale / sqrt(2.0), args.min_scale / sqrt(0.5)]
|
||||
else:
|
||||
@@ -240,7 +259,10 @@ detectionOut = NodeDef()
|
||||
detectionOut.name = 'detection_out'
|
||||
detectionOut.op = 'DetectionOutput'
|
||||
|
||||
detectionOut.input.append('BoxEncodingPredictor/concat')
|
||||
if args.box_predictor == 'convolutional':
|
||||
detectionOut.input.append('BoxEncodingPredictor/concat')
|
||||
else:
|
||||
detectionOut.input.append('BoxPredictor/concat')
|
||||
detectionOut.input.append(sigmoid.name)
|
||||
detectionOut.input.append('PriorBox/concat')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user