首页 > 解决方案 > 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.kerasTensorFlow 1.14,或者降级到 TensorFlow 1.14。

我目前在我的 Mac(Mojave) 上运行 Python 3.7.6 版本。我在我的机器上运行 TensorFlow 2.0.0 版本。

标签: tensorflowkerasdeep-learning

解决方案


我在使用 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

所以,我的新代码看起来像这样。我的新代码。


推荐阅读