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