Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tensorflow: What are the "output_node_names" for freeze_graph.py in the model_with_buckets model?

I trained a tf.nn.seq2seq.model_with_buckets with seq2seq = tf.nn.seq2seq.embedding_attention_seq2seq very similar to the example in the Tensorflow Tutorial.

Now I would like to freeze the graph using freeze_graph.py. How can I find the "output_node_names" in my model?

like image 238
WS91 Avatar asked Aug 15 '16 16:08

WS91


2 Answers

You can get all of the node names in your model with something like:

node_names = [node.name for node in tf.get_default_graph().as_graph_def().node]

Or with restoring the graph:

saver = tf.train.import_meta_graph(/path/to/meta/graph)
sess = tf.Session()
saver.restore(sess, /path/to/checkpoints)
graph = sess.graph
print([node.name for node in graph.as_graph_def().node])

You may need to filter these to get only your output nodes, or only the nodes that you want, but this can at least help you get the names for a graph that you have already trained and cannot afford to retrain with name='some_name' defined for each node.

Ideally, you want to define a name parameter for each operation or tensor that you are going to want to access later.

like image 143
Engineero Avatar answered Nov 06 '22 03:11

Engineero


You can choose names for the nodes in your model by passing the optional name="myname" argument to pretty much any Tensorflow operator that builds a node. Tensorflow will pick names for graph nodes automatically if you don't specify them, but if you want to identify those nodes to a tool like freeze_graph.py, then it's best to choose the names yourself. Those names are what you pass to output_node_names.

like image 39
Peter Hawkins Avatar answered Nov 06 '22 03:11

Peter Hawkins