我试图在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>';
&#34; dnn_mmod_face_detection_ex.cpp&#34;中给出的示例构建神经网络如下:
#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 example中共享的示例与以下内容相同:
#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中编译得很好,但第二个代码会抛出我上面提到的错误。我已经能够将其缩小到这样一个事实:编译器在实例化&#34; net_type net&#34;时出现了问题,但是无法找出原因。
答案 0 :(得分:0)
不确定dlib
的具体内部,但它看起来像编译器生成的默认移动构造函数(以及可能的移动赋值运算符)有问题;第一个代码块仅实例化net_type
对象,它不会将其包装在类中。
尝试删除ofApp
类的move-constructor,看看是否有帮助:
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;
};