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

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