Hey I am using the following code from face_recognition github: code Everything works out beside that I am getting 2 fps/sec when It detects a face, when it is not, the frame rate is ~30.
I looked up on task manager to see how's my computer doing and The CPU is on ~15% as well as the GPU so it isn't hardware problem. I also tried changing the resolution to 320x240 but It did nothing same problem.
How can I increase the fps? Edit: I have only one encoding to process so multi threading will probably not help
There are two processing steps to this program:
In the while loop, face_detection searches for faces in the frame, and then encodes them (uses linear algebra to simplify the face data into unique vectors).
In the for loop (which only runs once a face is detected), the program runs the encoding from step 1 against all other "known" encodings, returning the best match if it meets the default threshold of certainty.
If you have modified the code at all, increasing the number of "known" faces, it would slow the process down some. Also, I do not know how optimized the threading is. It is possible that some of the program is running on a single thread, which would show lower CPU usage even though the program is maxing what it has efficient access to.
Troubleshooting steps: Inside of loop #2 (the for loop), start by commenting out the framing lines (or everything after compare_faces), and see if it speeds up. That way you can narrow in on what is taking the most processing power. If you find that compare_faces IS the bottleneck, try decreasing the number of "known" faces. If that drastically increases fps, it is likely you are limited by number of cores/threading.
The example code you are using is a less optimized version. Here is a slightly faster version. Tweaks include:
Process each video frame at 1/4 resolution (though still display it at full resolution)
Only detect faces in every other frame of video.
Basically by decreasing the amount of processing it will speed up the processing rate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With