许可优化
许可优化
产品
产品
解决方案
解决方案
服务支持
服务支持
关于
关于
软件库
当前位置:服务支持 >  软件文章 >  Dlib训练人脸关键点检测器(194关键点)

Dlib训练人脸关键点检测器(194关键点)

阅读数 5
点赞 0
article_banner

转自:https://blog.csdn.net/longji/article/details/77984753

版权声明:技术分享,csdn longji https://blog.csdn.net/longji/article/details/77984753

01 dlib 人脸检测 器原始数据获取

68个关键点的训练 数据集  (1.7GB):http://dlib.net/files/data/ibug_300W_large_face_landmark_dataset.tar.gz

   194个关键点的数据集(需要翻墙):http://stackoverflow.com/questions/36711905/dlib-train-shape-predictor-ex-cpp?answertab=votes#tab-top

02 训练代码

dlib中examples中的代码。

   dlib/examples/train_shape_predictor_ex. cpp

// dlib/examples/train_shape_predictor_ex.cpp#include <dlib/image_processing.h>#include <dlib/data_io.h>#include <iostream> using namespace dlib;using namespace std; std::vector<std::vector<double> > get_interocular_distances (    const std::vector<std::vector<full_object_detection> >& objects); int main(int argc, char** argv){    try    {        if (argc != 2)        {            cout << "Give the path to the examples/faces directory as the argument to this" << endl;            cout << "program. For example, if you are in the examples folder then execute " << endl;            cout << "this program by running: " << endl;            cout << " ./train_shape_predictor_ex faces" << endl;            cout << endl;            return 0;        }        const std::string faces_directory = argv[1];        dlib::array<array2d<unsigned char> > images_train, images_test;        std::vector<std::vector<full_object_detection> > faces_train, faces_test;        // 1. 载入训练集,测试集        // load_image_dataset(images_train, faces_train, faces_directory+"/training_with_face_landmarks.xml");        // load_image_dataset(images_test, faces_test, faces_directory+"/testing_with_face_landmarks.xml");        // 68个点的训练数据集:http://dlib.net/files/data/ibug_300W_large_face_landmark_dataset.tar.gz        load_image_dataset(images_train, faces_train, faces_directory + "/labels_ibug_300W_train.xml");        load_image_dataset(images_test, faces_test, faces_directory + "/labels_ibug_300W_test.xml");         shape_predictor_trainer trainer;         // 测试中调节了 tree_depth参数:2,4, 5, 10        // 测试机器为8核,set_num_threads使用8,训练时cpu:70%        trainer.set_oversampling_amount(300);        trainer.set_nu(0.05);        trainer.set_tree_depth(5);        trainer.set_num_threads(8);        trainer.be_verbose();        // 训练        shape_predictor sp = trainer.train(images_train, faces_train);         cout << "mean training error: "<<             test_shape_predictor(sp, images_train, faces_train, get_interocular_distances(faces_train)) << endl;         cout << "mean testing error: "<<             test_shape_predictor(sp, images_test, faces_test, get_interocular_distances(faces_test)) << endl;        // 保存模型        serialize("sp.dat") << sp;        std::string str;        std::cin >> str;    }    catch (exception& e)    {        cout << "\nexception thrown!" << endl;        cout << e.what() << endl;    }} double interocular_distance (    const full_object_detection& det){    dlib::vector<double,2> l, r;    double cnt = 0;     for (unsigned long i = 36; i <= 41; ++i)     {        l += det.part(i);        ++cnt;    }    l /= cnt;     cnt = 0;    for (unsigned long i = 42; i <= 47; ++i)     {        r += det.part(i);        ++cnt;    }    r /= cnt;     return length(l-r);} std::vector<std::vector<double> > get_interocular_distances (    const std::vector<std::vector<full_object_detection> >& objects){    std::vector<std::vector<double> > temp(objects.size());    for (unsigned long i = 0; i < objects.size(); ++i)    {        for (unsigned long j = 0; j < objects[i].size(); ++j)        {            temp[i].push_back(interocular_distance(objects[i][j]));        }    }    return temp;}

03 训练结果

194关键点训练情况:

   tree_depth=2,num_threads=2,

   Release版本训练时间 5+小时
Debug  版本训练时间 148+小时(训练一定要使用Release版本)

   tree_depth=2,sp.dat=44.6MB,占用内存最大11GB

   tree_depth=10,sp.data=11GB

68关键点训练结果:

   tree_depth=2,num_threads=8, CPU  :70% 内存:20+GB 6+小时 sp.data=15.8MB

   tree_depth=4,num_threads=8,CPU:70% 内存:20+GB 12+小时 sp.data=63.3MB

   tree_depth=5,num_threads=8,CPU:70% 内存:20+GB 16+小时 sp.data=126MB

tree_depth=5,num_threads=8mean training error: 0.0479476mean testing error:  0.0586204

04 测试效果

使用dlib中examples中的代码测试。

   dlib/examples/face_landmark_detection_ex.cpp

   也可食用dlib提供的训练 模型  
http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2

原图:
原图

   检测效果图:
检测效果图

05 参考

http://blog.csdn.net/jcx1314/article/details/65937839
http://blog.csdn.net/elaine_bao/article/details/53054533


免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删



相关文章
技术文档
QR Code
微信扫一扫,欢迎咨询~
customer

online

联系我们
武汉格发信息技术有限公司
湖北省武汉市经开区科技园西路6号103孵化器
电话:155-2731-8020 座机:027-59821821
邮件:tanzw@gofarlic.com
Copyright © 2023 Gofarsoft Co.,Ltd. 保留所有权利
遇到许可问题?该如何解决!?
评估许可证实际采购量? 
不清楚软件许可证使用数据? 
收到软件厂商律师函!?  
想要少购买点许可证,节省费用? 
收到软件厂商侵权通告!?  
有正版license,但许可证不够用,需要新购? 
联系方式 board-phone 155-2731-8020
close1
预留信息,一起解决您的问题
* 姓名:
* 手机:

* 公司名称:

姓名不为空

姓名不为空

姓名不为空
手机不正确

手机不正确

手机不正确
公司不为空

公司不为空

公司不为空