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