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 6.3 kB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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_INTERNAL_INCLUDE_MODEL_H
  17. #define MINDSPORE_LITE_INTERNAL_INCLUDE_MODEL_H
  18. #include "internal/include/lite_utils.h"
  19. #include "nnacl/op_base.h"
  20. using PrimitiveC = OpParameter;
  21. enum NodeType {
  22. NodeType_ValueNode = 0,
  23. NodeType_Parameter = 1,
  24. NodeType_CNode = 2,
  25. NodeType_MIN = NodeType_ValueNode,
  26. NodeType_MAX = NodeType_CNode
  27. };
  28. enum KernelType : int {
  29. KernelType_Concat = 0,
  30. KernelType_SoftMax,
  31. KernelType_Activation,
  32. KernelType_Conv2D,
  33. KernelType_FusedBatchNorm,
  34. KernelType_BatchNorm,
  35. KernelType_BiasAdd,
  36. KernelType_Pooling,
  37. KernelType_ROIPooling,
  38. KernelType_DepthwiseConv2D,
  39. KernelType_DeDepthwiseConv2D,
  40. KernelType_Resize,
  41. KernelType_DetectionPostProcess,
  42. KernelType_FullConnection,
  43. KernelType_Mean,
  44. KernelType_DeConv2D,
  45. KernelType_Scale,
  46. KernelType_Reshape,
  47. KernelType_Eltwise,
  48. KernelType_NetOutput,
  49. KernelType_Add,
  50. KernelType_Sub,
  51. KernelType_MatMul,
  52. KernelType_StridedSlice,
  53. KernelType_Power,
  54. KernelType_Slice,
  55. KernelType_Stack,
  56. KernelType_Mul,
  57. KernelType_RealDiv,
  58. KernelType_Pad,
  59. KernelType_Maximum,
  60. KernelType_Minimum,
  61. KernelType_PReLU,
  62. KernelType_LeakyReLU,
  63. KernelType_ArgMax,
  64. KernelType_ArgMin,
  65. KernelType_Exp,
  66. KernelType_Crop,
  67. KernelType_Range,
  68. KernelType_Rsqrt,
  69. KernelType_ExpandDims,
  70. KernelType_Tile,
  71. KernelType_Cast,
  72. KernelType_Shape,
  73. KernelType_Nchw2Nhwc,
  74. KernelType_Nhwc2Nchw,
  75. KernelType_QuantDTypeCast,
  76. KernelType_Split,
  77. KernelType_Permute,
  78. KernelType_FakeQuantWithMinMaxVars,
  79. KernelType_Equal,
  80. KernelType_Less,
  81. KernelType_Greater,
  82. KernelType_NotEqual,
  83. KernelType_LessEqual,
  84. KernelType_GreaterEqual,
  85. KernelType_Min,
  86. KernelType_Floor,
  87. KernelType_Abs,
  88. KernelType_Neg,
  89. KernelType_Cos,
  90. KernelType_Sin,
  91. KernelType_Sqrt,
  92. KernelType_Square,
  93. KernelType_Constant,
  94. KernelType_Log,
  95. KernelType_Tan,
  96. KernelType_Atan,
  97. KernelType_Asin,
  98. KernelType_Clip,
  99. KernelType_Transpose,
  100. KernelType_Squeeze,
  101. KernelType_Unsqueeze,
  102. KernelType_Upsample,
  103. KernelType_Dropout,
  104. KernelType_Broadcast,
  105. KernelType_BroadcastTo,
  106. KernelType_Lrn,
  107. KernelType_ZerosLike,
  108. KernelType_TopK,
  109. KernelType_SpaceToDepth,
  110. KernelType_SpaceToBatch,
  111. KernelType_SparseToDense,
  112. KernelType_ReverseSequence,
  113. KernelType_Rank,
  114. KernelType_Gather,
  115. KernelType_GatherNd,
  116. KernelType_Fill,
  117. KernelType_Elu,
  118. KernelType_DepthToSpace,
  119. KernelType_BatchToSpace,
  120. KernelType_AddN,
  121. KernelType_Ceil,
  122. KernelType_EmbeddingLookup,
  123. KernelType_EmbeddingLookupSparse,
  124. KernelType_FloorDiv,
  125. KernelType_FloorMod,
  126. KernelType_L2Norm,
  127. KernelType_LocalResponseNormalization,
  128. KernelType_MatrixDiag,
  129. KernelType_Reduce,
  130. KernelType_Reverse,
  131. KernelType_Round,
  132. KernelType_Select,
  133. KernelType_Scatter,
  134. KernelType_ScatterND,
  135. KernelType_ConstantOfShape,
  136. KernelType_Unique,
  137. KernelType_Unstack,
  138. KernelType_LogicalAnd,
  139. KernelType_LogicalOr,
  140. KernelType_LogicalXor,
  141. KernelType_LogicalNot,
  142. KernelType_OnnxInt8Quantize,
  143. KernelType_OnnxInt8Dequantize,
  144. KernelType_FakeQuantWithMinMax,
  145. KernelType_FakeQuantWithMinMaxPerChannel,
  146. KernelType_BatchNormFold,
  147. KernelType_MulFold,
  148. KernelType_AddFold,
  149. KernelType_SquaredDifference,
  150. KernelType_Flatten,
  151. KernelType_FlattenGrad,
  152. KernelType_TupleGetItem,
  153. KernelType_Div,
  154. KernelType_Where,
  155. KernelType_OneHot,
  156. KernelType_Lstm,
  157. KernelType_Conv2DGradFilter,
  158. KernelType_Conv2DGradInput,
  159. KernelType_PoolingGrad,
  160. KernelType_BNGrad,
  161. KernelType_BNGradInput,
  162. KernelType_ApplyMomentum,
  163. KernelType_BiasGrad,
  164. KernelType_SoftmaxCrossEntropy,
  165. KernelType_AddGrad,
  166. KernelType_SubGrad,
  167. KernelType_MulGrad,
  168. KernelType_DivGrad,
  169. KernelType_PowerGrad,
  170. KernelType_ActivationGrad,
  171. KernelType_PriorBox,
  172. KernelType_SpaceToBatchND,
  173. KernelType_Depend,
  174. KernelType_Return,
  175. KernelType_MakeTuple,
  176. KernelType_ToFormat,
  177. KernelType_Proposal,
  178. KernelType_Custom,
  179. KernelType_BlackBox,
  180. KernelType_NegGrad,
  181. KernelType_LogGrad,
  182. KernelType_BatchToSpaceND,
  183. KernelType_END,
  184. };
  185. enum ActivationType {
  186. NO_ACTIVATION = 0,
  187. RELU = 1,
  188. SIGMOID = 2,
  189. RELU6 = 3,
  190. ELU = 4,
  191. LEAKY_RELU = 5,
  192. ABS = 6,
  193. RELU1 = 7,
  194. SOFTSIGN = 8,
  195. SOFTPLUS = 9,
  196. TANH = 10,
  197. SELU = 11,
  198. HSWISH = 12,
  199. HSIGMOID = 13,
  200. THRESHOLDRELU = 14,
  201. LINEAR = 15,
  202. UNKNOW = 16
  203. };
  204. enum ReduceMode {
  205. ReduceMode_ReduceMean = 0,
  206. ReduceMode_ReduceMax = 1,
  207. ReduceMode_ReduceMin = 2,
  208. ReduceMode_ReduceProd = 3,
  209. ReduceMode_ReduceSum = 4,
  210. ReduceMode_ReduceSumSquare = 5,
  211. ReduceMode_ReduceASum = 6,
  212. ReduceMode_MIN = ReduceMode_ReduceMean,
  213. ReduceMode_MAX = ReduceMode_ReduceASum
  214. };
  215. typedef struct Node {
  216. String name_;
  217. NodeType node_type_;
  218. PrimitiveC *primitive_;
  219. Uint32Vector input_indices_;
  220. Uint32Vector output_indices_;
  221. } Node;
  222. typedef struct Model {
  223. String name_;
  224. String version_;
  225. TensorPtrVector all_tensors_;
  226. Uint32Vector input_indices_;
  227. Uint32Vector output_indices_;
  228. NodePtrVector nodes_;
  229. char *buf;
  230. /// \brief Static method to create a Model pointer.
  231. ///
  232. /// \param[in] model_buf Define the buffer read from a model file.
  233. /// \param[in] size Define bytes number of model buffer.
  234. ///
  235. /// \return Pointer of MindSpore Lite Model.
  236. static Model *Import(const char *model_buf, size_t size);
  237. /// \brief Free all the temporary buffer
  238. void Free();
  239. } Model;
  240. #endif // MINDSPORE_LITE_INTERNAL_INCLUDE_MODEL_H