【发布时间】:2021-07-01 23:48:37
【问题描述】:
我的笔记本一直工作到今天。在我的 colab 笔记本开始时,我安装了 tf-nightly,但现在它给了我这个错误
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-589c442233c5> in <module>()
7 import tensorflow as tf
8 from tensorflow.keras import datasets, layers, models
----> 9 from keras.preprocessing import image
10 from keras_preprocessing.image import ImageDataGenerator #check underscore or not
11 from tensorflow.keras.preprocessing import image_dataset_from_directory
2 frames
/usr/local/lib/python3.7/dist-packages/keras/backend.py in <module>()
35 from tensorflow.python.distribute import distribute_coordinator as dc
36 from tensorflow.python.distribute import distribute_coordinator_context as dc_context
---> 37 from tensorflow.python.eager.context import get_config
38 from tensorflow.python.framework import config
39 from keras import backend_config
ImportError: cannot import name 'get_config' from 'tensorflow.python.eager.context' (/usr/local/lib/python3.7/dist-packages/tensorflow_core/python/eager/context.py)
这是我的代码:
!pip install tf-nightly
import tensorflow as tf
from tensorflow.keras import datasets, layers, models
from keras.preprocessing import image
from keras_preprocessing.image import ImageDataGenerator
from tensorflow.keras.preprocessing import image_dataset_from_directory
from keras.callbacks import Callback, ModelCheckpoint, ReduceLROnPlateau, EarlyStopping
我已尝试安装 tensorflow==2.1.0,但也没有成功。如果我注释掉一个导入,我只会在下一行收到另一个错误,而且我无法在网上找到很多关于此的内容。任何帮助将不胜感激!
【问题讨论】:
-
如果不需要,请卸载 tf-nightly。
-
我在尝试从 keras.utils.np_utils 导入 to_categorical() 方法时遇到了同样的问题。我没有找到直接的解决方案,但我设法通过从 tensorflow.keras.utils 导入来绕过错误...
标签: python tensorflow keras