-
-
Notifications
You must be signed in to change notification settings - Fork 294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Any plans to speed up recognition? #99
Comments
Not right now, no. I'm not experienced enough with machine learning to create my own model, and if i did it would probably be slower than the one used right now. @dmig has made some general optimizations, but they are more to make the code more readable and won't speed things up that much. You can set
So the most time by far is used on importing the |
For me noticeable speedup was gained by rebuilding |
Oh, btw, using normal cam (not IR one) slows down recognition, but gives more reliable result |
My results:
This is probably the best time, it can be up to 2 seconds sometimes. Notice the resolution: I set |
Looking at
All of them except first are available as packages in standard repositories. By default, not finding any, I'll make some tests and rewrite installation script later to choose best available libraries. I have a good feeling. |
Nice work! Does it speed up the per-frame recognition times or the face_recognition import? How much does installing OpenBLAS contribute to installation duration? |
I can't tell how much, since I didn't measure. I'll do that later. Libraries are installed as packages from Ubuntu repos. |
Maybe we have to build howdy as a background service because it's spend most of time on loading the library. The serivice will wake up camera upon authentication request. |
That's possible, but I don't like the approach. I'll try to reduce amount of data loaded. Also, it's possible to rely on filesystem cache to keep libraries in memory most of the time. |
I've also been thinking about offloading the actual recognition to an (optional) deamon. However, compare.py uses about 217MB of memory right now which i think is a bit much to keep reserved. If we could do it though a cache it would be the best of both worlds though. There's also the possibility of multithreading. Right now Howdy just uses 1 core and pushes it to maximum load, but doesn't utilize any of the other 7 on my machine because everything is running in a single thread. I think splitting the recognition into a separate process would also allow us to start multiple instances, increasing the amount of frames we can process. |
@boltgolt that's what I'm addressing right now. It's possible to reduce memory footprint, probably not much, need to test. |
Howdy depends on pam_python, which handles the conversation with the central authentication system. It's a bit outdated though and can only run python2 scripts, which is why pam.py runs in a different version than the rest of the script. I'm looking at alternatives in #9. In my opinion a C++ PAM module that starts compare.py would be the most efficient solution. |
Ok, let me ask another way: why do you use python3? Python2 would be sufficient. |
Python2 will be dropped in 2020, about a year from now. I don't think it's very future proof and all python packages should be moving to 3 relatively soon. |
Until pam_python gets updated to python3 in system repo, we can stick to 2.7. No need to waste time/ram spawning python3 interpreter. |
I don't particularly like the idea rewriting everything except pam.py to python2, which is slowly fading away. A more structural move would be to ditch the pam_python part and directly go from C++ to python3. |
You mean |
No, i mean writing a custom PAM module for Howdy alone. The major upside to this is that it should also be able to ask for simultaneous password input while Howdy is running. |
So, why stick to python code then? |
The honest answer to that is that i started this as a small script just for myself, and i'm much more familiar with python. It's the same reason why we're still depending on pam_python to this day, i'm not comfortable at all with C++. That doesn't mean we shouldn't switch. But my contributions would be much less in C++. |
I found a fork of pam_python which support python3 here https://github.com/minrk/pamela (used in JupyterHub). |
@dmig @boltgolt Original Resolution Improve version |
@sapjunior great! I'm looking into ditching |
Ok, tests finished. Here is a small report. Test HW: Core-i7 8550U, 8GB, SSD (SATA, 6MBit/s), no GPU acceleration used (unfortunately,
I built
Conclusion: More tests needed:
If someone wishes to repeat tests, I'll write some instructions and publish all scripts. |
Next step is -- get rid of |
Another test results. I've rewritten the test in the same way as @sapjunior example.
Most notable change: memory consumption reduced by ~70mb. |
Amazing work man! Very nice and readable with the great graphs. I agree that atlas is the obvious choice if you look at the data. MKL also looks quite good in a lot of tests but i trust your judgement. Would adding atlas be as simple (at least for Ubuntu) as adding |
I think ATLAS is the best choice because MKL is quite large and difficult to install. By the way, I'm trying to port MobileFacenet from https://github.com/deepinsight/insightface by using OpenCV 4.0 ONNX dnn module. This network is quite fast (~40ms inference time) and look promising in term of accuracy as well. |
@boltgolt all these libraries are mutually exclusive. There is no flag to tell
|
@sapjunior MKL is not really difficult to install -- it is available from system repositories, but one of dependencies is packaged wrong way, so one extra package must be installed manually. |
BTW this may help HDD owners:
|
I'll add them as recommended packages for Debian to the next release, thanks! I'd say we add the optimized face_recognition @sapjunior made directly into the code here. Then either keep howdy in memory as a whole or just the .dat files. |
I'd like to know some opinions about I see 2 options: leave it as a dependency or ditch it and download required Right now I tend to the second, because we already download |
If we ditch |
Ok, great. I made modifications to the code and testing them right now. |
Also, I added an option to use CNN for recognition. Test runs 12-15 times slower on my hardware and consumes 200-600MB ram (opposite to 120MB for HOG), but maybe someone with CUDA enabled will find it useful. |
Ok, the new code is in my repository https://github.com/dmig/howdy. Still not thoroughly tested, so not yet making a PR. I want to test a pure python2 version of pam module: this should reduce ram usage by 8-16MB and slightly reduce startup time. Probably, |
Changes look very nice! The speedup would be very welcome and completely dropping face_recognition is a huge improvement. Open PR whenever you're ready. I'm still against moving to python2 though. It's a step backwards in tech that 8 to 16 MB of memory doesn't compensate. Still working on a PAM module in C++ that should probably speed up startup time in a similar fashion. |
Python2 would be not a step backward, but a removal of ad-hoc code. Also, python code may be modified to run on both versions.
That would be great to have and it will give the same memory/startup improvements. |
I've managed to reduce auth time to less than 1 second:
A small gain compared to the previous result, around 250ms:
Some more tests and I'll make a PR. |
That's almost exactly as long as windows hello (on my machine), very nice work! |
That wasn't a final result. Probably this is:
|
I installed your branch, to see what might need to be changed for compatibility with the ffmpeg work I had been doing. It looks like you call a video_capture.grab() function, instead of .read(). In my ffmpeg_reader.py class, we'll need to add that function as a sort of redirect into .read().
Other than that it seems to work, and although the ffmpeg methods are slower than openCV, it looks like the new face recog saves around 500ms on average to the total time taken on my machine. Kudos for the hard work! |
In the spirit of speeding things up... I found a way to ditch ffmpeg, which is horrendously slow, by using fully python v4l2 implementation instead (for my own HP IR camera). :-) I ran a handful of tests. :-)
Original code with FFMPEG class (2210 ms):
Original code with new pyv4l2 class (1565 ms):
New recog code with new pyv4l2 class WITHOUT threading (885 ms):
New recog code with new pyv4l2 class WITH THREADING (748 ms):
|
Looks even better than the FFmpeg option! Again, very nice work! The performance improvement is definitely worth it so i'd add it as a new recorder, just like FFmpeg. I think it's best to keep the FFmpeg option available like it is now on the dev branch, for compatibility with non-v4l devices among other things. |
Sorry for the delay, but the code written by @dmig has now been merged into the dev branch. There were a few issues (a deprecated Github API endpoint for instance), but those are fixed now. The speed upgrade is incredible. Most of my tests succeeded in less than 0.3 seconds, which is just amazing. Because this thread was mostly about those changes and the goal of the author (<2 seconds) has been met i'm closing this issue. |
Right now when I am using howdy with certainty = 5, it usually cost more than 2-3 seconds to authenticate, which is considerably slower than Windows hello (average < 2s speed). Any plan to further improve algorithm?
The text was updated successfully, but these errors were encountered: