访问量: 9 次浏览
TensorFlow是谷歌设计的开源Python库,用于开发机器学习模型和深度学习神经网络。
executing\_eagerly() 用于检查当前线程中是否启用或禁用了急切执行。默认情况下,急切执行是启用的,所以在大多数情况下它会返回true。在以下情况下,它将返回false。
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