mtcnn icon indicating copy to clipboard operation
mtcnn copied to clipboard

AttributeError: module 'keras.utils.generic_utils' has no attribute 'populate_dict_with_module_objects'

Open khaitranhq opened this issue 3 years ago • 0 comments

Versions

mtcnn: 0.1.0
keras: 2.4.3
opencv-python: 4.5.2.54

Error

File "/home/leo/Workspace/global/pbl5/pbl5-api/api/urls.py", line 5, in <module>
    from . import views
  File "/home/leo/Workspace/global/pbl5/pbl5-api/api/views.py", line 15, in <module>
    from ai_models import recog, train
  File "/home/leo/Workspace/global/pbl5/pbl5-api/ai_models/recog.py", line 1, in <module>
    import detect
  File "/home/leo/Workspace/global/pbl5/pbl5-api/detect.py", line 4, in <module>
    from mtcnn import MTCNN
  File "/home/leo/.local/lib/python3.8/site-packages/mtcnn/__init__.py", line 26, in <module>
    from mtcnn.mtcnn import MTCNN
  File "/home/leo/.local/lib/python3.8/site-packages/mtcnn/mtcnn.py", line 37, in <module>
    from mtcnn.network.factory import NetworkFactory
  File "/home/leo/.local/lib/python3.8/site-packages/mtcnn/network/factory.py", line 27, in <module>
    from keras.models import Model
  File "/home/leo/.local/lib/python3.8/site-packages/keras/__init__.py", line 20, in <module>
    from . import initializers
  File "/home/leo/.local/lib/python3.8/site-packages/keras/initializers/__init__.py", line 124, in <module>
    populate_deserializable_objects()
  File "/home/leo/.local/lib/python3.8/site-packages/keras/initializers/__init__.py", line 82, in populate_deserializable_objects
    generic_utils.populate_dict_with_module_objects(
AttributeError: module 'keras.utils.generic_utils' has no attribute 'populate_dict_with_module_objects'

Description

I run the example in Readme and it shows this error. I found out the way to solve it, that's changes import part in mtcnn/network/factory/py from

from keras.layers import Input, Dense, Conv2D, MaxPooling2D, PReLU, Flatten, Softmax
from keras.models import Model

to

from tensorflow.keras.layers import Input, Dense, Conv2D, MaxPooling2D, PReLU, Flatten, Softmax
from tensorflow.keras.models import Model

However, I think it's better if there's a change in the source code.

Thanks in advance!

khaitranhq avatar Jun 20 '21 07:06 khaitranhq