dlib Templating with openFrameworks in VS2015

119 views Asked by At

I'm trying to use the deep neural network portion of the dlib library inside openFrameworks. So far I've been able to build dlib examples by themselves without any problem. I've also been working with openFrameworks for some time and know that it builds without any problem.

Whenever I try to integrate the two though, I get a compile issue in 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';

The example given in "dnn_mmod_face_detection_ex.cpp" constructs the neural network as follows:

#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;
}

The example shared in the openFrameworks example does the same as follows:

#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;
};

The first block of code compiles fine in VS2015, but the second throws the error I mentioned above. I've been able to narrow it down to the fact that the compiler has an issue with the instantiation of "net_type net", but have not been able to figure out why.

1

There are 1 answers

2
Chris On

Not sure on the specific internals of dlib, but it looks like it's having problems with the compiler-generated default move-constructor (and potentially move-assignment operator); the first code block only instanciates the net_type object, it doesn't wrap it in a class.

Try deleting the move-constructor of the ofApp class and see if that helps:

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;
};