serengil / deepface

A Lightweight Face Recognition and Facial Attribute Analysis (Age, Gender, Emotion and Race) Library for Python
https://www.youtube.com/watch?v=WnUVYQP4h44&list=PLsS_1RYmYQQFdWqxQggXHynP1rqaYXv_E&index=1
MIT License
13.72k stars 2.15k forks source link

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

Closed Hwang64 closed 3 years ago

Hwang64 commented 3 years ago

When using the deepface, I use conda the create a virsual envrionment, and using pip install deepface to install the packdge, but when I run the code, I met the error: AttributeError: module 'keras.utils.generic_utils' has no attribute 'populate_dict_with_module_objects' deepface==0.5.1 tensorflow==2.5.0 keras==2.4.3 image

serengil commented 3 years ago

Could you run it on tensorflow 2.2.0?

I think it is 2.5 version related problem.

Hwang64 commented 3 years ago

After I pip install tensorflow==2.2.0 and run the deepface, I meet a new error AttributeError: module 'tensorflow.compat.v2' has no attribute 'internal' image

duongminhhieu16 commented 3 years ago

I met the first error and I found out the error is from keras 2.4.3 is somehow not compatible with tensorflow 2.5.0. The error comes from where you import directly keras. Changing all import "keras..." to "tensorflow.keras..." will fix this.

Hwang64 commented 3 years ago

I met the first error and I found out the error is from keras 2.4.3 is somehow not compatible with tensorflow 2.5.0. The error comes from where you import directly keras. Changing all import "keras..." to "tensorflow.keras..." will fix this.

Thank you for your suggestion, but changing import keras to import tensorflow.keras is a labourious job, do you have some effective ways to do it?

serengil commented 3 years ago

Could you share the whole exception message? Dumping log is not coming from any deepface related module.

Besides, I need the code you are running. I might modify some arguments if I know which function is consumed and how.

Hwang64 commented 3 years ago

the whole exception message is: image

serengil commented 3 years ago

Oke, I found a workaround. But it is going to be resolved in the next release. I will publish it in the next couple of days.

Hwang64 commented 3 years ago

Oke, I found a workaround. But it is going to be resolved in the next release. I will publish it in the next couple of days.

Thank you for your reply, is there a temporary solution to make the deepface run based on the current veriosn (deepface==0.5.1& &tensorflow==2.5.0&keras==2.4.3)?

serengil commented 3 years ago

Try to run the following commands respectively

pip uninstall deepface pip uninstall tensorflow pip uninstall keras

pip install tensorflow==2.2.0 pip install keras==2.4.3 pip install mtcnn==0.1.0 pip install deepface==0.0.51 --no-deps

Hwang64 commented 3 years ago

Try to run the following commands respectively

pip uninstall deepface pip uninstall tensorflow pip uninstall keras

pip install tensorflow==2.2.0 pip install keras==2.4.3 pip install mtcnn==0.1.0 pip install deepface==0.0.51 --no-deps

After I implement the above commands, a new error happens: image

I wonder whether it will work when using previous versions for deepface, tensorflow and keras?

serengil commented 3 years ago

the problem is that its dependency mtcnn causes that trouble.

currently, i am using python 3.8.5, tensorflow 2.2.0, keras 2.4.3, mtcnn 0.1.0 and it works

you might downgrade to tensorflow 1.9.X to fix this issue.

serengil commented 3 years ago

I will publish the next release soon (half hour later) when I run unit tests successfully. You might want to wait.

serengil commented 3 years ago

This is handled in 0.0.52. It will be published soon.

serengil commented 3 years ago

0.0.52 is just published. please update deepface library. and use a different detector_backend than mtcnn

DeepFace.verify("img1.jpg", "img2.jpg", detector_backend = 'opencv')

ImMainak commented 3 years ago

Sir I'm still facing the same issue in 0.0.53

serengil commented 3 years ago

@ImMainak please share the code you are running and the whole exception message you got.

ImMainak commented 3 years ago

From the mentioned solution I downgraded Tensorflow to 2.2.0 and installed deepface version 0.0.52 but here it's showing that two picture of different people are of a same person. Here I'm sharing my code and the output I'm getting

Code :-

from deepface import DeepFace import pandas as pd df = DeepFace.verify("E:\Python_Test_Data\Test2.jpg", "E:\Python_Test_Data\Test1.jpg", detector_backend='opencv') print(df)

Output :-

vgg_face_weights.h5 will be downloaded... Access denied with the following error: Unable to open file (unable to open file: name = 'C:\Users\Mainak/.deepface/weights/vgg_face_weights.h5', errno = 2, error message = 'No such file or directory', flags = 0, o_flags = 0) Pre-trained weight could not be loaded. You might try to download the pre-trained weights from the url https://drive.google.com/uc?id=1CPSeum3HpopfomUEK1gybeuIVoeJT_Eo and copy it to the C:\Users\Mainak/.deepface/weights/vgg_face_weights.h5

Too many users have viewed or downloaded this file recently. Please try accessing the file again later. If the file you are trying to access is particularly large or is shared with many people, it may take up to 24 hours to be able to view or download the file. If you still can't access a file after 24 hours, contact your domain administrator.

You may still be able to access the file from the browser:

https://drive.google.com/uc?id=1CPSeum3HpopfomUEK1gybeuIVoeJT_Eo

WARNING: AutoGraph could not transform <function Model.make_predict_function..predict_function at 0x000001F2E00AD8B0> and will run it as-is. Please report this to the TensorFlow team. When filing the bug, set the verbosity to 10 (on Linux, export AUTOGRAPH_VERBOSITY=10) and attach the full output. Cause: To silence this warning, decorate the function with @tf.autograph.experimental.do_not_convert {'verified': True, 'distance': 0.0504792375197427, 'max_threshold_to_verify': 0.4, 'model': 'VGG-Face', 'similarity_metric': 'cosine'}

On Thu, Jun 3, 2021 at 4:33 PM Sefik Ilkin Serengil < @.***> wrote:

@ImMainak https://github.com/ImMainak please share the code you are running and the whole exception message you got.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/serengil/deepface/issues/246#issuecomment-853784521, or unsubscribe https://github.com/notifications/unsubscribe-auth/AUKWTCNNWXJYQSNCM6GURJ3TQ5OQPANCNFSM45TYXLCQ .

serengil commented 3 years ago

your trouble is totally different to this issue.

1- use the latest version: 0.0.53

2- download the weight manually from the browser and copy it to the HOME/.deepface/weights folder - follow the instructions in the troubleshooting and faq in the read me of the repo.

ImMainak commented 3 years ago

Thank you for this suggestion.