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

Dung Do Tien Jul 29 2022 172

Hi Guys. 

I have created a Python app, that help process image for me. I installed tensorflow & keras packages. Here is some declared package in the main.py file:

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

But I got an error throw : ImportError: cannot import name 'get_config' from 'tensorflow.python.eager.context'. Here is the full error message:

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
     
ImportError: cannot import name 'get_config' from 'tensorflow.python.eager.context' (/desktop/local/lib/python3.7/dist-packages/tensorflow_core/python/eager/context.py)

Actually, I know getting error at this line:

from keras.preprocessing import image

But how can I fix it?

I install Python version 3.10

Thanks for any solution.

Have 1 answer(s) found.
  • N

    Nguyễn Phong Jul 29 2022

    The best way for any incompatibility issue is to upgrade the submodule. Firstly, you need to update the modules.

    Solution 1: Here is the command for the upgrading tensorflow module.

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

    Solution 2 :

    Replace the import package from

    from keras.preprocessing import image

    Please use this import statement.

    from tensorflow.keras.preprocessing import image

    The idea here is to use keras subpackage in the place of keras package.

Leave An Answer
* NOTE: You need Login before leave an answer

* Type maximum 2000 characters.

* All comments have to wait approved before display.

* Please polite comment and respect questions and answers of others.

Popular Tips

X Close