I am trying to learn TensorFlow. Currently, I am working with placeholders. When I tried to create the placeholder, I got an error: RuntimeError: tf.placeholder() is not compatible with eager execution
, which makes sense as placeholders are not executable immediately.
So, how do I turn eager execution off?
I have never turned eager execution on in the first place, so I am not sure how it happened. Is there an opposite to tf.disable_eager_execution()
?
4条答案
按热度按时间wkyowqbh1#
假设您使用的是Tensorflow 2.0预览版,默认情况下启用了即时执行。v1 API中有一个
disable_eager_execution()
,您可以将其放在代码前面,如下所示:另一方面,如果您没有使用2.0预览,请检查您是否在某处意外启用了急切执行。
pu82cl6c2#
我假设您使用的是TensorFlow 2.0。在TF 2中,eager模式默认打开。但是,TensorFlow 2.0.0中有一个
disable_eager_execution()
-alpha 0,但它隐藏得很深,无法从顶层模块名称空间(即tf名称空间)直接访问。您可以像这样呼叫函式:
>>>Tensor("add:0", shape=(), dtype=int32)
>>>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.
wlwcrazw3#
在TensorFlow 2.3+中,您可以使用以下方法随时禁用急切模式:
7kqas0il4#
您可以禁用TensorFlow v2行为,如下所示: