[mlpack-git] [mlpack] ANN Saving the network and reloading (#531)

sudarshan notifications at github.com
Wed Mar 2 08:22:04 EST 2016


Thank you for your replies. After reading a bunch on tie and tuple I think I understand what they do. I changed my code to create the models using std::make_tuple instead of std::tie as shown:

```
auto modules = std::make_tuple(inputLayer, inputBiasLayer, inputBaseLayer, hiddenLayer1, hiddenBiasLayer1, outputLayer);
ann::FFN<decltype(modules), decltype(classOutputLayer), ann::RandomInitialization, PerformanceFunctionType> net(modules, classOutputLayer);

```
I have the function return type auto and I return the variable net after training the network. In the main function I save it to another auto'd variable and call predict on it:

```
auto net = BuildFFN<ann::LogisticFunction, ann::BinaryClassificationLayer, ann::MeanSquaredErrorFunction>
        (trainData, trainLabels, testData, testLabels, hiddenLayerSize);

arma::mat prediction;
net.Predict(testData, prediction);

```
I also made sure that ARMA_USE_CXX11 was enable (after checking out how to do it [here](http://stackoverflow.com/questions/33366730/armadillo-initializer-list-is-not-working)):

```
#if !defined(ARMA_USE_CXX11)
#define ARMA_USE_CXX11
//// Uncomment the above line if you have a C++ compiler that supports the C++11 standard
//// This will enable additional features, such as use of initialiser lists
#endif
```

However, the compiler doesn't like this, it spit out a huge amount of error:
```
In file included from /usr/include/c++/4.8/functional:55:0,
                 from /usr/include/c++/4.8/bits/stl_algo.h:66,
                 from /usr/include/c++/4.8/algorithm:62,
                 from /usr/include/boost/math/tools/config.hpp:16,
                 from /usr/include/boost/math/tools/series.hpp:16,
                 from /usr/include/boost/math/special_functions/gamma.hpp:17,
                 from /usr/local/include/mlpack/prereqs.hpp:32,
                 from /usr/local/include/mlpack/core.hpp:190,
                 from /home/sudarshan/project-yanack/mlpack_nn/src/ff_nn.cpp:4:
/usr/include/c++/4.8/tuple: In instantiation of ‘constexpr std::_Head_base<_Idx, _Head, false>::_Head_base(const _Head&) [with long unsigned int _Idx = 3ul; _Head = mlpack::ann::LinearLayer<>]’:
/usr/include/c++/4.8/tuple:257:44:   recursively required from ‘constexpr std::_Tuple_impl<_Idx, _Head, _Tail ...>::_Tuple_impl(const _Head&, const _Tail& ...) [with long unsigned int _Idx = 1ul; _Head = mlpack::ann::BiasLayer<>; _Tail = {mlpack::ann::BaseLayer<mlpack::ann::LogisticFunction, arma::Mat<double>, arma::Mat<double> >, mlpack::ann::LinearLayer<arma::Mat<double>, arma::Mat<double> >, mlpack::ann::BiasLayer<arma::Mat<double>, arma::Mat<double> >, mlpack::ann::BaseLayer<mlpack::ann::LogisticFunction, arma::Mat<double>, arma::Mat<double> >}]’
/usr/include/c++/4.8/tuple:257:44:   required from ‘constexpr std::_Tuple_impl<_Idx, _Head, _Tail ...>::_Tuple_impl(const _Head&, const _Tail& ...) [with long unsigned int _Idx = 0ul; _Head = mlpack::ann::LinearLayer<>; _Tail = {mlpack::ann::BiasLayer<arma::Mat<double>, arma::Mat<double> >, mlpack::ann::BaseLayer<mlpack::ann::LogisticFunction, arma::Mat<double>, arma::Mat<double> >, mlpack::ann::LinearLayer<arma::Mat<double>, arma::Mat<double> >, mlpack::ann::BiasLayer<arma::Mat<double>, arma::Mat<double> >, mlpack::ann::BaseLayer<mlpack::ann::LogisticFunction, arma::Mat<double>, arma::Mat<double> >}]’
/usr/include/c++/4.8/tuple:400:33:   required from ‘constexpr std::tuple< <template-parameter-1-1> >::tuple(const _Elements& ...) [with _Elements = {mlpack::ann::LinearLayer<arma::Mat<double>, arma::Mat<double> >, mlpack::ann::BiasLayer<arma::Mat<double>, arma::Mat<double> >, mlpack::ann::BaseLayer<mlpack::ann::LogisticFunction, arma::Mat<double>, arma::Mat<double> >, mlpack::ann::LinearLayer<arma::Mat<double>, arma::Mat<double> >, mlpack::ann::BiasLayer<arma::Mat<double>, arma::Mat<double> >, mlpack::ann::BaseLayer<mlpack::ann::LogisticFunction, arma::Mat<double>, arma::Mat<double> >}]’
/usr/include/c++/4.8/tuple:864:62:   required from ‘constexpr std::tuple<typename std::__decay_and_strip<_Elements>::__type ...> std::make_tuple(_Elements&& ...) [with _Elements = {mlpack::ann::LinearLayer<arma::Mat<double>, arma::Mat<double> >&, mlpack::ann::BiasLayer<arma::Mat<double>, arma::Mat<double> >&, mlpack::ann::BaseLayer<mlpack::ann::LogisticFunction, arma::Mat<double>, arma::Mat<double> >&, mlpack::ann::LinearLayer<arma::Mat<double>, arma::Mat<double> >&, mlpack::ann::BiasLayer<arma::Mat<double>, arma::Mat<double> >&, mlpack::ann::BaseLayer<mlpack::ann::LogisticFunction, arma::Mat<double>, arma::Mat<double> >&}]’
/home/sudarshan/project-yanack/mlpack_nn/src/ff_nn.cpp:42:123:   required from ‘auto BuildFFN(MatType&, MatType&, MatType&, MatType&, size_t) [with PerformanceFunction = mlpack::ann::LogisticFunction; OutputLayerType = mlpack::ann::BinaryClassificationLayer; PerformanceFunctionType = mlpack::ann::MeanSquaredErrorFunction; MatType = arma::Mat<double>; size_t = long unsigned int]’
/home/sudarshan/project-yanack/mlpack_nn/src/ff_nn.cpp:79:71:   required from here
/usr/include/c++/4.8/tuple:135:25: error: use of deleted function ‘mlpack::ann::LinearLayer<>::LinearLayer(const mlpack::ann::LinearLayer<>&)’
       : _M_head_impl(__h) { }
                         ^
In file included from /home/sudarshan/project-yanack/mlpack_nn/src/ff_nn.cpp:12:0:
/usr/local/include/mlpack/methods/ann/layer/linear_layer.hpp:30:7: note: ‘mlpack::ann::LinearLayer<>::LinearLayer(const mlpack::ann::LinearLayer<>&)’ is implicitly declared as deleted because ‘mlpack::ann::LinearLayer<>’ declares a move constructor or move assignment operator
 class LinearLayer
       ^
In file included from /usr/include/c++/4.8/functional:55:0,
                 from /usr/include/c++/4.8/bits/stl_algo.h:66,
                 from /usr/include/c++/4.8/algorithm:62,
                 from /usr/include/boost/math/tools/config.hpp:16,
                 from /usr/include/boost/math/tools/series.hpp:16,
                 from /usr/include/boost/math/special_functions/gamma.hpp:17,
                 from /usr/local/include/mlpack/prereqs.hpp:32,
                 from /usr/local/include/mlpack/core.hpp:190,
                 from /home/sudarshan/project-yanack/mlpack_nn/src/ff_nn.cpp:4:
/usr/include/c++/4.8/tuple: In instantiation of ‘constexpr std::_Head_base<_Idx, _Head, false>::_Head_base(const _Head&) [with long unsigned int _Idx = 0ul; _Head = mlpack::ann::LinearLayer<>]’:
/usr/include/c++/4.8/tuple:257:44:   required from ‘constexpr std::_Tuple_impl<_Idx, _Head, _Tail ...>::_Tuple_impl(const _Head&, const _Tail& ...) [with long unsigned int _Idx = 0ul; _Head = mlpack::ann::LinearLayer<>; _Tail = {mlpack::ann::BiasLayer<arma::Mat<double>, arma::Mat<double> >, mlpack::ann::BaseLayer<mlpack::ann::LogisticFunction, arma::Mat<double>, arma::Mat<double> >, mlpack::ann::LinearLayer<arma::Mat<double>, arma::Mat<double> >, mlpack::ann::BiasLayer<arma::Mat<double>, arma::Mat<double> >, mlpack::ann::BaseLayer<mlpack::ann::LogisticFunction, arma::Mat<double>, arma::Mat<double> >}]’
/usr/include/c++/4.8/tuple:400:33:   required from ‘constexpr std::tuple< <template-parameter-1-1> >::tuple(const _Elements& ...) [with _Elements = {mlpack::ann::LinearLayer<arma::Mat<double>, arma::Mat<double> >, mlpack::ann::BiasLayer<arma::Mat<double>, arma::Mat<double> >, mlpack::ann::BaseLayer<mlpack::ann::LogisticFunction, arma::Mat<double>, arma::Mat<double> >, mlpack::ann::LinearLayer<arma::Mat<double>, arma::Mat<double> >, mlpack::ann::BiasLayer<arma::Mat<double>, arma::Mat<double> >, mlpack::ann::BaseLayer<mlpack::ann::LogisticFunction, arma::Mat<double>, arma::Mat<double> >}]’
/usr/include/c++/4.8/tuple:864:62:   required from ‘constexpr std::tuple<typename std::__decay_and_strip<_Elements>::__type ...> std::make_tuple(_Elements&& ...) [with _Elements = {mlpack::ann::LinearLayer<arma::Mat<double>, arma::Mat<double> >&, mlpack::ann::BiasLayer<arma::Mat<double>, arma::Mat<double> >&, mlpack::ann::BaseLayer<mlpack::ann::LogisticFunction, arma::Mat<double>, arma::Mat<double> >&, mlpack::ann::LinearLayer<arma::Mat<double>, arma::Mat<double> >&, mlpack::ann::BiasLayer<arma::Mat<double>, arma::Mat<double> >&, mlpack::ann::BaseLayer<mlpack::ann::LogisticFunction, arma::Mat<double>, arma::Mat<double> >&}]’
/home/sudarshan/project-yanack/mlpack_nn/src/ff_nn.cpp:42:123:   required from ‘auto BuildFFN(MatType&, MatType&, MatType&, MatType&, size_t) [with PerformanceFunction = mlpack::ann::LogisticFunction; OutputLayerType = mlpack::ann::BinaryClassificationLayer; PerformanceFunctionType = mlpack::ann::MeanSquaredErrorFunction; MatType = arma::Mat<double>; size_t = long unsigned int]’
/home/sudarshan/project-yanack/mlpack_nn/src/ff_nn.cpp:79:71:   required from here
/usr/include/c++/4.8/tuple:135:25: error: use of deleted function ‘mlpack::ann::LinearLayer<>::LinearLayer(const mlpack::ann::LinearLayer<>&)’
       : _M_head_impl(__h) { }
                         ^
make[2]: *** [CMakeFiles/ff_nn.dir/src/ff_nn.cpp.o] Error 1
make[1]: *** [CMakeFiles/ff_nn.dir/all] Error 2
make: *** [all] Error 2

```
Based on what I can infer from this, it seems that the layers are references and making a tuple out of this is not working (I could be wrong). 

---
Reply to this email directly or view it on GitHub:
https://github.com/mlpack/mlpack/issues/531#issuecomment-191236445
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.cc.gatech.edu/pipermail/mlpack-git/attachments/20160302/00a23e49/attachment.html>


More information about the mlpack-git mailing list