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