没有属性 'enable_eager_execution' ?已经在使用 TensorFlow 1.7
No attribute 'enable_eager_execution' ? Already using TensorFlow 1.7
根据 TensorFlow Program's Guide (here),以下操作需要 TensorFlow 1.7
但我得到一个错误(见下文)。
from __future__ import absolute_import, division, print_function
import tensorflow as tf
tf.enable_eager_execution()
这是我的设置。
我在 Google Colab
中按照此页面 (link)
上的说明进行了此操作
!apt-get install -y -qq software-properties-common python-software-properties module-init-tools
!add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null
!apt-get update -qq 2>&1 > /dev/null
!apt-get -y install -qq google-drive-ocamlfuse fuse
from google.colab import auth
auth.authenticate_user()
from oauth2client.client import GoogleCredentials
creds = GoogleCredentials.get_application_default()
import getpass
!google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret} < /dev/null 2>&1 | grep URL
vcode = getpass.getpass()
!echo {vcode} | google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret}
然后
!mkdir -p drive
!google-drive-ocamlfuse drive
然后
!pip install -q keras
然后再次使用 TensorFlow Programmer's Guide
中的指令
pip install --upgrade tensorflow
本来应该升级到 1.7 的,但后来出现以下错误:
AttributeErrorTraceback (most recent call last)
<ipython-input-9-e1c25fd4f69c> in <module>()
1 from __future__ import absolute_import, division, print_function
2 import tensorflow as tf
----> 3 tf.enable_eager_execution()
AttributeError: 'module' object has no attribute 'enable_eager_execution'
有什么建议吗?
更新
我刚刚发现我仍然处于 TensorFlow 1.6
-- 即使在我尝试了夜间构建之后
print(tf.__version__)
1.6.0
尝试了夜间构建
!pip install tf-nightly
print(tf.__version__)
1.6.0
所以我想我现在的问题是——如何在 Google Colab
中升级到 1.7?
如果您已经在 运行 pip upgrade
之前导入了 TensorFlow,则需要在更新后重新启动内核。 (运行时菜单 -> 重新启动运行时)
从一个新启动的内核进程中,以下内容按我的预期打印 1.7:
!pip install -q -U tensorflow>=1.7
import tensorflow
tensorflow.__version__
哦,我找到答案了——笔记本必须使用 GPU 硬件加速器(编辑->笔记本设置)。
谢谢!
更新
到现在为止,我不确定使用 GPU 硬件加速器是否真的能解决问题。另请参阅 Bob Smith 的其他答案。我认为笔记本可能有一些记忆状态,所以我不确定我的实验结果的结论。您可能想尝试这两个建议。
好消息 -- 我们刚刚完成了对 TF 1.7 的更新,因此默认情况下您应该可以使用它。 :)
根据 TensorFlow Program's Guide (here),以下操作需要 TensorFlow 1.7
但我得到一个错误(见下文)。
from __future__ import absolute_import, division, print_function
import tensorflow as tf
tf.enable_eager_execution()
这是我的设置。
我在 Google Colab
中按照此页面 (link)
!apt-get install -y -qq software-properties-common python-software-properties module-init-tools
!add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null
!apt-get update -qq 2>&1 > /dev/null
!apt-get -y install -qq google-drive-ocamlfuse fuse
from google.colab import auth
auth.authenticate_user()
from oauth2client.client import GoogleCredentials
creds = GoogleCredentials.get_application_default()
import getpass
!google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret} < /dev/null 2>&1 | grep URL
vcode = getpass.getpass()
!echo {vcode} | google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret}
然后
!mkdir -p drive
!google-drive-ocamlfuse drive
然后
!pip install -q keras
然后再次使用 TensorFlow Programmer's Guide
中的指令pip install --upgrade tensorflow
本来应该升级到 1.7 的,但后来出现以下错误:
AttributeErrorTraceback (most recent call last)
<ipython-input-9-e1c25fd4f69c> in <module>()
1 from __future__ import absolute_import, division, print_function
2 import tensorflow as tf
----> 3 tf.enable_eager_execution()
AttributeError: 'module' object has no attribute 'enable_eager_execution'
有什么建议吗?
更新
我刚刚发现我仍然处于 TensorFlow 1.6
-- 即使在我尝试了夜间构建之后
print(tf.__version__)
1.6.0
尝试了夜间构建
!pip install tf-nightly
print(tf.__version__)
1.6.0
所以我想我现在的问题是——如何在 Google Colab
中升级到 1.7?
如果您已经在 运行 pip upgrade
之前导入了 TensorFlow,则需要在更新后重新启动内核。 (运行时菜单 -> 重新启动运行时)
从一个新启动的内核进程中,以下内容按我的预期打印 1.7:
!pip install -q -U tensorflow>=1.7
import tensorflow
tensorflow.__version__
哦,我找到答案了——笔记本必须使用 GPU 硬件加速器(编辑->笔记本设置)。
谢谢!
更新
到现在为止,我不确定使用 GPU 硬件加速器是否真的能解决问题。另请参阅 Bob Smith 的其他答案。我认为笔记本可能有一些记忆状态,所以我不确定我的实验结果的结论。您可能想尝试这两个建议。
好消息 -- 我们刚刚完成了对 TF 1.7 的更新,因此默认情况下您应该可以使用它。 :)