Search code examples
c++classneural-networkprivatedlib

dlib mlp::kernel_1a_c member initialization inside a class


I'm using dlib with the neural network example. dlib neural network

I get the error:

error: no matching function for call to ‘dlib::mlp_kernel_c::mlp_kernel_c()

I am trying to initialize the

"mlp::kernel_1a_c net(2,5);"

variable inside a class, but I get all kinds of errors. Here is the piece of code relevant to my issue:

#ifndef MYCLASS_H
#define MYCLASS_H
#include <dlib/mlp.h>
typedef dlib::mlp::kernel_1a_c mlp_trainer_type;
Class MyClass:
 public:
  MyClassConstructure()
  {
     /// After declaration, how do I initialize my_neural_network_ here?
     // my_neural_network_(5, 5);  ????
  }
 private:
  /* this part fails, even without using the typedef. */
  mlp_trainer_type mouth_neural_network_;
 #end

Won't work even if I do:

private:
  mlp_trainer_type mouth_neural_network_(2,5);

Or if I declare and define it as a public variable. How do I solve this problem? I don't want a global variable.

I also use the SVM library from dlib, and that one works inside my class. It's just MLP that does not work.

The program worked just using dlib's SVM until I included that neural private variable today.


Solution

  • The class you are trying to use mlp_kernel_c does not have a default constructor. You need to initialize the member variable before you enter the constructor body:

    MyConstructor() : mouth_neural_network_(2,5)
    {
         //Other stuff
    }