* @author Jihoon Lee <jhoon.it.lee@samsung.com>
* @bug No known bugs except for NYI items
*/
+#include "connection.h"
#include <algorithm>
#include <compiler_fwd.h>
#include <memory>
namespace nntrainer {
PreviousInputRealizer::PreviousInputRealizer(
- const std::vector<std::string> &identified_inputs_) :
+ const std::vector<Connection> &identified_inputs_) :
identified_inputs(identified_inputs_) {}
PreviousInputRealizer::~PreviousInputRealizer() {}
*/
auto is_actually_an_input_node = [this](const LayerNode &node) {
return node.hasInputShapeProperty() or
- std::any_of(identified_inputs.begin(), identified_inputs.end(),
- [&node](auto &name) { return node.getName() == name; });
+ std::any_of(
+ identified_inputs.begin(), identified_inputs.end(),
+ [&node](auto &conn) { return node.getName() == conn.getName(); });
};
for (auto iter = processed.begin(); iter != processed.end(); ++iter) {
#include <memory>
#include <vector>
+#include <connection.h>
#include <realizer.h>
namespace nntrainer {
* @param identified_inputs node that is identified as an input, this must not
* connect to other nodes automatically
*/
- PreviousInputRealizer(const std::vector<std::string> &identified_inputs);
+ PreviousInputRealizer(const std::vector<Connection> &identified_inputs);
/**
* @brief Destroy the Graph Realizer object
GraphRepresentation realize(const GraphRepresentation &reference) override;
private:
- std::vector<std::string> identified_inputs; /**< inputs are identified */
+ std::vector<Connection> identified_inputs; /**< inputs are identified */
};
} // namespace nntrainer
#include <addition_layer.h>
#include <bn_layer.h>
#include <concat_layer.h>
+#include <connection.h>
#include <cross_entropy_loss_layer.h>
#include <cross_entropy_sigmoid_loss_layer.h>
#include <cross_entropy_softmax_loss_layer.h>
return outputs;
}
-int NetworkGraph::initialize(
- const std::vector<std::string> &model_input_names,
- const std::vector<std::string> &model_label_names) {
+int NetworkGraph::initialize(const std::vector<Connection> &model_input_names,
+ const std::vector<Connection> &model_label_names) {
/**
* this contains the map from node name to its input tensor names
label_dims.push_back(node->getOutputDimensions()[0]);
};
- auto identify_external_tensors = [this](const std::vector<std::string> &names,
+ auto identify_external_tensors = [this](const std::vector<Connection> &conns,
auto &&pred, auto &&identify) {
- if (names.empty()) {
+ if (conns.empty()) {
for (unsigned int i = 0; i < graph.size(); ++i) {
auto lnode = getSortedLayerNode(i).get();
if (!pred(lnode)) {
identify(lnode);
}
} else {
- for (auto &name : names) {
- auto lnode = getLayerNode(name).get();
+ for (auto &conn : conns) {
+ auto lnode = getLayerNode(conn.getName()).get();
NNTR_THROW_IF(!pred(lnode), std::invalid_argument)
- << "given node is not of that kind, name: " << name;
+ << "given node is not of that kind, name: " << conn.getName();
identify(lnode);
}
unsigned int num_node_of_kind = 0;
}
num_node_of_kind++;
}
- NNTR_THROW_IF(num_node_of_kind != names.size(), std::invalid_argument)
- << "names given but there are not identified node of the kind, num "
+ NNTR_THROW_IF(num_node_of_kind != conns.size(), std::invalid_argument)
+ << "conns given but there are not identified node of the kind, num "
"node of kind: "
- << num_node_of_kind << " identifier size: " << names.size();
+ << num_node_of_kind << " identifier size: " << conns.size();
}
};
namespace nntrainer {
+class Connection;
/**
* @class NeuralNetwork Graph Class
* @brief NeuralNetwork Graph Class which manage layers
/**
* @brief initialize network graph
*
- * @param model_input_names model input names if empty list given, all of node
- * that can be inputs will be identified in the sort order
+ * @param model_input_names model input connection if empty list given, all of
+ * node that can be inputs will be identified in the sort order
* @param model_label_names model label names if empty list given, all of node
* that can be labels will be identified in the sort order
* @return int ML_ERROR_NONE if successful
*/
- int initialize(const std::vector<std::string> &model_input_names = {},
- const std::vector<std::string> &model_label_names = {});
+ int initialize(const std::vector<Connection> &model_input_names = {},
+ const std::vector<Connection> &model_label_names = {});
/**
* @brief Create run layer context from the given init layer context
static constexpr const char *key =
"input_layers"; /**< unique key to access */
using prop_tag = connection_prop_tag; /**< property type */
-
- /**
- * @brief cast operator for property
- * @todo deprecate this, this is needed to bridge input_layers(name) <-> input
- * connections temporarily
- *
- * @return std::string value
- */
- operator const std::string &() const { return get().getName(); }
-
- /**
- * @brief cast operator for property
- * @todo deprecate this, this is needed to bridge input_layers(name) <-> input
- * connections temporarily
- *
- * @return std::string value
- */
- operator std::string &() { return get().getName(); }
};
/**
? std::string()
: std::get<props::LossType>(model_props);
- auto &input_layer_prop =
- std::get<std::vector<props::InputConnection>>(model_props);
+ auto &input_conn = std::get<std::vector<props::InputConnection>>(model_props);
/// @note label layer might need to be treated in the similar way as well
- /// @todo deprecate this instead directly pass connection to the realizer
- std::vector<std::string> input_layers = {};
- if (!input_layer_prop.empty()) {
- input_layers = std::vector<std::string>(input_layer_prop.begin(),
- input_layer_prop.end());
- }
-
/// @todo make NetworkGraph compiled at the construction instead of having
/// graph.compile(), neuralnetwork have ownership of list of layer nodes,
/// which will be passed at compile time.
std::vector<std::unique_ptr<GraphRealizer>> realizers;
- realizers.emplace_back(new PreviousInputRealizer(input_layers));
+ realizers.emplace_back(new PreviousInputRealizer(
+ std::vector<Connection>(input_conn.begin(), input_conn.end())));
realizers.emplace_back(new MultioutRealizer());
realizers.emplace_back(new FlattenRealizer());
realizers.emplace_back(new ActivationRealizer());
model_graph.setBatchSize(
std::get<props::TrainingBatchSize>(model_flex_props));
- auto &input_layer_prop =
+ auto &input_conns =
std::get<std::vector<props::InputConnection>>(model_props);
auto &label_layer_prop =
std::get<std::vector<props::LabelLayer>>(model_props);
- std::vector<std::string> input_layers;
+ std::vector<Connection> input_layers(input_conns.begin(), input_conns.end());
std::vector<std::string> label_layers;
- if (!input_layer_prop.empty()) {
- input_layers = std::vector<std::string>(input_layer_prop.begin(),
- input_layer_prop.end());
- }
if (!label_layer_prop.empty()) {
label_layers = std::vector<std::string>(label_layer_prop.begin(),
label_layer_prop.end());
}
- status = model_graph.initialize(input_layers, label_layers);
+ status = model_graph.initialize(
+ std::vector<Connection>(input_conns.begin(), input_conns.end()),
+ std::vector<Connection>(label_layers.begin(), label_layers.end()));
NN_RETURN_STATUS();
// initialize optimizer and related variables
auto start_layers_ = normalize(start_layers);
auto end_layers_ = normalize(end_layers);
+ auto start_conns_ =
+ std::vector<Connection>(start_layers.begin(), start_layers.end());
+
std::vector<std::unique_ptr<GraphRealizer>> realizers;
- realizers.emplace_back(new PreviousInputRealizer(start_layers));
+ realizers.emplace_back(new PreviousInputRealizer(start_conns_));
realizers.emplace_back(new SliceRealizer(start_layers_, end_layers_));
if (!input_layers_.empty()) {
* @author Jihoon Lee <jhoon.it.lee@samsung.com>
* @bug No known bugs except for NYI items
*/
-
-#include "activation_realizer.h"
#include <gtest/gtest.h>
#include <vector>
+#include <activation_realizer.h>
+#include <connection.h>
#include <flatten_realizer.h>
#include <input_realizer.h>
#include <multiout_realizer.h>
{"fully_connected", {"name=fc3", "input_layers=fc1"}},
{"fully_connected", {"name=fc4"}},
};
- PreviousInputRealizer r({"fc1", "fc4"});
+ PreviousInputRealizer r({Connection("fc1"), Connection("fc4")});
realizeAndEqual(r, before, after);
}
{ /// intermediate node is auto input