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 26 namespace onnx { 27 class GraphProto; 28 class NodeProto; 29 } // namespace onnx 30 31 namespace caffe { 32 class LayerParameter; 33 } // namespace caffe 34 35 namespace tensorflow { 36 class NodeDef; 37 } // namespace tensorflow 38 39 namespace tflite { 40 struct OperatorT; 41 struct SubGraphT; 42 struct ModelT; 43 } // namespace tflite 44 45 namespace mindspore { 46 namespace ops { 47 /// \brief PrimitiveC defined a base class for storing properties 48 class PrimitiveC; 49 } // namespace ops 50 namespace converter { 51 /// \brief NodeParser defined a base class for parsing node's attributes. 52 class MS_API NodeParser { 53 public: 54 /// \brief Constructor. 55 NodeParser() = default; 56 57 /// \brief Destructor. 58 virtual ~NodeParser() = default; 59 60 /// \brief Method to parse node of ONNX. 61 /// 62 /// \param[in] onnx_graph Define the onnx graph, which contains all information about the graph. 63 /// \param[in] onnx_node Define the node to be resolved. 64 /// 65 /// \return PrimitiveC Attribute storage. Parse(const onnx::GraphProto & onnx_graph,const onnx::NodeProto & onnx_node)66 virtual ops::PrimitiveC *Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node) { 67 return nullptr; 68 } 69 70 /// \brief Method to parse node of CAFFE. 71 /// 72 /// \param[in] proto Define the node which contains attributes. 73 /// \param[in] weight Define the node which contains weight information. 74 /// 75 /// \return PrimitiveC Attribute storage. Parse(const caffe::LayerParameter & proto,const caffe::LayerParameter & weight)76 virtual ops::PrimitiveC *Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { 77 return nullptr; 78 } 79 80 /// \brief Method to parse node of TF. 81 /// 82 /// \param[in] tf_op Define the node to be resolved. 83 /// \param[in] tf_node_map Define the all nodes of the graph. 84 /// \param[in] inputs Define the input name, that determines which inputs will be parsed including their order. 85 /// Determined by user. 86 /// \param[in] output_size Define the output num of current node, which need to be determined by user. 87 /// 88 /// \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)89 virtual ops::PrimitiveC *Parse(const tensorflow::NodeDef &tf_op, 90 const std::map<std::string, const tensorflow::NodeDef *> &tf_node_map, 91 std::vector<std::string> *inputs, int *output_size) { 92 return nullptr; 93 } 94 95 /// \brief Method to parse node of TFLITE 96 /// 97 /// \param[in] tflite_op Define the node to be resolved. 98 /// \param[in] tflite_model Define the model, which contains all information abort the graph. 99 /// 100 /// \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)101 virtual ops::PrimitiveC *Parse(const std::unique_ptr<tflite::OperatorT> &tflite_op, 102 const std::unique_ptr<tflite::SubGraphT> &tflite_subgraph, 103 const std::unique_ptr<tflite::ModelT> &tflite_model) { 104 return nullptr; 105 } 106 }; 107 /// \brief NodeParserPtr defined a shared_ptr type. 108 using NodeParserPtr = std::shared_ptr<NodeParser>; 109 } // namespace converter 110 } // namespace mindspore 111 112 #endif // MINDSPORE_LITE_INCLUDE_REGISTRY_NODE_PARSER_H_ 113