Introducing eager execution
Eager execution in TensorFlow is more Pythonic and allows rapid prototyping. Unlike graph mode, where we need to construct a graph every time we want to perform any operation, eager execution follows the imperative programming paradigm, where any operation can be performed immediately, without having to create a graph, just like we do in Python. Hence, with eager execution, we can say goodbye to sessions and placeholders. It also makes the debugging process easier with an immediate runtime error, unlike graph mode. For instance, in graph mode, to compute anything, we run the session. As shown in the following code, to evaluate the value of z
, we have to run the TensorFlow session:
x = tf.constant(11)
y = tf.constant(11)
z = x*y
with tf.Session() as sess:
print(sess.run(z))
With eager execution, we don't need to create a session; we can simply compute z
, just like we do in Python. In order to enable eager execution, just call...