Why get_tensor_by_name requires adding a port to the tensor name

I know that when I get a tensor by name I have to add an output index

ex)

graph.get_tensor_by_name('example:0') 

Where: 0 is the output index. But why is this necessary?

here is a link to get_tensor_by_name in tensorflow docs. However, he does not mention the indication of the output index.

+6
source share
2 answers

In TensorFlow, names are assigned to tf.Operation objects (which correspond to nodes in tf.Graph ), and a tf.Tensor object tf.Tensor named for tf.Operation , which produces it as an output.

Since a tf.Operation can have more than one output, for the unique name tf.Tensor , we include its index in the outputs as part of its name.

Therefore, we chose the following format for the tf.Tensor object tf.Tensor , which is also the value returned by the tf.Tensor.name property:

 <name of operation>:<index of output> 
+8
source

The get_tensor_by_name to understanding the get_tensor_by_name function is to understand that the TensorFlow model TensorFlow first shown as a graph during the build phase. In this question, example is the name of the node operation in this graph. When this operation is performed during the execution phase, the output is done using this example node. This result is indexed by a number indicating its production order. In this case, it is 1 .

The graph and its outputs described above were saved during an earlier launch. Later, in another project execution, this runtime was restored, possibly using tf.train.import_meta_graph and graph becomes a link to it. The get_tensor_by_name function simply restores the link to the saved second output of the example node from the restored run-time metadata. Now you can use this restored tensor in your own task during another session.

0
source

Source: https://habr.com/ru/post/1013737/


All Articles