Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: cannot import name 'get_config' from 'tensorflow.python.eager.context'

My notebook was working up till today. At the beginning of my colab notebook I install tf-nightly, but now it is giving me this error:

---------------------------------------------------------------------------
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)

My code:

!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

Installing tensorflow==2.1.0 did not work either.

like image 390
Jehan Dastoor Avatar asked Apr 06 '21 07:04

Jehan Dastoor


3 Answers

Instead of:

import keras

Try:

from tensorflow import keras 
like image 68
Anusha Avatar answered Oct 20 '22 15:10

Anusha


These commands fixed the issue:

pip install --upgrade tensorflow
pip install --upgrade tensorflow-gpu
like image 36
thomle295 Avatar answered Oct 20 '22 16:10

thomle295


Try the version of Keras 2.3.1

pip install keras==2.3.1

then also install that

pip install git+https://www.github.com/keras-team/keras-contrib.git

like image 25
MD Gazuruddin Avatar answered Oct 20 '22 17:10

MD Gazuruddin