Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/3.4' into merge-3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
alalek committed Apr 5, 2019
2 parents 6db5c52 + 928c3da commit c721e82
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion testdata/dnn/tensorflow/generate_tf_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def prepare_for_dnn(sess, graph_def, in_node, out_node, out_graph, dtype, optimi
graph_def = TransformGraph(graph_def, [in_node], [out_node], transforms)
# Serialize
with tf.gfile.FastGFile(out_graph, 'wb') as f:
f.write(graph_def.SerializeToString())
f.write(graph_def.SerializeToString())

tf.reset_default_graph()
tf.Graph().as_default()
Expand Down Expand Up @@ -677,6 +677,32 @@ def pad_depth(x, desired_channels):
softmax = tf.contrib.slim.softmax(conv)
save(inp, softmax, 'slim_softmax')
################################################################################
# issue https://github.com/opencv/opencv/issues/14224
inp_node = 'img_inputs'
out_node = 'MobileFaceNet/MobileFaceNet/Conv2d_0/add'
with tf.Session(graph=tf.Graph()) as localSession:
localSession.graph.as_default()

with tf.gfile.FastGFile('frozen_model.pb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
for node in graph_def.node:
if node.name == inp_node:
del node.attr['shape']

tf.import_graph_def(graph_def, name='')

inputData = gen_data(tf.placeholder(tf.float32, [1, 4, 5, 3], inp_node))
outputData = localSession.run(localSession.graph.get_tensor_by_name(out_node + ':0'),
feed_dict={inp_node + ':0': inputData})
writeBlob(inputData, 'slim_batch_norm_in')
writeBlob(outputData, 'slim_batch_norm_out')

graph_def = TransformGraph(graph_def, [inp_node], [out_node], ['fold_constants', 'strip_unused_nodes'])
with tf.gfile.FastGFile('slim_batch_norm_net.pb', 'wb') as f:
f.write(graph_def.SerializeToString())

################################################################################

# Uncomment to print the final graph.
# with tf.gfile.FastGFile('fused_batch_norm_net.pb') as f:
Expand Down
Binary file added testdata/dnn/tensorflow/slim_batch_norm_in.npy
Binary file not shown.
Binary file added testdata/dnn/tensorflow/slim_batch_norm_net.pb
Binary file not shown.
Binary file added testdata/dnn/tensorflow/slim_batch_norm_out.npy
Binary file not shown.

0 comments on commit c721e82

Please sign in to comment.