Python – tensorflow.executing_eagerly()
TensorFlow是谷歌设计的开源Python库,用于开发机器学习模型和深度学习神经网络。
executing_eagerly()用于检查当前线程中是否启用或禁用了急切执行。默认情况下,急切执行是启用的,所以在大多数情况下它会返回true。在以下情况下,它将返回false。
- 如果它是在tensorflow.function_and_ tf.init_scope或tf.config.experimental_run_functions_eagerly(True)内执行的,则之前没有调用。
 - 在tensorflow.dataset的转换函数内执行。
 - tensorflow.compat.v1.disable_eager_execution()被调用。
 
语法: tensorflow.executing_eagerly()
参数:这不接受任何参数。
返回:如果启用了急切执行,则返回真,否则将返回假。
示例 1:
# Importing the library
import tensorflow as tf
  
# Checking eager execution
res = tf.executing_eagerly()
  
# Printing the result
print('res: ', res)
输出:
res:  True
实例2:本例检查了有无init_scope的tensorflow.function的急切执行。
# 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()
输出:
res 1: True
res 2: False
极客教程