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

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