You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

node_parser.h 3.8 kB

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