ageitgey / face_recognition

The world's simplest facial recognition api for Python and the command line
MIT License
52.84k stars 13.43k forks source link

save "known people" face detection to local db or similar #982

Open Sparviero-Sughero opened 4 years ago

Sparviero-Sughero commented 4 years ago

Description

face_detection need to scan "known_people" directory every time. in "known_people" directory I've 20 people and face_detection need a lot of time to "learn" before search known peoples inside new photos (unknown_pictures directory contain 2 photos). it's possible to cache "learn" analisys to emprove performances?

What I Did

# time face_recognition --cpus 4 ./known_people/ ./unknown_pictures/
WARNING: More than one face found in ./known_people/fenice_felce.jpg. Only considering the first face.
./unknown_pictures/01.jpg,formica_coriandolo
./unknown_pictures/01.jpg,formica_coriandolo
./unknown_pictures/01.jpg,iora_lenticchia
./unknown_pictures/02.jpg,unknown_person
./unknown_pictures/02.jpg,unknown_person
./unknown_pictures/02.jpg,cervo_volante_ginepro
./unknown_pictures/02.jpg,formica_coriandolo
./unknown_pictures/02.jpg,iora_lenticchia
./unknown_pictures/02.jpg,unknown_person
./unknown_pictures/02.jpg,formichiere_carota

real    0m48,144s
user    0m41,635s
sys     0m2,683s
ziadkadry99 commented 4 years ago

I'm having the same issue mostly focusing on an efficient way to save the face encodings. What i did though is use the pickle library to dump out a list of face encodings to a file and load it rather than encoding them again every time you start it. The only thing i'm not sure about with this is if it would scale up well or not since i'm not entirely sure if i have a huge list of encodings saved out to a file would loading it through pickle be slow or efficient

Good luck, I'll update you with my results

Sparviero-Sughero commented 4 years ago

tnx for answer ziadkadry99 I've downloaded py code from https://www.pyimagesearch.com/2018/09/24/opencv-face-recognition/ I'm not a py developer but the code it's simple and maybe it's possible to remove Xserver's stuff and reach our objective.

ziadkadry99 commented 4 years ago

I consulted the stackoverflow community with my ideas here's a link to the answer i got:

https://stackoverflow.com/questions/59004129/storing-a-list-of-face-encodings-in-python-for-face-identification/59005229#59005229

The pickle module would indeed be a good simple solution as well as MongoDB

Sparviero-Sughero commented 4 years ago

I'm using recognize.py from https://www.pyimagesearch.com/2018/09/24/opencv-face-recognition/ I've modified the py code after proba = preds[j] with this

name = le.classes_[j]
text = "{} ({:.2f}%)".format(name, proba * 100)
print "[FOUND]",text,"(",args["image"],")"
cv2.waitKey(0)
HananAhmadHunain commented 4 years ago

I'm having the same issue mostly focusing on an efficient way to save the face encodings. What i did though is use the pickle library to dump out a list of face encodings to a file and load it rather than encoding them again every time you start it. The only thing i'm not sure about with this is if it would scale up well or not since i'm not entirely sure if i have a huge list of encodings saved out to a file would loading it through pickle be slow or efficient

Good luck, I'll update you with my results

I liked your @ziadkadry99 idea of saving encoding to a file. What happens when you need to load a new face would it encode all faces again? or can i append in the previous file? Can you share your code which writes encoding to a file?

HAKANMAZI commented 4 years ago

https://github.com/HAKANMAZI/Python-Tutorials-/blob/master/FaceRecognation/From_DigitalFoto_to_MSSQL_Update.py

Here is my way, face of 128d features to mssql database.

Lmovadia commented 4 years ago

It is an interesting topic .will keep my eyes on .

alessiosavi commented 4 years ago

Another approach can be let a neural network "study" the face encodings. I've used this approach in PyRecognizer. The time to predict the face is instant (few milliseconds) with a dataset of 311 people (celebrities), and a total of 5425 photos.

r3x07 commented 4 years ago

@HAKANMAZI anyways to make it save from a live webcam ? i mean when it sees my face it saved in a file that it saw my face