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

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
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
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
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. /**
  2. * Copyright 2019-2020 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef GE_OP_TRANSFORMATION_OPS_H
  17. #define GE_OP_TRANSFORMATION_OPS_H
  18. #include "graph/operator_reg.h"
  19. namespace ge {
  20. /**
  21. *@brief Convert tensor format from HWCN to C1HWNCoC0.
  22. *@par Inputs:
  23. *x: A Tensor. Must be 4D Tensor of type float16, float32, int32, uint16, with format HWCN.
  24. *@par Outputs:
  25. *y: A 6D Tensor. Has the same type as "x", with format C1HWNCoC0.
  26. */
  27. REG_OP(DepthwiseWeight4DTo6D)
  28. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32, DT_UINT16}))
  29. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32, DT_UINT16}))
  30. .OP_END_FACTORY_REG(DepthwiseWeight4DTo6D)
  31. /**
  32. *@brief Convert tensor format from C1HWNCoC0 to HWCN.
  33. *@par Inputs:
  34. *x: A Tensor. Must be 6D Tensor of type float16, float32, int32, uint16, with format C1HWNCoC0.
  35. *@par Attributes:
  36. *channel_size: An optional int, specifying the channel size of 4D Tensor with format HWCN.
  37. *@par Outputs:
  38. *y: A 4D Tensor. Has the same type as "x", with format HWCN.
  39. */
  40. REG_OP(DepthwiseWeight6DTo4D)
  41. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32, DT_UINT16}))
  42. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32, DT_UINT16}))
  43. .ATTR(channel_size, Int, 16)
  44. .OP_END_FACTORY_REG(DepthwiseWeight6DTo4D)
  45. /**
  46. *@brief Permutes the dimensions according to perm.\n
  47. The returned tensor's dimension i will correspond to the input dimension perm[i].
  48. *@par Inputs:
  49. *x: A Tensor. Must be one of the following types: float16, float32, int8, int16, int32, int64, uint8, uint16, uint32, uint64.
  50. *@par Attributes:
  51. *perm: A permutation of the dimensions of "x".
  52. *@par Outputs:
  53. *y: A Tensor. Has the same type as "x".
  54. */
  55. REG_OP(TransposeD)
  56. .INPUT(x, TensorType({DT_INT8, DT_INT16, DT_INT32, DT_INT64, DT_UINT8,
  57. DT_UINT16, DT_UINT32, DT_UINT64, DT_FLOAT16, DT_FLOAT}))
  58. .OUTPUT(y, TensorType({DT_INT8, DT_INT16, DT_INT32, DT_INT64, DT_UINT8,
  59. DT_UINT16, DT_UINT32, DT_UINT64, DT_FLOAT16, DT_FLOAT}))
  60. .REQUIRED_ATTR(perm, ListInt)
  61. .OP_END_FACTORY_REG(TransposeD)
  62. /**
  63. *@brief Permutes the dimensions according to perm.\n
  64. The returned tensor's dimension i will correspond to the input dimension perm[i].
  65. *@par Inputs:
  66. *Two inputs, including:
  67. *@li x: A Tensor. Must be one of the following types: float16, float32, int8, int16, int32, int64, uint8, uint16, uint32, uint64.
  68. *@li perm: A Tensor of type int32 or int64. A permutation of the dimensions of "x".
  69. *@par Outputs:
  70. *y: A Tensor. Has the same type as "x".
  71. *@par Third-party framework compatibility
  72. *Compatible with the TensorFlow operator Transpose.
  73. */
  74. REG_OP(Transpose)
  75. .INPUT(x, TensorType::BasicType())
  76. .INPUT(perm, TensorType::IndexNumberType())
  77. .OUTPUT(y, TensorType::BasicType())
  78. .OP_END_FACTORY_REG(Transpose)
  79. REG_OP(TransData)
  80. .INPUT(src, TensorType::BasicType())
  81. .OUTPUT(dst, TensorType::BasicType())
  82. .REQUIRED_ATTR(src_format, String)
  83. .REQUIRED_ATTR(dst_format, String)
  84. .OP_END_FACTORY_REG(TransData)
  85. /**
  86. *@brief Permutes the dimensions according to order.\n
  87. The returned tensor's dimension i will correspond to the input dimension order[i].
  88. *@par Inputs:
  89. *x: A Tensor. Must be one of the following types: float16, float32.
  90. *@par Attributes:
  91. *order: A permutation of the dimensions of "x".Type is int32.support any axis transformation.Defaults to "{0}"
  92. *@par Outputs:
  93. *y: A Tensor. Has the same type as "x".
  94. */
  95. REG_OP(Permute)
  96. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  97. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  98. .ATTR(order, ListInt, {0})
  99. .OP_END_FACTORY_REG(Permute)
  100. /**
  101. *@brief Flattens the inputs. Reserves axis 0 and flattens the input tensors
  102. * along axis 1.
  103. *@par Inputs:
  104. *One input: \n
  105. *x: A multi-dimensional Tensor. Must be one of the following types:
  106. * int8, uint8, int16, uint16, int32, uint32, int64,uint64, float16, float32.
  107. *@par Outputs:
  108. *y: A 2D flattened Tensor (Reserves axis 0 and flattens the input tensors
  109. * along axis 1). Must be one of the following data types: int8, uint8, int16,
  110. * uint16, int32, uint32, int64,uint64, float16, float32.
  111. *@par Third-party framework compatibility
  112. * Compatible with TensorFlow operator Flatten.
  113. */
  114. REG_OP(Flatten)
  115. .INPUT(x, TensorType({DT_INT8, DT_INT16, DT_INT32, DT_INT64,
  116. DT_UINT8, DT_UINT16, DT_UINT32, DT_UINT64,
  117. DT_FLOAT, DT_FLOAT16}))
  118. .OUTPUT(y, TensorType({DT_INT8, DT_INT16, DT_INT32, DT_INT64,
  119. DT_UINT8, DT_UINT16, DT_UINT32, DT_UINT64,
  120. DT_FLOAT, DT_FLOAT16}))
  121. .OP_END_FACTORY_REG(Flatten)
  122. /**
  123. *@brief Permutes and crops the input tensor.
  124. *@par Inputs:
  125. * Three inputs, including:
  126. *@li x: A 5D Tensor of type float16 or int8 or uint8, with format NC1HWC0.
  127. *@li block_shape: A 1D list or tuple of int32 or int64.
  128. *@li crops: A 2D list or tuple of int32 or int64. Specifies the amount to
  129. *crop from start and end dimensions after permutation.
  130. *@par Outputs:
  131. *y: A Tensor with format NC1HWC0. Has the same type as input "x".
  132. *@par Third-party framework compatibility
  133. * Compatible with the TensorFlow operator BatchToSpaceND.
  134. */
  135. REG_OP(BatchToSpaceND)
  136. .INPUT(x, TensorType::BasicType())
  137. .INPUT(block_shape, TensorType::IndexNumberType())
  138. .INPUT(crops, TensorType::IndexNumberType())
  139. .OUTPUT(y, TensorType::BasicType())
  140. .OP_END_FACTORY_REG(BatchToSpaceND)
  141. /**
  142. *@brief Permutes and crops the input tensor.
  143. *@par Inputs:
  144. * One input:
  145. *x: A 5D Tensor of type float16 or int8 or uint8, with format NC1HWC0.
  146. *@par Attributes:
  147. *@li block_shape: A required 1D list or tuple of int32 or int64.
  148. *@li crops: A required 2D list or tuple of int32 or int64. Specifies the amount to crop
  149. * from the start and end dimensions after permutation.
  150. *@par Outputs:
  151. *y: A Tensor with format NC1HWC0. Has the same type as input "x".
  152. *@par Third-party framework compatibility
  153. * Compatible with the TensorFlow operator BatchToSpaceND.
  154. */
  155. REG_OP(BatchToSpaceNDD)
  156. .INPUT(x, TensorType::BasicType())
  157. .OUTPUT(y, TensorType::BasicType())
  158. .REQUIRED_ATTR(block_shape, ListInt)
  159. .REQUIRED_ATTR(crops, ListInt)
  160. .OP_END_FACTORY_REG(BatchToSpaceNDD)
  161. /**
  162. *@brief Pads and permutes the input tensor.
  163. *@par Inputs:
  164. * Three inputs, including: \n
  165. *@li x: A 5D Tensor of type float16 or float32, with format NC1HWC0.
  166. *@li block_shape: A 1D list or tuple of int32 or int64.
  167. *@li paddings: A 2D list or tuple of int32 or int64. Specifies the padding for the start and end dimensions after permutation.
  168. *@par Outputs:
  169. *y: A Tensor with format NC1HWC0. Has the same type as input "x".
  170. *@par Third-party framework compatibility
  171. * Compatible with the TensorFlow operator SpaceToBatchND.
  172. */
  173. REG_OP(SpaceToBatchND)
  174. .INPUT(x, TensorType::BasicType())
  175. .INPUT(block_shape, TensorType::IndexNumberType())
  176. .INPUT(paddings, TensorType::IndexNumberType())
  177. .OUTPUT(y, TensorType::BasicType())
  178. .OP_END_FACTORY_REG(SpaceToBatchND)
  179. /**
  180. *@brief Pads and permutes the input tensor.
  181. *@par Inputs:
  182. * One input: \n
  183. *x: A 5D Tensor of type float16 or float32, with format NC1HWC0.
  184. *@par Attributes:
  185. *@li block_shape: A required 1D list or tuple of int32 or int64.
  186. *@li paddings: A required 2D list or tuple of int32 or int64. Specifies the padding for the start and end dimensions after permutation.
  187. *@par Outputs:
  188. *y: A Tensor with format NC1HWC0. Has the same type as input "x".
  189. *@par Third-party framework compatibility
  190. * Compatible with the TensorFlow operator SpaceToBatchND.
  191. */
  192. REG_OP(SpaceToBatchNDD)
  193. .INPUT(x, TensorType::BasicType())
  194. .OUTPUT(y, TensorType::BasicType())
  195. .REQUIRED_ATTR(block_shape, ListInt)
  196. .REQUIRED_ATTR(paddings, ListInt)
  197. .OP_END_FACTORY_REG(SpaceToBatchNDD)
  198. /**
  199. *@brief Outputs a copy of the input tensor where values from the "height" and
  200. * "width" dimensions are moved to the "depth" dimension.
  201. *@par Inputs:
  202. *x: An NHWC Tensor. Must be one of the following types:
  203. * float16, float32, double, int64, int32, uint8, uint16, uint32, uint64, int8,
  204. * int16, complex64, complex128, qint8, quint8, qint16, quint16, qint32.
  205. *@par Attributes:
  206. *@li block_size: A required int, specifying the input block size.
  207. *@li data_format: An optional string, specifying the data format. Defaults to
  208. * "NHWC".
  209. *@par Outputs:
  210. *y: A Tensor. Has the same type as input "x".
  211. *@par Third-party framework compatibility
  212. * Compatible with the TensorFlow operator SpaceToDepth.
  213. */
  214. REG_OP(SpaceToDepth)
  215. .INPUT(x, TensorType::BasicType())
  216. .OUTPUT(y, TensorType::BasicType())
  217. .REQUIRED_ATTR(block_size, Int)
  218. .ATTR(data_format, String, "NHWC")
  219. .OP_END_FACTORY_REG(SpaceToDepth)
  220. /**
  221. *@brief Rearranges data from depth into blocks of spatial data.
  222. *@par Inputs:
  223. *x: A Tensor. Must be one of the following types: float16, float32, double, int32, uint8,
  224. * int16, int8, complex64, int64, qint8, quint8, qint32, qint16, quint16, uint16,
  225. * complex128, uint32, uint64
  226. *@par Attributes:
  227. *Two attributes, including:
  228. * @li block_size: An int >= 2, specifying the size of the spatial block.
  229. * @li data_format: An optional string, specifying the data format. Defaults to "NHWC".
  230. *@par Outputs:
  231. *y: A Tensor of the same type as "x".
  232. *@par Third-party framework compatibility:
  233. * Compatible with TensorFlow operator DepthToSpace.
  234. */
  235. REG_OP(DepthToSpace)
  236. .INPUT(x, TensorType::BasicType())
  237. .OUTPUT(y, TensorType::BasicType())
  238. .REQUIRED_ATTR(block_size, Int)
  239. .ATTR(data_format, String, "NHWC")
  240. .OP_END_FACTORY_REG(DepthToSpace)
  241. /**
  242. *@brief Permutes data into spatial data blocks and then prunes them.
  243. *@par Inputs:
  244. *@li x: A 4D Tensor with format NHWC.
  245. *@li crops: A 1D list or tuple of int32 or int64.
  246. *Must be one of the following types: float16, float32
  247. *@par Attributes:
  248. *block_size: A required int8, int16, int32, or int64. No default value.
  249. *@par Outputs:
  250. *y: A 4D Tensor with format NHWC,
  251. * of type float16 or float32.
  252. *@attention Constraints:
  253. *@li The size of the first dimension of input "x" must be divisible by (block_size * block_size).
  254. *@li "crops" is a 4Dshape [batch, height, width, depth], height = height_pad - crop_top - crop_bottom,
  255. *width = width_pad - crop_left - crop_right.
  256. *@li block_size > 2
  257. *@par Third-party framework compatibility
  258. * Compatible with the TensorFlow operator BatchToSpace.
  259. */
  260. REG_OP(BatchToSpace)
  261. .INPUT(x, TensorType::BasicType())
  262. .INPUT(crops, TensorType::IndexNumberType())
  263. .OUTPUT(y, TensorType::BasicType())
  264. .REQUIRED_ATTR(block_size, Int)
  265. .OP_END_FACTORY_REG(BatchToSpace)
  266. /**
  267. *@brief Rearrange the batch (permutes) data into spatial data blocks, and then crop them.
  268. *@par Inputs:
  269. * One input:
  270. *x: An Tensor of shape [batch*block_size*block_size, height_pad/block_size, width_pad/block_size, depth].
  271. *The batch size of the input tensor must be divisible by (block size * block size).
  272. *Must be one of the following types: float16, float32, double, int64, int32, uint8, uint16, uint32, uint64,
  273. *int8, int16, complex64, complex128, qint8, quint8, qint16, quint16, qint32.
  274. *@par Attributes:
  275. *@li block_size: Must be one of the following types: `int32`, `int64`.
  276. *@li crops: An Tensor. Must be one of the following types: int32, Int64.
  277. *2D tensor with non negative integer of shape [2, 2]. It specifies how many
  278. *elements are clipped from the intermediate result of spatial dimension.
  279. *@par Outputs:
  280. *y: A Tensor. Has the same type and format as input "x".
  281. *@attention Constraints:
  282. *@li The size of the first dimension of input "x" must be divisible by (block_size * block_size).
  283. *@li "crops" is a 2D tensor of non-negative integers with shape (2, 2).
  284. *@li block_size > 2
  285. *@par Third-party framework compatibility
  286. * Compatible with the TensorFlow operator BatchToSpace.
  287. */
  288. REG_OP(BatchToSpaceD)
  289. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT64, DT_INT32, DT_UINT8,
  290. DT_UINT16, DT_UINT32, DT_UINT64, DT_INT8, DT_INT16, DT_COMPLEX64,
  291. DT_COMPLEX128, DT_QINT8, DT_QUINT8, DT_QINT16, DT_QUINT16, DT_QINT32}))
  292. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT64, DT_INT32, DT_UINT8,
  293. DT_UINT16, DT_UINT32, DT_UINT64, DT_INT8, DT_INT16, DT_COMPLEX64,
  294. DT_COMPLEX128, DT_QINT8, DT_QUINT8, DT_QINT16, DT_QUINT16, DT_QINT32}))
  295. .REQUIRED_ATTR(block_size, Int)
  296. .REQUIRED_ATTR(crops, ListInt)
  297. .OP_END_FACTORY_REG(BatchToSpaceD)
  298. /**
  299. *@brief Outputs a copy of the input tensor where values from the "height" and
  300. * "width" dimensions are padded and rearranged to the "batch" dimension.
  301. *@par Inputs:
  302. * Two inputs, including:
  303. *@li x: An NHWC Tensor. Must be one of the following types:
  304. * float16, float32, double, int64, int32, uint8, uint16, uint32, uint64, int8,
  305. * int16, complex64, complex128, qint8, quint8, qint16, quint16, qint32.
  306. *@li paddings: A 2D tensor of type int, specifying the input.
  307. *@par Attributes:
  308. *block_size: A required int, specifying the input block size.
  309. *@par Outputs:
  310. *y: A Tensor. Has the same type as input "x".
  311. *@par Third-party framework compatibility
  312. * Compatible with the TensorFlow operator SpaceToBatch.
  313. */
  314. REG_OP(SpaceToBatch)
  315. .INPUT(x, TensorType::BasicType())
  316. .INPUT(paddings, TensorType::IndexNumberType())
  317. .OUTPUT(y, TensorType::BasicType())
  318. .REQUIRED_ATTR(block_size, Int)
  319. .OP_END_FACTORY_REG(SpaceToBatch)
  320. /**
  321. *@brief Outputs a copy of the input tensor where values from the "height" and "width" dimensions are padded and rearranged to the "batch" dimension.
  322. *@par Inputs:
  323. *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.
  324. *@par Attributes:
  325. *@li block_size: A required int, specifying the input block size.
  326. *@li paddings: A 2D tensor. All data types are supported.
  327. *@par Outputs:
  328. *y: A Tensor. Has the same type as input "x".
  329. *@par Third-party framework compatibility
  330. *@ Compatible with the TensorFlow operator SpaceToBatch.
  331. */
  332. REG_OP(SpaceToBatchD)
  333. .INPUT(x, TensorType::BasicType())
  334. .OUTPUT(y, TensorType::BasicType())
  335. .REQUIRED_ATTR(block_size, Int)
  336. .REQUIRED_ATTR(paddings, ListInt)
  337. .OP_END_FACTORY_REG(SpaceToBatchD)
  338. /**
  339. * @brief Unpacks the given dimension of a rank-R Tensor "x" into rank-(R-1)
  340. * tensors.
  341. * @par Inputs:
  342. * x: A rank-R tensor (R > 0) of type BasicType, with format ND or NC1HWC0.
  343. * @par Attributes:
  344. * @li num: A required int, specifying the number of tensors to be unpacked to.
  345. * Defaults to "None".
  346. * @li axis: An optional int, specifying the axis to unpack along. The value range
  347. * is [-R, R).
  348. * @par Outputs:
  349. * y: Dynamic output. The list of Tensor objects unpacked from "x", of type BasicType.
  350. * @attention Constraints:
  351. * @li If "num" is not specified, it is inferred from the shape of "x".
  352. * @li For the ND format, "axis" is in the range [-R, R); For the NC1HWC0 format,
  353. * "axis" must not be 2, 3, -2, or -3.
  354. * @par Third-party framework compatibility
  355. * Compatible with the TensorFlow operator Unpack.
  356. */
  357. REG_OP(Unpack)
  358. .INPUT(x, TensorType::BasicType())
  359. .DYNAMIC_OUTPUT(y, TensorType::BasicType())
  360. .REQUIRED_ATTR(num, Int)
  361. .ATTR(axis, Int, 0)
  362. .OP_END_FACTORY_REG(Unpack)
  363. /**
  364. * @brief Extract "patches" from "images" and stacks them in the "depth"
  365. * dimension of the output.
  366. * @par Inputs:
  367. * x: A 4D Tensor with shape [batch, in_rows, in_cols, depth], Must be one of the
  368. * following types:float32, double, int32, uint8, int16, int8, int64, uint16,
  369. * float16, uint32, uint64
  370. * @par Attributes:
  371. * @li ksizes: A required list or tuple. The size of the sliding window for each
  372. * dimension of images.
  373. * @li strides: A required list or tuple. How far the centers of two consecutive
  374. * patches are in the images. Must be: [1, stride_rows, stride_cols, 1].
  375. * @li rates: A required list or tuple. Must be: [1, rate_rows, rate_cols, 1].\n
  376. * This is the input stride, specifying how far two consecutive patch\n
  377. * samples are in the input. Equivalent to extracting patches
  378. * with patch_sizes_eff = patch_sizes + (patch_sizes - 1) *\n
  379. * (rates - 1), followed by subsampling them spatially by a factor of rates.\n
  380. * This is equivalent to rate in dilated (a.k.a. Atrous) convolutions.
  381. * @li padding: A required string. The type of padding algorithm to use.
  382. * @par Outputs:
  383. * y: A 4D Tensor with shape [batch, out_rows, out_cols, ksize_rows *\n
  384. * ksize_cols * depth] containing image patches with size ksize_rows x ksize_cols\n
  385. * x depth vectorized in the "depth" dimension. Note "out_rows" and "out_cols"\n
  386. * are the dimensions of the output patches.
  387. * @attention Constraints:
  388. * "ksizes", "strides" and "rates" are lists of integers.
  389. * @par Third-party framework compatibility
  390. * Compatible with the TensorFlow operator ExtractImagePatches.
  391. */
  392. REG_OP(ExtractImagePatches)
  393. .INPUT(x, TensorType::RealNumberType())
  394. .OUTPUT(y, TensorType::RealNumberType())
  395. .REQUIRED_ATTR(ksizes, ListInt)
  396. .REQUIRED_ATTR(strides, ListInt)
  397. .REQUIRED_ATTR(rates, ListInt)
  398. .REQUIRED_ATTR(padding, String)
  399. .OP_END_FACTORY_REG(ExtractImagePatches)
  400. /**
  401. * @brief Extract "patches" from "input" and put them in the "depth"
  402. * dimension of the output.
  403. * @par Inputs:
  404. * x: A 5D Tensor with shape [batch, in_planes, in_rows, in_cols, depth].
  405. * @par Attributes:
  406. * @li ksizes: A required list or tuple. The size of the sliding window for each
  407. * dimension of "x".
  408. * @li strides: A required list or tuple. How far the centers of two consecutive
  409. * patches are in "x". Must be: [1, stride_planes, stride_rows, stride_cols, 1].
  410. * @li padding: A required string. The type of padding algorithm to use.
  411. * @par Outputs:
  412. * Output: A 5D Tensor with shape [batch, out_planes, out_rows, out_cols, ksize_planes * \n
  413. * ksize_rows * ksize_cols * depth] containing patches with size (ksize_rows * ksize_cols\n
  414. * * depth) vectorized in the "depth" dimension. Note "out_planes", "out_rows" and "out_cols"\n
  415. * are the dimensions of the output patches.
  416. * @attention Constraints:
  417. * "ksizes" and "strides" are lists of integers.
  418. * @par Third-party framework compatibility
  419. * Compatible with the TensorFlow operator ExtractVolumePatches.
  420. */
  421. REG_OP(ExtractVolumePatches)
  422. .INPUT(x, TensorType::REALNUMBERTYPE())
  423. .OUTPUT(y, TensorType::REALNUMBERTYPE())
  424. .REQUIRED_ATTR(ksizes, ListInt)
  425. .REQUIRED_ATTR(strides, ListInt)
  426. .REQUIRED_ATTR(padding, String)
  427. .OP_END_FACTORY_REG(ExtractVolumePatches)
  428. /**
  429. *@brief Confuse reshape and transpose.
  430. *@par Inputs:
  431. *x: A Tensor. Must be one of the following types: float16, float32, int8, int16, int32, int64, uint8, uint16, uint32, uint64.
  432. *@par Attributes:
  433. *@li perm: A permutation of the dimensions of "x".
  434. *@li shape: The shape of the input.
  435. *@li transpose_first: If True, the transpose is first, otherwise the reshape is first.
  436. *@par Outputs:
  437. *y: A Tensor. Has the same type as "x".
  438. */
  439. REG_OP(ConfusionTransposeD)
  440. .INPUT(x, TensorType({DT_INT8, DT_INT16, DT_INT32, DT_INT64, DT_UINT8,
  441. DT_UINT16, DT_UINT32, DT_UINT64, DT_FLOAT16, DT_FLOAT}))
  442. .OUTPUT(y, TensorType({DT_INT8, DT_INT16, DT_INT32, DT_INT64, DT_UINT8,
  443. DT_UINT16, DT_UINT32, DT_UINT64, DT_FLOAT16, DT_FLOAT}))
  444. .REQUIRED_ATTR(perm, ListInt)
  445. .REQUIRED_ATTR(shape, ListInt)
  446. .REQUIRED_ATTR(transpose_first, Bool)
  447. .OP_END_FACTORY_REG(ConfusionTransposeD)
  448. /**
  449. *@brief Confuse reshape and transpose.
  450. *@par Inputs:
  451. *@li x: A Tensor. Must be one of the following types: float16, float32, int8, int16, int32, int64, uint8, uint16, uint32, uint64.
  452. *@li shape: The shape of the input.
  453. *@par Attributes:
  454. *@li perm: A permutation of the dimensions of "x".
  455. *@li transpose_first: If True, the transpose is first, otherwise the reshape is first.
  456. *@par Outputs:
  457. *y: A Tensor. Has the same type as "x".
  458. */
  459. REG_OP(ConfusionTranspose)
  460. .INPUT(x, TensorType::BasicType())
  461. .INPUT(shape, TensorType::IndexNumberType())
  462. .OUTPUT(y, TensorType::BasicType())
  463. .REQUIRED_ATTR(perm, ListInt)
  464. .REQUIRED_ATTR(transpose_first, Bool)
  465. .OP_END_FACTORY_REG(ConfusionTranspose)
  466. /**
  467. *@brief Flattens the input tensor to one-dimensional.
  468. *@par Inputs:
  469. *x: An ND tensor. All data types are supported.
  470. *@par Attributes:
  471. *@li axis: An optional int32, specifying the first axis to flatten. All preceding axes are retained in the output. Defaults to "1".
  472. *@li end_axis: An optional int32, specifying the last axis to flatten. All following axes are retained in the output. Defaults to "-1".
  473. *@par Outputs:
  474. *y: The flattened ND tensor. All data types are supported.
  475. *@attention Constraints:
  476. * "axis" and "end_axis" must be within the dimension range of the input. This operator cannot be directly called by the acllopExecute API.
  477. *@par Third-party framework compatibility
  478. * Compatible with the Caffe operator Flatten.
  479. */
  480. REG_OP(FlattenV2)
  481. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8, DT_UINT8, DT_INT16, DT_UINT16,
  482. DT_INT32, DT_UINT32, DT_INT64, DT_UINT64}))
  483. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8, DT_UINT8, DT_INT16, DT_UINT16,
  484. DT_INT32, DT_UINT32, DT_INT64, DT_UINT64}))
  485. .ATTR(axis, Int, 1)
  486. .ATTR(end_axis, Int, -1)
  487. .OP_END_FACTORY_REG(FlattenV2)
  488. REG_OP(DeConvTrans)
  489. .INPUT(x, TensorType({DT_INT8}))
  490. .OUTPUT(y, TensorType({DT_INT8}))
  491. .OP_END_FACTORY_REG(DeConvTrans)
  492. REG_OP(Compress)
  493. .INPUT(weight, TensorType({DT_INT8, DT_FLOAT16}))
  494. .OUTPUT(weight_compress, TensorType({DT_INT8, DT_FLOAT16}))
  495. .OUTPUT(compress_index, TensorType({DT_INT8}))
  496. .REQUIRED_ATTR(compress_parameters, ListInt)
  497. .OP_END_FACTORY_REG(Compress)
  498. REG_OP(CompressFcOp)
  499. .INPUT(weight, TensorType({DT_INT8}))
  500. .OUTPUT(weight_compress, TensorType({DT_INT8}))
  501. .OUTPUT(compress_index, TensorType({DT_INT8}))
  502. .REQUIRED_ATTR(compress_parameters, ListInt)
  503. .OP_END_FACTORY_REG(CompressFcOp)
  504. } // namespace ge
  505. #endif // GE_OP_TRANSFORMATION_OPS_H

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