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

I get "cannot import name 'get_config'" error when trying to import DeepFace #331

Closed kyuhyong closed 3 years ago

kyuhyong commented 3 years ago

Hello, I am trying to run deepface for image stream from a webcam. I am running ubuntu 18.04 on a laptop with nvidia rtx2060 and I installed CUDA 11.4 CUDNN 8.2.2 Below is output from nvcc --version

$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Wed_Jun__2_19:15:15_PDT_2021
Cuda compilation tools, release 11.4, V11.4.48
Build cuda_11.4.r11.4/compiler.30033411_0

For some reason, I was only able to install deepface by pip3 install deepface with below process.

$ sudo apt install python-pip
$ pip install --upgrade pip
$ pip3 install scikit-build
$ pip3 install deepface
Successfully built gdown Pillow termcolor grpcio wrapt
Failed to build opencv-python
Installing collected packages: filelock, urllib3, idna, certifi, charset-normalizer, PySocks, requests, six, tqdm, gdown, numpy, opencv-python, astor, keras-preprocessing, protobuf, wheel, termcolor, tensorflow-estimator, gast, grpcio, typing-extensions, zipp, importlib-metadata, markdown, setuptools, dataclasses, Werkzeug, absl-py, tensorboard, cached-property, h5py, keras-applications, google-pasta, wrapt, tensorflow, keras, click, MarkupSafe, Jinja2, itsdangerous, Flask, Pillow, pytz, python-dateutil, pandas, mtcnn, retina-face, deepface
  Running setup.py install for opencv-python ... |
done
Successfully installed Flask-2.0.1 Jinja2-3.0.1 MarkupSafe-2.0.1 Pillow-8.3.2 PySocks-1.7.1 Werkzeug-2.0.1 absl-py-0.13.0 astor-0.8.1 cached-property-1.5.2 certifi-2021.5.30 charset-normalizer-2.0.4 click-8.0.1 dataclasses-0.8 deepface-0.0.68 filelock-3.0.12 gast-0.5.2 gdown-3.13.0 google-pasta-0.2.0 grpcio-1.39.0 h5py-3.1.0 idna-3.2 importlib-metadata-4.8.1 itsdangerous-2.0.1 keras-2.6.0 keras-applications-1.0.8 keras-preprocessing-1.1.2 markdown-3.3.4 mtcnn-0.1.1 numpy-1.19.5 opencv-python-4.5.3.56 pandas-1.1.5 protobuf-3.17.3 python-dateutil-2.8.2 pytz-2021.1 requests-2.26.0 retina-face-0.0.5 setuptools-57.4.0 six-1.16.0 tensorboard-1.14.0 tensorflow-1.14.0 tensorflow-estimator-1.14.0 termcolor-1.1.0 tqdm-4.62.2 typing-extensions-3.10.0.2 urllib3-1.26.6 wheel-0.37.0 wrapt-1.12.1 zipp-3.5.0

In my face_analysis.py

from deepface import DeepFace
import cv2

And run it by python3 face_analysis.py gives below error

Traceback (most recent call last):
  File "face_analysis.py", line 3, in <module>
    from deepface import DeepFace
  File "/home/cto/.local/lib/python3.6/site-packages/deepface/DeepFace.py", line 15, in <module>
    from deepface.basemodels import VGGFace, OpenFace, Facenet, Facenet512, FbDeepFace, DeepID, DlibWrapper, ArcFace, Boosting
  File "/home/cto/.local/lib/python3.6/site-packages/deepface/basemodels/VGGFace.py", line 9, in <module>
    from keras.models import Model, Sequential
  File "/home/cto/.local/lib/python3.6/site-packages/keras/__init__.py", line 25, in <module>
    from keras import models
  File "/home/cto/.local/lib/python3.6/site-packages/keras/models.py", line 19, in <module>
    from keras import backend
  File "/home/cto/.local/lib/python3.6/site-packages/keras/backend.py", line 36, in <module>
    from tensorflow.python.eager.context import get_config
ImportError: cannot import name 'get_config'

For reference, import tensorflow as tf works print(tf.version) gives 1.14.0

import keras didn't work and instead from tensorflow import keras works and print(keras.version) gives 2.2.4-tf

How to solve this error? What am I doing wrong?

serengil commented 3 years ago

could you run the following command?

pip uninstall tensorflow pip install tensorflow==2.2.0

kyuhyong commented 3 years ago

Thank you for your reply. I tried as you explained but could not find 2.2.0 with below error message.

ERROR: Could not find a version that satisfies the requirement tensorflow==2.2.0 (from versions: 0.12.0rc0, 0.12.0rc1, 0.12.0, 0.12.1, 1.0.0, 1.0.1, 1.1.0rc0, 1.1.0rc1, 1.1.0rc2, 1.1.0, 1.2.0rc0, 1.2.0rc1, 1.2.0rc2, 1.2.0, 1.2.1, 1.3.0rc0, 1.3.0rc1, 1.3.0rc2, 1.3.0, 1.4.0rc0, 1.4.0rc1, 1.4.0, 1.4.1, 1.5.0rc0, 1.5.0rc1, 1.5.0, 1.5.1, 1.6.0rc0, 1.6.0rc1, 1.6.0, 1.7.0rc0, 1.7.0rc1, 1.7.0, 1.7.1, 1.8.0rc0, 1.8.0rc1, 1.8.0, 1.9.0rc0, 1.9.0rc1, 1.9.0rc2, 1.9.0, 1.10.0rc0, 1.10.0rc1, 1.10.0, 1.10.1, 1.11.0rc0, 1.11.0rc1, 1.11.0rc2, 1.11.0, 1.12.0rc0, 1.12.0rc1, 1.12.0rc2, 1.12.0, 1.12.2, 1.12.3, 1.13.0rc0, 1.13.0rc1, 1.13.0rc2, 1.13.1, 1.13.2, 1.14.0rc0, 1.14.0rc1, 1.14.0, 1.15.0rc0, 1.15.0rc1, 1.15.0rc2, 1.15.0rc3, 1.15.0, 2.0.0a0, 2.0.0b0, 2.0.0b1, 2.0.0rc0, 2.0.0rc1, 2.0.0rc2, 2.0.0, 2.1.0rc0, 2.1.0rc1, 2.1.0rc2, 2.1.0)
ERROR: No matching distribution found for tensorflow==2.2.0
kyuhyong commented 3 years ago

I was finally able to use deepface after upgrading python3.6 to python3.8 and install tensorflow=2.2.0 as below command For upgrading python3.6 to python3.8 https://www.itsupportwale.com/blog/how-to-upgrade-to-python-3-8-on-ubuntu-18-04-lts/

After upgrading, install python3-testresources $ sudo apt install python3-testresources

Install tensorflow 2.2.0 by pip3 install tensorflow==2.2.0

Re install deepface $ pip3 install deepface

Then everything works fine! Thanks