Ask Your Question

DLIB hack - for improving face detection rate

asked 2018-02-26 06:16:46 -0500

Ivan888 gravatar image

updated 2018-02-26 06:17:02 -0500

Hi guys!

I have one quick question regarding DLIB, and would appreciate your help!

I noticed HAAR has less face detection rate comparing to DLIB (DLIB is more reliable). But DLIB has its lacks also.

For example, it fails to detect face of woman that covers one eye with hair. Is there any way to get around this (or only way is to train my own model)?

Many thanks! :) Ivan

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2018-02-26 07:18:46 -0500

mshabunin gravatar image

Check the latest DNN-based face detector: (python version:

The model is here: (FP16 model:

It consumes ~ 11 Mb memory for weights plus 38 Mb for blobs and runs at 40 ms per frame (25 FPS) on Core-i7. Also there can be possibility to offload processing to GPU using OpenCL backend.

Finally you can train your own model:

edit flag offensive delete link more


Thanks alot!

I will try to play with it...

So obviously DLIB has its limits and DNN approach is better!

Ivan888 gravatar imageIvan888 ( 2018-02-26 08:45:29 -0500 )edit

BTW, DLib also has DNN support but I don't know any details.

mshabunin gravatar imagemshabunin ( 2018-02-26 12:32:57 -0500 )edit

@Ivan888 here is a Python tutorial on how to use the DNN-based face detector that you may be interested in (published today!)

phillity gravatar imagephillity ( 2018-02-26 19:18:50 -0500 )edit

Thanks alot guys!!

Do you know how to run this file (resnet_ssd_face.cpp) in a single separated (independent) folder? Maybe special version of CMakeLists.txt should be used...

Python code version works perfectly, but when I try to run .cpp file I get following error:

OPENCV Error: Unspecified error (FAILED: fs.is_open(): Cant open "") in ReadProtoFromTextFile, file tmp/opencv-20180113-80339-d8g5mw/opencv-3.4.0/modules/dnn/src/caffe/caffe_io,cpp, line 1119...

Abort trap: 6
Ivan888 gravatar imageIvan888 ( 2018-02-28 08:50:04 -0500 )edit

You need to supply file path to the prototext and model files as command line arguments. Then the command line arguments will be used for these lines:

String modelConfiguration = parser.get<string>("proto");
String modelBinary = parser.get<string>("model");

That way you can successfully load the model at this line:

dnn::Net net = readNetFromCaffe(modelConfiguration, modelBinary);

In the python version, these paths are hard-coded into the script:

prototxt = 'face_detector/deploy.prototxt'
caffemodel = 'face_detector/res10_300x300_ssd_iter_140000.caffemodel'

If you want, in the C++ version you can hardcode the modelConfiguration and modelBinary to equal the paths to these files the same way as the Python version. This way you won't need to supply them as arguments

phillity gravatar imagephillity ( 2018-02-28 11:51:12 -0500 )edit

Amazing! Thanks @phillity !

Ivan888 gravatar imageIvan888 ( 2018-03-01 02:33:59 -0500 )edit

Question Tools

1 follower


Asked: 2018-02-26 06:16:46 -0500

Seen: 1,983 times

Last updated: Feb 26 '18