Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

833
Visualizações
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)

This is 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

I have tried installing tensorflow==2.1.0 and this has not been working either. If I comment out that one import, I just get another error on the next line and I have not been able to find much online about this. Any help would be appreciated!

over 4 years ago · Santiago Trujillo
12 Respostas
Responde à pergunta

0

Instead of

import keras

try

from tensorflow import keras 

This worked for me!

over 4 years ago · Santiago Trujillo Relatório

0

These commands fixed the issue:

pip install --upgrade tensorflow
pip install --upgrade tensorflow-gpu
over 4 years ago · Santiago Trujillo Relatório

0

I had Tensorflow===2.2.0 and when I updated it to Tensorflow==2.4.0 this issue occurred.

I think there is a conflict of keras.models.load_model and the base version of tensorflow you are using.

Try running -

import tensorflow as tf
tf.keras.models.load_model(model_path)

It worked for me.

over 4 years ago · Santiago Trujillo Relatório

0

This strange problem corresponds with imports of tensorflow. If you change from keras.preprocessing import image to from tensorflow.keras.preprocessing import image it will work.

over 4 years ago · Santiago Trujillo Relatório

0

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

over 4 years ago · Santiago Trujillo Relatório

0

I've updated

from keras.preprocessing.image import ImageDataGenerator
from keras.preprocessing.image import img_to_array, load_img
from keras import layers, models, optimizers
from keras import backend as K

to

from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.preprocessing.image import img_to_array, load_img
from tensorflow.keras import layers, models, optimizers
from tensorflow.keras import backend as K

and it works :)

over 4 years ago · Santiago Trujillo Relatório

0

pip install --upgrade tensorflow
pip install --upgrade tensorflow-gpu

Works, but will interfere with the Tensorflow/NVIDIA CUDA Toolkit/NVIDIA cuDNN GPU-support set up. Better solution: unistall Keras 2.6.0, install Keras 2.4.3

The bug is fixed and GPU is running!

over 4 years ago · Santiago Trujillo Relatório

0

In my case with Google colab, I downgraded tensorflow to 2.2 and replaced all import keras.xxxx to import tensorflow.keras.xxxx. That fixed it.

over 4 years ago · Santiago Trujillo Relatório

0

instead of from keras.preprocessing import image do this: from tensorflow.keras.preprocessing import image

over 4 years ago · Santiago Trujillo Relatório

0

I just solved this problem for myself.

# Instead of this:
from keras.preprocessing import image

# Do this:
from tensorflow.keras.preprocessing import image
over 4 years ago · Santiago Trujillo Relatório

0

In my case I changed the import from the following:

from keras.preprocessing.image import ImageDataGenerator

To this:

from tensorflow.keras.preprocessing.image import ImageDataGenerator
over 4 years ago · Santiago Trujillo Relatório

0

For me it just work upgrading tensorflow. Note: if you're using special tensorflow as gpu version, you must update this one because it's a separate module.

pip install --upgrade tensorflow
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda