前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >人脸检测dlib, mtcnnx对比,FDDB测试对比

人脸检测dlib, mtcnnx对比,FDDB测试对比

作者头像
bear_fish
发布2018-09-14 09:44:29
2.9K0
发布2018-09-14 09:44:29
举报

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://cloud.tencent.com/developer/article/1338326

问题来源 How does MTCNN perform vs DLIB for face detection?

前面一直做人脸检测相关内容,然后对比了下dib以及MTCNN的人脸检测效果主要是速度,以及FDDB准确率。最后给出生成FDDB测试文件的C++代码。


FDDB 测试结果

注本文的MTCNN效果检测准确率不是最优的,最优的在FDDB上可达95%,测试效果如下:

可以看到三种方法:

  1. MTCNN 大概90%
  2. dlib 大概 77%
  3. opencv 大概 62%

dlib的作者非要说我的测试有问题,如果谁感兴趣可以使用dlib测试下FDDB的结果。


速度

在CPU和GPU模式下,对于三种不同尺寸的图片,运行一千次测试平均的时效:

CPU模式

MTCNN(既检测人脸又做landmark):

dlib (仅仅检测人脸):

GPU模式

MTCNN(既检测人脸又做landmark):

dlib (仅仅检测人脸):

可以看到:

  1. 在检测精度上MTCNN显然好于dlib
  2. 无论是CPU还是GPU模型下MTCNN的检测数度都好于dlib,而且dlib还做了人脸的landmark

dlib c++生成FDDB结果代码如下(至于怎么使用FDDB测试可见前面blog,有py实现)或者我的stackoverflow回答

代码语言:javascript
复制
#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>>>>>>>>;

// ----------------------------------------------------------------------------------------

void getAllImgPaths(const std::string& file, std::vector<std::string>& vecPaths){

    std::fstream fStream(file);
    std::string sLine;

    while (std::getline(fStream, sLine)){
        if (sLine.size() > 0){
            vecPaths.emplace_back(sLine);
        }
    }

    fStream.close();
}

void writeStrVecToFile(const std::string& file, const std::vector<std::string>& vecStr){
    std::ofstream fout(file);
    for (auto const& x:vecStr){
        fout<<x<<'\n';
    }

    fout.close();
}



int main(){

    std::string fPath = "/home/xy/face_sample/evaluation/compareROC/FDDB-folds/filePath.txt";
    std::vector<std::string> vecImgPaths;

    getAllImgPaths(fPath, vecImgPaths);

    std::string imgBaseDir = "/home/xy/face_sample/evaluation/compareROC/originalPics/";
    std::vector<std::string> vecDetRet;

    string model_path = "/home/xy/anaconda2/lib/python2.7/site-packages/face_recognition_models/models/mmod_human_face_detector.dat";
    net_type net;
    deserialize(model_path) >> net;

    for (auto const& img_name:vecImgPaths){
        std::string imgFullPath = imgBaseDir + img_name + ".jpg";

        matrix<rgb_pixel> img;
        load_image(img, imgFullPath);

        auto dets = net(img);
        vecDetRet.push_back(img_name);
        vecDetRet.push_back(std::to_string(dets.size()));

        for (auto det:dets){

            using std::to_string;

            // sFaceInfo like 49 55 193 193 0.999784
            std::string sFaceInfo = to_string(det.rect.left()) + " " + to_string(det.rect.top()) + " " +
                                    to_string(det.rect.width()) + " " + to_string(det.rect.height()) + " " + to_string(1);

            std::cout<<sFaceInfo<<std::endl;
            vecDetRet.push_back(sFaceInfo);

        }

    }

    // write face detect result to txt file for fddb compare
    std::string fddbTxtPath = "fddb_ret.txt";
    writeStrVecToFile(fddbTxtPath, vecDetRet);
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018年07月14日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • FDDB 测试结果
  • 速度
    • CPU模式
      • GPU模式
      相关产品与服务
      人脸识别
      腾讯云神图·人脸识别(Face Recognition)基于腾讯优图强大的面部分析技术,提供包括人脸检测与分析、比对、搜索、验证、五官定位、活体检测等多种功能,为开发者和企业提供高性能高可用的人脸识别服务。 可应用于在线娱乐、在线身份认证等多种应用场景,充分满足各行业客户的人脸属性识别及用户身份确认等需求。
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档