Google News
logo
TensorFlow.js - Interview Questions
What is the difference between Tensor.eval() and Session.run()?
In TensorFlow, we create graphs and provide values to that graph. The graph itself processes all the hardwork and generates the output based on the configuration that we have applied in the graph. Now, when we provide values to the graph, then first, we need to create a TensorFlow session.
tf.Session()  
Once the session is initialized, then we are supposed to use that session. It is necessary because all the variables and settings are now part of the session.
 
So, there are two possible ways that we can apply to pass external values to the graph so that the graph accepts them.
 
* The first one is to call the .run() while you are using the session and it is being executed.
* Another way to this is to use .eval(). The full syntax of .eval() is

tf.get_default_session().run(values)  ​

At the place of values.eval(), we can put tf.get_default_session().run(values) and It will provide the same behavior. Here, eval is using the default session and then executing run().
Advertisement