tensorflow - Colab 升级到 TensorFlow 2.0,现在遇到错误 RuntimeError: version does not support TensorFlow 2.0
问题描述
我一直在 colab 上很好地运行我的 DL 模型,直到他们上周五升级了系统。我收到此错误:
AttributeError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py in _get_default_graph()
65 try:
---> 66 return tf.get_default_graph()
67 except AttributeError:
AttributeError: module 'tensorflow' has no attribute 'get_default_graph'
During handling of the above exception, another exception occurred:
RuntimeError Traceback (most recent call last)
8 frames
/usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py in _get_default_graph()
67 except AttributeError:
68 raise RuntimeError(
---> 69 'It looks like you are trying to use '
70 'a version of multi-backend Keras that '
71 'does not support TensorFlow 2.0. We recommend '
RuntimeError:您似乎正在尝试使用不支持 TensorFlow 2.0 的多后端 Keras 版本。我们建议使用
tf.keras
TensorFlow 1.14,或者降级到 TensorFlow 1.14。
我目前在我的 Mac(Mojave) 上运行 Python 3.7.6 版本。我在我的机器上运行 TensorFlow 2.0.0 版本。
解决方案
我在使用 Google Colab 时也遇到了同样的问题。所以我所做的是,从 tensorflow.keras 模块中导入所有模块,而不是使用仅通过 keras 调用的传统方法。
例如。而不是
from keras.models import Sequential
使用
from tensorflow.keras import Sequential
并且,
from keras.layers import Conv2D, MaxPool2D, Dense, Flatten, Dropout
使用
from tensorflow.keras.layers import Conv2D, MaxPool2D, Flatten, Dropout, Dense
所以,我的新代码看起来像这样。我的新代码。
推荐阅读
- r - 降低 R 中双精度数
- c# - C# 在轮次之间等待而不暂停脚本的其余部分
- scheme - Racket 博士支持 MiniKanren
- php - SHA512 不正确的登录名从数据库中检索密码
- angular - 如何在 mat-calendar 上更改当前的样式
- php - 由于设置了标头授权,未发送 $_POST 变量
- winapi - 为什么 fopen 在 CreateFile 失败的地方成功?
- angular - Angular中的动画元素位置交换
- javascript - 将 SIP.js 与 React Native 集成
- routing - 有没有办法创建一个仅包含路由及其在 Rocket 中的功能的中央路由文件?