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