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