eval() and run() in tensorflow

If you have only one default session, they are basically the same.

From https://github.com/tensorflow/tensorflow/blob/v1.12.0/tensorflow/python/framework/ops.py#L2351:

op.run() is a shortcut for calling tf.get_default_session().run(op)

From https://github.com/tensorflow/tensorflow/blob/v1.12.0/tensorflow/python/framework/ops.py#L691:

t.eval() is a shortcut for calling tf.get_default_session().run(t)

Difference between Tensor and Operation:

Tensor: https://www.tensorflow.org/api_docs/python/tf/Tensor

Operation: https://www.tensorflow.org/api_docs/python/tf/Operation

Note: the Tensor class will be replaced by Output in the future. Currently these two are aliases for each other.


The difference is in Operations vs. Tensors. Operations use run() and Tensors use eval().

There seems to be a reference to this question in TensorFlow FAQ: https://www.tensorflow.org/programmers_guide/faq#running_a_tensorflow_computation

The section addresses the following question: What is the difference between Session.run() and Tensor.eval()?