From 30d652d6db07ddd962f970769b5a585aad121622 Mon Sep 17 00:00:00 2001 From: stereomatchingkiss Date: Sat, 27 Feb 2016 15:37:15 +0800 Subject: [PATCH 01/22] implement serialize --- src/mlpack/methods/ann/layer/softmax_layer.hpp | 8 ++++++++ src/mlpack/methods/ann/layer/sparse_bias_layer.hpp | 10 ++++++++++ src/mlpack/methods/ann/layer/sparse_input_layer.hpp | 10 ++++++++++ src/mlpack/methods/ann/layer/sparse_output_layer.hpp | 12 ++++++++++++ 4 files changed, 40 insertions(+) diff --git a/src/mlpack/methods/ann/layer/softmax_layer.hpp b/src/mlpack/methods/ann/layer/softmax_layer.hpp index 12e0146cbc..bb1ff895e5 100644 --- a/src/mlpack/methods/ann/layer/softmax_layer.hpp +++ b/src/mlpack/methods/ann/layer/softmax_layer.hpp @@ -96,6 +96,14 @@ class SoftmaxLayer InputDataType& Delta() const { return delta; } //! Modify the delta. InputDataType& Delta() { return delta; } + + /** + * Serialize the layer + */ + template + void Serialize(Archive& ar, const unsigned int /* version */) + { + } private: //! Locally-stored delta object. diff --git a/src/mlpack/methods/ann/layer/sparse_bias_layer.hpp b/src/mlpack/methods/ann/layer/sparse_bias_layer.hpp index 2723a98d31..effe912f22 100644 --- a/src/mlpack/methods/ann/layer/sparse_bias_layer.hpp +++ b/src/mlpack/methods/ann/layer/sparse_bias_layer.hpp @@ -130,6 +130,16 @@ class SparseBiasLayer InputDataType const& Gradient() const { return gradient; } //! Modify the gradient. InputDataType& Gradient() { return gradient; } + + /** + * Serialize the layer + */ + template + void Serialize(Archive& ar, const unsigned int /* version */) + { + ar & data::CreateNVP(lambda, "lambda"); + ar & data::CreateNVP(weights, "weights"); + } private: //! Locally-stored number of output units. diff --git a/src/mlpack/methods/ann/layer/sparse_input_layer.hpp b/src/mlpack/methods/ann/layer/sparse_input_layer.hpp index efdb7772b8..fbb0d67e52 100644 --- a/src/mlpack/methods/ann/layer/sparse_input_layer.hpp +++ b/src/mlpack/methods/ann/layer/sparse_input_layer.hpp @@ -132,6 +132,16 @@ class SparseInputLayer OutputDataType& Gradient() const { return gradient; } //! Modify the gradient. OutputDataType& Gradient() { return gradient; } + + /** + * Serialize the layer + */ + template + void Serialize(Archive& ar, const unsigned int /* version */) + { + ar & data::CreateNVP(lambda, "lambda"); + ar & data::CreateNVP(weights, "weights"); + } private: //! Locally-stored number of input units. diff --git a/src/mlpack/methods/ann/layer/sparse_output_layer.hpp b/src/mlpack/methods/ann/layer/sparse_output_layer.hpp index 950081a7ef..1d5cf70be5 100644 --- a/src/mlpack/methods/ann/layer/sparse_output_layer.hpp +++ b/src/mlpack/methods/ann/layer/sparse_output_layer.hpp @@ -142,6 +142,18 @@ class SparseOutputLayer { return rho; } + + /** + * Serialize the layer + */ + template + void Serialize(Archive& ar, const unsigned int /* version */) + { + ar & data::CreateNVP(rhoCap, "rhoCap"); + ar & data::CreateNVP(lambda, "lambda"); + ar & data::CreateNVP(beta, "beta"); + ar & data::CreateNVP(weights, "weights"); + } //! Get the weights. OutputDataType const& Weights() const { return weights; } From 9176684485e969df42807ae4416f47bb9b175aa7 Mon Sep 17 00:00:00 2001 From: stereomatchingkiss Date: Sat, 27 Feb 2016 15:38:15 +0800 Subject: [PATCH 02/22] implement serialize and remove move constructor and move assignemnt since c++11 should be able to generate them.Remember to specify [ARMA_USE_CXX11] --- .../methods/ann/layer/recurrent_layer.hpp | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/mlpack/methods/ann/layer/recurrent_layer.hpp b/src/mlpack/methods/ann/layer/recurrent_layer.hpp index 332a659983..da42fc09c3 100644 --- a/src/mlpack/methods/ann/layer/recurrent_layer.hpp +++ b/src/mlpack/methods/ann/layer/recurrent_layer.hpp @@ -55,21 +55,7 @@ class RecurrentLayer recurrentParameter(arma::zeros(outSize, 1)) { weights.set_size(outSize, inSize); - } - - RecurrentLayer(RecurrentLayer &&layer) noexcept - { - *this = std::move(layer); - } - - RecurrentLayer& operator=(RecurrentLayer &&layer) noexcept - { - inSize = layer.inSize; - outSize = layer.outSize; - weights.swap(layer.weights); - - return *this; - } + } /** * Ordinary feed forward pass of a neural network, evaluating the function @@ -142,6 +128,16 @@ class RecurrentLayer OutputDataType& Gradient() const { return gradient; } //! Modify the gradient. OutputDataType& Gradient() { return gradient; } + + /** + * Serialize the layer + */ + template + void Serialize(Archive& ar, const unsigned int /* version */) + { + ar & data::CreateNVP(recurrentParameter, "recurrentParameter"); + ar & data::CreateNVP(weights, "weights"); + } private: //! Locally-stored number of input units. From 2cba975c7e4b30ebd86a7376dc09125cadb51558 Mon Sep 17 00:00:00 2001 From: stereomatchingkiss Date: Sat, 27 Feb 2016 15:49:59 +0800 Subject: [PATCH 03/22] implement serialize --- src/mlpack/methods/ann/layer/lstm_layer.hpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/mlpack/methods/ann/layer/lstm_layer.hpp b/src/mlpack/methods/ann/layer/lstm_layer.hpp index 0ac04e7ec5..da990ac6f1 100644 --- a/src/mlpack/methods/ann/layer/lstm_layer.hpp +++ b/src/mlpack/methods/ann/layer/lstm_layer.hpp @@ -291,6 +291,14 @@ class LSTMLayer size_t SeqLen() const { return seqLen; } //! Modify the sequence length. size_t& SeqLen() { return seqLen; } + + /** + * Serialize the layer + */ + template + void Serialize(Archive& ar, const unsigned int /* version */) + { + } private: //! Locally-stored number of output units. From 7b85147f59a1cc7a33e87d682ac3a37fa5638e73 Mon Sep 17 00:00:00 2001 From: stereomatchingkiss Date: Sat, 27 Feb 2016 15:51:56 +0800 Subject: [PATCH 04/22] implement serialize --- src/mlpack/methods/ann/layer/linear_layer.hpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/mlpack/methods/ann/layer/linear_layer.hpp b/src/mlpack/methods/ann/layer/linear_layer.hpp index f059bb302f..56bb2b750d 100644 --- a/src/mlpack/methods/ann/layer/linear_layer.hpp +++ b/src/mlpack/methods/ann/layer/linear_layer.hpp @@ -148,6 +148,15 @@ class LinearLayer OutputDataType& Gradient() const { return gradient; } //! Modify the gradient. OutputDataType& Gradient() { return gradient; } + + /** + * Serialize the layer + */ + template + void Serialize(Archive& ar, const unsigned int /* version */) + { + ar & data::CreateNVP(weights, "weights"); + } private: /* From f64a84b07292348562b83848c2773c309bf43e4c Mon Sep 17 00:00:00 2001 From: stereomatchingkiss Date: Sat, 27 Feb 2016 15:52:49 +0800 Subject: [PATCH 05/22] implement serialize --- src/mlpack/methods/ann/layer/dropout_layer.hpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/mlpack/methods/ann/layer/dropout_layer.hpp b/src/mlpack/methods/ann/layer/dropout_layer.hpp index 4fa46afc8d..2b74c8754b 100644 --- a/src/mlpack/methods/ann/layer/dropout_layer.hpp +++ b/src/mlpack/methods/ann/layer/dropout_layer.hpp @@ -196,6 +196,14 @@ class DropoutLayer bool Rescale() const {return rescale; } //! Modify the value of the rescale parameter. bool& Rescale() {return rescale; } + + /** + * Serialize the layer + */ + template + void Serialize(Archive& ar, const unsigned int /* version */) + { + } private: //! Locally-stored delta object. From 9b672da91c369eab6779c8a7b77ae3f18cff1e0c Mon Sep 17 00:00:00 2001 From: stereomatchingkiss Date: Sat, 27 Feb 2016 15:53:56 +0800 Subject: [PATCH 06/22] only serialize weights --- .../methods/ann/layer/sparse_bias_layer.hpp | 3 +-- .../methods/ann/layer/sparse_input_layer.hpp | 3 +-- .../methods/ann/layer/sparse_output_layer.hpp | 23 ++++++++----------- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/mlpack/methods/ann/layer/sparse_bias_layer.hpp b/src/mlpack/methods/ann/layer/sparse_bias_layer.hpp index effe912f22..6ab7817f34 100644 --- a/src/mlpack/methods/ann/layer/sparse_bias_layer.hpp +++ b/src/mlpack/methods/ann/layer/sparse_bias_layer.hpp @@ -136,8 +136,7 @@ class SparseBiasLayer */ template void Serialize(Archive& ar, const unsigned int /* version */) - { - ar & data::CreateNVP(lambda, "lambda"); + { ar & data::CreateNVP(weights, "weights"); } diff --git a/src/mlpack/methods/ann/layer/sparse_input_layer.hpp b/src/mlpack/methods/ann/layer/sparse_input_layer.hpp index fbb0d67e52..33d34cd2cf 100644 --- a/src/mlpack/methods/ann/layer/sparse_input_layer.hpp +++ b/src/mlpack/methods/ann/layer/sparse_input_layer.hpp @@ -138,8 +138,7 @@ class SparseInputLayer */ template void Serialize(Archive& ar, const unsigned int /* version */) - { - ar & data::CreateNVP(lambda, "lambda"); + { ar & data::CreateNVP(weights, "weights"); } diff --git a/src/mlpack/methods/ann/layer/sparse_output_layer.hpp b/src/mlpack/methods/ann/layer/sparse_output_layer.hpp index 1d5cf70be5..a571210e10 100644 --- a/src/mlpack/methods/ann/layer/sparse_output_layer.hpp +++ b/src/mlpack/methods/ann/layer/sparse_output_layer.hpp @@ -141,19 +141,7 @@ class SparseOutputLayer double Rho() const { return rho; - } - - /** - * Serialize the layer - */ - template - void Serialize(Archive& ar, const unsigned int /* version */) - { - ar & data::CreateNVP(rhoCap, "rhoCap"); - ar & data::CreateNVP(lambda, "lambda"); - ar & data::CreateNVP(beta, "beta"); - ar & data::CreateNVP(weights, "weights"); - } + } //! Get the weights. OutputDataType const& Weights() const { return weights; } @@ -184,6 +172,15 @@ class SparseOutputLayer OutputDataType const& Gradient() const { return gradient; } //! Modify the gradient. OutputDataType& Gradient() { return gradient; } + + /** + * Serialize the layer + */ + template + void Serialize(Archive& ar, const unsigned int /* version */) + { + ar & data::CreateNVP(weights, "weights"); + } private: //! Locally-stored number of input units. From 2cbd9589ace8e40fc5af49bd70297d2bd8f4a855 Mon Sep 17 00:00:00 2001 From: stereomatchingkiss Date: Sat, 27 Feb 2016 16:22:31 +0800 Subject: [PATCH 07/22] implement serialize --- src/mlpack/methods/ann/layer/conv_layer.hpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/mlpack/methods/ann/layer/conv_layer.hpp b/src/mlpack/methods/ann/layer/conv_layer.hpp index 06f38a8bfc..287d587073 100644 --- a/src/mlpack/methods/ann/layer/conv_layer.hpp +++ b/src/mlpack/methods/ann/layer/conv_layer.hpp @@ -178,6 +178,15 @@ class ConvLayer } } } + + /** + * Serialize the layer + */ + template + void Serialize(Archive& ar, const unsigned int /* version */) + { + ar & data::CreateNVP(weights, "weights"); + } //! Get the weights. OutputDataType& Weights() const { return weights; } From fb7f43512add6d9b2cbb41b777327c38c9fd8b6c Mon Sep 17 00:00:00 2001 From: stereomatchingkiss Date: Sat, 27 Feb 2016 16:23:08 +0800 Subject: [PATCH 08/22] implement serialize --- .../methods/ann/layer/binary_classification_layer.hpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/mlpack/methods/ann/layer/binary_classification_layer.hpp b/src/mlpack/methods/ann/layer/binary_classification_layer.hpp index ae5fb46aee..976145893f 100644 --- a/src/mlpack/methods/ann/layer/binary_classification_layer.hpp +++ b/src/mlpack/methods/ann/layer/binary_classification_layer.hpp @@ -60,6 +60,14 @@ class BinaryClassificationLayer for (size_t i = 0; i < output.n_elem; i++) output(i) = output(i) > 0.5 ? 1 : 0; } + + /** + * Serialize the layer + */ + template + void Serialize(Archive& ar, const unsigned int /* version */) + { + } }; // class BinaryClassificationLayer //! Layer traits for the binary class classification layer. From ad598ccccb9c954aa598c9043c446c97083d3a8c Mon Sep 17 00:00:00 2001 From: stereomatchingkiss Date: Sat, 27 Feb 2016 16:24:02 +0800 Subject: [PATCH 09/22] implement serialize --- src/mlpack/methods/ann/layer/base_layer.hpp | 8 ++++++++ src/mlpack/methods/ann/layer/bias_layer.hpp | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/src/mlpack/methods/ann/layer/base_layer.hpp b/src/mlpack/methods/ann/layer/base_layer.hpp index 1b9f0d8b87..385e38cc8c 100644 --- a/src/mlpack/methods/ann/layer/base_layer.hpp +++ b/src/mlpack/methods/ann/layer/base_layer.hpp @@ -133,6 +133,14 @@ class BaseLayer OutputDataType const& Delta() const { return delta; } //! Modify the delta. OutputDataType& Delta() { return delta; } + + /** + * Serialize the layer + */ + template + void Serialize(Archive& ar, const unsigned int /* version */) + { + } private: //! Locally-stored delta object. diff --git a/src/mlpack/methods/ann/layer/bias_layer.hpp b/src/mlpack/methods/ann/layer/bias_layer.hpp index 11d293d2a7..bb29deb0ad 100644 --- a/src/mlpack/methods/ann/layer/bias_layer.hpp +++ b/src/mlpack/methods/ann/layer/bias_layer.hpp @@ -146,6 +146,15 @@ class BiasLayer InputDataType& Gradient() const { return gradient; } //! Modify the gradient. InputDataType& Gradient() { return gradient; } + + /** + * Serialize the layer + */ + template + void Serialize(Archive& ar, const unsigned int /* version */) + { + ar & data::CreateNVP(weights, "weights"); + } private: //! Locally-stored number of output units. From 277990681b33ecd102acb34a31cac25fe70d68f2 Mon Sep 17 00:00:00 2001 From: stereomatchingkiss Date: Sat, 27 Feb 2016 23:45:22 +0800 Subject: [PATCH 10/22] implement serialize --- src/mlpack/methods/ann/layer/one_hot_layer.hpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/mlpack/methods/ann/layer/one_hot_layer.hpp b/src/mlpack/methods/ann/layer/one_hot_layer.hpp index e820632652..b070d5d4b6 100644 --- a/src/mlpack/methods/ann/layer/one_hot_layer.hpp +++ b/src/mlpack/methods/ann/layer/one_hot_layer.hpp @@ -62,6 +62,14 @@ class OneHotLayer inputActivations.max(maxIndex); output(maxIndex) = 1; } + + /** + * Serialize the layer + */ + template + void Serialize(Archive& ar, const unsigned int /* version */) + { + } }; // class OneHotLayer //! Layer traits for the one-hot class classification layer. From 4f307dd71144dc869035cbf98fb008cf75ffcdcc Mon Sep 17 00:00:00 2001 From: stereomatchingkiss Date: Sat, 27 Feb 2016 23:51:27 +0800 Subject: [PATCH 11/22] implement serialize --- src/mlpack/methods/ann/layer/pooling_layer.hpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/mlpack/methods/ann/layer/pooling_layer.hpp b/src/mlpack/methods/ann/layer/pooling_layer.hpp index fdaefad589..729235ab2f 100644 --- a/src/mlpack/methods/ann/layer/pooling_layer.hpp +++ b/src/mlpack/methods/ann/layer/pooling_layer.hpp @@ -162,6 +162,14 @@ class PoolingLayer OutputDataType& Delta() const { return delta; } //! Modify the delta. OutputDataType& Delta() { return delta; } + + /** + * Serialize the layer + */ + template + void Serialize(Archive& ar, const unsigned int /* version */) + { + } private: /** From 5782655fb8b1dc0c360e6e47fd31cb483e068f03 Mon Sep 17 00:00:00 2001 From: stereomatchingkiss Date: Sat, 27 Feb 2016 23:51:56 +0800 Subject: [PATCH 12/22] implement serialize --- .../methods/ann/layer/multiclass_classification_layer.hpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/mlpack/methods/ann/layer/multiclass_classification_layer.hpp b/src/mlpack/methods/ann/layer/multiclass_classification_layer.hpp index f74ac2831a..0cf51e0996 100644 --- a/src/mlpack/methods/ann/layer/multiclass_classification_layer.hpp +++ b/src/mlpack/methods/ann/layer/multiclass_classification_layer.hpp @@ -61,6 +61,14 @@ class MulticlassClassificationLayer { output = inputActivations; } + + /** + * Serialize the layer + */ + template + void Serialize(Archive& ar, const unsigned int /* version */) + { + } }; // class MulticlassClassificationLayer //! Layer traits for the multiclass classification layer. From 8fd4466a42dd50b61cb13726621a9a85c2c0581f Mon Sep 17 00:00:00 2001 From: stereomatchingkiss Date: Sat, 27 Feb 2016 23:52:50 +0800 Subject: [PATCH 13/22] format codes --- src/mlpack/methods/ann/layer/conv_layer.hpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/mlpack/methods/ann/layer/conv_layer.hpp b/src/mlpack/methods/ann/layer/conv_layer.hpp index 287d587073..1375838514 100644 --- a/src/mlpack/methods/ann/layer/conv_layer.hpp +++ b/src/mlpack/methods/ann/layer/conv_layer.hpp @@ -177,16 +177,7 @@ class ConvLayer g.slice(s) += output.slice(i); } } - } - - /** - * Serialize the layer - */ - template - void Serialize(Archive& ar, const unsigned int /* version */) - { - ar & data::CreateNVP(weights, "weights"); - } + } //! Get the weights. OutputDataType& Weights() const { return weights; } @@ -212,6 +203,15 @@ class ConvLayer OutputDataType& Gradient() const { return gradient; } //! Modify the gradient. OutputDataType& Gradient() { return gradient; } + + /** + * Serialize the layer + */ + template + void Serialize(Archive& ar, const unsigned int /* version */) + { + ar & data::CreateNVP(weights, "weights"); + } private: /* From debb7ca026231348cb32bb8a046297e72da846d0 Mon Sep 17 00:00:00 2001 From: stereomatchingkiss Date: Sun, 28 Feb 2016 00:46:30 +0800 Subject: [PATCH 14/22] implement serialization --- src/mlpack/methods/ann/cnn_impl.hpp | 3 +++ src/mlpack/methods/ann/ffn_impl.hpp | 3 +++ src/mlpack/methods/ann/rnn_impl.hpp | 3 +++ 3 files changed, 9 insertions(+) diff --git a/src/mlpack/methods/ann/cnn_impl.hpp b/src/mlpack/methods/ann/cnn_impl.hpp index 3b568c46f6..d7520ce799 100644 --- a/src/mlpack/methods/ann/cnn_impl.hpp +++ b/src/mlpack/methods/ann/cnn_impl.hpp @@ -10,6 +10,8 @@ // In case it hasn't been included yet. #include "cnn.hpp" +#include + namespace mlpack { namespace ann /** Artificial Neural Network. */ { @@ -265,6 +267,7 @@ LayerTypes, OutputLayerType, InitializationRuleType, PerformanceFunction >::Serialize(Archive& ar, const unsigned int /* version */) { ar & data::CreateNVP(parameter, "parameter"); + ar & data::CreateNVP(network, "network"); } } // namespace ann diff --git a/src/mlpack/methods/ann/ffn_impl.hpp b/src/mlpack/methods/ann/ffn_impl.hpp index 4ab1fa1bf8..6f085c6d49 100644 --- a/src/mlpack/methods/ann/ffn_impl.hpp +++ b/src/mlpack/methods/ann/ffn_impl.hpp @@ -10,6 +10,8 @@ // In case it hasn't been included yet. #include "ffn.hpp" +#include + namespace mlpack { namespace ann /** Artificial Neural Network. */ { @@ -269,6 +271,7 @@ LayerTypes, OutputLayerType, InitializationRuleType, PerformanceFunction >::Serialize(Archive& ar, const unsigned int /* version */) { ar & data::CreateNVP(parameter, "parameter"); + ar & data::CreateNVP(network, "network"); } } // namespace ann diff --git a/src/mlpack/methods/ann/rnn_impl.hpp b/src/mlpack/methods/ann/rnn_impl.hpp index 01044510f8..12cd5ffcdc 100644 --- a/src/mlpack/methods/ann/rnn_impl.hpp +++ b/src/mlpack/methods/ann/rnn_impl.hpp @@ -10,6 +10,8 @@ // In case it hasn't been included yet. #include "rnn.hpp" +#include + namespace mlpack { namespace ann /** Artificial Neural Network. */ { @@ -328,6 +330,7 @@ LayerTypes, OutputLayerType, InitializationRuleType, PerformanceFunction >::Serialize(Archive& ar, const unsigned int /* version */) { ar & data::CreateNVP(parameter, "parameter"); + ar & data::CreateNVP(network, "network"); } } // namespace ann From 07833dd4046e9c9fdc8897bc07271b1a4c87e445 Mon Sep 17 00:00:00 2001 From: stereomatchingkiss Date: Sun, 28 Feb 2016 00:46:49 +0800 Subject: [PATCH 15/22] first commit --- src/mlpack/core/util/tuple_serialize.hpp | 36 ++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/mlpack/core/util/tuple_serialize.hpp diff --git a/src/mlpack/core/util/tuple_serialize.hpp b/src/mlpack/core/util/tuple_serialize.hpp new file mode 100644 index 0000000000..a6f7ebf23a --- /dev/null +++ b/src/mlpack/core/util/tuple_serialize.hpp @@ -0,0 +1,36 @@ +#ifndef MLPACK_CORE_SERIALIZE_TUPLE +#define MLPACK_CORE_SERIALIZE_TUPLE + +#include + +#include + +namespace boost { +namespace serialization { + + template< + size_t I, + size_t Max, + typename Archive, + typename... Args + > + typename std::enable_if::type + Serialize(Archive& ar, std::tuple& t, const unsigned int /* version */) + { + ar & data::CreateNVP(std::get(t), "tuple" + std::to_string(I)); + Serialize(ar, t, 0); + } + + template< + size_t I, + size_t Max, + typename Archive, + typename... Args + > + typename std::enable_if::type + Serialize(Archive&, std::tuple&, const unsigned int /* version */) + { + } +} +} +#endif \ No newline at end of file From dbffa870c6ffcd07f1e515c8c214a6e2a2d1f45c Mon Sep 17 00:00:00 2001 From: stereomatchingkiss Date: Sun, 28 Feb 2016 01:02:27 +0800 Subject: [PATCH 16/22] fix bug--did not specify range --- src/mlpack/methods/ann/cnn_impl.hpp | 3 ++- src/mlpack/methods/ann/ffn_impl.hpp | 3 ++- src/mlpack/methods/ann/rnn_impl.hpp | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/mlpack/methods/ann/cnn_impl.hpp b/src/mlpack/methods/ann/cnn_impl.hpp index d7520ce799..04c492ee99 100644 --- a/src/mlpack/methods/ann/cnn_impl.hpp +++ b/src/mlpack/methods/ann/cnn_impl.hpp @@ -267,7 +267,8 @@ LayerTypes, OutputLayerType, InitializationRuleType, PerformanceFunction >::Serialize(Archive& ar, const unsigned int /* version */) { ar & data::CreateNVP(parameter, "parameter"); - ar & data::CreateNVP(network, "network"); + ar & data::CreateNVP<0, std::tuple_size::value-1> + (network, "network"); } } // namespace ann diff --git a/src/mlpack/methods/ann/ffn_impl.hpp b/src/mlpack/methods/ann/ffn_impl.hpp index 6f085c6d49..1612eb82e4 100644 --- a/src/mlpack/methods/ann/ffn_impl.hpp +++ b/src/mlpack/methods/ann/ffn_impl.hpp @@ -271,7 +271,8 @@ LayerTypes, OutputLayerType, InitializationRuleType, PerformanceFunction >::Serialize(Archive& ar, const unsigned int /* version */) { ar & data::CreateNVP(parameter, "parameter"); - ar & data::CreateNVP(network, "network"); + ar & data::CreateNVP<0, std::tuple_size::value-1> + (network, "network"); } } // namespace ann diff --git a/src/mlpack/methods/ann/rnn_impl.hpp b/src/mlpack/methods/ann/rnn_impl.hpp index 12cd5ffcdc..eb57b66f49 100644 --- a/src/mlpack/methods/ann/rnn_impl.hpp +++ b/src/mlpack/methods/ann/rnn_impl.hpp @@ -330,7 +330,8 @@ LayerTypes, OutputLayerType, InitializationRuleType, PerformanceFunction >::Serialize(Archive& ar, const unsigned int /* version */) { ar & data::CreateNVP(parameter, "parameter"); - ar & data::CreateNVP(network, "network"); + ar & data::CreateNVP<0, std::tuple_size::value-1> + (network, "network"); } } // namespace ann From e9e7b85372a3bf0dc7cb5d8803c0603d036c62b2 Mon Sep 17 00:00:00 2001 From: stereomatchingkiss Date: Wed, 2 Mar 2016 12:25:10 +0800 Subject: [PATCH 17/22] adjust format --- src/mlpack/core/util/tuple_serialize.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mlpack/core/util/tuple_serialize.hpp b/src/mlpack/core/util/tuple_serialize.hpp index a6f7ebf23a..0c8c76f4d6 100644 --- a/src/mlpack/core/util/tuple_serialize.hpp +++ b/src/mlpack/core/util/tuple_serialize.hpp @@ -5,7 +5,7 @@ #include -namespace boost { +namespace mlpack { namespace serialization { template< @@ -18,7 +18,7 @@ namespace serialization { Serialize(Archive& ar, std::tuple& t, const unsigned int /* version */) { ar & data::CreateNVP(std::get(t), "tuple" + std::to_string(I)); - Serialize(ar, t, 0); + Serialize(ar, t, 0); } template< @@ -33,4 +33,4 @@ namespace serialization { } } } -#endif \ No newline at end of file +#endif From 95191cf4d68fb08325a3aac9a89557a2f9ab1640 Mon Sep 17 00:00:00 2001 From: stereomatchingkiss Date: Wed, 2 Mar 2016 13:10:12 +0800 Subject: [PATCH 18/22] change namespace to boost and provide overload of serialize --- src/mlpack/core/util/tuple_serialize.hpp | 16 +++++++++++----- src/mlpack/methods/ann/layer/base_layer.hpp | 4 ++-- src/mlpack/methods/ann/layer/bias_layer.hpp | 12 ++++++------ src/mlpack/methods/ann/layer/linear_layer.hpp | 12 ++++++------ 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/mlpack/core/util/tuple_serialize.hpp b/src/mlpack/core/util/tuple_serialize.hpp index 0c8c76f4d6..809976897a 100644 --- a/src/mlpack/core/util/tuple_serialize.hpp +++ b/src/mlpack/core/util/tuple_serialize.hpp @@ -5,7 +5,7 @@ #include -namespace mlpack { +namespace boost { namespace serialization { template< @@ -15,10 +15,10 @@ namespace serialization { typename... Args > typename std::enable_if::type - Serialize(Archive& ar, std::tuple& t, const unsigned int /* version */) + serialize(Archive& ar, std::tuple& t, const unsigned int /* version */) { ar & data::CreateNVP(std::get(t), "tuple" + std::to_string(I)); - Serialize(ar, t, 0); + serialize(ar, t, 0); } template< @@ -28,9 +28,15 @@ namespace serialization { typename... Args > typename std::enable_if::type - Serialize(Archive&, std::tuple&, const unsigned int /* version */) + serialize(Archive&, std::tuple&, const unsigned int /* version */) { - } + } + + template + void serialize(Archive& ar, std::tuple& t, const unsigned int /* version */) + { + serialize<0, std::tuple_size>::value-1>(ar, t, 0); + } } } #endif diff --git a/src/mlpack/methods/ann/layer/base_layer.hpp b/src/mlpack/methods/ann/layer/base_layer.hpp index 385e38cc8c..1cbeaaf1c4 100644 --- a/src/mlpack/methods/ann/layer/base_layer.hpp +++ b/src/mlpack/methods/ann/layer/base_layer.hpp @@ -120,12 +120,12 @@ class BaseLayer } //! Get the input parameter. - InputDataType& InputParameter() const { return inputParameter; } + InputDataType const& InputParameter() const { return inputParameter; } //! Modify the input parameter. InputDataType& InputParameter() { return inputParameter; } //! Get the output parameter. - OutputDataType& OutputParameter() const { return outputParameter; } + OutputDataType const& OutputParameter() const { return outputParameter; } //! Modify the output parameter. OutputDataType& OutputParameter() { return outputParameter; } diff --git a/src/mlpack/methods/ann/layer/bias_layer.hpp b/src/mlpack/methods/ann/layer/bias_layer.hpp index bb29deb0ad..007fa5419c 100644 --- a/src/mlpack/methods/ann/layer/bias_layer.hpp +++ b/src/mlpack/methods/ann/layer/bias_layer.hpp @@ -123,27 +123,27 @@ class BiasLayer } //! Get the weights. - InputDataType& Weights() const { return weights; } + InputDataType const& Weights() const { return weights; } //! Modify the weights. InputDataType& Weights() { return weights; } //! Get the input parameter. - InputDataType& InputParameter() const { return inputParameter; } + InputDataType const& InputParameter() const { return inputParameter; } //! Modify the input parameter. InputDataType& InputParameter() { return inputParameter; } //! Get the output parameter. - OutputDataType& OutputParameter() const { return outputParameter; } + OutputDataType const& OutputParameter() const { return outputParameter; } //! Modify the output parameter. OutputDataType& OutputParameter() { return outputParameter; } //! Get the delta. - OutputDataType& Delta() const { return delta; } + OutputDataType const& Delta() const { return delta; } //! Modify the delta. OutputDataType& Delta() { return delta; } //! Get the gradient. - InputDataType& Gradient() const { return gradient; } + InputDataType const& Gradient() const { return gradient; } //! Modify the gradient. InputDataType& Gradient() { return gradient; } @@ -153,7 +153,7 @@ class BiasLayer template void Serialize(Archive& ar, const unsigned int /* version */) { - ar & data::CreateNVP(weights, "weights"); + ar & data::CreateNVP(weights, "weights"); } private: diff --git a/src/mlpack/methods/ann/layer/linear_layer.hpp b/src/mlpack/methods/ann/layer/linear_layer.hpp index 0e78525b0e..70a00eb08d 100644 --- a/src/mlpack/methods/ann/layer/linear_layer.hpp +++ b/src/mlpack/methods/ann/layer/linear_layer.hpp @@ -111,27 +111,27 @@ class LinearLayer } //! Get the weights. - OutputDataType& Weights() const { return weights; } + OutputDataType const& Weights() const { return weights; } //! Modify the weights. OutputDataType& Weights() { return weights; } //! Get the input parameter. - InputDataType& InputParameter() const { return inputParameter; } + InputDataType const& InputParameter() const { return inputParameter; } //! Modify the input parameter. InputDataType& InputParameter() { return inputParameter; } //! Get the output parameter. - OutputDataType& OutputParameter() const { return outputParameter; } + OutputDataType const& OutputParameter() const { return outputParameter; } //! Modify the output parameter. OutputDataType& OutputParameter() { return outputParameter; } //! Get the delta. - OutputDataType& Delta() const { return delta; } + OutputDataType const& Delta() const { return delta; } //! Modify the delta. OutputDataType& Delta() { return delta; } //! Get the gradient. - OutputDataType& Gradient() const { return gradient; } + OutputDataType const& Gradient() const { return gradient; } //! Modify the gradient. OutputDataType& Gradient() { return gradient; } @@ -141,7 +141,7 @@ class LinearLayer template void Serialize(Archive& ar, const unsigned int /* version */) { - ar & data::CreateNVP(weights, "weights"); + ar & data::CreateNVP(weights, "weights"); } private: From 351797628beedaff2af61b675e3c4177d9bf91e6 Mon Sep 17 00:00:00 2001 From: stereomatchingkiss Date: Wed, 2 Mar 2016 13:12:45 +0800 Subject: [PATCH 19/22] remove useless file --- src/mlpack/core/util/tuple_serialize.hpp | 42 ------------------------ 1 file changed, 42 deletions(-) delete mode 100644 src/mlpack/core/util/tuple_serialize.hpp diff --git a/src/mlpack/core/util/tuple_serialize.hpp b/src/mlpack/core/util/tuple_serialize.hpp deleted file mode 100644 index 809976897a..0000000000 --- a/src/mlpack/core/util/tuple_serialize.hpp +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef MLPACK_CORE_SERIALIZE_TUPLE -#define MLPACK_CORE_SERIALIZE_TUPLE - -#include - -#include - -namespace boost { -namespace serialization { - - template< - size_t I, - size_t Max, - typename Archive, - typename... Args - > - typename std::enable_if::type - serialize(Archive& ar, std::tuple& t, const unsigned int /* version */) - { - ar & data::CreateNVP(std::get(t), "tuple" + std::to_string(I)); - serialize(ar, t, 0); - } - - template< - size_t I, - size_t Max, - typename Archive, - typename... Args - > - typename std::enable_if::type - serialize(Archive&, std::tuple&, const unsigned int /* version */) - { - } - - template - void serialize(Archive& ar, std::tuple& t, const unsigned int /* version */) - { - serialize<0, std::tuple_size>::value-1>(ar, t, 0); - } -} -} -#endif From f89396b84f52c41665cbd61e8cb654dd11d95c8f Mon Sep 17 00:00:00 2001 From: stereomatchingkiss Date: Wed, 2 Mar 2016 13:31:35 +0800 Subject: [PATCH 20/22] remove serialization of net --- src/mlpack/methods/ann/cnn_impl.hpp | 4 ---- src/mlpack/methods/ann/ffn_impl.hpp | 6 +----- src/mlpack/methods/ann/rnn_impl.hpp | 6 +----- 3 files changed, 2 insertions(+), 14 deletions(-) diff --git a/src/mlpack/methods/ann/cnn_impl.hpp b/src/mlpack/methods/ann/cnn_impl.hpp index 04c492ee99..3b568c46f6 100644 --- a/src/mlpack/methods/ann/cnn_impl.hpp +++ b/src/mlpack/methods/ann/cnn_impl.hpp @@ -10,8 +10,6 @@ // In case it hasn't been included yet. #include "cnn.hpp" -#include - namespace mlpack { namespace ann /** Artificial Neural Network. */ { @@ -267,8 +265,6 @@ LayerTypes, OutputLayerType, InitializationRuleType, PerformanceFunction >::Serialize(Archive& ar, const unsigned int /* version */) { ar & data::CreateNVP(parameter, "parameter"); - ar & data::CreateNVP<0, std::tuple_size::value-1> - (network, "network"); } } // namespace ann diff --git a/src/mlpack/methods/ann/ffn_impl.hpp b/src/mlpack/methods/ann/ffn_impl.hpp index 1612eb82e4..041b301267 100644 --- a/src/mlpack/methods/ann/ffn_impl.hpp +++ b/src/mlpack/methods/ann/ffn_impl.hpp @@ -10,8 +10,6 @@ // In case it hasn't been included yet. #include "ffn.hpp" -#include - namespace mlpack { namespace ann /** Artificial Neural Network. */ { @@ -270,9 +268,7 @@ void FFN< LayerTypes, OutputLayerType, InitializationRuleType, PerformanceFunction >::Serialize(Archive& ar, const unsigned int /* version */) { - ar & data::CreateNVP(parameter, "parameter"); - ar & data::CreateNVP<0, std::tuple_size::value-1> - (network, "network"); + ar & data::CreateNVP(parameter, "parameter"); } } // namespace ann diff --git a/src/mlpack/methods/ann/rnn_impl.hpp b/src/mlpack/methods/ann/rnn_impl.hpp index eb57b66f49..a55915f144 100644 --- a/src/mlpack/methods/ann/rnn_impl.hpp +++ b/src/mlpack/methods/ann/rnn_impl.hpp @@ -10,8 +10,6 @@ // In case it hasn't been included yet. #include "rnn.hpp" -#include - namespace mlpack { namespace ann /** Artificial Neural Network. */ { @@ -329,9 +327,7 @@ void RNN< LayerTypes, OutputLayerType, InitializationRuleType, PerformanceFunction >::Serialize(Archive& ar, const unsigned int /* version */) { - ar & data::CreateNVP(parameter, "parameter"); - ar & data::CreateNVP<0, std::tuple_size::value-1> - (network, "network"); + ar & data::CreateNVP(parameter, "parameter"); } } // namespace ann From 83f3752ba27a82100dcf724502782487cfa3668c Mon Sep 17 00:00:00 2001 From: stereomatchingkiss Date: Wed, 2 Mar 2016 13:38:09 +0800 Subject: [PATCH 21/22] const correctness and adjust format --- src/mlpack/methods/ann/layer/conv_layer.hpp | 12 ++++++------ src/mlpack/methods/ann/layer/dropout_layer.hpp | 6 +++--- src/mlpack/methods/ann/layer/lstm_layer.hpp | 10 +++++----- src/mlpack/methods/ann/layer/pooling_layer.hpp | 16 ++++------------ src/mlpack/methods/ann/layer/recurrent_layer.hpp | 16 ++++++++-------- src/mlpack/methods/ann/layer/softmax_layer.hpp | 6 +++--- .../methods/ann/layer/sparse_bias_layer.hpp | 2 +- .../methods/ann/layer/sparse_input_layer.hpp | 4 ++-- .../methods/ann/layer/sparse_output_layer.hpp | 2 +- 9 files changed, 33 insertions(+), 41 deletions(-) diff --git a/src/mlpack/methods/ann/layer/conv_layer.hpp b/src/mlpack/methods/ann/layer/conv_layer.hpp index 266742a642..21e3f6f543 100644 --- a/src/mlpack/methods/ann/layer/conv_layer.hpp +++ b/src/mlpack/methods/ann/layer/conv_layer.hpp @@ -160,27 +160,27 @@ class ConvLayer } //! Get the weights. - OutputDataType& Weights() const { return weights; } + OutputDataType const& Weights() const { return weights; } //! Modify the weights. OutputDataType& Weights() { return weights; } //! Get the input parameter. - InputDataType& InputParameter() const { return inputParameter; } + InputDataType const& InputParameter() const { return inputParameter; } //! Modify the input parameter. InputDataType& InputParameter() { return inputParameter; } //! Get the output parameter. - OutputDataType& OutputParameter() const { return outputParameter; } + OutputDataType const& OutputParameter() const { return outputParameter; } //! Modify the output parameter. OutputDataType& OutputParameter() { return outputParameter; } //! Get the delta. - OutputDataType& Delta() const { return delta; } + OutputDataType const& Delta() const { return delta; } //! Modify the delta. OutputDataType& Delta() { return delta; } //! Get the gradient. - OutputDataType& Gradient() const { return gradient; } + OutputDataType const& Gradient() const { return gradient; } //! Modify the gradient. OutputDataType& Gradient() { return gradient; } @@ -190,7 +190,7 @@ class ConvLayer template void Serialize(Archive& ar, const unsigned int /* version */) { - ar & data::CreateNVP(weights, "weights"); + ar & data::CreateNVP(weights, "weights"); } private: diff --git a/src/mlpack/methods/ann/layer/dropout_layer.hpp b/src/mlpack/methods/ann/layer/dropout_layer.hpp index eba1a2e9f1..b1915836d4 100644 --- a/src/mlpack/methods/ann/layer/dropout_layer.hpp +++ b/src/mlpack/methods/ann/layer/dropout_layer.hpp @@ -147,17 +147,17 @@ class DropoutLayer } //! Get the input parameter. - InputDataType& InputParameter() const { return inputParameter; } + InputDataType const& InputParameter() const { return inputParameter; } //! Modify the input parameter. InputDataType& InputParameter() { return inputParameter; } //! Get the output parameter. - OutputDataType& OutputParameter() const { return outputParameter; } + OutputDataType const& OutputParameter() const { return outputParameter; } //! Modify the output parameter. OutputDataType& OutputParameter() { return outputParameter; } //! Get the detla. - OutputDataType& Delta() const { return delta; } + OutputDataType const& Delta() const { return delta; } //! Modify the delta. OutputDataType& Delta() { return delta; } diff --git a/src/mlpack/methods/ann/layer/lstm_layer.hpp b/src/mlpack/methods/ann/layer/lstm_layer.hpp index 1ff6278b1e..d42467610e 100644 --- a/src/mlpack/methods/ann/layer/lstm_layer.hpp +++ b/src/mlpack/methods/ann/layer/lstm_layer.hpp @@ -248,27 +248,27 @@ class LSTMLayer } //! Get the peephole weights. - OutputDataType& Weights() const { return peepholeWeights; } + OutputDataType const& Weights() const { return peepholeWeights; } //! Modify the peephole weights. OutputDataType& Weights() { return peepholeWeights; } //! Get the input parameter. - InputDataType& InputParameter() const { return inputParameter; } + InputDataType const& InputParameter() const { return inputParameter; } //! Modify the input parameter. InputDataType& InputParameter() { return inputParameter; } //! Get the output parameter. - OutputDataType& OutputParameter() const { return outputParameter; } + OutputDataType const& OutputParameter() const { return outputParameter; } //! Modify the output parameter. OutputDataType& OutputParameter() { return outputParameter; } //! Get the delta. - OutputDataType& Delta() const { return delta; } + OutputDataType const& Delta() const { return delta; } //! Modify the delta. OutputDataType& Delta() { return delta; } //! Get the peephole gradient. - OutputDataType& Gradient() const { return peepholeGradient; } + OutputDataType const& Gradient() const { return peepholeGradient; } //! Modify the peephole gradient. OutputDataType& Gradient() { return peepholeGradient; } diff --git a/src/mlpack/methods/ann/layer/pooling_layer.hpp b/src/mlpack/methods/ann/layer/pooling_layer.hpp index d091e63d25..78e929f33a 100644 --- a/src/mlpack/methods/ann/layer/pooling_layer.hpp +++ b/src/mlpack/methods/ann/layer/pooling_layer.hpp @@ -133,27 +133,19 @@ class PoolingLayer } //! Get the input parameter. - InputDataType& InputParameter() const { return inputParameter; } + InputDataType const& InputParameter() const { return inputParameter; } //! Modify the input parameter. InputDataType& InputParameter() { return inputParameter; } //! Get the output parameter. - InputDataType& OutputParameter() const { return outputParameter; } + InputDataType const& OutputParameter() const { return outputParameter; } //! Modify the output parameter. InputDataType& OutputParameter() { return outputParameter; } //! Get the delta. - OutputDataType& Delta() const { return delta; } + OutputDataType const& Delta() const { return delta; } //! Modify the delta. - OutputDataType& Delta() { return delta; } - - /** - * Serialize the layer - */ - template - void Serialize(Archive& ar, const unsigned int /* version */) - { - } + OutputDataType& Delta() { return delta; } /** * Serialize the layer diff --git a/src/mlpack/methods/ann/layer/recurrent_layer.hpp b/src/mlpack/methods/ann/layer/recurrent_layer.hpp index be2868082d..55f3acdf8c 100644 --- a/src/mlpack/methods/ann/layer/recurrent_layer.hpp +++ b/src/mlpack/methods/ann/layer/recurrent_layer.hpp @@ -100,32 +100,32 @@ class RecurrentLayer } //! Get the weights. - OutputDataType& Weights() const { return weights; } + OutputDataType const& Weights() const { return weights; } //! Modify the weights. OutputDataType& Weights() { return weights; } //! Get the input parameter. - InputDataType& InputParameter() const { return inputParameter; } + InputDataType const& InputParameter() const { return inputParameter; } //! Modify the input parameter. InputDataType& InputParameter() { return inputParameter; } //! Get the input parameter. - InputDataType& RecurrentParameter() const { return recurrentParameter; } + InputDataType const& RecurrentParameter() const { return recurrentParameter; } //! Modify the input parameter. InputDataType& RecurrentParameter() { return recurrentParameter; } //! Get the output parameter. - OutputDataType& OutputParameter() const { return outputParameter; } + OutputDataType const& OutputParameter() const { return outputParameter; } //! Modify the output parameter. OutputDataType& OutputParameter() { return outputParameter; } //! Get the delta. - OutputDataType& Delta() const { return delta; } + OutputDataType const& Delta() const { return delta; } //! Modify the delta. OutputDataType& Delta() { return delta; } //! Get the gradient. - OutputDataType& Gradient() const { return gradient; } + OutputDataType const& Gradient() const { return gradient; } //! Modify the gradient. OutputDataType& Gradient() { return gradient; } @@ -135,8 +135,8 @@ class RecurrentLayer template void Serialize(Archive& ar, const unsigned int /* version */) { - ar & data::CreateNVP(recurrentParameter, "recurrentParameter"); - ar & data::CreateNVP(weights, "weights"); + ar & data::CreateNVP(recurrentParameter, "recurrentParameter"); + ar & data::CreateNVP(weights, "weights"); } private: diff --git a/src/mlpack/methods/ann/layer/softmax_layer.hpp b/src/mlpack/methods/ann/layer/softmax_layer.hpp index 5d282ba11a..087508435a 100644 --- a/src/mlpack/methods/ann/layer/softmax_layer.hpp +++ b/src/mlpack/methods/ann/layer/softmax_layer.hpp @@ -69,17 +69,17 @@ class SoftmaxLayer } //! Get the input parameter. - InputDataType& InputParameter() const { return inputParameter; } + InputDataType const& InputParameter() const { return inputParameter; } //! Modify the input parameter. InputDataType& InputParameter() { return inputParameter; } //! Get the output parameter. - OutputDataType& OutputParameter() const { return outputParameter; } + OutputDataType const& OutputParameter() const { return outputParameter; } //! Modify the output parameter. OutputDataType& OutputParameter() { return outputParameter; } //! Get the delta. - InputDataType& Delta() const { return delta; } + InputDataType const& Delta() const { return delta; } //! Modify the delta. InputDataType& Delta() { return delta; } diff --git a/src/mlpack/methods/ann/layer/sparse_bias_layer.hpp b/src/mlpack/methods/ann/layer/sparse_bias_layer.hpp index 4d83f1b9e8..c166ddaaf8 100644 --- a/src/mlpack/methods/ann/layer/sparse_bias_layer.hpp +++ b/src/mlpack/methods/ann/layer/sparse_bias_layer.hpp @@ -123,7 +123,7 @@ class SparseBiasLayer template void Serialize(Archive& ar, const unsigned int /* version */) { - ar & data::CreateNVP(weights, "weights"); + ar & data::CreateNVP(weights, "weights"); } private: diff --git a/src/mlpack/methods/ann/layer/sparse_input_layer.hpp b/src/mlpack/methods/ann/layer/sparse_input_layer.hpp index faa697da81..d5384daec2 100644 --- a/src/mlpack/methods/ann/layer/sparse_input_layer.hpp +++ b/src/mlpack/methods/ann/layer/sparse_input_layer.hpp @@ -114,7 +114,7 @@ class SparseInputLayer OutputDataType& Delta() { return delta; } //! Get the gradient. - OutputDataType& Gradient() const { return gradient; } + OutputDataType const& Gradient() const { return gradient; } //! Modify the gradient. OutputDataType& Gradient() { return gradient; } @@ -124,7 +124,7 @@ class SparseInputLayer template void Serialize(Archive& ar, const unsigned int /* version */) { - ar & data::CreateNVP(weights, "weights"); + ar & data::CreateNVP(weights, "weights"); } private: diff --git a/src/mlpack/methods/ann/layer/sparse_output_layer.hpp b/src/mlpack/methods/ann/layer/sparse_output_layer.hpp index a27569d894..3e647d69a7 100644 --- a/src/mlpack/methods/ann/layer/sparse_output_layer.hpp +++ b/src/mlpack/methods/ann/layer/sparse_output_layer.hpp @@ -162,7 +162,7 @@ class SparseOutputLayer template void Serialize(Archive& ar, const unsigned int /* version */) { - ar & data::CreateNVP(weights, "weights"); + ar & data::CreateNVP(weights, "weights"); } private: From bb8507c561d5e135ba2a6a168ad9d0d5735fc85b Mon Sep 17 00:00:00 2001 From: marcus Date: Wed, 2 Mar 2016 18:27:54 +0100 Subject: [PATCH 22/22] Serialize all necessary parameter and minor formatting fixes. --- src/mlpack/methods/ann/ffn_impl.hpp | 2 +- src/mlpack/methods/ann/layer/base_layer.hpp | 7 ++++--- src/mlpack/methods/ann/layer/bias_layer.hpp | 5 +++-- .../ann/layer/binary_classification_layer.hpp | 7 ++++--- src/mlpack/methods/ann/layer/conv_layer.hpp | 14 +++++++++++--- src/mlpack/methods/ann/layer/dropout_layer.hpp | 6 ++++-- src/mlpack/methods/ann/layer/linear_layer.hpp | 2 +- src/mlpack/methods/ann/layer/lstm_layer.hpp | 16 ++++++++++++++-- src/mlpack/methods/ann/layer/one_hot_layer.hpp | 7 ++++--- src/mlpack/methods/ann/layer/pooling_layer.hpp | 8 +++++--- src/mlpack/methods/ann/layer/recurrent_layer.hpp | 4 ++-- src/mlpack/methods/ann/layer/softmax_layer.hpp | 7 ++++--- .../methods/ann/layer/sparse_bias_layer.hpp | 5 +++-- .../methods/ann/layer/sparse_input_layer.hpp | 5 +++-- .../methods/ann/layer/sparse_output_layer.hpp | 9 ++++++--- src/mlpack/methods/ann/rnn_impl.hpp | 2 +- 16 files changed, 70 insertions(+), 36 deletions(-) diff --git a/src/mlpack/methods/ann/ffn_impl.hpp b/src/mlpack/methods/ann/ffn_impl.hpp index 041b301267..4ab1fa1bf8 100644 --- a/src/mlpack/methods/ann/ffn_impl.hpp +++ b/src/mlpack/methods/ann/ffn_impl.hpp @@ -268,7 +268,7 @@ void FFN< LayerTypes, OutputLayerType, InitializationRuleType, PerformanceFunction >::Serialize(Archive& ar, const unsigned int /* version */) { - ar & data::CreateNVP(parameter, "parameter"); + ar & data::CreateNVP(parameter, "parameter"); } } // namespace ann diff --git a/src/mlpack/methods/ann/layer/base_layer.hpp b/src/mlpack/methods/ann/layer/base_layer.hpp index 1cbeaaf1c4..876d87e6f2 100644 --- a/src/mlpack/methods/ann/layer/base_layer.hpp +++ b/src/mlpack/methods/ann/layer/base_layer.hpp @@ -135,11 +135,12 @@ class BaseLayer OutputDataType& Delta() { return delta; } /** - * Serialize the layer + * Serialize the layer. */ template - void Serialize(Archive& ar, const unsigned int /* version */) - { + void Serialize(Archive& /* ar */, const unsigned int /* version */) + { + /* Nothing to do here */ } private: diff --git a/src/mlpack/methods/ann/layer/bias_layer.hpp b/src/mlpack/methods/ann/layer/bias_layer.hpp index 007fa5419c..10b8b90436 100644 --- a/src/mlpack/methods/ann/layer/bias_layer.hpp +++ b/src/mlpack/methods/ann/layer/bias_layer.hpp @@ -148,12 +148,13 @@ class BiasLayer InputDataType& Gradient() { return gradient; } /** - * Serialize the layer + * Serialize the layer. */ template void Serialize(Archive& ar, const unsigned int /* version */) - { + { ar & data::CreateNVP(weights, "weights"); + ar & CreateNVP(bias, "bias"); } private: diff --git a/src/mlpack/methods/ann/layer/binary_classification_layer.hpp b/src/mlpack/methods/ann/layer/binary_classification_layer.hpp index 976145893f..368c1ecda9 100644 --- a/src/mlpack/methods/ann/layer/binary_classification_layer.hpp +++ b/src/mlpack/methods/ann/layer/binary_classification_layer.hpp @@ -62,11 +62,12 @@ class BinaryClassificationLayer } /** - * Serialize the layer + * Serialize the layer. */ template - void Serialize(Archive& ar, const unsigned int /* version */) - { + void Serialize(Archive& /* ar */, const unsigned int /* version */) + { + /* Nothing to do here */ } }; // class BinaryClassificationLayer diff --git a/src/mlpack/methods/ann/layer/conv_layer.hpp b/src/mlpack/methods/ann/layer/conv_layer.hpp index 21e3f6f543..aeb6c07093 100644 --- a/src/mlpack/methods/ann/layer/conv_layer.hpp +++ b/src/mlpack/methods/ann/layer/conv_layer.hpp @@ -157,7 +157,7 @@ class ConvLayer g.slice(s) += output.slice(i); } } - } + } //! Get the weights. OutputDataType const& Weights() const { return weights; } @@ -185,12 +185,20 @@ class ConvLayer OutputDataType& Gradient() { return gradient; } /** - * Serialize the layer + * Serialize the layer. */ template void Serialize(Archive& ar, const unsigned int /* version */) - { + { ar & data::CreateNVP(weights, "weights"); + ar & data::CreateNVP(wfilter, "wfilter"); + ar & data::CreateNVP(hfilter, "hfilter"); + ar & data::CreateNVP(inMaps, "inMaps"); + ar & data::CreateNVP(outMaps, "outMaps"); + ar & data::CreateNVP(xStride, "xStride"); + ar & data::CreateNVP(yStride, "yStride"); + ar & data::CreateNVP(wPad, "wPad"); + ar & data::CreateNVP(hPad, "hPad"); } private: diff --git a/src/mlpack/methods/ann/layer/dropout_layer.hpp b/src/mlpack/methods/ann/layer/dropout_layer.hpp index b1915836d4..05d38c6915 100644 --- a/src/mlpack/methods/ann/layer/dropout_layer.hpp +++ b/src/mlpack/methods/ann/layer/dropout_layer.hpp @@ -182,11 +182,13 @@ class DropoutLayer bool& Rescale() {return rescale; } /** - * Serialize the layer + * Serialize the layer. */ template void Serialize(Archive& ar, const unsigned int /* version */) - { + { + ar & data::CreateNVP(ratio, "ratio"); + ar & data::CreateNVP(rescale, "rescale"); } private: diff --git a/src/mlpack/methods/ann/layer/linear_layer.hpp b/src/mlpack/methods/ann/layer/linear_layer.hpp index 70a00eb08d..b34e978c36 100644 --- a/src/mlpack/methods/ann/layer/linear_layer.hpp +++ b/src/mlpack/methods/ann/layer/linear_layer.hpp @@ -140,7 +140,7 @@ class LinearLayer */ template void Serialize(Archive& ar, const unsigned int /* version */) - { + { ar & data::CreateNVP(weights, "weights"); } diff --git a/src/mlpack/methods/ann/layer/lstm_layer.hpp b/src/mlpack/methods/ann/layer/lstm_layer.hpp index d42467610e..59c103c15a 100644 --- a/src/mlpack/methods/ann/layer/lstm_layer.hpp +++ b/src/mlpack/methods/ann/layer/lstm_layer.hpp @@ -278,11 +278,23 @@ class LSTMLayer size_t& SeqLen() { return seqLen; } /** - * Serialize the layer + * Serialize the layer. */ template void Serialize(Archive& ar, const unsigned int /* version */) - { + { + ar & data::CreateNVP(peepholes, "peepholes"); + + if (peepholes) + { + ar & data::CreateNVP(peepholeWeights, "peepholeWeights"); + + if (Archive::is_loading::value) + { + peepholeDerivatives = arma::zeros( + peepholeWeights.n_rows, 3); + } + } } private: diff --git a/src/mlpack/methods/ann/layer/one_hot_layer.hpp b/src/mlpack/methods/ann/layer/one_hot_layer.hpp index a4dc6f4360..34458c3b2d 100644 --- a/src/mlpack/methods/ann/layer/one_hot_layer.hpp +++ b/src/mlpack/methods/ann/layer/one_hot_layer.hpp @@ -64,11 +64,12 @@ class OneHotLayer } /** - * Serialize the layer + * Serialize the layer. */ template - void Serialize(Archive& ar, const unsigned int /* version */) - { + void Serialize(Archive& /* ar */, const unsigned int /* version */) + { + /* Nothing to do here */ } }; // class OneHotLayer diff --git a/src/mlpack/methods/ann/layer/pooling_layer.hpp b/src/mlpack/methods/ann/layer/pooling_layer.hpp index 78e929f33a..e19ddceff2 100644 --- a/src/mlpack/methods/ann/layer/pooling_layer.hpp +++ b/src/mlpack/methods/ann/layer/pooling_layer.hpp @@ -145,14 +145,16 @@ class PoolingLayer //! Get the delta. OutputDataType const& Delta() const { return delta; } //! Modify the delta. - OutputDataType& Delta() { return delta; } + OutputDataType& Delta() { return delta; } /** - * Serialize the layer + * Serialize the layer. */ template void Serialize(Archive& ar, const unsigned int /* version */) - { + { + ar & data::CreateNVP(kSize, "kSize"); + ar & data::CreateNVP(pooling, "pooling"); } private: diff --git a/src/mlpack/methods/ann/layer/recurrent_layer.hpp b/src/mlpack/methods/ann/layer/recurrent_layer.hpp index 55f3acdf8c..639852eedc 100644 --- a/src/mlpack/methods/ann/layer/recurrent_layer.hpp +++ b/src/mlpack/methods/ann/layer/recurrent_layer.hpp @@ -130,11 +130,11 @@ class RecurrentLayer OutputDataType& Gradient() { return gradient; } /** - * Serialize the layer + * Serialize the layer. */ template void Serialize(Archive& ar, const unsigned int /* version */) - { + { ar & data::CreateNVP(recurrentParameter, "recurrentParameter"); ar & data::CreateNVP(weights, "weights"); } diff --git a/src/mlpack/methods/ann/layer/softmax_layer.hpp b/src/mlpack/methods/ann/layer/softmax_layer.hpp index 087508435a..151ebfef41 100644 --- a/src/mlpack/methods/ann/layer/softmax_layer.hpp +++ b/src/mlpack/methods/ann/layer/softmax_layer.hpp @@ -84,11 +84,12 @@ class SoftmaxLayer InputDataType& Delta() { return delta; } /** - * Serialize the layer + * Serialize the layer. */ template - void Serialize(Archive& ar, const unsigned int /* version */) - { + void Serialize(Archive& /* ar */, const unsigned int /* version */) + { + /* Nothing to do here */ } private: diff --git a/src/mlpack/methods/ann/layer/sparse_bias_layer.hpp b/src/mlpack/methods/ann/layer/sparse_bias_layer.hpp index c166ddaaf8..9b79536e5c 100644 --- a/src/mlpack/methods/ann/layer/sparse_bias_layer.hpp +++ b/src/mlpack/methods/ann/layer/sparse_bias_layer.hpp @@ -118,12 +118,13 @@ class SparseBiasLayer InputDataType& Gradient() { return gradient; } /** - * Serialize the layer + * Serialize the layer. */ template void Serialize(Archive& ar, const unsigned int /* version */) - { + { ar & data::CreateNVP(weights, "weights"); + ar & data::CreateNVP(batchSize, "batchSize"); } private: diff --git a/src/mlpack/methods/ann/layer/sparse_input_layer.hpp b/src/mlpack/methods/ann/layer/sparse_input_layer.hpp index d5384daec2..ce5ce7dc8e 100644 --- a/src/mlpack/methods/ann/layer/sparse_input_layer.hpp +++ b/src/mlpack/methods/ann/layer/sparse_input_layer.hpp @@ -119,12 +119,13 @@ class SparseInputLayer OutputDataType& Gradient() { return gradient; } /** - * Serialize the layer + * Serialize the layer. */ template void Serialize(Archive& ar, const unsigned int /* version */) - { + { ar & data::CreateNVP(weights, "weights"); + ar & data::CreateNVP(lambda, "lambda"); } private: diff --git a/src/mlpack/methods/ann/layer/sparse_output_layer.hpp b/src/mlpack/methods/ann/layer/sparse_output_layer.hpp index 3e647d69a7..3022e2a17a 100644 --- a/src/mlpack/methods/ann/layer/sparse_output_layer.hpp +++ b/src/mlpack/methods/ann/layer/sparse_output_layer.hpp @@ -124,7 +124,7 @@ class SparseOutputLayer double Rho() const { return rho; - } + } //! Get the weights. OutputDataType const& Weights() const { return weights; } @@ -157,12 +157,15 @@ class SparseOutputLayer OutputDataType& Gradient() { return gradient; } /** - * Serialize the layer + * Serialize the layer. */ template void Serialize(Archive& ar, const unsigned int /* version */) - { + { ar & data::CreateNVP(weights, "weights"); + ar & data::CreateNVP(lambda, "lambda"); + ar & data::CreateNVP(beta, "beta"); + ar & data::CreateNVP(rho, "rho"); } private: diff --git a/src/mlpack/methods/ann/rnn_impl.hpp b/src/mlpack/methods/ann/rnn_impl.hpp index a55915f144..01044510f8 100644 --- a/src/mlpack/methods/ann/rnn_impl.hpp +++ b/src/mlpack/methods/ann/rnn_impl.hpp @@ -327,7 +327,7 @@ void RNN< LayerTypes, OutputLayerType, InitializationRuleType, PerformanceFunction >::Serialize(Archive& ar, const unsigned int /* version */) { - ar & data::CreateNVP(parameter, "parameter"); + ar & data::CreateNVP(parameter, "parameter"); } } // namespace ann