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.

prior_box.h 6.5 kB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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_PRIORBOX_H
  17. #define GE_OP_PRIORBOX_H
  18. #include "graph/operator_reg.h"
  19. namespace ge {
  20. /**
  21. *@brief Performs SSD prior box detection.
  22. *@par Inputs:
  23. * Two inputs, including:
  24. *@li feature: An NC1HWC0 or NCHW feature map of type is float32 or float16.
  25. *@li img: source image. Has the same type and format as "feature".
  26. *@par Attributes:
  27. *@li min_size: A required float32, specifying the minimum edge length of a square prior box.
  28. *@li max_size: A required float32, specifying the maximum edge length of a square prior box: sqrt(min_size * max_size)
  29. *@li aspect_ratio: An optional float32, specifying the aspect ratio for generated rectangle boxes. The height is min_size/sqrt(aspect_ratio), the width is min_size*sqrt(aspect_ratio). Defaults to "1.0".
  30. *@li img_size: An optional int32, specifying the source image size. Defaults to "0".
  31. *@li img_h: An optional int32, specifying the source image height. Defaults to "0".
  32. *@li img_w: An optional int32, specifying the source image width. Defaults to "0".
  33. *@li step: An optional float32, specifying the step for mapping the center point from the feature map to the source image. Defaults to "0.0".
  34. *@li step_h: An optional float32, specifying the height step for mapping the center point from the feature map to the source image. Defaults to "0.0".
  35. *@li step_w: An optional float32, specifying the width step for mapping the center point from the feature map to the source image. Defaults to "0.0".
  36. *@li flip: An optional bool. If "True", "aspect_ratio" will be flipped. Defaults to "True".
  37. *@li clip: An optional bool. If "True", a prior box is clipped to within [0, 1]. Defaults to "False".
  38. *@li offset: An optional float32, specifying the offset. Defaults to "0.5".
  39. *@li variance: An optional float32, specifying the variance of a prior box, either one or four variances. Defaults to "0.1" (one value).
  40. *@par Outputs:
  41. *y: An ND tensor of type float32 or float16, specifying the prior box information, including its coordinates and variance.
  42. *@attention Constraints:\n
  43. * This operator applies only to SSD networks.
  44. *@see SSDDetectionOutput()
  45. */
  46. REG_OP(PriorBox)
  47. .INPUT(feature, TensorType({DT_FLOAT16, DT_FLOAT}))
  48. .INPUT(img, TensorType({DT_FLOAT16, DT_FLOAT}))
  49. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  50. .REQUIRED_ATTR(min_size, ListFloat)
  51. .REQUIRED_ATTR(max_size, ListFloat)
  52. .ATTR(aspect_ratio, ListFloat, {1.0})
  53. .ATTR(img_size, Int, 0)
  54. .ATTR(img_h, Int, 0)
  55. .ATTR(img_w, Int, 0)
  56. .ATTR(step, Float, 0.0)
  57. .ATTR(step_h, Float, 0.0)
  58. .ATTR(step_w, Float, 0.0)
  59. .ATTR(flip, Bool, true)
  60. .ATTR(clip, Bool, false)
  61. .ATTR(offset, Float, 0.5)
  62. .ATTR(variance, ListFloat, {0.1})
  63. .OP_END_FACTORY_REG(PriorBox);
  64. /**
  65. *@brief Performs SSD prior box detection, with four additional matrices and the "aspect_ratio" attribute deleted compared to PriorBox.
  66. *@par Inputs:
  67. * Six inputs, including:
  68. *@li feature: An NC1HWC0 or NCHW feature map of type is float32 or float16.
  69. *@li img: source image. Has the same type and format as "feature".
  70. *@li data_h: An NC1HWC0 or NCHW tensor of type float32 or float16, specifying the matrix for indexing the feature map height.
  71. *@li data_w: An NC1HWC0 or NCHW tensor of type float32 or float16, specifying the matrix for indexing the feature map width.
  72. *@li box_height: An NC1HWC0 or NCHW tensor of type float32 or float16, specifying the height of each prior box.
  73. *@li box_width: An NC1HWC0 or NCHW tensor of type float32 or float16, specifying the width of each prior box.
  74. *@par Attributes:
  75. *@li min_size: A required float32, specifying the minimum edge length of a square prior box.
  76. *@li max_size: A required float32, specifying the maximum edge length of a square prior box: sqrt(min_size * max_size)
  77. *@li img_size: An optional int32, specifying the size of the source image.
  78. *@li img_h: An optional int32, specifying the height of the source image.
  79. *@li img_w: An optional int32, specifying the width of the source image.
  80. *@li step: An optional float32, specifying the step for mapping the center point from the feature map to the source image.
  81. *@li step_h: An optional float32, specifying the height step for mapping the center point from the feature map to the source image.
  82. *@li step_w: An optional float32, specifying the width step for mapping the center point from the feature map to the source image.
  83. *@li flip: An optional bool. If "True", "aspect_ratio" will be flipped. Defaults to "True".
  84. *@li clip: An optional bool. If "True", a prior box is clipped to within [0, 1]. Defaults to "False".
  85. *@li offset: An optional float32, specifying the offset. Defaults to "0.5".
  86. *@li variance: An optional float32, specifying the variance of a prior box, either one or four variances. Defaults to "0.1" (one value).
  87. *@par Outputs:
  88. *y: An ND tensor of type float32 or float16, specifying the prior box information, including its coordinates and variance.
  89. *@attention Constraints:\n
  90. * This operator applies only to SSD networks.
  91. *@see SSDDetectionOutput()
  92. */
  93. REG_OP(PriorBoxD)
  94. .INPUT(feature, TensorType({DT_FLOAT16, DT_FLOAT}))
  95. .INPUT(img, TensorType({DT_FLOAT16, DT_FLOAT}))
  96. .INPUT(data_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  97. .INPUT(data_w, TensorType({DT_FLOAT16, DT_FLOAT}))
  98. .INPUT(box_height, TensorType({DT_FLOAT16, DT_FLOAT}))
  99. .INPUT(box_width, TensorType({DT_FLOAT16, DT_FLOAT}))
  100. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  101. .REQUIRED_ATTR(min_size, ListFloat)
  102. .REQUIRED_ATTR(max_size, ListFloat)
  103. .ATTR(img_size, Int, 0)
  104. .ATTR(img_h, Int, 0)
  105. .ATTR(img_w, Int, 0)
  106. .ATTR(step, Float, 0.0)
  107. .ATTR(step_h, Float, 0.0)
  108. .ATTR(step_w, Float, 0.0)
  109. .ATTR(flip, Bool, true)
  110. .ATTR(clip, Bool, false)
  111. .ATTR(offset, Float, 0.5)
  112. .ATTR(variance, ListFloat, {0.1})
  113. .OP_END_FACTORY_REG(PriorBoxD);
  114. } // namespace ge
  115. #endif // GE_OP_PRIORBOX_H

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

Contributors (1)