I'm getting the import error when trying to run a deepface code for a project I'm working on

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

This is my code

import cv2
from deepface import DeepFace
img1 = "simg.jpb"
img2 = "simg2.jpg"
print ("before")
resp = DeepFace.verify(img1_path=img1m, img2_path=img2)
print ("after")
if resp['verified']:
    print("access granted")
else:
    print("Access denied")

I have tried many solutions that were given here ImportError: cannot import name 'get_config' from 'tensorflow.python.eager.context' and many other sites but still get the same error.

Am running the code on Raspberry Pi 4.

Help is appreciated.

1

There are 1 best solutions below

0
On

I ran into the same issue today. The reason is because the Raspberry Pi is running Tensorflow 1 by default, and you need to upgrade to Tensorflow 2. Use the command below to upgrade to the right Tensorflow version.

pip3 install https://github.com/bitsy-ai/tensorflow-arm-bin/releases/download/v2.4.0-rc2/tensorflow-2.4.0rc2-cp37-none-linux_armv7l.whl

After this, I ran into an ImportError: numpy.core.multiarray failed to import, which was simply fixed by upgrading numpy by running

pip3 install -U numpy 

Hope this helped!