2017-09-18 66 views
0

我正嘗試在openFrameworks中使用dlib庫的深層神經網絡部分。到目前爲止,我已經能夠自己構建dlib示例,沒有任何問題。我也一直在使用openFrameworks一段時間,並知道它的構建沒有任何問題。dlib在VS2015中使用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 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中編譯得很好,但第二個代碼塊拋出上面提到的錯誤。我已經能夠將其縮小到編譯器與「net_type net」實例化有關的問題,但一直未能找出原因。

回答

0

不確定在dlib的具體內部,但它看起來有問題與編譯器生成的默認移動構造函數(和潛在的移動賦值運算符);第一個代碼塊只會實例化對象,它不會將它包裝在一個類中。

嘗試刪除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; 
}; 
+0

只是嘗試這樣做。它會導致「沒有適當的默認構造函數」錯誤。 – wildparadox

+0

這有點奇怪,因爲在代碼片段中,實際上並沒有構建一個對象。儘管如此,你可以添加一個默認構造函數。請參閱修改後的代碼片段。 – Chris