[moco/ONNX] Change parameter of convert_graph (#3547)
author남궁석/On-Device Lab(SR)/Engineer/삼성전자 <sk.namkoong@samsung.com>
Tue, 21 May 2019 02:11:20 +0000 (11:11 +0900)
committer박세희/On-Device Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Tue, 21 May 2019 02:11:20 +0000 (11:11 +0900)
For checking opset version of ONNX, onnx ModelProto is needed.
But until now, convert_graph has GraphProto, not ModelProto.
This commit will pass ModelProto parameter instead of GraphProto

Signed-off-by: Seok NamKoong <sk.namkoong@samsung.com>
contrib/moco/lib/frontend/onnx/src/Frontend.cpp

index e327b72..43847c6 100644 (file)
@@ -71,7 +71,7 @@ void load_onnx(const std::string &path, moco::onnx::Frontend::FileType type,
   }
 }
 
-void convert_graph(::onnx::GraphProto &onnx_graph_proto, loco::Graph *graph)
+void convert_graph(::onnx::ModelProto &onnx_model_proto, loco::Graph *graph)
 {
   auto nodes = stdex::make_unique<moco::onnx::SymbolTable>();
   auto input_names = stdex::make_unique<moco::onnx::SymbolTable>();
@@ -84,6 +84,9 @@ void convert_graph(::onnx::GraphProto &onnx_graph_proto, loco::Graph *graph)
   // 3. Set graph input
   // 4. Create loco::Push node and set input and set graph output
 
+  assert(onnx_model_proto.has_graph());
+  ::onnx::GraphProto onnx_graph_proto = onnx_model_proto.graph();
+
   // 1. Convert all the nodes to loco::Node
   for (const auto &n : onnx_graph_proto.node())
   {
@@ -174,15 +177,12 @@ Frontend::Frontend()
 std::unique_ptr<loco::Graph> Frontend::load(const char *modelfile, FileType type) const
 {
   ::onnx::ModelProto onnx_model_proto;
-  ::onnx::GraphProto onnx_graph_proto;
 
   load_onnx(modelfile, type, onnx_model_proto);
 
-  onnx_graph_proto = onnx_model_proto.graph();
-
   auto graph = loco::make_graph();
 
-  convert_graph(onnx_graph_proto, graph.get());
+  convert_graph(onnx_model_proto, graph.get());
 
   return std::move(graph);
 }