• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2021 Huawei Technologies Co., Ltd
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef MINDSPORE_LITE_INCLUDE_REGISTRY_NODE_PARSER_H_
18 #define MINDSPORE_LITE_INCLUDE_REGISTRY_NODE_PARSER_H_
19 
20 #include <map>
21 #include <memory>
22 #include <string>
23 #include <vector>
24 #include "include/registry/converter_context.h"
25 #include "ops/base_operator.h"
26 
27 namespace onnx {
28 class GraphProto;
29 class NodeProto;
30 }  // namespace onnx
31 
32 namespace caffe {
33 class LayerParameter;
34 }  // namespace caffe
35 
36 namespace tensorflow {
37 class NodeDef;
38 }  // namespace tensorflow
39 
40 namespace tflite {
41 struct OperatorT;
42 struct SubGraphT;
43 struct ModelT;
44 }  // namespace tflite
45 
46 namespace mindspore {
47 namespace ops {
48 /// \brief PrimitiveC defined a base class for storing properties
49 using BaseOperatorPtr = api::SharedPtr<ops::BaseOperator>;
50 }  // namespace ops
51 namespace converter {
52 /// \brief NodeParser defined a base class for parsing node's attributes.
53 class MS_API NodeParser {
54  public:
55   /// \brief Constructor.
56   NodeParser() = default;
57 
58   /// \brief Destructor.
59   virtual ~NodeParser() = default;
60 
61   /// \brief Method to parse node of ONNX.
62   ///
63   /// \param[in] onnx_graph Define the onnx graph, which contains all information about the graph.
64   /// \param[in] onnx_node Define the node to be resolved.
65   ///
66   /// \return PrimitiveC Attribute storage.
Parse(const onnx::GraphProto & onnx_graph,const onnx::NodeProto & onnx_node)67   virtual ops::BaseOperatorPtr Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node) {
68     return nullptr;
69   }
70 
71   /// \brief Method to parse node of CAFFE.
72   ///
73   /// \param[in] proto Define the node which contains attributes.
74   /// \param[in] weight Define the node which contains weight information.
75   ///
76   /// \return PrimitiveC Attribute storage.
Parse(const caffe::LayerParameter & proto,const caffe::LayerParameter & weight)77   virtual ops::BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) {
78     return nullptr;
79   }
80 
81   /// \brief Method to parse node of TF.
82   ///
83   /// \param[in] tf_op Define the node to be resolved.
84   /// \param[in] tf_node_map Define the all nodes of the graph.
85   /// \param[in] inputs Define the input name, that determines which inputs will be parsed including their order.
86   ///            Determined by user.
87   /// \param[in] output_size Define the output num of current node, which need to be determined by user.
88   ///
89   /// \return PrimitiveC Attribute storage.
Parse(const tensorflow::NodeDef & tf_op,const std::map<std::string,const tensorflow::NodeDef * > & tf_node_map,std::vector<std::string> * inputs,int * output_size)90   virtual ops::BaseOperatorPtr Parse(const tensorflow::NodeDef &tf_op,
91                                      const std::map<std::string, const tensorflow::NodeDef *> &tf_node_map,
92                                      std::vector<std::string> *inputs, int *output_size) {
93     return nullptr;
94   }
95 
96   /// \brief Method to parse node of TFLITE
97   ///
98   /// \param[in] tflite_op Define the node to be resolved.
99   /// \param[in] tflite_subgraph Define the subgraph to be resolved.
100   /// \param[in] tflite_model Define the model, which contains all information abort the graph.
101   ///
102   /// \return PrimitiveC Attribute storage.
Parse(const std::unique_ptr<tflite::OperatorT> & tflite_op,const std::unique_ptr<tflite::SubGraphT> & tflite_subgraph,const std::unique_ptr<tflite::ModelT> & tflite_model)103   virtual ops::BaseOperatorPtr Parse(const std::unique_ptr<tflite::OperatorT> &tflite_op,
104                                      const std::unique_ptr<tflite::SubGraphT> &tflite_subgraph,
105                                      const std::unique_ptr<tflite::ModelT> &tflite_model) {
106     return nullptr;
107   }
108 };
109 /// \brief NodeParserPtr defined a shared_ptr type.
110 using NodeParserPtr = std::shared_ptr<NodeParser>;
111 }  // namespace converter
112 }  // namespace mindspore
113 
114 #endif  // MINDSPORE_LITE_INCLUDE_REGISTRY_NODE_PARSER_H_
115