Open In App

Python – tensorflow.executing_eagerly()

TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning  neural networks. 

executing_eagerly() is used check if eager execution is enabled or disabled in current thread. By default eager execution is enabled so in most cases it will return true. This will return false in following cases:



Syntax: tensorflow.executing_eagerly()

Parameters: This doesn’t accept any parameters.



Returns: It returns true if eager execution is enabled otherwise it will return false.

Example 1:




# Importing the library
import tensorflow as tf
 
# Checking eager execution
res = tf.executing_eagerly()
 
# Printing the result
print('res: ', res)

Output:

res:  True

Example 2: This example checks eager execution for tensorflow.function with and without init_scope.




# Importing the library
import tensorflow as tf
 
@tf.function
def gfg():
  with tf.init_scope():
    # Checking eager execution inside init_scope
    res = tf.executing_eagerly()
    print("res 1:", res)
 
  # Checking eager execution outside init_scope
  res = tf.executing_eagerly()
  print("res 2:", res)
gfg()

Output:

res 1: True
res 2: False
Article Tags :