dlib 14 dlib自带demo 基于DNN的人脸检测
2017-09-20 23:03
686 查看
01 资源
代码:dlib\examples\dnn_mmod_face_detection_ex.cpp工程名:dnn_mmod_face_detection_ex
测试图像文件:
dlib\examples\faces\2008_001009.jpg
dlib\examples\faces\training.xml
dlib\examples\faces\testing.xml
从代码注释中可以获得model数据文件:
http://dlib.net/files/mmod_human_face_detector.dat.bz2
把上面获得的压缩包内容分别解压到data目录下:
\dlib\data\mmod_human_face_detector.dat
02 项目设置
把examples解决方案中的dnn_mmod_face_detection_ex工程设置为启动项。如需调试,使用debug。使用release运行速度会快一些。
配置属性==>调试==>命令参数==>..\..\..\data\mmod_human_face_detector.dat ..\..\..\examples\faces\2008_001009.jpg 配置属性==>调试==>工作目录==>$(OutDir)
03 运行结果
04 代码
dlib\examples\dnn_mmod_face_detection_ex.cpp// The contents of this file are in the public domain. See LICENSE_FOR_EXAMPLE_PROGRAMS.txt /* This example shows how to run a CNN based face detector using dlib. The example loads a pretrained model and uses it to find faces in images. The CNN model is much more accurate than the HOG based model shown in the face_detection_ex.cpp example, but takes much more computational power to run, and is meant to be executed on a GPU to attain reasonable speed. For example, on a NVIDIA Titan X GPU, this example program processes images at about the same speed as face_detection_ex.cpp. Also, users who are just learning about dlib's deep learning API should read the dnn_introduction_ex.cpp and dnn_introduction2_ex.cpp examples to learn how the API works. For an introduction to the object detection method you should read dnn_mmod_ex.cpp TRAINING THE MODEL Finally, users interested in how the face detector was trained should read the dnn_mmod_ex.cpp example program. It should be noted that the face detector used in this example uses a bigger training dataset and larger CNN architecture than what is shown in dnn_mmod_ex.cpp, but otherwise training is the same. If you compare the net_type statements in this file and dnn_mmod_ex.cpp you will see that they are very similar except that the number of parameters has been increased. Additionally, the following training parameters were different during training: The following lines in dnn_mmod_ex.cpp were changed from mmod_options options(face_boxes_train, 40*40); trainer.set_iterations_without_progress_threshold(300); to the following when training the model used in this example: mmod_options options(face_boxes_train, 80*80); trainer.set_iterations_without_progress_threshold(8000); Also, the random_cropper was left at its default settings, So we didn't call these functions: cropper.set_chip_dims(200, 200); cropper.set_min_object_height(0.2); The training data used to create the model is also available at http://dlib.net/files/data/dlib_face_detection_dataset-2016-09-30.tar.gz */ #include <iostream> #include <dlib/dnn.h> #include <dlib/data_io.h> #include <dlib/image_processing.h> #include <dlib/gui_widgets.h> using namespace std; using namespace dlib; // ---------------------------------------------------------------------------------------- template <long num_filters, typename SUBNET> using con5d = con<num_filters,5,5,2,2,SUBNET>; template <long num_filters, typename SUBNET> using con5 = con<num_filters,5,5,1,1,SUBNET>; template <typename SUBNET> using downsampler = relu<affine<con5d<32, relu<affine<con5d<32, relu<affine<con5d<16,SUBNET>>>>>>>>>; template <typename SUBNET> using rcon5 = relu<affine<con5<45,SUBNET>>>; using net_type = loss_mmod<con<1,9,9,1,1,rcon5<rcon5<rcon5<downsampler<input_rgb_image_pyramid<pyramid_down<6>>>>>>>>; // ---------------------------------------------------------------------------------------- int main(int argc, char** argv) try { if (argc == 1) { cout << "Call this program like this:" << endl; cout << "./dnn_mmod_face_detection_ex mmod_human_face_detector.dat faces/*.jpg" << endl; cout << "\nYou can get the mmod_human_face_detector.dat file from:\n"; cout << "http://dlib.net/files/mmod_human_face_detector.dat.bz2" << endl; return 0; } net_type net; deserialize(argv[1]) >> net; image_window win; for (int i = 2; i < argc; ++i) { matrix<rgb_pixel> img; load_image(img, argv[i]); // Upsampling the image will allow us to detect smaller faces but will cause the // program to use more RAM and run longer. while(img.size() < 1800*1800) pyramid_up(img); // Note that you can process a bunch of images in a std::vector at once and it runs // much faster, since this will form mini-batches of images and therefore get // better parallelism out of your GPU hardware. However, all the images must be // the same size. To avoid this requirement on images being the same size we // process them individually in this example. auto dets = net(img); win.clear_overlay(); win.set_image(img); for (auto&& d : dets) win.add_overlay(d); cout << "Hit enter to process the next image." << endl; cin.get(); } } catch(std::exception& e) { cout << e.what() << endl; }
相关文章推荐
- dlib 04 dlib自带demo 基于HOG的人脸特征检测
- dlib 15 dlib自带demo 基于DNN的车辆检测
- dlib 17 dlib自带demo 基于DNN的车辆检测模型训练
- 玩转Android Camera开发(五):基于Google自带算法实时检测人脸并绘制人脸框(网络首发,附完整demo)
- 玩转Android Camera开发(五):基于Google自带算法实时检测人脸并绘制人脸框(网络首发,附完整demo)
- dlib 05 dlib自带demo 人脸检测
- 基于Google自带算法实时检测人脸并绘制人脸框(网络首发,附完整demo)
- dlib 07 dlib自带demo 基于DNN的人脸识别
- dlib 13 dlib自带demo DNN狗脸检测
- 【AdaBoost算法】基于OpenCV实现人脸检测Demo
- dlib 03 dlib自带demo 人脸关键点检测器训练和测试
- dlib 12 dlib自带demo DNN基础demo
- 人脸关键点检测 ubuntu 16.04 + DLib + GPU(CUDA9 + cudnn7.0.5)
- dlib 08 dlib自带demo 基于ResNet34的imagenet图像分类
- 利用opencv,dlib,python编写人脸检测程序
- win10的visual studio 2015 安装opencv3.1,并且编写demo人脸检测
- 基于CNN的人脸相似度检测
- 基于肤色和眼睛定位的人脸检测算法——MATLAB实现【转】
- 基于Face++实现的人脸检测(年龄检测)Android程序
- 基于OpenCV的人脸检测——C++和Python实现