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