AttributeError: 模块“tensorflow”没有属性“enable_eager_execution”

ven*_*esh 7 python machine-learning anaconda tensorflow tensorflow2.0

我只是尝试在我的 shell 中启用 Eager Execution,这实际上显示了一个错误:

AttributeError: module 'tensorflow' has no attribute 'enable_eager_execution'
Run Code Online (Sandbox Code Playgroud)

我的 Tensorflow 版本是 2.0

图像显示了我的 tensorflow 版本

谁能告诉我为什么我得到这个...

提前致谢

ste*_*sha 16

Tensorflow 2.0默认情况下启用了eager_execution,因此您无需运行tf.enable_eager_execution. 仅当您的运行版本低于以下时2.0,您才应启用急切执行


小智 6

在 2.x 版本中默认启用急切执行,您可以使用以下命令进行检查

tf.executing_eagerly()
Run Code Online (Sandbox Code Playgroud)

它应该返回 True。如果您的版本低于 2.0,则可以使用以下命令启用它

tf.enable_eager_execution()
Run Code Online (Sandbox Code Playgroud)