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.

model.h 2.5 kB

5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /**
  2. * Copyright 2020 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_MODEL_H_
  17. #define MINDSPORE_LITE_INCLUDE_MODEL_H_
  18. #include "include/lite_utils.h"
  19. namespace mindspore::lite {
  20. struct MS_API Model {
  21. struct Node {
  22. String name_;
  23. int node_type_;
  24. const void *primitive_ = nullptr;
  25. Uint32Vector input_indices_;
  26. Uint32Vector output_indices_;
  27. int quant_type_;
  28. int device_type_ = -1;
  29. };
  30. using NodePtrVector = Vector<Node *>;
  31. struct SubGraph {
  32. String name_;
  33. Uint32Vector input_indices_;
  34. Uint32Vector output_indices_;
  35. Uint32Vector node_indices_;
  36. Uint32Vector tensor_indices_;
  37. };
  38. using SubGraphPtrVector = Vector<SubGraph *>;
  39. String name_;
  40. String version_;
  41. Uint32Vector input_indices_;
  42. Uint32Vector output_indices_;
  43. TensorPtrVector all_tensors_;
  44. NodePtrVector all_nodes_;
  45. char *buf = nullptr;
  46. SubGraphPtrVector sub_graphs_;
  47. #ifdef ENABLE_MODEL_OBF
  48. using NodeStatVector = Vector<uint32_t>;
  49. using PrimTypeVector = Vector<uint32_t>;
  50. using PrimVector = Vector<unsigned char *>;
  51. PrimTypeVector all_prims_type_;
  52. NodeStatVector all_nodes_stat_;
  53. bool model_obfuscated_ = false;
  54. PrimVector deobf_prims_;
  55. #endif
  56. /// \brief Static method to create a Model pointer.
  57. static Model *Import(const char *model_buf, size_t size);
  58. /// \brief Static method to create a Model pointer.
  59. static Model *Import(const char *filename);
  60. /// \brief method to export model to file.
  61. static int Export(Model *model, const char *filename);
  62. /// \brief method to export model to buffer.
  63. static int Export(Model *model, char *buf, size_t *size);
  64. /// \brief Free meta graph temporary buffer
  65. virtual void Free() = 0;
  66. /// \brief Free all temporary buffer.EG: nodes in the model.
  67. virtual void Destroy() = 0;
  68. /// \brief Model destruct, free all memory
  69. virtual ~Model() = default;
  70. };
  71. } // namespace mindspore::lite
  72. #endif // MINDSPORE_LITE_INCLUDE_MODEL_H_