Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Gian Marco | 36a0a46 | 2018-01-12 10:21:40 +0000 | [diff] [blame] | 2 | * Copyright (c) 2016-2018 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" |
Michel Iwaniec | 5dfeae6 | 2017-11-29 10:48:23 +0000 | [diff] [blame] | 28 | #include "arm_compute/core/QAsymm8.h" |
| 29 | #include "arm_compute/core/Rounding.h" |
Isabella Gottardi | 6e464c3 | 2018-01-26 12:32:45 +0000 | [diff] [blame] | 30 | #include "arm_compute/core/Size2D.h" |
Georgios Pinitas | 8795ffb | 2017-12-01 16:13:40 +0000 | [diff] [blame] | 31 | #include "arm_compute/core/Strides.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 32 | #include "arm_compute/core/TensorShape.h" |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 33 | #include "support/Half.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 34 | |
Michel Iwaniec | 5dfeae6 | 2017-11-29 10:48:23 +0000 | [diff] [blame] | 35 | #include <cmath> |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 36 | #include <cstddef> |
| 37 | #include <cstdint> |
| 38 | #include <string> |
| 39 | #include <utility> |
| 40 | |
| 41 | namespace arm_compute |
| 42 | { |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 43 | /** 16-bit floating point type */ |
| 44 | using half = half_float::half; |
| 45 | |
Georgios Pinitas | 8795ffb | 2017-12-01 16:13:40 +0000 | [diff] [blame] | 46 | /** Permutation vector */ |
| 47 | using PermutationVector = Strides; |
| 48 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 49 | /** Image colour formats */ |
| 50 | enum class Format |
| 51 | { |
Daniil Efremov | 02bf80d | 2017-11-22 00:26:51 +0700 | [diff] [blame] | 52 | UNKNOWN, /**< Unknown image format */ |
| 53 | U8, /**< 1 channel, 1 U8 per channel */ |
| 54 | S16, /**< 1 channel, 1 S16 per channel */ |
| 55 | U16, /**< 1 channel, 1 U16 per channel */ |
| 56 | S32, /**< 1 channel, 1 S32 per channel */ |
| 57 | U32, /**< 1 channel, 1 U32 per channel */ |
| 58 | F16, /**< 1 channel, 1 F16 per channel */ |
| 59 | F32, /**< 1 channel, 1 F32 per channel */ |
| 60 | UV88, /**< 2 channel, 1 U8 per channel */ |
| 61 | RGB888, /**< 3 channels, 1 U8 per channel */ |
| 62 | RGBA8888, /**< 4 channels, 1 U8 per channel */ |
| 63 | YUV444, /**< A 3 plane of 8 bit 4:4:4 sampled Y, U, V planes */ |
| 64 | YUYV422, /**< A single plane of 32-bit macro pixel of Y0, U0, Y1, V0 bytes */ |
| 65 | NV12, /**< A 2 plane YUV format of Luma (Y) and interleaved UV data at 4:2:0 sampling */ |
| 66 | NV21, /**< A 2 plane YUV format of Luma (Y) and interleaved VU data at 4:2:0 sampling */ |
| 67 | IYUV, /**< A 3 plane of 8-bit 4:2:0 sampled Y, U, V planes */ |
| 68 | 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] | 69 | }; |
| 70 | |
| 71 | /** Available data types */ |
| 72 | enum class DataType |
| 73 | { |
| 74 | UNKNOWN, |
| 75 | U8, |
| 76 | S8, |
| 77 | QS8, |
Michel Iwaniec | 0063380 | 2017-10-12 14:14:15 +0100 | [diff] [blame] | 78 | QASYMM8, |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 79 | U16, |
| 80 | S16, |
| 81 | QS16, |
| 82 | U32, |
| 83 | S32, |
Pablo Tello | f87cc7f | 2017-07-26 10:28:40 +0100 | [diff] [blame] | 84 | QS32, |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 85 | U64, |
| 86 | S64, |
| 87 | F16, |
| 88 | F32, |
| 89 | F64, |
| 90 | SIZET |
| 91 | }; |
| 92 | |
Daniil Efremov | 02bf80d | 2017-11-22 00:26:51 +0700 | [diff] [blame] | 93 | /** Available Sampling Policies */ |
| 94 | enum class SamplingPolicy |
| 95 | { |
| 96 | CENTER, /**< Samples are taken at pixel center */ |
| 97 | TOP_LEFT /**< Samples are taken at pixel top left corner */ |
| 98 | }; |
| 99 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 100 | /** Constant value of the border pixels when using BorderMode::CONSTANT */ |
| 101 | constexpr uint8_t CONSTANT_BORDER_VALUE = 199; |
| 102 | |
| 103 | /* Constant value used to indicate a half-scale pyramid */ |
| 104 | constexpr float SCALE_PYRAMID_HALF = 0.5f; |
| 105 | |
| 106 | /* Constant value used to indicate a ORB scaled pyramid */ |
| 107 | constexpr float SCALE_PYRAMID_ORB = 8.408964152537146130583778358414e-01; |
| 108 | |
Georgios Pinitas | 4074c99 | 2018-01-30 18:13:46 +0000 | [diff] [blame] | 109 | /** Supported tensor data layouts */ |
| 110 | enum class DataLayout |
| 111 | { |
| 112 | NCHW, |
| 113 | NHWC |
| 114 | }; |
| 115 | |
Michel Iwaniec | 0063380 | 2017-10-12 14:14:15 +0100 | [diff] [blame] | 116 | /** Quantization settings (used for QASYMM8 data type) */ |
| 117 | struct QuantizationInfo |
| 118 | { |
| 119 | QuantizationInfo() |
| 120 | : scale(0.0f), offset(0) |
| 121 | { |
| 122 | } |
| 123 | |
| 124 | QuantizationInfo(float scale, int offset) |
| 125 | : scale(scale), offset(offset) |
| 126 | { |
| 127 | } |
| 128 | |
Daniil Efremov | eed841c | 2017-11-09 19:05:25 +0700 | [diff] [blame] | 129 | bool operator==(const QuantizationInfo &other) |
| 130 | { |
| 131 | return scale == other.scale && offset == other.offset; |
| 132 | } |
| 133 | |
| 134 | bool operator!=(const QuantizationInfo &other) |
| 135 | { |
| 136 | return !(*this == other); |
| 137 | } |
| 138 | |
Michel Iwaniec | 0063380 | 2017-10-12 14:14:15 +0100 | [diff] [blame] | 139 | float scale; /**< scale */ |
| 140 | int offset; /**< offset */ |
| 141 | |
| 142 | /** Quantizes a value using the scale/offset in this QuantizationInfo */ |
Michel Iwaniec | 5dfeae6 | 2017-11-29 10:48:23 +0000 | [diff] [blame] | 143 | qasymm8_t quantize(float value, RoundingPolicy rounding_policy) const |
Michel Iwaniec | 0063380 | 2017-10-12 14:14:15 +0100 | [diff] [blame] | 144 | { |
| 145 | ARM_COMPUTE_ERROR_ON_MSG(scale == 0, "QuantizationInfo::quantize: scale == 0"); |
Michel Iwaniec | 5dfeae6 | 2017-11-29 10:48:23 +0000 | [diff] [blame] | 146 | return sqcvt_qasymm8_f32(value, scale, offset, rounding_policy); |
Michel Iwaniec | 0063380 | 2017-10-12 14:14:15 +0100 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | /** Dequantizes a value using the scale/offset in this QuantizationInfo */ |
Michel Iwaniec | 5dfeae6 | 2017-11-29 10:48:23 +0000 | [diff] [blame] | 150 | float dequantize(qasymm8_t value) const |
Michel Iwaniec | 0063380 | 2017-10-12 14:14:15 +0100 | [diff] [blame] | 151 | { |
| 152 | ARM_COMPUTE_ERROR_ON_MSG(scale == 0, "QuantizationInfo::dequantize: scale == 0"); |
Michel Iwaniec | 5dfeae6 | 2017-11-29 10:48:23 +0000 | [diff] [blame] | 153 | return scvt_f32_qasymm8(value, scale, offset); |
Michel Iwaniec | 0063380 | 2017-10-12 14:14:15 +0100 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | /** Indicates whether this QuantizationInfo has valid settings or not */ |
| 157 | bool empty() const |
| 158 | { |
| 159 | return scale == 0; |
| 160 | } |
| 161 | }; |
| 162 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 163 | struct ValidRegion |
| 164 | { |
| 165 | ValidRegion() |
| 166 | : anchor{}, shape{} |
| 167 | { |
| 168 | } |
| 169 | |
| 170 | ValidRegion(const ValidRegion &) = default; |
| 171 | ValidRegion(ValidRegion &&) = default; |
| 172 | ValidRegion &operator=(const ValidRegion &) = default; |
| 173 | ValidRegion &operator=(ValidRegion &&) = default; |
| 174 | ~ValidRegion() = default; |
| 175 | |
Diego Lopez Recas | bcbc970 | 2017-12-18 11:28:27 +0000 | [diff] [blame] | 176 | ValidRegion(const Coordinates &an_anchor, const TensorShape &a_shape) |
| 177 | : anchor{ an_anchor }, shape{ a_shape } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 178 | { |
Diego Lopez Recas | bcbc970 | 2017-12-18 11:28:27 +0000 | [diff] [blame] | 179 | anchor.set_num_dimensions(std::max(anchor.num_dimensions(), shape.num_dimensions())); |
| 180 | } |
| 181 | |
| 182 | ValidRegion(const Coordinates &an_anchor, const TensorShape &a_shape, size_t num_dimensions) |
| 183 | : anchor{ an_anchor }, shape{ a_shape } |
| 184 | { |
| 185 | ARM_COMPUTE_ERROR_ON(num_dimensions < std::max(anchor.num_dimensions(), shape.num_dimensions())); |
| 186 | anchor.set_num_dimensions(num_dimensions); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | /** Return the start of the valid region for the given dimension @p d */ |
| 190 | int start(unsigned int d) const |
| 191 | { |
| 192 | return anchor[d]; |
| 193 | } |
| 194 | |
| 195 | /** Return the end of the valid region for the given dimension @p d */ |
| 196 | int end(unsigned int d) const |
| 197 | { |
| 198 | return anchor[d] + shape[d]; |
| 199 | } |
| 200 | |
Diego Lopez Recas | 35ceeb2 | 2017-12-04 18:56:10 +0000 | [diff] [blame] | 201 | /** Accessor to set the value of anchor and shape for one of the dimensions. |
| 202 | * |
| 203 | * @param[in] dimension Dimension for which the value is set. |
| 204 | * @param[in] start Value to be set in anchor for the dimension. |
| 205 | * @param[in] size Value to be set in shape for the dimension. |
| 206 | * |
| 207 | * @return *this. |
| 208 | */ |
| 209 | ValidRegion &set(size_t dimension, int start, size_t size) |
| 210 | { |
| 211 | anchor.set(dimension, start); |
| 212 | shape.set(dimension, size); |
| 213 | return *this; |
| 214 | } |
| 215 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 216 | Coordinates anchor; |
| 217 | TensorShape shape; |
| 218 | }; |
| 219 | |
| 220 | /** Methods available to handle borders */ |
| 221 | enum class BorderMode |
| 222 | { |
| 223 | UNDEFINED, /**< Borders are left undefined */ |
| 224 | CONSTANT, /**< Pixels outside the image are assumed to have a constant value */ |
| 225 | REPLICATE /**< Pixels outside the image are assumed to have the same value as the closest image pixel */ |
| 226 | }; |
| 227 | |
| 228 | /** Container for 2D border size */ |
| 229 | struct BorderSize |
| 230 | { |
| 231 | /** Empty border, i.e. no border */ |
| 232 | constexpr BorderSize() |
| 233 | : top{ 0 }, right{ 0 }, bottom{ 0 }, left{ 0 } |
| 234 | { |
| 235 | } |
| 236 | |
| 237 | /** Border with equal size around the 2D plane */ |
Moritz Pflanzer | 7655a67 | 2017-09-23 11:57:33 +0100 | [diff] [blame] | 238 | explicit constexpr BorderSize(unsigned int size) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 239 | : top{ size }, right{ size }, bottom{ size }, left{ size } |
| 240 | { |
| 241 | } |
| 242 | |
| 243 | /** Border with same size for top/bottom and left/right */ |
| 244 | constexpr BorderSize(unsigned int top_bottom, unsigned int left_right) |
| 245 | : top{ top_bottom }, right{ left_right }, bottom{ top_bottom }, left{ left_right } |
| 246 | { |
| 247 | } |
| 248 | |
| 249 | /** Border with different sizes */ |
| 250 | constexpr BorderSize(unsigned int top, unsigned int right, unsigned int bottom, unsigned int left) |
| 251 | : top{ top }, right{ right }, bottom{ bottom }, left{ left } |
| 252 | { |
| 253 | } |
| 254 | |
| 255 | /** Check if the entire border is zero */ |
| 256 | constexpr bool empty() const |
| 257 | { |
| 258 | return top == 0 && right == 0 && bottom == 0 && left == 0; |
| 259 | } |
| 260 | |
| 261 | /** Check if the border is the same size on all sides */ |
| 262 | constexpr bool uniform() const |
| 263 | { |
| 264 | return top == right && top == bottom && top == left; |
| 265 | } |
| 266 | |
| 267 | BorderSize &operator*=(float scale) |
| 268 | { |
| 269 | top *= scale; |
| 270 | right *= scale; |
| 271 | bottom *= scale; |
| 272 | left *= scale; |
| 273 | |
| 274 | return *this; |
| 275 | } |
| 276 | |
| 277 | BorderSize operator*(float scale) |
| 278 | { |
| 279 | BorderSize size = *this; |
| 280 | size *= scale; |
| 281 | |
| 282 | return size; |
| 283 | } |
| 284 | |
| 285 | void limit(const BorderSize &limit) |
| 286 | { |
| 287 | top = std::min(top, limit.top); |
| 288 | right = std::min(right, limit.right); |
| 289 | bottom = std::min(bottom, limit.bottom); |
| 290 | left = std::min(left, limit.left); |
| 291 | } |
| 292 | |
| 293 | unsigned int top; |
| 294 | unsigned int right; |
| 295 | unsigned int bottom; |
| 296 | unsigned int left; |
| 297 | }; |
| 298 | |
| 299 | using PaddingSize = BorderSize; |
| 300 | |
| 301 | /** Policy to handle overflow */ |
| 302 | enum class ConvertPolicy |
| 303 | { |
| 304 | WRAP, /**< Wrap around */ |
| 305 | SATURATE /**< Saturate */ |
| 306 | }; |
| 307 | |
| 308 | /** Interpolation method */ |
| 309 | enum class InterpolationPolicy |
| 310 | { |
| 311 | NEAREST_NEIGHBOR, /**< Output values are defined to match the source pixel whose center is nearest to the sample position */ |
| 312 | BILINEAR, /**< Output values are defined by bilinear interpolation between the pixels */ |
| 313 | 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 */ |
| 314 | }; |
| 315 | |
| 316 | /** Bilinear Interpolation method used by LKTracker */ |
| 317 | enum class BilinearInterpolation |
| 318 | { |
| 319 | BILINEAR_OLD_NEW, |
| 320 | BILINEAR_SCHARR |
| 321 | }; |
| 322 | |
| 323 | /** Threshold mode */ |
| 324 | enum class ThresholdType |
| 325 | { |
| 326 | BINARY, /**< Threshold with one value */ |
| 327 | RANGE /**< Threshold with two values*/ |
| 328 | }; |
| 329 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 330 | /** Termination criteria */ |
| 331 | enum class Termination |
| 332 | { |
| 333 | TERM_CRITERIA_EPSILON, |
| 334 | TERM_CRITERIA_ITERATIONS, |
| 335 | TERM_CRITERIA_BOTH |
| 336 | }; |
| 337 | |
| 338 | /** Magnitude calculation type. */ |
| 339 | enum class MagnitudeType |
| 340 | { |
| 341 | L1NORM, /**< L1 normalization type */ |
| 342 | L2NORM /**< L2 normalization type */ |
| 343 | }; |
| 344 | |
| 345 | /** Phase calculation type. |
| 346 | * |
| 347 | * @note When PhaseType == SIGNED, each angle is mapped to the range 0 to 255 inclusive otherwise angles between 0 and 180 |
| 348 | */ |
| 349 | enum class PhaseType |
| 350 | { |
| 351 | SIGNED, /**< Angle range: [0, 360] */ |
| 352 | UNSIGNED /**< Angle range: [0, 180] */ |
| 353 | }; |
| 354 | |
| 355 | /** Keypoint type */ |
| 356 | struct KeyPoint |
| 357 | { |
| 358 | int32_t x{ 0 }; /**< X coordinates */ |
| 359 | int32_t y{ 0 }; /**< Y coordinates */ |
| 360 | float strength{ 0.f }; /**< Strength of the point */ |
| 361 | float scale{ 0.f }; /**< Scale initialized to 0 by the corner detector */ |
| 362 | float orientation{ 0.f }; /**< Orientation initialized to 0 by the corner detector */ |
| 363 | int32_t tracking_status{ 0 }; /**< Status initialized to 1 by the corner detector, set to 0 when the point is lost */ |
| 364 | float error{ 0.f }; /**< Tracking error initialized to 0 by the corner detector */ |
| 365 | }; |
| 366 | |
| 367 | using InternalKeypoint = std::tuple<float, float, float>; /* x,y,strength */ |
| 368 | |
| 369 | /** Rectangle type */ |
| 370 | struct Rectangle |
| 371 | { |
| 372 | uint16_t x; /**< Top-left x coordinate */ |
| 373 | uint16_t y; /**< Top-left y coordinate */ |
| 374 | uint16_t width; /**< Width of the rectangle */ |
| 375 | uint16_t height; /**< Height of the rectangle */ |
| 376 | }; |
| 377 | |
| 378 | /** Coordinate type */ |
| 379 | struct Coordinates2D |
| 380 | { |
| 381 | int32_t x; /**< X coordinates */ |
| 382 | int32_t y; /**< Y coordinates */ |
| 383 | }; |
| 384 | |
| 385 | /** Coordinate type */ |
| 386 | struct Coordinates3D |
| 387 | { |
| 388 | uint32_t x; /**< X coordinates */ |
| 389 | uint32_t y; /**< Y coordinates */ |
| 390 | uint32_t z; /**< Z coordinates */ |
| 391 | }; |
| 392 | |
Georgios Pinitas | 7b7858d | 2017-06-21 16:44:24 +0100 | [diff] [blame] | 393 | /** Region of interest */ |
| 394 | struct ROI |
| 395 | { |
| 396 | Rectangle rect; /**< Rectangle specifying the region of interest */ |
| 397 | uint16_t batch_idx; /**< The batch index of the region of interest */ |
| 398 | }; |
| 399 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 400 | /** Available channels */ |
| 401 | enum class Channel |
| 402 | { |
| 403 | UNKNOWN, /** Unknown channel format */ |
| 404 | C0, /**< First channel (used by formats with unknown channel types). */ |
| 405 | C1, /**< Second channel (used by formats with unknown channel types). */ |
| 406 | C2, /**< Third channel (used by formats with unknown channel types). */ |
| 407 | C3, /**< Fourth channel (used by formats with unknown channel types). */ |
| 408 | R, /**< Red channel. */ |
| 409 | G, /**< Green channel. */ |
| 410 | B, /**< Blue channel. */ |
| 411 | A, /**< Alpha channel. */ |
| 412 | Y, /**< Luma channel. */ |
| 413 | U, /**< Cb/U channel. */ |
| 414 | V /**< Cr/V/Value channel. */ |
| 415 | }; |
| 416 | |
| 417 | /** Available matrix patterns */ |
| 418 | enum class MatrixPattern |
| 419 | { |
| 420 | BOX, /**< Box pattern matrix. */ |
| 421 | CROSS, /**< Cross pattern matrix. */ |
| 422 | DISK, /**< Disk pattern matrix. */ |
| 423 | OTHER /**< Any other matrix pattern. */ |
| 424 | }; |
| 425 | |
| 426 | /** Available non linear functions. */ |
| 427 | enum class NonLinearFilterFunction : unsigned |
| 428 | { |
| 429 | MEDIAN = 0, /**< Non linear median filter. */ |
| 430 | MIN = 1, /**< Non linear erode. */ |
| 431 | MAX = 2, /**< Non linear dilate. */ |
| 432 | }; |
| 433 | |
Georgios Pinitas | d976958 | 2017-08-03 10:19:40 +0100 | [diff] [blame] | 434 | /** Available reduction operations */ |
| 435 | enum class ReductionOperation |
| 436 | { |
| 437 | SUM_SQUARE, /**< Sum of squares */ |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 438 | SUM, /**< Sum */ |
Georgios Pinitas | d976958 | 2017-08-03 10:19:40 +0100 | [diff] [blame] | 439 | }; |
| 440 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 441 | /** The normalization type used for the normalization layer */ |
| 442 | enum class NormType |
| 443 | { |
| 444 | IN_MAP_1D, /**< Normalization applied within the same map in 1D region */ |
| 445 | IN_MAP_2D, /**< Normalization applied within the same map in 2D region */ |
| 446 | CROSS_MAP /**< Normalization applied cross maps */ |
| 447 | }; |
| 448 | |
| 449 | /** Normalization type for Histogram of Oriented Gradients (HOG) */ |
| 450 | enum class HOGNormType |
| 451 | { |
| 452 | L2_NORM = 1, /**< L2-norm */ |
| 453 | L2HYS_NORM = 2, /**< L2-norm followed by clipping */ |
| 454 | L1_NORM = 3 /**< L1 norm */ |
| 455 | }; |
| 456 | |
| 457 | /** Detection window used for the object detection. The detection window keeps the following information: |
| 458 | * |
| 459 | * -# Geometry of the rectangular window (x/y of top-left corner and width/height) |
| 460 | * -# Index of the class used for evaluating which class the detection window belongs to |
| 461 | * -# Confidence value (score) obtained with the classifier |
| 462 | */ |
| 463 | struct DetectionWindow |
| 464 | { |
| 465 | uint16_t x{ 0 }; /**< Top-left x coordinate */ |
| 466 | uint16_t y{ 0 }; /**< Top-left y coordinate */ |
| 467 | uint16_t width{ 0 }; /**< Width of the detection window */ |
| 468 | uint16_t height{ 0 }; /**< Height of the detection window */ |
| 469 | uint16_t idx_class{ 0 }; /**< Index of the class */ |
| 470 | float score{ 0.f }; /**< Confidence value for the detection window */ |
| 471 | }; |
| 472 | |
| 473 | /** Dimension rounding type when down-scaling on CNNs |
| 474 | * @note Used in pooling and convolution layer |
| 475 | */ |
| 476 | enum class DimensionRoundingType |
| 477 | { |
| 478 | FLOOR, /**< Floor rounding */ |
| 479 | CEIL /**< Ceil rounding */ |
| 480 | }; |
| 481 | |
| 482 | /** Available pooling types */ |
| 483 | enum class PoolingType |
| 484 | { |
| 485 | MAX, /**< Max Pooling */ |
Georgios Pinitas | cdf5145 | 2017-08-31 14:21:36 +0100 | [diff] [blame] | 486 | AVG, /**< Average Pooling */ |
| 487 | L2 /**< L2 Pooling */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 488 | }; |
| 489 | |
| 490 | /** Padding and stride information class */ |
| 491 | class PadStrideInfo |
| 492 | { |
| 493 | public: |
| 494 | /** Constructor |
| 495 | * |
| 496 | * @param[in] stride_x (Optional) Stride, in elements, across x. Defaults to 1. |
| 497 | * @param[in] stride_y (Optional) Stride, in elements, across y. Defaults to 1. |
| 498 | * @param[in] pad_x (Optional) Padding, in elements, across x. Defaults to 0. |
| 499 | * @param[in] pad_y (Optional) Padding, in elements, across y. Defaults to 0. |
| 500 | * @param[in] round (Optional) Dimensions rounding. Defaults to @ref FLOOR. |
| 501 | */ |
| 502 | PadStrideInfo(unsigned int stride_x = 1, unsigned int stride_y = 1, |
| 503 | unsigned int pad_x = 0, unsigned int pad_y = 0, |
| 504 | DimensionRoundingType round = DimensionRoundingType::FLOOR) |
| 505 | : _stride(std::make_pair(stride_x, stride_y)), |
Jaroslaw Rzepecki | a1ed41f | 2017-10-13 11:13:58 +0100 | [diff] [blame] | 506 | _pad_left(pad_x), |
| 507 | _pad_top(pad_y), |
| 508 | _pad_right(pad_x), |
| 509 | _pad_bottom(pad_y), |
| 510 | _round_type(round) |
| 511 | { |
| 512 | } |
| 513 | /** Constructor |
| 514 | * |
| 515 | * @param[in] stride_x Stride, in elements, across x. |
| 516 | * @param[in] stride_y Stride, in elements, across y. |
| 517 | * @param[in] pad_left Padding across x on the left, in elements. |
| 518 | * @param[in] pad_top Padding across y on the top, in elements. |
| 519 | * @param[in] pad_right Padding across x on the right, in elements. |
| 520 | * @param[in] pad_bottom Padding across y on the bottom, in elements. |
| 521 | * @param[in] round Dimensions rounding. |
| 522 | */ |
| 523 | PadStrideInfo(unsigned int stride_x, unsigned int stride_y, |
| 524 | unsigned int pad_left, unsigned int pad_right, |
| 525 | unsigned int pad_top, unsigned int pad_bottom, |
| 526 | DimensionRoundingType round) |
| 527 | : _stride(std::make_pair(stride_x, stride_y)), |
| 528 | _pad_left(pad_left), |
| 529 | _pad_top(pad_top), |
| 530 | _pad_right(pad_right), |
| 531 | _pad_bottom(pad_bottom), |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 532 | _round_type(round) |
| 533 | { |
| 534 | } |
| 535 | std::pair<unsigned int, unsigned int> stride() const |
| 536 | { |
| 537 | return _stride; |
| 538 | } |
Anthony Barbier | 21f67d6 | 2018-02-16 15:17:48 +0000 | [diff] [blame] | 539 | bool padding_is_symmetric() const |
| 540 | { |
| 541 | return (_pad_left == _pad_right) && (_pad_top == _pad_bottom); |
| 542 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 543 | std::pair<unsigned int, unsigned int> pad() const |
| 544 | { |
Jaroslaw Rzepecki | a1ed41f | 2017-10-13 11:13:58 +0100 | [diff] [blame] | 545 | //this accessor should be used only when padding is symmetric |
Anthony Barbier | 21f67d6 | 2018-02-16 15:17:48 +0000 | [diff] [blame] | 546 | ARM_COMPUTE_ERROR_ON(!padding_is_symmetric()); |
Jaroslaw Rzepecki | a1ed41f | 2017-10-13 11:13:58 +0100 | [diff] [blame] | 547 | return std::make_pair(_pad_left, _pad_top); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 548 | } |
Jaroslaw Rzepecki | a1ed41f | 2017-10-13 11:13:58 +0100 | [diff] [blame] | 549 | |
| 550 | unsigned int pad_left() const |
| 551 | { |
| 552 | return _pad_left; |
| 553 | } |
| 554 | unsigned int pad_right() const |
| 555 | { |
| 556 | return _pad_right; |
| 557 | } |
| 558 | unsigned int pad_top() const |
| 559 | { |
| 560 | return _pad_top; |
| 561 | } |
| 562 | unsigned int pad_bottom() const |
| 563 | { |
| 564 | return _pad_bottom; |
| 565 | } |
| 566 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 567 | DimensionRoundingType round() const |
| 568 | { |
| 569 | return _round_type; |
| 570 | } |
| 571 | |
Jaroslaw Rzepecki | a1ed41f | 2017-10-13 11:13:58 +0100 | [diff] [blame] | 572 | bool has_padding() const |
| 573 | { |
| 574 | return (_pad_left != 0 || _pad_top != 0 || _pad_right != 0 || _pad_bottom != 0); |
| 575 | } |
| 576 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 577 | private: |
| 578 | std::pair<unsigned int, unsigned int> _stride; |
Jaroslaw Rzepecki | a1ed41f | 2017-10-13 11:13:58 +0100 | [diff] [blame] | 579 | unsigned int _pad_left; |
| 580 | unsigned int _pad_top; |
| 581 | unsigned int _pad_right; |
| 582 | unsigned int _pad_bottom; |
| 583 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 584 | DimensionRoundingType _round_type; |
| 585 | }; |
| 586 | |
| 587 | /** Pooling Layer Information class */ |
| 588 | class PoolingLayerInfo |
| 589 | { |
| 590 | public: |
Georgios Pinitas | 4c2dd54 | 2017-11-13 12:58:41 +0000 | [diff] [blame] | 591 | /** Default Constructor */ |
| 592 | PoolingLayerInfo() |
Isabella Gottardi | 6e464c3 | 2018-01-26 12:32:45 +0000 | [diff] [blame] | 593 | : _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] | 594 | { |
| 595 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 596 | /** Default Constructor |
| 597 | * |
Georgios Pinitas | 4c2dd54 | 2017-11-13 12:58:41 +0000 | [diff] [blame] | 598 | * @param[in] pool_type Pooling type @ref PoolingType. |
| 599 | * @param[in] pool_size Pooling size, in elements, across x and y. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 600 | * @param[in] pad_stride_info (Optional) Padding and stride information @ref PadStrideInfo |
Georgios Pinitas | adaae7e | 2017-10-30 15:56:32 +0000 | [diff] [blame] | 601 | * @param[in] exclude_padding (Optional) Strategy when accounting padding in calculations. |
| 602 | * True will exclude padding while false will not (Used in AVG/L2 pooling to determine the pooling area). |
| 603 | * Defaults to false; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 604 | */ |
Georgios Pinitas | 4c2dd54 | 2017-11-13 12:58:41 +0000 | [diff] [blame] | 605 | explicit PoolingLayerInfo(PoolingType pool_type, |
| 606 | unsigned int pool_size, |
| 607 | PadStrideInfo pad_stride_info = PadStrideInfo(), |
| 608 | bool exclude_padding = false) |
Isabella Gottardi | 6e464c3 | 2018-01-26 12:32:45 +0000 | [diff] [blame] | 609 | : _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) |
| 610 | { |
| 611 | } |
| 612 | /** Default Constructor |
| 613 | * |
| 614 | * @param[in] pool_type Pooling type @ref PoolingType. |
| 615 | * @param[in] pool_size Pooling size, in elements, across x and y. |
| 616 | * @param[in] pad_stride_info (Optional) Padding and stride information @ref PadStrideInfo |
| 617 | * @param[in] exclude_padding (Optional) Strategy when accounting padding in calculations. |
| 618 | * True will exclude padding while false will not (Used in AVG/L2 pooling to determine the pooling area). |
| 619 | * Defaults to false; |
| 620 | */ |
| 621 | explicit PoolingLayerInfo(PoolingType pool_type, |
| 622 | Size2D pool_size, |
| 623 | PadStrideInfo pad_stride_info = PadStrideInfo(), |
| 624 | bool exclude_padding = false) |
Georgios Pinitas | 4c2dd54 | 2017-11-13 12:58:41 +0000 | [diff] [blame] | 625 | : _pool_type(pool_type), _pool_size(pool_size), _pad_stride_info(pad_stride_info), _exclude_padding(exclude_padding), _is_global_pooling(false) |
| 626 | { |
| 627 | } |
| 628 | /** Default Constructor |
| 629 | * |
| 630 | * @note This constructor is used for global pooling |
| 631 | * |
| 632 | * @param[in] pool_type Pooling type @ref PoolingType. |
| 633 | */ |
| 634 | explicit PoolingLayerInfo(PoolingType pool_type) |
Isabella Gottardi | 6e464c3 | 2018-01-26 12:32:45 +0000 | [diff] [blame] | 635 | : _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] | 636 | { |
| 637 | } |
| 638 | PoolingType pool_type() const |
| 639 | { |
| 640 | return _pool_type; |
| 641 | } |
Isabella Gottardi | 6e464c3 | 2018-01-26 12:32:45 +0000 | [diff] [blame] | 642 | const Size2D &pool_size() const |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 643 | { |
| 644 | return _pool_size; |
| 645 | } |
| 646 | PadStrideInfo pad_stride_info() const |
| 647 | { |
| 648 | return _pad_stride_info; |
| 649 | } |
Georgios Pinitas | adaae7e | 2017-10-30 15:56:32 +0000 | [diff] [blame] | 650 | bool exclude_padding() const |
| 651 | { |
| 652 | return _exclude_padding; |
| 653 | } |
Georgios Pinitas | 4c2dd54 | 2017-11-13 12:58:41 +0000 | [diff] [blame] | 654 | bool is_global_pooling() const |
| 655 | { |
| 656 | return _is_global_pooling; |
| 657 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 658 | |
| 659 | private: |
| 660 | PoolingType _pool_type; |
Isabella Gottardi | 6e464c3 | 2018-01-26 12:32:45 +0000 | [diff] [blame] | 661 | Size2D _pool_size; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 662 | PadStrideInfo _pad_stride_info; |
Georgios Pinitas | adaae7e | 2017-10-30 15:56:32 +0000 | [diff] [blame] | 663 | bool _exclude_padding; |
Georgios Pinitas | 4c2dd54 | 2017-11-13 12:58:41 +0000 | [diff] [blame] | 664 | bool _is_global_pooling; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 665 | }; |
| 666 | |
Georgios Pinitas | 7b7858d | 2017-06-21 16:44:24 +0100 | [diff] [blame] | 667 | /** ROI Pooling Layer Information class */ |
| 668 | class ROIPoolingLayerInfo |
| 669 | { |
| 670 | public: |
| 671 | /** Default Constructor |
| 672 | * |
| 673 | * @param[in] pooled_width Pooled width of the layer. |
| 674 | * @param[in] pooled_height Pooled height of the layer. |
| 675 | * @param[in] spatial_scale Spatial scale to be applied to the ROI coordinates and dimensions. |
| 676 | */ |
| 677 | ROIPoolingLayerInfo(unsigned int pooled_width, unsigned int pooled_height, float spatial_scale) |
| 678 | : _pooled_width(pooled_width), _pooled_height(pooled_height), _spatial_scale(spatial_scale) |
| 679 | { |
| 680 | } |
| 681 | unsigned int pooled_width() const |
| 682 | { |
| 683 | return _pooled_width; |
| 684 | } |
| 685 | unsigned int pooled_height() const |
| 686 | { |
| 687 | return _pooled_height; |
| 688 | } |
| 689 | float spatial_scale() const |
| 690 | { |
| 691 | return _spatial_scale; |
| 692 | } |
| 693 | |
| 694 | private: |
| 695 | unsigned int _pooled_width; |
| 696 | unsigned int _pooled_height; |
| 697 | float _spatial_scale; |
| 698 | }; |
| 699 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 700 | /** Activation Layer Information class */ |
| 701 | class ActivationLayerInfo |
| 702 | { |
| 703 | public: |
| 704 | /** Available activation functions */ |
| 705 | enum class ActivationFunction |
| 706 | { |
Georgios Pinitas | 64ebe5b | 2017-09-01 17:44:24 +0100 | [diff] [blame] | 707 | LOGISTIC, /**< Logistic ( \f$ f(x) = \frac{1}{1 + e^{-x}} \f$ ) */ |
| 708 | TANH, /**< Hyperbolic tangent ( \f$ f(x) = a \cdot tanh(b \cdot x) \f$ ) */ |
| 709 | RELU, /**< Rectifier ( \f$ f(x) = max(0,x) \f$ ) */ |
| 710 | BOUNDED_RELU, /**< Upper Bounded Rectifier ( \f$ f(x) = min(a, max(0,x)) \f$ ) */ |
| 711 | LU_BOUNDED_RELU, /**< Lower and Upper Bounded Rectifier ( \f$ f(x) = min(a, max(b,x)) \f$ ) */ |
| 712 | LEAKY_RELU, /**< Leaky Rectifier ( \f$ f(x)= log(1+e^x) \f$ ) */ |
| 713 | SOFT_RELU, /**< Soft Rectifier ( \f$ f(x)= log(1+e^x) \f$ ) */ |
| 714 | ABS, /**< Absolute ( \f$ f(x)= |x| \f$ ) */ |
| 715 | SQUARE, /**< Square ( \f$ f(x)= x^2 \f$ )*/ |
| 716 | SQRT, /**< Square root ( \f$ f(x) = \sqrt{x} \f$ )*/ |
| 717 | LINEAR /**< Linear ( \f$ f(x)= ax + b \f$ ) */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 718 | }; |
| 719 | |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 720 | ActivationLayerInfo() = default; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 721 | /** Default Constructor |
| 722 | * |
| 723 | * @param[in] f The activation function to use. |
| 724 | * @param[in] a (Optional) The alpha parameter used by some activation functions |
Georgios Pinitas | 64ebe5b | 2017-09-01 17:44:24 +0100 | [diff] [blame] | 725 | * (@ref ActivationFunction::BOUNDED_RELU, @ref ActivationFunction::LU_BOUNDED_RELU, @ref ActivationFunction::LINEAR, @ref ActivationFunction::TANH). |
| 726 | * @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] | 727 | */ |
| 728 | ActivationLayerInfo(ActivationFunction f, float a = 0.0f, float b = 0.0f) |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 729 | : _act(f), _a(a), _b(b), _enabled(true) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 730 | { |
| 731 | } |
| 732 | ActivationFunction activation() const |
| 733 | { |
| 734 | return _act; |
| 735 | } |
| 736 | float a() const |
| 737 | { |
| 738 | return _a; |
| 739 | } |
| 740 | float b() const |
| 741 | { |
| 742 | return _b; |
| 743 | } |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 744 | bool enabled() const |
| 745 | { |
| 746 | return _enabled; |
| 747 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 748 | |
| 749 | private: |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 750 | ActivationFunction _act = { ActivationLayerInfo::ActivationFunction::LOGISTIC }; |
| 751 | float _a = {}; |
| 752 | float _b = {}; |
| 753 | bool _enabled = { false }; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 754 | }; |
| 755 | |
| 756 | /** Normalization Layer Information class */ |
| 757 | class NormalizationLayerInfo |
| 758 | { |
| 759 | public: |
| 760 | /** Default Constructor |
| 761 | * |
| 762 | * @param[in] type The normalization type. Can be @ref NormType::IN_MAP_1D, @ref NormType::IN_MAP_2D or @ref NORM_TYPE::CROSS_MAP |
| 763 | * @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] | 764 | * @param[in] alpha (Optional) Alpha parameter used by normalization equation. Defaults to 0.0001. |
| 765 | * @param[in] beta (Optional) Beta parameter used by normalization equation. Defaults to 0.5. |
| 766 | * @param[in] kappa (Optional) Kappa parameter used by [Krichevksy 2012] Across Channel Local Brightness Normalization equation. |
| 767 | * @param[in] is_scaled (Optional) Boolean that specifies if alpha will be scaled by the normalization size or not. |
| 768 | * Should be false to follow [Krichevksy 2012]. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 769 | */ |
Georgios Pinitas | 41caa62 | 2017-11-16 14:37:08 +0000 | [diff] [blame] | 770 | NormalizationLayerInfo(NormType type, uint32_t norm_size = 5, float alpha = 0.0001f, float beta = 0.5f, float kappa = 1.f, bool is_scaled = true) |
| 771 | : _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] | 772 | { |
| 773 | } |
| 774 | NormType type() const |
| 775 | { |
| 776 | return _type; |
| 777 | } |
| 778 | uint32_t norm_size() const |
| 779 | { |
| 780 | return _norm_size; |
| 781 | } |
| 782 | float alpha() const |
| 783 | { |
| 784 | return _alpha; |
| 785 | } |
| 786 | float beta() const |
| 787 | { |
| 788 | return _beta; |
| 789 | } |
| 790 | float kappa() const |
| 791 | { |
| 792 | return _kappa; |
| 793 | } |
Georgios Pinitas | 41caa62 | 2017-11-16 14:37:08 +0000 | [diff] [blame] | 794 | bool is_cross_map() const |
| 795 | { |
| 796 | return _type == NormType::CROSS_MAP; |
| 797 | } |
| 798 | bool is_in_map() const |
| 799 | { |
| 800 | return !is_cross_map(); |
| 801 | } |
| 802 | /** Return the scaling factor of the normalization function. |
| 803 | * |
| 804 | * If is_scaled is set to false then [Krichevksy 2012] normalization scaling is performed, |
| 805 | * 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] | 806 | * |
| 807 | * @return The normalization scaling factor. |
| 808 | */ |
| 809 | float scale_coeff() const |
| 810 | { |
| 811 | 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] | 812 | return (_is_scaled) ? (_alpha / size) : _alpha; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | private: |
| 816 | NormType _type; |
| 817 | uint32_t _norm_size; |
| 818 | float _alpha; |
| 819 | float _beta; |
| 820 | float _kappa; |
Georgios Pinitas | 41caa62 | 2017-11-16 14:37:08 +0000 | [diff] [blame] | 821 | bool _is_scaled; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 822 | }; |
| 823 | |
Gian Marco Iodice | 559d771 | 2017-08-08 08:38:09 +0100 | [diff] [blame] | 824 | /** 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] | 825 | class WeightsInfo |
| 826 | { |
| 827 | public: |
Gian Marco Iodice | 4e28869 | 2017-06-27 11:41:59 +0100 | [diff] [blame] | 828 | /** Default constructor */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 829 | WeightsInfo() |
Gian Marco Iodice | 559d771 | 2017-08-08 08:38:09 +0100 | [diff] [blame] | 830 | : _are_reshaped(false), _kernel_width(0), _kernel_height(0), _num_kernels(0) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 831 | { |
| 832 | } |
| 833 | /** Constructor |
| 834 | * |
Gian Marco Iodice | 4e28869 | 2017-06-27 11:41:59 +0100 | [diff] [blame] | 835 | * @param[in] are_reshaped True if the weights have been reshaped |
| 836 | * @param[in] kernel_width Kernel width. |
| 837 | * @param[in] kernel_height Kernel height. |
Gian Marco Iodice | 559d771 | 2017-08-08 08:38:09 +0100 | [diff] [blame] | 838 | * @param[in] num_kernels Number of convolution kernels. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 839 | */ |
Gian Marco Iodice | 559d771 | 2017-08-08 08:38:09 +0100 | [diff] [blame] | 840 | WeightsInfo(bool are_reshaped, unsigned int kernel_width, unsigned int kernel_height, unsigned int num_kernels) |
| 841 | : _are_reshaped(are_reshaped), _kernel_width(kernel_width), _kernel_height(kernel_height), _num_kernels(num_kernels) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 842 | { |
| 843 | } |
Gian Marco Iodice | 4e28869 | 2017-06-27 11:41:59 +0100 | [diff] [blame] | 844 | /** Flag which specifies if the weights tensor has been reshaped. |
| 845 | * |
| 846 | * @return True if the weights tensors has been reshaped |
| 847 | */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 848 | bool are_reshaped() const |
| 849 | { |
| 850 | return _are_reshaped; |
| 851 | }; |
Gian Marco Iodice | 559d771 | 2017-08-08 08:38:09 +0100 | [diff] [blame] | 852 | /** Return the number of convolution kernels |
| 853 | * |
| 854 | * @return The number of convolution kernels |
| 855 | */ |
| 856 | unsigned int num_kernels() const |
| 857 | { |
| 858 | return _num_kernels; |
| 859 | }; |
Gian Marco Iodice | 4e28869 | 2017-06-27 11:41:59 +0100 | [diff] [blame] | 860 | /** Return the width and height of the kernel |
| 861 | * |
| 862 | * @return The width and height of the kernel |
| 863 | */ |
| 864 | std::pair<unsigned int, unsigned int> kernel_size() const |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 865 | { |
Gian Marco Iodice | 4e28869 | 2017-06-27 11:41:59 +0100 | [diff] [blame] | 866 | return std::make_pair(_kernel_width, _kernel_height); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | private: |
| 870 | const bool _are_reshaped; |
Gian Marco Iodice | 4e28869 | 2017-06-27 11:41:59 +0100 | [diff] [blame] | 871 | const unsigned int _kernel_width; |
| 872 | const unsigned int _kernel_height; |
Gian Marco Iodice | 559d771 | 2017-08-08 08:38:09 +0100 | [diff] [blame] | 873 | const unsigned int _num_kernels; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 874 | }; |
| 875 | |
Gian Marco | 36a0a46 | 2018-01-12 10:21:40 +0000 | [diff] [blame] | 876 | /** GEMM reshape information class. This class stores the necessary information about matrix A and matrix B reshape. |
| 877 | * |
| 878 | * The matrix A can only be reshaped through @ref CLGEMMInterleave4x4Kernel or @ref NEGEMMInterleave4x4Kernel or @ref GCGEMMInterleave4x4Kernel |
| 879 | * Note: Optionally just for @ref CLGEMMInterleave4x4Kernel is it possible to set mult_interleave4x4_height, the multiplication factor for the height of the 4x4 interleaved block |
| 880 | * |
| 881 | * The matrix B can only be reshaped through @ref CLGEMMTranspose1xWKernel or @ref NEGEMMTranspose1xWKernel or @ref GCGEMMTranspose1xWKernel |
| 882 | * Note: Optionally just for @ref CLGEMMTranspose1xWKernel is it possible to set mult_transpose1xW_width, the multiplication factor for the width of the 1xW transposed block |
| 883 | * |
| 884 | */ |
| 885 | class GEMMReshapeInfo final |
| 886 | { |
| 887 | public: |
| 888 | /** Default constructor */ |
| 889 | GEMMReshapeInfo() |
| 890 | : _m(1), _n(1), _k(1), _mult_transpose1xW_width(1), _mult_interleave4x4_height(1) |
| 891 | { |
| 892 | } |
| 893 | /** Constructor |
| 894 | * |
| 895 | * @param[in] m Number of matrix A rows |
| 896 | * @param[in] n Number of matrix B columns |
| 897 | * @param[in] k Number of matrix A columns or matrix B rows |
| 898 | * @param[in] mult_transpose1xW_width (Optional) Multiplication factor for the width of the 1xW transposed block |
| 899 | * @param[in] mult_interleave4x4_height (Optional) Multiplication factor for the height of the 4x4 interleaved block |
| 900 | */ |
| 901 | GEMMReshapeInfo(int m, int n, int k, int mult_transpose1xW_width = 1, int mult_interleave4x4_height = 1) |
| 902 | : _m(m), _n(n), _k(k), _mult_transpose1xW_width(mult_transpose1xW_width), _mult_interleave4x4_height(mult_interleave4x4_height) |
| 903 | { |
| 904 | } |
| 905 | /** Number of matrix A rows |
| 906 | * |
| 907 | * @return the number of matrix A rows |
| 908 | */ |
| 909 | int m() const |
| 910 | { |
| 911 | return _m; |
| 912 | } |
| 913 | /** Number of matrix B columns |
| 914 | * |
| 915 | * @return the number of matrix B columns |
| 916 | */ |
| 917 | int n() const |
| 918 | { |
| 919 | return _n; |
| 920 | } |
| 921 | /** Number of matrix A columns or matrix B rows |
| 922 | * |
| 923 | * @return the number of matrix A columns or matrix B rows |
| 924 | */ |
| 925 | int k() const |
| 926 | { |
| 927 | return _k; |
| 928 | } |
| 929 | /** Multiplication factor for the width of the 1xW transposed block |
| 930 | * |
| 931 | * @return the multiplication factor for the width of the 1xW transposed block |
| 932 | */ |
| 933 | int mult_transpose1xW_width() const |
| 934 | { |
| 935 | return _mult_transpose1xW_width; |
| 936 | } |
| 937 | /** Multiplication factor for the height of the 4x4 interleaved block |
| 938 | * |
| 939 | * @return the multiplication factor for the height of the 4x4 interleaved block |
| 940 | */ |
| 941 | int mult_interleave4x4_height() const |
| 942 | { |
| 943 | return _mult_interleave4x4_height; |
| 944 | } |
| 945 | |
| 946 | private: |
| 947 | const int _m; |
| 948 | const int _n; |
| 949 | const int _k; |
| 950 | const int _mult_transpose1xW_width; |
| 951 | const int _mult_interleave4x4_height; |
| 952 | }; |
| 953 | |
| 954 | /** GEMM information class. This class stores the necessary information to compute GEMM functions |
| 955 | * |
| 956 | * This object also contains the information about how matrix A and matrix B have been reshaped |
| 957 | * |
| 958 | */ |
Chunosov | 5124be5 | 2017-11-22 20:42:13 +0700 | [diff] [blame] | 959 | class GEMMInfo |
| 960 | { |
| 961 | public: |
| 962 | /** Default constructor */ |
| 963 | GEMMInfo() |
Gian Marco | 36a0a46 | 2018-01-12 10:21:40 +0000 | [diff] [blame] | 964 | : _is_a_reshaped(false), _is_b_reshaped(false), _reshape_b_only_on_first_run(false), _reshape_info() |
Chunosov | 5124be5 | 2017-11-22 20:42:13 +0700 | [diff] [blame] | 965 | { |
| 966 | } |
| 967 | /** Constructor |
| 968 | * |
| 969 | * @param[in] is_a_reshaped True if the matrix A has been reshaped |
| 970 | * @param[in] is_b_reshaped True if the matrix B has been reshaped |
| 971 | * @param[in] reshape_b_only_on_first_run Reshape matrix B only for the first run |
Gian Marco | 36a0a46 | 2018-01-12 10:21:40 +0000 | [diff] [blame] | 972 | * @param[in] reshape_info (Optional) GEMM reshape information object |
Chunosov | 5124be5 | 2017-11-22 20:42:13 +0700 | [diff] [blame] | 973 | */ |
Gian Marco | 36a0a46 | 2018-01-12 10:21:40 +0000 | [diff] [blame] | 974 | GEMMInfo(bool is_a_reshaped, bool is_b_reshaped, bool reshape_b_only_on_first_run, const GEMMReshapeInfo &reshape_info = GEMMReshapeInfo()) |
| 975 | : _is_a_reshaped(is_a_reshaped), _is_b_reshaped(is_b_reshaped), _reshape_b_only_on_first_run(reshape_b_only_on_first_run), _reshape_info(reshape_info) |
Chunosov | 5124be5 | 2017-11-22 20:42:13 +0700 | [diff] [blame] | 976 | { |
| 977 | } |
| 978 | /** Flag which specifies if the matrix A has been reshaped |
| 979 | * |
| 980 | * @return True if the matrix A has been reshaped |
| 981 | */ |
| 982 | bool is_a_reshaped() const |
| 983 | { |
| 984 | return _is_a_reshaped; |
| 985 | }; |
| 986 | /** Flag which specifies if the matrix B has been reshaped |
| 987 | * |
| 988 | * @return True if the matrix B has been reshaped |
| 989 | */ |
| 990 | bool is_b_reshaped() const |
| 991 | { |
| 992 | return _is_b_reshaped; |
| 993 | }; |
| 994 | /** Flag which specifies if the reshape of matrix B should executed only for the first |
| 995 | * |
| 996 | * @note This flag could be set to TRUE when GEMM is used to accelerate convolution layer |
| 997 | * |
| 998 | * @return True if the reshaped of matrix B happens only for the first run |
| 999 | */ |
| 1000 | bool reshape_b_only_on_first_run() const |
| 1001 | { |
| 1002 | return _reshape_b_only_on_first_run; |
| 1003 | }; |
Gian Marco | 36a0a46 | 2018-01-12 10:21:40 +0000 | [diff] [blame] | 1004 | /** GEMMReshapeInfo object which stores the necessary information to understand how the matrix A and matrix B have been reshaped |
| 1005 | * |
| 1006 | * @return the GEMMReshapeInfo object |
| 1007 | */ |
| 1008 | const GEMMReshapeInfo &reshape_info() const |
| 1009 | { |
| 1010 | return _reshape_info; |
| 1011 | } |
Chunosov | 5124be5 | 2017-11-22 20:42:13 +0700 | [diff] [blame] | 1012 | |
| 1013 | private: |
Gian Marco | 36a0a46 | 2018-01-12 10:21:40 +0000 | [diff] [blame] | 1014 | const bool _is_a_reshaped; |
| 1015 | const bool _is_b_reshaped; |
| 1016 | const bool _reshape_b_only_on_first_run; |
| 1017 | GEMMReshapeInfo _reshape_info; |
Chunosov | 5124be5 | 2017-11-22 20:42:13 +0700 | [diff] [blame] | 1018 | }; |
| 1019 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1020 | /** IO formatting information class*/ |
| 1021 | struct IOFormatInfo |
| 1022 | { |
| 1023 | /** Precision type used when printing floating point numbers */ |
| 1024 | enum class PrecisionType |
| 1025 | { |
| 1026 | Default, /**< Default precision to the one that the current stream has */ |
| 1027 | Custom, /**< Custom precision specified by the user using the precision parameter */ |
| 1028 | Full /**< The maximum precision of the floating point representation */ |
| 1029 | }; |
| 1030 | |
| 1031 | /** Specifies the area to be printed, used by Tensor objects */ |
| 1032 | enum class PrintRegion |
| 1033 | { |
| 1034 | ValidRegion, /**< Prints the valid region of the Tensor object */ |
| 1035 | NoPadding, /**< Prints the Tensor object without the padding */ |
| 1036 | Full /**< Print the tensor object including padding */ |
| 1037 | }; |
| 1038 | |
| 1039 | IOFormatInfo(PrintRegion print_region = PrintRegion::ValidRegion, |
| 1040 | PrecisionType precision_type = PrecisionType::Default, |
| 1041 | unsigned int precision = 10, |
| 1042 | bool align_columns = true, |
| 1043 | std::string element_delim = " ", |
| 1044 | std::string row_delim = "\n") |
| 1045 | : print_region(print_region), |
| 1046 | precision_type(precision_type), |
| 1047 | precision(precision), |
| 1048 | element_delim(element_delim), |
| 1049 | row_delim(row_delim), |
| 1050 | align_columns(align_columns) |
| 1051 | { |
| 1052 | } |
| 1053 | |
| 1054 | PrintRegion print_region; |
| 1055 | PrecisionType precision_type; |
| 1056 | unsigned int precision; |
| 1057 | std::string element_delim; |
| 1058 | std::string row_delim; |
| 1059 | bool align_columns; |
| 1060 | }; |
Isabella Gottardi | f07d28d | 2018-02-06 14:52:43 +0000 | [diff] [blame] | 1061 | |
| 1062 | /** Available ConvolutionMethod*/ |
| 1063 | enum class ConvolutionMethod |
| 1064 | { |
| 1065 | GEMM, /**< Convolution using GEMM */ |
| 1066 | DIRECT, /**< Direct convolution */ |
| 1067 | WINOGRAD /**< Convolution using Winograd */ |
| 1068 | }; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1069 | } |
| 1070 | #endif /* __ARM_COMPUTE_TYPES_H__ */ |