From f1956ffd338e7c20d204abea1fb58db2984cb08a Mon Sep 17 00:00:00 2001 From: NippunSharma Date: Thu, 26 Nov 2020 23:07:06 +0530 Subject: [PATCH 01/51] first commit --- src/mlpack/methods/ann/ffn.hpp | 9 +++ src/mlpack/methods/ann/ffn_impl.hpp | 38 ++++++++++++- src/mlpack/methods/ann/layer/layer_traits.hpp | 4 ++ src/mlpack/methods/ann/layer/linear.hpp | 6 ++ src/mlpack/methods/ann/visitor/CMakeLists.txt | 2 + .../ann/visitor/input_shape_visitor.hpp | 57 +++++++++++++++++++ .../ann/visitor/input_shape_visitor_impl.hpp | 52 +++++++++++++++++ 7 files changed, 167 insertions(+), 1 deletion(-) create mode 100644 src/mlpack/methods/ann/visitor/input_shape_visitor.hpp create mode 100644 src/mlpack/methods/ann/visitor/input_shape_visitor_impl.hpp diff --git a/src/mlpack/methods/ann/ffn.hpp b/src/mlpack/methods/ann/ffn.hpp index 1c65bbb749..512f51fcf9 100644 --- a/src/mlpack/methods/ann/ffn.hpp +++ b/src/mlpack/methods/ann/ffn.hpp @@ -24,6 +24,7 @@ #include "visitor/weight_size_visitor.hpp" #include "visitor/copy_visitor.hpp" #include "visitor/loss_visitor.hpp" +#include "visitor/input_shape_visitor.hpp" #include "init_rules/network_init.hpp" @@ -324,6 +325,14 @@ class FFN //! Modify the matrix of data points (predictors). arma::mat& Predictors() { return predictors; } + /** + * Check wether the input size is consistent with the layer requirements. + * + * @param inputShape shape of the input + * @param functionName function that checks the input size + */ + void CheckInputShape(size_t inputShape, std::string functionName); + /** * Reset the module infomration (weights/parameters). */ diff --git a/src/mlpack/methods/ann/ffn_impl.hpp b/src/mlpack/methods/ann/ffn_impl.hpp index c16de548f4..9335a7bded 100644 --- a/src/mlpack/methods/ann/ffn_impl.hpp +++ b/src/mlpack/methods/ann/ffn_impl.hpp @@ -14,7 +14,7 @@ // In case it hasn't been included yet. #include "ffn.hpp" - +#include #include "visitor/forward_visitor.hpp" #include "visitor/backward_visitor.hpp" #include "visitor/deterministic_set_visitor.hpp" @@ -22,6 +22,7 @@ #include "visitor/gradient_visitor.hpp" #include "visitor/set_input_height_visitor.hpp" #include "visitor/set_input_width_visitor.hpp" +#include "visitor/input_shape_visitor.hpp" namespace mlpack { namespace ann /** Artificial Neural Network. */ { @@ -50,6 +51,33 @@ FFN::~FFN() boost::apply_visitor(deleteVisitor)); } +template +void FFN::CheckInputShape( + size_t inputShape, std::string functionName) +{ + for (size_t l=0; l void FFN::ResetData( @@ -109,6 +137,8 @@ double FFN::Train( OptimizerType& optimizer, CallbackTypes&&... callbacks) { + CheckInputShape(predictors.n_rows, "Train()"); + ResetData(std::move(predictors), std::move(responses)); WarnMessageMaxIterations(optimizer, this->predictors.n_cols); @@ -131,6 +161,8 @@ double FFN::Train( arma::mat responses, CallbackTypes&&... callbacks) { + CheckInputShape(predictors.n_rows, "Train()"); + ResetData(std::move(predictors), std::move(responses)); OptimizerType optimizer; @@ -217,6 +249,8 @@ template::Predict( arma::mat predictors, arma::mat& results) { + CheckInputShape(predictors.n_rows, "Predict()"); + if (parameter.is_empty()) ResetParameters(); @@ -250,6 +284,8 @@ template double FFN::Evaluate( const PredictorsType& predictors, const ResponsesType& responses) { + CheckInputShape(predictors.n_rows, "Evaluate()"); + if (parameter.is_empty()) ResetParameters(); diff --git a/src/mlpack/methods/ann/layer/layer_traits.hpp b/src/mlpack/methods/ann/layer/layer_traits.hpp index b9e2621d89..a6a447f43d 100644 --- a/src/mlpack/methods/ann/layer/layer_traits.hpp +++ b/src/mlpack/methods/ann/layer/layer_traits.hpp @@ -120,6 +120,10 @@ HAS_MEM_FUNC(Bias, HasBiasCheck); // we can use with SFINAE to catch when a type has a MaxIterations() function. HAS_MEM_FUNC(MaxIterations, HasMaxIterations); +// This gives us a HasInShapeCheck type we can use with SFINAE to catch when +// a type has a function named InputShape. +HAS_ANY_METHOD_FORM(InputShape, HasInputShapeCheck); + } // namespace ann } // namespace mlpack diff --git a/src/mlpack/methods/ann/layer/linear.hpp b/src/mlpack/methods/ann/layer/linear.hpp index f2c8015e04..cc31117c53 100644 --- a/src/mlpack/methods/ann/layer/linear.hpp +++ b/src/mlpack/methods/ann/layer/linear.hpp @@ -152,6 +152,12 @@ class Linear return (inSize * outSize) + outSize; } + //! Get the shape of the input. + size_t InputShape() const + { + return inSize; + } + /** * Serialize the layer */ diff --git a/src/mlpack/methods/ann/visitor/CMakeLists.txt b/src/mlpack/methods/ann/visitor/CMakeLists.txt index 43bcf71225..fa207d6092 100644 --- a/src/mlpack/methods/ann/visitor/CMakeLists.txt +++ b/src/mlpack/methods/ann/visitor/CMakeLists.txt @@ -57,6 +57,8 @@ set(SOURCES weight_set_visitor_impl.hpp weight_size_visitor.hpp weight_size_visitor_impl.hpp + input_shape_visitor.hpp + input_shape_visitor_impl.hpp ) # Add directory name to sources. diff --git a/src/mlpack/methods/ann/visitor/input_shape_visitor.hpp b/src/mlpack/methods/ann/visitor/input_shape_visitor.hpp new file mode 100644 index 0000000000..663057673d --- /dev/null +++ b/src/mlpack/methods/ann/visitor/input_shape_visitor.hpp @@ -0,0 +1,57 @@ +/** + * @file input_shape_visitor.hpp + * @author Nippun Sharma + * + * This file provides an abstraction for the InputShape() function for + * different layers and automatically directs any parameter to the right layer + * type. + * + * mlpack is free software; you may redistribute it and/or modify it under the + * terms of the 3-clause BSD license. You should have received a copy of the + * 3-clause BSD license along with mlpack. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. + */ +#ifndef MLPACK_METHODS_ANN_VISITOR_INPUT_SHAPE_VISITOR_HPP +#define MLPACK_METHODS_ANN_VISITOR_INPUT_SHAPE_VISITOR_HPP + +#include +#include + +#include + +namespace mlpack { +namespace ann { + +/** + * InShapeVisitor returns the input shape a Layer expects. + */ +class InShapeVisitor : public boost::static_visitor +{ + public: + //! Return the input shape of layer. + template + size_t operator()(LayerType* layer) const; + + size_t operator()(MoreTypes layer) const; + + private: + //! If the module doesn't implement the InputShape() function return 0. + template + typename std::enable_if< + !HasInputShapeCheck::value, size_t>::type + LayerInputShape(T* layer) const; + + //! If the module implements the InputShape() function returns the input shape. + template + typename std::enable_if< + HasInputShapeCheck::value, size_t>::type + LayerInputShape(T* layer) const; +}; + +} // namespace ann +} // namespace mlpack + +// Include implementation. +#include "input_shape_visitor_impl.hpp" + +#endif \ No newline at end of file diff --git a/src/mlpack/methods/ann/visitor/input_shape_visitor_impl.hpp b/src/mlpack/methods/ann/visitor/input_shape_visitor_impl.hpp new file mode 100644 index 0000000000..6f8c3b123d --- /dev/null +++ b/src/mlpack/methods/ann/visitor/input_shape_visitor_impl.hpp @@ -0,0 +1,52 @@ +/** + * @file input_shape_visitor_impl.hpp + * @author Nippun Sharma + * + * Implementation of the InputShape() function layer abstraction. + * + * mlpack is free software; you may redistribute it and/or modify it under the + * terms of the 3-clause BSD license. You should have received a copy of the + * 3-clause BSD license along with mlpack. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. + */ +#ifndef MLPACK_METHODS_ANN_VISITOR_INPUT_SHAPE_VISITOR_IMPL_HPP +#define MLPACK_METHODS_ANN_VISITOR_INPUT_SHAPE_VISITOR_IMPL_HPP + +// In case it hasn't been included yet. +#include "input_shape_visitor.hpp" + +namespace mlpack { +namespace ann { + +//! InShapeVisitor visitor class. +template +inline std::size_t InShapeVisitor::operator()(LayerType* layer) const +{ + return LayerInputShape(layer); +} + +inline std::size_t InShapeVisitor::operator()(MoreTypes layer) const +{ + return layer.apply_visitor(*this); +} + +template +inline typename std::enable_if< + !HasInputShapeCheck::value, std::size_t>::type +InShapeVisitor::LayerInputShape(T* /* layer */) const +{ + return 0; +} + +template +inline typename std::enable_if< + HasInputShapeCheck::value, std::size_t>::type +InShapeVisitor::LayerInputShape(T* layer) const +{ + return layer->InputShape(); +} + +} // namespace ann +} // namespace mlpack + +#endif \ No newline at end of file From 9e0b93a068b193a70089a0fa12d674245cc29f57 Mon Sep 17 00:00:00 2001 From: NippunSharma Date: Thu, 26 Nov 2020 23:11:35 +0530 Subject: [PATCH 02/51] removed some stuff --- src/mlpack/methods/ann/ffn_impl.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/mlpack/methods/ann/ffn_impl.hpp b/src/mlpack/methods/ann/ffn_impl.hpp index 9335a7bded..4ef10c2912 100644 --- a/src/mlpack/methods/ann/ffn_impl.hpp +++ b/src/mlpack/methods/ann/ffn_impl.hpp @@ -14,7 +14,6 @@ // In case it hasn't been included yet. #include "ffn.hpp" -#include #include "visitor/forward_visitor.hpp" #include "visitor/backward_visitor.hpp" #include "visitor/deterministic_set_visitor.hpp" From 5f067334cb26fd1c8ade45b05ead919f5942efd3 Mon Sep 17 00:00:00 2001 From: NippunSharma Date: Thu, 26 Nov 2020 23:14:24 +0530 Subject: [PATCH 03/51] added empty lines --- src/mlpack/methods/ann/ffn_impl.hpp | 1 + src/mlpack/methods/ann/visitor/input_shape_visitor.hpp | 2 +- src/mlpack/methods/ann/visitor/input_shape_visitor_impl.hpp | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/mlpack/methods/ann/ffn_impl.hpp b/src/mlpack/methods/ann/ffn_impl.hpp index 4ef10c2912..8b5ac908c2 100644 --- a/src/mlpack/methods/ann/ffn_impl.hpp +++ b/src/mlpack/methods/ann/ffn_impl.hpp @@ -14,6 +14,7 @@ // In case it hasn't been included yet. #include "ffn.hpp" + #include "visitor/forward_visitor.hpp" #include "visitor/backward_visitor.hpp" #include "visitor/deterministic_set_visitor.hpp" diff --git a/src/mlpack/methods/ann/visitor/input_shape_visitor.hpp b/src/mlpack/methods/ann/visitor/input_shape_visitor.hpp index 663057673d..bb1b4b392a 100644 --- a/src/mlpack/methods/ann/visitor/input_shape_visitor.hpp +++ b/src/mlpack/methods/ann/visitor/input_shape_visitor.hpp @@ -54,4 +54,4 @@ class InShapeVisitor : public boost::static_visitor // Include implementation. #include "input_shape_visitor_impl.hpp" -#endif \ No newline at end of file +#endif diff --git a/src/mlpack/methods/ann/visitor/input_shape_visitor_impl.hpp b/src/mlpack/methods/ann/visitor/input_shape_visitor_impl.hpp index 6f8c3b123d..2b87081927 100644 --- a/src/mlpack/methods/ann/visitor/input_shape_visitor_impl.hpp +++ b/src/mlpack/methods/ann/visitor/input_shape_visitor_impl.hpp @@ -49,4 +49,4 @@ InShapeVisitor::LayerInputShape(T* layer) const } // namespace ann } // namespace mlpack -#endif \ No newline at end of file +#endif From 70749bd0bb8f241810acdc1bcf9738906a5e258d Mon Sep 17 00:00:00 2001 From: NippunSharma Date: Thu, 26 Nov 2020 23:49:34 +0530 Subject: [PATCH 04/51] changed comments --- src/mlpack/methods/ann/ffn.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mlpack/methods/ann/ffn.hpp b/src/mlpack/methods/ann/ffn.hpp index 512f51fcf9..93b3136a0b 100644 --- a/src/mlpack/methods/ann/ffn.hpp +++ b/src/mlpack/methods/ann/ffn.hpp @@ -326,7 +326,7 @@ class FFN arma::mat& Predictors() { return predictors; } /** - * Check wether the input size is consistent with the layer requirements. + * Check wether the input shape is consistent with the layer requirements. * * @param inputShape shape of the input * @param functionName function that checks the input size From b63f5ad0af68105a12915da0717233359a8c0d6a Mon Sep 17 00:00:00 2001 From: NippunSharma Date: Fri, 27 Nov 2020 13:03:00 +0530 Subject: [PATCH 05/51] added InputShape() to conv --- src/mlpack/methods/ann/layer/convolution.hpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/mlpack/methods/ann/layer/convolution.hpp b/src/mlpack/methods/ann/layer/convolution.hpp index bcebf756cf..6eda5989a5 100644 --- a/src/mlpack/methods/ann/layer/convolution.hpp +++ b/src/mlpack/methods/ann/layer/convolution.hpp @@ -259,6 +259,12 @@ class Convolution return (outSize * inSize * kernelWidth * kernelHeight) + outSize; } + //! Get the shape of the input. + size_t InputShape() const + { + return inputHeight*inputWidth*inSize; + } + /** * Serialize the layer. */ From ecc63a81aac1b9e14209a2ac84aa6178ec50275d Mon Sep 17 00:00:00 2001 From: NippunSharma Date: Sat, 28 Nov 2020 17:52:25 +0530 Subject: [PATCH 06/51] add InputShape() to lstm and fast lstm --- src/mlpack/methods/ann/layer/fast_lstm.hpp | 5 +++++ src/mlpack/methods/ann/layer/lstm.hpp | 5 +++++ src/mlpack/methods/ann/rnn.hpp | 1 + src/mlpack/methods/ann/rnn_impl.hpp | 1 + 4 files changed, 12 insertions(+) diff --git a/src/mlpack/methods/ann/layer/fast_lstm.hpp b/src/mlpack/methods/ann/layer/fast_lstm.hpp index 121c97e176..67859bd0d4 100644 --- a/src/mlpack/methods/ann/layer/fast_lstm.hpp +++ b/src/mlpack/methods/ann/layer/fast_lstm.hpp @@ -170,6 +170,11 @@ class FastLSTM return 4 * outSize * inSize + 4 * outSize + 4 * outSize * outSize; } + size_t InputShape() const + { + return inSize; + } + /** * Serialize the layer */ diff --git a/src/mlpack/methods/ann/layer/lstm.hpp b/src/mlpack/methods/ann/layer/lstm.hpp index 1941778ce9..685d7b7994 100644 --- a/src/mlpack/methods/ann/layer/lstm.hpp +++ b/src/mlpack/methods/ann/layer/lstm.hpp @@ -171,6 +171,11 @@ class LSTM //! Get the number of output units. size_t OutSize() const { return outSize; } + size_t InputShape() const + { + return inSize; + } + /** * Serialize the layer */ diff --git a/src/mlpack/methods/ann/rnn.hpp b/src/mlpack/methods/ann/rnn.hpp index e9e6815de4..34a613daaf 100644 --- a/src/mlpack/methods/ann/rnn.hpp +++ b/src/mlpack/methods/ann/rnn.hpp @@ -18,6 +18,7 @@ #include "visitor/delta_visitor.hpp" #include "visitor/output_parameter_visitor.hpp" #include "visitor/reset_visitor.hpp" +#include "visitor/input_shape_visitor.hpp" #include "init_rules/network_init.hpp" diff --git a/src/mlpack/methods/ann/rnn_impl.hpp b/src/mlpack/methods/ann/rnn_impl.hpp index b81bc397b2..586e4e95dc 100644 --- a/src/mlpack/methods/ann/rnn_impl.hpp +++ b/src/mlpack/methods/ann/rnn_impl.hpp @@ -24,6 +24,7 @@ #include "visitor/gradient_set_visitor.hpp" #include "visitor/gradient_visitor.hpp" #include "visitor/weight_set_visitor.hpp" +#include "visitor/input_shape_visitor.hpp" namespace mlpack { namespace ann /** Artificial Neural Network. */ { From 2467580ef6c3f8efd23a54aaf144e26735da6605 Mon Sep 17 00:00:00 2001 From: NippunSharma Date: Sat, 28 Nov 2020 18:30:21 +0530 Subject: [PATCH 07/51] added CheckInputShape() to RNN and some comments --- src/mlpack/methods/ann/layer/fast_lstm.hpp | 1 + src/mlpack/methods/ann/layer/lstm.hpp | 1 + src/mlpack/methods/ann/rnn.hpp | 8 ++++++ src/mlpack/methods/ann/rnn_impl.hpp | 33 ++++++++++++++++++++++ 4 files changed, 43 insertions(+) diff --git a/src/mlpack/methods/ann/layer/fast_lstm.hpp b/src/mlpack/methods/ann/layer/fast_lstm.hpp index 67859bd0d4..bcf1a1c201 100644 --- a/src/mlpack/methods/ann/layer/fast_lstm.hpp +++ b/src/mlpack/methods/ann/layer/fast_lstm.hpp @@ -170,6 +170,7 @@ class FastLSTM return 4 * outSize * inSize + 4 * outSize + 4 * outSize * outSize; } + //! Get the shape of the input. size_t InputShape() const { return inSize; diff --git a/src/mlpack/methods/ann/layer/lstm.hpp b/src/mlpack/methods/ann/layer/lstm.hpp index 685d7b7994..50a1d466af 100644 --- a/src/mlpack/methods/ann/layer/lstm.hpp +++ b/src/mlpack/methods/ann/layer/lstm.hpp @@ -171,6 +171,7 @@ class LSTM //! Get the number of output units. size_t OutSize() const { return outSize; } + //! Get the shape of the input. size_t InputShape() const { return inSize; diff --git a/src/mlpack/methods/ann/rnn.hpp b/src/mlpack/methods/ann/rnn.hpp index 34a613daaf..e0f00a0e87 100644 --- a/src/mlpack/methods/ann/rnn.hpp +++ b/src/mlpack/methods/ann/rnn.hpp @@ -302,6 +302,14 @@ class RNN //! Modify the matrix of data points (predictors). arma::cube& Predictors() { return predictors; } + /** + * Check wether the input shape is consistent with the layer requirements. + * + * @param inputShape shape of the input + * @param functionName function that checks the input size + */ + void CheckInputShape(size_t inputShape, std::string functionName); + /** * Reset the state of the network. This ensures that all internally-held * gradients are set to 0, all memory cells are reset, and the parameters diff --git a/src/mlpack/methods/ann/rnn_impl.hpp b/src/mlpack/methods/ann/rnn_impl.hpp index 586e4e95dc..d6fd26d501 100644 --- a/src/mlpack/methods/ann/rnn_impl.hpp +++ b/src/mlpack/methods/ann/rnn_impl.hpp @@ -60,6 +60,33 @@ RNN::~RNN() } } +template +void RNN::CheckInputShape( + size_t inputShape, std::string functionName) +{ + for (size_t l=0; l template @@ -104,6 +131,8 @@ double RNN::Train( OptimizerType& optimizer, CallbackTypes&&... callbacks) { + CheckInputShape(predictors.n_rows, "Train()"); + numFunctions = responses.n_cols; this->predictors = std::move(predictors); @@ -148,6 +177,8 @@ double RNN::Train( arma::cube responses, CallbackTypes&&... callbacks) { + CheckInputShape(predictors.n_rows, "Train()"); + numFunctions = responses.n_cols; this->predictors = std::move(predictors); @@ -180,6 +211,8 @@ template::Predict( arma::cube predictors, arma::cube& results, const size_t batchSize) { + CheckInputShape(predictors.n_rows, "Train()"); + ResetCells(); if (parameter.is_empty()) From ef5e56e63cc52b00679f77936a7a0d35a809d545 Mon Sep 17 00:00:00 2001 From: NippunSharma Date: Sun, 29 Nov 2020 12:32:03 +0530 Subject: [PATCH 08/51] added InputShape() to recurrent class --- src/mlpack/methods/ann/layer/recurrent.hpp | 4 +++ .../methods/ann/layer/recurrent_impl.hpp | 31 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/mlpack/methods/ann/layer/recurrent.hpp b/src/mlpack/methods/ann/layer/recurrent.hpp index 0466b265b0..c6e396ddad 100644 --- a/src/mlpack/methods/ann/layer/recurrent.hpp +++ b/src/mlpack/methods/ann/layer/recurrent.hpp @@ -19,6 +19,7 @@ #include "../visitor/delta_visitor.hpp" #include "../visitor/copy_visitor.hpp" #include "../visitor/output_parameter_visitor.hpp" +#include "../visitor/input_shape_visitor.hpp" #include "layer_types.hpp" #include "add_merge.hpp" @@ -139,6 +140,9 @@ class Recurrent //! Get the number of steps to backpropagate through time. size_t const& Rho() const { return rho; } + //! Get the shape of the input. + size_t InputShape() const; + /** * Serialize the layer */ diff --git a/src/mlpack/methods/ann/layer/recurrent_impl.hpp b/src/mlpack/methods/ann/layer/recurrent_impl.hpp index 23a1dc4625..0c1ace86c1 100644 --- a/src/mlpack/methods/ann/layer/recurrent_impl.hpp +++ b/src/mlpack/methods/ann/layer/recurrent_impl.hpp @@ -20,6 +20,7 @@ #include "../visitor/backward_visitor.hpp" #include "../visitor/gradient_visitor.hpp" #include "../visitor/gradient_zero_visitor.hpp" +#include "../visitor/input_shape_visitor.hpp" namespace mlpack { namespace ann /** Artificial Neural Network. */ { @@ -126,6 +127,36 @@ Recurrent::Recurrent( this->network.push_back(recurrentModule); } +template +size_t Recurrent::InputShape() const +{ + size_t inputShapeStartModule = boost::apply_visitor(InShapeVisitor(), startModule); + size_t inputShapeInputModule = boost::apply_visitor(InShapeVisitor(), inputModule); + size_t inputShapeFeedbackModule = boost::apply_visitor(InShapeVisitor(), feedbackModule); + size_t inputShapeTransferModule = boost::apply_visitor(InShapeVisitor(), transferModule); + + if (inputShapeStartModule != 0) + return inputShapeStartModule; + else + { + if (inputShapeInputModule != 0) + return inputShapeInputModule; + else + { + if (inputShapeFeedbackModule != 0) + return inputShapeFeedbackModule; + else + { + if (inputShapeTransferModule != 0) + return inputShapeTransferModule; + else + return 0; + } + } + } +} + template template From 01b1480f22d08e0d5d0523ae4b91a1105b456ca1 Mon Sep 17 00:00:00 2001 From: NippunSharma Date: Sun, 29 Nov 2020 12:49:22 +0530 Subject: [PATCH 09/51] changed functionName from Train() to Predict() --- src/mlpack/methods/ann/rnn_impl.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mlpack/methods/ann/rnn_impl.hpp b/src/mlpack/methods/ann/rnn_impl.hpp index d6fd26d501..ff58a81ff1 100644 --- a/src/mlpack/methods/ann/rnn_impl.hpp +++ b/src/mlpack/methods/ann/rnn_impl.hpp @@ -211,7 +211,7 @@ template::Predict( arma::cube predictors, arma::cube& results, const size_t batchSize) { - CheckInputShape(predictors.n_rows, "Train()"); + CheckInputShape(predictors.n_rows, "Predict()"); ResetCells(); From 9dc9aa01f209d3b6e44df0a9cecd185f8709dc02 Mon Sep 17 00:00:00 2001 From: NippunSharma Date: Sun, 29 Nov 2020 14:13:25 +0530 Subject: [PATCH 10/51] added InputShape() to LinearNoBias, NoisyLinear --- src/mlpack/methods/ann/layer/linear_no_bias.hpp | 6 ++++++ src/mlpack/methods/ann/layer/noisylinear.hpp | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/mlpack/methods/ann/layer/linear_no_bias.hpp b/src/mlpack/methods/ann/layer/linear_no_bias.hpp index a06e97e735..7182e84238 100644 --- a/src/mlpack/methods/ann/layer/linear_no_bias.hpp +++ b/src/mlpack/methods/ann/layer/linear_no_bias.hpp @@ -123,6 +123,12 @@ class LinearNoBias //! Modify the gradient. OutputDataType& Gradient() { return gradient; } + //! Get the shape of the input. + size_t InputShape() const + { + return inSize; + } + /** * Serialize the layer */ diff --git a/src/mlpack/methods/ann/layer/noisylinear.hpp b/src/mlpack/methods/ann/layer/noisylinear.hpp index 34ca70193b..af10496d61 100644 --- a/src/mlpack/methods/ann/layer/noisylinear.hpp +++ b/src/mlpack/methods/ann/layer/noisylinear.hpp @@ -130,6 +130,12 @@ class NoisyLinear //! Modify the gradient. OutputDataType& Gradient() { return gradient; } + //! Get the shape of the input. + size_t InputShape() const + { + return inSize; + } + //! Modify the bias weights of the layer. arma::mat& Bias() { return bias; } From a44167f289a51286f8f67a70844c9f583e4d08a8 Mon Sep 17 00:00:00 2001 From: Nippun Sharma <53967069+NippunSharma@users.noreply.github.com> Date: Tue, 1 Dec 2020 11:19:01 +0530 Subject: [PATCH 11/51] Update src/mlpack/methods/ann/ffn.hpp Co-authored-by: Marcus Edel --- src/mlpack/methods/ann/ffn.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mlpack/methods/ann/ffn.hpp b/src/mlpack/methods/ann/ffn.hpp index 93b3136a0b..7befd23bda 100644 --- a/src/mlpack/methods/ann/ffn.hpp +++ b/src/mlpack/methods/ann/ffn.hpp @@ -326,7 +326,7 @@ class FFN arma::mat& Predictors() { return predictors; } /** - * Check wether the input shape is consistent with the layer requirements. + * Check whether the input shape is consistent with the layer requirements. * * @param inputShape shape of the input * @param functionName function that checks the input size From 45845f804c1153efa8b64753caf39864f85318cc Mon Sep 17 00:00:00 2001 From: Nippun Sharma <53967069+NippunSharma@users.noreply.github.com> Date: Tue, 1 Dec 2020 11:19:14 +0530 Subject: [PATCH 12/51] Update src/mlpack/methods/ann/ffn.hpp Co-authored-by: Marcus Edel --- src/mlpack/methods/ann/ffn.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mlpack/methods/ann/ffn.hpp b/src/mlpack/methods/ann/ffn.hpp index 7befd23bda..6cbb81d064 100644 --- a/src/mlpack/methods/ann/ffn.hpp +++ b/src/mlpack/methods/ann/ffn.hpp @@ -328,8 +328,8 @@ class FFN /** * Check whether the input shape is consistent with the layer requirements. * - * @param inputShape shape of the input - * @param functionName function that checks the input size + * @param inputShape Dhape of the input + * @param functionName Function that checks the input size */ void CheckInputShape(size_t inputShape, std::string functionName); From e773dff64e2e00b51ebbda2f1b72d2ccacf40807 Mon Sep 17 00:00:00 2001 From: Nippun Sharma <53967069+NippunSharma@users.noreply.github.com> Date: Tue, 1 Dec 2020 11:21:03 +0530 Subject: [PATCH 13/51] Update src/mlpack/methods/ann/ffn.hpp Co-authored-by: Marcus Edel --- src/mlpack/methods/ann/ffn.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mlpack/methods/ann/ffn.hpp b/src/mlpack/methods/ann/ffn.hpp index 6cbb81d064..8a02e1983d 100644 --- a/src/mlpack/methods/ann/ffn.hpp +++ b/src/mlpack/methods/ann/ffn.hpp @@ -331,7 +331,7 @@ class FFN * @param inputShape Dhape of the input * @param functionName Function that checks the input size */ - void CheckInputShape(size_t inputShape, std::string functionName); + void CheckInputShape(const size_t inputShape, const std::string& functionName); /** * Reset the module infomration (weights/parameters). From a6cdc2db1f1c454b315b0ffef468878f38b88c4b Mon Sep 17 00:00:00 2001 From: NippunSharma Date: Tue, 1 Dec 2020 12:30:06 +0530 Subject: [PATCH 14/51] updated CheckInputShape in ffn_impl, rnn, rnn_impl --- src/mlpack/methods/ann/ffn_impl.hpp | 2 +- src/mlpack/methods/ann/rnn.hpp | 2 +- src/mlpack/methods/ann/rnn_impl.hpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mlpack/methods/ann/ffn_impl.hpp b/src/mlpack/methods/ann/ffn_impl.hpp index 8b5ac908c2..4261ad5260 100644 --- a/src/mlpack/methods/ann/ffn_impl.hpp +++ b/src/mlpack/methods/ann/ffn_impl.hpp @@ -54,7 +54,7 @@ FFN::~FFN() template void FFN::CheckInputShape( - size_t inputShape, std::string functionName) + const size_t inputShape, const std::string& functionName) { for (size_t l=0; l::~RNN() template void RNN::CheckInputShape( - size_t inputShape, std::string functionName) + const size_t inputShape, const std::string& functionName) { for (size_t l=0; l Date: Wed, 2 Dec 2020 00:06:43 +0530 Subject: [PATCH 15/51] added util folder and moved CheckInputShape --- src/mlpack/methods/ann/CMakeLists.txt | 1 + src/mlpack/methods/ann/ffn.hpp | 9 ---- src/mlpack/methods/ann/ffn_impl.hpp | 46 +++++----------- src/mlpack/methods/ann/rnn.hpp | 9 ---- src/mlpack/methods/ann/rnn_impl.hpp | 42 ++++----------- src/mlpack/methods/ann/util/CMakeLists.txt | 14 +++++ .../methods/ann/util/check_input_shape.hpp | 52 +++++++++++++++++++ 7 files changed, 92 insertions(+), 81 deletions(-) create mode 100644 src/mlpack/methods/ann/util/CMakeLists.txt create mode 100644 src/mlpack/methods/ann/util/check_input_shape.hpp diff --git a/src/mlpack/methods/ann/CMakeLists.txt b/src/mlpack/methods/ann/CMakeLists.txt index 3c8236809c..8888113548 100644 --- a/src/mlpack/methods/ann/CMakeLists.txt +++ b/src/mlpack/methods/ann/CMakeLists.txt @@ -20,6 +20,7 @@ add_subdirectory(gan) add_subdirectory(rbm) add_subdirectory(augmented) add_subdirectory(regularizer) +add_subdirectory(util) # Add directory name to sources. set(DIR_SRCS) diff --git a/src/mlpack/methods/ann/ffn.hpp b/src/mlpack/methods/ann/ffn.hpp index 8a02e1983d..1c65bbb749 100644 --- a/src/mlpack/methods/ann/ffn.hpp +++ b/src/mlpack/methods/ann/ffn.hpp @@ -24,7 +24,6 @@ #include "visitor/weight_size_visitor.hpp" #include "visitor/copy_visitor.hpp" #include "visitor/loss_visitor.hpp" -#include "visitor/input_shape_visitor.hpp" #include "init_rules/network_init.hpp" @@ -325,14 +324,6 @@ class FFN //! Modify the matrix of data points (predictors). arma::mat& Predictors() { return predictors; } - /** - * Check whether the input shape is consistent with the layer requirements. - * - * @param inputShape Dhape of the input - * @param functionName Function that checks the input size - */ - void CheckInputShape(const size_t inputShape, const std::string& functionName); - /** * Reset the module infomration (weights/parameters). */ diff --git a/src/mlpack/methods/ann/ffn_impl.hpp b/src/mlpack/methods/ann/ffn_impl.hpp index 4261ad5260..401c094ca6 100644 --- a/src/mlpack/methods/ann/ffn_impl.hpp +++ b/src/mlpack/methods/ann/ffn_impl.hpp @@ -22,7 +22,8 @@ #include "visitor/gradient_visitor.hpp" #include "visitor/set_input_height_visitor.hpp" #include "visitor/set_input_width_visitor.hpp" -#include "visitor/input_shape_visitor.hpp" + +#include "util/check_input_shape.hpp" namespace mlpack { namespace ann /** Artificial Neural Network. */ { @@ -51,33 +52,6 @@ FFN::~FFN() boost::apply_visitor(deleteVisitor)); } -template -void FFN::CheckInputShape( - const size_t inputShape, const std::string& functionName) -{ - for (size_t l=0; l void FFN::ResetData( @@ -137,7 +111,9 @@ double FFN::Train( OptimizerType& optimizer, CallbackTypes&&... callbacks) { - CheckInputShape(predictors.n_rows, "Train()"); + CheckInputShape > >(network, + predictors.n_rows, + "FFN<>::Train()"); ResetData(std::move(predictors), std::move(responses)); @@ -161,7 +137,9 @@ double FFN::Train( arma::mat responses, CallbackTypes&&... callbacks) { - CheckInputShape(predictors.n_rows, "Train()"); + CheckInputShape > >(network, + predictors.n_rows, + "FFN<>::Train()"); ResetData(std::move(predictors), std::move(responses)); @@ -249,7 +227,9 @@ template::Predict( arma::mat predictors, arma::mat& results) { - CheckInputShape(predictors.n_rows, "Predict()"); + CheckInputShape > >(network, + predictors.n_rows, + "FFN<>::Predict()"); if (parameter.is_empty()) ResetParameters(); @@ -284,7 +264,9 @@ template double FFN::Evaluate( const PredictorsType& predictors, const ResponsesType& responses) { - CheckInputShape(predictors.n_rows, "Evaluate()"); + CheckInputShape > >(network, + predictors.n_rows, + "FFN<>::Evaluate()"); if (parameter.is_empty()) ResetParameters(); diff --git a/src/mlpack/methods/ann/rnn.hpp b/src/mlpack/methods/ann/rnn.hpp index 031731533c..e9e6815de4 100644 --- a/src/mlpack/methods/ann/rnn.hpp +++ b/src/mlpack/methods/ann/rnn.hpp @@ -18,7 +18,6 @@ #include "visitor/delta_visitor.hpp" #include "visitor/output_parameter_visitor.hpp" #include "visitor/reset_visitor.hpp" -#include "visitor/input_shape_visitor.hpp" #include "init_rules/network_init.hpp" @@ -302,14 +301,6 @@ class RNN //! Modify the matrix of data points (predictors). arma::cube& Predictors() { return predictors; } - /** - * Check wether the input shape is consistent with the layer requirements. - * - * @param inputShape shape of the input - * @param functionName function that checks the input size - */ - void CheckInputShape(const size_t inputShape, const std::string& functionName); - /** * Reset the state of the network. This ensures that all internally-held * gradients are set to 0, all memory cells are reset, and the parameters diff --git a/src/mlpack/methods/ann/rnn_impl.hpp b/src/mlpack/methods/ann/rnn_impl.hpp index 0feb8bea58..365056a739 100644 --- a/src/mlpack/methods/ann/rnn_impl.hpp +++ b/src/mlpack/methods/ann/rnn_impl.hpp @@ -24,7 +24,8 @@ #include "visitor/gradient_set_visitor.hpp" #include "visitor/gradient_visitor.hpp" #include "visitor/weight_set_visitor.hpp" -#include "visitor/input_shape_visitor.hpp" + +#include "util/check_input_shape.hpp" namespace mlpack { namespace ann /** Artificial Neural Network. */ { @@ -60,33 +61,6 @@ RNN::~RNN() } } -template -void RNN::CheckInputShape( - const size_t inputShape, const std::string& functionName) -{ - for (size_t l=0; l template @@ -131,7 +105,9 @@ double RNN::Train( OptimizerType& optimizer, CallbackTypes&&... callbacks) { - CheckInputShape(predictors.n_rows, "Train()"); + CheckInputShape > >(network, + predictors.n_rows, + "RNN<>::Train()"); numFunctions = responses.n_cols; @@ -177,7 +153,9 @@ double RNN::Train( arma::cube responses, CallbackTypes&&... callbacks) { - CheckInputShape(predictors.n_rows, "Train()"); + CheckInputShape > >(network, + predictors.n_rows, + "RNN<>::Train()"); numFunctions = responses.n_cols; @@ -211,7 +189,9 @@ template::Predict( arma::cube predictors, arma::cube& results, const size_t batchSize) { - CheckInputShape(predictors.n_rows, "Predict()"); + CheckInputShape > >(network, + predictors.n_rows, + "RNN<>::Predict()"); ResetCells(); diff --git a/src/mlpack/methods/ann/util/CMakeLists.txt b/src/mlpack/methods/ann/util/CMakeLists.txt new file mode 100644 index 0000000000..dffec0c265 --- /dev/null +++ b/src/mlpack/methods/ann/util/CMakeLists.txt @@ -0,0 +1,14 @@ +# Define the files we need to compile +# Anything not in this list will not be compiled into mlpack. +set(SOURCES + check_input_shape.hpp +) + +# Add directory name to sources. +set(DIR_SRCS) +foreach(file ${SOURCES}) + set(DIR_SRCS ${DIR_SRCS} ${CMAKE_CURRENT_SOURCE_DIR}/${file}) +endforeach() +# Append sources (with directory name) to list of all mlpack sources (used at +# the parent scope). +set(MLPACK_SRCS ${MLPACK_SRCS} ${DIR_SRCS} PARENT_SCOPE) \ No newline at end of file diff --git a/src/mlpack/methods/ann/util/check_input_shape.hpp b/src/mlpack/methods/ann/util/check_input_shape.hpp new file mode 100644 index 0000000000..52fa019e9c --- /dev/null +++ b/src/mlpack/methods/ann/util/check_input_shape.hpp @@ -0,0 +1,52 @@ +/** + * @file check_input_shape.hpp + * @author Nippun Sharma + * + * Definition of the CheckInputShape() function that checks + * whether the shape of input is consistent with the first layer + * of the neural network. + * + * mlpack is free software; you may redistribute it and/or modify it under the + * terms of the 3-clause BSD license. You should have received a copy of the + * 3-clause BSD license along with mlpack. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. + */ + +#ifndef MLPACK_METHODS_ANN_UTIL_CHECK_INPUT_SHAPE_HPP +#define MLPACK_METHODS_ANN_UTIL_CHECK_INPUT_SHAPE_HPP + +#include + +namespace mlpack { +namespace ann /** Artificial Neural Network. */{ + +template +void CheckInputShape(T network, const size_t inputShape, + const std::string& functionName) +{ + for (size_t l=0; l Date: Wed, 2 Dec 2020 15:13:08 +0530 Subject: [PATCH 16/51] Update src/mlpack/methods/ann/layer/convolution.hpp Co-authored-by: Ryan Curtin --- src/mlpack/methods/ann/layer/convolution.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mlpack/methods/ann/layer/convolution.hpp b/src/mlpack/methods/ann/layer/convolution.hpp index 6eda5989a5..1571c3e414 100644 --- a/src/mlpack/methods/ann/layer/convolution.hpp +++ b/src/mlpack/methods/ann/layer/convolution.hpp @@ -262,7 +262,7 @@ class Convolution //! Get the shape of the input. size_t InputShape() const { - return inputHeight*inputWidth*inSize; + return inputHeight * inputWidth * inSize; } /** From dd444d6c55b00fafb55e21ff3756a4e2efd2f16f Mon Sep 17 00:00:00 2001 From: Nippun Sharma <53967069+NippunSharma@users.noreply.github.com> Date: Wed, 2 Dec 2020 15:13:58 +0530 Subject: [PATCH 17/51] Update src/mlpack/methods/ann/layer/recurrent_impl.hpp Co-authored-by: Ryan Curtin --- src/mlpack/methods/ann/layer/recurrent_impl.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mlpack/methods/ann/layer/recurrent_impl.hpp b/src/mlpack/methods/ann/layer/recurrent_impl.hpp index 0c1ace86c1..a4e962227b 100644 --- a/src/mlpack/methods/ann/layer/recurrent_impl.hpp +++ b/src/mlpack/methods/ann/layer/recurrent_impl.hpp @@ -136,6 +136,7 @@ size_t Recurrent::InputShape() c size_t inputShapeFeedbackModule = boost::apply_visitor(InShapeVisitor(), feedbackModule); size_t inputShapeTransferModule = boost::apply_visitor(InShapeVisitor(), transferModule); + // Return the size of the first module that we have. if (inputShapeStartModule != 0) return inputShapeStartModule; else From ecf66d7bbbfa7d39f7e8c6fc6dbc0f3cfb007c0d Mon Sep 17 00:00:00 2001 From: NippunSharma Date: Wed, 2 Dec 2020 15:52:21 +0530 Subject: [PATCH 18/51] added comments in recurrent --- src/mlpack/methods/ann/layer/recurrent_impl.hpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/mlpack/methods/ann/layer/recurrent_impl.hpp b/src/mlpack/methods/ann/layer/recurrent_impl.hpp index a4e962227b..e37df89b69 100644 --- a/src/mlpack/methods/ann/layer/recurrent_impl.hpp +++ b/src/mlpack/methods/ann/layer/recurrent_impl.hpp @@ -139,18 +139,25 @@ size_t Recurrent::InputShape() c // Return the size of the first module that we have. if (inputShapeStartModule != 0) return inputShapeStartModule; + // If first module does not have any weights. else { + // Return the size of the second module we have. if (inputShapeInputModule != 0) return inputShapeInputModule; + // If second module does not have any weights. else { + // Return the size of the third module we have. if (inputShapeFeedbackModule != 0) return inputShapeFeedbackModule; + // If the third module does not have any weights. else { + // Return the size of the fourth module we have if (inputShapeTransferModule != 0) return inputShapeTransferModule; + // If the fourth module does not have any weights. else return 0; } From b9e4bcd72932e462450e39e3635232e272942048 Mon Sep 17 00:00:00 2001 From: NippunSharma Date: Wed, 2 Dec 2020 15:56:21 +0530 Subject: [PATCH 19/51] changed rows to dimensions --- src/mlpack/methods/ann/util/check_input_shape.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mlpack/methods/ann/util/check_input_shape.hpp b/src/mlpack/methods/ann/util/check_input_shape.hpp index 52fa019e9c..346b8e929f 100644 --- a/src/mlpack/methods/ann/util/check_input_shape.hpp +++ b/src/mlpack/methods/ann/util/check_input_shape.hpp @@ -40,7 +40,7 @@ void CheckInputShape(T network, const size_t inputShape, std::string estr = functionName + ": "; estr += "the first layer of the network expects "; estr += std::to_string(layerInShape) + " elements, "; - estr += "but the input has " + std::to_string(inputShape) + " rows! "; + estr += "but the input has " + std::to_string(inputShape) + " dimensions! "; throw std::logic_error(estr); } } From 6d66dfe846fdd137928d34741b9a3beadb448f09 Mon Sep 17 00:00:00 2001 From: NippunSharma Date: Wed, 2 Dec 2020 16:03:07 +0530 Subject: [PATCH 20/51] to avoid extra copies --- src/mlpack/methods/ann/util/check_input_shape.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mlpack/methods/ann/util/check_input_shape.hpp b/src/mlpack/methods/ann/util/check_input_shape.hpp index 346b8e929f..b2b7b7e67e 100644 --- a/src/mlpack/methods/ann/util/check_input_shape.hpp +++ b/src/mlpack/methods/ann/util/check_input_shape.hpp @@ -21,7 +21,7 @@ namespace mlpack { namespace ann /** Artificial Neural Network. */{ template -void CheckInputShape(T network, const size_t inputShape, +void CheckInputShape(const T& network, const size_t inputShape, const std::string& functionName) { for (size_t l=0; l Date: Wed, 2 Dec 2020 16:16:51 +0530 Subject: [PATCH 21/51] added to atrous conv --- src/mlpack/methods/ann/layer/atrous_convolution.hpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/mlpack/methods/ann/layer/atrous_convolution.hpp b/src/mlpack/methods/ann/layer/atrous_convolution.hpp index 478f62abe2..daddab76f2 100644 --- a/src/mlpack/methods/ann/layer/atrous_convolution.hpp +++ b/src/mlpack/methods/ann/layer/atrous_convolution.hpp @@ -263,6 +263,12 @@ class AtrousConvolution return (outSize * inSize * kernelWidth * kernelHeight) + outSize; } + //! Get the shape of the input. + size_t InputShape() const + { + return inputHeight * inputWidth * inSize; + } + /** * Serialize the layer. */ From 3f2863b06d195825f17e42ddcac3bf8182e9bc2e Mon Sep 17 00:00:00 2001 From: NippunSharma Date: Wed, 2 Dec 2020 16:18:47 +0530 Subject: [PATCH 22/51] added to transposed conv --- src/mlpack/methods/ann/layer/transposed_convolution.hpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/mlpack/methods/ann/layer/transposed_convolution.hpp b/src/mlpack/methods/ann/layer/transposed_convolution.hpp index a7a89b1dbc..350ca43a26 100644 --- a/src/mlpack/methods/ann/layer/transposed_convolution.hpp +++ b/src/mlpack/methods/ann/layer/transposed_convolution.hpp @@ -274,6 +274,12 @@ class TransposedConvolution //! Modify the right padding width. size_t& PadWRight() { return padWRight; } + //! Get the shape of the input. + size_t InputShape() const + { + return inputHeight * inputWidth * inSize; + } + /** * Serialize the layer. */ From f03464aa2cf46ffc34b18e36253836898456c5b5 Mon Sep 17 00:00:00 2001 From: NippunSharma Date: Wed, 2 Dec 2020 17:39:10 +0530 Subject: [PATCH 23/51] added to bilinear, glimpse, gru, highway, layer_norm, linear3d --- src/mlpack/methods/ann/layer/bilinear_interpolation.hpp | 6 ++++++ src/mlpack/methods/ann/layer/glimpse.hpp | 6 ++++++ src/mlpack/methods/ann/layer/gru.hpp | 6 ++++++ src/mlpack/methods/ann/layer/highway.hpp | 6 ++++++ src/mlpack/methods/ann/layer/layer_norm.hpp | 6 ++++++ src/mlpack/methods/ann/layer/linear3d.hpp | 6 ++++++ 6 files changed, 36 insertions(+) diff --git a/src/mlpack/methods/ann/layer/bilinear_interpolation.hpp b/src/mlpack/methods/ann/layer/bilinear_interpolation.hpp index 817763e973..2d611feb19 100644 --- a/src/mlpack/methods/ann/layer/bilinear_interpolation.hpp +++ b/src/mlpack/methods/ann/layer/bilinear_interpolation.hpp @@ -118,6 +118,12 @@ class BilinearInterpolation //! Modify the depth of the input. size_t& InDepth() { return depth; } + //! Get the shape of the input. + size_t WeightSize() const + { + return InRowSize; + } + /** * Serialize the layer. */ diff --git a/src/mlpack/methods/ann/layer/glimpse.hpp b/src/mlpack/methods/ann/layer/glimpse.hpp index 661fab551d..99a268b6a8 100644 --- a/src/mlpack/methods/ann/layer/glimpse.hpp +++ b/src/mlpack/methods/ann/layer/glimpse.hpp @@ -182,6 +182,12 @@ class Glimpse //! Get the used glimpse size (height = width). size_t GlimpseSize() const { return size;} + //! Get the shape of the input. + size_t InputShape() const + { + return inSize; + } + /** * Serialize the layer. */ diff --git a/src/mlpack/methods/ann/layer/gru.hpp b/src/mlpack/methods/ann/layer/gru.hpp index b732b41af1..3d98a712d8 100644 --- a/src/mlpack/methods/ann/layer/gru.hpp +++ b/src/mlpack/methods/ann/layer/gru.hpp @@ -155,6 +155,12 @@ class GRU //! Get the number of output units. size_t OutSize() const { return outSize; } + //! Get the shape of the input. + size_t InputShape() const + { + return inSize; + } + /** * Serialize the layer */ diff --git a/src/mlpack/methods/ann/layer/highway.hpp b/src/mlpack/methods/ann/layer/highway.hpp index 7e5893c424..aa539a4972 100644 --- a/src/mlpack/methods/ann/layer/highway.hpp +++ b/src/mlpack/methods/ann/layer/highway.hpp @@ -177,6 +177,12 @@ class Highway //! Get the number of input units. size_t InSize() const { return inSize; } + //! Get the shape of the input. + size_t InputShape() const + { + return inSize; + } + /** * Serialize the layer. */ diff --git a/src/mlpack/methods/ann/layer/layer_norm.hpp b/src/mlpack/methods/ann/layer/layer_norm.hpp index ba0d3f4c29..c22408c221 100644 --- a/src/mlpack/methods/ann/layer/layer_norm.hpp +++ b/src/mlpack/methods/ann/layer/layer_norm.hpp @@ -148,6 +148,12 @@ class LayerNorm //! Get the value of epsilon. double Epsilon() const { return eps; } + //! Get the shape of the input. + size_t InputShape() const + { + return size; + } + /** * Serialize the layer. */ diff --git a/src/mlpack/methods/ann/layer/linear3d.hpp b/src/mlpack/methods/ann/layer/linear3d.hpp index b4579a6c62..7bd03e8176 100644 --- a/src/mlpack/methods/ann/layer/linear3d.hpp +++ b/src/mlpack/methods/ann/layer/linear3d.hpp @@ -136,6 +136,12 @@ class Linear3D //! Modify the bias weights of the layer. OutputDataType& Bias() { return bias; } + //! Get the shape of the input. + size_t InputShape() const + { + return inSize; + } + /** * Serialize the layer */ From ed274d7a8b62a1ef1ffa0bd8fdaee6250157760a Mon Sep 17 00:00:00 2001 From: NippunSharma Date: Wed, 2 Dec 2020 18:02:14 +0530 Subject: [PATCH 24/51] added to minibatch_discrimination, radial_basis_function --- src/mlpack/methods/ann/layer/minibatch_discrimination.hpp | 6 ++++++ src/mlpack/methods/ann/layer/radial_basis_function.hpp | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/mlpack/methods/ann/layer/minibatch_discrimination.hpp b/src/mlpack/methods/ann/layer/minibatch_discrimination.hpp index 88f8dff1ba..3448f36b5d 100644 --- a/src/mlpack/methods/ann/layer/minibatch_discrimination.hpp +++ b/src/mlpack/methods/ann/layer/minibatch_discrimination.hpp @@ -134,6 +134,12 @@ class MiniBatchDiscrimination //! Modify the gradient. OutputDataType& Gradient() { return gradient; } + //! Get the shape of the input. + size_t InputShape() const + { + return A; + } + /** * Serialize the layer. */ diff --git a/src/mlpack/methods/ann/layer/radial_basis_function.hpp b/src/mlpack/methods/ann/layer/radial_basis_function.hpp index b867e9e936..2387d612ab 100644 --- a/src/mlpack/methods/ann/layer/radial_basis_function.hpp +++ b/src/mlpack/methods/ann/layer/radial_basis_function.hpp @@ -110,6 +110,12 @@ class RBF //! Modify the delta. OutputDataType& Delta() { return delta; } + //! Get the shape of the input. + size_t InputShape() const + { + return inSize; + } + /** * Serialize the layer. */ From 10f9b49dc0bf91f2a0dddd9b62cee5ac05616c30 Mon Sep 17 00:00:00 2001 From: NippunSharma Date: Sun, 6 Dec 2020 17:26:58 +0530 Subject: [PATCH 25/51] made some changes --- .../methods/ann/layer/recurrent_impl.hpp | 55 +++++++++++-------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/src/mlpack/methods/ann/layer/recurrent_impl.hpp b/src/mlpack/methods/ann/layer/recurrent_impl.hpp index 975103df12..5b1b2d29b5 100644 --- a/src/mlpack/methods/ann/layer/recurrent_impl.hpp +++ b/src/mlpack/methods/ann/layer/recurrent_impl.hpp @@ -130,35 +130,44 @@ template size_t Recurrent::InputShape() const { - size_t inputShapeStartModule = boost::apply_visitor(InShapeVisitor(), startModule); - size_t inputShapeInputModule = boost::apply_visitor(InShapeVisitor(), inputModule); - size_t inputShapeFeedbackModule = boost::apply_visitor(InShapeVisitor(), feedbackModule); - size_t inputShapeTransferModule = boost::apply_visitor(InShapeVisitor(), transferModule); - - // Return the size of the first module that we have. + const size_t inputShapeStartModule = boost::apply_visitor(InShapeVisitor(), startModule); + // Return the input shape of the first module that we have. if (inputShapeStartModule != 0) - return inputShapeStartModule; - // If first module does not have any weights. - else { - // Return the size of the second module we have. - if (inputShapeInputModule != 0) - return inputShapeInputModule; - // If second module does not have any weights. + return inputShapeStartModule; + // If input shape of first module is 0 else { - // Return the size of the third module we have. - if (inputShapeFeedbackModule != 0) - return inputShapeFeedbackModule; - // If the third module does not have any weights. - else + // Return input shape of the second module that we have. + const size_t inputShapeInputModule = boost::apply_visitor(InShapeVisitor(), inputModule); + if (inputShapeInputModule != 0) { - // Return the size of the fourth module we have - if (inputShapeTransferModule != 0) - return inputShapeTransferModule; - // If the fourth module does not have any weights. + return inputShapeInputModule; + // If the input shape of second module is 0 else - return 0; + { + // Return input shape of the third module that we have. + const size_t inputShapeFeedbackModule = boost::apply_visitor(InShapeVisitor(), + feedbackModule); + if (inputShapeFeedbackModule != 0) + { + return inputShapeFeedbackModule; + // If the input shape of the third module is 0 + else + { + // Return the shape of the fourth module that we have. + const size_t inputShapeTransferModule = boost::apply_visitor(InShapeVisitor(), + transferModule); + if (inputShapeTransferModule != 0) + { + return inputShapeTransferModule; + } + // If the input shape of the fourth module is 0. + else + return 0; + } + } + } } } } From f654f9221683aaa1ef8935944c0d49593c107356 Mon Sep 17 00:00:00 2001 From: NippunSharma Date: Sun, 6 Dec 2020 18:53:24 +0530 Subject: [PATCH 26/51] fixing errors --- .../methods/ann/layer/recurrent_impl.hpp | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/mlpack/methods/ann/layer/recurrent_impl.hpp b/src/mlpack/methods/ann/layer/recurrent_impl.hpp index 5b1b2d29b5..0276318b0f 100644 --- a/src/mlpack/methods/ann/layer/recurrent_impl.hpp +++ b/src/mlpack/methods/ann/layer/recurrent_impl.hpp @@ -136,40 +136,40 @@ size_t Recurrent::InputShape() c { return inputShapeStartModule; // If input shape of first module is 0 + else + { + // Return input shape of the second module that we have. + const size_t inputShapeInputModule = boost::apply_visitor(InShapeVisitor(), inputModule); + if (inputShapeInputModule != 0) + { + return inputShapeInputModule; + // If the input shape of second module is 0 else { - // Return input shape of the second module that we have. - const size_t inputShapeInputModule = boost::apply_visitor(InShapeVisitor(), inputModule); - if (inputShapeInputModule != 0) + // Return input shape of the third module that we have. + const size_t inputShapeFeedbackModule = boost::apply_visitor(InShapeVisitor(), + feedbackModule); + if (inputShapeFeedbackModule != 0) { - return inputShapeInputModule; - // If the input shape of second module is 0 - else + return inputShapeFeedbackModule; + // If the input shape of the third module is 0 + else + { + // Return the shape of the fourth module that we have. + const size_t inputShapeTransferModule = boost::apply_visitor(InShapeVisitor(), + transferModule); + if (inputShapeTransferModule != 0) { - // Return input shape of the third module that we have. - const size_t inputShapeFeedbackModule = boost::apply_visitor(InShapeVisitor(), - feedbackModule); - if (inputShapeFeedbackModule != 0) - { - return inputShapeFeedbackModule; - // If the input shape of the third module is 0 - else - { - // Return the shape of the fourth module that we have. - const size_t inputShapeTransferModule = boost::apply_visitor(InShapeVisitor(), - transferModule); - if (inputShapeTransferModule != 0) - { - return inputShapeTransferModule; - } - // If the input shape of the fourth module is 0. - else - return 0; - } - } + return inputShapeTransferModule; } + // If the input shape of the fourth module is 0. + else + return 0; + } } } + } + } } } From f9f4c86aa30b37471d9a2ded3c39eac087d8241a Mon Sep 17 00:00:00 2001 From: NippunSharma Date: Sun, 6 Dec 2020 19:24:35 +0530 Subject: [PATCH 27/51] fixing errors again --- src/mlpack/methods/ann/layer/recurrent_impl.hpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/mlpack/methods/ann/layer/recurrent_impl.hpp b/src/mlpack/methods/ann/layer/recurrent_impl.hpp index 0276318b0f..fae8c21672 100644 --- a/src/mlpack/methods/ann/layer/recurrent_impl.hpp +++ b/src/mlpack/methods/ann/layer/recurrent_impl.hpp @@ -135,7 +135,8 @@ size_t Recurrent::InputShape() c if (inputShapeStartModule != 0) { return inputShapeStartModule; - // If input shape of first module is 0 + } + // If input shape of first module is 0 else { // Return input shape of the second module that we have. @@ -143,7 +144,8 @@ size_t Recurrent::InputShape() c if (inputShapeInputModule != 0) { return inputShapeInputModule; - // If the input shape of second module is 0 + // If the input shape of second module is 0 + } else { // Return input shape of the third module that we have. @@ -152,7 +154,8 @@ size_t Recurrent::InputShape() c if (inputShapeFeedbackModule != 0) { return inputShapeFeedbackModule; - // If the input shape of the third module is 0 + // If the input shape of the third module is 0 + } else { // Return the shape of the fourth module that we have. @@ -166,10 +169,7 @@ size_t Recurrent::InputShape() c else return 0; } - } } - } - } } } From 11410db316d2ba66178f20e2e5fd16409b6b8d0e Mon Sep 17 00:00:00 2001 From: Nippun Sharma <53967069+NippunSharma@users.noreply.github.com> Date: Wed, 9 Dec 2020 15:47:58 +0530 Subject: [PATCH 28/51] Update src/mlpack/methods/ann/layer/recurrent_impl.hpp Co-authored-by: Marcus Edel --- src/mlpack/methods/ann/layer/recurrent_impl.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mlpack/methods/ann/layer/recurrent_impl.hpp b/src/mlpack/methods/ann/layer/recurrent_impl.hpp index fae8c21672..905ead9764 100644 --- a/src/mlpack/methods/ann/layer/recurrent_impl.hpp +++ b/src/mlpack/methods/ann/layer/recurrent_impl.hpp @@ -136,7 +136,7 @@ size_t Recurrent::InputShape() c { return inputShapeStartModule; } - // If input shape of first module is 0 + // If input shape of first module is 0. else { // Return input shape of the second module that we have. From cfa26a6b20220d9b616bddf89866384a0c7571a3 Mon Sep 17 00:00:00 2001 From: NippunSharma Date: Wed, 9 Dec 2020 15:52:39 +0530 Subject: [PATCH 29/51] added stops --- src/mlpack/methods/ann/layer/recurrent_impl.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mlpack/methods/ann/layer/recurrent_impl.hpp b/src/mlpack/methods/ann/layer/recurrent_impl.hpp index 905ead9764..e6b933bd20 100644 --- a/src/mlpack/methods/ann/layer/recurrent_impl.hpp +++ b/src/mlpack/methods/ann/layer/recurrent_impl.hpp @@ -144,7 +144,7 @@ size_t Recurrent::InputShape() c if (inputShapeInputModule != 0) { return inputShapeInputModule; - // If the input shape of second module is 0 + // If the input shape of second module is 0. } else { @@ -154,7 +154,7 @@ size_t Recurrent::InputShape() c if (inputShapeFeedbackModule != 0) { return inputShapeFeedbackModule; - // If the input shape of the third module is 0 + // If the input shape of the third module is 0. } else { From 86c4105841477db899ef6192501b54eb5aa1eb2f Mon Sep 17 00:00:00 2001 From: NippunSharma Date: Fri, 11 Dec 2020 10:47:44 +0530 Subject: [PATCH 30/51] added test for FFN --- src/mlpack/tests/feedforward_network_test.cpp | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/mlpack/tests/feedforward_network_test.cpp b/src/mlpack/tests/feedforward_network_test.cpp index f7c0b99ea9..00a91f0e9c 100644 --- a/src/mlpack/tests/feedforward_network_test.cpp +++ b/src/mlpack/tests/feedforward_network_test.cpp @@ -908,3 +908,41 @@ TEST_CASE("OptimizerTest", "[FeedForwardNetworkTest]") ens::DE opt(200, 1000, 0.6, 0.8, 1e-5); model.Train(trainData, trainLabels, opt); } + +/** + * Test to see if an exception is thrown when input with + * wrong shape is provided to a FFN. + */ +TEST_CASE("CheckInputShapeTest", "[FeedForwardNetworkTest]") +{ + // Load the dataset. + arma::mat trainData; + data::Load("thyroid_train.csv", trainData, true); + + arma::mat trainLabels = trainData.row(trainData.n_rows - 1); + trainData.shed_row(trainData.n_rows - 1); + + arma::mat testData; + data::Load("thyroid_test.csv", testData, true); + + arma::mat testLabels = testData.row(testData.n_rows - 1); + testData.shed_row(testData.n_rows - 1); + + FFN, RandomInitialization, CustomLayer<> > model; + // Purposely putting wrong input shape so that error is thrown + model.Add >(trainData.n_rows - 3, 8); + model.Add >(); + model.Add >(8, 3); + model.Add >(); + + std::string expectedMsg = "FFN<>::Train: "; + expectedMsg += "the first layer of the network expects "; + expectedMsg += std::to_string(trainData.n_rows - 3) + " elements, "; + expectedMsg += "but the input shape has " + std::to_string(trainData.n_rows) + " dimensions! "; + + ens::DE opt(200, 1000, 0.6, 0.8, 1e-5); + + REQUIRE_THROWS_MATCHES(model.Train(trainData, trainLabels, opt), + std::logic_error, + expectedMsg); +} From 818011bcf4d75a760a14254067d68680d3a6108f Mon Sep 17 00:00:00 2001 From: NippunSharma Date: Fri, 11 Dec 2020 11:55:46 +0530 Subject: [PATCH 31/51] added tests for RNN --- src/mlpack/tests/feedforward_network_test.cpp | 2 +- src/mlpack/tests/recurrent_network_test.cpp | 65 +++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/src/mlpack/tests/feedforward_network_test.cpp b/src/mlpack/tests/feedforward_network_test.cpp index 00a91f0e9c..9398c75240 100644 --- a/src/mlpack/tests/feedforward_network_test.cpp +++ b/src/mlpack/tests/feedforward_network_test.cpp @@ -944,5 +944,5 @@ TEST_CASE("CheckInputShapeTest", "[FeedForwardNetworkTest]") REQUIRE_THROWS_MATCHES(model.Train(trainData, trainLabels, opt), std::logic_error, - expectedMsg); + Message(expectedMsg)); } diff --git a/src/mlpack/tests/recurrent_network_test.cpp b/src/mlpack/tests/recurrent_network_test.cpp index 987c808ef2..0d69bcf40f 100644 --- a/src/mlpack/tests/recurrent_network_test.cpp +++ b/src/mlpack/tests/recurrent_network_test.cpp @@ -868,3 +868,68 @@ TEST_CASE("LargeRhoValueRnnTest", "[RecurrentNetworkTest]") model.Train(inputs[0], targets[0], opt); INFO("Training over"); } + +/** + * Test to make sure that an error is thrown when input with + * wrong input shape is provided to a RNN. + */ +TEST_CASE("CheckInputShapeTest", "[RecurrentNetworkTest]") +{ + const size_t rho = 10; + + // Generate 12 (2 * 6) noisy sines. A single sine contains rho + // points/features. + arma::cube input; + arma::mat labelsTemp; + GenerateNoisySines(input, labelsTemp, rho, 6); + + arma::cube labels = arma::zeros(1, labelsTemp.n_cols, rho); + for (size_t i = 0; i < labelsTemp.n_cols; ++i) + { + const int value = arma::as_scalar(arma::find( + arma::max(labelsTemp.col(i)) == labelsTemp.col(i), 1)) + 1; + labels.tube(0, i).fill(value); + } + + /** + * Construct a network with 1 input unit, 4 hidden units and 10 output + * units. The hidden layer is connected to itself. The network structure + * looks like: + * + * Input Hidden Output + * Layer(1) Layer(4) Layer(10) + * +-----+ +-----+ +-----+ + * | | | | | | + * | +------>| +------>| | + * | | ..>| | | | + * +-----+ . +--+--+ +-----+ + * . . + * . . + * ....... + */ + Add<> add(4); + // Purposely providing wrong input shape of 3. + // The correct input shape is 1. + Linear<> lookup(3, 4); + SigmoidLayer<> sigmoidLayer; + Linear<> linear(4, 4); + Recurrent<>* recurrent = new Recurrent<>(add, lookup, linear, + sigmoidLayer, rho); + + RNN<> model(rho); + model.Add >(); + model.Add(recurrent); + model.Add >(4, 10); + model.Add >(); + + std::string expectedMsg = "RNN<>::Train: "; + expectedMsg += "the first layer of the network expects "; + expectedMsg += std::to_string(3) + " elements, "; + expectedMsg += "but the input shape has " + std::to_string(1) + " dimensions! " + + StandardSGD opt(0.1, 1, input.n_cols /* 1 epoch */, -100); + + REQUIRE_THROWS_MATCHES(model.Train(input, labels, opt), + std::logic_error, + Message(expectedMsg)); +} From 0c256c8fbfb6e46d11db0806a0c63da802e279d0 Mon Sep 17 00:00:00 2001 From: NippunSharma Date: Fri, 11 Dec 2020 12:43:57 +0530 Subject: [PATCH 32/51] fixing errors --- src/mlpack/tests/feedforward_network_test.cpp | 2 +- src/mlpack/tests/recurrent_network_test.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mlpack/tests/feedforward_network_test.cpp b/src/mlpack/tests/feedforward_network_test.cpp index 9398c75240..abd392c720 100644 --- a/src/mlpack/tests/feedforward_network_test.cpp +++ b/src/mlpack/tests/feedforward_network_test.cpp @@ -944,5 +944,5 @@ TEST_CASE("CheckInputShapeTest", "[FeedForwardNetworkTest]") REQUIRE_THROWS_MATCHES(model.Train(trainData, trainLabels, opt), std::logic_error, - Message(expectedMsg)); + Catch::Matchers::Message(expectedMsg)); } diff --git a/src/mlpack/tests/recurrent_network_test.cpp b/src/mlpack/tests/recurrent_network_test.cpp index 0d69bcf40f..6b3c1730a3 100644 --- a/src/mlpack/tests/recurrent_network_test.cpp +++ b/src/mlpack/tests/recurrent_network_test.cpp @@ -931,5 +931,5 @@ TEST_CASE("CheckInputShapeTest", "[RecurrentNetworkTest]") REQUIRE_THROWS_MATCHES(model.Train(input, labels, opt), std::logic_error, - Message(expectedMsg)); + Catch::Matchers::Message(expectedMsg)); } From 5c58eb01f012cedc689bb6d66dd2ec9c0a8850a6 Mon Sep 17 00:00:00 2001 From: NippunSharma Date: Fri, 11 Dec 2020 13:21:50 +0530 Subject: [PATCH 33/51] added ; --- src/mlpack/tests/recurrent_network_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mlpack/tests/recurrent_network_test.cpp b/src/mlpack/tests/recurrent_network_test.cpp index 6b3c1730a3..9318154b89 100644 --- a/src/mlpack/tests/recurrent_network_test.cpp +++ b/src/mlpack/tests/recurrent_network_test.cpp @@ -925,7 +925,7 @@ TEST_CASE("CheckInputShapeTest", "[RecurrentNetworkTest]") std::string expectedMsg = "RNN<>::Train: "; expectedMsg += "the first layer of the network expects "; expectedMsg += std::to_string(3) + " elements, "; - expectedMsg += "but the input shape has " + std::to_string(1) + " dimensions! " + expectedMsg += "but the input shape has " + std::to_string(1) + " dimensions! "; StandardSGD opt(0.1, 1, input.n_cols /* 1 epoch */, -100); From d0aa3de850a58f8bc76dde91dfa6e9a28cc2e011 Mon Sep 17 00:00:00 2001 From: NippunSharma Date: Fri, 11 Dec 2020 14:11:15 +0530 Subject: [PATCH 34/51] changed names of tests --- src/mlpack/tests/feedforward_network_test.cpp | 2 +- src/mlpack/tests/recurrent_network_test.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mlpack/tests/feedforward_network_test.cpp b/src/mlpack/tests/feedforward_network_test.cpp index abd392c720..ee501871dc 100644 --- a/src/mlpack/tests/feedforward_network_test.cpp +++ b/src/mlpack/tests/feedforward_network_test.cpp @@ -913,7 +913,7 @@ TEST_CASE("OptimizerTest", "[FeedForwardNetworkTest]") * Test to see if an exception is thrown when input with * wrong shape is provided to a FFN. */ -TEST_CASE("CheckInputShapeTest", "[FeedForwardNetworkTest]") +TEST_CASE("FFNCheckInputShapeTest", "[FeedForwardNetworkTest]") { // Load the dataset. arma::mat trainData; diff --git a/src/mlpack/tests/recurrent_network_test.cpp b/src/mlpack/tests/recurrent_network_test.cpp index 9318154b89..d02f5a18e4 100644 --- a/src/mlpack/tests/recurrent_network_test.cpp +++ b/src/mlpack/tests/recurrent_network_test.cpp @@ -873,7 +873,7 @@ TEST_CASE("LargeRhoValueRnnTest", "[RecurrentNetworkTest]") * Test to make sure that an error is thrown when input with * wrong input shape is provided to a RNN. */ -TEST_CASE("CheckInputShapeTest", "[RecurrentNetworkTest]") +TEST_CASE("RNNCheckInputShapeTest", "[RecurrentNetworkTest]") { const size_t rho = 10; From 684dd5e513d8183fdb89e9f7be063b1746b6a5d6 Mon Sep 17 00:00:00 2001 From: NippunSharma Date: Fri, 11 Dec 2020 15:55:47 +0530 Subject: [PATCH 35/51] fixes --- src/mlpack/tests/feedforward_network_test.cpp | 2 +- src/mlpack/tests/recurrent_network_test.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mlpack/tests/feedforward_network_test.cpp b/src/mlpack/tests/feedforward_network_test.cpp index ee501871dc..17cf23eab4 100644 --- a/src/mlpack/tests/feedforward_network_test.cpp +++ b/src/mlpack/tests/feedforward_network_test.cpp @@ -938,7 +938,7 @@ TEST_CASE("FFNCheckInputShapeTest", "[FeedForwardNetworkTest]") std::string expectedMsg = "FFN<>::Train: "; expectedMsg += "the first layer of the network expects "; expectedMsg += std::to_string(trainData.n_rows - 3) + " elements, "; - expectedMsg += "but the input shape has " + std::to_string(trainData.n_rows) + " dimensions! "; + expectedMsg += "but the input has " + std::to_string(trainData.n_rows) + " dimensions! "; ens::DE opt(200, 1000, 0.6, 0.8, 1e-5); diff --git a/src/mlpack/tests/recurrent_network_test.cpp b/src/mlpack/tests/recurrent_network_test.cpp index d02f5a18e4..07150f9433 100644 --- a/src/mlpack/tests/recurrent_network_test.cpp +++ b/src/mlpack/tests/recurrent_network_test.cpp @@ -925,7 +925,7 @@ TEST_CASE("RNNCheckInputShapeTest", "[RecurrentNetworkTest]") std::string expectedMsg = "RNN<>::Train: "; expectedMsg += "the first layer of the network expects "; expectedMsg += std::to_string(3) + " elements, "; - expectedMsg += "but the input shape has " + std::to_string(1) + " dimensions! "; + expectedMsg += "but the input has " + std::to_string(1) + " dimensions! "; StandardSGD opt(0.1, 1, input.n_cols /* 1 epoch */, -100); From db9550507e36b77b3e614c2de5c201510a1c3217 Mon Sep 17 00:00:00 2001 From: NippunSharma Date: Fri, 11 Dec 2020 17:46:06 +0530 Subject: [PATCH 36/51] fixing again --- src/mlpack/tests/feedforward_network_test.cpp | 2 +- src/mlpack/tests/recurrent_network_test.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mlpack/tests/feedforward_network_test.cpp b/src/mlpack/tests/feedforward_network_test.cpp index 17cf23eab4..81a87ccc6d 100644 --- a/src/mlpack/tests/feedforward_network_test.cpp +++ b/src/mlpack/tests/feedforward_network_test.cpp @@ -935,7 +935,7 @@ TEST_CASE("FFNCheckInputShapeTest", "[FeedForwardNetworkTest]") model.Add >(8, 3); model.Add >(); - std::string expectedMsg = "FFN<>::Train: "; + std::string expectedMsg = "FFN<>::Train(): "; expectedMsg += "the first layer of the network expects "; expectedMsg += std::to_string(trainData.n_rows - 3) + " elements, "; expectedMsg += "but the input has " + std::to_string(trainData.n_rows) + " dimensions! "; diff --git a/src/mlpack/tests/recurrent_network_test.cpp b/src/mlpack/tests/recurrent_network_test.cpp index 07150f9433..b78523b150 100644 --- a/src/mlpack/tests/recurrent_network_test.cpp +++ b/src/mlpack/tests/recurrent_network_test.cpp @@ -922,7 +922,7 @@ TEST_CASE("RNNCheckInputShapeTest", "[RecurrentNetworkTest]") model.Add >(4, 10); model.Add >(); - std::string expectedMsg = "RNN<>::Train: "; + std::string expectedMsg = "RNN<>::Train(): "; expectedMsg += "the first layer of the network expects "; expectedMsg += std::to_string(3) + " elements, "; expectedMsg += "but the input has " + std::to_string(1) + " dimensions! "; From 1168acb0e413cde2317efeb2766c37eb169fc462 Mon Sep 17 00:00:00 2001 From: Nippun Sharma <53967069+NippunSharma@users.noreply.github.com> Date: Sat, 12 Dec 2020 00:11:56 +0530 Subject: [PATCH 37/51] Update src/mlpack/tests/feedforward_network_test.cpp Co-authored-by: Marcus Edel --- src/mlpack/tests/feedforward_network_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mlpack/tests/feedforward_network_test.cpp b/src/mlpack/tests/feedforward_network_test.cpp index 81a87ccc6d..bef5dbe7af 100644 --- a/src/mlpack/tests/feedforward_network_test.cpp +++ b/src/mlpack/tests/feedforward_network_test.cpp @@ -929,7 +929,7 @@ TEST_CASE("FFNCheckInputShapeTest", "[FeedForwardNetworkTest]") testData.shed_row(testData.n_rows - 1); FFN, RandomInitialization, CustomLayer<> > model; - // Purposely putting wrong input shape so that error is thrown + // Purposely putting wrong input shape so that error is thrown. model.Add >(trainData.n_rows - 3, 8); model.Add >(); model.Add >(8, 3); From 588a9be14bee12834a828a03b6f97f1a1d1455a1 Mon Sep 17 00:00:00 2001 From: NippunSharma Date: Sat, 12 Dec 2020 00:18:46 +0530 Subject: [PATCH 38/51] style fixes --- src/mlpack/tests/feedforward_network_test.cpp | 9 ++++----- src/mlpack/tests/recurrent_network_test.cpp | 3 +-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/mlpack/tests/feedforward_network_test.cpp b/src/mlpack/tests/feedforward_network_test.cpp index 81a87ccc6d..cab3f03891 100644 --- a/src/mlpack/tests/feedforward_network_test.cpp +++ b/src/mlpack/tests/feedforward_network_test.cpp @@ -936,13 +936,12 @@ TEST_CASE("FFNCheckInputShapeTest", "[FeedForwardNetworkTest]") model.Add >(); std::string expectedMsg = "FFN<>::Train(): "; - expectedMsg += "the first layer of the network expects "; - expectedMsg += std::to_string(trainData.n_rows - 3) + " elements, "; - expectedMsg += "but the input has " + std::to_string(trainData.n_rows) + " dimensions! "; + expectedMsg += "the first layer of the network expects "; + expectedMsg += std::to_string(trainData.n_rows - 3) + " elements, "; + expectedMsg += "but the input has " + std::to_string(trainData.n_rows) + " dimensions! "; ens::DE opt(200, 1000, 0.6, 0.8, 1e-5); REQUIRE_THROWS_MATCHES(model.Train(trainData, trainLabels, opt), - std::logic_error, - Catch::Matchers::Message(expectedMsg)); + std::logic_error, Catch::Matchers::Message(expectedMsg)); } diff --git a/src/mlpack/tests/recurrent_network_test.cpp b/src/mlpack/tests/recurrent_network_test.cpp index b78523b150..d0912802d0 100644 --- a/src/mlpack/tests/recurrent_network_test.cpp +++ b/src/mlpack/tests/recurrent_network_test.cpp @@ -930,6 +930,5 @@ TEST_CASE("RNNCheckInputShapeTest", "[RecurrentNetworkTest]") StandardSGD opt(0.1, 1, input.n_cols /* 1 epoch */, -100); REQUIRE_THROWS_MATCHES(model.Train(input, labels, opt), - std::logic_error, - Catch::Matchers::Message(expectedMsg)); + std::logic_error, Catch::Matchers::Message(expectedMsg)); } From da78659ff3c414cea867c03fc3b8e4a3cc37a2aa Mon Sep 17 00:00:00 2001 From: Nippun Sharma <53967069+NippunSharma@users.noreply.github.com> Date: Sat, 12 Dec 2020 00:22:38 +0530 Subject: [PATCH 39/51] style fixes 2 --- src/mlpack/tests/feedforward_network_test.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mlpack/tests/feedforward_network_test.cpp b/src/mlpack/tests/feedforward_network_test.cpp index e512fe3f7c..45530ea466 100644 --- a/src/mlpack/tests/feedforward_network_test.cpp +++ b/src/mlpack/tests/feedforward_network_test.cpp @@ -936,9 +936,9 @@ TEST_CASE("FFNCheckInputShapeTest", "[FeedForwardNetworkTest]") model.Add >(); std::string expectedMsg = "FFN<>::Train(): "; - expectedMsg += "the first layer of the network expects "; - expectedMsg += std::to_string(trainData.n_rows - 3) + " elements, "; - expectedMsg += "but the input has " + std::to_string(trainData.n_rows) + " dimensions! "; + expectedMsg += "the first layer of the network expects "; + expectedMsg += std::to_string(trainData.n_rows - 3) + " elements, "; + expectedMsg += "but the input has " + std::to_string(trainData.n_rows) + " dimensions! "; ens::DE opt(200, 1000, 0.6, 0.8, 1e-5); From 41e52f58b20cfebc569190bc6184892f114d9f7d Mon Sep 17 00:00:00 2001 From: NippunSharma Date: Sun, 13 Dec 2020 13:53:59 +0530 Subject: [PATCH 40/51] added co-author's name for PR #2122 --- src/mlpack/methods/ann/util/check_input_shape.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mlpack/methods/ann/util/check_input_shape.hpp b/src/mlpack/methods/ann/util/check_input_shape.hpp index b2b7b7e67e..87ec25bb67 100644 --- a/src/mlpack/methods/ann/util/check_input_shape.hpp +++ b/src/mlpack/methods/ann/util/check_input_shape.hpp @@ -1,5 +1,6 @@ /** * @file check_input_shape.hpp + * @author Khizir Siddiqui * @author Nippun Sharma * * Definition of the CheckInputShape() function that checks From a66dcc7c8aca95bc99997c4bcff769dae44c47ac Mon Sep 17 00:00:00 2001 From: NippunSharma Date: Sun, 13 Dec 2020 13:55:23 +0530 Subject: [PATCH 41/51] added co-author's name for PR #2122 --- src/mlpack/methods/ann/visitor/input_shape_visitor.hpp | 1 + src/mlpack/methods/ann/visitor/input_shape_visitor_impl.hpp | 1 + 2 files changed, 2 insertions(+) diff --git a/src/mlpack/methods/ann/visitor/input_shape_visitor.hpp b/src/mlpack/methods/ann/visitor/input_shape_visitor.hpp index bb1b4b392a..92d2c5d553 100644 --- a/src/mlpack/methods/ann/visitor/input_shape_visitor.hpp +++ b/src/mlpack/methods/ann/visitor/input_shape_visitor.hpp @@ -1,5 +1,6 @@ /** * @file input_shape_visitor.hpp + * @author Khizir Siddiqui * @author Nippun Sharma * * This file provides an abstraction for the InputShape() function for diff --git a/src/mlpack/methods/ann/visitor/input_shape_visitor_impl.hpp b/src/mlpack/methods/ann/visitor/input_shape_visitor_impl.hpp index 2b87081927..5ceef063d0 100644 --- a/src/mlpack/methods/ann/visitor/input_shape_visitor_impl.hpp +++ b/src/mlpack/methods/ann/visitor/input_shape_visitor_impl.hpp @@ -1,5 +1,6 @@ /** * @file input_shape_visitor_impl.hpp + * @author Khizir Siddiqui * @author Nippun Sharma * * Implementation of the InputShape() function layer abstraction. From ad4057179c7e953c0a065f8a3fb6ebd6ac683d44 Mon Sep 17 00:00:00 2001 From: Nippun Sharma <53967069+NippunSharma@users.noreply.github.com> Date: Wed, 16 Dec 2020 00:01:27 +0530 Subject: [PATCH 42/51] Update src/mlpack/methods/ann/util/check_input_shape.hpp Co-authored-by: Marcus Edel --- src/mlpack/methods/ann/util/check_input_shape.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mlpack/methods/ann/util/check_input_shape.hpp b/src/mlpack/methods/ann/util/check_input_shape.hpp index 87ec25bb67..44c6d39b11 100644 --- a/src/mlpack/methods/ann/util/check_input_shape.hpp +++ b/src/mlpack/methods/ann/util/check_input_shape.hpp @@ -1,5 +1,5 @@ /** - * @file check_input_shape.hpp + * @file methods/ann/util/check_input_shape.hpp * @author Khizir Siddiqui * @author Nippun Sharma * @@ -50,4 +50,4 @@ void CheckInputShape(const T& network, const size_t inputShape, } // namespace ann } // namespace mlpack -#endif \ No newline at end of file +#endif From f6f3b626250a16b54d470f75392483a9369f82f8 Mon Sep 17 00:00:00 2001 From: Nippun Sharma <53967069+NippunSharma@users.noreply.github.com> Date: Wed, 16 Dec 2020 00:01:41 +0530 Subject: [PATCH 43/51] Update src/mlpack/methods/ann/visitor/input_shape_visitor.hpp Co-authored-by: Marcus Edel --- src/mlpack/methods/ann/visitor/input_shape_visitor.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mlpack/methods/ann/visitor/input_shape_visitor.hpp b/src/mlpack/methods/ann/visitor/input_shape_visitor.hpp index 92d2c5d553..c27135aae3 100644 --- a/src/mlpack/methods/ann/visitor/input_shape_visitor.hpp +++ b/src/mlpack/methods/ann/visitor/input_shape_visitor.hpp @@ -1,5 +1,5 @@ /** - * @file input_shape_visitor.hpp + * @file methods/ann/visitor/input_shape_visitor.hpp * @author Khizir Siddiqui * @author Nippun Sharma * From 8c56b4f1edd7fd9a413307afa9e3b123aa881e2d Mon Sep 17 00:00:00 2001 From: Nippun Sharma <53967069+NippunSharma@users.noreply.github.com> Date: Wed, 16 Dec 2020 00:01:54 +0530 Subject: [PATCH 44/51] Update src/mlpack/methods/ann/visitor/input_shape_visitor_impl.hpp Co-authored-by: Marcus Edel --- src/mlpack/methods/ann/visitor/input_shape_visitor_impl.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mlpack/methods/ann/visitor/input_shape_visitor_impl.hpp b/src/mlpack/methods/ann/visitor/input_shape_visitor_impl.hpp index 5ceef063d0..bda5f7b604 100644 --- a/src/mlpack/methods/ann/visitor/input_shape_visitor_impl.hpp +++ b/src/mlpack/methods/ann/visitor/input_shape_visitor_impl.hpp @@ -1,5 +1,5 @@ /** - * @file input_shape_visitor_impl.hpp + * @file methods/ann/visitor/input_shape_visitor_impl.hpp * @author Khizir Siddiqui * @author Nippun Sharma * From 6a0bf85cbadd15ecf348cbdfecc851b055539462 Mon Sep 17 00:00:00 2001 From: Nippun Sharma <53967069+NippunSharma@users.noreply.github.com> Date: Thu, 17 Dec 2020 10:50:04 +0530 Subject: [PATCH 45/51] Update src/mlpack/methods/ann/util/check_input_shape.hpp Co-authored-by: Ryan Curtin --- src/mlpack/methods/ann/util/check_input_shape.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mlpack/methods/ann/util/check_input_shape.hpp b/src/mlpack/methods/ann/util/check_input_shape.hpp index 44c6d39b11..653c21276a 100644 --- a/src/mlpack/methods/ann/util/check_input_shape.hpp +++ b/src/mlpack/methods/ann/util/check_input_shape.hpp @@ -25,7 +25,7 @@ template void CheckInputShape(const T& network, const size_t inputShape, const std::string& functionName) { - for (size_t l=0; l Date: Thu, 17 Dec 2020 10:51:05 +0530 Subject: [PATCH 46/51] Update src/mlpack/methods/ann/util/check_input_shape.hpp Co-authored-by: Ryan Curtin --- src/mlpack/methods/ann/util/check_input_shape.hpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/mlpack/methods/ann/util/check_input_shape.hpp b/src/mlpack/methods/ann/util/check_input_shape.hpp index 653c21276a..566c363e3f 100644 --- a/src/mlpack/methods/ann/util/check_input_shape.hpp +++ b/src/mlpack/methods/ann/util/check_input_shape.hpp @@ -38,10 +38,9 @@ void CheckInputShape(const T& network, const size_t inputShape, } else { - std::string estr = functionName + ": "; - estr += "the first layer of the network expects "; - estr += std::to_string(layerInShape) + " elements, "; - estr += "but the input has " + std::to_string(inputShape) + " dimensions! "; + std::string estr = functionName + ": the first layer of the network " + + "expects " + std::to_string(layerInShape) + " elements, but the " + + "input has " + std::to_string(inputShape) + " dimensions!"; throw std::logic_error(estr); } } From f61da066ed769ed3f218236f9cf7feee1603df2c Mon Sep 17 00:00:00 2001 From: NippunSharma Date: Thu, 17 Dec 2020 11:00:56 +0530 Subject: [PATCH 47/51] reverting back to REQUIRE_THROWS_AS --- src/mlpack/tests/feedforward_network_test.cpp | 3 +-- src/mlpack/tests/recurrent_network_test.cpp | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/mlpack/tests/feedforward_network_test.cpp b/src/mlpack/tests/feedforward_network_test.cpp index 45530ea466..8216f2e623 100644 --- a/src/mlpack/tests/feedforward_network_test.cpp +++ b/src/mlpack/tests/feedforward_network_test.cpp @@ -942,6 +942,5 @@ TEST_CASE("FFNCheckInputShapeTest", "[FeedForwardNetworkTest]") ens::DE opt(200, 1000, 0.6, 0.8, 1e-5); - REQUIRE_THROWS_MATCHES(model.Train(trainData, trainLabels, opt), - std::logic_error, Catch::Matchers::Message(expectedMsg)); + REQUIRE_THROWS_AS(model.Train(trainData, trainLabels, opt), std::logic_error); } diff --git a/src/mlpack/tests/recurrent_network_test.cpp b/src/mlpack/tests/recurrent_network_test.cpp index d0912802d0..c9159daeff 100644 --- a/src/mlpack/tests/recurrent_network_test.cpp +++ b/src/mlpack/tests/recurrent_network_test.cpp @@ -929,6 +929,5 @@ TEST_CASE("RNNCheckInputShapeTest", "[RecurrentNetworkTest]") StandardSGD opt(0.1, 1, input.n_cols /* 1 epoch */, -100); - REQUIRE_THROWS_MATCHES(model.Train(input, labels, opt), - std::logic_error, Catch::Matchers::Message(expectedMsg)); + REQUIRE_THROWS_AS(model.Train(input, labels, opt), std::logic_error); } From ceb6f7ebed602e14e93851dd54dad41c626aa494 Mon Sep 17 00:00:00 2001 From: NippunSharma Date: Thu, 17 Dec 2020 11:03:33 +0530 Subject: [PATCH 48/51] fixing bilinear_interpolation.hpp --- src/mlpack/methods/ann/layer/bilinear_interpolation.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mlpack/methods/ann/layer/bilinear_interpolation.hpp b/src/mlpack/methods/ann/layer/bilinear_interpolation.hpp index 2d611feb19..8595bc4d57 100644 --- a/src/mlpack/methods/ann/layer/bilinear_interpolation.hpp +++ b/src/mlpack/methods/ann/layer/bilinear_interpolation.hpp @@ -119,9 +119,9 @@ class BilinearInterpolation size_t& InDepth() { return depth; } //! Get the shape of the input. - size_t WeightSize() const + size_t InputShape() const { - return InRowSize; + return inRowSize; } /** From 01db8c739b48baf0ed360f663392c8c4fa65c538 Mon Sep 17 00:00:00 2001 From: NippunSharma Date: Thu, 17 Dec 2020 13:28:48 +0530 Subject: [PATCH 49/51] added InputShape() to multihead_attention, positional_encoding, reparametrization, sequential --- .../methods/ann/layer/multihead_attention.hpp | 5 +++++ .../methods/ann/layer/positional_encoding.hpp | 5 +++++ .../methods/ann/layer/reparametrization.hpp | 5 +++++ src/mlpack/methods/ann/layer/sequential.hpp | 3 +++ .../methods/ann/layer/sequential_impl.hpp | 20 +++++++++++++++++++ 5 files changed, 38 insertions(+) diff --git a/src/mlpack/methods/ann/layer/multihead_attention.hpp b/src/mlpack/methods/ann/layer/multihead_attention.hpp index 3421fa4183..ec079d197d 100644 --- a/src/mlpack/methods/ann/layer/multihead_attention.hpp +++ b/src/mlpack/methods/ann/layer/multihead_attention.hpp @@ -176,6 +176,11 @@ class MultiheadAttention //! Modify the parameters. OutputDataType& Parameters() { return weights; } + size_t InputShape() const + { + return embedDim * (tgtSeqLen + 2 * srcSeqLen); + } + private: //! Element Type of the input. typedef typename OutputDataType::elem_type ElemType; diff --git a/src/mlpack/methods/ann/layer/positional_encoding.hpp b/src/mlpack/methods/ann/layer/positional_encoding.hpp index 1e6cb445a0..8678426414 100644 --- a/src/mlpack/methods/ann/layer/positional_encoding.hpp +++ b/src/mlpack/methods/ann/layer/positional_encoding.hpp @@ -93,6 +93,11 @@ class PositionalEncoding //! Get the positional encoding vector. InputDataType const& Encoding() const { return positionalEncoding; } + size_t InputShape() const + { + return embedDim * maxSequenceLength; + } + /** * Serialize the layer */ diff --git a/src/mlpack/methods/ann/layer/reparametrization.hpp b/src/mlpack/methods/ann/layer/reparametrization.hpp index f6e6fe3b7f..65aa96da53 100644 --- a/src/mlpack/methods/ann/layer/reparametrization.hpp +++ b/src/mlpack/methods/ann/layer/reparametrization.hpp @@ -130,6 +130,11 @@ class Reparametrization //! Get the value of the beta hyperparameter. double Beta() const { return beta; } + size_t InputShape() const + { + return 2 * latentSize; + } + /** * Serialize the layer */ diff --git a/src/mlpack/methods/ann/layer/sequential.hpp b/src/mlpack/methods/ann/layer/sequential.hpp index f4466161a0..ebf3c6fd6a 100644 --- a/src/mlpack/methods/ann/layer/sequential.hpp +++ b/src/mlpack/methods/ann/layer/sequential.hpp @@ -23,6 +23,7 @@ #include "../visitor/output_height_visitor.hpp" #include "../visitor/output_parameter_visitor.hpp" #include "../visitor/output_width_visitor.hpp" +#include "../visitor/input_shape_visitor.hpp" #include "layer_types.hpp" #include "add_merge.hpp" @@ -184,6 +185,8 @@ class Sequential //! Modify the gradient. arma::mat& Gradient() { return gradient; } + size_t InputShape() const; + /** * Serialize the layer */ diff --git a/src/mlpack/methods/ann/layer/sequential_impl.hpp b/src/mlpack/methods/ann/layer/sequential_impl.hpp index 5e9c4cd6f6..26669b3b5e 100644 --- a/src/mlpack/methods/ann/layer/sequential_impl.hpp +++ b/src/mlpack/methods/ann/layer/sequential_impl.hpp @@ -21,6 +21,7 @@ #include "../visitor/gradient_visitor.hpp" #include "../visitor/set_input_height_visitor.hpp" #include "../visitor/set_input_width_visitor.hpp" +#include "../visitor/input_shape_visitor.hpp" namespace mlpack { namespace ann /** Artificial Neural Network. */ { @@ -94,6 +95,25 @@ Sequential< } } +template +template +size_t Sequential(InputDataType, OutputDataType, Residual, CustomLayers...):: +InputShape() const +{ + size_t inputShape = 0; + + for (size_t l = 0; l < network.size(); ++l) + { + if (inputShape == 0) + inputShape = boost::apply_visitor(InShapeVisitor(), network[l]); + else + break; + } + + return inputShape; +} + template template From f2594e52b331e8a523fceb0506af44619ee47702 Mon Sep 17 00:00:00 2001 From: Nippun Sharma <53967069+NippunSharma@users.noreply.github.com> Date: Thu, 17 Dec 2020 14:03:58 +0530 Subject: [PATCH 50/51] changed () to <> in sequential --- src/mlpack/methods/ann/layer/sequential_impl.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mlpack/methods/ann/layer/sequential_impl.hpp b/src/mlpack/methods/ann/layer/sequential_impl.hpp index 26669b3b5e..0a89f8be10 100644 --- a/src/mlpack/methods/ann/layer/sequential_impl.hpp +++ b/src/mlpack/methods/ann/layer/sequential_impl.hpp @@ -98,7 +98,7 @@ Sequential< template template -size_t Sequential(InputDataType, OutputDataType, Residual, CustomLayers...):: +size_t Sequential:: InputShape() const { size_t inputShape = 0; From 1d66eb40784133849abdd1b8b6b8542dae8a0342 Mon Sep 17 00:00:00 2001 From: NippunSharma Date: Thu, 17 Dec 2020 14:38:55 +0530 Subject: [PATCH 51/51] fixing errors --- src/mlpack/methods/ann/layer/sequential_impl.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/mlpack/methods/ann/layer/sequential_impl.hpp b/src/mlpack/methods/ann/layer/sequential_impl.hpp index 0a89f8be10..1290a15ebb 100644 --- a/src/mlpack/methods/ann/layer/sequential_impl.hpp +++ b/src/mlpack/methods/ann/layer/sequential_impl.hpp @@ -97,7 +97,6 @@ Sequential< template -template size_t Sequential:: InputShape() const {