我假设您正在使用TensorFlow 2.0。在TF2中,默认情况下开启了紧急模式。但是,在TensorFlow 2.0.0-alpha0中有一个disable_eager_execution()
,但它隐藏得很深,无法从顶层模块名称空间(即tf名称空间)直接访问。
您可以像这样调用该函数:
import tensorflow as tf
from tensorflow.python.framework.ops import disable_eager_execution
disable_eager_execution()
a = tf.constant(1)
b = tf.constant(2)
c = a + b
print(c)
>>>Tensor("add:0", shape=(), dtype=int32)
print(disable_eager_execution.__doc__)
>>>Disables eager execution.
This function can only be called before any Graphs, Ops, or Tensors have been created. It can be used at the beginning of the program for complex migration projects from TensorFlow 1.x to 2.x.
0
我正在尝试学习TensorFlow。目前,我正在与占位符一起工作。当我尝试创建占位符时,出现错误:
RuntimeError: tf.placeholder() is not compatible with eager execution
,这是有道理的,因为占位符不能立即执行。那么,如何关闭渴望执行的程序?
首先,我从未渴望执行过,所以我不确定它是如何发生的。与
tf.disable_eager_execution()
是否相反?