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.

transformation_ops.h 38 kB

5 years ago
5 years ago
5 years ago
5 years ago
3 years ago
3 years ago
3 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
5 years ago
3 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
3 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
3 years ago
5 years ago
3 years ago
3 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
3 years ago
5 years ago
5 years ago
5 years ago
5 years ago
3 years ago
5 years ago
5 years ago
5 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963
  1. /**
  2. * Copyright 2019 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. * \file transformation_ops.h
  18. * \brief
  19. */
  20. #ifndef OPS_BUILT_IN_OP_PROTO_INC_TRANSFORMATION_OPS_H_
  21. #define OPS_BUILT_IN_OP_PROTO_INC_TRANSFORMATION_OPS_H_
  22. #include "graph/operator_reg.h"
  23. namespace ge {
  24. /**
  25. *@brief This operation convert output dataType and shape
  26. *@par Inputs:
  27. *The input handle must have the resource type. Inputs include:
  28. *x:A list of Tensor objects. One or more tensors from which
  29. the enqueued tensors should be taken . \n
  30. *@par Outputs:
  31. *y:A list of Tensor objects. One or more tensors from which
  32. the enqueued tensors should be taken . \n
  33. *@par Attributes:
  34. *type: An optional ge::DataType. It refers to the target data type of outputs . \n
  35. *@par Third-party framework compatibility
  36. *Compatible with tensorflow QueueIsClosed operator.
  37. */
  38. REG_OP(Bitcast)
  39. .INPUT(x, TensorType({DT_BOOL, DT_FLOAT16, DT_FLOAT, DT_INT8, DT_INT32, DT_UINT32, DT_UINT8,
  40. DT_INT64, DT_UINT64, DT_INT16, DT_UINT16, DT_DOUBLE, DT_COMPLEX64,
  41. DT_COMPLEX128, DT_QINT8, DT_QUINT8, DT_QINT16, DT_QUINT16, DT_QINT32}))
  42. .OUTPUT(y, TensorType({DT_BOOL, DT_FLOAT16, DT_FLOAT, DT_INT8, DT_INT32, DT_UINT32, DT_UINT8,
  43. DT_INT64, DT_UINT64, DT_INT16, DT_UINT16, DT_DOUBLE, DT_COMPLEX64,
  44. DT_COMPLEX128, DT_QINT8, DT_QUINT8, DT_QINT16, DT_QUINT16, DT_QINT32}))
  45. .REQUIRED_ATTR(type, Type)
  46. .OP_END_FACTORY_REG(Bitcast)
  47. /**
  48. *@brief Convert tensor format from HWCN to C1HWNCoC0 . \n
  49. *@par Inputs:
  50. *x: A Tensor. Must be 4D Tensor of type float16, float32, int32, uint16, with format HWCN . \n
  51. *@par Outputs:
  52. *y: A 6D Tensor. Has the same type as "x", with format C1HWNCoC0.
  53. */
  54. REG_OP(DepthwiseWeight4DTo6D)
  55. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32, DT_UINT16}))
  56. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32, DT_UINT16}))
  57. .OP_END_FACTORY_REG(DepthwiseWeight4DTo6D)
  58. /**
  59. *@brief Convert tensor format from C1HWNCoC0 to HWCN . \n
  60. *@par Inputs:
  61. *x: A Tensor. Must be 6D Tensor of type float16, float32, int32, uint16, with format C1HWNCoC0 . \n
  62. *@par Attributes:
  63. *channel_size: An optional int, specifying the channel size of 4D Tensor with format HWCN . \n
  64. *@par Outputs:
  65. *y: A 4D Tensor. Has the same type as "x", with format HWCN.
  66. */
  67. REG_OP(DepthwiseWeight6DTo4D)
  68. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32, DT_UINT16}))
  69. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32, DT_UINT16}))
  70. .ATTR(channel_size, Int, 16)
  71. .OP_END_FACTORY_REG(DepthwiseWeight6DTo4D)
  72. /**
  73. *@brief Permutes the dimensions according to perm.
  74. The returned tensor's dimension i will correspond to the input dimension perm[i] . \n
  75. *@par Inputs:
  76. *x: A Tensor. Must be one of the following types: float16, float32, int8, int16, int32, int64, uint8, uint16, uint32, uint64 . \n
  77. *@par Attributes:
  78. *perm: A permutation of the dimensions of "x" . \n
  79. *@par Outputs:
  80. *y: A Tensor. Has the same type as "x".
  81. *@par Restrictions:
  82. *Warning: THIS FUNCTION IS DEPRECATED. Please use Transpose instead.
  83. */
  84. REG_OP(TransposeD)
  85. .INPUT(x, TensorType({DT_INT8, DT_INT16, DT_INT32, DT_INT64, DT_UINT8,
  86. DT_UINT16, DT_UINT32, DT_UINT64, DT_FLOAT16, DT_FLOAT}))
  87. .OUTPUT(y, TensorType({DT_INT8, DT_INT16, DT_INT32, DT_INT64, DT_UINT8,
  88. DT_UINT16, DT_UINT32, DT_UINT64, DT_FLOAT16, DT_FLOAT}))
  89. .REQUIRED_ATTR(perm, ListInt)
  90. .OP_END_FACTORY_REG(TransposeD)
  91. /**
  92. *@brief Permutes the dimensions according to perm.
  93. The returned tensor's dimension i will correspond to the input dimension perm[i] . \n
  94. *@par Inputs:
  95. *Two inputs, including:
  96. *@li x: A Tensor. Must be one of the following types: float16, float32, int8, int16, int32, int64, uint8, uint16, uint32, uint64.
  97. *@li perm: A Tensor of type int32 or int64. A permutation of the dimensions of "x" . \n
  98. *@par Outputs:
  99. *y: A Tensor. Has the same type as "x" . \n
  100. *@par Third-party framework compatibility
  101. *Compatible with the TensorFlow operator Transpose.
  102. */
  103. REG_OP(Transpose)
  104. .INPUT(x, TensorType::BasicType())
  105. .INPUT(perm, TensorType::IndexNumberType())
  106. .OUTPUT(y, TensorType::BasicType())
  107. .OP_END_FACTORY_REG(Transpose)
  108. /**
  109. *@brief Do format transfer for various data format.
  110. * In general, the framework will insert it atomatically . \n
  111. *@par Inputs:
  112. *src: A Tensor. For all branches can be types: float16, float32, int32, int8, bool.
  113. * For branches without padding also can be types: int16, int64, uint8, uint16, uint32, uint64 . \n
  114. *@par Attributes:
  115. *@li src_format: A string source data format, can be "NHWC", "NCHW" etc.
  116. *@li dst_format: A string target data format, can be "NCHW" etc.
  117. *@li src_subformat: A optional int32 for source sub-format, default value is 0.
  118. *@li dst_subformat: A optional int32 for target sub-format, default value is 0.
  119. *@li groups: A optional int32, default value is 1. \n
  120. *@par Outputs:
  121. *dst: A Tensor. Has the same type as "src".
  122. */
  123. REG_OP(TransData)
  124. .INPUT(src, TensorType::BasicType())
  125. .OUTPUT(dst, TensorType::BasicType())
  126. .REQUIRED_ATTR(src_format, String)
  127. .REQUIRED_ATTR(dst_format, String)
  128. .ATTR(src_subformat, Int, 0)
  129. .ATTR(dst_subformat, Int, 0)
  130. .ATTR(groups, Int, 1)
  131. .OP_END_FACTORY_REG(TransData)
  132. /**
  133. *@brief Do format transfer for various data format only
  134. support "ND" to "ND_RNN_BIAS" and "ND" to "FRACTAL_ZN_RNN"
  135. *@par Inputs:
  136. *src: A Tensor. For all branches can be types: float16, float32, int32, int8, bool.
  137. * For branches without padding also can be types: int16, int64, uint8, uint16, uint32, uint64 . \n
  138. *@par Attributes:
  139. *@li src_format: A string source data format, can be "ND", "ND_RNN_BIAS", "FRACTAL_ZN_RNN" etc.
  140. *@li dst_format: A string target data format, can be "ND", "ND_RNN_BIAS", "FRACTAL_ZN_RNN" etc.
  141. *@li input_size: A mental int32.
  142. *@li hidden_size: A mental int32.
  143. *@par Outputs:
  144. *dst: A Tensor. Has the same type as "src".
  145. */
  146. REG_OP(TransDataRNN)
  147. .INPUT(src, TensorType::BasicType())
  148. .OUTPUT(dst, TensorType::BasicType())
  149. .REQUIRED_ATTR(src_format, String)
  150. .REQUIRED_ATTR(dst_format, String)
  151. .REQUIRED_ATTR(input_size, Int)
  152. .REQUIRED_ATTR(hidden_size, Int)
  153. .OP_END_FACTORY_REG(TransDataRNN)
  154. /**
  155. *@brief Permutes the dimensions according to order.
  156. The returned tensor's dimension i will correspond to the input dimension order[i] . \n
  157. *@par Inputs:
  158. *x: A Tensor. Must be one of the following types: float16, float32 . \n
  159. *@par Attributes:
  160. *order: A permutation of the dimensions of "x".Type is int32.support any axis transformation.Defaults to "{0}"
  161. *@par Outputs:
  162. *y: A Tensor. Has the same type as "x".
  163. */
  164. REG_OP(Permute)
  165. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  166. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  167. .ATTR(order, ListInt, {0})
  168. .OP_END_FACTORY_REG(Permute)
  169. /**
  170. *@brief Flattens the inputs tensor into a 2D matrix. If input tensor has shape (d_0, d_1,..., d_n),
  171. * then the output will have shape (d_0 X d_1 ... d_(axis-1), d_axis X d_(axis + 1)...X d_n)\n
  172. *@par Inputs:
  173. * One input:
  174. * x: A multi-dimensional Tensor. Must be one of the following types:
  175. * int8, uint8, int16, uint16, int32, uint32, int64,uint64, float16, float32.
  176. *@par Outputs:
  177. * y: A 2D flattened Tensor with the contents of the input tensor, with input dimensions up to axis flattened
  178. * to the outer dimension of the output and remaining input dimensions flattened into the inner dimension of the output.
  179. * Must be one of the following data types: int8, uint8, int16, uint16, int32, uint32, int64,uint64, float16, float32 .
  180. *@par Attributes:
  181. * axis: A optional int32, default value is 1. Indicate up to which input dimensions (exclusive) should be flattened
  182. * to the outer dimension of the output. The value for axis must be in the range [-r, r], where r is the rank of
  183. * the input tensor. Negative value means counting dimensions from the back. When axis = 0, the shape of
  184. * the output tensor is (1, (d_0 X d_1 ... d_n), where the shape of the input tensor is (d_0, d_1, ... d_n).
  185. *@par Third-party framework compatibility
  186. * Compatible with TensorFlow / ONNX operator Flatten.
  187. */
  188. REG_OP(Flatten)
  189. .INPUT(x, TensorType({DT_INT8, DT_INT16, DT_INT32, DT_INT64,
  190. DT_UINT8, DT_UINT16, DT_UINT32, DT_UINT64,
  191. DT_FLOAT, DT_FLOAT16}))
  192. .OUTPUT(y, TensorType({DT_INT8, DT_INT16, DT_INT32, DT_INT64,
  193. DT_UINT8, DT_UINT16, DT_UINT32, DT_UINT64,
  194. DT_FLOAT, DT_FLOAT16}))
  195. .ATTR(axis, Int, 1)
  196. .OP_END_FACTORY_REG(Flatten)
  197. /**
  198. *@brief Permutes and crops the input tensor . \n
  199. *@par Inputs:
  200. * Three inputs, including:
  201. *@li x: A 5D Tensor of type float16 or int8 or uint8.
  202. *@li block_shape: A 1D list or tuple of int32 or int64.
  203. *@li crops: A 2D list or tuple of int32 or int64. Specifies the amount to
  204. *crop from start and end dimensions after permutation . \n
  205. *@par Outputs:
  206. *y: A Tensor has the same type as input "x" . \n
  207. *@par Third-party framework compatibility
  208. * Compatible with the TensorFlow operator BatchToSpaceND.
  209. */
  210. REG_OP(BatchToSpaceND)
  211. .INPUT(x, TensorType::BasicType())
  212. .INPUT(block_shape, TensorType::IndexNumberType())
  213. .INPUT(crops, TensorType::IndexNumberType())
  214. .OUTPUT(y, TensorType::BasicType())
  215. .OP_END_FACTORY_REG(BatchToSpaceND)
  216. /**
  217. *@brief Permutes and crops the input tensor . \n
  218. *@par Inputs:
  219. * One input:
  220. *x: A 5D Tensor of type float16 or int8 or uint8. \n
  221. *@par Attributes:
  222. *@li block_shape: A required 1D list or tuple of int32 or int64.
  223. *@li crops: A required 2D list or tuple of int32 or int64. Specifies the amount to crop
  224. * from the start and end dimensions after permutation . \n
  225. *@par Outputs:
  226. *y: A Tensor has the same type as input "x".
  227. *@par Third-party framework compatibility
  228. * Compatible with the TensorFlow operator BatchToSpaceND.
  229. *
  230. * @par Restrictions:
  231. * Warning: THIS FUNCTION IS DEPRECATED. Please use BatchToSpaceND instead.
  232. */
  233. REG_OP(BatchToSpaceNDD)
  234. .INPUT(x, TensorType::BasicType())
  235. .OUTPUT(y, TensorType::BasicType())
  236. .REQUIRED_ATTR(block_shape, ListInt)
  237. .REQUIRED_ATTR(crops, ListInt)
  238. .OP_END_FACTORY_REG(BatchToSpaceNDD)
  239. /**
  240. *@brief Pads and permutes the input tensor . \n
  241. *@par Inputs:
  242. * Three inputs, including:
  243. *@li x: A 5D Tensor of type float16 or float32.
  244. *@li block_shape: A 1D list or tuple of int32 or int64.
  245. *@li paddings: A 2D list or tuple of int32 or int64. Specifies the padding for the start and end dimensions after permutation . \n
  246. *@par Outputs:
  247. *y: A Tensor has the same type as input "x" . \n
  248. *@par Third-party framework compatibility
  249. * Compatible with the TensorFlow operator SpaceToBatchND.
  250. */
  251. REG_OP(SpaceToBatchND)
  252. .INPUT(x, TensorType::BasicType())
  253. .INPUT(block_shape, TensorType::IndexNumberType())
  254. .INPUT(paddings, TensorType::IndexNumberType())
  255. .OUTPUT(y, TensorType::BasicType())
  256. .OP_END_FACTORY_REG(SpaceToBatchND)
  257. /**
  258. *@brief Pads and permutes the input tensor . \n
  259. *@par Inputs:
  260. * One input:
  261. *x: A 5D Tensor of type float16 or float32. \n
  262. *@par Attributes:
  263. *@li block_shape: A required 1D list or tuple of int32 or int64.
  264. *@li paddings: A required 2D list or tuple of int32 or int64. Specifies the padding for the start and end dimensions after permutation . \n
  265. *@par Outputs:
  266. *y: A Tensor has the same type as input "x" . \n
  267. *@par Third-party framework compatibility
  268. * Compatible with the TensorFlow operator SpaceToBatchND.
  269. *
  270. * @par Restrictions:
  271. * Warning: THIS FUNCTION IS DEPRECATED. Please use SpaceToBatchND instead.
  272. */
  273. REG_OP(SpaceToBatchNDD)
  274. .INPUT(x, TensorType::BasicType())
  275. .OUTPUT(y, TensorType::BasicType())
  276. .REQUIRED_ATTR(block_shape, ListInt)
  277. .REQUIRED_ATTR(paddings, ListInt)
  278. .OP_END_FACTORY_REG(SpaceToBatchNDD)
  279. /**
  280. *@brief Outputs a copy of the input tensor where values from the "height" and
  281. * "width" dimensions are moved to the "depth" dimension . \n
  282. *@par Inputs:
  283. *x: An NHWC Tensor. Must be one of the following types:
  284. * float16, float32, double, int64, int32, uint8, uint16, uint32, uint64, int8,
  285. * int16, complex64, complex128, qint8, quint8, qint16, quint16, qint32.
  286. *@par Attributes:
  287. *@li block_size: A required int, specifying the input block size.
  288. *@li data_format: An optional string, specifying the data format. Defaults to
  289. * "NHWC" . \n
  290. *@par Outputs:
  291. *y: A Tensor. Has the same type as input "x".
  292. *@par Third-party framework compatibility
  293. * Compatible with the TensorFlow operator SpaceToDepth.
  294. */
  295. REG_OP(SpaceToDepth)
  296. .INPUT(x, TensorType::BasicType())
  297. .OUTPUT(y, TensorType::BasicType())
  298. .REQUIRED_ATTR(block_size, Int)
  299. .ATTR(data_format, String, "NHWC")
  300. .OP_END_FACTORY_REG(SpaceToDepth)
  301. /**
  302. *@brief Rearranges data from depth into blocks of spatial data . \n
  303. *@par Inputs:
  304. *x: A Tensor. Must be one of the following types: float16, float32, double, int32, uint8,
  305. * int16, int8, complex64, int64, qint8, quint8, qint32, qint16, quint16, uint16,
  306. * complex128, uint32, uint64
  307. *@par Attributes:
  308. *Three attributes, including:
  309. * @li block_size: An int >= 2, specifying the size of the spatial block.
  310. * @li mode: An optional string, specifying the mode. Defaults to "DCR".
  311. * @li data_format: An optional string, specifying the data format. Defaults to "NHWC" . \n
  312. *@par Outputs:
  313. *y: A Tensor of the same type as "x" . \n
  314. *@par Third-party framework compatibility:
  315. * Compatible with TensorFlow operator DepthToSpace.
  316. */
  317. REG_OP(DepthToSpace)
  318. .INPUT(x, TensorType::BasicType())
  319. .OUTPUT(y, TensorType::BasicType())
  320. .REQUIRED_ATTR(block_size, Int)
  321. .ATTR(mode, String, "DCR")
  322. .ATTR(data_format, String, "NHWC")
  323. .OP_END_FACTORY_REG(DepthToSpace)
  324. /**
  325. *@brief Permutes data into spatial data blocks and then prunes them . \n
  326. *@par Inputs:
  327. *@li x: A 4D Tensor with format. Must set the format, supported format list ["NCHW, NHWC"]
  328. *@li crops: A 1D list or tuple of int32 or int64 . \n
  329. *Must be one of the following types: float16, float32
  330. *@par Attributes:
  331. *block_size: A required int8, int16, int32, or int64. No default value . \n
  332. *@par Outputs:
  333. *y: A 4D Tensor with format NHWC,
  334. * of type float16 or float32 . \n
  335. *@attention Constraints:
  336. *@li The size of the first dimension of input "x" must be divisible by (block_size * block_size).
  337. *@li "crops" is a 4Dshape [batch, height, width, depth], height = height_pad - crop_top - crop_bottom,
  338. *width = width_pad - crop_left - crop_right.
  339. *@li block_size > 2
  340. *@par Third-party framework compatibility
  341. * Compatible with the TensorFlow operator BatchToSpace.
  342. */
  343. REG_OP(BatchToSpace)
  344. .INPUT(x, TensorType::BasicType())
  345. .INPUT(crops, TensorType::IndexNumberType())
  346. .OUTPUT(y, TensorType::BasicType())
  347. .REQUIRED_ATTR(block_size, Int)
  348. .OP_END_FACTORY_REG(BatchToSpace)
  349. /**
  350. *@brief Rearrange the batch (permutes) data into spatial data blocks, and then crop them . \n
  351. *@par Inputs:
  352. * One input:
  353. *x: An Tensor of shape [batch*block_size*block_size, height_pad/block_size, width_pad/block_size, depth].
  354. *The batch size of the input tensor must be divisible by (block size * block size).
  355. *Must be one of the following types: float16, float32, double, int64, int32, uint8, uint16, uint32, uint64,
  356. *int8, int16, complex64, complex128, qint8, quint8, qint16, quint16, qint32 . \n
  357. *@par Attributes:
  358. *@li block_size: Must be one of the following types: `int32`, `int64`.
  359. *@li crops: An Tensor. Must be one of the following types: int32, Int64.
  360. *2D tensor with non negative integer of shape [2, 2]. It specifies how many
  361. *elements are clipped from the intermediate result of spatial dimension . \n
  362. *@par Outputs:
  363. *y: A Tensor. Has the same type and format as input "x" . \n
  364. *@attention Constraints:
  365. *@li The size of the first dimension of input "x" must be divisible by (block_size * block_size).
  366. *@li "crops" is a 2D tensor of non-negative integers with shape (2, 2).
  367. *@li block_size > 2
  368. *@par Third-party framework compatibility
  369. * Compatible with the TensorFlow operator BatchToSpace.
  370. *
  371. * @par Restrictions:
  372. * Warning: THIS FUNCTION IS DEPRECATED. Please use BatchToSpace instead.
  373. */
  374. REG_OP(BatchToSpaceD)
  375. .INPUT(x, TensorType::BasicType())
  376. .OUTPUT(y, TensorType::BasicType())
  377. .REQUIRED_ATTR(block_size, Int)
  378. .REQUIRED_ATTR(crops, ListInt)
  379. .OP_END_FACTORY_REG(BatchToSpaceD)
  380. /**
  381. *@brief Outputs a copy of the input tensor where values from the "height" and
  382. * "width" dimensions are padded and rearranged to the "batch" dimension . \n
  383. *@par Inputs:
  384. * Two inputs, including:
  385. *@li x: An 4D Tensor. Must be one of the following types:
  386. * float16, float32, double, int64, int32, uint8, uint16, uint32, uint64, int8,
  387. * int16, complex64, complex128, qint8, quint8, qint16, quint16, qint32.
  388. * Must set the format, supported format list ["NCHW, NHWC"]
  389. *@li paddings: A 2D tensor of type int, specifying the input . \n
  390. *@par Attributes:
  391. *block_size: A required int, specifying the input block size . \n
  392. *@par Outputs:
  393. *y: A Tensor. Has the same type as input "x".
  394. *@par Third-party framework compatibility
  395. * Compatible with the TensorFlow operator SpaceToBatch.
  396. */
  397. REG_OP(SpaceToBatch)
  398. .INPUT(x, TensorType::BasicType())
  399. .INPUT(paddings, TensorType::IndexNumberType())
  400. .OUTPUT(y, TensorType::BasicType())
  401. .REQUIRED_ATTR(block_size, Int)
  402. .OP_END_FACTORY_REG(SpaceToBatch)
  403. /**
  404. *@brief Outputs a copy of the input tensor where values from the "height" and "width" dimensions are padded and rearranged to the "batch" dimension . \n
  405. *@par Inputs:
  406. *x: An NHWC Tensor. Must be one of the following types: float16, float32, double, int64, int32, uint8, uint16, uint32, uint64, int8, int16, complex64, complex128, qint8, quint8, qint16, quint16, qint32.
  407. *@par Attributes:
  408. *@li block_size: A required int, specifying the input block size.
  409. *@li paddings: A 2D tensor. All data types are supported . \n
  410. *@par Outputs:
  411. *y: A Tensor. Has the same type as input "x".
  412. *@par Third-party framework compatibility
  413. *@ Compatible with the TensorFlow operator SpaceToBatch.
  414. *
  415. * @par Restrictions:
  416. * Warning: THIS FUNCTION IS DEPRECATED. Please use SpaceToBatch instead.
  417. */
  418. REG_OP(SpaceToBatchD)
  419. .INPUT(x, TensorType::BasicType())
  420. .OUTPUT(y, TensorType::BasicType())
  421. .REQUIRED_ATTR(block_size, Int)
  422. .REQUIRED_ATTR(paddings, ListInt)
  423. .OP_END_FACTORY_REG(SpaceToBatchD)
  424. /**
  425. * @brief Unpacks the given dimension of a rank-R Tensor "x" into rank-(R-1)
  426. * tensors . \n
  427. * @par Inputs:
  428. * x: A rank-R tensor (R > 0) of type BasicType. \n
  429. * @par Attributes:
  430. * @li num: A required int, specifying the number of tensors to be unpacked to.
  431. * Defaults to "None".
  432. * @li axis: An optional int, specifying the axis to unpack along. The value range
  433. * is [-R, R) . \n
  434. * @par Outputs:
  435. * y: Dynamic output. The list of Tensor objects unpacked from "x", of type BasicType . \n
  436. * @attention Constraints:
  437. * @li If "num" is not specified, it is inferred from the shape of "x".
  438. * @li For the ND format, "axis" is in the range [-R, R). \n
  439. * @par Third-party framework compatibility
  440. * Compatible with the TensorFlow operator Unpack.
  441. */
  442. REG_OP(Unpack)
  443. .INPUT(x, TensorType::BasicType())
  444. .DYNAMIC_OUTPUT(y, TensorType::BasicType())
  445. .REQUIRED_ATTR(num, Int)
  446. .ATTR(axis, Int, 0)
  447. .OP_END_FACTORY_REG(Unpack)
  448. /**
  449. * @brief Extract "patches" from "images" and stacks them in the "depth"
  450. * dimension of the output . \n
  451. * @par Inputs:
  452. * x: A 4D Tensor with shape [batch, in_rows, in_cols, depth], Must be one of the
  453. * following types:float32, double, int32, uint8, int16, int8, int64, uint16,
  454. * float16, uint32, uint64. The inputs must have data_format with one of follows:
  455. * NHWC, NCHW.
  456. * @par Attributes:
  457. * @li ksizes: A required list or tuple. The size of the sliding window for each
  458. * dimension of images.
  459. * @li strides: A required list or tuple. How far the centers of two consecutive
  460. * patches are in the images. Must be: [1, stride_rows, stride_cols, 1].
  461. * @li rates: A required list or tuple. Must be: [1, rate_rows, rate_cols, 1].
  462. * This is the input stride, specifying how far two consecutive patch
  463. * samples are in the input. Equivalent to extracting patches
  464. * with patch_sizes_eff = patch_sizes + (patch_sizes - 1) *
  465. * (rates - 1), followed by subsampling them spatially by a factor of rates.
  466. * This is equivalent to rate in dilated (a.k.a. Atrous) convolutions.
  467. * @li padding: A required string. The type of padding algorithm to use,
  468. support "SAME" or "VALID". \n
  469. * @par Outputs:
  470. * y: A 4D Tensor with shape [batch, out_rows, out_cols, ksize_rows *
  471. * ksize_cols * depth] containing image patches with size ksize_rows x ksize_cols
  472. * x depth vectorized in the "depth" dimension. Note "out_rows" and "out_cols"
  473. * are the dimensions of the output patches . \n
  474. * @attention Constraints:
  475. * "ksizes", "strides" and "rates" are lists of integers . \n
  476. * @par Third-party framework compatibility
  477. * Compatible with the TensorFlow operator ExtractImagePatches.
  478. */
  479. REG_OP(ExtractImagePatches)
  480. .INPUT(x, TensorType::RealNumberType())
  481. .OUTPUT(y, TensorType::RealNumberType())
  482. .REQUIRED_ATTR(ksizes, ListInt)
  483. .REQUIRED_ATTR(strides, ListInt)
  484. .REQUIRED_ATTR(rates, ListInt)
  485. .REQUIRED_ATTR(padding, String)
  486. .OP_END_FACTORY_REG(ExtractImagePatches)
  487. /**
  488. * @brief Extract "patches" from "input" and put them in the "depth"
  489. * dimension of the output . \n
  490. * @par Inputs:
  491. * x: A 5D Tensor with shape [batch, in_planes, in_rows, in_cols, depth] . \n
  492. * The inputs must have data_format with one of follows: NDHWC, NCDHW. \n
  493. * @par Attributes:
  494. * @li ksizes: A required list or tuple. The size of the sliding window for each
  495. * dimension of "x".
  496. * @li strides: A required list or tuple. How far the centers of two consecutive
  497. * patches are in "x". Must be: [1, stride_planes, stride_rows, stride_cols, 1].
  498. * @li padding: A required string. The type of padding algorithm to use ,
  499. * support "SAME" or "VALID" . \n
  500. * @par Outputs:
  501. * Output: A 5D Tensor with shape [batch, out_planes, out_rows, out_cols, ksize_planes *
  502. * ksize_rows * ksize_cols * depth] containing patches with size (ksize_rows * ksize_cols
  503. * * depth) vectorized in the "depth" dimension. Note "out_planes", "out_rows" and "out_cols"
  504. * are the dimensions of the output patches . \n
  505. * @attention Constraints:
  506. * "ksizes" and "strides" are lists of integers.
  507. * @par Third-party framework compatibility
  508. * Compatible with the TensorFlow operator ExtractVolumePatches.
  509. */
  510. REG_OP(ExtractVolumePatches)
  511. .INPUT(x, TensorType::REALNUMBERTYPE())
  512. .OUTPUT(y, TensorType::REALNUMBERTYPE())
  513. .REQUIRED_ATTR(ksizes, ListInt)
  514. .REQUIRED_ATTR(strides, ListInt)
  515. .REQUIRED_ATTR(padding, String)
  516. .OP_END_FACTORY_REG(ExtractVolumePatches)
  517. /**
  518. *@brief Confuse reshape and transpose . \n
  519. *@par Inputs:
  520. *x: A Tensor. Must be one of the following types: float16, float32, int8, int16, int32, int64, uint8, uint16, uint32, uint64 . \n
  521. *@par Attributes:
  522. *@li perm: A permutation of the dimensions of "x".
  523. *@li shape: The shape of the input.
  524. *@li transpose_first: If True, the transpose is first, otherwise the reshape is first . \n
  525. *@par Outputs:
  526. *y: A Tensor. Has the same type as "x".
  527. *
  528. * @par Restrictions:
  529. * Warning: THIS FUNCTION IS DEPRECATED. Please use ConfusionTranspose instead.
  530. */
  531. REG_OP(ConfusionTransposeD)
  532. .INPUT(x, TensorType({DT_INT8, DT_INT16, DT_INT32, DT_INT64, DT_UINT8,
  533. DT_UINT16, DT_UINT32, DT_UINT64, DT_FLOAT16, DT_FLOAT}))
  534. .OUTPUT(y, TensorType({DT_INT8, DT_INT16, DT_INT32, DT_INT64, DT_UINT8,
  535. DT_UINT16, DT_UINT32, DT_UINT64, DT_FLOAT16, DT_FLOAT}))
  536. .REQUIRED_ATTR(perm, ListInt)
  537. .REQUIRED_ATTR(shape, ListInt)
  538. .REQUIRED_ATTR(transpose_first, Bool)
  539. .OP_END_FACTORY_REG(ConfusionTransposeD)
  540. /**
  541. *@brief Confuse reshape and transpose . \n
  542. *@par Inputs:
  543. *@li x: A Tensor. Must be one of the following types: float16, float32, int8, int16, int32, int64, uint8, uint16, uint32, uint64.
  544. *@li shape: The shape of the input . \n
  545. *@par Attributes:
  546. *@li perm: A permutation of the dimensions of "x".
  547. *@li transpose_first: If True, the transpose is first, otherwise the reshape is first . \n
  548. *@par Outputs:
  549. *y: A Tensor. Has the same type as "x".
  550. *@par Restrictions:
  551. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  552. */
  553. REG_OP(ConfusionTranspose)
  554. .INPUT(x, TensorType::BasicType())
  555. .INPUT(shape, TensorType::IndexNumberType())
  556. .OUTPUT(y, TensorType::BasicType())
  557. .REQUIRED_ATTR(perm, ListInt)
  558. .REQUIRED_ATTR(transpose_first, Bool)
  559. .OP_END_FACTORY_REG(ConfusionTranspose)
  560. /**
  561. *@brief Flattens the input tensor to one-dimensional . \n
  562. *@par Inputs:
  563. *x: An ND tensor. All data types are supported . \n
  564. *@par Attributes:
  565. *@li axis: An optional int32, specifying the first axis to flatten. All preceding axes are retained in the output. Defaults to "1".
  566. *@li end_axis: An optional int32, specifying the last axis to flatten. All following axes are retained in the output. Defaults to "-1" . \n
  567. *@par Outputs:
  568. *y: The flattened ND tensor. All data types are supported . \n
  569. *@attention Constraints:
  570. * "axis" and "end_axis" must be within the dimension range of the input. This operator cannot be directly called by the acllopExecute API.
  571. *@par Third-party framework compatibility
  572. * Compatible with the Caffe operator Flatten.
  573. */
  574. REG_OP(FlattenV2)
  575. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8, DT_UINT8, DT_INT16, DT_UINT16,
  576. DT_INT32, DT_UINT32, DT_INT64, DT_UINT64}))
  577. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8, DT_UINT8, DT_INT16, DT_UINT16,
  578. DT_INT32, DT_UINT32, DT_INT64, DT_UINT64}))
  579. .ATTR(axis, Int, 1)
  580. .ATTR(end_axis, Int, -1)
  581. .OP_END_FACTORY_REG(FlattenV2)
  582. /**
  583. *@brief Compress large weight to small one. Usually inserted before Conv2d.
  584. *
  585. *@par Inputs:
  586. *weight: A tensor before compress. Must be one of the following types: DT_INT8, DT_FLOAT16
  587. *
  588. *@par Outputs:
  589. *@li weight_compress: A tensor after compress. Must be one of the following types: DT_INT8, DT_FLOAT16
  590. *@li compress_index: A tensor. Must be one of the following types: DT_INT8
  591. *
  592. *@par Attributes:
  593. *compress_parameters: A required int8, specifying the compressing block.
  594. *
  595. *@par Restrictions:
  596. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  597. */
  598. REG_OP(Compress)
  599. .INPUT(weight, TensorType({DT_INT8, DT_FLOAT16}))
  600. .OUTPUT(weight_compress, TensorType({DT_INT8, DT_FLOAT16}))
  601. .OUTPUT(compress_index, TensorType({DT_INT8}))
  602. .REQUIRED_ATTR(compress_parameters, ListInt)
  603. .OP_END_FACTORY_REG(Compress)
  604. /**
  605. *@brief Compress large weight to small one. Usually inserted before FullyConnection.
  606. *
  607. *@par Inputs:
  608. *weight: A tensor before compress. Must be one of the following types: DT_INT8, DT_FLOAT16
  609. *
  610. *@par Outputs:
  611. *@li weight_compress: A tensor after compress. Must be one of the following types: DT_INT8, DT_FLOAT16
  612. *@li compress_index: A tensor. Must be one of the following types: DT_INT8
  613. *
  614. *@par Attributes:
  615. *compress_parameters: A required int8, specifying the compressing block.
  616. *
  617. *@par Restrictions:
  618. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  619. */
  620. REG_OP(CompressFcOp)
  621. .INPUT(weight, TensorType({DT_INT8}))
  622. .OUTPUT(weight_compress, TensorType({DT_INT8}))
  623. .OUTPUT(compress_index, TensorType({DT_INT8}))
  624. .REQUIRED_ATTR(compress_parameters, ListInt)
  625. .OP_END_FACTORY_REG(CompressFcOp)
  626. /**
  627. *@brief Performs Col2im for each batch entry. \n
  628. *@par Inputs:
  629. *@li x: The Col Tensor. 4-D, shape: `(n, c, kernel_h*kernel_w, ho*wo)`.
  630. where ho/wo is do = (output_d + 2*padding_d - dilation_d*(kernel_d - 1) - 1)//stride_d + 1.
  631. *@li output_size: The img shape Tensor. 1-D, shape:`(2)`, value: (output_h, output_w). \n
  632. *@par Outputs:
  633. *y: The img Tensor. 4-D, shape: `(n, c, output_h, output_w)`. \n
  634. *@par Attributes:
  635. *@li kernel_shape: ListInt, value: `(kernel_h, kernel_w)`, the shape of kernel in convolution.
  636. *@li dilation: ListInt, value: `(dilation_h, dilation_w)`, the dilation in convolution.
  637. *@li padding: ListInt, value: `(padding_h, padding_w)`, the dilation in convolution.
  638. *@li stride: ListInt, value: `(stride_h, stride_w)`, the dilation in convolution. \n
  639. *@par Third-party framework compatibility
  640. * Compatible with Pytorch col2im/im2col_backward operator.
  641. */
  642. REG_OP(Col2im)
  643. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16}))
  644. .INPUT(output_size, TensorType({DT_INT32, DT_INT32}))
  645. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16}))
  646. .REQUIRED_ATTR(kernel_size, ListInt)
  647. .REQUIRED_ATTR(dilation, ListInt)
  648. .REQUIRED_ATTR(padding, ListInt)
  649. .REQUIRED_ATTR(stride, ListInt)
  650. .OP_END_FACTORY_REG(Col2im)
  651. /**
  652. * @brief Performs Im2col for each batch entry. \n
  653. * @par Inputs:
  654. * x: A 4D Tensor with shape [batch, in_rows, in_cols, depth], Must be one of the
  655. * following types:float32, int8, float16. The inputs must have data_format with
  656. * one of follows:NHWC, NCHW.
  657. * @par Attributes:
  658. * @li ksizes: A required list or tuple. The size of the sliding window for each
  659. * dimension of images.
  660. * @li strides: A optional list or tuple. How far the centers of two consecutive
  661. * patches are in the images. Defaults to "{1}".
  662. * @li dilations: A optional list or tuple. Defaults to "{1}".
  663. * This is the input stride, specifying how far two consecutive patch
  664. * samples are in the input. Equivalent to extracting patches
  665. * with patch_sizes_eff = patch_sizes + (patch_sizes - 1) *
  666. * (dilations - 1), followed by subsampling them spatially by a factor of dilations.
  667. * This is equivalent to rate in dilated (a.k.a. Atrous) convolutions.
  668. * @li padding_mode: A optional String. The type of padding algorithm to use,
  669. * support "SAME", "VALID", "CALCULATED". Among the three modes, only the "CALCULATED"
  670. * means to use the pads below. Defaults to "CALCULATED".
  671. * @li pads: A optional list or tuple. The pad distance. Defaults to "{0}". \n
  672. * @par Outputs:
  673. * y: A 4D Tensor with shape [batch, out_rows, out_cols, ksize_rows *
  674. * ksize_cols * depth] containing image patches with size ksize_rows x ksize_cols
  675. * x depth vectorized in the "depth" dimension. Note "out_rows" and "out_cols"
  676. * are the dimensions of the output patches . \n
  677. * @attention Constraints:
  678. * "ksizes", "strides", "dilations" and "pads" are lists of integers . \n
  679. * @par Third-party framework compatibility
  680. * Compatible with Pytorch Im2col operator.
  681. */
  682. REG_OP(Im2col)
  683. .INPUT(x, TensorType::RealNumberType())
  684. .OUTPUT(y, TensorType::RealNumberType())
  685. .REQUIRED_ATTR(ksizes, ListInt)
  686. .ATTR(strides, ListInt, {1})
  687. .ATTR(dilations, ListInt, {1})
  688. .ATTR(padding_mode, String, "CALCULATED")
  689. .ATTR(pads, ListInt, {0})
  690. .OP_END_FACTORY_REG(Im2col)
  691. /**
  692. *@brief Generates a 2D or 3D flow field (sampling grid), given a batch of affine
  693. matrices theta. \n
  694. *@par Inputs:
  695. *Input theta must be float16 or float, output_size must be int32 type.Inputs
  696. include:
  697. *@li theta: input batch of affine matrices with shape (N,2,3) for 2D or (N,3,4)
  698. for 3D
  699. *@li output_size: the target output image size. (N×C×H×W for 2D or N×C×D×H×W for
  700. 3D) Example: torch.Size((32, 3, 24, 24)) . \n
  701. *@par Attributes:
  702. *align_corners: if True, consider -1 and 1 to refer to the centers of the corner
  703. pixels rather than the image corners.Refer to grid_sample() for a more complete
  704. description. A grid generated by affine_grid() should be passed to grid_sample()
  705. with the same setting for this option. Default: False \n
  706. *@par Outputs:
  707. *@li y: A 2-D integer tensor of shape [M] representing the
  708. selected indices from the boxes tensor, where M <= max_output_size. \n
  709. *@attention Constraints:
  710. *Input theta must be float16 or float, output_size must be int32 type .
  711. The current implementation of AffineGrid operator AiCore adopts
  712. BatchMatMul's FP16 fusion operator scheme, and the accuracy will
  713. decrease when the theta range exceeds [-10,10].If the model requires
  714. high accuracy of AffineGrid, it is recommended to use AICPU. \n
  715. *@par Third-party framework compatibility
  716. *Compatible with Pytorch affine_grid operator.
  717. */
  718. REG_OP(AffineGrid)
  719. .INPUT(theta, TensorType({DT_FLOAT16, DT_FLOAT}))
  720. .INPUT(output_size, TensorType({DT_INT32}))
  721. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  722. .ATTR(align_corners, Bool, false)
  723. .OP_END_FACTORY_REG(AffineGrid)
  724. /**
  725. *@brief Make memory of a view be contiguous. \n
  726. *@par Inputs:
  727. *Four inputs, including:
  728. *@li x: The input tensor.
  729. *@li size: The shape of output tensor.
  730. *@li stride: The stride of output tensor.
  731. *@li storage_offset: The offset in the underlying storage of the output tensor. \n
  732. *@par Outputs:
  733. *y: A Tensor. Has the same type as "x" . \n
  734. *@par Third-party framework compatibility
  735. *Compatible with the pytorch operator as_strided.
  736. */
  737. REG_OP(AsStrided)
  738. .INPUT(x, TensorType::BasicType())
  739. .INPUT(size, TensorType::IndexNumberType())
  740. .INPUT(stride, TensorType::IndexNumberType())
  741. .INPUT(storage_offset, TensorType::IndexNumberType())
  742. .OUTPUT(y, TensorType::BasicType())
  743. .OP_END_FACTORY_REG(AsStrided)
  744. /**
  745. *@brief This transform extracts n-grams from the input sequence and save them as a
  746. vector. \n
  747. *@par Inputs:
  748. *@li input: can be either a 1-D or 2-D tensor for n-gram extraction, It is ether string UTF-8 or int32/int64 . \n
  749. *@par Attributes:
  750. *@li max_gram_length : int (required)
  751. *Maximum n-gram length. If this value is 3, 3-grams will be used to generate the output .
  752. *@li max_skip_count : int (required)
  753. *Maximum number of items (integers/strings) to be skipped when constructing an n-gram from X.
  754. If max_skip_count=1, min_gram_length=2, max_gram_length=3, this operator may generate 2-grams
  755. with skip_count=0 and skip_count=1, and 3-grams with skip_count=0 and skip_count=1.
  756. *@li min_gram_length : int (required)
  757. *Minimum n-gram length. If this value is 2 and max_gram_length is 3, output may contain counts of
  758. 2-grams and 3-grams.
  759. *@li mode : string (required)
  760. *The weighting criteria. It can be one of "TF" (term frequency), "IDF" (inverse document frequency),
  761. and "TFIDF" (the combination of TF and IDF).
  762. *@li ngram_counts : list of ints (required)
  763. *The starting indexes of 1-grams, 2-grams, and so on in pool. It is useful when determining the boundary
  764. between two consecutive collections of n-grams. For example, if ngram_counts is [0, 17, 36],
  765. the first index (zero-based) of 1-gram/2-gram/3-gram in pool are 0/17/36. This format is essentially identical
  766. to CSR (or CSC) sparse matrix format, and we choose to use this due to its popularity.
  767. *@li ngram_indexes : list of ints (required)
  768. *list of int64s (type: AttributeProto::INTS). This list is parallel to the specified 'pool_*' attribute. The i-th element
  769. in ngram_indexes indicate the coordinate of the i-th n-gram in the output tensor.
  770. *@li pool_int64s : list of ints
  771. *List of int64 n-grams learned from the training set. Either this or pool_strings attributes must be present but not both.
  772. It's an 1-D tensor starting with the collections of all 1-grams and ending with the collections of n-grams. The i-th element
  773. in pool stores the n-gram that should be mapped to coordinate ngram_indexes[i] in the output vector.
  774. *@li pool_strings : list of strings
  775. *List of strings n-grams learned from the training set. Either this or pool_int64s attributes must be present but not both.
  776. It's an 1-D tensor starting with the collections of all 1-grams and ending with the collections of n-grams. The i-th element
  777. in pool stores the n-gram that should be mapped to coordinate ngram_indexes[i] in the output vector.
  778. *@li weights : list of floats
  779. *list of floats. This attribute stores the weight of each n-gram in pool. The i-th element in weights is the weight of
  780. the i-th n-gram in pool. Its length equals to the size of ngram_indexes. By default, weights is an all-one tensor.This attribute
  781. is used when mode is "IDF" or "TFIDF" to scale the associated word counts. \n
  782. *@par Outputs:
  783. *@li output: tensor(float)
  784. *For 1-D input, output is the n-gram representation of that input. For 2-D input, the output is also a 2-D tensor
  785. whose i-th row is the n-gram representation of the i-th input row. More specifically, if input shape is [C], the corresponding
  786. output shape would be [max(ngram_indexes) + 1]. If input shape is [N, C], this operator produces a [N, max(ngram_indexes) + 1]-tensor. \n
  787. *@attention Constraints:
  788. *@li input can be either a 1-D or 2-D tensor, shape is [C] or [N, C].
  789. *@li max(ngram_indexes) + 1 == len(weights), len(y) == len(weights).
  790. *@li ngram_counts and pool(pool_int64s or pool_strings) must match.
  791. *@li either pool_strings or pool_int64s attributes must be present but not both.
  792. */
  793. REG_OP(TfIdfVectorizer)
  794. .INPUT(input, TensorType({DT_INT32, DT_INT64, DT_STRING}))
  795. .OUTPUT(output, TensorType({DT_FLOAT}))
  796. .REQUIRED_ATTR(max_gram_length, Int)
  797. .REQUIRED_ATTR(max_skip_count, Int)
  798. .REQUIRED_ATTR(min_gram_length, Int)
  799. .REQUIRED_ATTR(mode, String)
  800. .REQUIRED_ATTR(ngram_counts, ListInt)
  801. .REQUIRED_ATTR(ngram_indexes, ListInt)
  802. .ATTR(pool_int64s, ListInt, {})
  803. .ATTR(pool_strings, ListString, {})
  804. .ATTR(weights, ListFloat, {})
  805. .OP_END_FACTORY_REG(TfIdfVectorizer)
  806. } // namespace ge
  807. #endif // OPS_BUILT_IN_OP_PROTO_INC_TRANSFORMATION_OPS_H_

图引擎模块(GE)是MindSpore的一个子模块,其代码由C++实现,位于前端模块ME和底层硬件之间,起到承接作用。图引擎模块以ME下发的图作为输入,然后进行一系列的深度图优化操作,最后输出一张可以在底层硬件上高效运行的图。GE针对昇腾AI处理器的硬件结构特点,做了特定的优化工作,以此来充分发挥出昇腾AI处理器的强大算力。在进行模型训练/推理时,GE会被自动调用而用户并不感知。GE主要由GE API和GE Core两部分组成,详细的架构图如下所示