close

[Solved] How AttributeError: module ‘tensorflow.python.keras.utils.generic_utils’ has no attribute ‘populate_dict_with_module_objects’ ?

Hello Guys How Are You All ? Hope You all are fine. Today I Have Faced How AttributeError: module ‘tensorflow.python.keras.utils.generic_utils’ has no attribute ‘populate_dict_with_module_objects’ ? So Here I am Explain to you all the possible solutions Here.

Without Wasting your time, Lets start This Article to Solve This Error in Anaconda

How to solve AttributeError: module ‘tensorflow.python.keras.utils.generic_utils’ has no attribute ‘populate_dict_with_module_objects’ ?

When I import keras, the error above pops up even though it was working fine yesterday.

How do I resolve this error?

I am working on windows 10 my keras version is: 2.2.4 my tensorflow version is: 2.2.0rc2

complete error traceback is seen below as such:

Traceback (most recent call last):

    from keras import models
  File "C:\Users\world\AppData\Local\Programs\Python\Python38\lib\site-packages\keras\__init__.py", line 3, in <module>

    from . import utils
  File "C:\Users\world\AppData\Local\Programs\Python\Python38\lib\site-packages\keras\utils\__init__.py", line 6, in <module>

    from . import conv_utils

  File "C:\Users\world\AppData\Local\Programs\Python\Python38\lib\site-packages\keras\utils\conv_utils.py", line 9, in <module>

    from .. import backend as K

  File "C:\Users\world\AppData\Local\Programs\Python\Python38\lib\site-packages\keras\backend\__init__.py", line 1, in <module>

    from .load_backend import epsilon

  File "C:\Users\world\AppData\Local\Programs\Python\Python38\lib\site-packages\keras\backend\load_backend.py", line 90, in <module>

    from .tensorflow_backend import *

  File "C:\Users\world\AppData\Local\Programs\Python\Python38\lib\site-packages\keras\backend\tensorflow_backend.py", line 5, in <module>

    import tensorflow as tf

  File "C:\Users\world\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\__init__.py", line 41, in <module>

    from tensorflow.python.tools import module_util as _module_util
  File "C:\Users\world\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\__init__.py", line 84, in <module>

    from tensorflow.python import keras

  File "C:\Users\world\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\keras\__init__.py", line 27, in <module>
  1. How AttributeError: module 'tensorflow.python.keras.utils.generic_utils' has no attribute 'populate_dict_with_module_objects' ?

    I had the same problem, and I have successfully solved this issue with downgrading tensorflow version to 2.1.0.

  2. How AttributeError: module 'tensorflow.python.keras.utils.generic_utils' has no attribute 'populate_dict_with_module_objects' ?

    I had the same problem, and I have successfully solved this issue with downgrading tensorflow version to 2.1.0.

Solution 1

Please copy “populate_dict_with_module_objects” function from this link (line 827 to 832) and add it to “generic_utils.py”

Solution 2

change from keras import models to from tensorflow.keras import models
this solved the problem for me with tensorflow 2.5.0

Solution 3

I encountered the same problem using Python 3.9 and Tensorflow 2.5. The problem for me was that those two are not yet compatible, and as such, the solution is to install python 3.8 instead, and possibly also downgrade Tensorflow 2.5 to Tensorflow 2.4.

Solution 4

I’ve gotten around this by uninstalling Keras and changing anything I import from Keras to instead import from tensorflow.keras

So this:

    from keras.preprocessing.image import load_img
    from keras.preprocessing.image import img_to_array
    from keras.applications.vgg16 import preprocess_input
    from keras.applications.vgg16 import decode_predictions
    from keras.applications.vgg16 import VGG16

became this:

    from tensorflow.keras.preprocessing.image import load_img
    from tensorflow.keras.preprocessing.image import img_to_array
    from tensorflow.keras.applications.vgg16 import preprocess_input
    from tensorflow.keras.applications.vgg16 import decode_predictions
    from tensorflow.keras.applications.vgg16 import VGG16

and then I didn’t have to amend the rest of my work

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also Read

Leave a Comment