From 10be43e689c0e9bcd2a6fe4b45c8e6777f0021fa Mon Sep 17 00:00:00 2001 From: Jihoon Lee Date: Thu, 7 Oct 2021 01:38:50 +0900 Subject: [PATCH] [Neuralnet] Add property of input layers, label layers This patch add property, input layers and label layers to neuralnet **Self evaluation:** 1. Build test: [X]Passed [ ]Failed [ ]Skipped 2. Run test: [X]Passed [ ]Failed [ ]Skipped Signed-off-by: Jihoon Lee --- nntrainer/layers/common_properties.cpp | 13 +++++++++---- nntrainer/layers/common_properties.h | 26 ++++++++++++++++++++++++++ nntrainer/layers/layer_node.cpp | 13 ------------- nntrainer/models/neuralnet.cpp | 2 +- nntrainer/models/neuralnet.h | 5 ++++- 5 files changed, 40 insertions(+), 19 deletions(-) diff --git a/nntrainer/layers/common_properties.cpp b/nntrainer/layers/common_properties.cpp index 7a7270a..eaf8140 100644 --- a/nntrainer/layers/common_properties.cpp +++ b/nntrainer/layers/common_properties.cpp @@ -76,8 +76,7 @@ bool NumClass::isValid(const unsigned int &v) const { return v > 0; } ConnectionSpec::ConnectionSpec(const std::vector &layer_ids_, const std::string &op_type_) : - op_type(op_type_), - layer_ids(layer_ids_) { + op_type(op_type_), layer_ids(layer_ids_) { NNTR_THROW_IF((op_type != ConnectionSpec::NoneType && layer_ids.size() < 2), std::invalid_argument) << "connection type is not none but has only a single or empty layer id, " @@ -94,8 +93,8 @@ ConnectionSpec::ConnectionSpec(const std::vector &layer_ids_, ConnectionSpec::ConnectionSpec(const ConnectionSpec &rhs) = default; ConnectionSpec &ConnectionSpec::operator=(const ConnectionSpec &rhs) = default; ConnectionSpec::ConnectionSpec(ConnectionSpec &&rhs) noexcept = default; -ConnectionSpec &ConnectionSpec:: -operator=(ConnectionSpec &&rhs) noexcept = default; +ConnectionSpec & +ConnectionSpec::operator=(ConnectionSpec &&rhs) noexcept = default; bool ConnectionSpec::operator==(const ConnectionSpec &rhs) const { return op_type == rhs.op_type && layer_ids == rhs.layer_ids; @@ -222,6 +221,12 @@ bool WeightRegularizerConstant::isValid(const float &value) const { return value >= 0.0f; } +InputLayer::InputLayer() : Name() {} +InputLayer::InputLayer(const std::string &name) : Name(name) {} + +LabelLayer::LabelLayer() : Name() {} +LabelLayer::LabelLayer(const std::string &name) : Name(name) {} + HiddenStateActivation::HiddenStateActivation(ActivationTypeInfo::Enum value) { set(value); }; diff --git a/nntrainer/layers/common_properties.h b/nntrainer/layers/common_properties.h index c038f63..b313908 100644 --- a/nntrainer/layers/common_properties.h +++ b/nntrainer/layers/common_properties.h @@ -581,6 +581,32 @@ public: bool isValid(const float &value) const override; }; +/** + * @brief Input Layer name property which saves a single connection + * (practically, std::vector is used) + * + */ +class InputLayer : public Name { +public: + InputLayer(); + InputLayer(const std::string &name); + static constexpr const char *key = "input_layers"; + using prop_tag = str_prop_tag; +}; + +/** + * @brief label Layer name property which saves a single + * connection (practically, std::vector is used) + * + */ +class LabelLayer : public Name { +public: + LabelLayer(); + LabelLayer(const std::string &name); + static constexpr const char *key = "label_layers"; + using prop_tag = str_prop_tag; +}; + /******** below section is for enumerations ***************/ /** * @brief Enumeration of activation function type diff --git a/nntrainer/layers/layer_node.cpp b/nntrainer/layers/layer_node.cpp index d862679..60013a1 100644 --- a/nntrainer/layers/layer_node.cpp +++ b/nntrainer/layers/layer_node.cpp @@ -54,19 +54,6 @@ public: }; /** - * @brief Input Layer name property which saves a single connection - * (practically, std::vector is used) - * - */ -class InputLayer : public Name { -public: - InputLayer() : Name(){}; - InputLayer(const std::string &name) : Name(name) {} - static constexpr const char *key = "input_layers"; - using prop_tag = str_prop_tag; -}; - -/** * @brief Loss property, this defines loss specification of layer * */ diff --git a/nntrainer/models/neuralnet.cpp b/nntrainer/models/neuralnet.cpp index 9810c16..33610e2 100644 --- a/nntrainer/models/neuralnet.cpp +++ b/nntrainer/models/neuralnet.cpp @@ -48,7 +48,7 @@ namespace nntrainer { NeuralNetwork::NeuralNetwork(AppContext app_context_, bool in_place_opt) : - model_props(props::LossType()), + model_props(props::LossType(), {}, {}), model_flex_props(props::Epochs(), props::TrainingBatchSize(), props::SavePath(), props::ContinueTrain(), props::SaveBestPath()), diff --git a/nntrainer/models/neuralnet.h b/nntrainer/models/neuralnet.h index 86fcb00..5555cdb 100644 --- a/nntrainer/models/neuralnet.h +++ b/nntrainer/models/neuralnet.h @@ -34,6 +34,7 @@ #endif #include +#include #include #include #include @@ -477,7 +478,9 @@ private: using FlexiblePropTypes = std::tuple; - using RigidPropTypes = std::tuple; + using RigidPropTypes = + std::tuple, + std::vector>; RigidPropTypes model_props; /**< model props */ FlexiblePropTypes model_flex_props; /**< model train props */ -- 2.7.4