6

So far I can get the list of all node names given any .ckpt.meta file, but I was wondering if there is a systematic way of finding out the output node name from the list.

import tensorflow as tf

tf.reset_default_graph()
with tf.Session() as sess:
    saver = tf.train.import_meta_graph('mymodel.ckpt.meta')
    graph_def = tf.get_default_graph().as_graph_def()
    node_list=[n.name for n in graph_def.node]
Shawn
  • 126
  • 1
  • 6
  • 1
    Generally it is useful to use namespaces to make your search easier. Also, you can use `tf.identity` to give an output of an operation a name of your liking. You can get the variable name with `graph_def.get_tensor_by_name('mynamespace/myvar:0')`. I haven't come across a better way yet. – DocDriven Jul 27 '18 at 09:04
  • Did you find a solution? – gogasca Sep 19 '18 at 23:24

2 Answers2

1

You can try:

[n.name for n in tf.get_default_graph().as_graph_def().node]
gogasca
  • 9,283
  • 6
  • 80
  • 125
-1

This works for me:

    import tensorflow as tf

    def get_node_name():
        tf.reset_default_graph()
        with tf.Session() as sess:
            saver = tf.train.import_meta_graph(meta_file)
            graph_def = tf.get_default_graph().as_graph_def()
            name_list = []
    
            
            for node in graph_def.node:
                name_list.append(node.name)
    
            outputs = set(name_list)
    
            for index, output in enumerate(outputs):
                print('Node Name: ', output)

Then run:

get_node_name()
Mwenda
  • 422
  • 3
  • 6