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.

image_ops.h 46 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
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
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238
  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_MAGE_OPS_H_
  17. #define GE_OP_MAGE_OPS_H_
  18. #include "graph/operator_reg.h"
  19. namespace ge {
  20. /**
  21. *@brief Adjust the hue of one or more images.
  22. *@par Inputs:
  23. *Input images is a tensor of at least 3 dimensions. The last dimension is \n
  24. interpretted as channels, and must be three. Inputs include: \n
  25. *@li images:A Tensor of type float. Images to adjust. At least 3-D.
  26. *@li delta:A Tensor of type float. A float delta to add to the hue.
  27. *@par Outputs:
  28. *y:A Tensor of type float.
  29. *@attention Constraints: \n
  30. *Input images is a tensor of at least 3 dimensions. The last dimension is \n
  31. interpretted as channels, and must be three.
  32. *@par Third-party framework compatibility
  33. *Compatible with tensorflow AdjustHue operator.
  34. */
  35. REG_OP(AdjustHue)
  36. .INPUT(images, TensorType({DT_FLOAT16,DT_FLOAT}))
  37. .INPUT(delta, TensorType({DT_FLOAT}))
  38. .OUTPUT(y, TensorType({DT_FLOAT16,DT_FLOAT}))
  39. .OP_END_FACTORY_REG(AdjustHue)
  40. /**
  41. *@brief Adjust the saturation of one or more images.
  42. *@par Inputs:
  43. *Input images is a tensor of at least 3 dimensions. The last dimension is \n
  44. interpretted as channels, and must be three. Inputs include: \n
  45. *@li images:A Tensor of type float. Images to adjust. At least 3-D.
  46. *@li scale:A Tensor of type float. A float scale to add to the saturation.
  47. *@par Outputs:
  48. *y:A Tensor of type float.
  49. *@attention Constraints: \n
  50. *Input images is a tensor of at least 3 dimensions. The last dimension is \n
  51. interpretted as channels, and must be three.
  52. *@par Third-party framework compatibility
  53. *Compatible with tensorflow AdjustSaturation operator.
  54. */
  55. REG_OP(AdjustSaturation)
  56. .INPUT(images, TensorType({DT_FLOAT16,DT_FLOAT}))
  57. .INPUT(scale, TensorType({DT_FLOAT}))
  58. .OUTPUT(y, TensorType({DT_FLOAT16,DT_FLOAT}))
  59. .OP_END_FACTORY_REG(AdjustSaturation)
  60. /**
  61. *@brief Adjust the contrast of one or more images.
  62. *@par Inputs:
  63. *Input images is a tensor of at least 3 dimensions. The last 3 dimensions are \n
  64. interpreted as '[height, width, channels]'. Inputs include: \n
  65. *@li images:A Tensor of type float. Images to adjust. At least 3-D.
  66. *@li scale:A Tensor of type float. A float multiplier for adjusting contrast.
  67. *@par Outputs:
  68. *y:A Tensor of type float.
  69. *@attention Constraints: \n
  70. *Input images is a tensor of at least 3 dimensions. The last dimension is \n
  71. interpretted as channels, and must be three.
  72. *@par Third-party framework compatibility
  73. *Compatible with tensorflow AdjustContrast operator.
  74. */
  75. REG_OP(AdjustContrast)
  76. .INPUT(images, TensorType({DT_FLOAT16,DT_FLOAT}))
  77. .INPUT(contrast_factor, TensorType({DT_FLOAT}))
  78. .OUTPUT(y, TensorType({DT_FLOAT16,DT_FLOAT}))
  79. .OP_END_FACTORY_REG(AdjustContrast)
  80. /**
  81. *@brief Extracts crops from the input image tensor and resizes them. Extracts \n
  82. crops from the input image tensor and resizes them using bilinear sampling or \n
  83. nearest neighbor sampling to a common output size specified by crop_size.
  84. *@par Inputs:
  85. *Input images must be a 4-D tensor. Inputs include: \n
  86. *@li images:A Tensor. Must be one of the following types:uint8, uint16, int8, \n
  87. int16, int32, int64, float16, float, double. A 4-D tensor of shape \n
  88. [batch, image_height, image_width, depth].
  89. *@li boxes: A Tensor of type float. A 2-D tensor of shape [num_boxes, 4].
  90. *@li box_index: A Tensor of type int32. A 1-D tensor of shape [num_boxes] with \n
  91. int32 values in [0, batch).
  92. *@li crop_size: A Tensor of type int32. A 1-D tensor of 2 elements, crop_size \n
  93. = [crop_height, crop_width]. All cropped image patches are resized to this size.
  94. *@par Attributes:
  95. *@li extrapolation_value: An optional float. Defaults to 0. Value used for \n
  96. extrapolation, when applicable.
  97. *@li method: An optional string from: '"bilinear", "nearest"'. Defaults to \n
  98. "bilinear". Currently two sampling methods are supported: Bilinear and \n
  99. NearestNeighbor.
  100. *@par Outputs:
  101. *y:A Tensor of type float.
  102. *@attention Constraints: \n
  103. *Input images must be a 4-D tensor.
  104. *@par Third-party framework compatibility
  105. *Compatible with tensorflow CropAndResize operator.
  106. */
  107. REG_OP(CropAndResize)
  108. .INPUT(x, TensorType({DT_UINT8, DT_UINT16, DT_INT8, \
  109. DT_INT16, DT_INT32, DT_INT64, DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  110. .INPUT(boxes, TensorType({DT_FLOAT}))
  111. .INPUT(box_index, TensorType({DT_INT32}))
  112. .INPUT(crop_size, TensorType({DT_INT32}))
  113. .OUTPUT(y, TensorType({DT_FLOAT}))
  114. .ATTR(extrapolation_value, Float, 0)
  115. .ATTR(method, String, "bilinear")
  116. .OP_END_FACTORY_REG(CropAndResize)
  117. /**
  118. *@brief Computes the gradient of the crop_and_resize op wrt the input \n
  119. boxes tensor.
  120. *@par Inputs:
  121. *Input images and grads must be a 4-D tensor. Inputs include: \n
  122. *@li grads: A 4-D tensor of shape [num_boxes, crop_height, crop_width, depth].
  123. *@li images: A 4-D tensor of shape [batch, image_height, image_width, depth]. \n
  124. Both image_height and image_width need to be positive.
  125. *@li boxes: A 2-D tensor of shape [num_boxes, 4]. The i-th row of the tensor \n
  126. specifies the coordinates of a box in the box_ind[i] image and is specified in \n
  127. normalized coordinates [y1, x1, y2, x2].
  128. *@li box_index: A 1-D tensor of shape [num_boxes] with int32 values in \n
  129. [0, batch). The value of box_ind[i] specifies the image that the i-th box \n
  130. refers to.
  131. *@par Attributes:
  132. method: A string specifying the interpolation method. Only 'bilinear' is \n
  133. supported for now.
  134. *@par Outputs:
  135. *y:A 2-D tensor of shape [num_boxes, 4].
  136. *@attention Constraints: \n
  137. *Input images and grads must be a 4-D tensor.
  138. *@par Third-party framework compatibility
  139. *Compatible with tensorflow CropAndResizeGradBoxes operator.
  140. */
  141. REG_OP(CropAndResizeGradBoxes)
  142. .INPUT(grads, TensorType({DT_FLOAT}))
  143. .INPUT(images, TensorType({DT_UINT8, DT_UINT16, DT_INT8, DT_INT16, \
  144. DT_INT32, DT_INT64, DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  145. .INPUT(boxes, TensorType({DT_FLOAT}))
  146. .INPUT(box_index, TensorType({DT_INT32}))
  147. .OUTPUT(y, TensorType({DT_FLOAT}))
  148. .ATTR(method, String, "bilinear")
  149. .OP_END_FACTORY_REG(CropAndResizeGradBoxes)
  150. /**
  151. *@brief Computes the gradient of the crop_and_resize op wrt the input \n
  152. images tensor.
  153. *@par Inputs:
  154. *Input grads must be a 4-D tensor. Inputs include: \n
  155. *@li grads: A 4-D tensor of shape [num_boxes, crop_height, crop_width, depth].
  156. *@li boxes: A 2-D tensor of shape [num_boxes, 4]. The i-th row of the tensor \n
  157. specifies the coordinates of a box in the box_ind[i] image and is specified \n
  158. in normalized coordinates [y1, x1, y2, x2].
  159. *@li box_index: A 1-D tensor of shape [num_boxes] with int32 values in \n
  160. [0, batch). The value of box_ind[i] specifies the image that the i-th box \n
  161. refers to.
  162. *@li image_size: A 1-D tensor with value [batch, image_height, image_width, \n
  163. depth] containing the original image size. Both image_height and image_width \n
  164. need to be positive.
  165. *@par Attributes:
  166. method: A string specifying the interpolation method. Only 'bilinear' is \n
  167. supported for now.
  168. *@par Outputs:
  169. *y:A 4-D tensor of shape [batch, image_height, image_width, depth].
  170. *@attention Constraints: \n
  171. *Input grads must be a 4-D tensor.
  172. *@par Third-party framework compatibility
  173. *Compatible with tensorflow CropAndResizeGradImage operator.
  174. */
  175. REG_OP(CropAndResizeGradImage)
  176. .INPUT(grads, TensorType({DT_FLOAT}))
  177. .INPUT(boxes, TensorType({DT_FLOAT}))
  178. .INPUT(box_index, TensorType({DT_INT32}))
  179. .INPUT(image_size, TensorType({DT_INT32}))
  180. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  181. .ATTR(method, String, "bilinear")
  182. .REQUIRED_ATTR(T, Type)
  183. .OP_END_FACTORY_REG(CropAndResizeGradImage)
  184. /**
  185. *@brief Extracts a glimpse from the input tensor.
  186. *@par Inputs:
  187. *Input x must be a 4-D tensor. Inputs include: \n
  188. *@li x: A 4-D float tensor of shape [batch_size, height, width, channels].
  189. *@li size: A 1-D tensor of 2 elements containing the size of the glimpses to \n
  190. extract. The glimpse height must be specified first, following by the glimpse \n
  191. width.
  192. *@li offsets: A 2-D integer tensor of shape [batch_size, 2] containing the y, \n
  193. x locations of the center of each window.
  194. *@par Attributes:
  195. *@li centered: indicates if the offset coordinates are centered relative to \n
  196. the image, in which case the (0, 0) offset is relative to the center of the \n
  197. input images. If false, the (0,0) offset corresponds to the upper left corner \n
  198. of the input images.
  199. *@li normalized: indicates if the offset coordinates are normalized.
  200. *@li uniform_noise: indicates if the noise should be generated using a \n
  201. uniform distribution or a Gaussian distribution.
  202. *@li noise: indicates if the noise should uniform, gaussian, or zero. \n
  203. The default is uniform which means the the noise type will be decided by \n
  204. uniform_noise.
  205. *@par Outputs:
  206. *y:A tensor representing the glimpses [batch_size, glimpse_height, \n
  207. glimpse_width, channels].
  208. *@attention Constraints: \n
  209. *Input x must be a 4-D tensor.
  210. *@par Third-party framework compatibility
  211. *Compatible with tensorflow CropAndResizeGradImage operator.
  212. */
  213. REG_OP(ExtractGlimpse)
  214. .INPUT(x, TensorType({DT_FLOAT}))
  215. .INPUT(size, TensorType({DT_INT32}))
  216. .INPUT(offsets, TensorType({DT_FLOAT}))
  217. .OUTPUT(y, TensorType({DT_FLOAT}))
  218. .ATTR(centered, Bool, true)
  219. .ATTR(normalized, Bool, true)
  220. .ATTR(uniform_noise, Bool, true)
  221. .ATTR(noise, String, "uniform")
  222. .OP_END_FACTORY_REG(ExtractGlimpse)
  223. /**
  224. *@brief Convert one or more images from HSV to RGB.
  225. *@par Inputs:
  226. *Last dimension of input x must be size 3. Inputs include: \n
  227. *images: 1-D or higher rank. HSV data to convert. Last dimension must be size 3.
  228. *@par Outputs:
  229. *y:images converted to RGB.
  230. *@attention Constraints: \n
  231. *Last dimension of input x must be size 3.
  232. *@par Third-party framework compatibility
  233. *Compatible with tensorflow HSVToRGB operator.
  234. */
  235. REG_OP(HSVToRGB)
  236. .INPUT(images, TensorType({DT_FLOAT16,DT_FLOAT,DT_DOUBLE}))
  237. .OUTPUT(y, TensorType({DT_FLOAT16,DT_FLOAT,DT_DOUBLE}))
  238. .OP_END_FACTORY_REG(HSVToRGB)
  239. /**
  240. *@brief Resize quantized images to size using quantized bilinear interpolation.
  241. *@par Inputs:
  242. *Input images must be a 4-D tensor. Inputs include: \n
  243. *@li images: 4-D with shape [batch, height, width, channels].
  244. *@li size: A 1-D int32 Tensor of 2 elements: new_height, new_width. The new \n
  245. size for the images.
  246. *@li min: A Tensor of type float.
  247. *@li max: A Tensor of type float.
  248. *@par Attributes:
  249. *@li align_corners: An optional bool. Defaults to False. If true, the centers \n
  250. of the 4 corner pixels of the input and output tensors are aligned, preserving \n
  251. the values at the corner pixels. Defaults to false.
  252. *@li half_pixel_centers: indicates if the offset coordinates are normalized.
  253. *@par Outputs:
  254. *@li resized_images: 4-D with shape [batch, new_height, new_width, channels].
  255. *@li y_min: A Tensor of type float.
  256. *@li y_max: A Tensor of type float.
  257. *@attention Constraints: \n
  258. *Input images and output images must be quantized types.
  259. *@par Third-party framework compatibility
  260. *Compatible with tensorflow QuantizedResizeBilinear operator.
  261. */
  262. REG_OP(QuantizedResizeBilinear)
  263. .INPUT(images, TensorType({DT_QUINT8,DT_QINT32,DT_FLOAT}))
  264. .INPUT(size, TensorType({ DT_INT32 }))
  265. .INPUT(min, TensorType({ DT_FLOAT }))
  266. .INPUT(max, TensorType({ DT_FLOAT }))
  267. .OUTPUT(resized_images, TensorType({DT_QUINT8,DT_QINT32,DT_FLOAT }))
  268. .OUTPUT(y_min, TensorType({ DT_FLOAT }))
  269. .OUTPUT(y_max, TensorType({ DT_FLOAT }))
  270. .ATTR(align_corners, Bool, false)
  271. .ATTR(half_pixel_centers, Bool, false)
  272. .OP_END_FACTORY_REG(QuantizedResizeBilinear)
  273. /**
  274. *@brief Resize images to size using area interpolation.
  275. *@par Inputs:
  276. *Input images must be a 4-D tensor. Inputs include: \n
  277. *@li images: 4-D with shape [batch, height, width, channels].
  278. *@li size: A 1-D int32 Tensor of 2 elements: new_height, new_width. \n
  279. The new size for the images.
  280. *@par Attributes:
  281. *align_corners: If true, the centers of the 4 corner pixels of the input and \n
  282. output tensors are aligned, preserving the values at the corner pixels. \n
  283. Defaults to false.
  284. *@par Outputs:
  285. *y: 4-D with shape [batch, new_height, new_width, channels].
  286. *@attention Constraints: \n
  287. *Input images can be of different types but output images are always float.
  288. *@par Third-party framework compatibility
  289. *Compatible with tensorflow ResizeArea operator.
  290. */
  291. REG_OP(ResizeArea)
  292. .INPUT(images, TensorType({DT_INT8, DT_UINT8, DT_INT16, DT_UINT16, \
  293. DT_INT32, DT_INT64, DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  294. .INPUT(size, TensorType({DT_INT32}))
  295. .OUTPUT(y, TensorType({DT_FLOAT}))
  296. .ATTR(align_corners, Bool, false)
  297. .OP_END_FACTORY_REG(ResizeArea)
  298. /**
  299. *@brief Computes the gradient of bicubic interpolation.
  300. *@par Inputs:
  301. *Input grads must be a 4-D tensor. Inputs include: \n
  302. *@li grads: A Tensor of type float. 4-D with shape [batch, height, width, \n
  303. channels].
  304. *@li original_image: A Tensor. Must be one of the following types: float, \n
  305. double. 4-D with shape [batch, orig_height, orig_width, channels], The image \n
  306. tensor that was resized.
  307. *@par Attributes:
  308. *@li align_corners: An optional bool. Defaults to False. If true, the centers \n
  309. of the 4 corner pixels of the input and grad tensors are aligned. Defaults to \n
  310. false.
  311. *@li half_pixel_centers: An optional bool. Defaults to False.
  312. *@par Outputs:
  313. *y: A Tensor. Has the same type as original_image.
  314. *@attention Constraints: \n
  315. *Input images can be of different types but output images are always float.
  316. *@par Third-party framework compatibility
  317. *Compatible with tensorflow ResizeBicubicGrad operator.
  318. */
  319. REG_OP(ResizeBicubicGrad)
  320. .INPUT(grads, TensorType({DT_FLOAT}))
  321. .INPUT(original_image, TensorType({DT_FLOAT, DT_DOUBLE}))
  322. .OUTPUT(y, TensorType({DT_FLOAT, DT_DOUBLE}))
  323. .ATTR(align_corners, Bool, false)
  324. .ATTR(half_pixel_centers, Bool, false)
  325. .OP_END_FACTORY_REG(ResizeBicubicGrad)
  326. /**
  327. *@brief Resize images to size using bicubic interpolation.
  328. *@par Inputs:
  329. *Input images must be a 4-D tensor. Inputs include: \n
  330. *@li images: 4-D with shape [batch, height, width, channels].
  331. *@li size: A 1-D int32 Tensor of 2 elements: new_height, new_width. The new \n
  332. size for the images.
  333. *@par Attributes:
  334. *@li align_corners: If true, the centers of the 4 corner pixels of the input \n
  335. and output tensors are aligned, preserving the values at the corner pixels. \n
  336. Defaults to false.
  337. *@li half_pixel_centers: An optional bool. Defaults to False.
  338. *@par Outputs:
  339. *y: 4-D with shape [batch, new_height, new_width, channels].
  340. *@attention Constraints: \n
  341. *Input images can be of different types but output images are always float.
  342. *@par Third-party framework compatibility
  343. *Compatible with tensorflow ResizeBicubic operator.
  344. */
  345. REG_OP(ResizeBicubic)
  346. .INPUT(images, TensorType({DT_INT8, DT_UINT8, DT_INT16, DT_UINT16, \
  347. DT_INT32, DT_INT64, DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  348. .INPUT(size, TensorType({DT_INT32}))
  349. .OUTPUT(y, TensorType({DT_FLOAT}))
  350. .ATTR(align_corners, Bool, false)
  351. .ATTR(half_pixel_centers, Bool, false)
  352. .OP_END_FACTORY_REG(ResizeBicubic)
  353. /**
  354. *@brief Computes the gradient of nearest neighbor interpolation.
  355. *@par Inputs:
  356. *Input grads must be a 4-D tensor. Inputs include: \n
  357. *@li grads: A Tensor. Must be one of the following types: uint8, int8, int32, \n
  358. float16, float, double. 4-D with shape [batch, height, width, channels].
  359. *@li size: A 1-D int32 Tensor of 2 elements: orig_height, orig_width. \n
  360. The original input size.
  361. *@par Attributes:
  362. *@li align_corners: An optional bool. Defaults to False. If true, the centers \n
  363. of the 4 corner pixels of the input and grad tensors are aligned. Defaults to \n
  364. false.
  365. *@li half_pixel_centers: An optional bool. Defaults to False.
  366. *@par Outputs:
  367. *y: A Tensor. Has the same type as grads.
  368. *@attention Constraints: \n
  369. *Input grads must be a 4-D tensor.
  370. *@par Third-party framework compatibility
  371. *Compatible with tensorflow ResizeNearestNeighborV2Grad operator.
  372. */
  373. REG_OP(ResizeNearestNeighborV2Grad)
  374. .INPUT(grads, TensorType({DT_INT8, DT_UINT8, DT_INT16, DT_UINT16, DT_INT32,
  375. DT_INT64, DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  376. .INPUT(size, TensorType({DT_INT32}))
  377. .OUTPUT(y, TensorType({DT_INT8, DT_UINT8, DT_INT16, DT_UINT16, DT_INT32,
  378. DT_INT64, DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  379. .ATTR(align_corners, Bool, false)
  380. .ATTR(half_pixel_centers, Bool, false)
  381. .OP_END_FACTORY_REG(ResizeNearestNeighborV2Grad)
  382. /**
  383. *@brief Computes the gradient of nearest neighbor interpolation.
  384. *@par Inputs:
  385. *Input grads must be a 4-D tensor. Inputs include: \n
  386. *grads: A Tensor. 4-D with shape [batch, height, width, channels].
  387. *@par Attributes:
  388. *@li align_corners: An optional bool. Defaults to False. If true, the centers \n
  389. of the 4 corner pixels of the input and grad tensors are aligned. Defaults to \n
  390. false.
  391. *@li size: An list type. Specify the images size.
  392. *@par Outputs:
  393. *y: A Tensor. Has the same type as grads.
  394. *@par Third-party framework compatibility
  395. *Compatible with tensorflow ResizeNearestNeighborV2GradD operator.
  396. */
  397. REG_OP(ResizeNearestNeighborV2GradD)
  398. .INPUT(grads, TensorType({DT_FLOAT}))
  399. .OUTPUT(y, TensorType({DT_FLOAT}))
  400. .REQUIRED_ATTR(size, ListInt)
  401. .ATTR(align_corners, Bool, false)
  402. .ATTR(half_pixel_centers, Bool, false)
  403. .OP_END_FACTORY_REG(ResizeNearestNeighborV2GradD)
  404. /**
  405. *@brief Computes the gradient of bilinear interpolation.
  406. *@par Inputs:
  407. *Input grads must be a 4-D tensor. Inputs include: \n
  408. *@li grads: A Tensor of type float32. 4-D with shape [batch, height, width, \n
  409. channels].
  410. *@li original_image: A Tensor. 4-D with shape [batch, orig_height, orig_width, \n
  411. channels], The image tensor that was resized.
  412. *@par Attributes:
  413. *align_corners: An optional bool. Defaults to False. If true, the centers of \n
  414. the 4 corner pixels of the input and grad tensors are aligned. Defaults to \n
  415. false.
  416. *@par Outputs:
  417. *y: A Tensor. Has the same type as original_image.
  418. *@attention Constraints: \n
  419. *Input grads must be a 4-D tensor.
  420. *@par Third-party framework compatibility
  421. *Compatible with tensorflow ResizeBilinearV2Grad operator.
  422. */
  423. REG_OP(ResizeBilinearV2Grad)
  424. .INPUT(grads, TensorType({DT_FLOAT}))
  425. .INPUT(original_image, TensorType::FloatingDataType())
  426. .OUTPUT(y, TensorType({DT_FLOAT}))
  427. .ATTR(align_corners, Bool, false)
  428. .ATTR(half_pixel_centers, Bool, false)
  429. .OP_END_FACTORY_REG(ResizeBilinearV2Grad)
  430. /**
  431. *@brief Resize images to size using bilinear interpolation.
  432. *@par Inputs:
  433. *Input images must be a 4-D tensor. Inputs include: \n
  434. *@li x: 4-D with shape [batch, height, width, channels].
  435. *@li size: A 1-D int32 Tensor of 2 elements: new_height, new_width. The new \n
  436. size for the images.
  437. *@par Attributes:
  438. *align_corners: If true, the centers of the 4 corner pixels of the input and \n
  439. output tensors are aligned, preserving the values at the corner pixels. \n
  440. Defaults to false.
  441. *@par Outputs:
  442. *y: 4-D with shape [batch, new_height, new_width, channels].
  443. *@attention Constraints: \n
  444. *Input images can be of different types but output images are always float.
  445. *@par Third-party framework compatibility
  446. *Compatible with tensorflow ResizeBilinearV2 operator.
  447. */
  448. REG_OP(ResizeBilinearV2)
  449. .INPUT(x, TensorType({DT_INT8, DT_UINT8, DT_INT16, DT_UINT16,
  450. DT_INT32, DT_INT64, DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  451. .INPUT(size, TensorType({DT_INT32}))
  452. .OUTPUT(y, TensorType({DT_FLOAT}))
  453. .ATTR(align_corners, Bool, false)
  454. .ATTR(half_pixel_centers, Bool, false)
  455. .OP_END_FACTORY_REG(ResizeBilinearV2)
  456. /**
  457. *@brief Converts one or more images from RGB to HSV.
  458. *@par Inputs:
  459. *Last dimension of input images must be size 3. Inputs include: \n
  460. *images: A Tensor. Must be one of the following types: float, double. 1-D or \n
  461. higher rank. RGB data to convert. Last dimension must be size 3.
  462. *@par Outputs:
  463. *y: A Tensor. Has the same type as images.
  464. *@attention Constraints: \n
  465. *Outputs a tensor of the same shape as the images tensor, containing the HSV \n
  466. value of the pixels. The output is only well defined if the value in images \n
  467. are in [0,1].
  468. *@par Third-party framework compatibility
  469. *Compatible with tensorflow RGBToHSV operator.
  470. */
  471. REG_OP(RGBToHSV)
  472. .INPUT(images, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE }))
  473. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE }))
  474. .OP_END_FACTORY_REG(RGBToHSV)
  475. /**
  476. *@brief Generate a single randomly distorted bounding box for an image.
  477. *@par Inputs:
  478. *Input images must be a 4-D tensor. Inputs include: \n
  479. *@li image_size: 1-D, containing [height, width, channels].
  480. *@li bounding_boxes: 3-D with shape [batch, N, 4] describing the N bounding \n
  481. boxes associated with the image.
  482. *@li min_object_covered: The cropped area of the image must contain at least \n
  483. this fraction of any bounding box supplied. The value of this parameter should \n
  484. be non-negative. In the case of 0, the cropped area does not need to overlap \n
  485. any of the bounding boxes supplied.
  486. *@par Attributes:
  487. *@li seed: If either seed or seed2 are set to non-zero, the random number \n
  488. generator is seeded by the given seed. Otherwise, it is seeded by a random seed.
  489. *@li seed2: A second seed to avoid seed collision.
  490. *@li aspect_ratio_range: The cropped area of the image must have an aspect \n
  491. ratio = width / height within this range.
  492. *@li max_attempts: Number of attempts at generating a cropped region of the \n
  493. image of the specified constraints. After max_attempts failures, return the \n
  494. entire image.
  495. *@li use_image_if_no_bounding_boxes: Controls behavior if no bounding boxes \n
  496. supplied. If true, assume an implicit bounding box covering the whole input. \n
  497. If false, raise an error.
  498. *@par Outputs:
  499. *@li begin: 1-D, containing [offset_height, offset_width, 0].
  500. *@li size: 1-D, containing [target_height, target_width, -1].
  501. *@li bboxes: 3-D with shape [1, 1, 4] containing the distorted bounding box.
  502. *@attention Constraints: \n
  503. *Input images can be of different types but output images are always float.
  504. *@par Third-party framework compatibility
  505. *Compatible with tensorflow SampleDistortedBoundingBoxExt2 operator.
  506. */
  507. REG_OP(SampleDistortedBoundingBoxExt2)
  508. .INPUT(image_size, TensorType({ DT_UINT8, DT_INT8, DT_INT16, \
  509. DT_INT32, DT_INT64 }))
  510. .INPUT(bounding_boxes, TensorType({ DT_FLOAT }))
  511. .INPUT(min_object_covered, TensorType({ DT_FLOAT }))
  512. .OUTPUT(begin, TensorType({ DT_UINT8, DT_INT8, DT_INT16, \
  513. DT_INT32, DT_INT64 }))
  514. .OUTPUT(size, TensorType({ DT_UINT8, DT_INT8, DT_INT16, \
  515. DT_INT32, DT_INT64 }))
  516. .OUTPUT(bboxes, TensorType({ DT_FLOAT }))
  517. .ATTR(seed, Int, 0)
  518. .ATTR(seed2, Int, 0)
  519. .ATTR(aspect_ratio_range, ListFloat, { 0.75f, 1.33f })
  520. .ATTR(area_range, ListFloat, { 0.05f, 1.0f })
  521. .ATTR(max_attempts, Int, 100)
  522. .ATTR(use_image_if_no_bounding_boxes, Bool, false)
  523. .OP_END_FACTORY_REG(SampleDistortedBoundingBoxExt2)
  524. /**
  525. *@brief Resize images to size using nearest neighbor interpolation.
  526. *@par Inputs:
  527. *Input x must be a 4-D tensor. Inputs include: \n
  528. *@li x: 4-D with shape [batch, height, width, channels].
  529. *@li size: A 1-D int32 Tensor of 2 elements: new_height, new_width. \n
  530. The new size for the images.
  531. *@par Attributes:
  532. *align_corners: If true, the centers of the 4 corner pixels of the input and \n
  533. output tensors are aligned, preserving the values at the corner pixels. \n
  534. Defaults to false.
  535. *@par Outputs:
  536. *y: 4-D with shape [batch, new_height, new_width, channels].
  537. *@par Third-party framework compatibility
  538. *Compatible with tensorflow ResizeNearestNeighborV2 operator.
  539. */
  540. REG_OP(ResizeNearestNeighborV2)
  541. .INPUT(x, TensorType({DT_INT8, DT_UINT8, DT_INT16, DT_UINT16, DT_INT32,
  542. DT_INT64, DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  543. .INPUT(size, TensorType({DT_INT32}))
  544. .OUTPUT(y, TensorType({DT_INT8, DT_UINT8, DT_INT16, DT_UINT16, DT_INT32,
  545. DT_INT64, DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  546. .ATTR(align_corners, Bool, false)
  547. .ATTR(half_pixel_centers, Bool, false)
  548. .OP_END_FACTORY_REG(ResizeNearestNeighborV2)
  549. /**
  550. *@brief Draw bounding boxes on a batch of images.
  551. *@par Inputs:
  552. *Input images must be a 4-D tensor. Inputs include: \n
  553. *@li images: A Tensor. Must be one of the following types: float. 4-D with \n
  554. shape [batch, height, width, depth]. A batch of images.
  555. *@li boxes: A Tensor of type float32. 3-D with shape [batch, \n
  556. num_bounding_boxes, 4] containing bounding boxes.
  557. *@par Outputs:
  558. *A Tensor. Has the same type as images.
  559. *@attention Constraints: \n
  560. *Input images must be a 4-D tensor.
  561. *@par Third-party framework compatibility
  562. *Compatible with tensorflow DrawBoundingBoxes operator.
  563. */
  564. REG_OP(DrawBoundingBoxes)
  565. .INPUT(images, TensorType({DT_FLOAT}))
  566. .INPUT(boxes, TensorType({DT_FLOAT}))
  567. .OUTPUT(y, TensorType({DT_FLOAT}))
  568. .OP_END_FACTORY_REG(DrawBoundingBoxes)
  569. /**
  570. *@brief Greedily selects a subset of bounding boxes in descending order of \n
  571. score.
  572. *@par Inputs:
  573. *Input boxes and scores must be float type. Inputs include: \n
  574. *@li boxes: A 2-D float tensor of shape [num_boxes, 4].
  575. *@li scores: A 1-D float tensor of shape [num_boxes] representing a single \n
  576. score corresponding to each box (each row of boxes).
  577. *@li max_output_size: A scalar integer tensor representing the maximum number \n
  578. of boxes to be selected by non max suppression.
  579. *@par Attributes:
  580. *iou_threshold: A float representing the threshold for deciding whether boxes \n
  581. overlap too much with respect to IOU.
  582. *@par Outputs:
  583. *selected_indices: A 1-D integer tensor of shape [M] representing the selected \n
  584. indices from the boxes tensor, where M <= max_output_size.
  585. *@attention Constraints: \n
  586. *Input boxes and scores must be float type.
  587. *@par Third-party framework compatibility
  588. *Compatible with tensorflow NonMaxSuppression operator.
  589. */
  590. REG_OP(NonMaxSuppression)
  591. .INPUT(boxes, TensorType({DT_FLOAT}))
  592. .INPUT(scores, TensorType({DT_FLOAT}))
  593. .INPUT(max_output_size, TensorType({DT_INT32}))
  594. .OUTPUT(selected_indices, TensorType({DT_INT32}))
  595. .ATTR(iou_threshold, Float, 0.5f)
  596. .OP_END_FACTORY_REG(NonMaxSuppression)
  597. /**
  598. *@brief Greedily selects a subset of bounding boxes in descending order of \n
  599. score.
  600. *@par Inputs:
  601. *Input boxes and scores must be float type. Inputs include: \n
  602. *@li boxes: A 2-D float tensor of shape [num_boxes, 4].
  603. *@li scores: A 1-D float tensor of shape [num_boxes] representing a single \n
  604. score corresponding to each box (each row of boxes).
  605. *@li max_output_size: A scalar integer tensor representing the maximum number \n
  606. of boxes to be selected by non max suppression.
  607. *@li iou_threshold: A 0-D float tensor representing the threshold for deciding \n
  608. whether boxes overlap too much with respect to IOU.
  609. *@par Outputs:
  610. *selected_indices: A 1-D integer tensor of shape [M] representing the selected \n
  611. indices from the boxes tensor, where M <= max_output_size.
  612. *@attention Constraints: \n
  613. *Input boxes and scores must be float type.
  614. *@par Third-party framework compatibility
  615. *Compatible with tensorflow NonMaxSuppressionV2 operator.
  616. */
  617. REG_OP(NonMaxSuppressionV2)
  618. .INPUT(boxes, TensorType({DT_FLOAT16, DT_FLOAT}))
  619. .INPUT(scores, TensorType({DT_FLOAT16, DT_FLOAT}))
  620. .INPUT(max_output_size, TensorType({DT_INT32}))
  621. .INPUT(iou_threshold, TensorType({DT_FLOAT16,DT_FLOAT}))
  622. .OUTPUT(selected_indices, TensorType({DT_INT32}))
  623. .OP_END_FACTORY_REG(NonMaxSuppressionV2)
  624. /**
  625. *@brief Greedily selects a subset of bounding boxes in descending order of \n
  626. score.
  627. *@par Inputs:
  628. *Input boxes and scores must be float type. Inputs include: \n
  629. *@li boxes: A 2-D float tensor of shape [num_boxes, 4].
  630. *@li scores: A 1-D float tensor of shape [num_boxes] representing a single \n
  631. score corresponding to each box (each row of boxes).
  632. *@li max_output_size: A scalar integer tensor representing the maximum number \n
  633. of boxes to be selected by non max suppression.
  634. *@li iou_threshold: A 0-D float tensor representing the threshold for deciding \n
  635. whether boxes overlap too much with respect to IOU.
  636. *@li score_threshold: A 0-D float tensor representing the threshold for \n
  637. deciding when to remove boxes based on score.
  638. *@par Outputs:
  639. *selected_indices: A 1-D integer tensor of shape [M] representing the selected \n
  640. indices from the boxes tensor, where M <= max_output_size.
  641. *@attention Constraints: \n
  642. *Input boxes and scores must be float type.
  643. *@par Third-party framework compatibility
  644. *Compatible with tensorflow NonMaxSuppressionV3 operator.
  645. */
  646. REG_OP(NonMaxSuppressionV3)
  647. .INPUT(boxes, TensorType({DT_FLOAT16, DT_FLOAT}))
  648. .INPUT(scores, TensorType({DT_FLOAT16, DT_FLOAT}))
  649. .INPUT(max_output_size, TensorType({DT_INT32}))
  650. .INPUT(iou_threshold, TensorType({DT_FLOAT16,DT_FLOAT}))
  651. .INPUT(score_threshold, TensorType({DT_FLOAT16,DT_FLOAT}))
  652. .OUTPUT(selected_indices, TensorType({DT_INT32}))
  653. .OP_END_FACTORY_REG(NonMaxSuppressionV3)
  654. /**
  655. *@brief Greedily selects a subset of bounding boxes in descending order of \n
  656. score.
  657. *@par Inputs:
  658. *Input boxes and scores must be float type. Inputs include: \n
  659. *@li boxes: A 2-D float tensor of shape [num_boxes, 4].
  660. *@li scores: A 1-D float tensor of shape [num_boxes] representing a single \n
  661. score corresponding to each box (each row of boxes).
  662. *@li max_output_size: A scalar integer tensor representing the maximum number \n
  663. of boxes to be selected by non max suppression.
  664. *@li iou_threshold: A 0-D float tensor representing the threshold for deciding \n
  665. whether boxes overlap too much with respect to IOU.
  666. *@li score_threshold: A 0-D float tensor representing the threshold for \n
  667. deciding when to remove boxes based on score.
  668. *@par Attributes:
  669. *pad_to_max_output_size: If true, the output selected_indices is padded \n
  670. to be of length max_output_size. Defaults to false.
  671. *@par Outputs:
  672. *@li selected_indices: A 1-D integer tensor of shape [M] representing the \n
  673. selected indices from the boxes tensor, where M <= max_output_size.
  674. *@li valid_outputs: A 0-D integer tensor representing the number of valid \n
  675. elements in selected_indices, with the valid elements appearing first.
  676. *@attention Constraints: \n
  677. *Input boxes and scores must be float type.
  678. *@par Third-party framework compatibility
  679. *Compatible with tensorflow NonMaxSuppressionV4 operator.
  680. */
  681. REG_OP(NonMaxSuppressionV4)
  682. .INPUT(boxes, TensorType({DT_FLOAT16, DT_FLOAT}))
  683. .INPUT(scores, TensorType({DT_FLOAT16, DT_FLOAT}))
  684. .INPUT(max_output_size, TensorType({DT_INT32}))
  685. .INPUT(iou_threshold, TensorType({DT_FLOAT16,DT_FLOAT}))
  686. .INPUT(score_threshold, TensorType({DT_FLOAT16,DT_FLOAT}))
  687. .OUTPUT(selected_indices, TensorType({DT_INT32}))
  688. .OUTPUT(valid_outputs, TensorType({DT_INT32}))
  689. .ATTR(pad_to_max_output_size, Bool, false)
  690. .OP_END_FACTORY_REG(NonMaxSuppressionV4)
  691. /**
  692. *@brief Greedily selects a subset of bounding boxes in descending order of \n
  693. score.
  694. *@par Inputs:
  695. *Input overlaps and scores must be float type. Inputs include: \n
  696. *@li overlaps: A 2-D float tensor of shape [num_boxes, num_boxes] \n
  697. representing the n-by-n box overlap values.
  698. *@li scores: A 1-D float tensor of shape [num_boxes] representing a single \n
  699. score corresponding to each box (each row of boxes).
  700. *@li max_output_size: A scalar integer tensor representing the maximum number \n
  701. of boxes to be selected by non max suppression.
  702. *@li overlap_threshold: A 0-D float tensor representing the threshold for \n
  703. deciding whether boxes overlap too.
  704. *@li score_threshold: A 0-D float tensor representing the threshold for \n
  705. deciding when to remove boxes based on score.
  706. *@par Attributes:
  707. *pad_to_max_output_size: If true, the output selected_indices is padded \n
  708. to be of length max_output_size. Defaults to false.
  709. *@par Outputs:
  710. *selected_indices: A 1-D integer tensor of shape [M] representing the \n
  711. selected indices from the boxes tensor, where M <= max_output_size.
  712. *@par Third-party framework compatibility
  713. *Compatible with tensorflow NonMaxSuppressionWithOverlaps operator.
  714. */
  715. REG_OP(NonMaxSuppressionWithOverlaps)
  716. .INPUT(overlaps, TensorType({DT_FLOAT}))
  717. .INPUT(scores, TensorType({DT_FLOAT}))
  718. .INPUT(max_output_size, TensorType({DT_INT32}))
  719. .INPUT(overlap_threshold, TensorType({DT_FLOAT}))
  720. .INPUT(score_threshold, TensorType({DT_FLOAT}))
  721. .OUTPUT(selected_indices, TensorType({DT_INT32}))
  722. .OP_END_FACTORY_REG(NonMaxSuppressionWithOverlaps)
  723. /**
  724. *@brief JPEG-encode an image.
  725. *@par Inputs:
  726. *Input image must be unit8 type. Inputs include: \n
  727. *image: A 3-D uint8 Tensor of shape [height, width, channels].
  728. *@par Attributes:
  729. *@li format: Per pixel image format.
  730. *@li quality: Quality of the compression from 0 to 100 (higher is better \n
  731. and slower).
  732. *@li progressive: If True, create a JPEG that loads progressively (coarse \n
  733. to fine).
  734. *@li optimize_size: If True, spend CPU/RAM to reduce size with no quality \n
  735. change.
  736. *@li chroma_downsampling: A boolean, default is true.
  737. *@li density_unit: Unit used to specify x_density and y_density: pixels per \n
  738. inch ('in') or centimeter ('cm').
  739. *@li x_density: Horizontal pixels per density unit.
  740. *@li y_density: Vertical pixels per density unit.
  741. *@li xmp_metadata: If not empty, embed this XMP metadata in the image header.
  742. *@par Outputs:
  743. *contents: 0-D. JPEG-encoded image.
  744. *@par Third-party framework compatibility
  745. *Compatible with tensorflow EncodeJpeg operator.
  746. */
  747. REG_OP(EncodeJpeg)
  748. .INPUT(image, TensorType({DT_UINT8}))
  749. .OUTPUT(contents, TensorType({DT_STRING}))
  750. .ATTR(format, String, "")
  751. .ATTR(quality, Int, 95)
  752. .ATTR(progressive, Bool, false)
  753. .ATTR(optimize_size, Bool, false)
  754. .ATTR(chroma_downsampling, Bool, true)
  755. .ATTR(density_unit, String, "in")
  756. .ATTR(x_density, Int, 300)
  757. .ATTR(y_density, Int, 300)
  758. .ATTR(xmp_metadata, String, "")
  759. .OP_END_FACTORY_REG(EncodeJpeg)
  760. /**
  761. *@brief PNG-encode an image.
  762. *@par Inputs:
  763. *Input image must be unit8 or uint16 type. Inputs include: \n
  764. *image: is a 3-D uint8 or uint16 Tensor of shape [height, width, channels] \n
  765. where channels is: 1: for grayscale; 2: for grayscale + alpha; 3: for RGB; \n
  766. 4: for RGBA.
  767. *@par Attributes:
  768. *compression: Compression level.
  769. *@par Outputs:
  770. *contents: 0-D. PNG-encoded image.
  771. *@par Third-party framework compatibility
  772. *Compatible with tensorflow EncodePng operator.
  773. */
  774. REG_OP(EncodePng)
  775. .INPUT(image, TensorType({DT_UINT8, DT_UINT16}))
  776. .OUTPUT(contents, TensorType({DT_STRING}))
  777. .ATTR(compression, Int, -1)
  778. .OP_END_FACTORY_REG(EncodePng)
  779. /**
  780. *@brief Resizes "images" to "size" using bilinear interpolation.
  781. *@par Inputs:
  782. * One input:
  783. *x: An NC1HWC0 Tensor. \n
  784. * Must be one of the following types: float16, float32.
  785. *@par Attributes:
  786. *@li size: A required int32 Tensor specifying the new size for the images. \n
  787. No default value.
  788. *@li align_corners: An optional bool. If "true", the centers of the corner \n
  789. pixels of the input and output tensors are aligned. Defaults to "false".
  790. *@par Outputs:
  791. *y: A Tensor with type float32 and the same format as input "images".
  792. *@attention Constraints:
  793. *@li The input "size" must be a tensor of 2 elements: size[0] <= 2048, \n
  794. size[1] <= 2048.
  795. *@li The input "images" must be a tensor of 5 elements: images[2] <= 2048, \n
  796. images[3] <= 2048.
  797. *@par Third-party framework compatibility
  798. * Compatible with TensorFlow operator ResizeBilinearV2D.
  799. */
  800. REG_OP(ResizeBilinearV2D)
  801. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  802. .OUTPUT(y, TensorType({DT_FLOAT}))
  803. .ATTR(align_corners, Bool, false)
  804. .ATTR(half_pixel_centers, Bool, false)
  805. .REQUIRED_ATTR(size, ListInt)
  806. .OP_END_FACTORY_REG(ResizeBilinearV2D)
  807. /**
  808. *@brief Resizes "images" to "size" using nearest neighbor interpolation.
  809. *@par Inputs:
  810. * One input:
  811. *x: An NC1HWC0 Tensor. \n
  812. * Must be one of the following types: float16, float32, int32, int8, uint8
  813. *@par Attributes:
  814. *@li size: A required int32 Tensor specifying the new size for the images. \n
  815. No default value.
  816. *@li align_corners: An optional bool. If "true", the centers of the corner \n
  817. pixels of the input and output tensors are aligned. Defaults to "false".
  818. *@par Outputs:
  819. *y: A Tensor with the same type and format as input "images".
  820. *@attention Constraints:
  821. * The input "size" must be a tensor of 2 elements: size[0] <= 7680, \n
  822. size[1] <= 4320
  823. *@par Third-party framework compatibility
  824. * Compatible with TensorFlow operator ResizeNearestNeighborV2.
  825. */
  826. REG_OP(ResizeNearestNeighborV2D)
  827. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  828. .OUTPUT(y, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  829. .REQUIRED_ATTR(size, ListInt)
  830. .ATTR(align_corners, Bool, false)
  831. .ATTR(half_pixel_centers, Bool, false)
  832. .OP_END_FACTORY_REG(ResizeNearestNeighborV2D)
  833. /**
  834. *@brief Extract the shape information of a JPEG-encoded image.
  835. *@par Inputs:
  836. *Input contents must be 0-D. Inputs include: \n
  837. *contents: 0-D. The JPEG-encoded image.
  838. *@par Attributes:
  839. *output_type: The output type of the operation (int32 or int64). Defaults \n
  840. to int32.
  841. *@par Outputs:
  842. *image_shape: 1-D. The image shape with format [height, width, channels].
  843. *@par Third-party framework compatibility
  844. *Compatible with tensorflow ExtractJpegShape operator.
  845. */
  846. REG_OP(ExtractJpegShape)
  847. .INPUT(contents, TensorType({DT_STRING}))
  848. .OUTPUT(image_shape, TensorType({DT_INT32, DT_INT64}))
  849. .REQUIRED_ATTR(output_type, Type)
  850. .OP_END_FACTORY_REG(ExtractJpegShape)
  851. /**
  852. *@brief Draw bounding boxes on a batch of images.
  853. *@par Inputs:
  854. *@li images: 4-D with shape `[batch, height, width, depth]`. \n
  855. A batch of images.
  856. *@li boxes: 3-D with shape `[batch, num_bounding_boxes, 4]` \n
  857. containing bounding boxes.
  858. *@li colors: 2-D. A list of RGBA colors to cycle through for the boxes.
  859. *@par Outputs:
  860. *y: Returns 4-D with the same shape as `images`. \n
  861. The batch of input images with bounding boxes drawn on the images.
  862. *@par Third-party framework compatibility
  863. * Compatible with tensorflow DrawBoundingBoxesV2 operator.
  864. */
  865. REG_OP(DrawBoundingBoxesV2)
  866. .INPUT(images, TensorType({DT_FLOAT}))
  867. .INPUT(boxes, TensorType({DT_FLOAT}))
  868. .INPUT(colors, TensorType({DT_FLOAT}))
  869. .OUTPUT(y, TensorType({DT_FLOAT}))
  870. .OP_END_FACTORY_REG(DrawBoundingBoxesV2)
  871. /**
  872. *@brief Greedily selects a subset of bounding boxes in descending order of score, \n
  873. pruning away boxes that have high intersection-over-union (IOU) overlap \n
  874. with previously selected boxes.
  875. *@par Inputs:
  876. *@li boxes: A 2-D float tensor of shape `[num_boxes, 4]`.
  877. *@li scores: A 1-D float tensor of shape `[num_boxes]` representing a single \n
  878. score corresponding to each box (each row of boxes).
  879. *@li max_output_size: A scalar integer tensor representing the maximum number of \n
  880. boxes to be selected by non max suppression.
  881. *@li iou_threshold: A 0-D float tensor representing the threshold for deciding whether \n
  882. boxes overlap too much with respect to IOU.
  883. *@li score_threshold: A 0-D float tensor representing the threshold for deciding when to \n
  884. remove boxes based on score.
  885. *@li soft_nms_sigma: A 0-D float tensor representing the sigma parameter for Soft NMS.
  886. *@par Attributes:
  887. pad_to_max_output_size: If true, the output `selected_indices` is padded to be of length \n
  888. `max_output_size`. Defaults to false. If not specified, defaults to false.
  889. *@par Outputs:
  890. *@li selected_indices: A 1-D integer tensor of shape [M] representing the \n
  891. selected indices from the boxes tensor, where M <= max_output_size.
  892. *@li selected_scores: A 1-D float tensor of shape `[M]` representing the corresponding \n
  893. scores for each selected box, where `M <= max_output_size`.
  894. *@li valid_outputs: A 0-D integer tensor representing the number of valid \n
  895. elements in selected_indices, with the valid elements appearing first.
  896. *@par Third-party framework compatibility
  897. * Compatible with tensorflow NonMaxSuppressionV5 operator.
  898. */
  899. REG_OP(NonMaxSuppressionV5)
  900. .INPUT(boxes, TensorType({DT_FLOAT16, DT_FLOAT}))
  901. .INPUT(scores, TensorType({DT_FLOAT16, DT_FLOAT}))
  902. .INPUT(max_output_size, TensorType({DT_INT32}))
  903. .INPUT(iou_threshold, TensorType({DT_FLOAT16, DT_FLOAT}))
  904. .INPUT(score_threshold, TensorType({DT_FLOAT16, DT_FLOAT}))
  905. .INPUT(soft_nms_sigma, TensorType({DT_FLOAT16, DT_FLOAT}))
  906. .OUTPUT(selected_indices, TensorType({DT_INT32}))
  907. .OUTPUT(selected_scores, TensorType({DT_FLOAT16, DT_FLOAT}))
  908. .OUTPUT(valid_outputs, TensorType({DT_INT32}))
  909. .ATTR(pad_to_max_output_size, Bool, false)
  910. .REQUIRED_ATTR(T, Type)
  911. .OP_END_FACTORY_REG(NonMaxSuppressionV5)
  912. /**
  913. *@brief Resizes "images" to "size" by scale and translate.
  914. *@par Inputs:
  915. *@li images: A `Tensor`. Must be one of the following types: `int8`, `uint8`, \n
  916. `int16`, `uint16`, `int32`, `int64`, `bfloat16`, `half`, `float32`, `float64`.
  917. *@li size: A `Tensor` of type `int32`.
  918. *@li scale: A `Tensor` of type `float32`.
  919. *@li translation: A `Tensor` of type `float32`.
  920. *@par Outputs:
  921. *y: A Tensor with type float32.
  922. *@par Third-party framework compatibility
  923. * Compatible with TensorFlow ScaleAndTranslate operator.
  924. */
  925. REG_OP(ScaleAndTranslate)
  926. .INPUT(images, TensorType({DT_INT8, DT_UINT8, DT_INT16, DT_UINT16,
  927. DT_INT32, DT_INT64, DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  928. .INPUT(size, TensorType({DT_INT32}))
  929. .INPUT(scale, TensorType({DT_FLOAT}))
  930. .INPUT(translation, TensorType({DT_FLOAT}))
  931. .OUTPUT(y, TensorType({DT_FLOAT}))
  932. .ATTR(kernel_type, String, "lanczos3")
  933. .ATTR(antialias, Bool, true)
  934. .OP_END_FACTORY_REG(ScaleAndTranslate)
  935. /**
  936. *@brief Computes the gradient by scale and translate.
  937. *@par Inputs:
  938. *@li grads: A `Tensor`. Must be one of the following types: `float32`.
  939. *@li original_image: A `Tensor`. Must have the same type as `grads`.
  940. *@li scale: A `Tensor` of type `float32`.
  941. *@li translation: A `Tensor` of type `float32`.
  942. *@par Outputs:
  943. *y: A `Tensor`. Has the same type as `grads`.
  944. *@par Third-party framework compatibility
  945. * Compatible with TensorFlow ScaleAndTranslateGrad operator.
  946. */
  947. REG_OP(ScaleAndTranslateGrad)
  948. .INPUT(grads, TensorType({DT_FLOAT}))
  949. .INPUT(original_image, TensorType({DT_FLOAT}))
  950. .INPUT(scale, TensorType({DT_FLOAT}))
  951. .INPUT(translation, TensorType({DT_FLOAT}))
  952. .OUTPUT(y, TensorType({DT_FLOAT}))
  953. .ATTR(kernel_type, String, "lanczos3")
  954. .ATTR(antialias, Bool, true)
  955. .OP_END_FACTORY_REG(ScaleAndTranslateGrad)
  956. /**
  957. *@brief Greedily selects a subset of bounding boxes in descending order of score, \n
  958. This operation performs non_max_suppression on the inputs per batch, across all classes.
  959. *@par Inputs:
  960. *@li boxes: A 4-D float tensor of shape `[batch_size, num_boxes, q, 4]`. If `q` is 1 then \n
  961. same boxes are used for all classes otherwise, if `q` is equal to number of \n
  962. classes, class-specific boxes are used.
  963. *@li scores: A 3-D float tensor of shape `[batch_size, num_boxes, num_classes]` \n
  964. representing a single score corresponding to each box (each row of boxes).
  965. *@li max_output_size_per_class: A scalar integer tensor representing the maximum number of \n
  966. boxes to be selected by non max suppression per class.
  967. *@li max_total_size: A scalar representing maximum number of boxes retained over all classes. \n
  968. *@li iou_threshold: A 0-D float tensor representing the threshold for deciding whether \n
  969. boxes overlap too much with respect to IOU.
  970. *@li score_threshold: A 0-D float tensor representing the threshold for deciding when to remove \n
  971. boxes based on score.
  972. *@par Attributes:
  973. *@li pad_per_class: If false, the output nmsed boxes, scores and classes \n
  974. are padded/clipped to `max_total_size`. If true, the \n
  975. output nmsed boxes, scores and classes are padded to be of length \n
  976. `max_size_per_class`*`num_classes`, unless it exceeds `max_total_size` in \n
  977. which case it is clipped to `max_total_size`. Defaults to false.
  978. *@li clip_boxes: If true, assume the box coordinates are between [0, 1] and clip the output boxes \n
  979. if they fall beyond [0, 1]. If false, do not do clipping and output the box \n
  980. coordinates as it is. If not specified, defaults to true.
  981. *@par Outputs:
  982. *y: A 1-D integer tensor of shape `[M]` representing the selected \n
  983. indices from the boxes tensor, where `M <= max_output_size`.
  984. *@par Third-party framework compatibility
  985. * Compatible with tensorflow CombinedNonMaxSuppression operator.
  986. */
  987. REG_OP(CombinedNonMaxSuppression)
  988. .INPUT(boxes, TensorType({DT_FLOAT}))
  989. .INPUT(scores, TensorType({DT_FLOAT}))
  990. .INPUT(max_output_size_per_class, TensorType({DT_INT32}))
  991. .INPUT(max_total_size, TensorType({DT_INT32}))
  992. .INPUT(iou_threshold, TensorType({DT_FLOAT}))
  993. .INPUT(score_threshold, TensorType({DT_FLOAT}))
  994. .OUTPUT(nmsed_boxes, TensorType({DT_FLOAT}))
  995. .OUTPUT(nmsed_scores, TensorType({DT_FLOAT}))
  996. .OUTPUT(nmsed_classes, TensorType({DT_FLOAT}))
  997. .OUTPUT(valid_detections, TensorType({DT_INT32}))
  998. .ATTR(pad_per_class, Bool, false)
  999. .ATTR(clip_boxes, Bool, true)
  1000. .OP_END_FACTORY_REG(CombinedNonMaxSuppression)
  1001. REG_OP(SpatialTransformerD)
  1002. .INPUT(x, TensorType({DT_FLOAT,DT_FLOAT16}))
  1003. .OPTIONAL_INPUT(theta, TensorType({DT_FLOAT,DT_FLOAT16}))
  1004. .OUTPUT(y, TensorType({DT_FLOAT,DT_FLOAT16}))
  1005. .ATTR(output_size, ListInt, {-1, -1})
  1006. .ATTR(default_theta, ListFloat, {})
  1007. .ATTR(align_corners, Bool, false)
  1008. .ATTR(use_default_theta, ListBool, {})
  1009. .OP_END_FACTORY_REG(SpatialTransformerD)
  1010. } // namespace ge
  1011. #endif // GE_OP_MAGE_OPS_H_

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