Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List of tensor names in graph in Tensorflow

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 valid names for the pretrained model inception-v3 from here? From their example, pool_3, is one valid tensor but a list of all of them would be nice. I looked at the paper referred to and some of the layers seems to correspond to the sizes in table 1 but not all of them.

like image 252
John Pertoft Avatar asked Feb 11 '16 10:02

John Pertoft


People also ask

How do I get a TensorFlow tensor name?

Finally, we close the TensorFlow session to release the TensorFlow resources we used within the session. That is how you can get a TensorFlow tensor by name using the tf. get_default_graph operation and then the TensorFlow get_tensor_by_name operation.

How do you find the TensorFlow graph?

Visualization of a TensorFlow graph. To see your own graph, run TensorBoard pointing it to the log directory of the job, click on the graph tab on the top pane and select the appropriate run using the menu at the upper left corner.

What is tensor graph?

Graphs are data structures that contain a set of tf. Operation objects, which represent units of computation; and tf. Tensor objects, which represent the units of data that flow between operations. They are defined in a tf. Graph context.

What does TF Get_default_graph () do?

Returns the default graph for the current thread.


2 Answers

The paper is not accurately reflecting the model. If you download the source from arxiv it has an accurate model description as model.txt, and the names in there correlate strongly with the names in the released model.

To answer your first question, sess.graph.get_operations() gives you a list of operations. For an op, op.name gives you the name and op.values() gives you a list of tensors it produces (in the inception-v3 model, all tensor names are the op name with a ":0" appended to it, so pool_3:0 is the tensor produced by the final pooling op.)

like image 175
etarion Avatar answered Sep 22 '22 05:09

etarion


The above answers are correct. I came across an easy to understand / simple code for the above task. So sharing it here :-

import tensorflow as tf  def printTensors(pb_file):      # read pb into graph_def     with tf.gfile.GFile(pb_file, "rb") as f:         graph_def = tf.GraphDef()         graph_def.ParseFromString(f.read())      # import graph_def     with tf.Graph().as_default() as graph:         tf.import_graph_def(graph_def)      # print operations     for op in graph.get_operations():         print(op.name)   printTensors("path-to-my-pbfile.pb") 
like image 24
Akash Goyal Avatar answered Sep 20 '22 05:09

Akash Goyal