Tensorflow: difference get_tensor_by_name vs get_operation_by_name?

The answer here says that one returns an operation and the other returns a tensor. This is pretty obvious from the name and documentation. However, suppose I do the following:

logits = tf.add(tf.matmul(inputs, weights), biases, name='logits')

I follow the circuit described in Tensorflow Mechanics 101 . Should I restore it as an operation or as a tensor? I am afraid that if I restore it as a tensor, I will only get the last calculated values ​​for logits; however, the post here seems to suggest that there is no difference or that I should just use it get_tensor_by_name. The idea is to calculate the logic for a new set of inputs, and then make predictions accordingly.

+4
source share
1 answer

Short answer: you can use both get_operation_by_name()and parameters get_tensor_by_name(). Long answer:

tf.Operation

When you call

op = graph.get_operation_by_name('logits')

... it returns an instance of a type tf.Operation, which is a node in a computational graph that executes some op on its inputs and produces one or more outputs. In this case, it is a plusop.

You can always evaluate op in a session, and if this operator needs some placehoder values ​​to be submitted, the engine will force you to provide them. Some operating systems, for example. reading a variable has no dependencies and can be performed without placeholders.

( ) logits x, logits x.

tf.Tensor

,

tensor = graph.get_tensor_by_name('logits:0')

... tensor, tf.Tensor:

Operation.

A tensor Operation. , TensorFlow tf.Session.

, , , , , .

tensor ? A tensor Operation, . , .

+2

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


All Articles