| 277 | #endif |
| 278 | |
| 279 | bool Graph::RealCreateFromStatic(const StaticGraphPtr& static_graph) |
| 280 | { |
| 281 | orig_graph_ = static_graph; |
| 282 | attrs_ = static_graph->attrs; |
| 283 | |
| 284 | int node_number = static_graph->node_list.size(); |
| 285 | |
| 286 | /* create node and its output tensor */ |
| 287 | for(int i = 0; i < node_number; i++) |
| 288 | { |
| 289 | const StaticNode* node_ptr = static_graph->node_list[i].get(); |
| 290 | |
| 291 | Node* node = new Node(node_ptr->name); |
| 292 | |
| 293 | if(!CreateNodeFromStatic(node, static_graph.get(), node_ptr)) |
| 294 | return false; |
| 295 | } |
| 296 | |
| 297 | /* Setup the connections */ |
| 298 | int tensor_number = static_graph->tensor_list.size(); |
| 299 | |
| 300 | for(int i = 0; i < tensor_number; i++) |
| 301 | { |
| 302 | const StaticTensor* static_tensor = static_graph->tensor_list[i].get(); |
| 303 | Tensor* tensor = FindTensor(static_tensor->name); |
| 304 | |
| 305 | if(tensor == nullptr) |
| 306 | { |
| 307 | XLOG_ERROR() << "cannot find tensor: " << static_tensor->name << "\n"; |
| 308 | return false; |
| 309 | } |
| 310 | |
| 311 | if(!SetupConnection(tensor, static_graph.get(), static_tensor)) |
| 312 | return false; |
| 313 | } |
| 314 | |
| 315 | /* set the input and output */ |
| 316 | |
| 317 | for(unsigned int i = 0; i < static_graph->input_node_list.size(); i++) |
| 318 | { |
| 319 | int node_idx = static_graph->input_node_list[i]; |
| 320 | Node* node = FindNode(static_graph->node_list[node_idx].get()->name); |
| 321 | input_nodes.push_back(node); |
| 322 | |
| 323 | /* update the input node's tensor type */ |
| 324 | Tensor* tensor = node->GetOutputTensor(0); |
| 325 | tensor->SetType(kInputTensor); |
| 326 | } |
| 327 | |
| 328 | for(unsigned int i = 0; i < static_graph->output_node_list.size(); i++) |
| 329 | { |
| 330 | int node_idx = static_graph->output_node_list[i]; |
| 331 | Node* node = FindNode(static_graph->node_list[node_idx].get()->name); |
| 332 | output_nodes.push_back(node); |
| 333 | } |
| 334 | |
| 335 | /* re-order the seq_nodes_, removing un-used node, according to node dependency*/ |
| 336 |
no test coverage detected