dlib在VS2015中使用OpenFrameWorks模板

dlib Templating with openFrameworks in VS2015

本文关键字:OpenFrameWorks 模板 VS2015 dlib      更新时间:2023-10-16

我正在尝试使用OpenFrameworks内的DLIB库的深神经网络部分。到目前为止,我已经能够自己构建DLIB示例没有任何问题。我也与OpenFrameWorks合作了一段时间,并且知道它可以毫无问题地构建。

每当我尝试整合两者时,我都会在Visual Studio 2015中获得编译问题:

dlib::add_loss_layer<dlib::loss_mmod_,dlib::add_layer<dlib::con_<1,9,9,1,1,4,4,SUBNET,void>>::add_loss_layer(T &&...)': could not deduce template argument for '<unnamed-symbol&gt';

" dnn_mmod_face_detection_ex.cpp"中给出的示例如下:

#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;
}
catch(std::exception& e)
{
    cout << e.what() << endl;
}

在OpenFrameWorks示例中共享的示例与以下方式相同:

#include "ofMain.h"
#include <dlib/dnn.h>
#include <dlib/data_io.h>
#include <dlib/image_processing.h>
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>>>>>>>>;
class ofApp : public ofBaseApp
{
public:
    void setup() override;
    void draw() override;
    net_type net;
};

代码的第一个块在VS2015中填充了罚款,但是第二个块引发了我上面提到的错误。我已经能够将其缩小到以下事实,即编译器在" net_type net"的实例化中存在问题,但无法弄清楚为什么。

不确定dlib的特定内部内容,但似乎与编译器生成的默认移动构建器(以及潜在的移动分配操作员)有问题;第一个代码块仅插入net_type对象,它不会将其包装在类中。

尝试删除ofApp类的移动组件,看看是否有帮助:

class ofApp : public ofBaseApp
{
public:
    ofApp() = default;
    ~ofApp() = default;
    ofApp(ofApp&&) = delete;
    ofApp& operator=(ofApp&&) = delete;
    void setup() override;
    void draw() override;
    net_type net;
};