List of tensor names in graph in Tensorflow

后端 未结 6 1125
死守一世寂寞
死守一世寂寞 2020-11-28 21:04

The graph object in Tensorflow has a method called \"get_tensor_by_name(name)\". Is there anyway to get a list of valid tensor names?

If not, does anyone know the va

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-28 21:25

    You do not even have to create a session to see the names of all operation names in the graph. To do this you just need to grab a default graph tf.get_default_graph() and extract all the operations: .get_operations. Each operation has many fields, the one you need is name.

    Here is the code:

    import tensorflow as tf
    a = tf.Variable(5)
    b = tf.Variable(6)
    c = tf.Variable(7)
    d = (a + b) * c
    
    for i in tf.get_default_graph().get_operations():
        print i.name
    

提交回复
热议问题