From: Jihoon Lee Date: Wed, 6 Oct 2021 16:19:09 +0000 (+0900) Subject: [graph] update getter of input/output dims X-Git-Tag: accepted/tizen/unified/20220323.062643~354 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=30c498b68cd732e305f9129bff14dc4f6d90002f;p=platform%2Fcore%2Fml%2Fnntrainer.git [graph] update getter of input/output dims This patch update input/output dims to properly reflect model input, output dimensions, not just a single object. **Self evaluation:** 1. Build test: [X]Passed [ ]Failed [ ]Skipped 2. Run test: [X]Passed [ ]Failed [ ]Skipped Signed-off-by: Jihoon Lee --- diff --git a/nntrainer/graph/network_graph.cpp b/nntrainer/graph/network_graph.cpp index 8619f67..5cc35f7 100644 --- a/nntrainer/graph/network_graph.cpp +++ b/nntrainer/graph/network_graph.cpp @@ -496,17 +496,19 @@ sharedConstTensors NetworkGraph::forwarding(bool training) const { } std::vector NetworkGraph::getInputDimension() const { - NNTR_THROW_IF(this->empty(), std::invalid_argument) - << "[NetworkGraph] the graph has no node!"; - return getSortedLayerNode(0)->getInputDimensions(); + NNTR_THROW_IF(input_dims.empty(), std::invalid_argument) + << "[NetworkGraph] the graph has no node identified as input!"; + return input_dims; } unsigned int NetworkGraph::getBatchSize() const { return batch_size; } std::vector NetworkGraph::getOutputDimension() const { - NNTR_THROW_IF(this->empty(), std::invalid_argument) - << "[NetworkGraph] the graph has no node!"; - return getSortedLayerNode(graph.size() - 1)->getOutputDimensions(); + NNTR_THROW_IF(label_dims.empty(), std::invalid_argument) + << "[NetworkGraph] the graph has no node identified as output!"; + /// for now, outputting label_dims works, later label dim will be different + /// from output dimension + return label_dims; } std::vector> @@ -857,6 +859,7 @@ int NetworkGraph::initialize( << num_input; input_list.push_back(node->getInput(0).getName()); + input_dims.push_back(node->getInputDimensions()[0]); }; auto is_label_node = [](LayerNode *node) { return node->requireLabel(); }; @@ -872,6 +875,7 @@ int NetworkGraph::initialize( << num_label; label_list.push_back(node->getOutputGrad(0).getName()); + label_dims.push_back(node->getOutputDimensions()[0]); }; auto identify_external_tensors = [this](const std::vector &names, diff --git a/nntrainer/graph/network_graph.h b/nntrainer/graph/network_graph.h index 217bf66..8f564ed 100644 --- a/nntrainer/graph/network_graph.h +++ b/nntrainer/graph/network_graph.h @@ -95,6 +95,7 @@ public: * @brief Swap function for the class */ friend void swap(NetworkGraph &lhs, NetworkGraph &rhs) { + /// @fixme this swap function need maintenance using std::swap; swap(lhs.graph, rhs.graph); @@ -382,8 +383,11 @@ private: unsigned int batch_size; /**< current batch_size */ // std::vector label_list; /**< var_grads for the labels */ // std::vector input_list; /**< var_grads for the inputs */ - std::vector label_list; /**< var_grads for the labels */ - std::vector input_list; /**< var_grads for the inputs */ + std::vector label_list; /**< identifier for the model labels */ + std::vector input_list; /**< identifier for the model inputs */ + std::vector label_dims; /**< graph label dimensions */ + std::vector input_dims; /**< graph input dimensions */ + ExecutionMode exec_mode; /**< execution mode with which the graph has been currently set or previously set */