diff --git a/testdata/dnn/tensorflow/generate_tf_models.py b/testdata/dnn/tensorflow/generate_tf_models.py index 8c282228d..bbc4de449 100644 --- a/testdata/dnn/tensorflow/generate_tf_models.py +++ b/testdata/dnn/tensorflow/generate_tf_models.py @@ -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() @@ -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: diff --git a/testdata/dnn/tensorflow/slim_batch_norm_in.npy b/testdata/dnn/tensorflow/slim_batch_norm_in.npy new file mode 100644 index 000000000..8f7297776 Binary files /dev/null and b/testdata/dnn/tensorflow/slim_batch_norm_in.npy differ diff --git a/testdata/dnn/tensorflow/slim_batch_norm_net.pb b/testdata/dnn/tensorflow/slim_batch_norm_net.pb new file mode 100644 index 000000000..270b6fad5 Binary files /dev/null and b/testdata/dnn/tensorflow/slim_batch_norm_net.pb differ diff --git a/testdata/dnn/tensorflow/slim_batch_norm_out.npy b/testdata/dnn/tensorflow/slim_batch_norm_out.npy new file mode 100644 index 000000000..ff85cfc2b Binary files /dev/null and b/testdata/dnn/tensorflow/slim_batch_norm_out.npy differ