ageitgey / face_recognition

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

face_recognition uses only one CPU core. Is there a way to run it multithreaded? #649

Open ls0h opened 6 years ago

ls0h commented 6 years ago

I am working on a program, that should recognize (identify) and track a lot of faces in real time. Face_recognition is not fast enough and it uses only one CPU core. I tried to compile Dlib with Intel MKL and nothing has changed. Even in CNN mode no more than one core is used. But CNN mode was created for multithreaded parallel execution. It runs on CUDA in parallel, why it can not on CPU?

Is it possible to use face_recognition (face_locations and face_encodings) in multithread way? Is it possible on pure Dlib or Is it a restriction within Dlib?

I know that I can make queue of frames and process each frame on it's own core. But this is not an option in my case. I need to find and compare faces on each frame faster to have time to do another processing and inter-frame comparison.

deeptechs commented 6 years ago

There is a description about it in main page:

Speeding up Face Recognition Face recognition can be done in parallel if you have a computer with multiple CPU cores. For example if your system has 4 CPU cores, you can process about 4 times as many images in the same amount of time by using all your CPU cores in parallel.

If you are using Python 3.4 or newer, pass in a --cpus parameter:

$ face_recognition --cpus 4 ./pictures_of_people_i_know/ ./unknown_pictures/ You can also pass in --cpus -1 to use all CPU cores in your system.

ls0h commented 5 years ago

Face recognition can be done in parallel if you have a computer with multiple CPU cores. For example if your system has 4 CPU cores, you can process about 4 times as many images in the same amount of time by using all your CPU cores in parallel. Thank you for your answer.

But I am talking about speeding up of processing one frame (each frame of the video), not an image set. My program should work with a live video stream in real time, it can not wait for a bunch of frames. And for now face_recognition takes too long to compute face detection on each frame, but it uses only one core. So I am need some solution to parallelize it.

deeptechs commented 5 years ago

Sorry for misunderstanding. I don't know if there is such this feature. But you can do some tricks like below example. Off course if your problem is suitable fot it. Lowering resolution, dropping some frames if the source is video etc.. Did you try to build dlib with avx instruction? It is for Cpu optimization in terms of speeding.

https://github.com/ageitgey/face_recognition/blob/master/examples/facerec_from_webcam_faster.py

ryankrage77 commented 5 years ago

In my experience, passing in --cpus 4 or --cpus -1 makes no difference on my 4 core system. Only 1 core is a 98%, the rest are idling.

alexvaa commented 5 years ago

Hi, you will try to speed up the face location part with this https://github.com/arunponnusamy/cvlib I managed to speed up this part 3.5 times. (210ms via 60ms) But recognition is still too slow.

WHLiao commented 5 years ago

N

deeptechs notifications@github.com 於 2018年10月20日 週六 16:36 寫道:

There is a description about it in main page:

Speeding up Face Recognition Face recognition can be done in parallel if you have a computer with multiple CPU cores. For example if your system has 4 CPU cores, you can process about 4 times as many images in the same amount of time by using all your CPU cores in parallel.

If you are using Python 3.4 or newer, pass in a --cpus

parameter: $ face_recognition --cpus 4 ./pictures_of_people_i_know/ ./unknown_pictures/ You can also pass in --cpus -1 to use all CPU cores in your system. — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub , or mute the thread .
nbhupendra commented 4 years ago

Hi, you will try to speed up the face location part with this https://github.com/arunponnusamy/cvlib I managed to speed up this part 3.5 times. (210ms via 60ms) But recognition is still too slow.

How can i use this with face_encoding? Please help.

nbhupendra commented 4 years ago

Hi, you will try to speed up the face location part with this https://github.com/arunponnusamy/cvlib I managed to speed up this part 3.5 times. (210ms via 60ms) But recognition is still too slow.

@alexvaa How can i use this with face_encoding? Please help.