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
14.24k stars 2.19k forks source link

Deepface is still downloading model even though it is already in a local folder #524

Closed Terminazor closed 2 years ago

Terminazor commented 2 years ago

Hello, I have a usecase where I have to recognize people from a livestream and I found your library and want to test it. I already have a good face-detection AI, so I'm only interested in the recognition part of deepface and use the DeepFace.find() function. I want to test all models: ["VGG-Face", "Facenet", "Facenet512", "OpenFace", "DeepFace", "DeepID", "ArcFace", "Dlib", "SFace"]

I have already downloaded all of the above models and saved them locally in a folder called deepface_models:

deepface_models/arcface_weights.h5
deepface_models/deepid_keras_weights.h5
deepface_models/dlib_face_recognition_resnet_model_v1.dat.bz2
deepface_models/face_recognition_sface_2021dec.onnx
deepface_models/facenet_weights.h5
deepface_models/facenet512_weights.h5
deepface_models/openface_weights.h5
deepface_models/vgg_face_weights.h5
deepface_models/VGGFace2_DeepFace_weights_val-0.9034.h5.zip

I also use Docker to save them where they seem to belong to: COPY deepface_models/ /root/.deepface/weights/

My issue is now, that of all of the models only "DeepFace" (VGGFace2_Deepface) still gets downloaded externally (when DeepFace.find() gets called the first time with model="DeepFace") even though it is available in the "weights" folder. I just don't get it why all other models are loaded from the local folder, but DeepFace isn't.

serengil commented 2 years ago

try this path: ~/.deepface/weights/

also you need to confirm that you copied the weight files not folder to here.

Terminazor commented 2 years ago

I checked the files again and the solution was to simply unzip VGGFace (and Dlib!) weights before building the docker image.

dopaminista commented 2 years ago

@Terminazor How did you unzip weights before building docker image ? Aren't they downloaded from internet in runtime ?
I'm using containerized gcp cloud run service... Same error....

Terminazor commented 2 years ago

@MertTanyur If you watch closely the logs when deepface downloads the models from internet, there is always a path written from where it gets the model. I just followed the links and downloaded the weights manually and saved it locally. In my usecase the user might not have internet so I had to download it beforehand!

The unzip had only to be done with VGGFace2 and dlib model (watch out: adapt the directory to your needs!):

unzip deepface_models/VGGFace2_DeepFace_weights_val-0.9034.h5.zip -d deepface_models/
bzip2 -dk deepface_models/dlib_face_recognition_resnet_model_v1.dat.bz2