如何在 dlib 正面面部检测器中拆分级联级别?

How to split cascades levels in dlib frontal face detector?

跟进:openface/issue/157

我正在尝试将 dlib 正面面部检测器中的五级级联拆分为三级(正面,正面但向左旋转,正面但向右旋转)

Evgeniy suggested to split the detector in C++. I am not familiar with C++. When I look into frontal_face_detector.h, get_serialized_frontal_faces returns 一个base64编码的对象。

我学会了如何将现有检测器保存到 .svm 文件中:

#include <dlib/image_processing/frontal_face_detector.h>
#include <iostream>

using namespace dlib;
using namespace std;

int main()
{   
    frontal_face_detector detector = get_frontal_face_detector(); 

    dlib::serialize("new_detector.svm") << detector;  

    std::cout<<"End of the Program"<<endl;
    return 0;   
}

那么如何拆分级联并将新检测器保存到 .svm 文件?

frontal_face_detector.h 中,通过将金字塔级别从 <6> 降低到较低的值,检测器性能也会提高吗?

只需阅读 object detector documentation,您就会找到解释。 下面是将检测器拆分成多个部分、重建原始文件并限制金字塔级别的代码:

#include <dlib/image_processing/frontal_face_detector.h>
#include <iostream>
#include <string>

using namespace dlib;
using namespace std;

int main()
{   
    frontal_face_detector detector = get_frontal_face_detector(); 

    dlib::serialize("current.svm") << detector;

    std::vector<frontal_face_detector> parts;
    // Split into parts and serialize to disk
    for (unsigned long i = 0; i < detector.num_detectors(); ++i)
    {
        dlib::frontal_face_detector part(detector.get_scanner(), detector.get_overlap_tester(), detector.get_w(i));
        dlib::serialize("part" + std::to_string(i) + ".svm") << part;
        parts.push_back(part);
    }

    // Reconstruct original detector
    frontal_face_detector reconstructed(parts);
    dlib::serialize("reconstructed.svm") << reconstructed;

    // Create detector that will work only on one level of pyramid
    typedef dlib::scan_fhog_pyramid<dlib::pyramid_down<6> > image_scanner_type;
    image_scanner_type scanner;
    scanner.copy_configuration(detector.get_scanner());
    scanner.set_max_pyramid_levels(1); //try setting to 2, 3...
    frontal_face_detector one_level_detector = dlib::object_detector<image_scanner_type>(scanner, detector.get_overlap_tester(), detector.get_w());

    std::cout<<"End of the Program"<<endl;
    return 0;   
}

并且不,将金字塔级别从 <6> 更改为任何其他值不会有太大帮助,因为 6 不是金字塔级别的限制,而是金字塔级别的比例金字塔尺度:

6 = 5/6

5 = 4/5

...