ageitgey / face_recognition

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

MMOD face detector and GPU question #14

Closed Cospel closed 7 years ago

Cospel commented 7 years ago
  1. Hi is it possible to implemenet MMOD CNN as face detector instead of or as alternative to HOG which is used currently?

http://blog.dlib.net/2016/10/easily-create-high-quality-object.html

This can even improve this awesome package!

  1. I have also one question about gpu, is it possible to run face_encodings on gpu?

Thank you!

ageitgey commented 7 years ago
  1. Great question. I looked into it. The problem is that dlib's CNN interface isn't available from python and I don't think @davisking has any plans to support that interface from Python (because of how it's written). So I don't think it's (easily) possible.

  2. I think it will use a gpu if you compile dlib with CUDA support, but I can't remember for sure. I'll try recompiling it on my linux machine when I have a minute and check.

ageitgey commented 7 years ago

Yeah, it seems to use the GPU when you compile dlib with CUDA support. Here's what the card reports when running face_recognition.face_encodings() in a loop (passing in face locations so it doesn't have to re-look that up each time):

$ nvidia-smi 
Fri Mar 17 16:51:41 2017       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 367.57                 Driver Version: 367.57                    |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce GTX 980 Ti  Off  | 0000:01:00.0      On |                  N/A |
|  0%   47C    P2    78W / 250W |    842MiB /  6074MiB |     39%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID  Type  Process name                               Usage      |
|=============================================================================|
|    0      1251    G   /usr/lib/xorg/Xorg                             197MiB |
|    0      6181    C   python3                                        283MiB |

With GPU support, it took me a little under a minute to calculate 10,000 face encodings. For comparison, my laptop (different hardware) without a GPU took over 4 min to do the same thing.

davisking commented 7 years ago

It's certainly possible to make a python API for the CNN face detector model. Although as @ageitgey mentioned, it's impossible to make a full wrapper for the entire DNN API in python because python lacks the core language mechanics to deal with the C++ API. But that's not what you are asking about.

As for GPU use. If you compile dlib to use CUDA it will use CUDA, if you don't then it won't. This has nothing to do with using python or anything else.

davisking commented 7 years ago

Also, I'm in general not very motivated to add dlib python wrappers since I hardly ever use pyhton myself. So someone else should do it and submit a PR :)

ageitgey commented 7 years ago

Fair enough @davisking. Thanks for the reply!

Cospel commented 7 years ago

Thank you for your answers!

What I have now is face detection based on facenet/openface https://github.com/davidsandberg/facenet. And face recognition or better say face descriptor from dlib/resnet/face_recognition.

My expertise in C++ is very bad and it is few years that I last touch it. However I tried to play with C++ Boost to port MMOD CNN to the python but with no success.

xinshengdehuamei commented 7 years ago

@ageitgey How can i compile the dlib with CUDA support ? Usually I use 'python setup.py install' to install the dlib in Ubantu. How can I make sure the dlib with CUDA support is successful ?

davisking commented 7 years ago

When you build it there are a bunch of messages that print. Some of them talk about CUDA and you can see if it's being used or not.

xinshengdehuamei commented 7 years ago

@davisking Yes, thank you !

ageitgey commented 7 years ago

@Cospel I submitted a dlib python wrapper for the mmod cnn face detector. So I should be able to make that an option in face_recognition when the next dlib update is released.

yanglixiao1994 commented 4 years ago

@davisking Hi. I already compiled dlib with cuda enable. image In c++ code,dlib::cuda::get_num_devices()==1,but dlib::cuda::get_device_name=="CUDA_DISABLED".And MMOD face detector use the cpu version instead of cuda.Do you have any idea?