serengil / deepface

A Lightweight Face Recognition and Facial Attribute Analysis (Age, Gender, Emotion and Race) Library for Python
https://bit.ly/deepface-py
MIT License
14.68k stars 2.22k forks source link

Advice on how to install GhostFaceNet #1155

Closed oj-random closed 7 months ago

oj-random commented 7 months ago

All models except GhostFaceNet can be installed via pip.

Any hint on how to easily install GhostFaceNet?

serengil commented 7 months ago

What is the problem? I cannot understand.

None of models are being installed via pip.

oj-random commented 7 months ago

If I want to choose a model - lets say 'ArcFace' - in this example

result = DeepFace.verify(img1_path = "img1.jpg",  img2_path = "img2.jpg",  model_name = ArcFace)

It will work out of the box. Also all other models will work this way if I install them like this...

pip install deepface mediapipe dlib facenet-pytorch ultralytics

My question is now how to get the model GhostFaceNet to work?

Do you have any advice on this?

serengil commented 7 months ago

Oh i see, you do not have to do something special if you install the latest deepface.

Just run this

result = DeepFace.verify(img1_path = "img1.jpg", img2_path = "img2.jpg", model_name = "GhostFaceNet")

This will download its pre-trained weights in the background automatically.

oj-random commented 7 months ago

Many thanks for the hint!

I can confirm your solution...

pip install --upgrade deepface
oj-random commented 7 months ago

wait a minute... this piece of code...

resp_objs = DeepFace.represent(
                    img_path=file,
                    model_name="GhostFaceNet",
                    enforce_detection=False,
                    detector_backend="retinaface",
                    align=True,
                    expand_percentage=0,
                    normalization="base",
                )

still throws...

ImportError('Keras cannot be imported. Check that it is installed.')
oj-random commented 7 months ago

This is a bit strange because if I do

sh-5.2$ pip install keras

it shows

Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: keras in /home/nuc/.var/app/com.vscodium.codium/data/python/lib/python3.11/site-packages (2.15.0)

Environment: Debian testing, VSCodium

oj-random commented 7 months ago

BUT the same code works if I combine GhostFaceNet and yolov8

resp_objs = DeepFace.represent(
                    img_path=file,
                    model_name="GhostFaceNet",
                    enforce_detection=False,
                    detector_backend="yolov8",
                    align=True,
                    expand_percentage=0,
                    normalization="base",
                )
serengil commented 7 months ago

What is your tf version? Downgrade it to 2.15 if it is 2.16.

Keras cannot be imported message is not coming from deepface.

oj-random commented 7 months ago

It is not GhostFaceNet that cause the trouble. Instead it is retinaface in combination with some models.

Many thanks for you fast replies and you patience!

I will try a bit more and then report.

And yes - I messed around with the upgrade and the "eager" parameter and it might be a mess now.

oj-random commented 7 months ago

After executing

pip install --upgrade tf-keras==2.15 tensorflow==2.15

the combination of GhostFaceNet and retinaface does work now.

Just for interest.... I included tf-keras==2.15 because the downgrade of tensorflow to 2.15 showed an

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
tf-keras 2.16.0 requires tensorflow<2.17,>=2.16, but you have tensorflow 2.15.0 which is incompatible.

Thanks again for your time and support!

serengil commented 7 months ago

Happy to hear