1

遵循此文档:,我在安装 tensorflow 版本为 1.8.0 且 python 版本为 2.7.13 后尝试运行这些行。

*import tensorflow as tf
tf.enable_eager_execution()*

我转到安装 tensorflow 的顶级目录中的 jupyter notebook 并创建一个新的 jupyter notebook,然后运行上面的行,得到了这个错误:

*---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-1-1ff77c8b7a69> in <module>()
      1 import tensorflow as tf
      2 from __future__ import absolute_import, division, print_function
----> 3 tf.enable_eager_execution()
AttributeError: 'module' object has no attribute 'enable_eager_execution'*

但是当我从终端访问python或使用ipython时,我可以成功运行这两行。有谁知道这是为什么,我该如何解决笔记本中的问题?

4

1 回答 1

1

我在使用 colab 时遇到了这个错误,我通过从运行时菜单中选择选项“重置所有运行时”项来重置环境来消除这个错误。

消除此错误的另一种方法是在代码单元中执行以下命令:

import tensorflow as tf
tf.enable_eager_execution()
于 2019-05-13T12:55:55.727 回答