Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Mohammed Suhail Munshi | d538d16 | 2023-02-16 16:22:32 +0000 | [diff] [blame] | 2 | * Copyright (c) 2016-2023 Arm Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
Jakub Sujak | 0d27b2e | 2023-08-24 14:01:20 +0100 | [diff] [blame^] | 24 | #ifndef ACL_ARM_COMPUTE_CORE_TYPES_H |
| 25 | #define ACL_ARM_COMPUTE_CORE_TYPES_H |
SiCong Li | 9129549 | 2023-07-21 18:16:13 +0100 | [diff] [blame] | 26 | |
| 27 | /** The following symbols have been moved to: |
| 28 | * half |
| 29 | * PermutationVector |
| 30 | * Format |
| 31 | * DataType |
| 32 | * DataLayout |
| 33 | * DataLayoutDimension |
| 34 | * PadStrideInfo |
| 35 | * WeightFormat |
| 36 | * Channel |
| 37 | * DimensionRoundingType |
| 38 | */ |
| 39 | #include "arm_compute/core/CoreTypes.h" |
| 40 | /** The following symbols have been moved to: |
| 41 | * ActivationFunction |
| 42 | * ActivationLayerInfo |
| 43 | */ |
| 44 | #include "arm_compute/function_info/ActivationLayerInfo.h" |
| 45 | /** The following symbols have been moved to: |
| 46 | * ConvolutionInfo |
| 47 | */ |
| 48 | #include "arm_compute/function_info/ConvolutionInfo.h" |
| 49 | /** The following symbols have been moved to: |
| 50 | * FullyConnectedLayerInfo |
| 51 | */ |
| 52 | #include "arm_compute/function_info/FullyConnectedLayerInfo.h" |
| 53 | /** The following symbols have been moved to: |
| 54 | * GEMMLowpOutputStageType |
| 55 | * GEMMLowpOutputStageInfo |
| 56 | * GEMMInfo |
| 57 | */ |
| 58 | #include "arm_compute/function_info/GEMMInfo.h" |
| 59 | /** The following symbols have been moved to: |
| 60 | * MatMulInfo |
| 61 | */ |
| 62 | #include "arm_compute/function_info/MatMulInfo.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 63 | |
| 64 | #include "arm_compute/core/Coordinates.h" |
Isabella Gottardi | 6e464c3 | 2018-01-26 12:32:45 +0000 | [diff] [blame] | 65 | #include "arm_compute/core/Size2D.h" |
Adnan AlSinan | e4563a0 | 2021-09-01 15:32:03 +0100 | [diff] [blame] | 66 | #include "arm_compute/core/Size3D.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 67 | #include "arm_compute/core/TensorShape.h" |
Sang-Hoon Park | 11fedda | 2020-01-15 14:44:04 +0000 | [diff] [blame] | 68 | #include "arm_compute/core/utils/misc/Macros.h" |
Georgios Pinitas | e8291ac | 2020-02-26 09:58:13 +0000 | [diff] [blame] | 69 | #include "support/Bfloat16.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 70 | |
Michel Iwaniec | 5dfeae6 | 2017-11-29 10:48:23 +0000 | [diff] [blame] | 71 | #include <cmath> |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 72 | #include <cstddef> |
| 73 | #include <cstdint> |
Isabella Gottardi | a7acb3c | 2019-01-08 13:48:44 +0000 | [diff] [blame] | 74 | #include <map> |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 75 | #include <string> |
| 76 | #include <utility> |
| 77 | |
| 78 | namespace arm_compute |
| 79 | { |
Georgios Pinitas | 77589b5 | 2018-08-21 14:41:35 +0100 | [diff] [blame] | 80 | /** Bidirectional strides */ |
| 81 | using BiStrides = Coordinates; |
Georgios Pinitas | 8795ffb | 2017-12-01 16:13:40 +0000 | [diff] [blame] | 82 | |
Daniil Efremov | 02bf80d | 2017-11-22 00:26:51 +0700 | [diff] [blame] | 83 | /** Available Sampling Policies */ |
| 84 | enum class SamplingPolicy |
| 85 | { |
| 86 | CENTER, /**< Samples are taken at pixel center */ |
| 87 | TOP_LEFT /**< Samples are taken at pixel top left corner */ |
| 88 | }; |
| 89 | |
Georgios Pinitas | 7900a9e | 2018-11-23 11:44:58 +0000 | [diff] [blame] | 90 | /** Available ConvolutionMethod*/ |
| 91 | enum class ConvolutionMethod |
| 92 | { |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 93 | GEMM, /**< Convolution using GEMM */ |
| 94 | GEMM_CONV2D, /**< Direct 2D GEMM convolution */ |
| 95 | DIRECT, /**< Direct convolution */ |
Gian Marco Iodice | a5cb79f | 2022-12-28 13:53:51 +0000 | [diff] [blame] | 96 | INDIRECT, /**< Indirect convolution */ |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 97 | WINOGRAD, /**< Convolution using Winograd */ |
| 98 | FFT /**< Convolution using FFT */ |
Georgios Pinitas | 7900a9e | 2018-11-23 11:44:58 +0000 | [diff] [blame] | 99 | }; |
| 100 | |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 101 | /** Available DepthwiseConvolutionFunction*/ |
| 102 | enum class DepthwiseConvolutionFunction |
| 103 | { |
| 104 | OPTIMIZED, /**< Optimized Depthwise Convolution */ |
| 105 | GENERIC, /**< Generic Depthwise Convolution */ |
| 106 | }; |
| 107 | |
giuros01 | 46a49a0 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 108 | /** Available DeconvolutionMethod*/ |
| 109 | enum class DeconvolutionMethod |
| 110 | { |
SiCong Li | 4ceb453 | 2023-03-13 15:02:23 +0000 | [diff] [blame] | 111 | GEMM, /**< Deconvolution using GEMM */ |
| 112 | DIRECT, /**< Direct deconvolution */ |
| 113 | UPSCALE_CONV2D /**< Deconvolution with Upscaling */ |
giuros01 | 46a49a0 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 114 | }; |
| 115 | |
Manuel Bottini | 2732cca | 2019-05-28 11:44:41 +0100 | [diff] [blame] | 116 | /** Available FuseBatchNormalizationType*/ |
| 117 | enum class FuseBatchNormalizationType |
| 118 | { |
| 119 | CONVOLUTION, /**< For Convolution weights */ |
| 120 | DEPTHWISECONVOLUTION /**< For Depthwise Convolution weights*/ |
| 121 | }; |
| 122 | |
Usama Arif | 89890c6 | 2019-03-19 10:57:05 +0000 | [diff] [blame] | 123 | /** Padding mode to use for PadLayer */ |
| 124 | enum class PaddingMode |
| 125 | { |
| 126 | CONSTANT, |
| 127 | REFLECT, |
| 128 | SYMMETRIC |
| 129 | }; |
| 130 | |
Georgios Pinitas | 7900a9e | 2018-11-23 11:44:58 +0000 | [diff] [blame] | 131 | /** Supported comparison operations */ |
| 132 | enum class ComparisonOperation |
| 133 | { |
| 134 | Equal, /**< Equal comparison ( \f$ x == y \f$ ) */ |
| 135 | NotEqual, /**< NotEqual comparison ( \f$ x != y \f$ ) */ |
| 136 | Greater, /**< Greater comparison ( \f$ x > y \f$ ) */ |
| 137 | GreaterEqual, /**< Greater equal comparison ( \f$ x >= y \f$ ) */ |
| 138 | Less, /**< Less comparison ( \f$ x < y \f$ ) */ |
| 139 | LessEqual /**< Less equal comparison ( \f$ x <= y \f$ ) */ |
| 140 | }; |
| 141 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 142 | /** Container for valid region of a window */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 143 | struct ValidRegion |
| 144 | { |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 145 | /** Default constructor */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 146 | ValidRegion() |
| 147 | : anchor{}, shape{} |
| 148 | { |
| 149 | } |
| 150 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 151 | /** Allow instances of this class to be copy constructed */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 152 | ValidRegion(const ValidRegion &) = default; |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 153 | /** Allow instances of this class to be move constructed */ |
| 154 | ValidRegion(ValidRegion &&) = default; |
| 155 | /** Allow instances of this class to be copied */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 156 | ValidRegion &operator=(const ValidRegion &) = default; |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 157 | /** Allow instances of this class to be moved */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 158 | ValidRegion &operator=(ValidRegion &&) = default; |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 159 | /** Default destructor */ |
| 160 | ~ValidRegion() = default; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 161 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 162 | /** Constructor for a valid region with default number of dimensions |
| 163 | * |
| 164 | * @param[in] an_anchor Anchor for the start of the valid region. |
| 165 | * @param[in] a_shape Shape of the valid region. |
| 166 | * |
| 167 | */ |
Diego Lopez Recas | bcbc970 | 2017-12-18 11:28:27 +0000 | [diff] [blame] | 168 | ValidRegion(const Coordinates &an_anchor, const TensorShape &a_shape) |
| 169 | : anchor{ an_anchor }, shape{ a_shape } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 170 | { |
Diego Lopez Recas | bcbc970 | 2017-12-18 11:28:27 +0000 | [diff] [blame] | 171 | anchor.set_num_dimensions(std::max(anchor.num_dimensions(), shape.num_dimensions())); |
| 172 | } |
| 173 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 174 | /** Constructor for a valid region with specified number of dimensions |
| 175 | * |
| 176 | * @param[in] an_anchor Anchor for the start of the valid region. |
| 177 | * @param[in] a_shape Shape of the valid region. |
| 178 | * @param[in] num_dimensions Number of dimensions (must be >= number of dimensions of anchor and shape). |
| 179 | * |
| 180 | */ |
Diego Lopez Recas | bcbc970 | 2017-12-18 11:28:27 +0000 | [diff] [blame] | 181 | ValidRegion(const Coordinates &an_anchor, const TensorShape &a_shape, size_t num_dimensions) |
| 182 | : anchor{ an_anchor }, shape{ a_shape } |
| 183 | { |
| 184 | ARM_COMPUTE_ERROR_ON(num_dimensions < std::max(anchor.num_dimensions(), shape.num_dimensions())); |
| 185 | anchor.set_num_dimensions(num_dimensions); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | /** Return the start of the valid region for the given dimension @p d */ |
| 189 | int start(unsigned int d) const |
| 190 | { |
| 191 | return anchor[d]; |
| 192 | } |
| 193 | |
| 194 | /** Return the end of the valid region for the given dimension @p d */ |
| 195 | int end(unsigned int d) const |
| 196 | { |
| 197 | return anchor[d] + shape[d]; |
| 198 | } |
| 199 | |
Diego Lopez Recas | 35ceeb2 | 2017-12-04 18:56:10 +0000 | [diff] [blame] | 200 | /** Accessor to set the value of anchor and shape for one of the dimensions. |
| 201 | * |
| 202 | * @param[in] dimension Dimension for which the value is set. |
| 203 | * @param[in] start Value to be set in anchor for the dimension. |
| 204 | * @param[in] size Value to be set in shape for the dimension. |
| 205 | * |
| 206 | * @return *this. |
| 207 | */ |
| 208 | ValidRegion &set(size_t dimension, int start, size_t size) |
| 209 | { |
| 210 | anchor.set(dimension, start); |
| 211 | shape.set(dimension, size); |
| 212 | return *this; |
| 213 | } |
| 214 | |
SiCong Li | b63b119 | 2022-01-28 18:24:39 +0000 | [diff] [blame] | 215 | /** Check whether two valid regions are equal. |
| 216 | * |
| 217 | * @param[in] lhs LHS valid region |
| 218 | * @param[in] rhs RHS valid region |
| 219 | * |
| 220 | * @return True if the valid regions are the same. |
| 221 | */ |
| 222 | inline friend bool operator==(const ValidRegion &lhs, const ValidRegion &rhs); |
| 223 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 224 | Coordinates anchor; /**< Anchor for the start of the valid region. */ |
| 225 | TensorShape shape; /**< Shape of the valid region. */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 226 | }; |
SiCong Li | b63b119 | 2022-01-28 18:24:39 +0000 | [diff] [blame] | 227 | inline bool operator==(const ValidRegion &lhs, const ValidRegion &rhs) |
| 228 | { |
| 229 | return (lhs.anchor == rhs.anchor) && (lhs.shape == rhs.shape); |
| 230 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 231 | |
| 232 | /** Methods available to handle borders */ |
| 233 | enum class BorderMode |
| 234 | { |
| 235 | UNDEFINED, /**< Borders are left undefined */ |
| 236 | CONSTANT, /**< Pixels outside the image are assumed to have a constant value */ |
| 237 | REPLICATE /**< Pixels outside the image are assumed to have the same value as the closest image pixel */ |
| 238 | }; |
| 239 | |
| 240 | /** Container for 2D border size */ |
| 241 | struct BorderSize |
| 242 | { |
| 243 | /** Empty border, i.e. no border */ |
Pablo Marquez Tello | 383de02 | 2021-03-18 11:31:13 +0000 | [diff] [blame] | 244 | constexpr BorderSize() noexcept |
| 245 | : top{ 0 }, |
| 246 | right{ 0 }, |
| 247 | bottom{ 0 }, |
| 248 | left{ 0 } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 249 | { |
| 250 | } |
| 251 | |
| 252 | /** Border with equal size around the 2D plane */ |
Pablo Marquez Tello | 383de02 | 2021-03-18 11:31:13 +0000 | [diff] [blame] | 253 | explicit constexpr BorderSize(unsigned int size) noexcept |
| 254 | : top{ size }, |
| 255 | right{ size }, |
| 256 | bottom{ size }, |
| 257 | left{ size } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 258 | { |
| 259 | } |
| 260 | |
| 261 | /** Border with same size for top/bottom and left/right */ |
| 262 | constexpr BorderSize(unsigned int top_bottom, unsigned int left_right) |
| 263 | : top{ top_bottom }, right{ left_right }, bottom{ top_bottom }, left{ left_right } |
| 264 | { |
| 265 | } |
| 266 | |
| 267 | /** Border with different sizes */ |
| 268 | constexpr BorderSize(unsigned int top, unsigned int right, unsigned int bottom, unsigned int left) |
| 269 | : top{ top }, right{ right }, bottom{ bottom }, left{ left } |
| 270 | { |
| 271 | } |
| 272 | |
| 273 | /** Check if the entire border is zero */ |
| 274 | constexpr bool empty() const |
| 275 | { |
| 276 | return top == 0 && right == 0 && bottom == 0 && left == 0; |
| 277 | } |
| 278 | |
| 279 | /** Check if the border is the same size on all sides */ |
| 280 | constexpr bool uniform() const |
| 281 | { |
| 282 | return top == right && top == bottom && top == left; |
| 283 | } |
| 284 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 285 | /** Scale this border size. |
| 286 | * |
| 287 | * @param[in] scale Scale to multiply border size by. |
| 288 | * |
| 289 | * @return *this. |
| 290 | */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 291 | BorderSize &operator*=(float scale) |
| 292 | { |
| 293 | top *= scale; |
| 294 | right *= scale; |
| 295 | bottom *= scale; |
| 296 | left *= scale; |
| 297 | |
| 298 | return *this; |
| 299 | } |
| 300 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 301 | /** Scale a copy of this border size. |
| 302 | * |
| 303 | * @param[in] scale Scale to multiply border size by. |
| 304 | * |
| 305 | * @return a scaled copy of this. |
| 306 | */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 307 | BorderSize operator*(float scale) |
| 308 | { |
| 309 | BorderSize size = *this; |
| 310 | size *= scale; |
| 311 | |
| 312 | return size; |
| 313 | } |
| 314 | |
Giorgio Arena | 1e2af2a | 2020-10-15 17:39:41 +0100 | [diff] [blame] | 315 | /** Check equality with another BorderSize struct |
| 316 | * |
| 317 | * @param[in] rhs other struct to check against |
| 318 | * |
| 319 | * @return true if they are equal |
| 320 | */ |
SiCong Li | b63b119 | 2022-01-28 18:24:39 +0000 | [diff] [blame] | 321 | bool operator==(const BorderSize &rhs) const |
Giorgio Arena | 1e2af2a | 2020-10-15 17:39:41 +0100 | [diff] [blame] | 322 | { |
| 323 | return (top == rhs.top) && (right == rhs.right) && (bottom == rhs.bottom) && (left == rhs.left); |
| 324 | } |
| 325 | |
| 326 | /** Check non-equality with another BorderSize struct |
| 327 | * |
| 328 | * @param[in] rhs other struct to check against |
| 329 | * |
| 330 | * @return true if they are different |
| 331 | */ |
SiCong Li | b63b119 | 2022-01-28 18:24:39 +0000 | [diff] [blame] | 332 | bool operator!=(const BorderSize &rhs) const |
Giorgio Arena | 1e2af2a | 2020-10-15 17:39:41 +0100 | [diff] [blame] | 333 | { |
| 334 | return !(*this == rhs); |
| 335 | } |
| 336 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 337 | /** Limit this border size. |
| 338 | * |
| 339 | * @param[in] limit Border size to limit this border size to. |
| 340 | */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 341 | void limit(const BorderSize &limit) |
| 342 | { |
| 343 | top = std::min(top, limit.top); |
| 344 | right = std::min(right, limit.right); |
| 345 | bottom = std::min(bottom, limit.bottom); |
| 346 | left = std::min(left, limit.left); |
| 347 | } |
| 348 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 349 | unsigned int top; /**< top of the border */ |
| 350 | unsigned int right; /**< right of the border */ |
| 351 | unsigned int bottom; /**< bottom of the border */ |
| 352 | unsigned int left; /**< left of the border */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 353 | }; |
| 354 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 355 | /** Container for 2D padding size */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 356 | using PaddingSize = BorderSize; |
| 357 | |
SiCongLi | 1af5416 | 2021-10-06 15:25:57 +0100 | [diff] [blame] | 358 | /** Policy to handle integer overflow |
| 359 | * @note: This is ignored by floating point operations where the overflow behavior adheres to the IEEE-754 standard |
| 360 | * which states that in case of overflow ±infinity is returned for the round-to-nearest modes (and follows the |
| 361 | * rounding rules for the directed rounding modes) by default. |
| 362 | */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 363 | enum class ConvertPolicy |
| 364 | { |
| 365 | WRAP, /**< Wrap around */ |
| 366 | SATURATE /**< Saturate */ |
| 367 | }; |
| 368 | |
| 369 | /** Interpolation method */ |
| 370 | enum class InterpolationPolicy |
| 371 | { |
| 372 | NEAREST_NEIGHBOR, /**< Output values are defined to match the source pixel whose center is nearest to the sample position */ |
| 373 | BILINEAR, /**< Output values are defined by bilinear interpolation between the pixels */ |
| 374 | AREA, /**< Output values are determined by averaging the source pixels whose areas fall under the area of the destination pixel, projected onto the source image */ |
| 375 | }; |
| 376 | |
| 377 | /** Bilinear Interpolation method used by LKTracker */ |
| 378 | enum class BilinearInterpolation |
| 379 | { |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 380 | BILINEAR_OLD_NEW, /**< Old-new method */ |
| 381 | BILINEAR_SCHARR /**< Scharr method */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 382 | }; |
| 383 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 384 | /** Rectangle type */ |
| 385 | struct Rectangle |
| 386 | { |
| 387 | uint16_t x; /**< Top-left x coordinate */ |
| 388 | uint16_t y; /**< Top-left y coordinate */ |
| 389 | uint16_t width; /**< Width of the rectangle */ |
| 390 | uint16_t height; /**< Height of the rectangle */ |
| 391 | }; |
| 392 | |
| 393 | /** Coordinate type */ |
| 394 | struct Coordinates2D |
| 395 | { |
| 396 | int32_t x; /**< X coordinates */ |
| 397 | int32_t y; /**< Y coordinates */ |
| 398 | }; |
| 399 | |
| 400 | /** Coordinate type */ |
| 401 | struct Coordinates3D |
| 402 | { |
| 403 | uint32_t x; /**< X coordinates */ |
| 404 | uint32_t y; /**< Y coordinates */ |
| 405 | uint32_t z; /**< Z coordinates */ |
| 406 | }; |
| 407 | |
Giuseppe Rossini | d7647d4 | 2018-07-17 18:13:13 +0100 | [diff] [blame] | 408 | /** Padding information as a pair of unsigned int start/end */ |
| 409 | using PaddingInfo = std::pair<uint32_t, uint32_t>; |
| 410 | |
| 411 | /** List of padding information */ |
| 412 | using PaddingList = std::vector<PaddingInfo>; |
| 413 | |
giuros01 | 3175fcf | 2018-11-21 09:59:17 +0000 | [diff] [blame] | 414 | /** Information to produce a tiled version of a Tensor */ |
| 415 | using Multiples = std::vector<uint32_t>; |
| 416 | |
Georgios Pinitas | d976958 | 2017-08-03 10:19:40 +0100 | [diff] [blame] | 417 | /** Available reduction operations */ |
| 418 | enum class ReductionOperation |
| 419 | { |
Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +0000 | [diff] [blame] | 420 | ARG_IDX_MAX, /**< Index of the max value */ |
Manuel Bottini | b412fab | 2018-12-10 17:40:23 +0000 | [diff] [blame] | 421 | ARG_IDX_MIN, /**< Index of the min value */ |
| 422 | MEAN_SUM, /**< Mean of sum */ |
| 423 | PROD, /**< Product */ |
| 424 | SUM_SQUARE, /**< Sum of squares */ |
Usama Arif | a4a08ad | 2019-05-20 12:38:33 +0100 | [diff] [blame] | 425 | SUM, /**< Sum */ |
| 426 | MIN, /**< Min */ |
Usama Arif | 28f0dd9 | 2019-05-20 13:44:34 +0100 | [diff] [blame] | 427 | MAX, /**< Max */ |
Georgios Pinitas | d976958 | 2017-08-03 10:19:40 +0100 | [diff] [blame] | 428 | }; |
| 429 | |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 430 | /** Available element-wise operations */ |
| 431 | enum class ArithmeticOperation |
| 432 | { |
| 433 | ADD, /**< (x + y) */ |
| 434 | SUB, /**< (x - y) */ |
| 435 | DIV, /**< (x / y) */ |
| 436 | MIN, /**< Min(x, y) */ |
| 437 | MAX, /**< Max(x, y) */ |
| 438 | SQUARED_DIFF, /**< (x - y)^2 */ |
Usama Arif | 81e671e | 2019-05-13 13:33:14 +0100 | [diff] [blame] | 439 | POWER, /**< x ^ y */ |
giuros01 | 1e6e1b8 | 2019-05-14 16:12:53 +0100 | [diff] [blame] | 440 | PRELU, /**< y*x if x < 0, x otherwise */ |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 441 | }; |
| 442 | |
Michalis Spyrou | e936262 | 2018-11-23 17:41:37 +0000 | [diff] [blame] | 443 | /** Available element wise unary operations */ |
| 444 | enum class ElementWiseUnary |
| 445 | { |
Sang-Hoon Park | 75eea33 | 2020-11-13 13:44:13 +0000 | [diff] [blame] | 446 | RSQRT, /**< Reverse square root */ |
| 447 | EXP, /**< Exponential */ |
| 448 | NEG, /**< Negate */ |
| 449 | LOG, /**< Natural Logarithm */ |
| 450 | ABS, /**< Absolute value */ |
| 451 | SIN, /**< Sine */ |
| 452 | ROUND, /**< Round */ |
| 453 | LOGICAL_NOT, /**< Logical Not */ |
Michalis Spyrou | e936262 | 2018-11-23 17:41:37 +0000 | [diff] [blame] | 454 | }; |
| 455 | |
Manuel Bottini | 63bb7ca | 2020-12-02 13:22:14 +0000 | [diff] [blame] | 456 | /** Available bitwise operations */ |
| 457 | enum class BitwiseOperation |
| 458 | { |
| 459 | AND, /**< Bitwise AND operation */ |
| 460 | NOT, /**< Bitwise NOT operation */ |
| 461 | OR, /**< Bitwise OR operation */ |
| 462 | XOR, /**< Bitwise XOR operation */ |
| 463 | }; |
| 464 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 465 | /** The normalization type used for the normalization layer */ |
| 466 | enum class NormType |
| 467 | { |
| 468 | IN_MAP_1D, /**< Normalization applied within the same map in 1D region */ |
| 469 | IN_MAP_2D, /**< Normalization applied within the same map in 2D region */ |
| 470 | CROSS_MAP /**< Normalization applied cross maps */ |
| 471 | }; |
| 472 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 473 | /** Detection window used for the object detection. The detection window keeps the following information: |
| 474 | * |
| 475 | * -# Geometry of the rectangular window (x/y of top-left corner and width/height) |
| 476 | * -# Index of the class used for evaluating which class the detection window belongs to |
| 477 | * -# Confidence value (score) obtained with the classifier |
| 478 | */ |
| 479 | struct DetectionWindow |
| 480 | { |
| 481 | uint16_t x{ 0 }; /**< Top-left x coordinate */ |
| 482 | uint16_t y{ 0 }; /**< Top-left y coordinate */ |
| 483 | uint16_t width{ 0 }; /**< Width of the detection window */ |
| 484 | uint16_t height{ 0 }; /**< Height of the detection window */ |
| 485 | uint16_t idx_class{ 0 }; /**< Index of the class */ |
| 486 | float score{ 0.f }; /**< Confidence value for the detection window */ |
| 487 | }; |
| 488 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 489 | /** Available pooling types */ |
| 490 | enum class PoolingType |
| 491 | { |
| 492 | MAX, /**< Max Pooling */ |
Georgios Pinitas | cdf5145 | 2017-08-31 14:21:36 +0100 | [diff] [blame] | 493 | AVG, /**< Average Pooling */ |
| 494 | L2 /**< L2 Pooling */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 495 | }; |
| 496 | |
Michalis Spyrou | 2709d61 | 2018-09-19 09:46:47 +0100 | [diff] [blame] | 497 | /** Available non maxima suppression types */ |
| 498 | enum class NMSType |
| 499 | { |
| 500 | LINEAR, /**< Linear NMS */ |
| 501 | GAUSSIAN, /**< Gaussian NMS */ |
| 502 | ORIGINAL /**< Original NMS */ |
| 503 | }; |
| 504 | |
| 505 | /** BoxWithNonMaximaSuppressionLimit Information class */ |
| 506 | class BoxNMSLimitInfo final |
| 507 | { |
| 508 | public: |
| 509 | /** Constructor |
| 510 | * |
| 511 | * @param[in] score_thresh (Optional) Score threshold. |
| 512 | * @param[in] nms (Optional) NMS value |
| 513 | * @param[in] detections (Optional) Number of detections |
| 514 | * @param[in] soft_nms_enabled (Optional) Enable SoftNMS |
| 515 | * @param[in] soft_nms_method (Optional) Soft NMS method |
| 516 | * @param[in] soft_nms_sigma (Optional) Soft NMS sigma value |
| 517 | * @param[in] soft_nms_min_score_thres (Optional) Soft NMS minimum score threshold |
Manuel Bottini | 5209be5 | 2019-02-13 16:34:56 +0000 | [diff] [blame] | 518 | * @param[in] suppress_size (Optional) Filter out boxes based on their size. Defaults to false |
| 519 | * @param[in] min_size (Optional) Smaller boxes than min_size will be filtered out. Defaults to 1 |
| 520 | * @param[in] im_width (Optional) Boxes whose centers (on the x axis) is beyond im_width will be filtered. Defaults to 1 |
| 521 | * @param[in] im_height (Optional) Boxes whose centers (on the y axis) is beyond im_height will be filtered. Defaults to 1 |
Michalis Spyrou | 2709d61 | 2018-09-19 09:46:47 +0100 | [diff] [blame] | 522 | */ |
| 523 | BoxNMSLimitInfo(float score_thresh = 0.05f, float nms = 0.3f, |
| 524 | int detections = 100, bool soft_nms_enabled = false, |
| 525 | NMSType soft_nms_method = NMSType::LINEAR, |
Manuel Bottini | 5209be5 | 2019-02-13 16:34:56 +0000 | [diff] [blame] | 526 | float soft_nms_sigma = 0.5f, float soft_nms_min_score_thres = 0.001f, bool suppress_size = false, float min_size = 1.0f, float im_width = 1.0f, float im_height = 1.0f) |
Michalis Spyrou | 2709d61 | 2018-09-19 09:46:47 +0100 | [diff] [blame] | 527 | : _score_thresh(score_thresh), _nms(nms), _detections_per_im(detections), _soft_nms_enabled(soft_nms_enabled), _soft_nms_method(soft_nms_method), _soft_nms_sigma(soft_nms_sigma), |
Manuel Bottini | 5209be5 | 2019-02-13 16:34:56 +0000 | [diff] [blame] | 528 | _soft_nms_min_score_thres(soft_nms_min_score_thres), _suppress_size(suppress_size), _min_size(min_size), _im_width(im_width), _im_height(im_height) |
Michalis Spyrou | 2709d61 | 2018-09-19 09:46:47 +0100 | [diff] [blame] | 529 | { |
| 530 | } |
| 531 | /** Get the score threshold */ |
| 532 | float score_thresh() const |
| 533 | { |
| 534 | return _score_thresh; |
| 535 | } |
| 536 | /** Get the NMS */ |
| 537 | float nms() const |
| 538 | { |
| 539 | return _nms; |
| 540 | } |
| 541 | /** Get the number of detections */ |
| 542 | int detections_per_im() const |
| 543 | { |
| 544 | return _detections_per_im; |
| 545 | } |
| 546 | /** Check if soft NMS is enabled */ |
| 547 | bool soft_nms_enabled() const |
| 548 | { |
| 549 | return _soft_nms_enabled; |
| 550 | } |
| 551 | /** Get soft NMS method */ |
| 552 | NMSType soft_nms_method() const |
| 553 | { |
| 554 | return _soft_nms_method; |
| 555 | } |
| 556 | /** Get soft NMS sigma */ |
| 557 | float soft_nms_sigma() const |
| 558 | { |
| 559 | return _soft_nms_sigma; |
| 560 | } |
| 561 | /** Get soft nms min score threshold */ |
| 562 | float soft_nms_min_score_thres() const |
| 563 | { |
| 564 | return _soft_nms_min_score_thres; |
| 565 | } |
Manuel Bottini | 5209be5 | 2019-02-13 16:34:56 +0000 | [diff] [blame] | 566 | /** Get if NMS will suppress boxes based on their size/position */ |
| 567 | bool suppress_size() const |
| 568 | { |
| 569 | return _suppress_size; |
| 570 | } |
| 571 | /** Get size suppression threshold */ |
| 572 | float min_size() const |
| 573 | { |
| 574 | return _min_size; |
| 575 | } |
| 576 | /** Get image width (NMS may suppress boxes whose center sits beyond the image width) */ |
| 577 | float im_width() const |
| 578 | { |
| 579 | return _im_width; |
| 580 | } |
| 581 | /** Get image height (NMS may suppress boxes whose center sits beyond the image height) */ |
| 582 | float im_height() const |
| 583 | { |
| 584 | return _im_height; |
| 585 | } |
Michalis Spyrou | 2709d61 | 2018-09-19 09:46:47 +0100 | [diff] [blame] | 586 | |
| 587 | private: |
| 588 | float _score_thresh; |
| 589 | float _nms; |
| 590 | int _detections_per_im; |
| 591 | bool _soft_nms_enabled; |
| 592 | NMSType _soft_nms_method; |
| 593 | float _soft_nms_sigma; |
| 594 | float _soft_nms_min_score_thres; |
Manuel Bottini | 5209be5 | 2019-02-13 16:34:56 +0000 | [diff] [blame] | 595 | bool _suppress_size; |
| 596 | float _min_size; |
| 597 | float _im_width; |
| 598 | float _im_height; |
Michalis Spyrou | 2709d61 | 2018-09-19 09:46:47 +0100 | [diff] [blame] | 599 | }; |
| 600 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 601 | /** Padding and stride information class */ |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 602 | /** Padding information for 2D operations like Conv2d */ |
| 603 | struct Padding2D |
| 604 | { |
| 605 | Padding2D() = default; |
| 606 | Padding2D(size_t left, size_t right, size_t top, size_t bottom) |
| 607 | : left(left), right(right), top(top), bottom(bottom) |
| 608 | { |
| 609 | } |
| 610 | size_t left = { 0 }; /**< Padding across the width dimension on the left, in elements. */ |
| 611 | size_t right = { 0 }; /**< Padding across the width dimension on the right, in elements. */ |
| 612 | size_t top = { 0 }; /**< Padding across the height dimension on the top, in elements. */ |
| 613 | size_t bottom = { 0 }; /**< Padding across the height dimension on the bottom, in elements. */ |
| 614 | }; |
| 615 | |
Adnan AlSinan | e4563a0 | 2021-09-01 15:32:03 +0100 | [diff] [blame] | 616 | /** Padding information for 3D operations like Conv3d */ |
| 617 | struct Padding3D |
| 618 | { |
Freddie Liardet | ebefe52 | 2021-11-25 16:19:28 +0000 | [diff] [blame] | 619 | Padding3D() noexcept |
Giorgio Arena | c9fe9fc | 2021-10-06 12:54:29 +0100 | [diff] [blame] | 620 | { |
| 621 | } |
| 622 | |
| 623 | Padding3D(size_t pad_x, size_t pad_y, size_t pad_z) |
| 624 | : left(pad_x), right(pad_x), top(pad_y), bottom(pad_y), front(pad_z), back(pad_z) |
| 625 | { |
| 626 | } |
| 627 | |
| 628 | Padding3D(size_t left, size_t right, size_t top, size_t bottom, size_t front, size_t back) |
| 629 | : left(left), right(right), top(top), bottom(bottom), front(front), back(back) |
| 630 | { |
| 631 | } |
| 632 | |
Adnan AlSinan | e4563a0 | 2021-09-01 15:32:03 +0100 | [diff] [blame] | 633 | size_t left = { 0 }; /**< Padding across the width dimenstion on the left, in elements. */ |
| 634 | size_t right = { 0 }; /**< Padding across the width dimenstion on the right, in elements. */ |
| 635 | size_t top = { 0 }; /**< Padding across the height dimenstion on the top, in elements. */ |
| 636 | size_t bottom = { 0 }; /**< Padding across the height dimenstion on the bottom, in elements. */ |
| 637 | size_t front = { 0 }; /**< Padding across the depth dimenstion on the front, in elements. */ |
| 638 | size_t back = { 0 }; /**< Padding across the depth dimenstion on the back, in elements. */ |
| 639 | }; |
| 640 | |
Michalis Spyrou | 6c7c38e | 2018-08-29 16:28:11 +0100 | [diff] [blame] | 641 | /** PriorBox layer info */ |
| 642 | class PriorBoxLayerInfo final |
| 643 | { |
| 644 | public: |
| 645 | /** Default Constructor */ |
| 646 | PriorBoxLayerInfo() |
| 647 | : _min_sizes(), |
| 648 | _variances(), |
| 649 | _offset(), |
| 650 | _flip(true), |
| 651 | _clip(false), |
| 652 | _max_sizes(), |
| 653 | _aspect_ratios(), |
| 654 | _img_size(), |
| 655 | _steps() |
| 656 | { |
| 657 | } |
| 658 | /** Constructor |
| 659 | * |
| 660 | * @param[in] min_sizes Min sizes vector. |
Michalis Spyrou | 721c4cb | 2018-09-04 15:27:25 +0100 | [diff] [blame] | 661 | * @param[in] variances Variances vector. |
Michalis Spyrou | 6c7c38e | 2018-08-29 16:28:11 +0100 | [diff] [blame] | 662 | * @param[in] offset Offset value. |
| 663 | * @param[in] flip (Optional) Flip the aspect ratios. |
| 664 | * @param[in] clip (Optional) Clip coordinates so that they're within [0,1]. |
| 665 | * @param[in] max_sizes (Optional) Max sizes vector. |
| 666 | * @param[in] aspect_ratios (Optional) Aspect ratios of the boxes. |
| 667 | * @param[in] img_size (Optional) Image size. |
| 668 | * @param[in] steps (Optional) Step values. |
| 669 | */ |
| 670 | PriorBoxLayerInfo(const std::vector<float> &min_sizes, const std::vector<float> &variances, float offset, bool flip = true, bool clip = false, |
Pablo Tello | 3252143 | 2018-11-15 14:43:10 +0000 | [diff] [blame] | 671 | const std::vector<float> &max_sizes = {}, const std::vector<float> &aspect_ratios = {}, |
| 672 | const Coordinates2D &img_size = Coordinates2D{ 0, 0 }, const std::array<float, 2> &steps = { { 0.f, 0.f } }) |
Michalis Spyrou | 6c7c38e | 2018-08-29 16:28:11 +0100 | [diff] [blame] | 673 | : _min_sizes(min_sizes), |
| 674 | _variances(variances), |
| 675 | _offset(offset), |
| 676 | _flip(flip), |
| 677 | _clip(clip), |
| 678 | _max_sizes(max_sizes), |
Michalis Spyrou | 721c4cb | 2018-09-04 15:27:25 +0100 | [diff] [blame] | 679 | _aspect_ratios(), |
Michalis Spyrou | 6c7c38e | 2018-08-29 16:28:11 +0100 | [diff] [blame] | 680 | _img_size(img_size), |
| 681 | _steps(steps) |
| 682 | { |
| 683 | _aspect_ratios.push_back(1.); |
| 684 | for(unsigned int i = 0; i < aspect_ratios.size(); ++i) |
| 685 | { |
| 686 | float ar = aspect_ratios[i]; |
| 687 | bool already_exist = false; |
| 688 | for(auto ar_new : _aspect_ratios) |
| 689 | { |
| 690 | if(fabs(ar - ar_new) < 1e-6) |
| 691 | { |
| 692 | already_exist = true; |
| 693 | break; |
| 694 | } |
| 695 | } |
| 696 | if(!already_exist) |
| 697 | { |
| 698 | _aspect_ratios.push_back(ar); |
| 699 | if(flip) |
| 700 | { |
| 701 | _aspect_ratios.push_back(1.f / ar); |
| 702 | } |
| 703 | } |
| 704 | } |
| 705 | } |
| 706 | /** Get min sizes. */ |
| 707 | std::vector<float> min_sizes() const |
| 708 | { |
| 709 | return _min_sizes; |
| 710 | } |
| 711 | /** Get min variances. */ |
| 712 | std::vector<float> variances() const |
| 713 | { |
| 714 | return _variances; |
| 715 | } |
| 716 | /** Get the step coordinates */ |
| 717 | std::array<float, 2> steps() const |
| 718 | { |
| 719 | return _steps; |
| 720 | } |
| 721 | /** Get the image size coordinates */ |
| 722 | Coordinates2D img_size() const |
| 723 | { |
| 724 | return _img_size; |
| 725 | } |
| 726 | /** Get the offset */ |
| 727 | float offset() const |
| 728 | { |
| 729 | return _offset; |
| 730 | } |
| 731 | /** Get the flip value */ |
| 732 | bool flip() const |
| 733 | { |
| 734 | return _flip; |
| 735 | } |
| 736 | /** Get the clip value */ |
| 737 | bool clip() const |
| 738 | { |
| 739 | return _clip; |
| 740 | } |
| 741 | /** Get max sizes. */ |
| 742 | std::vector<float> max_sizes() const |
| 743 | { |
| 744 | return _max_sizes; |
| 745 | } |
| 746 | /** Get aspect ratios. */ |
| 747 | std::vector<float> aspect_ratios() const |
| 748 | { |
| 749 | return _aspect_ratios; |
| 750 | } |
| 751 | |
| 752 | private: |
Jakub Sujak | 0d27b2e | 2023-08-24 14:01:20 +0100 | [diff] [blame^] | 753 | std::vector<float> _min_sizes; |
| 754 | std::vector<float> _variances; |
| 755 | float _offset; |
| 756 | bool _flip; |
| 757 | bool _clip; |
| 758 | std::vector<float> _max_sizes; |
| 759 | std::vector<float> _aspect_ratios; |
| 760 | Coordinates2D _img_size; |
Michalis Spyrou | 6c7c38e | 2018-08-29 16:28:11 +0100 | [diff] [blame] | 761 | std::array<float, 2> _steps; |
| 762 | }; |
| 763 | |
Isabella Gottardi | a7acb3c | 2019-01-08 13:48:44 +0000 | [diff] [blame] | 764 | // Bounding Box [xmin, ymin, xmax, ymax] |
| 765 | using BBox = std::array<float, 4>; |
| 766 | // LabelBBox used for map label and bounding box |
| 767 | using LabelBBox = std::map<int, std::vector<BBox>>; |
| 768 | |
Isabella Gottardi | 05e5644 | 2018-11-16 11:26:52 +0000 | [diff] [blame] | 769 | /** Available Detection Output code types */ |
| 770 | enum class DetectionOutputLayerCodeType |
| 771 | { |
| 772 | CORNER, /**< Use box corners */ |
| 773 | CENTER_SIZE, /**< Use box centers and size */ |
| 774 | CORNER_SIZE, /**< Use box centers and size */ |
| 775 | TF_CENTER /**< Use box centers and size but flip x and y co-ordinates */ |
| 776 | }; |
| 777 | |
| 778 | /** Detection Output layer info */ |
| 779 | class DetectionOutputLayerInfo final |
| 780 | { |
| 781 | public: |
| 782 | /** Default Constructor */ |
| 783 | DetectionOutputLayerInfo() |
| 784 | : _num_classes(), |
| 785 | _share_location(), |
| 786 | _code_type(DetectionOutputLayerCodeType::CORNER), |
| 787 | _keep_top_k(), |
| 788 | _nms_threshold(), |
| 789 | _top_k(), |
| 790 | _background_label_id(), |
| 791 | _confidence_threshold(), |
| 792 | _variance_encoded_in_target(false), |
| 793 | _eta(), |
| 794 | _num_loc_classes() |
| 795 | { |
| 796 | _num_loc_classes = _share_location ? 1 : _num_classes; |
| 797 | } |
| 798 | /** Constructor |
| 799 | * |
| 800 | * @param[in] num_classes Number of classes to be predicted. |
| 801 | * @param[in] share_location If true, bounding box are shared among different classes. |
| 802 | * @param[in] code_type Type of coding method for bbox. |
| 803 | * @param[in] keep_top_k Number of total bounding boxes to be kept per image after NMS step. |
| 804 | * @param[in] nms_threshold Threshold to be used in NMS. |
| 805 | * @param[in] top_k (Optional) Number of boxes per image with top confidence scores that are fed into the NMS algorithm. Default set to -1. |
| 806 | * @param[in] background_label_id (Optional) Background label ID. If there is no background class, set it as -1. |
| 807 | * @param[in] confidence_threshold (Optional) Only consider detections whose confidences are larger than a threshold. Default set to -FLT_MAX. |
| 808 | * @param[in] variance_encoded_in_target (Optional) If true, variance is encoded in target. Otherwise we need to adjust the predicted offset accordingly.Default set to false. |
| 809 | * @param[in] eta (Optional) Eta. |
| 810 | */ |
| 811 | DetectionOutputLayerInfo(int num_classes, bool share_location, DetectionOutputLayerCodeType code_type, int keep_top_k, float nms_threshold, int top_k = -1, int background_label_id = -1, |
| 812 | float confidence_threshold = std::numeric_limits<float>::lowest(), bool variance_encoded_in_target = false, float eta = 1) |
| 813 | : _num_classes(num_classes), |
| 814 | _share_location(share_location), |
| 815 | _code_type(code_type), |
| 816 | _keep_top_k(keep_top_k), |
| 817 | _nms_threshold(nms_threshold), |
| 818 | _top_k(top_k), |
| 819 | _background_label_id(background_label_id), |
| 820 | _confidence_threshold(confidence_threshold), |
| 821 | _variance_encoded_in_target(variance_encoded_in_target), |
| 822 | _eta(eta), |
| 823 | _num_loc_classes() |
| 824 | { |
| 825 | _num_loc_classes = _share_location ? 1 : _num_classes; |
| 826 | } |
| 827 | /** Get num classes. */ |
| 828 | int num_classes() const |
| 829 | { |
| 830 | return _num_classes; |
| 831 | } |
| 832 | /** Get share location. */ |
| 833 | bool share_location() const |
| 834 | { |
| 835 | return _share_location; |
| 836 | } |
| 837 | /** Get detection output code type. */ |
| 838 | DetectionOutputLayerCodeType code_type() const |
| 839 | { |
| 840 | return _code_type; |
| 841 | } |
| 842 | /** Get if variance encoded in target. */ |
| 843 | bool variance_encoded_in_target() const |
| 844 | { |
| 845 | return _variance_encoded_in_target; |
| 846 | } |
| 847 | /** Get the number of total bounding boxes to be kept per image. */ |
| 848 | int keep_top_k() const |
| 849 | { |
| 850 | return _keep_top_k; |
| 851 | } |
| 852 | /** Get nms threshold. */ |
| 853 | float nms_threshold() const |
| 854 | { |
| 855 | return _nms_threshold; |
| 856 | } |
| 857 | /** Get eta. */ |
| 858 | float eta() const |
| 859 | { |
| 860 | return _eta; |
| 861 | } |
| 862 | /** Get background label ID. */ |
| 863 | int background_label_id() const |
| 864 | { |
| 865 | return _background_label_id; |
| 866 | } |
| 867 | /** Get confidence threshold. */ |
| 868 | float confidence_threshold() const |
| 869 | { |
| 870 | return _confidence_threshold; |
| 871 | } |
| 872 | /** Get top K. */ |
| 873 | int top_k() const |
| 874 | { |
| 875 | return _top_k; |
| 876 | } |
| 877 | /** Get number of location classes. */ |
| 878 | int num_loc_classes() const |
| 879 | { |
| 880 | return _num_loc_classes; |
| 881 | } |
| 882 | |
| 883 | private: |
| 884 | int _num_classes; |
| 885 | bool _share_location; |
| 886 | DetectionOutputLayerCodeType _code_type; |
| 887 | int _keep_top_k; |
| 888 | float _nms_threshold; |
| 889 | int _top_k; |
| 890 | int _background_label_id; |
| 891 | float _confidence_threshold; |
| 892 | bool _variance_encoded_in_target; |
| 893 | float _eta; |
| 894 | int _num_loc_classes; |
| 895 | }; |
| 896 | |
Isabella Gottardi | a7acb3c | 2019-01-08 13:48:44 +0000 | [diff] [blame] | 897 | /** Detection Output layer info */ |
| 898 | class DetectionPostProcessLayerInfo final |
| 899 | { |
| 900 | public: |
| 901 | /** Default Constructor */ |
| 902 | DetectionPostProcessLayerInfo() |
| 903 | : _max_detections(), |
| 904 | _max_classes_per_detection(), |
| 905 | _nms_score_threshold(), |
| 906 | _iou_threshold(), |
| 907 | _num_classes(), |
| 908 | _scales_values(), |
| 909 | _use_regular_nms(), |
Giuseppe Rossini | d985378 | 2019-10-25 11:11:44 +0100 | [diff] [blame] | 910 | _detection_per_class(), |
| 911 | _dequantize_scores() |
Isabella Gottardi | a7acb3c | 2019-01-08 13:48:44 +0000 | [diff] [blame] | 912 | { |
| 913 | } |
| 914 | /** Constructor |
| 915 | * |
| 916 | * @param[in] max_detections Number of total detection. |
| 917 | * @param[in] max_classes_per_detection Number of total classes to be kept after NMS step. Used in the Fast Non-Max-Suppression |
| 918 | * @param[in] nms_score_threshold Threshold to be used in NMS |
| 919 | * @param[in] iou_threshold Threshold to be used during the intersection over union. |
| 920 | * @param[in] num_classes Number of classes. |
| 921 | * @param[in] scales_values Scales values used for decode center size boxes. |
Giuseppe Rossini | d985378 | 2019-10-25 11:11:44 +0100 | [diff] [blame] | 922 | * @param[in] use_regular_nms (Optional) Boolean to determinate if use regular or fast nms. Defaults to false. |
| 923 | * @param[in] detection_per_class (Optional) Number of detection per class. Used in the Regular Non-Max-Suppression. Defaults to 100. |
| 924 | * @param[in] dequantize_scores (Optional) If the scores need to be dequantized. Defaults to true. |
Isabella Gottardi | a7acb3c | 2019-01-08 13:48:44 +0000 | [diff] [blame] | 925 | */ |
| 926 | DetectionPostProcessLayerInfo(unsigned int max_detections, unsigned int max_classes_per_detection, float nms_score_threshold, float iou_threshold, unsigned int num_classes, |
Giuseppe Rossini | d985378 | 2019-10-25 11:11:44 +0100 | [diff] [blame] | 927 | std::array<float, 4> scales_values, bool use_regular_nms = false, unsigned int detection_per_class = 100, bool dequantize_scores = true) |
Isabella Gottardi | a7acb3c | 2019-01-08 13:48:44 +0000 | [diff] [blame] | 928 | : _max_detections(max_detections), |
| 929 | _max_classes_per_detection(max_classes_per_detection), |
| 930 | _nms_score_threshold(nms_score_threshold), |
| 931 | _iou_threshold(iou_threshold), |
| 932 | _num_classes(num_classes), |
| 933 | _scales_values(scales_values), |
| 934 | _use_regular_nms(use_regular_nms), |
Giuseppe Rossini | d985378 | 2019-10-25 11:11:44 +0100 | [diff] [blame] | 935 | _detection_per_class(detection_per_class), |
| 936 | _dequantize_scores(dequantize_scores) |
Isabella Gottardi | a7acb3c | 2019-01-08 13:48:44 +0000 | [diff] [blame] | 937 | { |
| 938 | } |
| 939 | /** Get max detections. */ |
| 940 | unsigned int max_detections() const |
| 941 | { |
| 942 | return _max_detections; |
| 943 | } |
| 944 | /** Get max_classes per detection. Used in the Fast Non-Max-Suppression.*/ |
| 945 | unsigned int max_classes_per_detection() const |
| 946 | { |
| 947 | return _max_classes_per_detection; |
| 948 | } |
| 949 | /** Get detection per class. Used in the Regular Non-Max-Suppression */ |
| 950 | unsigned int detection_per_class() const |
| 951 | { |
| 952 | return _detection_per_class; |
| 953 | } |
| 954 | /** Get nms threshold. */ |
| 955 | float nms_score_threshold() const |
| 956 | { |
| 957 | return _nms_score_threshold; |
| 958 | } |
| 959 | /** Get intersection over union threshold. */ |
| 960 | float iou_threshold() const |
| 961 | { |
| 962 | return _iou_threshold; |
| 963 | } |
| 964 | /** Get num classes. */ |
| 965 | unsigned int num_classes() const |
| 966 | { |
| 967 | return _num_classes; |
| 968 | } |
| 969 | /** Get if use regular nms. */ |
| 970 | bool use_regular_nms() const |
| 971 | { |
| 972 | return _use_regular_nms; |
| 973 | } |
| 974 | /** Get y scale value. */ |
| 975 | float scale_value_y() const |
| 976 | { |
| 977 | // Saved as [y,x,h,w] |
| 978 | return _scales_values[0]; |
| 979 | } |
| 980 | /** Get x scale value. */ |
| 981 | float scale_value_x() const |
| 982 | { |
| 983 | // Saved as [y,x,h,w] |
| 984 | return _scales_values[1]; |
| 985 | } |
| 986 | /** Get h scale value. */ |
| 987 | float scale_value_h() const |
| 988 | { |
| 989 | // Saved as [y,x,h,w] |
| 990 | return _scales_values[2]; |
| 991 | } |
| 992 | /** Get w scale value. */ |
| 993 | float scale_value_w() const |
| 994 | { |
| 995 | // Saved as [y,x,h,w] |
| 996 | return _scales_values[3]; |
| 997 | } |
Giuseppe Rossini | d985378 | 2019-10-25 11:11:44 +0100 | [diff] [blame] | 998 | /** Get dequantize_scores value. */ |
| 999 | bool dequantize_scores() const |
| 1000 | { |
| 1001 | return _dequantize_scores; |
| 1002 | } |
Isabella Gottardi | a7acb3c | 2019-01-08 13:48:44 +0000 | [diff] [blame] | 1003 | |
| 1004 | private: |
Jakub Sujak | 0d27b2e | 2023-08-24 14:01:20 +0100 | [diff] [blame^] | 1005 | unsigned int _max_detections; |
| 1006 | unsigned int _max_classes_per_detection; |
| 1007 | float _nms_score_threshold; |
| 1008 | float _iou_threshold; |
| 1009 | unsigned int _num_classes; |
Isabella Gottardi | a7acb3c | 2019-01-08 13:48:44 +0000 | [diff] [blame] | 1010 | std::array<float, 4> _scales_values; |
Jakub Sujak | 0d27b2e | 2023-08-24 14:01:20 +0100 | [diff] [blame^] | 1011 | bool _use_regular_nms; |
| 1012 | unsigned int _detection_per_class; |
| 1013 | bool _dequantize_scores; |
Isabella Gottardi | a7acb3c | 2019-01-08 13:48:44 +0000 | [diff] [blame] | 1014 | }; |
| 1015 | |
Sang-Hoon Park | 0cb3da6 | 2020-01-15 12:39:56 +0000 | [diff] [blame] | 1016 | /** Pooling Layer Information struct*/ |
| 1017 | struct PoolingLayerInfo |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1018 | { |
Georgios Pinitas | 4c2dd54 | 2017-11-13 12:58:41 +0000 | [diff] [blame] | 1019 | /** Default Constructor */ |
| 1020 | PoolingLayerInfo() |
Sang-Hoon Park | 11fedda | 2020-01-15 14:44:04 +0000 | [diff] [blame] | 1021 | : pool_type(PoolingType::MAX), |
| 1022 | pool_size(Size2D()), |
| 1023 | data_layout(DataLayout::UNKNOWN), |
| 1024 | pad_stride_info(PadStrideInfo()), |
| 1025 | exclude_padding(false), |
| 1026 | is_global_pooling(false), |
Adnan AlSinan | 227db8d | 2023-02-14 14:24:09 +0000 | [diff] [blame] | 1027 | fp_mixed_precision(false), |
Adnan AlSinan | bbf2e74 | 2023-02-22 12:15:14 +0000 | [diff] [blame] | 1028 | use_inf_as_limit(true), |
| 1029 | use_kernel_indices(false) |
Georgios Pinitas | 4c2dd54 | 2017-11-13 12:58:41 +0000 | [diff] [blame] | 1030 | { |
| 1031 | } |
Sang-Hoon Park | 11fedda | 2020-01-15 14:44:04 +0000 | [diff] [blame] | 1032 | /** Constructor |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1033 | * |
Sang-Hoon Park | 2aa7fd0 | 2019-09-18 13:39:00 +0100 | [diff] [blame] | 1034 | * @param[in] pool_type Pooling type @ref PoolingType. |
| 1035 | * @param[in] pool_size Pooling size, in elements, across x and y. |
Sang-Hoon Park | 11fedda | 2020-01-15 14:44:04 +0000 | [diff] [blame] | 1036 | * @param[in] data_layout Data layout used by the layer @ref DataLayout |
| 1037 | * @param[in] pad_stride_info (Optional) Padding and stride information @ref PadStrideInfo |
| 1038 | * @param[in] exclude_padding (Optional) Strategy when accounting padding in calculations. |
| 1039 | * True will exclude padding while false will not (Used in AVG/L2 pooling to determine the pooling area). |
| 1040 | * Defaults to false; |
| 1041 | * @param[in] fp_mixed_precision (Optional) Use wider accumulators (32 bit instead of 16 for FP16) to improve accuracy. |
Adnan AlSinan | 227db8d | 2023-02-14 14:24:09 +0000 | [diff] [blame] | 1042 | * @param[in] use_inf_as_limit (Optional) Use inf to represent the limits of datatypes range, instead of using "lowest" property of the data type. |
Adnan AlSinan | bbf2e74 | 2023-02-22 12:15:14 +0000 | [diff] [blame] | 1043 | * @param[in] use_kernel_indices (Optional) Use kernel indices instead of using source indices while computing indices tensor. |
Sang-Hoon Park | 11fedda | 2020-01-15 14:44:04 +0000 | [diff] [blame] | 1044 | */ |
Georgios Pinitas | 4c2dd54 | 2017-11-13 12:58:41 +0000 | [diff] [blame] | 1045 | explicit PoolingLayerInfo(PoolingType pool_type, |
| 1046 | unsigned int pool_size, |
Sang-Hoon Park | 11fedda | 2020-01-15 14:44:04 +0000 | [diff] [blame] | 1047 | DataLayout data_layout, |
Sang-Hoon Park | 2aa7fd0 | 2019-09-18 13:39:00 +0100 | [diff] [blame] | 1048 | PadStrideInfo pad_stride_info = PadStrideInfo(), |
| 1049 | bool exclude_padding = false, |
Adnan AlSinan | 227db8d | 2023-02-14 14:24:09 +0000 | [diff] [blame] | 1050 | bool fp_mixed_precision = false, |
Adnan AlSinan | bbf2e74 | 2023-02-22 12:15:14 +0000 | [diff] [blame] | 1051 | bool use_inf_as_limit = true, |
| 1052 | bool use_kernel_indices = false) |
Sang-Hoon Park | 11fedda | 2020-01-15 14:44:04 +0000 | [diff] [blame] | 1053 | : pool_type(pool_type), |
| 1054 | pool_size(Size2D(pool_size, pool_size)), |
| 1055 | data_layout(data_layout), |
| 1056 | pad_stride_info(pad_stride_info), |
| 1057 | exclude_padding(exclude_padding), |
| 1058 | is_global_pooling(false), |
Adnan AlSinan | 227db8d | 2023-02-14 14:24:09 +0000 | [diff] [blame] | 1059 | fp_mixed_precision(fp_mixed_precision), |
Adnan AlSinan | bbf2e74 | 2023-02-22 12:15:14 +0000 | [diff] [blame] | 1060 | use_inf_as_limit(use_inf_as_limit), |
| 1061 | use_kernel_indices(use_kernel_indices) |
Isabella Gottardi | 6e464c3 | 2018-01-26 12:32:45 +0000 | [diff] [blame] | 1062 | { |
| 1063 | } |
Sang-Hoon Park | 11fedda | 2020-01-15 14:44:04 +0000 | [diff] [blame] | 1064 | |
| 1065 | /** Constructor |
Isabella Gottardi | 6e464c3 | 2018-01-26 12:32:45 +0000 | [diff] [blame] | 1066 | * |
Sang-Hoon Park | 2aa7fd0 | 2019-09-18 13:39:00 +0100 | [diff] [blame] | 1067 | * @param[in] pool_type Pooling type @ref PoolingType. |
| 1068 | * @param[in] pool_size Pooling size, in elements, across x and y. |
Sang-Hoon Park | 11fedda | 2020-01-15 14:44:04 +0000 | [diff] [blame] | 1069 | * @param[in] data_layout Data layout used by the layer @ref DataLayout |
Sang-Hoon Park | 2aa7fd0 | 2019-09-18 13:39:00 +0100 | [diff] [blame] | 1070 | * @param[in] pad_stride_info (Optional) Padding and stride information @ref PadStrideInfo |
| 1071 | * @param[in] exclude_padding (Optional) Strategy when accounting padding in calculations. |
| 1072 | * True will exclude padding while false will not (Used in AVG/L2 pooling to determine the pooling area). |
| 1073 | * Defaults to false; |
| 1074 | * @param[in] fp_mixed_precision (Optional) Use wider accumulators (32 bit instead of 16 for FP16) to improve accuracy. |
Adnan AlSinan | 227db8d | 2023-02-14 14:24:09 +0000 | [diff] [blame] | 1075 | * @param[in] use_inf_as_limit (Optional) Use inf to represent the limits of datatypes range, instead of using "lowest" property of the data type. |
Adnan AlSinan | bbf2e74 | 2023-02-22 12:15:14 +0000 | [diff] [blame] | 1076 | * @param[in] use_kernel_indices (Optional) Use kernel indices instead of using source indices while computing indices tensor. |
Isabella Gottardi | 6e464c3 | 2018-01-26 12:32:45 +0000 | [diff] [blame] | 1077 | */ |
| 1078 | explicit PoolingLayerInfo(PoolingType pool_type, |
| 1079 | Size2D pool_size, |
Sang-Hoon Park | 11fedda | 2020-01-15 14:44:04 +0000 | [diff] [blame] | 1080 | DataLayout data_layout, |
Sang-Hoon Park | 2aa7fd0 | 2019-09-18 13:39:00 +0100 | [diff] [blame] | 1081 | PadStrideInfo pad_stride_info = PadStrideInfo(), |
| 1082 | bool exclude_padding = false, |
Adnan AlSinan | 227db8d | 2023-02-14 14:24:09 +0000 | [diff] [blame] | 1083 | bool fp_mixed_precision = false, |
Adnan AlSinan | bbf2e74 | 2023-02-22 12:15:14 +0000 | [diff] [blame] | 1084 | bool use_inf_as_limit = true, |
| 1085 | bool use_kernel_indices = false) |
Sang-Hoon Park | 11fedda | 2020-01-15 14:44:04 +0000 | [diff] [blame] | 1086 | : pool_type(pool_type), |
| 1087 | pool_size(pool_size), |
| 1088 | data_layout(data_layout), |
| 1089 | pad_stride_info(pad_stride_info), |
| 1090 | exclude_padding(exclude_padding), |
| 1091 | is_global_pooling(false), |
Adnan AlSinan | 227db8d | 2023-02-14 14:24:09 +0000 | [diff] [blame] | 1092 | fp_mixed_precision(fp_mixed_precision), |
Adnan AlSinan | bbf2e74 | 2023-02-22 12:15:14 +0000 | [diff] [blame] | 1093 | use_inf_as_limit(use_inf_as_limit), |
| 1094 | use_kernel_indices(use_kernel_indices) |
Georgios Pinitas | 4c2dd54 | 2017-11-13 12:58:41 +0000 | [diff] [blame] | 1095 | { |
| 1096 | } |
Sang-Hoon Park | 11fedda | 2020-01-15 14:44:04 +0000 | [diff] [blame] | 1097 | |
| 1098 | /** Constructor |
Georgios Pinitas | 4c2dd54 | 2017-11-13 12:58:41 +0000 | [diff] [blame] | 1099 | * |
| 1100 | * @note This constructor is used for global pooling |
| 1101 | * |
Sang-Hoon Park | 11fedda | 2020-01-15 14:44:04 +0000 | [diff] [blame] | 1102 | * @param[in] pool_type Pooling type @ref PoolingType. |
| 1103 | * @param[in] data_layout Data layout used by the layer @ref DataLayout |
Georgios Pinitas | 4c2dd54 | 2017-11-13 12:58:41 +0000 | [diff] [blame] | 1104 | */ |
Sang-Hoon Park | 11fedda | 2020-01-15 14:44:04 +0000 | [diff] [blame] | 1105 | explicit PoolingLayerInfo(PoolingType pool_type, DataLayout data_layout) |
| 1106 | : pool_type(pool_type), |
| 1107 | pool_size(Size2D()), |
| 1108 | data_layout(data_layout), |
| 1109 | pad_stride_info(PadStrideInfo(1, 1, 0, 0)), |
| 1110 | exclude_padding(false), |
| 1111 | is_global_pooling(true), |
Adnan AlSinan | 227db8d | 2023-02-14 14:24:09 +0000 | [diff] [blame] | 1112 | fp_mixed_precision(false), |
Adnan AlSinan | bbf2e74 | 2023-02-22 12:15:14 +0000 | [diff] [blame] | 1113 | use_inf_as_limit(true), |
| 1114 | use_kernel_indices(false) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1115 | { |
| 1116 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1117 | |
Sang-Hoon Park | 0cb3da6 | 2020-01-15 12:39:56 +0000 | [diff] [blame] | 1118 | PoolingType pool_type; |
| 1119 | Size2D pool_size; |
Sang-Hoon Park | 11fedda | 2020-01-15 14:44:04 +0000 | [diff] [blame] | 1120 | DataLayout data_layout; |
Sang-Hoon Park | 0cb3da6 | 2020-01-15 12:39:56 +0000 | [diff] [blame] | 1121 | PadStrideInfo pad_stride_info; |
| 1122 | bool exclude_padding; |
| 1123 | bool is_global_pooling; |
| 1124 | bool fp_mixed_precision; |
Adnan AlSinan | 227db8d | 2023-02-14 14:24:09 +0000 | [diff] [blame] | 1125 | bool use_inf_as_limit; |
Adnan AlSinan | bbf2e74 | 2023-02-22 12:15:14 +0000 | [diff] [blame] | 1126 | bool use_kernel_indices; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1127 | }; |
| 1128 | |
ramelg01 | 3751569 | 2022-02-26 22:06:20 +0000 | [diff] [blame] | 1129 | /** Pooling Layer Information struct*/ |
| 1130 | struct Pooling3dLayerInfo |
| 1131 | { |
| 1132 | /** Default Constructor */ |
Michalis Spyrou | 50e48aa | 2022-04-21 16:42:56 +0100 | [diff] [blame] | 1133 | Pooling3dLayerInfo() noexcept |
ramelg01 | 3751569 | 2022-02-26 22:06:20 +0000 | [diff] [blame] | 1134 | : pool_type(PoolingType::MAX), |
| 1135 | pool_size(Size3D()), |
| 1136 | stride(Size3D()), |
| 1137 | padding(Padding3D()), |
| 1138 | exclude_padding(false), |
| 1139 | is_global_pooling(false), |
| 1140 | fp_mixed_precision(false), |
| 1141 | round_type(DimensionRoundingType::FLOOR) |
| 1142 | { |
| 1143 | } |
| 1144 | /** Constructor |
| 1145 | * |
| 1146 | * @param[in] pool_type Pooling type @ref PoolingType. |
| 1147 | * @param[in] pool_size Pooling size, in elements, across x, y and z. |
| 1148 | * @param[in] stride (Optional) stride information @ref Size3D |
| 1149 | * @param[in] padding (Optional) padding information @ref Padding3D |
| 1150 | * @param[in] exclude_padding (Optional) Strategy when accounting padding in calculations. |
| 1151 | * True will exclude padding while false will not (Used in AVG/L2 pooling to determine the pooling area). |
| 1152 | * Defaults to false; |
| 1153 | * @param[in] fp_mixed_precision (Optional) Use wider accumulators (32 bit instead of 16 for FP16) to improve accuracy. |
ramy.elgammal@arm.com | a2561f0 | 2023-06-16 20:45:48 +0100 | [diff] [blame] | 1154 | * @param[in] round_type (Optional) Dimensions rounding. Defaults to @ref DimensionRoundingType::FLOOR |
ramelg01 | 3751569 | 2022-02-26 22:06:20 +0000 | [diff] [blame] | 1155 | */ |
| 1156 | explicit Pooling3dLayerInfo(PoolingType pool_type, |
| 1157 | unsigned int pool_size, |
| 1158 | Size3D stride = Size3D(1U, 1U, 1U), |
| 1159 | Padding3D padding = Padding3D(), |
| 1160 | bool exclude_padding = false, |
| 1161 | bool fp_mixed_precision = false, |
| 1162 | DimensionRoundingType round_type = DimensionRoundingType::FLOOR) |
| 1163 | : pool_type(pool_type), |
| 1164 | pool_size(Size3D(pool_size, pool_size, pool_size)), |
| 1165 | stride(stride), |
| 1166 | padding(padding), |
| 1167 | exclude_padding(exclude_padding), |
| 1168 | is_global_pooling(false), |
| 1169 | fp_mixed_precision(fp_mixed_precision), |
| 1170 | round_type(round_type) |
| 1171 | { |
| 1172 | } |
| 1173 | |
| 1174 | /** Constructor |
| 1175 | * |
| 1176 | * @param[in] pool_type Pooling type @ref PoolingType. |
| 1177 | * @param[in] pool_size Pooling size, in elements, across x, y and z. |
| 1178 | * @param[in] stride (Optional) stride information @ref Size3D |
| 1179 | * @param[in] padding (Optional) padding information @ref Padding3D |
| 1180 | * @param[in] exclude_padding (Optional) Strategy when accounting padding in calculations. |
| 1181 | * True will exclude padding while false will not (Used in AVG/L2 pooling to determine the pooling area). |
| 1182 | * Defaults to false; |
| 1183 | * @param[in] fp_mixed_precision (Optional) Use wider accumulators (32 bit instead of 16 for FP16) to improve accuracy. |
ramy.elgammal@arm.com | a2561f0 | 2023-06-16 20:45:48 +0100 | [diff] [blame] | 1184 | * @param[in] round_type (Optional) Dimensions rounding. Defaults to @ref DimensionRoundingType::FLOOR |
ramelg01 | 3751569 | 2022-02-26 22:06:20 +0000 | [diff] [blame] | 1185 | */ |
| 1186 | explicit Pooling3dLayerInfo(PoolingType pool_type, |
| 1187 | Size3D pool_size, |
| 1188 | Size3D stride = Size3D(1U, 1U, 1U), |
| 1189 | Padding3D padding = Padding3D(), |
| 1190 | bool exclude_padding = false, |
| 1191 | bool fp_mixed_precision = false, |
| 1192 | DimensionRoundingType round_type = DimensionRoundingType::FLOOR) |
| 1193 | : pool_type(pool_type), |
| 1194 | pool_size(pool_size), |
| 1195 | stride(stride), |
| 1196 | padding(padding), |
| 1197 | exclude_padding(exclude_padding), |
| 1198 | is_global_pooling(false), |
| 1199 | fp_mixed_precision(fp_mixed_precision), |
| 1200 | round_type(round_type) |
| 1201 | { |
| 1202 | } |
| 1203 | |
| 1204 | /** Constructor |
| 1205 | * |
| 1206 | * @note This constructor is used for global pooling |
| 1207 | * |
| 1208 | * @param[in] pool_type Pooling type @ref PoolingType. |
| 1209 | */ |
| 1210 | explicit Pooling3dLayerInfo(PoolingType pool_type) |
| 1211 | : pool_type(pool_type), |
| 1212 | pool_size(Size3D()), |
| 1213 | stride(Size3D(1U, 1U, 1U)), |
| 1214 | padding(Padding3D(0, 0, 0)), |
| 1215 | exclude_padding(false), |
| 1216 | is_global_pooling(true), |
| 1217 | fp_mixed_precision(false), |
| 1218 | round_type(DimensionRoundingType::FLOOR) |
| 1219 | { |
| 1220 | } |
| 1221 | |
| 1222 | PoolingType pool_type; |
| 1223 | Size3D pool_size; |
| 1224 | Size3D stride; |
| 1225 | Padding3D padding; |
| 1226 | bool exclude_padding; |
| 1227 | bool is_global_pooling; |
| 1228 | bool fp_mixed_precision; |
| 1229 | DimensionRoundingType round_type; |
| 1230 | }; |
| 1231 | |
Georgios Pinitas | 7b7858d | 2017-06-21 16:44:24 +0100 | [diff] [blame] | 1232 | /** ROI Pooling Layer Information class */ |
giuros01 | 1887081 | 2018-09-13 09:31:40 +0100 | [diff] [blame] | 1233 | class ROIPoolingLayerInfo final |
Georgios Pinitas | 7b7858d | 2017-06-21 16:44:24 +0100 | [diff] [blame] | 1234 | { |
| 1235 | public: |
giuros01 | 1887081 | 2018-09-13 09:31:40 +0100 | [diff] [blame] | 1236 | /** Constructor |
Georgios Pinitas | 7b7858d | 2017-06-21 16:44:24 +0100 | [diff] [blame] | 1237 | * |
giuros01 | 1887081 | 2018-09-13 09:31:40 +0100 | [diff] [blame] | 1238 | * @param[in] pooled_width Pooled width of the layer. |
| 1239 | * @param[in] pooled_height Pooled height of the layer. |
| 1240 | * @param[in] spatial_scale Spatial scale to be applied to the ROI coordinates and dimensions. |
| 1241 | * @param[in] sampling_ratio Number of samples to include in each pooling region (if set to zero, a ceil(roi_dims/pooling_dims)) |
Georgios Pinitas | 7b7858d | 2017-06-21 16:44:24 +0100 | [diff] [blame] | 1242 | */ |
giuros01 | 1887081 | 2018-09-13 09:31:40 +0100 | [diff] [blame] | 1243 | ROIPoolingLayerInfo(unsigned int pooled_width, unsigned int pooled_height, float spatial_scale, unsigned int sampling_ratio = 0) |
| 1244 | : _pooled_width(pooled_width), _pooled_height(pooled_height), _spatial_scale(spatial_scale), _sampling_ratio(sampling_ratio) |
Georgios Pinitas | 7b7858d | 2017-06-21 16:44:24 +0100 | [diff] [blame] | 1245 | { |
| 1246 | } |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 1247 | /** Get the pooled width of the layer */ |
Georgios Pinitas | 7b7858d | 2017-06-21 16:44:24 +0100 | [diff] [blame] | 1248 | unsigned int pooled_width() const |
| 1249 | { |
| 1250 | return _pooled_width; |
| 1251 | } |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 1252 | /** Get the pooled height of the layer */ |
Georgios Pinitas | 7b7858d | 2017-06-21 16:44:24 +0100 | [diff] [blame] | 1253 | unsigned int pooled_height() const |
| 1254 | { |
| 1255 | return _pooled_height; |
| 1256 | } |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 1257 | /** Get the spatial scale */ |
Georgios Pinitas | 7b7858d | 2017-06-21 16:44:24 +0100 | [diff] [blame] | 1258 | float spatial_scale() const |
| 1259 | { |
| 1260 | return _spatial_scale; |
| 1261 | } |
giuros01 | 1887081 | 2018-09-13 09:31:40 +0100 | [diff] [blame] | 1262 | /** Get sampling ratio */ |
| 1263 | unsigned int sampling_ratio() const |
| 1264 | { |
| 1265 | return _sampling_ratio; |
| 1266 | } |
Georgios Pinitas | 7b7858d | 2017-06-21 16:44:24 +0100 | [diff] [blame] | 1267 | |
| 1268 | private: |
| 1269 | unsigned int _pooled_width; |
| 1270 | unsigned int _pooled_height; |
| 1271 | float _spatial_scale; |
giuros01 | 1887081 | 2018-09-13 09:31:40 +0100 | [diff] [blame] | 1272 | unsigned int _sampling_ratio; |
Georgios Pinitas | 7b7858d | 2017-06-21 16:44:24 +0100 | [diff] [blame] | 1273 | }; |
| 1274 | |
Manuel Bottini | 5209be5 | 2019-02-13 16:34:56 +0000 | [diff] [blame] | 1275 | /** Generate Proposals Information class */ |
| 1276 | class GenerateProposalsInfo |
| 1277 | { |
| 1278 | public: |
| 1279 | /** Constructor |
| 1280 | * |
| 1281 | * @param[in] im_width Width of the original image |
| 1282 | * @param[in] im_height Height of the original image |
| 1283 | * @param[in] im_scale Scale applied to the original image |
| 1284 | * @param[in] spatial_scale (Optional)Scale applied to the feature map. Defaults to 1.0 |
| 1285 | * @param[in] pre_nms_topN (Optional)Number of the best scores to be selected from the transformations. Defaults to 6000. |
| 1286 | * @param[in] post_nms_topN (Optional)Number of the best scores to be selected from the NMS operation. Defaults to 300. |
| 1287 | * @param[in] nms_thres (Optional)NMS overlap threshold. Defaults to 0.7. |
| 1288 | * @param[in] min_size (Optional)Size used to validate the anchors produced. Defaults to 16. |
| 1289 | * @param[in] values_per_roi (Optional)Values used to represent a ROI(Region of interest). Defaults to 4. |
| 1290 | */ |
| 1291 | GenerateProposalsInfo(float im_width, float im_height, float im_scale, float spatial_scale = 1.0, int pre_nms_topN = 6000, int post_nms_topN = 300, float nms_thres = 0.7, float min_size = 16.0, |
| 1292 | size_t values_per_roi = 4) |
| 1293 | : _im_height(im_height), _im_width(im_width), _im_scale(im_scale), _spatial_scale(spatial_scale), _pre_nms_topN(pre_nms_topN), _post_nms_topN(post_nms_topN), _nms_thres(nms_thres), |
| 1294 | _min_size(min_size), _values_per_roi(values_per_roi) |
| 1295 | { |
| 1296 | } |
| 1297 | |
| 1298 | /* Get the original height */ |
| 1299 | float im_height() const |
| 1300 | { |
| 1301 | return _im_height; |
| 1302 | } |
| 1303 | /* Get the original width */ |
| 1304 | float im_width() const |
| 1305 | { |
| 1306 | return _im_width; |
| 1307 | } |
| 1308 | /* Get the image scale */ |
| 1309 | float im_scale() const |
| 1310 | { |
| 1311 | return _im_scale; |
| 1312 | } |
| 1313 | /* Get the value of how many best scores to select (before NMS) */ |
| 1314 | int pre_nms_topN() const |
| 1315 | { |
| 1316 | return _pre_nms_topN; |
| 1317 | } |
| 1318 | /* Get the value of how many best scores to select (after NMS) */ |
| 1319 | int post_nms_topN() const |
| 1320 | { |
| 1321 | return _post_nms_topN; |
| 1322 | } |
| 1323 | /* Get the NMS overlap threshold */ |
| 1324 | float nms_thres() const |
| 1325 | { |
| 1326 | return _nms_thres; |
| 1327 | } |
| 1328 | /* Get the minimal size */ |
| 1329 | float min_size() const |
| 1330 | { |
| 1331 | return _min_size; |
| 1332 | } |
| 1333 | /* Get the spatial scale to be applied to the feature maps */ |
| 1334 | float spatial_scale() const |
| 1335 | { |
| 1336 | return _spatial_scale; |
| 1337 | } |
| 1338 | /* Get the values used to represent a ROI(Region of interest)*/ |
| 1339 | size_t values_per_roi() const |
| 1340 | { |
| 1341 | return _values_per_roi; |
| 1342 | } |
| 1343 | |
| 1344 | private: |
| 1345 | float _im_height; |
| 1346 | float _im_width; |
| 1347 | float _im_scale; |
| 1348 | float _spatial_scale; |
| 1349 | int _pre_nms_topN; |
| 1350 | int _post_nms_topN; |
| 1351 | float _nms_thres; |
| 1352 | float _min_size; |
| 1353 | size_t _values_per_roi; |
| 1354 | }; |
| 1355 | |
| 1356 | /** ComputeAnchors information class */ |
| 1357 | class ComputeAnchorsInfo |
| 1358 | { |
| 1359 | public: |
| 1360 | /** Constructor |
| 1361 | * |
| 1362 | * @param[in] feat_width Feature map width |
| 1363 | * @param[in] feat_height Feature map height |
| 1364 | * @param[in] spatial_scale Feature map scale |
| 1365 | * @param[in] values_per_roi (Optional)Values used to represent a ROI(Region Of Interest). Defaults to 4 |
| 1366 | */ |
| 1367 | ComputeAnchorsInfo(float feat_width, float feat_height, float spatial_scale, size_t values_per_roi = 4) |
| 1368 | : _feat_height(feat_height), |
| 1369 | _feat_width(feat_width), |
| 1370 | _spatial_scale(spatial_scale), |
| 1371 | _values_per_roi(values_per_roi) |
| 1372 | { |
| 1373 | } |
| 1374 | |
| 1375 | /* Get the height of the feature map */ |
| 1376 | float feat_height() const |
| 1377 | { |
| 1378 | return _feat_height; |
| 1379 | } |
| 1380 | |
| 1381 | /* Get the width of the feature map */ |
| 1382 | float feat_width() const |
| 1383 | { |
| 1384 | return _feat_width; |
| 1385 | } |
| 1386 | |
| 1387 | /* Get the scale of the feature map */ |
| 1388 | float spatial_scale() const |
| 1389 | { |
| 1390 | return _spatial_scale; |
| 1391 | } |
| 1392 | |
| 1393 | /* Get the values used to represent a ROI(Region Of Interest)*/ |
| 1394 | size_t values_per_roi() const |
| 1395 | { |
| 1396 | return _values_per_roi; |
| 1397 | } |
| 1398 | |
| 1399 | private: |
| 1400 | float _feat_height; |
| 1401 | float _feat_width; |
| 1402 | float _spatial_scale; |
| 1403 | size_t _values_per_roi; |
| 1404 | }; |
| 1405 | |
giuros01 | c04a0e8 | 2018-10-03 12:44:35 +0100 | [diff] [blame] | 1406 | /** Bounding Box Transform information class */ |
giuros01 | d696cb6 | 2018-11-16 10:39:59 +0000 | [diff] [blame] | 1407 | class BoundingBoxTransformInfo final |
giuros01 | c04a0e8 | 2018-10-03 12:44:35 +0100 | [diff] [blame] | 1408 | { |
| 1409 | public: |
| 1410 | /** Constructor |
| 1411 | * |
giuros01 | d696cb6 | 2018-11-16 10:39:59 +0000 | [diff] [blame] | 1412 | * @param[in] img_width Width of the original image |
| 1413 | * @param[in] img_height Height, of the original image |
| 1414 | * @param[in] scale Scale of the original image |
| 1415 | * @param[in] apply_scale (Optional)Re-apply scaling after transforming the boxes. Defaults to false |
| 1416 | * @param[in] weights (Optional)Weights [wx, wy, ww, wh] for the deltas. Defaults to all ones |
| 1417 | * @param[in] correct_transform_coords (Optional)Correct bounding box transform coordinates. Defaults to false |
| 1418 | * @param[in] bbox_xform_clip (Optional)Minimum bounding box width and height after bounding box transformation in log-space. Defaults to log(1000/16) |
giuros01 | c04a0e8 | 2018-10-03 12:44:35 +0100 | [diff] [blame] | 1419 | */ |
giuros01 | d696cb6 | 2018-11-16 10:39:59 +0000 | [diff] [blame] | 1420 | BoundingBoxTransformInfo(float img_width, float img_height, float scale, bool apply_scale = false, const std::array<float, 4> weights = { { 1.f, 1.f, 1.f, 1.f } }, bool correct_transform_coords = |
| 1421 | false, |
| 1422 | float bbox_xform_clip = |
| 1423 | 4.135166556742356f) |
| 1424 | : _img_width(img_width), _img_height(img_height), _scale(scale), _apply_scale(apply_scale), _correct_transform_coords(correct_transform_coords), _weights(weights), _bbox_xform_clip(bbox_xform_clip) |
giuros01 | c04a0e8 | 2018-10-03 12:44:35 +0100 | [diff] [blame] | 1425 | { |
| 1426 | } |
| 1427 | |
| 1428 | std::array<float, 4> weights() const |
| 1429 | { |
| 1430 | return _weights; |
| 1431 | } |
| 1432 | |
| 1433 | float bbox_xform_clip() const |
| 1434 | { |
| 1435 | return _bbox_xform_clip; |
| 1436 | } |
| 1437 | |
| 1438 | float img_height() const |
| 1439 | { |
| 1440 | return _img_height; |
| 1441 | } |
| 1442 | |
| 1443 | float img_width() const |
| 1444 | { |
| 1445 | return _img_width; |
| 1446 | } |
| 1447 | |
| 1448 | float scale() const |
| 1449 | { |
| 1450 | return _scale; |
| 1451 | } |
| 1452 | |
| 1453 | bool apply_scale() const |
| 1454 | { |
| 1455 | return _apply_scale; |
| 1456 | } |
| 1457 | |
giuros01 | d696cb6 | 2018-11-16 10:39:59 +0000 | [diff] [blame] | 1458 | bool correct_transform_coords() const |
| 1459 | { |
| 1460 | return _correct_transform_coords; |
| 1461 | } |
| 1462 | |
giuros01 | c04a0e8 | 2018-10-03 12:44:35 +0100 | [diff] [blame] | 1463 | private: |
Jakub Sujak | 0d27b2e | 2023-08-24 14:01:20 +0100 | [diff] [blame^] | 1464 | float _img_width; |
| 1465 | float _img_height; |
| 1466 | float _scale; |
| 1467 | bool _apply_scale; |
| 1468 | bool _correct_transform_coords; |
giuros01 | c04a0e8 | 2018-10-03 12:44:35 +0100 | [diff] [blame] | 1469 | std::array<float, 4> _weights; |
Jakub Sujak | 0d27b2e | 2023-08-24 14:01:20 +0100 | [diff] [blame^] | 1470 | float _bbox_xform_clip; |
giuros01 | c04a0e8 | 2018-10-03 12:44:35 +0100 | [diff] [blame] | 1471 | }; |
| 1472 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1473 | /** Normalization Layer Information class */ |
| 1474 | class NormalizationLayerInfo |
| 1475 | { |
| 1476 | public: |
| 1477 | /** Default Constructor |
| 1478 | * |
Michele Di Giorgio | 9d3a831 | 2018-11-20 12:31:24 +0000 | [diff] [blame] | 1479 | * @param[in] type The normalization type. Can be @ref NormType::IN_MAP_1D, @ref NormType::IN_MAP_2D or @ref NormType::CROSS_MAP |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1480 | * @param[in] norm_size The normalization size is the number of elements to normalize across. Defaults to 5. |
Georgios Pinitas | 41caa62 | 2017-11-16 14:37:08 +0000 | [diff] [blame] | 1481 | * @param[in] alpha (Optional) Alpha parameter used by normalization equation. Defaults to 0.0001. |
| 1482 | * @param[in] beta (Optional) Beta parameter used by normalization equation. Defaults to 0.5. |
| 1483 | * @param[in] kappa (Optional) Kappa parameter used by [Krichevksy 2012] Across Channel Local Brightness Normalization equation. |
| 1484 | * @param[in] is_scaled (Optional) Boolean that specifies if alpha will be scaled by the normalization size or not. |
| 1485 | * Should be false to follow [Krichevksy 2012]. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1486 | */ |
Georgios Pinitas | 41caa62 | 2017-11-16 14:37:08 +0000 | [diff] [blame] | 1487 | NormalizationLayerInfo(NormType type, uint32_t norm_size = 5, float alpha = 0.0001f, float beta = 0.5f, float kappa = 1.f, bool is_scaled = true) |
| 1488 | : _type(type), _norm_size(norm_size), _alpha(alpha), _beta(beta), _kappa(kappa), _is_scaled(is_scaled) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1489 | { |
| 1490 | } |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 1491 | /** Get the normalization type */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1492 | NormType type() const |
| 1493 | { |
| 1494 | return _type; |
| 1495 | } |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 1496 | /** Get the normalization size */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1497 | uint32_t norm_size() const |
| 1498 | { |
| 1499 | return _norm_size; |
| 1500 | } |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 1501 | /** Get the alpha value */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1502 | float alpha() const |
| 1503 | { |
| 1504 | return _alpha; |
| 1505 | } |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 1506 | /** Get the beta value */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1507 | float beta() const |
| 1508 | { |
| 1509 | return _beta; |
| 1510 | } |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 1511 | /** Get the kappa value */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1512 | float kappa() const |
| 1513 | { |
| 1514 | return _kappa; |
| 1515 | } |
Michele Di Giorgio | 9d3a831 | 2018-11-20 12:31:24 +0000 | [diff] [blame] | 1516 | /** Get the is_scaled value */ |
| 1517 | bool is_scaled() const |
| 1518 | { |
| 1519 | return _is_scaled; |
| 1520 | } |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 1521 | /** Check if normalization is cross map */ |
Georgios Pinitas | 41caa62 | 2017-11-16 14:37:08 +0000 | [diff] [blame] | 1522 | bool is_cross_map() const |
| 1523 | { |
| 1524 | return _type == NormType::CROSS_MAP; |
| 1525 | } |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 1526 | /** Check if normalization is not cross map */ |
Georgios Pinitas | 41caa62 | 2017-11-16 14:37:08 +0000 | [diff] [blame] | 1527 | bool is_in_map() const |
| 1528 | { |
| 1529 | return !is_cross_map(); |
| 1530 | } |
| 1531 | /** Return the scaling factor of the normalization function. |
| 1532 | * |
| 1533 | * If is_scaled is set to false then [Krichevksy 2012] normalization scaling is performed, |
| 1534 | * where alpha is returned plainly, else alpha is scaled by the total number of elements used for the normalization. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1535 | * |
| 1536 | * @return The normalization scaling factor. |
| 1537 | */ |
| 1538 | float scale_coeff() const |
| 1539 | { |
| 1540 | const uint32_t size = (_type == NormType::IN_MAP_2D) ? _norm_size * _norm_size : _norm_size; |
Georgios Pinitas | 41caa62 | 2017-11-16 14:37:08 +0000 | [diff] [blame] | 1541 | return (_is_scaled) ? (_alpha / size) : _alpha; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1542 | } |
| 1543 | |
| 1544 | private: |
| 1545 | NormType _type; |
| 1546 | uint32_t _norm_size; |
| 1547 | float _alpha; |
| 1548 | float _beta; |
| 1549 | float _kappa; |
Georgios Pinitas | 41caa62 | 2017-11-16 14:37:08 +0000 | [diff] [blame] | 1550 | bool _is_scaled; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1551 | }; |
| 1552 | |
thecha01 | 2bfadd9 | 2020-08-12 17:25:51 +0100 | [diff] [blame] | 1553 | class StridedSliceLayerInfo |
| 1554 | { |
| 1555 | public: |
| 1556 | /** Default Constructor |
| 1557 | * |
| 1558 | * @param[in] begin_mask (Optional) If the ith bit of begin_mask is set, starts[i] is ignored and the fullest possible range in that dimension is used instead. |
| 1559 | * @param[in] end_mask (Optional) If the ith bit of end_mask is set, ends[i] is ignored and the fullest possible range in that dimension is used instead. |
| 1560 | * @param[in] shrink_axis_mask (Optional) If the ith bit of shrink_axis_mask is set, it implies that the ith specification shrinks the dimensionality by 1. |
| 1561 | */ |
| 1562 | StridedSliceLayerInfo(int32_t begin_mask = 0, int32_t end_mask = 0, int32_t shrink_axis_mask = 0) |
| 1563 | : _begin_mask(begin_mask), _end_mask(end_mask), _shrink_axis_mask(shrink_axis_mask) |
| 1564 | { |
| 1565 | } |
| 1566 | |
| 1567 | /* Get the begin mask value */ |
| 1568 | int32_t begin_mask() const |
| 1569 | { |
| 1570 | return _begin_mask; |
| 1571 | } |
| 1572 | |
| 1573 | /* Get the end mask value */ |
| 1574 | int32_t end_mask() const |
| 1575 | { |
| 1576 | return _end_mask; |
| 1577 | } |
| 1578 | |
| 1579 | /* Get the shrink axis mask value */ |
| 1580 | int32_t shrink_axis_mask() const |
| 1581 | { |
| 1582 | return _shrink_axis_mask; |
| 1583 | } |
| 1584 | |
| 1585 | private: |
| 1586 | int32_t _begin_mask; |
| 1587 | int32_t _end_mask; |
| 1588 | int32_t _shrink_axis_mask; |
| 1589 | }; |
| 1590 | |
Ramy Elgammal | 9178002 | 2022-07-20 14:57:37 +0100 | [diff] [blame] | 1591 | // OHWIo<interleave_by>i<block_by> |
| 1592 | inline int interleave_by(const WeightFormat wf) |
| 1593 | { |
Pablo Marquez Tello | 93581a5 | 2022-07-21 13:55:27 +0100 | [diff] [blame] | 1594 | return (static_cast<int>(wf) >> 8) & 0xFFF; |
Ramy Elgammal | 9178002 | 2022-07-20 14:57:37 +0100 | [diff] [blame] | 1595 | } |
| 1596 | inline int block_by(const WeightFormat wf) |
| 1597 | { |
Pablo Marquez Tello | 93581a5 | 2022-07-21 13:55:27 +0100 | [diff] [blame] | 1598 | return (static_cast<int>(wf) >> 20) & 0xF; |
Ramy Elgammal | 9178002 | 2022-07-20 14:57:37 +0100 | [diff] [blame] | 1599 | } |
Pablo Marquez Tello | 93581a5 | 2022-07-21 13:55:27 +0100 | [diff] [blame] | 1600 | inline bool is_fixed_format(const WeightFormat &wf) |
Ramy Elgammal | 9178002 | 2022-07-20 14:57:37 +0100 | [diff] [blame] | 1601 | { |
| 1602 | return wf != WeightFormat::UNSPECIFIED && wf != WeightFormat::ANY; |
| 1603 | } |
Pablo Marquez Tello | 93581a5 | 2022-07-21 13:55:27 +0100 | [diff] [blame] | 1604 | inline bool is_fixed_format_fast_math(const WeightFormat &wf) |
| 1605 | { |
| 1606 | return (static_cast<int>(wf) >> 4) & 0x1; |
| 1607 | } |
Ramy Elgammal | 9178002 | 2022-07-20 14:57:37 +0100 | [diff] [blame] | 1608 | |
Gian Marco Iodice | 559d771 | 2017-08-08 08:38:09 +0100 | [diff] [blame] | 1609 | /** Convolution Layer Weights Information class. This class stores the necessary information to compute convolution layer when the weights are already reshaped */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1610 | class WeightsInfo |
| 1611 | { |
| 1612 | public: |
Gian Marco Iodice | 4e28869 | 2017-06-27 11:41:59 +0100 | [diff] [blame] | 1613 | /** Default constructor */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1614 | WeightsInfo() |
Ramy Elgammal | 9178002 | 2022-07-20 14:57:37 +0100 | [diff] [blame] | 1615 | : _are_reshaped(false), _kernel_width(0), _kernel_height(0), _num_kernels(0), _retain_internal_weights(false), _weight_format(arm_compute::WeightFormat::UNSPECIFIED) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1616 | { |
| 1617 | } |
| 1618 | /** Constructor |
| 1619 | * |
Michele Di Giorgio | b62280a | 2018-05-31 17:31:05 +0100 | [diff] [blame] | 1620 | * @param[in] are_reshaped True if the weights have been reshaped |
| 1621 | * @param[in] kernel_width Kernel width. |
| 1622 | * @param[in] kernel_height Kernel height. |
| 1623 | * @param[in] num_kernels Number of convolution kernels. |
| 1624 | * @param[in] retain_internal_weights (Optional) True if internal reshaped weights must be retained. Used for reconfiguration purposes. Default is false. |
Ramy Elgammal | 9178002 | 2022-07-20 14:57:37 +0100 | [diff] [blame] | 1625 | * @param[in] weight_format (Optional) arm_gemm:WeightFormat enumeration requested by the user. Default is arm_compute::WeightFormat::UNSPECIFIED. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1626 | */ |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 1627 | WeightsInfo(bool are_reshaped, unsigned int kernel_width, unsigned int kernel_height, unsigned int num_kernels, bool retain_internal_weights = false, |
Ramy Elgammal | 9178002 | 2022-07-20 14:57:37 +0100 | [diff] [blame] | 1628 | arm_compute::WeightFormat weight_format = arm_compute::WeightFormat::UNSPECIFIED) |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 1629 | : _are_reshaped(are_reshaped), _kernel_width(kernel_width), _kernel_height(kernel_height), _num_kernels(num_kernels), _retain_internal_weights(retain_internal_weights), _weight_format(weight_format) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1630 | { |
| 1631 | } |
Gian Marco Iodice | 4e28869 | 2017-06-27 11:41:59 +0100 | [diff] [blame] | 1632 | /** Flag which specifies if the weights tensor has been reshaped. |
| 1633 | * |
| 1634 | * @return True if the weights tensors has been reshaped |
| 1635 | */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1636 | bool are_reshaped() const |
| 1637 | { |
| 1638 | return _are_reshaped; |
| 1639 | }; |
Gian Marco Iodice | 559d771 | 2017-08-08 08:38:09 +0100 | [diff] [blame] | 1640 | /** Return the number of convolution kernels |
| 1641 | * |
| 1642 | * @return The number of convolution kernels |
| 1643 | */ |
| 1644 | unsigned int num_kernels() const |
| 1645 | { |
| 1646 | return _num_kernels; |
| 1647 | }; |
Gian Marco Iodice | 4e28869 | 2017-06-27 11:41:59 +0100 | [diff] [blame] | 1648 | /** Return the width and height of the kernel |
| 1649 | * |
| 1650 | * @return The width and height of the kernel |
| 1651 | */ |
| 1652 | std::pair<unsigned int, unsigned int> kernel_size() const |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1653 | { |
Gian Marco Iodice | 4e28869 | 2017-06-27 11:41:59 +0100 | [diff] [blame] | 1654 | return std::make_pair(_kernel_width, _kernel_height); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1655 | } |
Michele Di Giorgio | b62280a | 2018-05-31 17:31:05 +0100 | [diff] [blame] | 1656 | bool retain_internal_weights() const |
| 1657 | { |
| 1658 | return _retain_internal_weights; |
| 1659 | } |
Ramy Elgammal | 9178002 | 2022-07-20 14:57:37 +0100 | [diff] [blame] | 1660 | arm_compute::WeightFormat weight_format() const |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 1661 | { |
| 1662 | return _weight_format; |
| 1663 | } |
Milos Puzovic | 13b623e | 2022-07-27 17:53:21 +0000 | [diff] [blame] | 1664 | void set_weight_format(arm_compute::WeightFormat weight_format) |
| 1665 | { |
| 1666 | _weight_format = weight_format; |
| 1667 | } |
| 1668 | |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 1669 | unsigned int kernel_width() const |
| 1670 | { |
| 1671 | return _kernel_width; |
| 1672 | } |
| 1673 | unsigned int kernel_height() const |
| 1674 | { |
| 1675 | return _kernel_height; |
| 1676 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1677 | |
| 1678 | private: |
Ramy Elgammal | 9178002 | 2022-07-20 14:57:37 +0100 | [diff] [blame] | 1679 | bool _are_reshaped; |
| 1680 | unsigned int _kernel_width; |
| 1681 | unsigned int _kernel_height; |
| 1682 | unsigned int _num_kernels; |
| 1683 | bool _retain_internal_weights; |
| 1684 | arm_compute::WeightFormat _weight_format; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1685 | }; |
| 1686 | |
Gian Marco | 36a0a46 | 2018-01-12 10:21:40 +0000 | [diff] [blame] | 1687 | /** GEMM reshape information class. This class stores the necessary information about matrix A and matrix B reshape. |
| 1688 | * |
Michele Di Giorgio | 93b75e0 | 2021-06-21 12:00:43 +0100 | [diff] [blame] | 1689 | * The matrix A can only be reshaped through @ref opencl::kernels::ClGemmReshapeLhsMatrixKernel or @ref cpu::kernels::CpuGemmInterleave4x4Kernel |
Georgios Pinitas | 856f66e | 2021-04-22 21:13:21 +0100 | [diff] [blame] | 1690 | * Note: Optionally just for @ref opencl::kernels::ClGemmReshapeLhsMatrixKernel is it possible to set mult_interleave4x4_height, the multiplication factor for the height of the 4x4 interleaved block |
Gian Marco | 36a0a46 | 2018-01-12 10:21:40 +0000 | [diff] [blame] | 1691 | * |
Michele Di Giorgio | 93b75e0 | 2021-06-21 12:00:43 +0100 | [diff] [blame] | 1692 | * The matrix B can only be reshaped through @ref opencl::kernels::ClGemmReshapeRhsMatrixKernel or @ref cpu::kernels::CpuGemmTranspose1xWKernel |
Georgios Pinitas | 856f66e | 2021-04-22 21:13:21 +0100 | [diff] [blame] | 1693 | * Note: Optionally just for @ref opencl::kernels::ClGemmReshapeRhsMatrixKernel is it possible to set mult_transpose1xW_width, the multiplication factor for the width of the 1xW transposed block |
Gian Marco | 36a0a46 | 2018-01-12 10:21:40 +0000 | [diff] [blame] | 1694 | * |
| 1695 | */ |
| 1696 | class GEMMReshapeInfo final |
| 1697 | { |
| 1698 | public: |
| 1699 | /** Default constructor */ |
| 1700 | GEMMReshapeInfo() |
Georgios Pinitas | b0f342e | 2019-05-21 13:32:43 +0100 | [diff] [blame] | 1701 | : _m(1), _n(1), _k(1), _mult_transpose1xW_width(1), _mult_interleave4x4_height(1), _depth_output_gemm3d(0), _reinterpret_input_as_3d(false), _broadcast_bias(false) |
Gian Marco | 36a0a46 | 2018-01-12 10:21:40 +0000 | [diff] [blame] | 1702 | { |
| 1703 | } |
| 1704 | /** Constructor |
| 1705 | * |
| 1706 | * @param[in] m Number of matrix A rows |
| 1707 | * @param[in] n Number of matrix B columns |
| 1708 | * @param[in] k Number of matrix A columns or matrix B rows |
| 1709 | * @param[in] mult_transpose1xW_width (Optional) Multiplication factor for the width of the 1xW transposed block |
| 1710 | * @param[in] mult_interleave4x4_height (Optional) Multiplication factor for the height of the 4x4 interleaved block |
Gian Marco Iodice | 3139f03 | 2018-11-05 14:26:32 +0000 | [diff] [blame] | 1711 | * @param[in] depth_output_gemm3d (Optional) Depth (third dimension) of the output tensor to be used with the GEMM3D kernel. |
| 1712 | * If 0 the output will not be reinterpreted as 3D. Default 0 |
Gian Marco Iodice | 68a3f56 | 2018-07-26 11:44:03 +0100 | [diff] [blame] | 1713 | * @param[in] reinterpret_input_as_3d (Optional) Reinterpret the input as 3D tensor. (i.e. this flag should be set to true when GEMM is used |
Georgios Pinitas | b0f342e | 2019-05-21 13:32:43 +0100 | [diff] [blame] | 1714 | * to perform 1x1 convolutions with the NHWC data layout) |
| 1715 | * @param[in] broadcast_bias (Optional) Broadcast the shape of the bias tensor from a vector to a matrix. |
Gian Marco | 36a0a46 | 2018-01-12 10:21:40 +0000 | [diff] [blame] | 1716 | */ |
Georgios Pinitas | b0f342e | 2019-05-21 13:32:43 +0100 | [diff] [blame] | 1717 | GEMMReshapeInfo(int m, int n, int k, int mult_transpose1xW_width = 1, int mult_interleave4x4_height = 1, int depth_output_gemm3d = 0, bool reinterpret_input_as_3d = false, bool broadcast_bias = false) |
Gian Marco Iodice | 68a3f56 | 2018-07-26 11:44:03 +0100 | [diff] [blame] | 1718 | : _m(m), _n(n), _k(k), _mult_transpose1xW_width(mult_transpose1xW_width), _mult_interleave4x4_height(mult_interleave4x4_height), _depth_output_gemm3d(depth_output_gemm3d), |
Georgios Pinitas | b0f342e | 2019-05-21 13:32:43 +0100 | [diff] [blame] | 1719 | _reinterpret_input_as_3d(reinterpret_input_as_3d), _broadcast_bias(broadcast_bias) |
Gian Marco | 36a0a46 | 2018-01-12 10:21:40 +0000 | [diff] [blame] | 1720 | { |
| 1721 | } |
| 1722 | /** Number of matrix A rows |
| 1723 | * |
| 1724 | * @return the number of matrix A rows |
| 1725 | */ |
| 1726 | int m() const |
| 1727 | { |
| 1728 | return _m; |
| 1729 | } |
| 1730 | /** Number of matrix B columns |
| 1731 | * |
| 1732 | * @return the number of matrix B columns |
| 1733 | */ |
| 1734 | int n() const |
| 1735 | { |
| 1736 | return _n; |
| 1737 | } |
| 1738 | /** Number of matrix A columns or matrix B rows |
| 1739 | * |
| 1740 | * @return the number of matrix A columns or matrix B rows |
| 1741 | */ |
| 1742 | int k() const |
| 1743 | { |
| 1744 | return _k; |
| 1745 | } |
| 1746 | /** Multiplication factor for the width of the 1xW transposed block |
| 1747 | * |
| 1748 | * @return the multiplication factor for the width of the 1xW transposed block |
| 1749 | */ |
| 1750 | int mult_transpose1xW_width() const |
| 1751 | { |
| 1752 | return _mult_transpose1xW_width; |
| 1753 | } |
| 1754 | /** Multiplication factor for the height of the 4x4 interleaved block |
| 1755 | * |
| 1756 | * @return the multiplication factor for the height of the 4x4 interleaved block |
| 1757 | */ |
| 1758 | int mult_interleave4x4_height() const |
| 1759 | { |
| 1760 | return _mult_interleave4x4_height; |
| 1761 | } |
Isabella Gottardi | 8e74f44 | 2018-03-01 16:42:00 +0000 | [diff] [blame] | 1762 | /** Depth (third dimension) of the output tensor to be used with the GEMM3D kernel |
| 1763 | * |
| 1764 | * @note GEMM3D kernel is used when the output has to be reinterpret as 3D tensor. In that case: |
| 1765 | * m = depth_output_gemm3d * output_height |
| 1766 | * |
| 1767 | * @return the depth of the output tensor to be used with the GEMM3D kernel |
| 1768 | */ |
| 1769 | int depth_output_gemm3d() const |
| 1770 | { |
| 1771 | return _depth_output_gemm3d; |
| 1772 | } |
Gian Marco Iodice | 68a3f56 | 2018-07-26 11:44:03 +0100 | [diff] [blame] | 1773 | /** Flag which specifies if the input tensor has to be reinterpreted as 3D |
| 1774 | * |
| 1775 | * @return True if the input tensor has to be reinterpreted as 3D tensor |
| 1776 | */ |
| 1777 | bool reinterpret_input_as_3d() const |
| 1778 | { |
| 1779 | return _reinterpret_input_as_3d; |
| 1780 | }; |
Georgios Pinitas | b0f342e | 2019-05-21 13:32:43 +0100 | [diff] [blame] | 1781 | /** Flag which specifies whether to broadcast the shape of the bias tensor. |
| 1782 | * |
| 1783 | * @return True if the shape of the bias tensor is to be broadcasted. |
| 1784 | */ |
| 1785 | bool broadcast_bias() const |
| 1786 | { |
| 1787 | return _broadcast_bias; |
| 1788 | }; |
Gian Marco | 36a0a46 | 2018-01-12 10:21:40 +0000 | [diff] [blame] | 1789 | |
| 1790 | private: |
SiCong Li | ebd8fb4 | 2020-08-18 11:03:14 +0100 | [diff] [blame] | 1791 | int _m; |
| 1792 | int _n; |
| 1793 | int _k; |
| 1794 | int _mult_transpose1xW_width; |
| 1795 | int _mult_interleave4x4_height; |
| 1796 | int _depth_output_gemm3d; |
| 1797 | bool _reinterpret_input_as_3d; |
| 1798 | bool _broadcast_bias; |
Gian Marco | 36a0a46 | 2018-01-12 10:21:40 +0000 | [diff] [blame] | 1799 | }; |
| 1800 | |
Gian Marco Iodice | 5ba5e09 | 2018-12-06 17:13:09 +0000 | [diff] [blame] | 1801 | /** GEMM LHS (Left Hand Side) matrix information */ |
| 1802 | struct GEMMLHSMatrixInfo |
| 1803 | { |
morgolock | aba2f91 | 2020-05-05 16:28:19 +0100 | [diff] [blame] | 1804 | GEMMLHSMatrixInfo() = default; |
| 1805 | GEMMLHSMatrixInfo(unsigned int m, unsigned int k, unsigned int v, bool trans, bool inter) |
| 1806 | : m0(m), k0(k), v0(v), transpose(trans), interleave(inter) |
| 1807 | { |
| 1808 | } |
Gian Marco Iodice | 5ba5e09 | 2018-12-06 17:13:09 +0000 | [diff] [blame] | 1809 | unsigned int m0{ 1 }; /**< Number of rows processed by the matrix multiplication */ |
| 1810 | unsigned int k0{ 1 }; /**< Number of partial accumulations performed by the matrix multiplication */ |
| 1811 | unsigned int v0{ 1 }; /**< Number of vertical blocks of size (m0xk0) stored on the same output row */ |
| 1812 | bool transpose{ true }; /**< True if the (m0xk0) block has to be transposed before been stored */ |
| 1813 | bool interleave{ true }; /**< True if the v0 (m0xk0) blocks have to be interleaved in the output row */ |
| 1814 | }; |
| 1815 | |
Gian Marco Iodice | 3b0a265 | 2018-12-07 11:18:09 +0000 | [diff] [blame] | 1816 | /** GEMM RHS (Right Hand Side) matrix information */ |
| 1817 | struct GEMMRHSMatrixInfo |
| 1818 | { |
morgolock | aba2f91 | 2020-05-05 16:28:19 +0100 | [diff] [blame] | 1819 | GEMMRHSMatrixInfo() = default; |
Gian Marco Iodice | e3a849a | 2020-06-10 17:59:30 +0100 | [diff] [blame] | 1820 | GEMMRHSMatrixInfo(unsigned int n, unsigned int k, unsigned int h, bool trans, bool inter, bool export_to_cl_img) |
| 1821 | : n0(n), k0(k), h0(h), transpose(trans), interleave(inter), export_to_cl_image(export_to_cl_img) |
morgolock | aba2f91 | 2020-05-05 16:28:19 +0100 | [diff] [blame] | 1822 | { |
| 1823 | } |
Gian Marco Iodice | dd717c3 | 2020-05-28 10:22:03 +0100 | [diff] [blame] | 1824 | unsigned int n0{ 1 }; /**< Number of columns processed by the matrix multiplication */ |
| 1825 | unsigned int k0{ 1 }; /**< Number of partial accumulations performed by the matrix multiplication */ |
| 1826 | unsigned int h0{ 1 }; /**< Number of horizontal blocks of size (k0xn0) stored on the same output row */ |
| 1827 | bool transpose{ true }; /**< True if the (k0xn0) block has to be transposed before been stored */ |
| 1828 | bool interleave{ true }; /**< True if the h0 (k0xn0) blocks have to be interleaved in the output row */ |
| 1829 | bool export_to_cl_image{ false }; /**< True if the reshaped rhs has to be exported to cl_image. n0 must be equal to 4 */ |
Gian Marco Iodice | 3b0a265 | 2018-12-07 11:18:09 +0000 | [diff] [blame] | 1830 | }; |
| 1831 | |
SiCongLi | 579ca84 | 2021-10-18 09:38:33 +0100 | [diff] [blame] | 1832 | class ITensorInfo; |
Chunosov | 5124be5 | 2017-11-22 20:42:13 +0700 | [diff] [blame] | 1833 | |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 1834 | /** Winograd information */ |
| 1835 | struct WinogradInfo |
| 1836 | { |
| 1837 | /** Default constructor |
| 1838 | * |
| 1839 | * @param[in] output_tile_sz Width and height of the output tile |
| 1840 | * @param[in] kernel_sz Width and height of the kernel |
| 1841 | * @param[in] input_dims Width and height of the input tensor before the convolution is applied |
| 1842 | * @param[in] conv_info Convolution info (Pads, strides) |
| 1843 | * @param[in] data_layout Data layout to use for the output tensor once the convolution has been applied |
| 1844 | */ |
| 1845 | WinogradInfo(Size2D output_tile_sz, Size2D kernel_sz, Size2D input_dims, PadStrideInfo conv_info, DataLayout data_layout) |
| 1846 | : output_tile_size(output_tile_sz), kernel_size(kernel_sz), input_dimensions(input_dims), convolution_info(conv_info), output_data_layout(data_layout) |
| 1847 | { |
| 1848 | } |
| 1849 | |
| 1850 | Size2D output_tile_size{}; /**< Width and height of the output tile */ |
| 1851 | Size2D kernel_size{}; /**< Width and height of the kernel*/ |
| 1852 | Size2D input_dimensions{}; /**< Width and height of the input tensor before the convolution is applied */ |
| 1853 | PadStrideInfo convolution_info{}; /**< Convolution info (Pads, strides,...) */ |
| 1854 | DataLayout output_data_layout{ DataLayout::NCHW }; /**< Data layout to use for the output tensor once the convolution has been applied (NCHW or NHWC) */ |
| 1855 | }; |
| 1856 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1857 | /** IO formatting information class*/ |
| 1858 | struct IOFormatInfo |
| 1859 | { |
| 1860 | /** Precision type used when printing floating point numbers */ |
| 1861 | enum class PrecisionType |
| 1862 | { |
| 1863 | Default, /**< Default precision to the one that the current stream has */ |
| 1864 | Custom, /**< Custom precision specified by the user using the precision parameter */ |
| 1865 | Full /**< The maximum precision of the floating point representation */ |
| 1866 | }; |
| 1867 | |
| 1868 | /** Specifies the area to be printed, used by Tensor objects */ |
| 1869 | enum class PrintRegion |
| 1870 | { |
| 1871 | ValidRegion, /**< Prints the valid region of the Tensor object */ |
| 1872 | NoPadding, /**< Prints the Tensor object without the padding */ |
| 1873 | Full /**< Print the tensor object including padding */ |
| 1874 | }; |
| 1875 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 1876 | /** Construct a set of IO formatting information. |
| 1877 | * |
| 1878 | * @param[in] print_region Area to be printed. Used by Tensor objects. Default: ValidRegion. |
| 1879 | * @param[in] precision_type Precision type for floating point numbers. Default: stream default. |
| 1880 | * @param[in] precision Precision value for float point numbers. Default: 10. |
| 1881 | * @param[in] align_columns Whether to align columns when printed. Default: true. |
| 1882 | * @param[in] element_delim Delimeter between elements. Default: " ". |
| 1883 | * @param[in] row_delim Delimenter between rows. Default: "\n". |
| 1884 | */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1885 | IOFormatInfo(PrintRegion print_region = PrintRegion::ValidRegion, |
| 1886 | PrecisionType precision_type = PrecisionType::Default, |
| 1887 | unsigned int precision = 10, |
| 1888 | bool align_columns = true, |
| 1889 | std::string element_delim = " ", |
| 1890 | std::string row_delim = "\n") |
| 1891 | : print_region(print_region), |
| 1892 | precision_type(precision_type), |
| 1893 | precision(precision), |
| 1894 | element_delim(element_delim), |
| 1895 | row_delim(row_delim), |
| 1896 | align_columns(align_columns) |
| 1897 | { |
| 1898 | } |
| 1899 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 1900 | /** Area to be printed by Tensor objects */ |
| 1901 | PrintRegion print_region; |
| 1902 | /** Floating point precision type */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1903 | PrecisionType precision_type; |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 1904 | /** Floating point precision */ |
| 1905 | unsigned int precision; |
| 1906 | /** Element delimeter */ |
| 1907 | std::string element_delim; |
| 1908 | /** Row delimeter */ |
| 1909 | std::string row_delim; |
| 1910 | /** Align columns */ |
| 1911 | bool align_columns; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1912 | }; |
Mohammed Suhail Munshi | d538d16 | 2023-02-16 16:22:32 +0000 | [diff] [blame] | 1913 | |
SiCong Li | 4ceb453 | 2023-03-13 15:02:23 +0000 | [diff] [blame] | 1914 | /** Class for holding information related to cropping */ |
| 1915 | using CropInfo = Padding2D; |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 1916 | } // namespace arm_compute |
Jakub Sujak | 0d27b2e | 2023-08-24 14:01:20 +0100 | [diff] [blame^] | 1917 | #endif // ACL_ARM_COMPUTE_CORE_TYPES_H |