blob: 83ab2d755a1d11f21eab2a7b3a06234cf6735688 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Manuel Bottinicc5171b2019-01-09 17:04:39 +00002 * Copyright (c) 2016-2019 ARM Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01003 *
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 Iwaniec5dfeae62017-11-29 10:48:23 +000028#include "arm_compute/core/QAsymm8.h"
29#include "arm_compute/core/Rounding.h"
Isabella Gottardi6e464c32018-01-26 12:32:45 +000030#include "arm_compute/core/Size2D.h"
Georgios Pinitas8795ffb2017-12-01 16:13:40 +000031#include "arm_compute/core/Strides.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010032#include "arm_compute/core/TensorShape.h"
Georgios Pinitas583137c2017-08-31 18:12:42 +010033#include "support/Half.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010034
Michel Iwaniec5dfeae62017-11-29 10:48:23 +000035#include <cmath>
Anthony Barbier6ff3b192017-09-04 18:44:23 +010036#include <cstddef>
37#include <cstdint>
38#include <string>
39#include <utility>
40
41namespace arm_compute
42{
Georgios Pinitas583137c2017-08-31 18:12:42 +010043/** 16-bit floating point type */
44using half = half_float::half;
45
Georgios Pinitas8795ffb2017-12-01 16:13:40 +000046/** Permutation vector */
47using PermutationVector = Strides;
Georgios Pinitas77589b52018-08-21 14:41:35 +010048/** Bidirectional strides */
49using BiStrides = Coordinates;
Georgios Pinitas8795ffb2017-12-01 16:13:40 +000050
Anthony Barbier6ff3b192017-09-04 18:44:23 +010051/** Image colour formats */
52enum class Format
53{
Daniil Efremov02bf80d2017-11-22 00:26:51 +070054 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 Barbier6ff3b192017-09-04 18:44:23 +010071};
72
73/** Available data types */
74enum class DataType
75{
Alex Gildayc357c472018-03-21 13:54:09 +000076 UNKNOWN, /**< Unknown data type */
77 U8, /**< unsigned 8-bit number */
78 S8, /**< signed 8-bit number */
Alex Gildayc357c472018-03-21 13:54:09 +000079 QASYMM8, /**< quantized, asymmetric fixed-point 8-bit number */
80 U16, /**< unsigned 16-bit number */
81 S16, /**< signed 16-bit number */
Alex Gildayc357c472018-03-21 13:54:09 +000082 U32, /**< unsigned 32-bit number */
83 S32, /**< signed 32-bit number */
Alex Gildayc357c472018-03-21 13:54:09 +000084 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 Barbier6ff3b192017-09-04 18:44:23 +010090};
91
Daniil Efremov02bf80d2017-11-22 00:26:51 +070092/** Available Sampling Policies */
93enum 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 Barbier6ff3b192017-09-04 18:44:23 +010099/** Constant value of the border pixels when using BorderMode::CONSTANT */
100constexpr uint8_t CONSTANT_BORDER_VALUE = 199;
101
Alex Gildayc357c472018-03-21 13:54:09 +0000102/** Constant value used to indicate a half-scale pyramid */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100103constexpr float SCALE_PYRAMID_HALF = 0.5f;
104
Alex Gildayc357c472018-03-21 13:54:09 +0000105/** Constant value used to indicate a ORB scaled pyramid */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100106constexpr float SCALE_PYRAMID_ORB = 8.408964152537146130583778358414e-01;
107
Vidhya Sudhan Loganathand646ae12018-11-19 15:18:20 +0000108/** [DataLayout enum definition] **/
109
Georgios Pinitas4074c992018-01-30 18:13:46 +0000110/** Supported tensor data layouts */
111enum class DataLayout
112{
Alex Gildayc357c472018-03-21 13:54:09 +0000113 UNKNOWN, /**< Unknown data layout */
114 NCHW, /**< Num samples, channels, height, width */
115 NHWC /**< Num samples, height, width, channels */
Georgios Pinitas4074c992018-01-30 18:13:46 +0000116};
Vidhya Sudhan Loganathand646ae12018-11-19 15:18:20 +0000117/** [DataLayout enum definition] **/
Georgios Pinitas4074c992018-01-30 18:13:46 +0000118
Isabella Gottardid17a6772018-02-27 17:41:55 +0000119/** Supported tensor data layout dimensions */
120enum class DataLayoutDimension
121{
Alex Gildayc357c472018-03-21 13:54:09 +0000122 CHANNEL, /**< channel */
123 HEIGHT, /**< height */
124 WIDTH, /**< width */
125 BATCHES /**< batches */
Isabella Gottardid17a6772018-02-27 17:41:55 +0000126};
127
Georgios Pinitas7900a9e2018-11-23 11:44:58 +0000128/** Available ConvolutionMethod*/
129enum class ConvolutionMethod
130{
Vidhya Sudhan Loganathan8ec0bb62019-04-23 10:40:44 +0100131 GEMM, /**< Convolution using GEMM */
132 DIRECT, /**< Direct convolution */
133 WINOGRAD, /**< Convolution using Winograd */
134 FFT /**< Convolution using FFT */
Georgios Pinitas7900a9e2018-11-23 11:44:58 +0000135};
136
giuros0146a49a02019-04-01 13:50:22 +0100137/** Available DeconvolutionMethod*/
138enum class DeconvolutionMethod
139{
140 GEMM, /**< Deconvolution using GEMM */
141 DIRECT, /**< Direct deconvolution */
142};
143
Usama Arif89890c62019-03-19 10:57:05 +0000144/** Padding mode to use for PadLayer */
145enum class PaddingMode
146{
147 CONSTANT,
148 REFLECT,
149 SYMMETRIC
150};
151
Georgios Pinitas7900a9e2018-11-23 11:44:58 +0000152/** Supported comparison operations */
153enum class ComparisonOperation
154{
155 Equal, /**< Equal comparison ( \f$ x == y \f$ ) */
156 NotEqual, /**< NotEqual comparison ( \f$ x != y \f$ ) */
157 Greater, /**< Greater comparison ( \f$ x > y \f$ ) */
158 GreaterEqual, /**< Greater equal comparison ( \f$ x >= y \f$ ) */
159 Less, /**< Less comparison ( \f$ x < y \f$ ) */
160 LessEqual /**< Less equal comparison ( \f$ x <= y \f$ ) */
161};
162
Michel Iwaniec00633802017-10-12 14:14:15 +0100163/** Quantization settings (used for QASYMM8 data type) */
164struct QuantizationInfo
165{
Alex Gildayc357c472018-03-21 13:54:09 +0000166 /** Default constructor */
Georgios Pinitasf8d8f3a2018-06-06 17:57:04 +0100167 QuantizationInfo() noexcept
168 : scale(0.0f),
169 offset(0)
Michel Iwaniec00633802017-10-12 14:14:15 +0100170 {
171 }
172
Alex Gildayc357c472018-03-21 13:54:09 +0000173 /** Construct quantization info.
174 *
175 * @param[in] scale Scale.
176 * @param[in] offset Offset.
177 */
Michel Iwaniec00633802017-10-12 14:14:15 +0100178 QuantizationInfo(float scale, int offset)
179 : scale(scale), offset(offset)
180 {
181 }
182
Alex Gildayc357c472018-03-21 13:54:09 +0000183 /** Check whether equal to a given quantization info.
184 *
185 * @param[in] other Other quantization info.
186 *
187 * @return True if the given quantization info is the same.
188 */
Georgios Pinitas08346e92018-10-16 19:10:46 +0100189 bool operator==(const QuantizationInfo &other) const
Daniil Efremoveed841c2017-11-09 19:05:25 +0700190 {
191 return scale == other.scale && offset == other.offset;
192 }
193
Alex Gildayc357c472018-03-21 13:54:09 +0000194 /** Check whether not equal to a given quantization info.
195 *
196 * @param[in] other Other quantization info.
197 *
198 * @return True if the given quantization info is not the same.
199 */
Georgios Pinitas08346e92018-10-16 19:10:46 +0100200 bool operator!=(const QuantizationInfo &other) const
Daniil Efremoveed841c2017-11-09 19:05:25 +0700201 {
202 return !(*this == other);
203 }
204
Michel Iwaniec00633802017-10-12 14:14:15 +0100205 float scale; /**< scale */
206 int offset; /**< offset */
207
Alex Gildayc357c472018-03-21 13:54:09 +0000208 /** Quantizes a value using the scale/offset in this QuantizationInfo
209 *
210 * @param[in] value Value to quantize.
211 * @param[in] rounding_policy Policy to use when rounding.
212 *
213 * @return the quantized value.
214 */
Michel Iwaniec5dfeae62017-11-29 10:48:23 +0000215 qasymm8_t quantize(float value, RoundingPolicy rounding_policy) const
Michel Iwaniec00633802017-10-12 14:14:15 +0100216 {
217 ARM_COMPUTE_ERROR_ON_MSG(scale == 0, "QuantizationInfo::quantize: scale == 0");
Michel Iwaniec5dfeae62017-11-29 10:48:23 +0000218 return sqcvt_qasymm8_f32(value, scale, offset, rounding_policy);
Michel Iwaniec00633802017-10-12 14:14:15 +0100219 }
220
Alex Gildayc357c472018-03-21 13:54:09 +0000221 /** Dequantizes a value using the scale/offset in this QuantizationInfo
222 *
223 * @param[in] value Value to dequantize.
224 *
225 * @return the original value before quantization.
226 */
Michel Iwaniec5dfeae62017-11-29 10:48:23 +0000227 float dequantize(qasymm8_t value) const
Michel Iwaniec00633802017-10-12 14:14:15 +0100228 {
229 ARM_COMPUTE_ERROR_ON_MSG(scale == 0, "QuantizationInfo::dequantize: scale == 0");
Michel Iwaniec5dfeae62017-11-29 10:48:23 +0000230 return scvt_f32_qasymm8(value, scale, offset);
Michel Iwaniec00633802017-10-12 14:14:15 +0100231 }
232
Alex Gildayc357c472018-03-21 13:54:09 +0000233 /** Indicates whether this QuantizationInfo has valid settings or not
234 *
235 * @return True if the this has invalid settings.
236 */
Michel Iwaniec00633802017-10-12 14:14:15 +0100237 bool empty() const
238 {
239 return scale == 0;
240 }
241};
242
Alex Gildayc357c472018-03-21 13:54:09 +0000243/** Container for valid region of a window */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100244struct ValidRegion
245{
Alex Gildayc357c472018-03-21 13:54:09 +0000246 /** Default constructor */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100247 ValidRegion()
248 : anchor{}, shape{}
249 {
250 }
251
Alex Gildayc357c472018-03-21 13:54:09 +0000252 /** Allow instances of this class to be copy constructed */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100253 ValidRegion(const ValidRegion &) = default;
Alex Gildayc357c472018-03-21 13:54:09 +0000254 /** Allow instances of this class to be move constructed */
255 ValidRegion(ValidRegion &&) = default;
256 /** Allow instances of this class to be copied */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100257 ValidRegion &operator=(const ValidRegion &) = default;
Alex Gildayc357c472018-03-21 13:54:09 +0000258 /** Allow instances of this class to be moved */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100259 ValidRegion &operator=(ValidRegion &&) = default;
Alex Gildayc357c472018-03-21 13:54:09 +0000260 /** Default destructor */
261 ~ValidRegion() = default;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100262
Alex Gildayc357c472018-03-21 13:54:09 +0000263 /** Constructor for a valid region with default number of dimensions
264 *
265 * @param[in] an_anchor Anchor for the start of the valid region.
266 * @param[in] a_shape Shape of the valid region.
267 *
268 */
Diego Lopez Recasbcbc9702017-12-18 11:28:27 +0000269 ValidRegion(const Coordinates &an_anchor, const TensorShape &a_shape)
270 : anchor{ an_anchor }, shape{ a_shape }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100271 {
Diego Lopez Recasbcbc9702017-12-18 11:28:27 +0000272 anchor.set_num_dimensions(std::max(anchor.num_dimensions(), shape.num_dimensions()));
273 }
274
Alex Gildayc357c472018-03-21 13:54:09 +0000275 /** Constructor for a valid region with specified number of dimensions
276 *
277 * @param[in] an_anchor Anchor for the start of the valid region.
278 * @param[in] a_shape Shape of the valid region.
279 * @param[in] num_dimensions Number of dimensions (must be >= number of dimensions of anchor and shape).
280 *
281 */
Diego Lopez Recasbcbc9702017-12-18 11:28:27 +0000282 ValidRegion(const Coordinates &an_anchor, const TensorShape &a_shape, size_t num_dimensions)
283 : anchor{ an_anchor }, shape{ a_shape }
284 {
285 ARM_COMPUTE_ERROR_ON(num_dimensions < std::max(anchor.num_dimensions(), shape.num_dimensions()));
286 anchor.set_num_dimensions(num_dimensions);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100287 }
288
289 /** Return the start of the valid region for the given dimension @p d */
290 int start(unsigned int d) const
291 {
292 return anchor[d];
293 }
294
295 /** Return the end of the valid region for the given dimension @p d */
296 int end(unsigned int d) const
297 {
298 return anchor[d] + shape[d];
299 }
300
Diego Lopez Recas35ceeb22017-12-04 18:56:10 +0000301 /** Accessor to set the value of anchor and shape for one of the dimensions.
302 *
303 * @param[in] dimension Dimension for which the value is set.
304 * @param[in] start Value to be set in anchor for the dimension.
305 * @param[in] size Value to be set in shape for the dimension.
306 *
307 * @return *this.
308 */
309 ValidRegion &set(size_t dimension, int start, size_t size)
310 {
311 anchor.set(dimension, start);
312 shape.set(dimension, size);
313 return *this;
314 }
315
Alex Gildayc357c472018-03-21 13:54:09 +0000316 Coordinates anchor; /**< Anchor for the start of the valid region. */
317 TensorShape shape; /**< Shape of the valid region. */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100318};
319
320/** Methods available to handle borders */
321enum class BorderMode
322{
323 UNDEFINED, /**< Borders are left undefined */
324 CONSTANT, /**< Pixels outside the image are assumed to have a constant value */
325 REPLICATE /**< Pixels outside the image are assumed to have the same value as the closest image pixel */
326};
327
328/** Container for 2D border size */
329struct BorderSize
330{
331 /** Empty border, i.e. no border */
332 constexpr BorderSize()
333 : top{ 0 }, right{ 0 }, bottom{ 0 }, left{ 0 }
334 {
335 }
336
337 /** Border with equal size around the 2D plane */
Moritz Pflanzer7655a672017-09-23 11:57:33 +0100338 explicit constexpr BorderSize(unsigned int size)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100339 : top{ size }, right{ size }, bottom{ size }, left{ size }
340 {
341 }
342
343 /** Border with same size for top/bottom and left/right */
344 constexpr BorderSize(unsigned int top_bottom, unsigned int left_right)
345 : top{ top_bottom }, right{ left_right }, bottom{ top_bottom }, left{ left_right }
346 {
347 }
348
349 /** Border with different sizes */
350 constexpr BorderSize(unsigned int top, unsigned int right, unsigned int bottom, unsigned int left)
351 : top{ top }, right{ right }, bottom{ bottom }, left{ left }
352 {
353 }
354
355 /** Check if the entire border is zero */
356 constexpr bool empty() const
357 {
358 return top == 0 && right == 0 && bottom == 0 && left == 0;
359 }
360
361 /** Check if the border is the same size on all sides */
362 constexpr bool uniform() const
363 {
364 return top == right && top == bottom && top == left;
365 }
366
Alex Gildayc357c472018-03-21 13:54:09 +0000367 /** Scale this border size.
368 *
369 * @param[in] scale Scale to multiply border size by.
370 *
371 * @return *this.
372 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100373 BorderSize &operator*=(float scale)
374 {
375 top *= scale;
376 right *= scale;
377 bottom *= scale;
378 left *= scale;
379
380 return *this;
381 }
382
Alex Gildayc357c472018-03-21 13:54:09 +0000383 /** Scale a copy of this border size.
384 *
385 * @param[in] scale Scale to multiply border size by.
386 *
387 * @return a scaled copy of this.
388 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100389 BorderSize operator*(float scale)
390 {
391 BorderSize size = *this;
392 size *= scale;
393
394 return size;
395 }
396
Alex Gildayc357c472018-03-21 13:54:09 +0000397 /** Limit this border size.
398 *
399 * @param[in] limit Border size to limit this border size to.
400 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100401 void limit(const BorderSize &limit)
402 {
403 top = std::min(top, limit.top);
404 right = std::min(right, limit.right);
405 bottom = std::min(bottom, limit.bottom);
406 left = std::min(left, limit.left);
407 }
408
Alex Gildayc357c472018-03-21 13:54:09 +0000409 unsigned int top; /**< top of the border */
410 unsigned int right; /**< right of the border */
411 unsigned int bottom; /**< bottom of the border */
412 unsigned int left; /**< left of the border */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100413};
414
Alex Gildayc357c472018-03-21 13:54:09 +0000415/** Container for 2D padding size */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100416using PaddingSize = BorderSize;
417
418/** Policy to handle overflow */
419enum class ConvertPolicy
420{
421 WRAP, /**< Wrap around */
422 SATURATE /**< Saturate */
423};
424
425/** Interpolation method */
426enum class InterpolationPolicy
427{
428 NEAREST_NEIGHBOR, /**< Output values are defined to match the source pixel whose center is nearest to the sample position */
429 BILINEAR, /**< Output values are defined by bilinear interpolation between the pixels */
430 AREA, /**< Output values are determined by averaging the source pixels whose areas fall under the area of the destination pixel, projected onto the source image */
431};
432
433/** Bilinear Interpolation method used by LKTracker */
434enum class BilinearInterpolation
435{
Alex Gildayc357c472018-03-21 13:54:09 +0000436 BILINEAR_OLD_NEW, /**< Old-new method */
437 BILINEAR_SCHARR /**< Scharr method */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100438};
439
440/** Threshold mode */
441enum class ThresholdType
442{
443 BINARY, /**< Threshold with one value */
444 RANGE /**< Threshold with two values*/
445};
446
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100447/** Termination criteria */
448enum class Termination
449{
Alex Gildayc357c472018-03-21 13:54:09 +0000450 TERM_CRITERIA_EPSILON, /**< Terminate when within epsilon of a threshold */
451 TERM_CRITERIA_ITERATIONS, /**< Terminate after a maximum number of iterations */
452 TERM_CRITERIA_BOTH /**< Terminate on whichever of the other conditions occurs first */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100453};
454
455/** Magnitude calculation type. */
456enum class MagnitudeType
457{
458 L1NORM, /**< L1 normalization type */
459 L2NORM /**< L2 normalization type */
460};
461
462/** Phase calculation type.
463 *
464 * @note When PhaseType == SIGNED, each angle is mapped to the range 0 to 255 inclusive otherwise angles between 0 and 180
465 */
466enum class PhaseType
467{
468 SIGNED, /**< Angle range: [0, 360] */
469 UNSIGNED /**< Angle range: [0, 180] */
470};
471
472/** Keypoint type */
473struct KeyPoint
474{
475 int32_t x{ 0 }; /**< X coordinates */
476 int32_t y{ 0 }; /**< Y coordinates */
477 float strength{ 0.f }; /**< Strength of the point */
478 float scale{ 0.f }; /**< Scale initialized to 0 by the corner detector */
479 float orientation{ 0.f }; /**< Orientation initialized to 0 by the corner detector */
480 int32_t tracking_status{ 0 }; /**< Status initialized to 1 by the corner detector, set to 0 when the point is lost */
481 float error{ 0.f }; /**< Tracking error initialized to 0 by the corner detector */
482};
483
Alex Gildayc357c472018-03-21 13:54:09 +0000484/** Internal key point */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100485using InternalKeypoint = std::tuple<float, float, float>; /* x,y,strength */
486
487/** Rectangle type */
488struct Rectangle
489{
490 uint16_t x; /**< Top-left x coordinate */
491 uint16_t y; /**< Top-left y coordinate */
492 uint16_t width; /**< Width of the rectangle */
493 uint16_t height; /**< Height of the rectangle */
494};
495
496/** Coordinate type */
497struct Coordinates2D
498{
499 int32_t x; /**< X coordinates */
500 int32_t y; /**< Y coordinates */
501};
502
503/** Coordinate type */
504struct Coordinates3D
505{
506 uint32_t x; /**< X coordinates */
507 uint32_t y; /**< Y coordinates */
508 uint32_t z; /**< Z coordinates */
509};
510
Giuseppe Rossinid7647d42018-07-17 18:13:13 +0100511/** Padding information as a pair of unsigned int start/end */
512using PaddingInfo = std::pair<uint32_t, uint32_t>;
513
514/** List of padding information */
515using PaddingList = std::vector<PaddingInfo>;
516
giuros013175fcf2018-11-21 09:59:17 +0000517/** Information to produce a tiled version of a Tensor */
518using Multiples = std::vector<uint32_t>;
519
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100520/** Available channels */
521enum class Channel
522{
523 UNKNOWN, /** Unknown channel format */
524 C0, /**< First channel (used by formats with unknown channel types). */
525 C1, /**< Second channel (used by formats with unknown channel types). */
526 C2, /**< Third channel (used by formats with unknown channel types). */
527 C3, /**< Fourth channel (used by formats with unknown channel types). */
528 R, /**< Red channel. */
529 G, /**< Green channel. */
530 B, /**< Blue channel. */
531 A, /**< Alpha channel. */
532 Y, /**< Luma channel. */
533 U, /**< Cb/U channel. */
534 V /**< Cr/V/Value channel. */
535};
536
537/** Available matrix patterns */
538enum class MatrixPattern
539{
540 BOX, /**< Box pattern matrix. */
541 CROSS, /**< Cross pattern matrix. */
542 DISK, /**< Disk pattern matrix. */
543 OTHER /**< Any other matrix pattern. */
544};
545
546/** Available non linear functions. */
547enum class NonLinearFilterFunction : unsigned
548{
549 MEDIAN = 0, /**< Non linear median filter. */
550 MIN = 1, /**< Non linear erode. */
551 MAX = 2, /**< Non linear dilate. */
552};
553
Georgios Pinitasd9769582017-08-03 10:19:40 +0100554/** Available reduction operations */
555enum class ReductionOperation
556{
Michalis Spyrou7930db42018-11-22 17:36:28 +0000557 ARG_IDX_MAX, /**< Index of the max value */
Manuel Bottinib412fab2018-12-10 17:40:23 +0000558 ARG_IDX_MIN, /**< Index of the min value */
559 MEAN_SUM, /**< Mean of sum */
560 PROD, /**< Product */
561 SUM_SQUARE, /**< Sum of squares */
562 SUM /**< Sum */
Georgios Pinitasd9769582017-08-03 10:19:40 +0100563};
564
giuros01164a2722018-11-20 18:34:46 +0000565/** Available element-wise operations */
566enum class ArithmeticOperation
567{
568 ADD, /**< (x + y) */
569 SUB, /**< (x - y) */
570 DIV, /**< (x / y) */
571 MIN, /**< Min(x, y) */
572 MAX, /**< Max(x, y) */
573 SQUARED_DIFF, /**< (x - y)^2 */
Usama Arif81e671e2019-05-13 13:33:14 +0100574 POWER, /**< x ^ y */
giuros01164a2722018-11-20 18:34:46 +0000575};
576
Michalis Spyroue9362622018-11-23 17:41:37 +0000577/** Available element wise unary operations */
578enum class ElementWiseUnary
579{
580 RSQRT, /**< Reverse square root */
581 EXP, /**< Exponential */
Usama Ariff6e475c2019-05-10 12:06:28 +0100582 NEG, /**< Negate */
Usama Arifc255aa72019-05-13 16:26:29 +0100583 LOG, /**< Natural Logarithm */
Manuel Bottini6ac59922019-05-15 14:06:02 +0100584 ABS, /**< Absolute value */
Michalis Spyrou0af44182019-05-17 14:04:47 +0100585 SIN, /**< Sine */
Michalis Spyroue9362622018-11-23 17:41:37 +0000586};
587
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100588/** The normalization type used for the normalization layer */
589enum class NormType
590{
591 IN_MAP_1D, /**< Normalization applied within the same map in 1D region */
592 IN_MAP_2D, /**< Normalization applied within the same map in 2D region */
593 CROSS_MAP /**< Normalization applied cross maps */
594};
595
596/** Normalization type for Histogram of Oriented Gradients (HOG) */
597enum class HOGNormType
598{
599 L2_NORM = 1, /**< L2-norm */
600 L2HYS_NORM = 2, /**< L2-norm followed by clipping */
601 L1_NORM = 3 /**< L1 norm */
602};
603
604/** Detection window used for the object detection. The detection window keeps the following information:
605 *
606 * -# Geometry of the rectangular window (x/y of top-left corner and width/height)
607 * -# Index of the class used for evaluating which class the detection window belongs to
608 * -# Confidence value (score) obtained with the classifier
609 */
610struct DetectionWindow
611{
612 uint16_t x{ 0 }; /**< Top-left x coordinate */
613 uint16_t y{ 0 }; /**< Top-left y coordinate */
614 uint16_t width{ 0 }; /**< Width of the detection window */
615 uint16_t height{ 0 }; /**< Height of the detection window */
616 uint16_t idx_class{ 0 }; /**< Index of the class */
617 float score{ 0.f }; /**< Confidence value for the detection window */
618};
619
620/** Dimension rounding type when down-scaling on CNNs
621 * @note Used in pooling and convolution layer
622 */
623enum class DimensionRoundingType
624{
625 FLOOR, /**< Floor rounding */
626 CEIL /**< Ceil rounding */
627};
628
629/** Available pooling types */
630enum class PoolingType
631{
632 MAX, /**< Max Pooling */
Georgios Pinitascdf51452017-08-31 14:21:36 +0100633 AVG, /**< Average Pooling */
634 L2 /**< L2 Pooling */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100635};
636
Michalis Spyrou2709d612018-09-19 09:46:47 +0100637/** Available non maxima suppression types */
638enum class NMSType
639{
640 LINEAR, /**< Linear NMS */
641 GAUSSIAN, /**< Gaussian NMS */
642 ORIGINAL /**< Original NMS */
643};
644
645/** BoxWithNonMaximaSuppressionLimit Information class */
646class BoxNMSLimitInfo final
647{
648public:
649 /** Constructor
650 *
651 * @param[in] score_thresh (Optional) Score threshold.
652 * @param[in] nms (Optional) NMS value
653 * @param[in] detections (Optional) Number of detections
654 * @param[in] soft_nms_enabled (Optional) Enable SoftNMS
655 * @param[in] soft_nms_method (Optional) Soft NMS method
656 * @param[in] soft_nms_sigma (Optional) Soft NMS sigma value
657 * @param[in] soft_nms_min_score_thres (Optional) Soft NMS minimum score threshold
Manuel Bottini5209be52019-02-13 16:34:56 +0000658 * @param[in] suppress_size (Optional) Filter out boxes based on their size. Defaults to false
659 * @param[in] min_size (Optional) Smaller boxes than min_size will be filtered out. Defaults to 1
660 * @param[in] im_width (Optional) Boxes whose centers (on the x axis) is beyond im_width will be filtered. Defaults to 1
661 * @param[in] im_height (Optional) Boxes whose centers (on the y axis) is beyond im_height will be filtered. Defaults to 1
Michalis Spyrou2709d612018-09-19 09:46:47 +0100662 */
663 BoxNMSLimitInfo(float score_thresh = 0.05f, float nms = 0.3f,
664 int detections = 100, bool soft_nms_enabled = false,
665 NMSType soft_nms_method = NMSType::LINEAR,
Manuel Bottini5209be52019-02-13 16:34:56 +0000666 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 Spyrou2709d612018-09-19 09:46:47 +0100667 : _score_thresh(score_thresh), _nms(nms), _detections_per_im(detections), _soft_nms_enabled(soft_nms_enabled), _soft_nms_method(soft_nms_method), _soft_nms_sigma(soft_nms_sigma),
Manuel Bottini5209be52019-02-13 16:34:56 +0000668 _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 Spyrou2709d612018-09-19 09:46:47 +0100669 {
670 }
671 /** Get the score threshold */
672 float score_thresh() const
673 {
674 return _score_thresh;
675 }
676 /** Get the NMS */
677 float nms() const
678 {
679 return _nms;
680 }
681 /** Get the number of detections */
682 int detections_per_im() const
683 {
684 return _detections_per_im;
685 }
686 /** Check if soft NMS is enabled */
687 bool soft_nms_enabled() const
688 {
689 return _soft_nms_enabled;
690 }
691 /** Get soft NMS method */
692 NMSType soft_nms_method() const
693 {
694 return _soft_nms_method;
695 }
696 /** Get soft NMS sigma */
697 float soft_nms_sigma() const
698 {
699 return _soft_nms_sigma;
700 }
701 /** Get soft nms min score threshold */
702 float soft_nms_min_score_thres() const
703 {
704 return _soft_nms_min_score_thres;
705 }
Manuel Bottini5209be52019-02-13 16:34:56 +0000706 /** Get if NMS will suppress boxes based on their size/position */
707 bool suppress_size() const
708 {
709 return _suppress_size;
710 }
711 /** Get size suppression threshold */
712 float min_size() const
713 {
714 return _min_size;
715 }
716 /** Get image width (NMS may suppress boxes whose center sits beyond the image width) */
717 float im_width() const
718 {
719 return _im_width;
720 }
721 /** Get image height (NMS may suppress boxes whose center sits beyond the image height) */
722 float im_height() const
723 {
724 return _im_height;
725 }
Michalis Spyrou2709d612018-09-19 09:46:47 +0100726
727private:
728 float _score_thresh;
729 float _nms;
730 int _detections_per_im;
731 bool _soft_nms_enabled;
732 NMSType _soft_nms_method;
733 float _soft_nms_sigma;
734 float _soft_nms_min_score_thres;
Manuel Bottini5209be52019-02-13 16:34:56 +0000735 bool _suppress_size;
736 float _min_size;
737 float _im_width;
738 float _im_height;
Michalis Spyrou2709d612018-09-19 09:46:47 +0100739};
740
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100741/** Padding and stride information class */
742class PadStrideInfo
743{
744public:
745 /** Constructor
746 *
747 * @param[in] stride_x (Optional) Stride, in elements, across x. Defaults to 1.
748 * @param[in] stride_y (Optional) Stride, in elements, across y. Defaults to 1.
749 * @param[in] pad_x (Optional) Padding, in elements, across x. Defaults to 0.
750 * @param[in] pad_y (Optional) Padding, in elements, across y. Defaults to 0.
751 * @param[in] round (Optional) Dimensions rounding. Defaults to @ref FLOOR.
752 */
753 PadStrideInfo(unsigned int stride_x = 1, unsigned int stride_y = 1,
754 unsigned int pad_x = 0, unsigned int pad_y = 0,
755 DimensionRoundingType round = DimensionRoundingType::FLOOR)
756 : _stride(std::make_pair(stride_x, stride_y)),
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100757 _pad_left(pad_x),
758 _pad_top(pad_y),
759 _pad_right(pad_x),
760 _pad_bottom(pad_y),
761 _round_type(round)
762 {
763 }
764 /** Constructor
765 *
766 * @param[in] stride_x Stride, in elements, across x.
767 * @param[in] stride_y Stride, in elements, across y.
768 * @param[in] pad_left Padding across x on the left, in elements.
769 * @param[in] pad_top Padding across y on the top, in elements.
770 * @param[in] pad_right Padding across x on the right, in elements.
771 * @param[in] pad_bottom Padding across y on the bottom, in elements.
772 * @param[in] round Dimensions rounding.
773 */
774 PadStrideInfo(unsigned int stride_x, unsigned int stride_y,
775 unsigned int pad_left, unsigned int pad_right,
776 unsigned int pad_top, unsigned int pad_bottom,
777 DimensionRoundingType round)
778 : _stride(std::make_pair(stride_x, stride_y)),
779 _pad_left(pad_left),
780 _pad_top(pad_top),
781 _pad_right(pad_right),
782 _pad_bottom(pad_bottom),
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100783 _round_type(round)
784 {
785 }
Alex Gildayc357c472018-03-21 13:54:09 +0000786 /** Get the stride.
787 *
788 * @return a pair: stride x, stride y.
789 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100790 std::pair<unsigned int, unsigned int> stride() const
791 {
792 return _stride;
793 }
Alex Gildayc357c472018-03-21 13:54:09 +0000794 /** Check whether the padding is symmetric.
795 *
796 * @return True if the padding is symmetric.
797 */
Anthony Barbier21f67d62018-02-16 15:17:48 +0000798 bool padding_is_symmetric() const
799 {
800 return (_pad_left == _pad_right) && (_pad_top == _pad_bottom);
801 }
Alex Gildayc357c472018-03-21 13:54:09 +0000802 /** Get the padding.
803 *
804 * @note This should only be used when the padding is symmetric.
805 *
806 * @return a pair: padding left/right, padding top/bottom
807 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100808 std::pair<unsigned int, unsigned int> pad() const
809 {
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100810 //this accessor should be used only when padding is symmetric
Anthony Barbier21f67d62018-02-16 15:17:48 +0000811 ARM_COMPUTE_ERROR_ON(!padding_is_symmetric());
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100812 return std::make_pair(_pad_left, _pad_top);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100813 }
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100814
Alex Gildayc357c472018-03-21 13:54:09 +0000815 /** Get the left padding */
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100816 unsigned int pad_left() const
817 {
818 return _pad_left;
819 }
Alex Gildayc357c472018-03-21 13:54:09 +0000820 /** Get the right padding */
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100821 unsigned int pad_right() const
822 {
823 return _pad_right;
824 }
Alex Gildayc357c472018-03-21 13:54:09 +0000825 /** Get the top padding */
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100826 unsigned int pad_top() const
827 {
828 return _pad_top;
829 }
Alex Gildayc357c472018-03-21 13:54:09 +0000830 /** Get the bottom padding */
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100831 unsigned int pad_bottom() const
832 {
833 return _pad_bottom;
834 }
835
Alex Gildayc357c472018-03-21 13:54:09 +0000836 /** Get the rounding type */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100837 DimensionRoundingType round() const
838 {
839 return _round_type;
840 }
841
Alex Gildayc357c472018-03-21 13:54:09 +0000842 /** Check whether this has any padding */
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100843 bool has_padding() const
844 {
845 return (_pad_left != 0 || _pad_top != 0 || _pad_right != 0 || _pad_bottom != 0);
846 }
847
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100848private:
849 std::pair<unsigned int, unsigned int> _stride;
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100850 unsigned int _pad_left;
851 unsigned int _pad_top;
852 unsigned int _pad_right;
853 unsigned int _pad_bottom;
854
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100855 DimensionRoundingType _round_type;
856};
857
Georgios Pinitas7d66a8e2018-07-17 12:28:42 +0100858/** Fully connected layer info */
859struct FullyConnectedLayerInfo
860{
861 DataLayout weights_trained_layout{ DataLayout::NCHW }; /**< Layout that the weights have been trained with. */
862 bool transpose_weights{ true }; /**< Transpose weights if true. */
863 bool are_weights_reshaped{ false }; /**< Reshape the weights tensor if false. */
864 bool retain_internal_weights{ false }; /**< Retain internal reshaped weights. */
Georgios Pinitasc55cef12018-08-01 15:24:18 +0100865
866 /** Sets the weights trained data layout
867 *
868 * @param[in] layout Data layout that the weights were trained with
869 *
870 * @return Updated object
871 */
872 FullyConnectedLayerInfo &set_weights_trained_layout(DataLayout layout)
873 {
874 weights_trained_layout = layout;
875 return *this;
876 }
Georgios Pinitas195b0ba2018-08-02 17:18:51 +0100877 /** Sets the transpose weights flag
878 *
879 * @param[in] should_transpose_weights Boolean flag indicating if weights should be transposed
880 *
881 * @return Updated object
882 */
883 FullyConnectedLayerInfo &set_transpose_weights(bool should_transpose_weights)
884 {
885 transpose_weights = should_transpose_weights;
886 return *this;
887 }
Georgios Pinitas7d66a8e2018-07-17 12:28:42 +0100888};
889
Michalis Spyrou6c7c38e2018-08-29 16:28:11 +0100890/** PriorBox layer info */
891class PriorBoxLayerInfo final
892{
893public:
894 /** Default Constructor */
895 PriorBoxLayerInfo()
896 : _min_sizes(),
897 _variances(),
898 _offset(),
899 _flip(true),
900 _clip(false),
901 _max_sizes(),
902 _aspect_ratios(),
903 _img_size(),
904 _steps()
905 {
906 }
907 /** Constructor
908 *
909 * @param[in] min_sizes Min sizes vector.
Michalis Spyrou721c4cb2018-09-04 15:27:25 +0100910 * @param[in] variances Variances vector.
Michalis Spyrou6c7c38e2018-08-29 16:28:11 +0100911 * @param[in] offset Offset value.
912 * @param[in] flip (Optional) Flip the aspect ratios.
913 * @param[in] clip (Optional) Clip coordinates so that they're within [0,1].
914 * @param[in] max_sizes (Optional) Max sizes vector.
915 * @param[in] aspect_ratios (Optional) Aspect ratios of the boxes.
916 * @param[in] img_size (Optional) Image size.
917 * @param[in] steps (Optional) Step values.
918 */
919 PriorBoxLayerInfo(const std::vector<float> &min_sizes, const std::vector<float> &variances, float offset, bool flip = true, bool clip = false,
Pablo Tello32521432018-11-15 14:43:10 +0000920 const std::vector<float> &max_sizes = {}, const std::vector<float> &aspect_ratios = {},
921 const Coordinates2D &img_size = Coordinates2D{ 0, 0 }, const std::array<float, 2> &steps = { { 0.f, 0.f } })
Michalis Spyrou6c7c38e2018-08-29 16:28:11 +0100922 : _min_sizes(min_sizes),
923 _variances(variances),
924 _offset(offset),
925 _flip(flip),
926 _clip(clip),
927 _max_sizes(max_sizes),
Michalis Spyrou721c4cb2018-09-04 15:27:25 +0100928 _aspect_ratios(),
Michalis Spyrou6c7c38e2018-08-29 16:28:11 +0100929 _img_size(img_size),
930 _steps(steps)
931 {
932 _aspect_ratios.push_back(1.);
933 for(unsigned int i = 0; i < aspect_ratios.size(); ++i)
934 {
935 float ar = aspect_ratios[i];
936 bool already_exist = false;
937 for(auto ar_new : _aspect_ratios)
938 {
939 if(fabs(ar - ar_new) < 1e-6)
940 {
941 already_exist = true;
942 break;
943 }
944 }
945 if(!already_exist)
946 {
947 _aspect_ratios.push_back(ar);
948 if(flip)
949 {
950 _aspect_ratios.push_back(1.f / ar);
951 }
952 }
953 }
954 }
955 /** Get min sizes. */
956 std::vector<float> min_sizes() const
957 {
958 return _min_sizes;
959 }
960 /** Get min variances. */
961 std::vector<float> variances() const
962 {
963 return _variances;
964 }
965 /** Get the step coordinates */
966 std::array<float, 2> steps() const
967 {
968 return _steps;
969 }
970 /** Get the image size coordinates */
971 Coordinates2D img_size() const
972 {
973 return _img_size;
974 }
975 /** Get the offset */
976 float offset() const
977 {
978 return _offset;
979 }
980 /** Get the flip value */
981 bool flip() const
982 {
983 return _flip;
984 }
985 /** Get the clip value */
986 bool clip() const
987 {
988 return _clip;
989 }
990 /** Get max sizes. */
991 std::vector<float> max_sizes() const
992 {
993 return _max_sizes;
994 }
995 /** Get aspect ratios. */
996 std::vector<float> aspect_ratios() const
997 {
998 return _aspect_ratios;
999 }
1000
1001private:
1002 std::vector<float> _min_sizes;
1003 std::vector<float> _variances;
1004 float _offset;
1005 bool _flip;
1006 bool _clip;
1007 std::vector<float> _max_sizes;
1008 std::vector<float> _aspect_ratios;
1009 Coordinates2D _img_size;
1010 std::array<float, 2> _steps;
1011};
1012
Isabella Gottardi05e56442018-11-16 11:26:52 +00001013/** Available Detection Output code types */
1014enum class DetectionOutputLayerCodeType
1015{
1016 CORNER, /**< Use box corners */
1017 CENTER_SIZE, /**< Use box centers and size */
1018 CORNER_SIZE, /**< Use box centers and size */
1019 TF_CENTER /**< Use box centers and size but flip x and y co-ordinates */
1020};
1021
1022/** Detection Output layer info */
1023class DetectionOutputLayerInfo final
1024{
1025public:
1026 /** Default Constructor */
1027 DetectionOutputLayerInfo()
1028 : _num_classes(),
1029 _share_location(),
1030 _code_type(DetectionOutputLayerCodeType::CORNER),
1031 _keep_top_k(),
1032 _nms_threshold(),
1033 _top_k(),
1034 _background_label_id(),
1035 _confidence_threshold(),
1036 _variance_encoded_in_target(false),
1037 _eta(),
1038 _num_loc_classes()
1039 {
1040 _num_loc_classes = _share_location ? 1 : _num_classes;
1041 }
1042 /** Constructor
1043 *
1044 * @param[in] num_classes Number of classes to be predicted.
1045 * @param[in] share_location If true, bounding box are shared among different classes.
1046 * @param[in] code_type Type of coding method for bbox.
1047 * @param[in] keep_top_k Number of total bounding boxes to be kept per image after NMS step.
1048 * @param[in] nms_threshold Threshold to be used in NMS.
1049 * @param[in] top_k (Optional) Number of boxes per image with top confidence scores that are fed into the NMS algorithm. Default set to -1.
1050 * @param[in] background_label_id (Optional) Background label ID. If there is no background class, set it as -1.
1051 * @param[in] confidence_threshold (Optional) Only consider detections whose confidences are larger than a threshold. Default set to -FLT_MAX.
1052 * @param[in] variance_encoded_in_target (Optional) If true, variance is encoded in target. Otherwise we need to adjust the predicted offset accordingly.Default set to false.
1053 * @param[in] eta (Optional) Eta.
1054 */
1055 DetectionOutputLayerInfo(int num_classes, bool share_location, DetectionOutputLayerCodeType code_type, int keep_top_k, float nms_threshold, int top_k = -1, int background_label_id = -1,
1056 float confidence_threshold = std::numeric_limits<float>::lowest(), bool variance_encoded_in_target = false, float eta = 1)
1057 : _num_classes(num_classes),
1058 _share_location(share_location),
1059 _code_type(code_type),
1060 _keep_top_k(keep_top_k),
1061 _nms_threshold(nms_threshold),
1062 _top_k(top_k),
1063 _background_label_id(background_label_id),
1064 _confidence_threshold(confidence_threshold),
1065 _variance_encoded_in_target(variance_encoded_in_target),
1066 _eta(eta),
1067 _num_loc_classes()
1068 {
1069 _num_loc_classes = _share_location ? 1 : _num_classes;
1070 }
1071 /** Get num classes. */
1072 int num_classes() const
1073 {
1074 return _num_classes;
1075 }
1076 /** Get share location. */
1077 bool share_location() const
1078 {
1079 return _share_location;
1080 }
1081 /** Get detection output code type. */
1082 DetectionOutputLayerCodeType code_type() const
1083 {
1084 return _code_type;
1085 }
1086 /** Get if variance encoded in target. */
1087 bool variance_encoded_in_target() const
1088 {
1089 return _variance_encoded_in_target;
1090 }
1091 /** Get the number of total bounding boxes to be kept per image. */
1092 int keep_top_k() const
1093 {
1094 return _keep_top_k;
1095 }
1096 /** Get nms threshold. */
1097 float nms_threshold() const
1098 {
1099 return _nms_threshold;
1100 }
1101 /** Get eta. */
1102 float eta() const
1103 {
1104 return _eta;
1105 }
1106 /** Get background label ID. */
1107 int background_label_id() const
1108 {
1109 return _background_label_id;
1110 }
1111 /** Get confidence threshold. */
1112 float confidence_threshold() const
1113 {
1114 return _confidence_threshold;
1115 }
1116 /** Get top K. */
1117 int top_k() const
1118 {
1119 return _top_k;
1120 }
1121 /** Get number of location classes. */
1122 int num_loc_classes() const
1123 {
1124 return _num_loc_classes;
1125 }
1126
1127private:
1128 int _num_classes;
1129 bool _share_location;
1130 DetectionOutputLayerCodeType _code_type;
1131 int _keep_top_k;
1132 float _nms_threshold;
1133 int _top_k;
1134 int _background_label_id;
1135 float _confidence_threshold;
1136 bool _variance_encoded_in_target;
1137 float _eta;
1138 int _num_loc_classes;
1139};
1140
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001141/** Pooling Layer Information class */
1142class PoolingLayerInfo
1143{
1144public:
Georgios Pinitas4c2dd542017-11-13 12:58:41 +00001145 /** Default Constructor */
1146 PoolingLayerInfo()
Isabella Gottardi6e464c32018-01-26 12:32:45 +00001147 : _pool_type(PoolingType::MAX), _pool_size(Size2D()), _pad_stride_info(PadStrideInfo()), _exclude_padding(false), _is_global_pooling(false)
Georgios Pinitas4c2dd542017-11-13 12:58:41 +00001148 {
1149 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001150 /** Default Constructor
1151 *
Georgios Pinitas4c2dd542017-11-13 12:58:41 +00001152 * @param[in] pool_type Pooling type @ref PoolingType.
1153 * @param[in] pool_size Pooling size, in elements, across x and y.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001154 * @param[in] pad_stride_info (Optional) Padding and stride information @ref PadStrideInfo
Georgios Pinitasadaae7e2017-10-30 15:56:32 +00001155 * @param[in] exclude_padding (Optional) Strategy when accounting padding in calculations.
1156 * True will exclude padding while false will not (Used in AVG/L2 pooling to determine the pooling area).
1157 * Defaults to false;
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001158 */
Georgios Pinitas4c2dd542017-11-13 12:58:41 +00001159 explicit PoolingLayerInfo(PoolingType pool_type,
1160 unsigned int pool_size,
1161 PadStrideInfo pad_stride_info = PadStrideInfo(),
1162 bool exclude_padding = false)
Isabella Gottardi6e464c32018-01-26 12:32:45 +00001163 : _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)
1164 {
1165 }
1166 /** Default Constructor
1167 *
1168 * @param[in] pool_type Pooling type @ref PoolingType.
1169 * @param[in] pool_size Pooling size, in elements, across x and y.
1170 * @param[in] pad_stride_info (Optional) Padding and stride information @ref PadStrideInfo
1171 * @param[in] exclude_padding (Optional) Strategy when accounting padding in calculations.
1172 * True will exclude padding while false will not (Used in AVG/L2 pooling to determine the pooling area).
1173 * Defaults to false;
1174 */
1175 explicit PoolingLayerInfo(PoolingType pool_type,
1176 Size2D pool_size,
1177 PadStrideInfo pad_stride_info = PadStrideInfo(),
1178 bool exclude_padding = false)
Georgios Pinitas4c2dd542017-11-13 12:58:41 +00001179 : _pool_type(pool_type), _pool_size(pool_size), _pad_stride_info(pad_stride_info), _exclude_padding(exclude_padding), _is_global_pooling(false)
1180 {
1181 }
1182 /** Default Constructor
1183 *
1184 * @note This constructor is used for global pooling
1185 *
1186 * @param[in] pool_type Pooling type @ref PoolingType.
1187 */
1188 explicit PoolingLayerInfo(PoolingType pool_type)
Isabella Gottardi6e464c32018-01-26 12:32:45 +00001189 : _pool_type(pool_type), _pool_size(Size2D()), _pad_stride_info(PadStrideInfo(1, 1, 0, 0)), _exclude_padding(false), _is_global_pooling(true)
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001190 {
1191 }
Alex Gildayc357c472018-03-21 13:54:09 +00001192 /** Get the pooling type */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001193 PoolingType pool_type() const
1194 {
1195 return _pool_type;
1196 }
Alex Gildayc357c472018-03-21 13:54:09 +00001197 /** Get the pooling size */
Isabella Gottardi6e464c32018-01-26 12:32:45 +00001198 const Size2D &pool_size() const
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001199 {
1200 return _pool_size;
1201 }
Alex Gildayc357c472018-03-21 13:54:09 +00001202 /** Get the padding and stride */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001203 PadStrideInfo pad_stride_info() const
1204 {
1205 return _pad_stride_info;
1206 }
Alex Gildayc357c472018-03-21 13:54:09 +00001207 /** Check if padding is excluded in calculations */
Georgios Pinitasadaae7e2017-10-30 15:56:32 +00001208 bool exclude_padding() const
1209 {
1210 return _exclude_padding;
1211 }
Alex Gildayc357c472018-03-21 13:54:09 +00001212 /** Check if is global pooling */
Georgios Pinitas4c2dd542017-11-13 12:58:41 +00001213 bool is_global_pooling() const
1214 {
1215 return _is_global_pooling;
1216 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001217
1218private:
1219 PoolingType _pool_type;
Isabella Gottardi6e464c32018-01-26 12:32:45 +00001220 Size2D _pool_size;
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001221 PadStrideInfo _pad_stride_info;
Georgios Pinitasadaae7e2017-10-30 15:56:32 +00001222 bool _exclude_padding;
Georgios Pinitas4c2dd542017-11-13 12:58:41 +00001223 bool _is_global_pooling;
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001224};
1225
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001226/** ROI Pooling Layer Information class */
giuros0118870812018-09-13 09:31:40 +01001227class ROIPoolingLayerInfo final
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001228{
1229public:
giuros0118870812018-09-13 09:31:40 +01001230 /** Constructor
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001231 *
giuros0118870812018-09-13 09:31:40 +01001232 * @param[in] pooled_width Pooled width of the layer.
1233 * @param[in] pooled_height Pooled height of the layer.
1234 * @param[in] spatial_scale Spatial scale to be applied to the ROI coordinates and dimensions.
1235 * @param[in] sampling_ratio Number of samples to include in each pooling region (if set to zero, a ceil(roi_dims/pooling_dims))
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001236 */
giuros0118870812018-09-13 09:31:40 +01001237 ROIPoolingLayerInfo(unsigned int pooled_width, unsigned int pooled_height, float spatial_scale, unsigned int sampling_ratio = 0)
1238 : _pooled_width(pooled_width), _pooled_height(pooled_height), _spatial_scale(spatial_scale), _sampling_ratio(sampling_ratio)
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001239 {
1240 }
Alex Gildayc357c472018-03-21 13:54:09 +00001241 /** Get the pooled width of the layer */
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001242 unsigned int pooled_width() const
1243 {
1244 return _pooled_width;
1245 }
Alex Gildayc357c472018-03-21 13:54:09 +00001246 /** Get the pooled height of the layer */
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001247 unsigned int pooled_height() const
1248 {
1249 return _pooled_height;
1250 }
Alex Gildayc357c472018-03-21 13:54:09 +00001251 /** Get the spatial scale */
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001252 float spatial_scale() const
1253 {
1254 return _spatial_scale;
1255 }
giuros0118870812018-09-13 09:31:40 +01001256 /** Get sampling ratio */
1257 unsigned int sampling_ratio() const
1258 {
1259 return _sampling_ratio;
1260 }
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001261
1262private:
1263 unsigned int _pooled_width;
1264 unsigned int _pooled_height;
1265 float _spatial_scale;
giuros0118870812018-09-13 09:31:40 +01001266 unsigned int _sampling_ratio;
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001267};
1268
Manuel Bottini5209be52019-02-13 16:34:56 +00001269/** Generate Proposals Information class */
1270class GenerateProposalsInfo
1271{
1272public:
1273 /** Constructor
1274 *
1275 * @param[in] im_width Width of the original image
1276 * @param[in] im_height Height of the original image
1277 * @param[in] im_scale Scale applied to the original image
1278 * @param[in] spatial_scale (Optional)Scale applied to the feature map. Defaults to 1.0
1279 * @param[in] pre_nms_topN (Optional)Number of the best scores to be selected from the transformations. Defaults to 6000.
1280 * @param[in] post_nms_topN (Optional)Number of the best scores to be selected from the NMS operation. Defaults to 300.
1281 * @param[in] nms_thres (Optional)NMS overlap threshold. Defaults to 0.7.
1282 * @param[in] min_size (Optional)Size used to validate the anchors produced. Defaults to 16.
1283 * @param[in] values_per_roi (Optional)Values used to represent a ROI(Region of interest). Defaults to 4.
1284 */
1285 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,
1286 size_t values_per_roi = 4)
1287 : _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),
1288 _min_size(min_size), _values_per_roi(values_per_roi)
1289 {
1290 }
1291
1292 /* Get the original height */
1293 float im_height() const
1294 {
1295 return _im_height;
1296 }
1297 /* Get the original width */
1298 float im_width() const
1299 {
1300 return _im_width;
1301 }
1302 /* Get the image scale */
1303 float im_scale() const
1304 {
1305 return _im_scale;
1306 }
1307 /* Get the value of how many best scores to select (before NMS) */
1308 int pre_nms_topN() const
1309 {
1310 return _pre_nms_topN;
1311 }
1312 /* Get the value of how many best scores to select (after NMS) */
1313 int post_nms_topN() const
1314 {
1315 return _post_nms_topN;
1316 }
1317 /* Get the NMS overlap threshold */
1318 float nms_thres() const
1319 {
1320 return _nms_thres;
1321 }
1322 /* Get the minimal size */
1323 float min_size() const
1324 {
1325 return _min_size;
1326 }
1327 /* Get the spatial scale to be applied to the feature maps */
1328 float spatial_scale() const
1329 {
1330 return _spatial_scale;
1331 }
1332 /* Get the values used to represent a ROI(Region of interest)*/
1333 size_t values_per_roi() const
1334 {
1335 return _values_per_roi;
1336 }
1337
1338private:
1339 float _im_height;
1340 float _im_width;
1341 float _im_scale;
1342 float _spatial_scale;
1343 int _pre_nms_topN;
1344 int _post_nms_topN;
1345 float _nms_thres;
1346 float _min_size;
1347 size_t _values_per_roi;
1348};
1349
1350/** ComputeAnchors information class */
1351class ComputeAnchorsInfo
1352{
1353public:
1354 /** Constructor
1355 *
1356 * @param[in] feat_width Feature map width
1357 * @param[in] feat_height Feature map height
1358 * @param[in] spatial_scale Feature map scale
1359 * @param[in] values_per_roi (Optional)Values used to represent a ROI(Region Of Interest). Defaults to 4
1360 */
1361 ComputeAnchorsInfo(float feat_width, float feat_height, float spatial_scale, size_t values_per_roi = 4)
1362 : _feat_height(feat_height),
1363 _feat_width(feat_width),
1364 _spatial_scale(spatial_scale),
1365 _values_per_roi(values_per_roi)
1366 {
1367 }
1368
1369 /* Get the height of the feature map */
1370 float feat_height() const
1371 {
1372 return _feat_height;
1373 }
1374
1375 /* Get the width of the feature map */
1376 float feat_width() const
1377 {
1378 return _feat_width;
1379 }
1380
1381 /* Get the scale of the feature map */
1382 float spatial_scale() const
1383 {
1384 return _spatial_scale;
1385 }
1386
1387 /* Get the values used to represent a ROI(Region Of Interest)*/
1388 size_t values_per_roi() const
1389 {
1390 return _values_per_roi;
1391 }
1392
1393private:
1394 float _feat_height;
1395 float _feat_width;
1396 float _spatial_scale;
1397 size_t _values_per_roi;
1398};
1399
giuros01c04a0e82018-10-03 12:44:35 +01001400/** Bounding Box Transform information class */
giuros01d696cb62018-11-16 10:39:59 +00001401class BoundingBoxTransformInfo final
giuros01c04a0e82018-10-03 12:44:35 +01001402{
1403public:
1404 /** Constructor
1405 *
giuros01d696cb62018-11-16 10:39:59 +00001406 * @param[in] img_width Width of the original image
1407 * @param[in] img_height Height, of the original image
1408 * @param[in] scale Scale of the original image
1409 * @param[in] apply_scale (Optional)Re-apply scaling after transforming the boxes. Defaults to false
1410 * @param[in] weights (Optional)Weights [wx, wy, ww, wh] for the deltas. Defaults to all ones
1411 * @param[in] correct_transform_coords (Optional)Correct bounding box transform coordinates. Defaults to false
1412 * @param[in] bbox_xform_clip (Optional)Minimum bounding box width and height after bounding box transformation in log-space. Defaults to log(1000/16)
giuros01c04a0e82018-10-03 12:44:35 +01001413 */
giuros01d696cb62018-11-16 10:39:59 +00001414 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 =
1415 false,
1416 float bbox_xform_clip =
1417 4.135166556742356f)
1418 : _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)
giuros01c04a0e82018-10-03 12:44:35 +01001419 {
1420 }
1421
1422 std::array<float, 4> weights() const
1423 {
1424 return _weights;
1425 }
1426
1427 float bbox_xform_clip() const
1428 {
1429 return _bbox_xform_clip;
1430 }
1431
1432 float img_height() const
1433 {
1434 return _img_height;
1435 }
1436
1437 float img_width() const
1438 {
1439 return _img_width;
1440 }
1441
1442 float scale() const
1443 {
1444 return _scale;
1445 }
1446
1447 bool apply_scale() const
1448 {
1449 return _apply_scale;
1450 }
1451
giuros01d696cb62018-11-16 10:39:59 +00001452 bool correct_transform_coords() const
1453 {
1454 return _correct_transform_coords;
1455 }
1456
giuros01c04a0e82018-10-03 12:44:35 +01001457private:
1458 float _img_width;
1459 float _img_height;
1460 float _scale;
1461 bool _apply_scale;
giuros01d696cb62018-11-16 10:39:59 +00001462 bool _correct_transform_coords;
giuros01c04a0e82018-10-03 12:44:35 +01001463 std::array<float, 4> _weights;
1464 float _bbox_xform_clip;
1465};
1466
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001467/** Activation Layer Information class */
1468class ActivationLayerInfo
1469{
1470public:
1471 /** Available activation functions */
1472 enum class ActivationFunction
1473 {
Georgios Pinitas64ebe5b2017-09-01 17:44:24 +01001474 LOGISTIC, /**< Logistic ( \f$ f(x) = \frac{1}{1 + e^{-x}} \f$ ) */
1475 TANH, /**< Hyperbolic tangent ( \f$ f(x) = a \cdot tanh(b \cdot x) \f$ ) */
1476 RELU, /**< Rectifier ( \f$ f(x) = max(0,x) \f$ ) */
1477 BOUNDED_RELU, /**< Upper Bounded Rectifier ( \f$ f(x) = min(a, max(0,x)) \f$ ) */
1478 LU_BOUNDED_RELU, /**< Lower and Upper Bounded Rectifier ( \f$ f(x) = min(a, max(b,x)) \f$ ) */
Manuel Bottini581c8982019-02-07 10:31:57 +00001479 LEAKY_RELU, /**< Leaky Rectifier ( \f$ f(x) = \begin{cases} \alpha x & \quad \text{if } x \text{ < 0}\\ x & \quad \text{if } x \geq \text{ 0 } \end{cases} \f$ ) */
Georgios Pinitas64ebe5b2017-09-01 17:44:24 +01001480 SOFT_RELU, /**< Soft Rectifier ( \f$ f(x)= log(1+e^x) \f$ ) */
1481 ABS, /**< Absolute ( \f$ f(x)= |x| \f$ ) */
1482 SQUARE, /**< Square ( \f$ f(x)= x^2 \f$ )*/
1483 SQRT, /**< Square root ( \f$ f(x) = \sqrt{x} \f$ )*/
Usama Arif6a98a6e2019-05-10 17:07:27 +01001484 LINEAR, /**< Linear ( \f$ f(x)= ax + b \f$ ) */
1485 IDENTITY /**< Identity ( \f$ f(x)= x \f$ ) */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001486 };
1487
Giorgio Arena11674872018-02-07 15:38:12 +00001488 ActivationLayerInfo() = default;
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001489 /** Default Constructor
1490 *
1491 * @param[in] f The activation function to use.
1492 * @param[in] a (Optional) The alpha parameter used by some activation functions
Georgios Pinitas64ebe5b2017-09-01 17:44:24 +01001493 * (@ref ActivationFunction::BOUNDED_RELU, @ref ActivationFunction::LU_BOUNDED_RELU, @ref ActivationFunction::LINEAR, @ref ActivationFunction::TANH).
1494 * @param[in] b (Optional) The beta parameter used by some activation functions (@ref ActivationFunction::LINEAR, @ref ActivationFunction::LU_BOUNDED_RELU, @ref ActivationFunction::TANH).
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001495 */
1496 ActivationLayerInfo(ActivationFunction f, float a = 0.0f, float b = 0.0f)
Giorgio Arena11674872018-02-07 15:38:12 +00001497 : _act(f), _a(a), _b(b), _enabled(true)
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001498 {
1499 }
Alex Gildayc357c472018-03-21 13:54:09 +00001500 /** Get the type of activation function */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001501 ActivationFunction activation() const
1502 {
1503 return _act;
1504 }
Alex Gildayc357c472018-03-21 13:54:09 +00001505 /** Get the alpha value */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001506 float a() const
1507 {
1508 return _a;
1509 }
Alex Gildayc357c472018-03-21 13:54:09 +00001510 /** Get the beta value */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001511 float b() const
1512 {
1513 return _b;
1514 }
Alex Gildayc357c472018-03-21 13:54:09 +00001515 /** Check if initialised */
Giorgio Arena11674872018-02-07 15:38:12 +00001516 bool enabled() const
1517 {
1518 return _enabled;
1519 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001520
1521private:
Usama Arif6a98a6e2019-05-10 17:07:27 +01001522 ActivationFunction _act = { ActivationLayerInfo::ActivationFunction::IDENTITY };
Giorgio Arena11674872018-02-07 15:38:12 +00001523 float _a = {};
1524 float _b = {};
1525 bool _enabled = { false };
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001526};
1527
1528/** Normalization Layer Information class */
1529class NormalizationLayerInfo
1530{
1531public:
1532 /** Default Constructor
1533 *
Michele Di Giorgio9d3a8312018-11-20 12:31:24 +00001534 * @param[in] type The normalization type. Can be @ref NormType::IN_MAP_1D, @ref NormType::IN_MAP_2D or @ref NormType::CROSS_MAP
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001535 * @param[in] norm_size The normalization size is the number of elements to normalize across. Defaults to 5.
Georgios Pinitas41caa622017-11-16 14:37:08 +00001536 * @param[in] alpha (Optional) Alpha parameter used by normalization equation. Defaults to 0.0001.
1537 * @param[in] beta (Optional) Beta parameter used by normalization equation. Defaults to 0.5.
1538 * @param[in] kappa (Optional) Kappa parameter used by [Krichevksy 2012] Across Channel Local Brightness Normalization equation.
1539 * @param[in] is_scaled (Optional) Boolean that specifies if alpha will be scaled by the normalization size or not.
1540 * Should be false to follow [Krichevksy 2012].
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001541 */
Georgios Pinitas41caa622017-11-16 14:37:08 +00001542 NormalizationLayerInfo(NormType type, uint32_t norm_size = 5, float alpha = 0.0001f, float beta = 0.5f, float kappa = 1.f, bool is_scaled = true)
1543 : _type(type), _norm_size(norm_size), _alpha(alpha), _beta(beta), _kappa(kappa), _is_scaled(is_scaled)
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001544 {
1545 }
Alex Gildayc357c472018-03-21 13:54:09 +00001546 /** Get the normalization type */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001547 NormType type() const
1548 {
1549 return _type;
1550 }
Alex Gildayc357c472018-03-21 13:54:09 +00001551 /** Get the normalization size */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001552 uint32_t norm_size() const
1553 {
1554 return _norm_size;
1555 }
Alex Gildayc357c472018-03-21 13:54:09 +00001556 /** Get the alpha value */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001557 float alpha() const
1558 {
1559 return _alpha;
1560 }
Alex Gildayc357c472018-03-21 13:54:09 +00001561 /** Get the beta value */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001562 float beta() const
1563 {
1564 return _beta;
1565 }
Alex Gildayc357c472018-03-21 13:54:09 +00001566 /** Get the kappa value */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001567 float kappa() const
1568 {
1569 return _kappa;
1570 }
Michele Di Giorgio9d3a8312018-11-20 12:31:24 +00001571 /** Get the is_scaled value */
1572 bool is_scaled() const
1573 {
1574 return _is_scaled;
1575 }
Alex Gildayc357c472018-03-21 13:54:09 +00001576 /** Check if normalization is cross map */
Georgios Pinitas41caa622017-11-16 14:37:08 +00001577 bool is_cross_map() const
1578 {
1579 return _type == NormType::CROSS_MAP;
1580 }
Alex Gildayc357c472018-03-21 13:54:09 +00001581 /** Check if normalization is not cross map */
Georgios Pinitas41caa622017-11-16 14:37:08 +00001582 bool is_in_map() const
1583 {
1584 return !is_cross_map();
1585 }
1586 /** Return the scaling factor of the normalization function.
1587 *
1588 * If is_scaled is set to false then [Krichevksy 2012] normalization scaling is performed,
1589 * where alpha is returned plainly, else alpha is scaled by the total number of elements used for the normalization.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001590 *
1591 * @return The normalization scaling factor.
1592 */
1593 float scale_coeff() const
1594 {
1595 const uint32_t size = (_type == NormType::IN_MAP_2D) ? _norm_size * _norm_size : _norm_size;
Georgios Pinitas41caa622017-11-16 14:37:08 +00001596 return (_is_scaled) ? (_alpha / size) : _alpha;
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001597 }
1598
1599private:
1600 NormType _type;
1601 uint32_t _norm_size;
1602 float _alpha;
1603 float _beta;
1604 float _kappa;
Georgios Pinitas41caa622017-11-16 14:37:08 +00001605 bool _is_scaled;
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001606};
1607
Gian Marco Iodice559d7712017-08-08 08:38:09 +01001608/** Convolution Layer Weights Information class. This class stores the necessary information to compute convolution layer when the weights are already reshaped */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001609class WeightsInfo
1610{
1611public:
Gian Marco Iodice4e288692017-06-27 11:41:59 +01001612 /** Default constructor */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001613 WeightsInfo()
Michele Di Giorgiob62280a2018-05-31 17:31:05 +01001614 : _are_reshaped(false), _kernel_width(0), _kernel_height(0), _num_kernels(0), _retain_internal_weights(false)
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001615 {
1616 }
1617 /** Constructor
1618 *
Michele Di Giorgiob62280a2018-05-31 17:31:05 +01001619 * @param[in] are_reshaped True if the weights have been reshaped
1620 * @param[in] kernel_width Kernel width.
1621 * @param[in] kernel_height Kernel height.
1622 * @param[in] num_kernels Number of convolution kernels.
1623 * @param[in] retain_internal_weights (Optional) True if internal reshaped weights must be retained. Used for reconfiguration purposes. Default is false.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001624 */
Michele Di Giorgiob62280a2018-05-31 17:31:05 +01001625 WeightsInfo(bool are_reshaped, unsigned int kernel_width, unsigned int kernel_height, unsigned int num_kernels, bool retain_internal_weights = false)
1626 : _are_reshaped(are_reshaped), _kernel_width(kernel_width), _kernel_height(kernel_height), _num_kernels(num_kernels), _retain_internal_weights(retain_internal_weights)
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001627 {
1628 }
Gian Marco Iodice4e288692017-06-27 11:41:59 +01001629 /** Flag which specifies if the weights tensor has been reshaped.
1630 *
1631 * @return True if the weights tensors has been reshaped
1632 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001633 bool are_reshaped() const
1634 {
1635 return _are_reshaped;
1636 };
Gian Marco Iodice559d7712017-08-08 08:38:09 +01001637 /** Return the number of convolution kernels
1638 *
1639 * @return The number of convolution kernels
1640 */
1641 unsigned int num_kernels() const
1642 {
1643 return _num_kernels;
1644 };
Gian Marco Iodice4e288692017-06-27 11:41:59 +01001645 /** Return the width and height of the kernel
1646 *
1647 * @return The width and height of the kernel
1648 */
1649 std::pair<unsigned int, unsigned int> kernel_size() const
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001650 {
Gian Marco Iodice4e288692017-06-27 11:41:59 +01001651 return std::make_pair(_kernel_width, _kernel_height);
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001652 }
Michele Di Giorgiob62280a2018-05-31 17:31:05 +01001653 bool retain_internal_weights() const
1654 {
1655 return _retain_internal_weights;
1656 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001657
1658private:
1659 const bool _are_reshaped;
Gian Marco Iodice4e288692017-06-27 11:41:59 +01001660 const unsigned int _kernel_width;
1661 const unsigned int _kernel_height;
Gian Marco Iodice559d7712017-08-08 08:38:09 +01001662 const unsigned int _num_kernels;
Michele Di Giorgiob62280a2018-05-31 17:31:05 +01001663 const bool _retain_internal_weights;
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001664};
1665
Gian Marco36a0a462018-01-12 10:21:40 +00001666/** GEMM reshape information class. This class stores the necessary information about matrix A and matrix B reshape.
1667 *
Gian Marco Iodice5fc07aa2019-05-15 17:08:02 +01001668 * The matrix A can only be reshaped through @ref CLGEMMReshapeLHSMatrixKernel or @ref NEGEMMInterleave4x4Kernel or @ref GCGEMMInterleave4x4Kernel
1669 * Note: Optionally just for @ref CLGEMMReshapeLHSMatrixKernel is it possible to set mult_interleave4x4_height, the multiplication factor for the height of the 4x4 interleaved block
Gian Marco36a0a462018-01-12 10:21:40 +00001670 *
giuros018b6b4a92018-12-18 19:01:33 +00001671 * The matrix B can only be reshaped through @ref CLGEMMReshapeRHSMatrixKernel or @ref NEGEMMTranspose1xWKernel or @ref GCGEMMTranspose1xWKernel
1672 * Note: Optionally just for @ref CLGEMMReshapeRHSMatrixKernel is it possible to set mult_transpose1xW_width, the multiplication factor for the width of the 1xW transposed block
Gian Marco36a0a462018-01-12 10:21:40 +00001673 *
1674 */
1675class GEMMReshapeInfo final
1676{
1677public:
1678 /** Default constructor */
1679 GEMMReshapeInfo()
Gian Marco Iodice3139f032018-11-05 14:26:32 +00001680 : _m(1), _n(1), _k(1), _mult_transpose1xW_width(1), _mult_interleave4x4_height(1), _depth_output_gemm3d(0), _reinterpret_input_as_3d(false)
Gian Marco36a0a462018-01-12 10:21:40 +00001681 {
1682 }
1683 /** Constructor
1684 *
1685 * @param[in] m Number of matrix A rows
1686 * @param[in] n Number of matrix B columns
1687 * @param[in] k Number of matrix A columns or matrix B rows
1688 * @param[in] mult_transpose1xW_width (Optional) Multiplication factor for the width of the 1xW transposed block
1689 * @param[in] mult_interleave4x4_height (Optional) Multiplication factor for the height of the 4x4 interleaved block
Gian Marco Iodice3139f032018-11-05 14:26:32 +00001690 * @param[in] depth_output_gemm3d (Optional) Depth (third dimension) of the output tensor to be used with the GEMM3D kernel.
1691 * If 0 the output will not be reinterpreted as 3D. Default 0
Gian Marco Iodice68a3f562018-07-26 11:44:03 +01001692 * @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
1693 * to perform 1x1 convolutions with the NHWC data layout)
Gian Marco36a0a462018-01-12 10:21:40 +00001694 */
Gian Marco Iodice3139f032018-11-05 14:26:32 +00001695 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 Iodice68a3f562018-07-26 11:44:03 +01001696 : _m(m), _n(n), _k(k), _mult_transpose1xW_width(mult_transpose1xW_width), _mult_interleave4x4_height(mult_interleave4x4_height), _depth_output_gemm3d(depth_output_gemm3d),
1697 _reinterpret_input_as_3d(reinterpret_input_as_3d)
Gian Marco36a0a462018-01-12 10:21:40 +00001698 {
1699 }
1700 /** Number of matrix A rows
1701 *
1702 * @return the number of matrix A rows
1703 */
1704 int m() const
1705 {
1706 return _m;
1707 }
1708 /** Number of matrix B columns
1709 *
1710 * @return the number of matrix B columns
1711 */
1712 int n() const
1713 {
1714 return _n;
1715 }
1716 /** Number of matrix A columns or matrix B rows
1717 *
1718 * @return the number of matrix A columns or matrix B rows
1719 */
1720 int k() const
1721 {
1722 return _k;
1723 }
1724 /** Multiplication factor for the width of the 1xW transposed block
1725 *
1726 * @return the multiplication factor for the width of the 1xW transposed block
1727 */
1728 int mult_transpose1xW_width() const
1729 {
1730 return _mult_transpose1xW_width;
1731 }
1732 /** Multiplication factor for the height of the 4x4 interleaved block
1733 *
1734 * @return the multiplication factor for the height of the 4x4 interleaved block
1735 */
1736 int mult_interleave4x4_height() const
1737 {
1738 return _mult_interleave4x4_height;
1739 }
Isabella Gottardi8e74f442018-03-01 16:42:00 +00001740 /** Depth (third dimension) of the output tensor to be used with the GEMM3D kernel
1741 *
1742 * @note GEMM3D kernel is used when the output has to be reinterpret as 3D tensor. In that case:
1743 * m = depth_output_gemm3d * output_height
1744 *
1745 * @return the depth of the output tensor to be used with the GEMM3D kernel
1746 */
1747 int depth_output_gemm3d() const
1748 {
1749 return _depth_output_gemm3d;
1750 }
Gian Marco Iodice68a3f562018-07-26 11:44:03 +01001751 /** Flag which specifies if the input tensor has to be reinterpreted as 3D
1752 *
1753 * @return True if the input tensor has to be reinterpreted as 3D tensor
1754 */
1755 bool reinterpret_input_as_3d() const
1756 {
1757 return _reinterpret_input_as_3d;
1758 };
Gian Marco36a0a462018-01-12 10:21:40 +00001759
1760private:
Gian Marco Iodice68a3f562018-07-26 11:44:03 +01001761 const int _m;
1762 const int _n;
1763 const int _k;
1764 const int _mult_transpose1xW_width;
1765 const int _mult_interleave4x4_height;
1766 const int _depth_output_gemm3d;
1767 const bool _reinterpret_input_as_3d;
Gian Marco36a0a462018-01-12 10:21:40 +00001768};
1769
giuros016d109962019-01-07 17:47:19 +00001770struct DepthwiseConvolutionReshapeInfo
1771{
1772 unsigned int c0{ 1 }; /**< Number of channels processed by the depth-wise convolution */
1773 bool transpose{ false }; /**< True if the block MxC0 (where M is the area of the filter i.e. KwxKh) has to be transposed */
1774};
1775
Gian Marco Iodice4b908652018-10-18 10:21:02 +01001776/** GEMMLowp output stage type */
1777enum class GEMMLowpOutputStageType
1778{
1779 NONE, /**< No quantization to uint8 */
1780 QUANTIZE_DOWN, /**< Quantize to uint8 using an integer multiplication */
1781 QUANTIZE_DOWN_FIXEDPOINT, /**< Quantize to uint8 using a fixed point multiplication */
1782 QUANTIZE_DOWN_FLOAT /**< Quantize to uint8 using a floating point multiplication */
1783};
1784
1785/** GEMMLowp output stage info */
1786struct GEMMLowpOutputStageInfo
1787{
1788 GEMMLowpOutputStageType type{ GEMMLowpOutputStageType::NONE }; /**< GEMMLowp output stage type */
1789 int gemmlowp_offset{ 0 }; /**< GEMMLowp output stage offset used for quantizing to QASYMM8 */
1790 int gemmlowp_multiplier{ 0 }; /**< GEMMLowp output stage multiplier used for quantizing to QASYMM8 */
1791 int gemmlowp_shift{ 0 }; /**< GEMMLowp output stage shift used for quantizing to uint8 */
1792 int gemmlowp_min_bound{ 0 }; /**< GEMMLowp min value used to saturate down the output result before converting back to QASYMM8 */
1793 int gemmlowp_max_bound{ 0 }; /**< GEMMLowp max value used to saturate down the output result before converting back to QASYMM8 */
1794};
1795
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +00001796/** GEMM LHS (Left Hand Side) matrix information */
1797struct GEMMLHSMatrixInfo
1798{
1799 unsigned int m0{ 1 }; /**< Number of rows processed by the matrix multiplication */
1800 unsigned int k0{ 1 }; /**< Number of partial accumulations performed by the matrix multiplication */
1801 unsigned int v0{ 1 }; /**< Number of vertical blocks of size (m0xk0) stored on the same output row */
1802 bool transpose{ true }; /**< True if the (m0xk0) block has to be transposed before been stored */
1803 bool interleave{ true }; /**< True if the v0 (m0xk0) blocks have to be interleaved in the output row */
1804};
1805
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +00001806/** GEMM RHS (Right Hand Side) matrix information */
1807struct GEMMRHSMatrixInfo
1808{
1809 unsigned int n0{ 1 }; /**< Number of columns processed by the matrix multiplication */
1810 unsigned int k0{ 1 }; /**< Number of partial accumulations performed by the matrix multiplication */
1811 unsigned int h0{ 1 }; /**< Number of horizontal blocks of size (k0xn0) stored on the same output row */
1812 bool transpose{ true }; /**< True if the (k0xn0) block has to be transposed before been stored */
1813 bool interleave{ true }; /**< True if the h0 (k0xn0) blocks have to be interleaved in the output row */
1814};
1815
Gian Marco36a0a462018-01-12 10:21:40 +00001816/** GEMM information class. This class stores the necessary information to compute GEMM functions
1817 *
1818 * This object also contains the information about how matrix A and matrix B have been reshaped
1819 *
1820 */
Chunosov5124be52017-11-22 20:42:13 +07001821class GEMMInfo
1822{
1823public:
1824 /** Default constructor */
1825 GEMMInfo()
Anthony Barbier08a45172018-11-30 17:20:26 +00001826 : _is_a_reshaped(false), _is_b_reshaped(false), _reshape_b_only_on_first_run(true), _depth_output_gemm3d(0), _reinterpret_input_as_3d(false), _retain_internal_weights(false), _gemmlowp_output_stage(),
1827 _fp_mixed_precision(false)
Chunosov5124be52017-11-22 20:42:13 +07001828 {
1829 }
1830 /** Constructor
1831 *
1832 * @param[in] is_a_reshaped True if the matrix A has been reshaped
1833 * @param[in] is_b_reshaped True if the matrix B has been reshaped
1834 * @param[in] reshape_b_only_on_first_run Reshape matrix B only for the first run
Isabella Gottardi8e74f442018-03-01 16:42:00 +00001835 * @param[in] depth_output_gemm3d (Optional) Depth (third dimension) of the output tensor to be used with the GEMM3D kernel
Gian Marco Iodice3139f032018-11-05 14:26:32 +00001836 * If 0 the output will not be reinterpreted as 3D. Default 0
Gian Marco Iodice68a3f562018-07-26 11:44:03 +01001837 * @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
1838 * to perform 1x1 convolutions with the NHWC data layout)
Michele Di Giorgioba1ffe92018-08-22 14:28:30 +01001839 * @param[in] retain_internal_weights (Optional) Retain the weights tensor from previous run
Gian Marco Iodice4b908652018-10-18 10:21:02 +01001840 * @param[in] gemmlowp_output_stage (Optional) GEMMLowp Output stage info
Vidhya Sudhan Loganathana25d16c2018-11-16 11:33:12 +00001841 * @param[in] fp_mixed_precision (Optional) Use wider accumulators (32 bit instead of 16 for FP16) to improve accuracy.
Isabella Gottardi8e74f442018-03-01 16:42:00 +00001842 *
Chunosov5124be52017-11-22 20:42:13 +07001843 */
Gian Marco Iodice3139f032018-11-05 14:26:32 +00001844 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 Loganathana25d16c2018-11-16 11:33:12 +00001845 GEMMLowpOutputStageInfo gemmlowp_output_stage = GEMMLowpOutputStageInfo(), bool fp_mixed_precision = false)
Gian Marco Iodice68a3f562018-07-26 11:44:03 +01001846 : _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 Loganathana25d16c2018-11-16 11:33:12 +00001847 _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)
Chunosov5124be52017-11-22 20:42:13 +07001848 {
1849 }
1850 /** Flag which specifies if the matrix A has been reshaped
1851 *
1852 * @return True if the matrix A has been reshaped
1853 */
1854 bool is_a_reshaped() const
1855 {
1856 return _is_a_reshaped;
1857 };
1858 /** Flag which specifies if the matrix B has been reshaped
1859 *
1860 * @return True if the matrix B has been reshaped
1861 */
1862 bool is_b_reshaped() const
1863 {
1864 return _is_b_reshaped;
1865 };
1866 /** Flag which specifies if the reshape of matrix B should executed only for the first
1867 *
1868 * @note This flag could be set to TRUE when GEMM is used to accelerate convolution layer
1869 *
1870 * @return True if the reshaped of matrix B happens only for the first run
1871 */
1872 bool reshape_b_only_on_first_run() const
1873 {
1874 return _reshape_b_only_on_first_run;
1875 };
Isabella Gottardi8e74f442018-03-01 16:42:00 +00001876 /** Depth of the output when GEMM output is reinterpreted as 3D tensor
Gian Marco36a0a462018-01-12 10:21:40 +00001877 *
Isabella Gottardi8e74f442018-03-01 16:42:00 +00001878 * @return the depth of the output tensor
Gian Marco36a0a462018-01-12 10:21:40 +00001879 */
Isabella Gottardi8e74f442018-03-01 16:42:00 +00001880 int depth_output_gemm3d() const
Gian Marco36a0a462018-01-12 10:21:40 +00001881 {
Isabella Gottardi8e74f442018-03-01 16:42:00 +00001882 return _depth_output_gemm3d;
1883 };
Gian Marco Iodice68a3f562018-07-26 11:44:03 +01001884 /** Flag which specifies if the input tensor has to be reinterpreted as 3D
1885 *
1886 * @return True if the input tensor has to be reinterpreted as 3D tensor
1887 */
1888 bool reinterpret_input_as_3d() const
1889 {
1890 return _reinterpret_input_as_3d;
1891 };
Michele Di Giorgioba1ffe92018-08-22 14:28:30 +01001892 /** Flag which specifies if the weights tensor has to be retained from previous run
1893 *
1894 * @return True if the weights tensor has to be retained
1895 */
1896 bool retain_internal_weights() const
1897 {
1898 return _retain_internal_weights;
1899 };
Gian Marco Iodice4b908652018-10-18 10:21:02 +01001900 /** GEMMLowp output stage
1901 *
1902 * @return the GEMMLowp output stage info
1903 */
1904 GEMMLowpOutputStageInfo gemmlowp_output_stage() const
1905 {
1906 return _gemmlowp_output_stage;
1907 };
Vidhya Sudhan Loganathana25d16c2018-11-16 11:33:12 +00001908 /** Flag which specifies if a wider accumulator should be used.
1909 *
1910 * @return True if a wider accumulator has to be used
1911 */
1912 bool fp_mixed_precision() const
1913 {
1914 return _fp_mixed_precision;
1915 };
Chunosov5124be52017-11-22 20:42:13 +07001916
1917private:
Gian Marco Iodice4b908652018-10-18 10:21:02 +01001918 const bool _is_a_reshaped;
1919 const bool _is_b_reshaped;
1920 const bool _reshape_b_only_on_first_run;
1921 const int _depth_output_gemm3d;
1922 const bool _reinterpret_input_as_3d;
1923 const bool _retain_internal_weights;
1924 const GEMMLowpOutputStageInfo _gemmlowp_output_stage;
Vidhya Sudhan Loganathana25d16c2018-11-16 11:33:12 +00001925 const bool _fp_mixed_precision;
Chunosov5124be52017-11-22 20:42:13 +07001926};
1927
Gian Marco Iodice247f52c2018-03-22 11:24:56 +00001928/** Winograd information */
1929struct WinogradInfo
1930{
1931 /** Default constructor
1932 *
1933 * @param[in] output_tile_sz Width and height of the output tile
1934 * @param[in] kernel_sz Width and height of the kernel
1935 * @param[in] input_dims Width and height of the input tensor before the convolution is applied
1936 * @param[in] conv_info Convolution info (Pads, strides)
1937 * @param[in] data_layout Data layout to use for the output tensor once the convolution has been applied
1938 */
1939 WinogradInfo(Size2D output_tile_sz, Size2D kernel_sz, Size2D input_dims, PadStrideInfo conv_info, DataLayout data_layout)
1940 : output_tile_size(output_tile_sz), kernel_size(kernel_sz), input_dimensions(input_dims), convolution_info(conv_info), output_data_layout(data_layout)
1941 {
1942 }
1943
1944 Size2D output_tile_size{}; /**< Width and height of the output tile */
1945 Size2D kernel_size{}; /**< Width and height of the kernel*/
1946 Size2D input_dimensions{}; /**< Width and height of the input tensor before the convolution is applied */
1947 PadStrideInfo convolution_info{}; /**< Convolution info (Pads, strides,...) */
1948 DataLayout output_data_layout{ DataLayout::NCHW }; /**< Data layout to use for the output tensor once the convolution has been applied (NCHW or NHWC) */
1949};
1950
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001951/** IO formatting information class*/
1952struct IOFormatInfo
1953{
1954 /** Precision type used when printing floating point numbers */
1955 enum class PrecisionType
1956 {
1957 Default, /**< Default precision to the one that the current stream has */
1958 Custom, /**< Custom precision specified by the user using the precision parameter */
1959 Full /**< The maximum precision of the floating point representation */
1960 };
1961
1962 /** Specifies the area to be printed, used by Tensor objects */
1963 enum class PrintRegion
1964 {
1965 ValidRegion, /**< Prints the valid region of the Tensor object */
1966 NoPadding, /**< Prints the Tensor object without the padding */
1967 Full /**< Print the tensor object including padding */
1968 };
1969
Alex Gildayc357c472018-03-21 13:54:09 +00001970 /** Construct a set of IO formatting information.
1971 *
1972 * @param[in] print_region Area to be printed. Used by Tensor objects. Default: ValidRegion.
1973 * @param[in] precision_type Precision type for floating point numbers. Default: stream default.
1974 * @param[in] precision Precision value for float point numbers. Default: 10.
1975 * @param[in] align_columns Whether to align columns when printed. Default: true.
1976 * @param[in] element_delim Delimeter between elements. Default: " ".
1977 * @param[in] row_delim Delimenter between rows. Default: "\n".
1978 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001979 IOFormatInfo(PrintRegion print_region = PrintRegion::ValidRegion,
1980 PrecisionType precision_type = PrecisionType::Default,
1981 unsigned int precision = 10,
1982 bool align_columns = true,
1983 std::string element_delim = " ",
1984 std::string row_delim = "\n")
1985 : print_region(print_region),
1986 precision_type(precision_type),
1987 precision(precision),
1988 element_delim(element_delim),
1989 row_delim(row_delim),
1990 align_columns(align_columns)
1991 {
1992 }
1993
Alex Gildayc357c472018-03-21 13:54:09 +00001994 /** Area to be printed by Tensor objects */
1995 PrintRegion print_region;
1996 /** Floating point precision type */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001997 PrecisionType precision_type;
Alex Gildayc357c472018-03-21 13:54:09 +00001998 /** Floating point precision */
1999 unsigned int precision;
2000 /** Element delimeter */
2001 std::string element_delim;
2002 /** Row delimeter */
2003 std::string row_delim;
2004 /** Align columns */
2005 bool align_columns;
Anthony Barbier6ff3b192017-09-04 18:44:23 +01002006};
Georgios Pinitasd8734b52017-12-22 15:27:52 +00002007} // namespace arm_compute
Anthony Barbier6ff3b192017-09-04 18:44:23 +01002008#endif /* __ARM_COMPUTE_TYPES_H__ */