blob: 9551cc6547161c105a2fe619063bc50cbd797580 [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"
Georgios Pinitas4c5469b2019-05-21 13:32:43 +010028#include "arm_compute/core/QuantizationInfo.h"
Isabella Gottardi6e464c32018-01-26 12:32:45 +000029#include "arm_compute/core/Size2D.h"
Georgios Pinitas8795ffb2017-12-01 16:13:40 +000030#include "arm_compute/core/Strides.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010031#include "arm_compute/core/TensorShape.h"
Georgios Pinitas583137c2017-08-31 18:12:42 +010032#include "support/Half.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010033
Michel Iwaniec5dfeae62017-11-29 10:48:23 +000034#include <cmath>
Anthony Barbier6ff3b192017-09-04 18:44:23 +010035#include <cstddef>
36#include <cstdint>
Isabella Gottardia7acb3c2019-01-08 13:48:44 +000037#include <map>
Anthony Barbier6ff3b192017-09-04 18:44:23 +010038#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{
Michalis Spyrouc8530212019-08-22 11:44:04 +010076 UNKNOWN, /**< Unknown data type */
77 U8, /**< unsigned 8-bit number */
78 S8, /**< signed 8-bit number */
79 QSYMM8, /**< quantized, symmetric fixed-point 8-bit number */
Georgios Pinitasdbdea0d2019-10-16 19:21:40 +010080 QASYMM8, /**< quantized, asymmetric fixed-point 8-bit number unsigned */
81 QASYMM8_SIGNED, /**< quantized, asymmetric fixed-point 8-bit number signed */
Michalis Spyrouc8530212019-08-22 11:44:04 +010082 QSYMM8_PER_CHANNEL, /**< quantized, symmetric per channel fixed-point 8-bit number */
83 QASYMM8_PER_CHANNEL, /**< quantized, asymmetric per channel fixed-point 8-bit number */
84 U16, /**< unsigned 16-bit number */
85 S16, /**< signed 16-bit number */
86 QSYMM16, /**< quantized, symmetric fixed-point 16-bit number */
Michele Di Giorgio35ea9a72019-08-23 12:02:06 +010087 QASYMM16, /**< quantized, asymmetric fixed-point 16-bit number */
Michalis Spyrouc8530212019-08-22 11:44:04 +010088 U32, /**< unsigned 32-bit number */
89 S32, /**< signed 32-bit number */
90 U64, /**< unsigned 64-bit number */
91 S64, /**< signed 64-bit number */
92 F16, /**< 16-bit floating-point number */
93 F32, /**< 32-bit floating-point number */
94 F64, /**< 64-bit floating-point number */
95 SIZET /**< size_t */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010096};
97
Daniil Efremov02bf80d2017-11-22 00:26:51 +070098/** Available Sampling Policies */
99enum class SamplingPolicy
100{
101 CENTER, /**< Samples are taken at pixel center */
102 TOP_LEFT /**< Samples are taken at pixel top left corner */
103};
104
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100105/** Constant value of the border pixels when using BorderMode::CONSTANT */
106constexpr uint8_t CONSTANT_BORDER_VALUE = 199;
107
Alex Gildayc357c472018-03-21 13:54:09 +0000108/** Constant value used to indicate a half-scale pyramid */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100109constexpr float SCALE_PYRAMID_HALF = 0.5f;
110
Alex Gildayc357c472018-03-21 13:54:09 +0000111/** Constant value used to indicate a ORB scaled pyramid */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100112constexpr float SCALE_PYRAMID_ORB = 8.408964152537146130583778358414e-01;
113
Vidhya Sudhan Loganathand646ae12018-11-19 15:18:20 +0000114/** [DataLayout enum definition] **/
115
Georgios Pinitas4074c992018-01-30 18:13:46 +0000116/** Supported tensor data layouts */
117enum class DataLayout
118{
Alex Gildayc357c472018-03-21 13:54:09 +0000119 UNKNOWN, /**< Unknown data layout */
120 NCHW, /**< Num samples, channels, height, width */
121 NHWC /**< Num samples, height, width, channels */
Georgios Pinitas4074c992018-01-30 18:13:46 +0000122};
Vidhya Sudhan Loganathand646ae12018-11-19 15:18:20 +0000123/** [DataLayout enum definition] **/
Georgios Pinitas4074c992018-01-30 18:13:46 +0000124
Isabella Gottardid17a6772018-02-27 17:41:55 +0000125/** Supported tensor data layout dimensions */
126enum class DataLayoutDimension
127{
Alex Gildayc357c472018-03-21 13:54:09 +0000128 CHANNEL, /**< channel */
129 HEIGHT, /**< height */
130 WIDTH, /**< width */
131 BATCHES /**< batches */
Isabella Gottardid17a6772018-02-27 17:41:55 +0000132};
133
Georgios Pinitas7900a9e2018-11-23 11:44:58 +0000134/** Available ConvolutionMethod*/
135enum class ConvolutionMethod
136{
Vidhya Sudhan Loganathan8ec0bb62019-04-23 10:40:44 +0100137 GEMM, /**< Convolution using GEMM */
138 DIRECT, /**< Direct convolution */
139 WINOGRAD, /**< Convolution using Winograd */
140 FFT /**< Convolution using FFT */
Georgios Pinitas7900a9e2018-11-23 11:44:58 +0000141};
142
Manuel Bottini05069f02019-09-26 17:18:26 +0100143/** Available DepthwiseConvolutionFunction*/
144enum class DepthwiseConvolutionFunction
145{
146 OPTIMIZED, /**< Optimized Depthwise Convolution */
147 GENERIC, /**< Generic Depthwise Convolution */
148};
149
giuros0146a49a02019-04-01 13:50:22 +0100150/** Available DeconvolutionMethod*/
151enum class DeconvolutionMethod
152{
153 GEMM, /**< Deconvolution using GEMM */
154 DIRECT, /**< Direct deconvolution */
155};
156
Manuel Bottini2732cca2019-05-28 11:44:41 +0100157/** Available FuseBatchNormalizationType*/
158enum class FuseBatchNormalizationType
159{
160 CONVOLUTION, /**< For Convolution weights */
161 DEPTHWISECONVOLUTION /**< For Depthwise Convolution weights*/
162};
163
Usama Arif89890c62019-03-19 10:57:05 +0000164/** Padding mode to use for PadLayer */
165enum class PaddingMode
166{
167 CONSTANT,
168 REFLECT,
169 SYMMETRIC
170};
171
Georgios Pinitas7900a9e2018-11-23 11:44:58 +0000172/** Supported comparison operations */
173enum class ComparisonOperation
174{
175 Equal, /**< Equal comparison ( \f$ x == y \f$ ) */
176 NotEqual, /**< NotEqual comparison ( \f$ x != y \f$ ) */
177 Greater, /**< Greater comparison ( \f$ x > y \f$ ) */
178 GreaterEqual, /**< Greater equal comparison ( \f$ x >= y \f$ ) */
179 Less, /**< Less comparison ( \f$ x < y \f$ ) */
180 LessEqual /**< Less equal comparison ( \f$ x <= y \f$ ) */
181};
182
Alex Gildayc357c472018-03-21 13:54:09 +0000183/** Container for valid region of a window */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100184struct ValidRegion
185{
Alex Gildayc357c472018-03-21 13:54:09 +0000186 /** Default constructor */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100187 ValidRegion()
188 : anchor{}, shape{}
189 {
190 }
191
Alex Gildayc357c472018-03-21 13:54:09 +0000192 /** Allow instances of this class to be copy constructed */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100193 ValidRegion(const ValidRegion &) = default;
Alex Gildayc357c472018-03-21 13:54:09 +0000194 /** Allow instances of this class to be move constructed */
195 ValidRegion(ValidRegion &&) = default;
196 /** Allow instances of this class to be copied */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100197 ValidRegion &operator=(const ValidRegion &) = default;
Alex Gildayc357c472018-03-21 13:54:09 +0000198 /** Allow instances of this class to be moved */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100199 ValidRegion &operator=(ValidRegion &&) = default;
Alex Gildayc357c472018-03-21 13:54:09 +0000200 /** Default destructor */
201 ~ValidRegion() = default;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100202
Alex Gildayc357c472018-03-21 13:54:09 +0000203 /** Constructor for a valid region with default number of dimensions
204 *
205 * @param[in] an_anchor Anchor for the start of the valid region.
206 * @param[in] a_shape Shape of the valid region.
207 *
208 */
Diego Lopez Recasbcbc9702017-12-18 11:28:27 +0000209 ValidRegion(const Coordinates &an_anchor, const TensorShape &a_shape)
210 : anchor{ an_anchor }, shape{ a_shape }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100211 {
Diego Lopez Recasbcbc9702017-12-18 11:28:27 +0000212 anchor.set_num_dimensions(std::max(anchor.num_dimensions(), shape.num_dimensions()));
213 }
214
Alex Gildayc357c472018-03-21 13:54:09 +0000215 /** Constructor for a valid region with specified number of dimensions
216 *
217 * @param[in] an_anchor Anchor for the start of the valid region.
218 * @param[in] a_shape Shape of the valid region.
219 * @param[in] num_dimensions Number of dimensions (must be >= number of dimensions of anchor and shape).
220 *
221 */
Diego Lopez Recasbcbc9702017-12-18 11:28:27 +0000222 ValidRegion(const Coordinates &an_anchor, const TensorShape &a_shape, size_t num_dimensions)
223 : anchor{ an_anchor }, shape{ a_shape }
224 {
225 ARM_COMPUTE_ERROR_ON(num_dimensions < std::max(anchor.num_dimensions(), shape.num_dimensions()));
226 anchor.set_num_dimensions(num_dimensions);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100227 }
228
229 /** Return the start of the valid region for the given dimension @p d */
230 int start(unsigned int d) const
231 {
232 return anchor[d];
233 }
234
235 /** Return the end of the valid region for the given dimension @p d */
236 int end(unsigned int d) const
237 {
238 return anchor[d] + shape[d];
239 }
240
Diego Lopez Recas35ceeb22017-12-04 18:56:10 +0000241 /** Accessor to set the value of anchor and shape for one of the dimensions.
242 *
243 * @param[in] dimension Dimension for which the value is set.
244 * @param[in] start Value to be set in anchor for the dimension.
245 * @param[in] size Value to be set in shape for the dimension.
246 *
247 * @return *this.
248 */
249 ValidRegion &set(size_t dimension, int start, size_t size)
250 {
251 anchor.set(dimension, start);
252 shape.set(dimension, size);
253 return *this;
254 }
255
Alex Gildayc357c472018-03-21 13:54:09 +0000256 Coordinates anchor; /**< Anchor for the start of the valid region. */
257 TensorShape shape; /**< Shape of the valid region. */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100258};
259
260/** Methods available to handle borders */
261enum class BorderMode
262{
263 UNDEFINED, /**< Borders are left undefined */
264 CONSTANT, /**< Pixels outside the image are assumed to have a constant value */
265 REPLICATE /**< Pixels outside the image are assumed to have the same value as the closest image pixel */
266};
267
268/** Container for 2D border size */
269struct BorderSize
270{
271 /** Empty border, i.e. no border */
272 constexpr BorderSize()
273 : top{ 0 }, right{ 0 }, bottom{ 0 }, left{ 0 }
274 {
275 }
276
277 /** Border with equal size around the 2D plane */
Moritz Pflanzer7655a672017-09-23 11:57:33 +0100278 explicit constexpr BorderSize(unsigned int size)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100279 : top{ size }, right{ size }, bottom{ size }, left{ size }
280 {
281 }
282
283 /** Border with same size for top/bottom and left/right */
284 constexpr BorderSize(unsigned int top_bottom, unsigned int left_right)
285 : top{ top_bottom }, right{ left_right }, bottom{ top_bottom }, left{ left_right }
286 {
287 }
288
289 /** Border with different sizes */
290 constexpr BorderSize(unsigned int top, unsigned int right, unsigned int bottom, unsigned int left)
291 : top{ top }, right{ right }, bottom{ bottom }, left{ left }
292 {
293 }
294
295 /** Check if the entire border is zero */
296 constexpr bool empty() const
297 {
298 return top == 0 && right == 0 && bottom == 0 && left == 0;
299 }
300
301 /** Check if the border is the same size on all sides */
302 constexpr bool uniform() const
303 {
304 return top == right && top == bottom && top == left;
305 }
306
Alex Gildayc357c472018-03-21 13:54:09 +0000307 /** Scale this border size.
308 *
309 * @param[in] scale Scale to multiply border size by.
310 *
311 * @return *this.
312 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100313 BorderSize &operator*=(float scale)
314 {
315 top *= scale;
316 right *= scale;
317 bottom *= scale;
318 left *= scale;
319
320 return *this;
321 }
322
Alex Gildayc357c472018-03-21 13:54:09 +0000323 /** Scale a copy of this border size.
324 *
325 * @param[in] scale Scale to multiply border size by.
326 *
327 * @return a scaled copy of this.
328 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100329 BorderSize operator*(float scale)
330 {
331 BorderSize size = *this;
332 size *= scale;
333
334 return size;
335 }
336
Alex Gildayc357c472018-03-21 13:54:09 +0000337 /** Limit this border size.
338 *
339 * @param[in] limit Border size to limit this border size to.
340 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100341 void limit(const BorderSize &limit)
342 {
343 top = std::min(top, limit.top);
344 right = std::min(right, limit.right);
345 bottom = std::min(bottom, limit.bottom);
346 left = std::min(left, limit.left);
347 }
348
Alex Gildayc357c472018-03-21 13:54:09 +0000349 unsigned int top; /**< top of the border */
350 unsigned int right; /**< right of the border */
351 unsigned int bottom; /**< bottom of the border */
352 unsigned int left; /**< left of the border */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100353};
354
Alex Gildayc357c472018-03-21 13:54:09 +0000355/** Container for 2D padding size */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100356using PaddingSize = BorderSize;
357
358/** Policy to handle overflow */
359enum class ConvertPolicy
360{
361 WRAP, /**< Wrap around */
362 SATURATE /**< Saturate */
363};
364
365/** Interpolation method */
366enum class InterpolationPolicy
367{
368 NEAREST_NEIGHBOR, /**< Output values are defined to match the source pixel whose center is nearest to the sample position */
369 BILINEAR, /**< Output values are defined by bilinear interpolation between the pixels */
370 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 */
371};
372
373/** Bilinear Interpolation method used by LKTracker */
374enum class BilinearInterpolation
375{
Alex Gildayc357c472018-03-21 13:54:09 +0000376 BILINEAR_OLD_NEW, /**< Old-new method */
377 BILINEAR_SCHARR /**< Scharr method */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100378};
379
380/** Threshold mode */
381enum class ThresholdType
382{
383 BINARY, /**< Threshold with one value */
384 RANGE /**< Threshold with two values*/
385};
386
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100387/** Termination criteria */
388enum class Termination
389{
Alex Gildayc357c472018-03-21 13:54:09 +0000390 TERM_CRITERIA_EPSILON, /**< Terminate when within epsilon of a threshold */
391 TERM_CRITERIA_ITERATIONS, /**< Terminate after a maximum number of iterations */
392 TERM_CRITERIA_BOTH /**< Terminate on whichever of the other conditions occurs first */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100393};
394
395/** Magnitude calculation type. */
396enum class MagnitudeType
397{
398 L1NORM, /**< L1 normalization type */
399 L2NORM /**< L2 normalization type */
400};
401
402/** Phase calculation type.
403 *
404 * @note When PhaseType == SIGNED, each angle is mapped to the range 0 to 255 inclusive otherwise angles between 0 and 180
405 */
406enum class PhaseType
407{
408 SIGNED, /**< Angle range: [0, 360] */
409 UNSIGNED /**< Angle range: [0, 180] */
410};
411
412/** Keypoint type */
413struct KeyPoint
414{
415 int32_t x{ 0 }; /**< X coordinates */
416 int32_t y{ 0 }; /**< Y coordinates */
417 float strength{ 0.f }; /**< Strength of the point */
418 float scale{ 0.f }; /**< Scale initialized to 0 by the corner detector */
419 float orientation{ 0.f }; /**< Orientation initialized to 0 by the corner detector */
420 int32_t tracking_status{ 0 }; /**< Status initialized to 1 by the corner detector, set to 0 when the point is lost */
421 float error{ 0.f }; /**< Tracking error initialized to 0 by the corner detector */
422};
423
Alex Gildayc357c472018-03-21 13:54:09 +0000424/** Internal key point */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100425using InternalKeypoint = std::tuple<float, float, float>; /* x,y,strength */
426
427/** Rectangle type */
428struct Rectangle
429{
430 uint16_t x; /**< Top-left x coordinate */
431 uint16_t y; /**< Top-left y coordinate */
432 uint16_t width; /**< Width of the rectangle */
433 uint16_t height; /**< Height of the rectangle */
434};
435
436/** Coordinate type */
437struct Coordinates2D
438{
439 int32_t x; /**< X coordinates */
440 int32_t y; /**< Y coordinates */
441};
442
443/** Coordinate type */
444struct Coordinates3D
445{
446 uint32_t x; /**< X coordinates */
447 uint32_t y; /**< Y coordinates */
448 uint32_t z; /**< Z coordinates */
449};
450
Giuseppe Rossinid7647d42018-07-17 18:13:13 +0100451/** Padding information as a pair of unsigned int start/end */
452using PaddingInfo = std::pair<uint32_t, uint32_t>;
453
454/** List of padding information */
455using PaddingList = std::vector<PaddingInfo>;
456
giuros013175fcf2018-11-21 09:59:17 +0000457/** Information to produce a tiled version of a Tensor */
458using Multiples = std::vector<uint32_t>;
459
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100460/** Available channels */
461enum class Channel
462{
463 UNKNOWN, /** Unknown channel format */
464 C0, /**< First channel (used by formats with unknown channel types). */
465 C1, /**< Second channel (used by formats with unknown channel types). */
466 C2, /**< Third channel (used by formats with unknown channel types). */
467 C3, /**< Fourth channel (used by formats with unknown channel types). */
468 R, /**< Red channel. */
469 G, /**< Green channel. */
470 B, /**< Blue channel. */
471 A, /**< Alpha channel. */
472 Y, /**< Luma channel. */
473 U, /**< Cb/U channel. */
474 V /**< Cr/V/Value channel. */
475};
476
477/** Available matrix patterns */
478enum class MatrixPattern
479{
480 BOX, /**< Box pattern matrix. */
481 CROSS, /**< Cross pattern matrix. */
482 DISK, /**< Disk pattern matrix. */
483 OTHER /**< Any other matrix pattern. */
484};
485
486/** Available non linear functions. */
487enum class NonLinearFilterFunction : unsigned
488{
489 MEDIAN = 0, /**< Non linear median filter. */
490 MIN = 1, /**< Non linear erode. */
491 MAX = 2, /**< Non linear dilate. */
492};
493
Georgios Pinitasd9769582017-08-03 10:19:40 +0100494/** Available reduction operations */
495enum class ReductionOperation
496{
Michalis Spyrou7930db42018-11-22 17:36:28 +0000497 ARG_IDX_MAX, /**< Index of the max value */
Manuel Bottinib412fab2018-12-10 17:40:23 +0000498 ARG_IDX_MIN, /**< Index of the min value */
499 MEAN_SUM, /**< Mean of sum */
500 PROD, /**< Product */
501 SUM_SQUARE, /**< Sum of squares */
Usama Arifa4a08ad2019-05-20 12:38:33 +0100502 SUM, /**< Sum */
503 MIN, /**< Min */
Usama Arif28f0dd92019-05-20 13:44:34 +0100504 MAX, /**< Max */
Georgios Pinitasd9769582017-08-03 10:19:40 +0100505};
506
giuros01164a2722018-11-20 18:34:46 +0000507/** Available element-wise operations */
508enum class ArithmeticOperation
509{
510 ADD, /**< (x + y) */
511 SUB, /**< (x - y) */
512 DIV, /**< (x / y) */
513 MIN, /**< Min(x, y) */
514 MAX, /**< Max(x, y) */
515 SQUARED_DIFF, /**< (x - y)^2 */
Usama Arif81e671e2019-05-13 13:33:14 +0100516 POWER, /**< x ^ y */
giuros011e6e1b82019-05-14 16:12:53 +0100517 PRELU, /**< y*x if x < 0, x otherwise */
giuros01164a2722018-11-20 18:34:46 +0000518};
519
Michalis Spyroue9362622018-11-23 17:41:37 +0000520/** Available element wise unary operations */
521enum class ElementWiseUnary
522{
523 RSQRT, /**< Reverse square root */
524 EXP, /**< Exponential */
Usama Ariff6e475c2019-05-10 12:06:28 +0100525 NEG, /**< Negate */
Usama Arifc255aa72019-05-13 16:26:29 +0100526 LOG, /**< Natural Logarithm */
Manuel Bottini6ac59922019-05-15 14:06:02 +0100527 ABS, /**< Absolute value */
Michalis Spyrou0af44182019-05-17 14:04:47 +0100528 SIN, /**< Sine */
Usama Arif0a5a57a2019-05-23 14:20:33 +0100529 ROUND, /**< Round */
Michalis Spyroue9362622018-11-23 17:41:37 +0000530};
531
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100532/** The normalization type used for the normalization layer */
533enum class NormType
534{
535 IN_MAP_1D, /**< Normalization applied within the same map in 1D region */
536 IN_MAP_2D, /**< Normalization applied within the same map in 2D region */
537 CROSS_MAP /**< Normalization applied cross maps */
538};
539
540/** Normalization type for Histogram of Oriented Gradients (HOG) */
541enum class HOGNormType
542{
543 L2_NORM = 1, /**< L2-norm */
544 L2HYS_NORM = 2, /**< L2-norm followed by clipping */
545 L1_NORM = 3 /**< L1 norm */
546};
547
548/** Detection window used for the object detection. The detection window keeps the following information:
549 *
550 * -# Geometry of the rectangular window (x/y of top-left corner and width/height)
551 * -# Index of the class used for evaluating which class the detection window belongs to
552 * -# Confidence value (score) obtained with the classifier
553 */
554struct DetectionWindow
555{
556 uint16_t x{ 0 }; /**< Top-left x coordinate */
557 uint16_t y{ 0 }; /**< Top-left y coordinate */
558 uint16_t width{ 0 }; /**< Width of the detection window */
559 uint16_t height{ 0 }; /**< Height of the detection window */
560 uint16_t idx_class{ 0 }; /**< Index of the class */
561 float score{ 0.f }; /**< Confidence value for the detection window */
562};
563
564/** Dimension rounding type when down-scaling on CNNs
565 * @note Used in pooling and convolution layer
566 */
567enum class DimensionRoundingType
568{
569 FLOOR, /**< Floor rounding */
570 CEIL /**< Ceil rounding */
571};
572
573/** Available pooling types */
574enum class PoolingType
575{
576 MAX, /**< Max Pooling */
Georgios Pinitascdf51452017-08-31 14:21:36 +0100577 AVG, /**< Average Pooling */
578 L2 /**< L2 Pooling */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100579};
580
Michalis Spyrou2709d612018-09-19 09:46:47 +0100581/** Available non maxima suppression types */
582enum class NMSType
583{
584 LINEAR, /**< Linear NMS */
585 GAUSSIAN, /**< Gaussian NMS */
586 ORIGINAL /**< Original NMS */
587};
588
589/** BoxWithNonMaximaSuppressionLimit Information class */
590class BoxNMSLimitInfo final
591{
592public:
593 /** Constructor
594 *
595 * @param[in] score_thresh (Optional) Score threshold.
596 * @param[in] nms (Optional) NMS value
597 * @param[in] detections (Optional) Number of detections
598 * @param[in] soft_nms_enabled (Optional) Enable SoftNMS
599 * @param[in] soft_nms_method (Optional) Soft NMS method
600 * @param[in] soft_nms_sigma (Optional) Soft NMS sigma value
601 * @param[in] soft_nms_min_score_thres (Optional) Soft NMS minimum score threshold
Manuel Bottini5209be52019-02-13 16:34:56 +0000602 * @param[in] suppress_size (Optional) Filter out boxes based on their size. Defaults to false
603 * @param[in] min_size (Optional) Smaller boxes than min_size will be filtered out. Defaults to 1
604 * @param[in] im_width (Optional) Boxes whose centers (on the x axis) is beyond im_width will be filtered. Defaults to 1
605 * @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 +0100606 */
607 BoxNMSLimitInfo(float score_thresh = 0.05f, float nms = 0.3f,
608 int detections = 100, bool soft_nms_enabled = false,
609 NMSType soft_nms_method = NMSType::LINEAR,
Manuel Bottini5209be52019-02-13 16:34:56 +0000610 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 +0100611 : _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 +0000612 _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 +0100613 {
614 }
615 /** Get the score threshold */
616 float score_thresh() const
617 {
618 return _score_thresh;
619 }
620 /** Get the NMS */
621 float nms() const
622 {
623 return _nms;
624 }
625 /** Get the number of detections */
626 int detections_per_im() const
627 {
628 return _detections_per_im;
629 }
630 /** Check if soft NMS is enabled */
631 bool soft_nms_enabled() const
632 {
633 return _soft_nms_enabled;
634 }
635 /** Get soft NMS method */
636 NMSType soft_nms_method() const
637 {
638 return _soft_nms_method;
639 }
640 /** Get soft NMS sigma */
641 float soft_nms_sigma() const
642 {
643 return _soft_nms_sigma;
644 }
645 /** Get soft nms min score threshold */
646 float soft_nms_min_score_thres() const
647 {
648 return _soft_nms_min_score_thres;
649 }
Manuel Bottini5209be52019-02-13 16:34:56 +0000650 /** Get if NMS will suppress boxes based on their size/position */
651 bool suppress_size() const
652 {
653 return _suppress_size;
654 }
655 /** Get size suppression threshold */
656 float min_size() const
657 {
658 return _min_size;
659 }
660 /** Get image width (NMS may suppress boxes whose center sits beyond the image width) */
661 float im_width() const
662 {
663 return _im_width;
664 }
665 /** Get image height (NMS may suppress boxes whose center sits beyond the image height) */
666 float im_height() const
667 {
668 return _im_height;
669 }
Michalis Spyrou2709d612018-09-19 09:46:47 +0100670
671private:
672 float _score_thresh;
673 float _nms;
674 int _detections_per_im;
675 bool _soft_nms_enabled;
676 NMSType _soft_nms_method;
677 float _soft_nms_sigma;
678 float _soft_nms_min_score_thres;
Manuel Bottini5209be52019-02-13 16:34:56 +0000679 bool _suppress_size;
680 float _min_size;
681 float _im_width;
682 float _im_height;
Michalis Spyrou2709d612018-09-19 09:46:47 +0100683};
684
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100685/** Padding and stride information class */
686class PadStrideInfo
687{
688public:
689 /** Constructor
690 *
691 * @param[in] stride_x (Optional) Stride, in elements, across x. Defaults to 1.
692 * @param[in] stride_y (Optional) Stride, in elements, across y. Defaults to 1.
693 * @param[in] pad_x (Optional) Padding, in elements, across x. Defaults to 0.
694 * @param[in] pad_y (Optional) Padding, in elements, across y. Defaults to 0.
695 * @param[in] round (Optional) Dimensions rounding. Defaults to @ref FLOOR.
696 */
697 PadStrideInfo(unsigned int stride_x = 1, unsigned int stride_y = 1,
698 unsigned int pad_x = 0, unsigned int pad_y = 0,
699 DimensionRoundingType round = DimensionRoundingType::FLOOR)
700 : _stride(std::make_pair(stride_x, stride_y)),
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100701 _pad_left(pad_x),
702 _pad_top(pad_y),
703 _pad_right(pad_x),
704 _pad_bottom(pad_y),
705 _round_type(round)
706 {
707 }
708 /** Constructor
709 *
710 * @param[in] stride_x Stride, in elements, across x.
711 * @param[in] stride_y Stride, in elements, across y.
712 * @param[in] pad_left Padding across x on the left, in elements.
713 * @param[in] pad_top Padding across y on the top, in elements.
714 * @param[in] pad_right Padding across x on the right, in elements.
715 * @param[in] pad_bottom Padding across y on the bottom, in elements.
716 * @param[in] round Dimensions rounding.
717 */
718 PadStrideInfo(unsigned int stride_x, unsigned int stride_y,
719 unsigned int pad_left, unsigned int pad_right,
720 unsigned int pad_top, unsigned int pad_bottom,
721 DimensionRoundingType round)
722 : _stride(std::make_pair(stride_x, stride_y)),
723 _pad_left(pad_left),
724 _pad_top(pad_top),
725 _pad_right(pad_right),
726 _pad_bottom(pad_bottom),
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100727 _round_type(round)
728 {
729 }
Alex Gildayc357c472018-03-21 13:54:09 +0000730 /** Get the stride.
731 *
732 * @return a pair: stride x, stride y.
733 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100734 std::pair<unsigned int, unsigned int> stride() const
735 {
736 return _stride;
737 }
Alex Gildayc357c472018-03-21 13:54:09 +0000738 /** Check whether the padding is symmetric.
739 *
740 * @return True if the padding is symmetric.
741 */
Anthony Barbier21f67d62018-02-16 15:17:48 +0000742 bool padding_is_symmetric() const
743 {
744 return (_pad_left == _pad_right) && (_pad_top == _pad_bottom);
745 }
Alex Gildayc357c472018-03-21 13:54:09 +0000746 /** Get the padding.
747 *
748 * @note This should only be used when the padding is symmetric.
749 *
750 * @return a pair: padding left/right, padding top/bottom
751 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100752 std::pair<unsigned int, unsigned int> pad() const
753 {
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100754 //this accessor should be used only when padding is symmetric
Anthony Barbier21f67d62018-02-16 15:17:48 +0000755 ARM_COMPUTE_ERROR_ON(!padding_is_symmetric());
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100756 return std::make_pair(_pad_left, _pad_top);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100757 }
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100758
Alex Gildayc357c472018-03-21 13:54:09 +0000759 /** Get the left padding */
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100760 unsigned int pad_left() const
761 {
762 return _pad_left;
763 }
Alex Gildayc357c472018-03-21 13:54:09 +0000764 /** Get the right padding */
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100765 unsigned int pad_right() const
766 {
767 return _pad_right;
768 }
Alex Gildayc357c472018-03-21 13:54:09 +0000769 /** Get the top padding */
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100770 unsigned int pad_top() const
771 {
772 return _pad_top;
773 }
Alex Gildayc357c472018-03-21 13:54:09 +0000774 /** Get the bottom padding */
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100775 unsigned int pad_bottom() const
776 {
777 return _pad_bottom;
778 }
779
Alex Gildayc357c472018-03-21 13:54:09 +0000780 /** Get the rounding type */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100781 DimensionRoundingType round() const
782 {
783 return _round_type;
784 }
785
Alex Gildayc357c472018-03-21 13:54:09 +0000786 /** Check whether this has any padding */
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100787 bool has_padding() const
788 {
789 return (_pad_left != 0 || _pad_top != 0 || _pad_right != 0 || _pad_bottom != 0);
790 }
791
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100792private:
793 std::pair<unsigned int, unsigned int> _stride;
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100794 unsigned int _pad_left;
795 unsigned int _pad_top;
796 unsigned int _pad_right;
797 unsigned int _pad_bottom;
798
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100799 DimensionRoundingType _round_type;
800};
801
Georgios Pinitas7d66a8e2018-07-17 12:28:42 +0100802/** Fully connected layer info */
803struct FullyConnectedLayerInfo
804{
805 DataLayout weights_trained_layout{ DataLayout::NCHW }; /**< Layout that the weights have been trained with. */
806 bool transpose_weights{ true }; /**< Transpose weights if true. */
807 bool are_weights_reshaped{ false }; /**< Reshape the weights tensor if false. */
808 bool retain_internal_weights{ false }; /**< Retain internal reshaped weights. */
Georgios Pinitas44bfc3f2019-10-28 14:16:31 +0000809 bool fp_mixed_precision{ false }; /**< Use wider accumulators (32 bit instead of 16 for FP16) to improve accuracy. */
Georgios Pinitasc55cef12018-08-01 15:24:18 +0100810
811 /** Sets the weights trained data layout
812 *
813 * @param[in] layout Data layout that the weights were trained with
814 *
815 * @return Updated object
816 */
817 FullyConnectedLayerInfo &set_weights_trained_layout(DataLayout layout)
818 {
819 weights_trained_layout = layout;
820 return *this;
821 }
Georgios Pinitas195b0ba2018-08-02 17:18:51 +0100822 /** Sets the transpose weights flag
823 *
824 * @param[in] should_transpose_weights Boolean flag indicating if weights should be transposed
825 *
826 * @return Updated object
827 */
828 FullyConnectedLayerInfo &set_transpose_weights(bool should_transpose_weights)
829 {
830 transpose_weights = should_transpose_weights;
831 return *this;
832 }
Georgios Pinitas7d66a8e2018-07-17 12:28:42 +0100833};
834
Michalis Spyrou6c7c38e2018-08-29 16:28:11 +0100835/** PriorBox layer info */
836class PriorBoxLayerInfo final
837{
838public:
839 /** Default Constructor */
840 PriorBoxLayerInfo()
841 : _min_sizes(),
842 _variances(),
843 _offset(),
844 _flip(true),
845 _clip(false),
846 _max_sizes(),
847 _aspect_ratios(),
848 _img_size(),
849 _steps()
850 {
851 }
852 /** Constructor
853 *
854 * @param[in] min_sizes Min sizes vector.
Michalis Spyrou721c4cb2018-09-04 15:27:25 +0100855 * @param[in] variances Variances vector.
Michalis Spyrou6c7c38e2018-08-29 16:28:11 +0100856 * @param[in] offset Offset value.
857 * @param[in] flip (Optional) Flip the aspect ratios.
858 * @param[in] clip (Optional) Clip coordinates so that they're within [0,1].
859 * @param[in] max_sizes (Optional) Max sizes vector.
860 * @param[in] aspect_ratios (Optional) Aspect ratios of the boxes.
861 * @param[in] img_size (Optional) Image size.
862 * @param[in] steps (Optional) Step values.
863 */
864 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 +0000865 const std::vector<float> &max_sizes = {}, const std::vector<float> &aspect_ratios = {},
866 const Coordinates2D &img_size = Coordinates2D{ 0, 0 }, const std::array<float, 2> &steps = { { 0.f, 0.f } })
Michalis Spyrou6c7c38e2018-08-29 16:28:11 +0100867 : _min_sizes(min_sizes),
868 _variances(variances),
869 _offset(offset),
870 _flip(flip),
871 _clip(clip),
872 _max_sizes(max_sizes),
Michalis Spyrou721c4cb2018-09-04 15:27:25 +0100873 _aspect_ratios(),
Michalis Spyrou6c7c38e2018-08-29 16:28:11 +0100874 _img_size(img_size),
875 _steps(steps)
876 {
877 _aspect_ratios.push_back(1.);
878 for(unsigned int i = 0; i < aspect_ratios.size(); ++i)
879 {
880 float ar = aspect_ratios[i];
881 bool already_exist = false;
882 for(auto ar_new : _aspect_ratios)
883 {
884 if(fabs(ar - ar_new) < 1e-6)
885 {
886 already_exist = true;
887 break;
888 }
889 }
890 if(!already_exist)
891 {
892 _aspect_ratios.push_back(ar);
893 if(flip)
894 {
895 _aspect_ratios.push_back(1.f / ar);
896 }
897 }
898 }
899 }
900 /** Get min sizes. */
901 std::vector<float> min_sizes() const
902 {
903 return _min_sizes;
904 }
905 /** Get min variances. */
906 std::vector<float> variances() const
907 {
908 return _variances;
909 }
910 /** Get the step coordinates */
911 std::array<float, 2> steps() const
912 {
913 return _steps;
914 }
915 /** Get the image size coordinates */
916 Coordinates2D img_size() const
917 {
918 return _img_size;
919 }
920 /** Get the offset */
921 float offset() const
922 {
923 return _offset;
924 }
925 /** Get the flip value */
926 bool flip() const
927 {
928 return _flip;
929 }
930 /** Get the clip value */
931 bool clip() const
932 {
933 return _clip;
934 }
935 /** Get max sizes. */
936 std::vector<float> max_sizes() const
937 {
938 return _max_sizes;
939 }
940 /** Get aspect ratios. */
941 std::vector<float> aspect_ratios() const
942 {
943 return _aspect_ratios;
944 }
945
946private:
947 std::vector<float> _min_sizes;
948 std::vector<float> _variances;
949 float _offset;
950 bool _flip;
951 bool _clip;
952 std::vector<float> _max_sizes;
953 std::vector<float> _aspect_ratios;
954 Coordinates2D _img_size;
955 std::array<float, 2> _steps;
956};
957
Isabella Gottardia7acb3c2019-01-08 13:48:44 +0000958// Bounding Box [xmin, ymin, xmax, ymax]
959using BBox = std::array<float, 4>;
960// LabelBBox used for map label and bounding box
961using LabelBBox = std::map<int, std::vector<BBox>>;
962
Isabella Gottardi05e56442018-11-16 11:26:52 +0000963/** Available Detection Output code types */
964enum class DetectionOutputLayerCodeType
965{
966 CORNER, /**< Use box corners */
967 CENTER_SIZE, /**< Use box centers and size */
968 CORNER_SIZE, /**< Use box centers and size */
969 TF_CENTER /**< Use box centers and size but flip x and y co-ordinates */
970};
971
972/** Detection Output layer info */
973class DetectionOutputLayerInfo final
974{
975public:
976 /** Default Constructor */
977 DetectionOutputLayerInfo()
978 : _num_classes(),
979 _share_location(),
980 _code_type(DetectionOutputLayerCodeType::CORNER),
981 _keep_top_k(),
982 _nms_threshold(),
983 _top_k(),
984 _background_label_id(),
985 _confidence_threshold(),
986 _variance_encoded_in_target(false),
987 _eta(),
988 _num_loc_classes()
989 {
990 _num_loc_classes = _share_location ? 1 : _num_classes;
991 }
992 /** Constructor
993 *
994 * @param[in] num_classes Number of classes to be predicted.
995 * @param[in] share_location If true, bounding box are shared among different classes.
996 * @param[in] code_type Type of coding method for bbox.
997 * @param[in] keep_top_k Number of total bounding boxes to be kept per image after NMS step.
998 * @param[in] nms_threshold Threshold to be used in NMS.
999 * @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.
1000 * @param[in] background_label_id (Optional) Background label ID. If there is no background class, set it as -1.
1001 * @param[in] confidence_threshold (Optional) Only consider detections whose confidences are larger than a threshold. Default set to -FLT_MAX.
1002 * @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.
1003 * @param[in] eta (Optional) Eta.
1004 */
1005 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,
1006 float confidence_threshold = std::numeric_limits<float>::lowest(), bool variance_encoded_in_target = false, float eta = 1)
1007 : _num_classes(num_classes),
1008 _share_location(share_location),
1009 _code_type(code_type),
1010 _keep_top_k(keep_top_k),
1011 _nms_threshold(nms_threshold),
1012 _top_k(top_k),
1013 _background_label_id(background_label_id),
1014 _confidence_threshold(confidence_threshold),
1015 _variance_encoded_in_target(variance_encoded_in_target),
1016 _eta(eta),
1017 _num_loc_classes()
1018 {
1019 _num_loc_classes = _share_location ? 1 : _num_classes;
1020 }
1021 /** Get num classes. */
1022 int num_classes() const
1023 {
1024 return _num_classes;
1025 }
1026 /** Get share location. */
1027 bool share_location() const
1028 {
1029 return _share_location;
1030 }
1031 /** Get detection output code type. */
1032 DetectionOutputLayerCodeType code_type() const
1033 {
1034 return _code_type;
1035 }
1036 /** Get if variance encoded in target. */
1037 bool variance_encoded_in_target() const
1038 {
1039 return _variance_encoded_in_target;
1040 }
1041 /** Get the number of total bounding boxes to be kept per image. */
1042 int keep_top_k() const
1043 {
1044 return _keep_top_k;
1045 }
1046 /** Get nms threshold. */
1047 float nms_threshold() const
1048 {
1049 return _nms_threshold;
1050 }
1051 /** Get eta. */
1052 float eta() const
1053 {
1054 return _eta;
1055 }
1056 /** Get background label ID. */
1057 int background_label_id() const
1058 {
1059 return _background_label_id;
1060 }
1061 /** Get confidence threshold. */
1062 float confidence_threshold() const
1063 {
1064 return _confidence_threshold;
1065 }
1066 /** Get top K. */
1067 int top_k() const
1068 {
1069 return _top_k;
1070 }
1071 /** Get number of location classes. */
1072 int num_loc_classes() const
1073 {
1074 return _num_loc_classes;
1075 }
1076
1077private:
1078 int _num_classes;
1079 bool _share_location;
1080 DetectionOutputLayerCodeType _code_type;
1081 int _keep_top_k;
1082 float _nms_threshold;
1083 int _top_k;
1084 int _background_label_id;
1085 float _confidence_threshold;
1086 bool _variance_encoded_in_target;
1087 float _eta;
1088 int _num_loc_classes;
1089};
1090
Isabella Gottardia7acb3c2019-01-08 13:48:44 +00001091/** Detection Output layer info */
1092class DetectionPostProcessLayerInfo final
1093{
1094public:
1095 /** Default Constructor */
1096 DetectionPostProcessLayerInfo()
1097 : _max_detections(),
1098 _max_classes_per_detection(),
1099 _nms_score_threshold(),
1100 _iou_threshold(),
1101 _num_classes(),
1102 _scales_values(),
1103 _use_regular_nms(),
Giuseppe Rossinid9853782019-10-25 11:11:44 +01001104 _detection_per_class(),
1105 _dequantize_scores()
Isabella Gottardia7acb3c2019-01-08 13:48:44 +00001106 {
1107 }
1108 /** Constructor
1109 *
1110 * @param[in] max_detections Number of total detection.
1111 * @param[in] max_classes_per_detection Number of total classes to be kept after NMS step. Used in the Fast Non-Max-Suppression
1112 * @param[in] nms_score_threshold Threshold to be used in NMS
1113 * @param[in] iou_threshold Threshold to be used during the intersection over union.
1114 * @param[in] num_classes Number of classes.
1115 * @param[in] scales_values Scales values used for decode center size boxes.
Giuseppe Rossinid9853782019-10-25 11:11:44 +01001116 * @param[in] use_regular_nms (Optional) Boolean to determinate if use regular or fast nms. Defaults to false.
1117 * @param[in] detection_per_class (Optional) Number of detection per class. Used in the Regular Non-Max-Suppression. Defaults to 100.
1118 * @param[in] dequantize_scores (Optional) If the scores need to be dequantized. Defaults to true.
Isabella Gottardia7acb3c2019-01-08 13:48:44 +00001119 */
1120 DetectionPostProcessLayerInfo(unsigned int max_detections, unsigned int max_classes_per_detection, float nms_score_threshold, float iou_threshold, unsigned int num_classes,
Giuseppe Rossinid9853782019-10-25 11:11:44 +01001121 std::array<float, 4> scales_values, bool use_regular_nms = false, unsigned int detection_per_class = 100, bool dequantize_scores = true)
Isabella Gottardia7acb3c2019-01-08 13:48:44 +00001122 : _max_detections(max_detections),
1123 _max_classes_per_detection(max_classes_per_detection),
1124 _nms_score_threshold(nms_score_threshold),
1125 _iou_threshold(iou_threshold),
1126 _num_classes(num_classes),
1127 _scales_values(scales_values),
1128 _use_regular_nms(use_regular_nms),
Giuseppe Rossinid9853782019-10-25 11:11:44 +01001129 _detection_per_class(detection_per_class),
1130 _dequantize_scores(dequantize_scores)
Isabella Gottardia7acb3c2019-01-08 13:48:44 +00001131 {
1132 }
1133 /** Get max detections. */
1134 unsigned int max_detections() const
1135 {
1136 return _max_detections;
1137 }
1138 /** Get max_classes per detection. Used in the Fast Non-Max-Suppression.*/
1139 unsigned int max_classes_per_detection() const
1140 {
1141 return _max_classes_per_detection;
1142 }
1143 /** Get detection per class. Used in the Regular Non-Max-Suppression */
1144 unsigned int detection_per_class() const
1145 {
1146 return _detection_per_class;
1147 }
1148 /** Get nms threshold. */
1149 float nms_score_threshold() const
1150 {
1151 return _nms_score_threshold;
1152 }
1153 /** Get intersection over union threshold. */
1154 float iou_threshold() const
1155 {
1156 return _iou_threshold;
1157 }
1158 /** Get num classes. */
1159 unsigned int num_classes() const
1160 {
1161 return _num_classes;
1162 }
1163 /** Get if use regular nms. */
1164 bool use_regular_nms() const
1165 {
1166 return _use_regular_nms;
1167 }
1168 /** Get y scale value. */
1169 float scale_value_y() const
1170 {
1171 // Saved as [y,x,h,w]
1172 return _scales_values[0];
1173 }
1174 /** Get x scale value. */
1175 float scale_value_x() const
1176 {
1177 // Saved as [y,x,h,w]
1178 return _scales_values[1];
1179 }
1180 /** Get h scale value. */
1181 float scale_value_h() const
1182 {
1183 // Saved as [y,x,h,w]
1184 return _scales_values[2];
1185 }
1186 /** Get w scale value. */
1187 float scale_value_w() const
1188 {
1189 // Saved as [y,x,h,w]
1190 return _scales_values[3];
1191 }
Giuseppe Rossinid9853782019-10-25 11:11:44 +01001192 /** Get dequantize_scores value. */
1193 bool dequantize_scores() const
1194 {
1195 return _dequantize_scores;
1196 }
Isabella Gottardia7acb3c2019-01-08 13:48:44 +00001197
1198private:
1199 unsigned int _max_detections;
1200 unsigned int _max_classes_per_detection;
1201 float _nms_score_threshold;
1202 float _iou_threshold;
1203 unsigned int _num_classes;
1204 std::array<float, 4> _scales_values;
1205 bool _use_regular_nms;
1206 unsigned int _detection_per_class;
Giuseppe Rossinid9853782019-10-25 11:11:44 +01001207 bool _dequantize_scores;
Isabella Gottardia7acb3c2019-01-08 13:48:44 +00001208};
1209
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001210/** Pooling Layer Information class */
1211class PoolingLayerInfo
1212{
1213public:
Georgios Pinitas4c2dd542017-11-13 12:58:41 +00001214 /** Default Constructor */
1215 PoolingLayerInfo()
Sang-Hoon Park2aa7fd02019-09-18 13:39:00 +01001216 : _pool_type(PoolingType::MAX), _pool_size(Size2D()), _pad_stride_info(PadStrideInfo()), _exclude_padding(false), _is_global_pooling(false), _fp_mixed_precision(false)
Georgios Pinitas4c2dd542017-11-13 12:58:41 +00001217 {
1218 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001219 /** Default Constructor
1220 *
Sang-Hoon Park2aa7fd02019-09-18 13:39:00 +01001221 * @param[in] pool_type Pooling type @ref PoolingType.
1222 * @param[in] pool_size Pooling size, in elements, across x and y.
1223 * @param[in] pad_stride_info (Optional) Padding and stride information @ref PadStrideInfo
1224 * @param[in] exclude_padding (Optional) Strategy when accounting padding in calculations.
1225 * True will exclude padding while false will not (Used in AVG/L2 pooling to determine the pooling area).
1226 * Defaults to false;
1227 * @param[in] fp_mixed_precision (Optional) Use wider accumulators (32 bit instead of 16 for FP16) to improve accuracy.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001228 */
Georgios Pinitas4c2dd542017-11-13 12:58:41 +00001229 explicit PoolingLayerInfo(PoolingType pool_type,
1230 unsigned int pool_size,
Sang-Hoon Park2aa7fd02019-09-18 13:39:00 +01001231 PadStrideInfo pad_stride_info = PadStrideInfo(),
1232 bool exclude_padding = false,
1233 bool fp_mixed_precision = false)
1234 : _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),
1235 _fp_mixed_precision(fp_mixed_precision)
Isabella Gottardi6e464c32018-01-26 12:32:45 +00001236 {
1237 }
1238 /** Default Constructor
1239 *
Sang-Hoon Park2aa7fd02019-09-18 13:39:00 +01001240 * @param[in] pool_type Pooling type @ref PoolingType.
1241 * @param[in] pool_size Pooling size, in elements, across x and y.
1242 * @param[in] pad_stride_info (Optional) Padding and stride information @ref PadStrideInfo
1243 * @param[in] exclude_padding (Optional) Strategy when accounting padding in calculations.
1244 * True will exclude padding while false will not (Used in AVG/L2 pooling to determine the pooling area).
1245 * Defaults to false;
1246 * @param[in] fp_mixed_precision (Optional) Use wider accumulators (32 bit instead of 16 for FP16) to improve accuracy.
Isabella Gottardi6e464c32018-01-26 12:32:45 +00001247 */
1248 explicit PoolingLayerInfo(PoolingType pool_type,
1249 Size2D pool_size,
Sang-Hoon Park2aa7fd02019-09-18 13:39:00 +01001250 PadStrideInfo pad_stride_info = PadStrideInfo(),
1251 bool exclude_padding = false,
1252 bool fp_mixed_precision = false)
1253 : _pool_type(pool_type), _pool_size(pool_size), _pad_stride_info(pad_stride_info), _exclude_padding(exclude_padding), _is_global_pooling(false), _fp_mixed_precision(fp_mixed_precision)
Georgios Pinitas4c2dd542017-11-13 12:58:41 +00001254 {
1255 }
1256 /** Default Constructor
1257 *
1258 * @note This constructor is used for global pooling
1259 *
1260 * @param[in] pool_type Pooling type @ref PoolingType.
1261 */
1262 explicit PoolingLayerInfo(PoolingType pool_type)
Sang-Hoon Park2aa7fd02019-09-18 13:39:00 +01001263 : _pool_type(pool_type), _pool_size(Size2D()), _pad_stride_info(PadStrideInfo(1, 1, 0, 0)), _exclude_padding(false), _is_global_pooling(true), _fp_mixed_precision(false)
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001264 {
1265 }
Alex Gildayc357c472018-03-21 13:54:09 +00001266 /** Get the pooling type */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001267 PoolingType pool_type() const
1268 {
1269 return _pool_type;
1270 }
Alex Gildayc357c472018-03-21 13:54:09 +00001271 /** Get the pooling size */
Isabella Gottardi6e464c32018-01-26 12:32:45 +00001272 const Size2D &pool_size() const
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001273 {
1274 return _pool_size;
1275 }
Alex Gildayc357c472018-03-21 13:54:09 +00001276 /** Get the padding and stride */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001277 PadStrideInfo pad_stride_info() const
1278 {
1279 return _pad_stride_info;
1280 }
Alex Gildayc357c472018-03-21 13:54:09 +00001281 /** Check if padding is excluded in calculations */
Georgios Pinitasadaae7e2017-10-30 15:56:32 +00001282 bool exclude_padding() const
1283 {
1284 return _exclude_padding;
1285 }
Sang-Hoon Park2aa7fd02019-09-18 13:39:00 +01001286 /** Check if a wider accumulator should be used. */
1287 bool fp_mixed_precision() const
1288 {
1289 return _fp_mixed_precision;
1290 }
Alex Gildayc357c472018-03-21 13:54:09 +00001291 /** Check if is global pooling */
Georgios Pinitas4c2dd542017-11-13 12:58:41 +00001292 bool is_global_pooling() const
1293 {
1294 return _is_global_pooling;
1295 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001296
1297private:
1298 PoolingType _pool_type;
Isabella Gottardi6e464c32018-01-26 12:32:45 +00001299 Size2D _pool_size;
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001300 PadStrideInfo _pad_stride_info;
Georgios Pinitasadaae7e2017-10-30 15:56:32 +00001301 bool _exclude_padding;
Georgios Pinitas4c2dd542017-11-13 12:58:41 +00001302 bool _is_global_pooling;
Sang-Hoon Park2aa7fd02019-09-18 13:39:00 +01001303 bool _fp_mixed_precision;
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001304};
1305
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001306/** ROI Pooling Layer Information class */
giuros0118870812018-09-13 09:31:40 +01001307class ROIPoolingLayerInfo final
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001308{
1309public:
giuros0118870812018-09-13 09:31:40 +01001310 /** Constructor
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001311 *
giuros0118870812018-09-13 09:31:40 +01001312 * @param[in] pooled_width Pooled width of the layer.
1313 * @param[in] pooled_height Pooled height of the layer.
1314 * @param[in] spatial_scale Spatial scale to be applied to the ROI coordinates and dimensions.
1315 * @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 +01001316 */
giuros0118870812018-09-13 09:31:40 +01001317 ROIPoolingLayerInfo(unsigned int pooled_width, unsigned int pooled_height, float spatial_scale, unsigned int sampling_ratio = 0)
1318 : _pooled_width(pooled_width), _pooled_height(pooled_height), _spatial_scale(spatial_scale), _sampling_ratio(sampling_ratio)
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001319 {
1320 }
Alex Gildayc357c472018-03-21 13:54:09 +00001321 /** Get the pooled width of the layer */
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001322 unsigned int pooled_width() const
1323 {
1324 return _pooled_width;
1325 }
Alex Gildayc357c472018-03-21 13:54:09 +00001326 /** Get the pooled height of the layer */
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001327 unsigned int pooled_height() const
1328 {
1329 return _pooled_height;
1330 }
Alex Gildayc357c472018-03-21 13:54:09 +00001331 /** Get the spatial scale */
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001332 float spatial_scale() const
1333 {
1334 return _spatial_scale;
1335 }
giuros0118870812018-09-13 09:31:40 +01001336 /** Get sampling ratio */
1337 unsigned int sampling_ratio() const
1338 {
1339 return _sampling_ratio;
1340 }
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001341
1342private:
1343 unsigned int _pooled_width;
1344 unsigned int _pooled_height;
1345 float _spatial_scale;
giuros0118870812018-09-13 09:31:40 +01001346 unsigned int _sampling_ratio;
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001347};
1348
Manuel Bottini5209be52019-02-13 16:34:56 +00001349/** Generate Proposals Information class */
1350class GenerateProposalsInfo
1351{
1352public:
1353 /** Constructor
1354 *
1355 * @param[in] im_width Width of the original image
1356 * @param[in] im_height Height of the original image
1357 * @param[in] im_scale Scale applied to the original image
1358 * @param[in] spatial_scale (Optional)Scale applied to the feature map. Defaults to 1.0
1359 * @param[in] pre_nms_topN (Optional)Number of the best scores to be selected from the transformations. Defaults to 6000.
1360 * @param[in] post_nms_topN (Optional)Number of the best scores to be selected from the NMS operation. Defaults to 300.
1361 * @param[in] nms_thres (Optional)NMS overlap threshold. Defaults to 0.7.
1362 * @param[in] min_size (Optional)Size used to validate the anchors produced. Defaults to 16.
1363 * @param[in] values_per_roi (Optional)Values used to represent a ROI(Region of interest). Defaults to 4.
1364 */
1365 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,
1366 size_t values_per_roi = 4)
1367 : _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),
1368 _min_size(min_size), _values_per_roi(values_per_roi)
1369 {
1370 }
1371
1372 /* Get the original height */
1373 float im_height() const
1374 {
1375 return _im_height;
1376 }
1377 /* Get the original width */
1378 float im_width() const
1379 {
1380 return _im_width;
1381 }
1382 /* Get the image scale */
1383 float im_scale() const
1384 {
1385 return _im_scale;
1386 }
1387 /* Get the value of how many best scores to select (before NMS) */
1388 int pre_nms_topN() const
1389 {
1390 return _pre_nms_topN;
1391 }
1392 /* Get the value of how many best scores to select (after NMS) */
1393 int post_nms_topN() const
1394 {
1395 return _post_nms_topN;
1396 }
1397 /* Get the NMS overlap threshold */
1398 float nms_thres() const
1399 {
1400 return _nms_thres;
1401 }
1402 /* Get the minimal size */
1403 float min_size() const
1404 {
1405 return _min_size;
1406 }
1407 /* Get the spatial scale to be applied to the feature maps */
1408 float spatial_scale() const
1409 {
1410 return _spatial_scale;
1411 }
1412 /* Get the values used to represent a ROI(Region of interest)*/
1413 size_t values_per_roi() const
1414 {
1415 return _values_per_roi;
1416 }
1417
1418private:
1419 float _im_height;
1420 float _im_width;
1421 float _im_scale;
1422 float _spatial_scale;
1423 int _pre_nms_topN;
1424 int _post_nms_topN;
1425 float _nms_thres;
1426 float _min_size;
1427 size_t _values_per_roi;
1428};
1429
1430/** ComputeAnchors information class */
1431class ComputeAnchorsInfo
1432{
1433public:
1434 /** Constructor
1435 *
1436 * @param[in] feat_width Feature map width
1437 * @param[in] feat_height Feature map height
1438 * @param[in] spatial_scale Feature map scale
1439 * @param[in] values_per_roi (Optional)Values used to represent a ROI(Region Of Interest). Defaults to 4
1440 */
1441 ComputeAnchorsInfo(float feat_width, float feat_height, float spatial_scale, size_t values_per_roi = 4)
1442 : _feat_height(feat_height),
1443 _feat_width(feat_width),
1444 _spatial_scale(spatial_scale),
1445 _values_per_roi(values_per_roi)
1446 {
1447 }
1448
1449 /* Get the height of the feature map */
1450 float feat_height() const
1451 {
1452 return _feat_height;
1453 }
1454
1455 /* Get the width of the feature map */
1456 float feat_width() const
1457 {
1458 return _feat_width;
1459 }
1460
1461 /* Get the scale of the feature map */
1462 float spatial_scale() const
1463 {
1464 return _spatial_scale;
1465 }
1466
1467 /* Get the values used to represent a ROI(Region Of Interest)*/
1468 size_t values_per_roi() const
1469 {
1470 return _values_per_roi;
1471 }
1472
1473private:
1474 float _feat_height;
1475 float _feat_width;
1476 float _spatial_scale;
1477 size_t _values_per_roi;
1478};
1479
giuros01c04a0e82018-10-03 12:44:35 +01001480/** Bounding Box Transform information class */
giuros01d696cb62018-11-16 10:39:59 +00001481class BoundingBoxTransformInfo final
giuros01c04a0e82018-10-03 12:44:35 +01001482{
1483public:
1484 /** Constructor
1485 *
giuros01d696cb62018-11-16 10:39:59 +00001486 * @param[in] img_width Width of the original image
1487 * @param[in] img_height Height, of the original image
1488 * @param[in] scale Scale of the original image
1489 * @param[in] apply_scale (Optional)Re-apply scaling after transforming the boxes. Defaults to false
1490 * @param[in] weights (Optional)Weights [wx, wy, ww, wh] for the deltas. Defaults to all ones
1491 * @param[in] correct_transform_coords (Optional)Correct bounding box transform coordinates. Defaults to false
1492 * @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 +01001493 */
giuros01d696cb62018-11-16 10:39:59 +00001494 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 =
1495 false,
1496 float bbox_xform_clip =
1497 4.135166556742356f)
1498 : _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 +01001499 {
1500 }
1501
1502 std::array<float, 4> weights() const
1503 {
1504 return _weights;
1505 }
1506
1507 float bbox_xform_clip() const
1508 {
1509 return _bbox_xform_clip;
1510 }
1511
1512 float img_height() const
1513 {
1514 return _img_height;
1515 }
1516
1517 float img_width() const
1518 {
1519 return _img_width;
1520 }
1521
1522 float scale() const
1523 {
1524 return _scale;
1525 }
1526
1527 bool apply_scale() const
1528 {
1529 return _apply_scale;
1530 }
1531
giuros01d696cb62018-11-16 10:39:59 +00001532 bool correct_transform_coords() const
1533 {
1534 return _correct_transform_coords;
1535 }
1536
giuros01c04a0e82018-10-03 12:44:35 +01001537private:
1538 float _img_width;
1539 float _img_height;
1540 float _scale;
1541 bool _apply_scale;
giuros01d696cb62018-11-16 10:39:59 +00001542 bool _correct_transform_coords;
giuros01c04a0e82018-10-03 12:44:35 +01001543 std::array<float, 4> _weights;
1544 float _bbox_xform_clip;
1545};
1546
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001547/** Activation Layer Information class */
1548class ActivationLayerInfo
1549{
1550public:
1551 /** Available activation functions */
1552 enum class ActivationFunction
1553 {
Georgios Pinitas64ebe5b2017-09-01 17:44:24 +01001554 LOGISTIC, /**< Logistic ( \f$ f(x) = \frac{1}{1 + e^{-x}} \f$ ) */
1555 TANH, /**< Hyperbolic tangent ( \f$ f(x) = a \cdot tanh(b \cdot x) \f$ ) */
1556 RELU, /**< Rectifier ( \f$ f(x) = max(0,x) \f$ ) */
1557 BOUNDED_RELU, /**< Upper Bounded Rectifier ( \f$ f(x) = min(a, max(0,x)) \f$ ) */
1558 LU_BOUNDED_RELU, /**< Lower and Upper Bounded Rectifier ( \f$ f(x) = min(a, max(b,x)) \f$ ) */
Manuel Bottini581c8982019-02-07 10:31:57 +00001559 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 +01001560 SOFT_RELU, /**< Soft Rectifier ( \f$ f(x)= log(1+e^x) \f$ ) */
Georgios Pinitasfb0fdcd2019-08-22 17:10:04 +01001561 ELU, /**< Exponential Linear Unit ( \f$ f(x) = \begin{cases} \alpha (exp(x) - 1) & \quad \text{if } x \text{ < 0}\\ x & \quad \text{if } x \geq \text{ 0 } \end{cases} \f$ ) */
Georgios Pinitas64ebe5b2017-09-01 17:44:24 +01001562 ABS, /**< Absolute ( \f$ f(x)= |x| \f$ ) */
1563 SQUARE, /**< Square ( \f$ f(x)= x^2 \f$ )*/
1564 SQRT, /**< Square root ( \f$ f(x) = \sqrt{x} \f$ )*/
Usama Arif6a98a6e2019-05-10 17:07:27 +01001565 LINEAR, /**< Linear ( \f$ f(x)= ax + b \f$ ) */
1566 IDENTITY /**< Identity ( \f$ f(x)= x \f$ ) */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001567 };
1568
Giorgio Arena11674872018-02-07 15:38:12 +00001569 ActivationLayerInfo() = default;
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001570 /** Default Constructor
1571 *
1572 * @param[in] f The activation function to use.
1573 * @param[in] a (Optional) The alpha parameter used by some activation functions
Georgios Pinitas64ebe5b2017-09-01 17:44:24 +01001574 * (@ref ActivationFunction::BOUNDED_RELU, @ref ActivationFunction::LU_BOUNDED_RELU, @ref ActivationFunction::LINEAR, @ref ActivationFunction::TANH).
1575 * @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 +01001576 */
1577 ActivationLayerInfo(ActivationFunction f, float a = 0.0f, float b = 0.0f)
Giorgio Arena11674872018-02-07 15:38:12 +00001578 : _act(f), _a(a), _b(b), _enabled(true)
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001579 {
1580 }
Alex Gildayc357c472018-03-21 13:54:09 +00001581 /** Get the type of activation function */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001582 ActivationFunction activation() const
1583 {
1584 return _act;
1585 }
Alex Gildayc357c472018-03-21 13:54:09 +00001586 /** Get the alpha value */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001587 float a() const
1588 {
1589 return _a;
1590 }
Alex Gildayc357c472018-03-21 13:54:09 +00001591 /** Get the beta value */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001592 float b() const
1593 {
1594 return _b;
1595 }
Alex Gildayc357c472018-03-21 13:54:09 +00001596 /** Check if initialised */
Giorgio Arena11674872018-02-07 15:38:12 +00001597 bool enabled() const
1598 {
1599 return _enabled;
1600 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001601
1602private:
Usama Arif6a98a6e2019-05-10 17:07:27 +01001603 ActivationFunction _act = { ActivationLayerInfo::ActivationFunction::IDENTITY };
Giorgio Arena11674872018-02-07 15:38:12 +00001604 float _a = {};
1605 float _b = {};
1606 bool _enabled = { false };
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001607};
1608
1609/** Normalization Layer Information class */
1610class NormalizationLayerInfo
1611{
1612public:
1613 /** Default Constructor
1614 *
Michele Di Giorgio9d3a8312018-11-20 12:31:24 +00001615 * @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 +01001616 * @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 +00001617 * @param[in] alpha (Optional) Alpha parameter used by normalization equation. Defaults to 0.0001.
1618 * @param[in] beta (Optional) Beta parameter used by normalization equation. Defaults to 0.5.
1619 * @param[in] kappa (Optional) Kappa parameter used by [Krichevksy 2012] Across Channel Local Brightness Normalization equation.
1620 * @param[in] is_scaled (Optional) Boolean that specifies if alpha will be scaled by the normalization size or not.
1621 * Should be false to follow [Krichevksy 2012].
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001622 */
Georgios Pinitas41caa622017-11-16 14:37:08 +00001623 NormalizationLayerInfo(NormType type, uint32_t norm_size = 5, float alpha = 0.0001f, float beta = 0.5f, float kappa = 1.f, bool is_scaled = true)
1624 : _type(type), _norm_size(norm_size), _alpha(alpha), _beta(beta), _kappa(kappa), _is_scaled(is_scaled)
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001625 {
1626 }
Alex Gildayc357c472018-03-21 13:54:09 +00001627 /** Get the normalization type */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001628 NormType type() const
1629 {
1630 return _type;
1631 }
Alex Gildayc357c472018-03-21 13:54:09 +00001632 /** Get the normalization size */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001633 uint32_t norm_size() const
1634 {
1635 return _norm_size;
1636 }
Alex Gildayc357c472018-03-21 13:54:09 +00001637 /** Get the alpha value */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001638 float alpha() const
1639 {
1640 return _alpha;
1641 }
Alex Gildayc357c472018-03-21 13:54:09 +00001642 /** Get the beta value */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001643 float beta() const
1644 {
1645 return _beta;
1646 }
Alex Gildayc357c472018-03-21 13:54:09 +00001647 /** Get the kappa value */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001648 float kappa() const
1649 {
1650 return _kappa;
1651 }
Michele Di Giorgio9d3a8312018-11-20 12:31:24 +00001652 /** Get the is_scaled value */
1653 bool is_scaled() const
1654 {
1655 return _is_scaled;
1656 }
Alex Gildayc357c472018-03-21 13:54:09 +00001657 /** Check if normalization is cross map */
Georgios Pinitas41caa622017-11-16 14:37:08 +00001658 bool is_cross_map() const
1659 {
1660 return _type == NormType::CROSS_MAP;
1661 }
Alex Gildayc357c472018-03-21 13:54:09 +00001662 /** Check if normalization is not cross map */
Georgios Pinitas41caa622017-11-16 14:37:08 +00001663 bool is_in_map() const
1664 {
1665 return !is_cross_map();
1666 }
1667 /** Return the scaling factor of the normalization function.
1668 *
1669 * If is_scaled is set to false then [Krichevksy 2012] normalization scaling is performed,
1670 * 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 +01001671 *
1672 * @return The normalization scaling factor.
1673 */
1674 float scale_coeff() const
1675 {
1676 const uint32_t size = (_type == NormType::IN_MAP_2D) ? _norm_size * _norm_size : _norm_size;
Georgios Pinitas41caa622017-11-16 14:37:08 +00001677 return (_is_scaled) ? (_alpha / size) : _alpha;
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001678 }
1679
1680private:
1681 NormType _type;
1682 uint32_t _norm_size;
1683 float _alpha;
1684 float _beta;
1685 float _kappa;
Georgios Pinitas41caa622017-11-16 14:37:08 +00001686 bool _is_scaled;
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001687};
1688
Gian Marco Iodice559d7712017-08-08 08:38:09 +01001689/** 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 +01001690class WeightsInfo
1691{
1692public:
Gian Marco Iodice4e288692017-06-27 11:41:59 +01001693 /** Default constructor */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001694 WeightsInfo()
Michele Di Giorgiob62280a2018-05-31 17:31:05 +01001695 : _are_reshaped(false), _kernel_width(0), _kernel_height(0), _num_kernels(0), _retain_internal_weights(false)
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001696 {
1697 }
1698 /** Constructor
1699 *
Michele Di Giorgiob62280a2018-05-31 17:31:05 +01001700 * @param[in] are_reshaped True if the weights have been reshaped
1701 * @param[in] kernel_width Kernel width.
1702 * @param[in] kernel_height Kernel height.
1703 * @param[in] num_kernels Number of convolution kernels.
1704 * @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 +01001705 */
Michele Di Giorgiob62280a2018-05-31 17:31:05 +01001706 WeightsInfo(bool are_reshaped, unsigned int kernel_width, unsigned int kernel_height, unsigned int num_kernels, bool retain_internal_weights = false)
1707 : _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 +01001708 {
1709 }
Gian Marco Iodice4e288692017-06-27 11:41:59 +01001710 /** Flag which specifies if the weights tensor has been reshaped.
1711 *
1712 * @return True if the weights tensors has been reshaped
1713 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001714 bool are_reshaped() const
1715 {
1716 return _are_reshaped;
1717 };
Gian Marco Iodice559d7712017-08-08 08:38:09 +01001718 /** Return the number of convolution kernels
1719 *
1720 * @return The number of convolution kernels
1721 */
1722 unsigned int num_kernels() const
1723 {
1724 return _num_kernels;
1725 };
Gian Marco Iodice4e288692017-06-27 11:41:59 +01001726 /** Return the width and height of the kernel
1727 *
1728 * @return The width and height of the kernel
1729 */
1730 std::pair<unsigned int, unsigned int> kernel_size() const
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001731 {
Gian Marco Iodice4e288692017-06-27 11:41:59 +01001732 return std::make_pair(_kernel_width, _kernel_height);
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001733 }
Michele Di Giorgiob62280a2018-05-31 17:31:05 +01001734 bool retain_internal_weights() const
1735 {
1736 return _retain_internal_weights;
1737 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001738
1739private:
1740 const bool _are_reshaped;
Gian Marco Iodice4e288692017-06-27 11:41:59 +01001741 const unsigned int _kernel_width;
1742 const unsigned int _kernel_height;
Gian Marco Iodice559d7712017-08-08 08:38:09 +01001743 const unsigned int _num_kernels;
Michele Di Giorgiob62280a2018-05-31 17:31:05 +01001744 const bool _retain_internal_weights;
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001745};
1746
Gian Marco36a0a462018-01-12 10:21:40 +00001747/** GEMM reshape information class. This class stores the necessary information about matrix A and matrix B reshape.
1748 *
Gian Marco Iodice5fc07aa2019-05-15 17:08:02 +01001749 * The matrix A can only be reshaped through @ref CLGEMMReshapeLHSMatrixKernel or @ref NEGEMMInterleave4x4Kernel or @ref GCGEMMInterleave4x4Kernel
1750 * 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 +00001751 *
giuros018b6b4a92018-12-18 19:01:33 +00001752 * The matrix B can only be reshaped through @ref CLGEMMReshapeRHSMatrixKernel or @ref NEGEMMTranspose1xWKernel or @ref GCGEMMTranspose1xWKernel
1753 * 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 +00001754 *
1755 */
1756class GEMMReshapeInfo final
1757{
1758public:
1759 /** Default constructor */
1760 GEMMReshapeInfo()
Georgios Pinitasb0f342e2019-05-21 13:32:43 +01001761 : _m(1), _n(1), _k(1), _mult_transpose1xW_width(1), _mult_interleave4x4_height(1), _depth_output_gemm3d(0), _reinterpret_input_as_3d(false), _broadcast_bias(false)
Gian Marco36a0a462018-01-12 10:21:40 +00001762 {
1763 }
1764 /** Constructor
1765 *
1766 * @param[in] m Number of matrix A rows
1767 * @param[in] n Number of matrix B columns
1768 * @param[in] k Number of matrix A columns or matrix B rows
1769 * @param[in] mult_transpose1xW_width (Optional) Multiplication factor for the width of the 1xW transposed block
1770 * @param[in] mult_interleave4x4_height (Optional) Multiplication factor for the height of the 4x4 interleaved block
Gian Marco Iodice3139f032018-11-05 14:26:32 +00001771 * @param[in] depth_output_gemm3d (Optional) Depth (third dimension) of the output tensor to be used with the GEMM3D kernel.
1772 * If 0 the output will not be reinterpreted as 3D. Default 0
Gian Marco Iodice68a3f562018-07-26 11:44:03 +01001773 * @param[in] reinterpret_input_as_3d (Optional) Reinterpret the input as 3D tensor. (i.e. this flag should be set to true when GEMM is used
Georgios Pinitasb0f342e2019-05-21 13:32:43 +01001774 * to perform 1x1 convolutions with the NHWC data layout)
1775 * @param[in] broadcast_bias (Optional) Broadcast the shape of the bias tensor from a vector to a matrix.
Gian Marco36a0a462018-01-12 10:21:40 +00001776 */
Georgios Pinitasb0f342e2019-05-21 13:32:43 +01001777 GEMMReshapeInfo(int m, int n, int k, int mult_transpose1xW_width = 1, int mult_interleave4x4_height = 1, int depth_output_gemm3d = 0, bool reinterpret_input_as_3d = false, bool broadcast_bias = false)
Gian Marco Iodice68a3f562018-07-26 11:44:03 +01001778 : _m(m), _n(n), _k(k), _mult_transpose1xW_width(mult_transpose1xW_width), _mult_interleave4x4_height(mult_interleave4x4_height), _depth_output_gemm3d(depth_output_gemm3d),
Georgios Pinitasb0f342e2019-05-21 13:32:43 +01001779 _reinterpret_input_as_3d(reinterpret_input_as_3d), _broadcast_bias(broadcast_bias)
Gian Marco36a0a462018-01-12 10:21:40 +00001780 {
1781 }
1782 /** Number of matrix A rows
1783 *
1784 * @return the number of matrix A rows
1785 */
1786 int m() const
1787 {
1788 return _m;
1789 }
1790 /** Number of matrix B columns
1791 *
1792 * @return the number of matrix B columns
1793 */
1794 int n() const
1795 {
1796 return _n;
1797 }
1798 /** Number of matrix A columns or matrix B rows
1799 *
1800 * @return the number of matrix A columns or matrix B rows
1801 */
1802 int k() const
1803 {
1804 return _k;
1805 }
1806 /** Multiplication factor for the width of the 1xW transposed block
1807 *
1808 * @return the multiplication factor for the width of the 1xW transposed block
1809 */
1810 int mult_transpose1xW_width() const
1811 {
1812 return _mult_transpose1xW_width;
1813 }
1814 /** Multiplication factor for the height of the 4x4 interleaved block
1815 *
1816 * @return the multiplication factor for the height of the 4x4 interleaved block
1817 */
1818 int mult_interleave4x4_height() const
1819 {
1820 return _mult_interleave4x4_height;
1821 }
Isabella Gottardi8e74f442018-03-01 16:42:00 +00001822 /** Depth (third dimension) of the output tensor to be used with the GEMM3D kernel
1823 *
1824 * @note GEMM3D kernel is used when the output has to be reinterpret as 3D tensor. In that case:
1825 * m = depth_output_gemm3d * output_height
1826 *
1827 * @return the depth of the output tensor to be used with the GEMM3D kernel
1828 */
1829 int depth_output_gemm3d() const
1830 {
1831 return _depth_output_gemm3d;
1832 }
Gian Marco Iodice68a3f562018-07-26 11:44:03 +01001833 /** Flag which specifies if the input tensor has to be reinterpreted as 3D
1834 *
1835 * @return True if the input tensor has to be reinterpreted as 3D tensor
1836 */
1837 bool reinterpret_input_as_3d() const
1838 {
1839 return _reinterpret_input_as_3d;
1840 };
Georgios Pinitasb0f342e2019-05-21 13:32:43 +01001841 /** Flag which specifies whether to broadcast the shape of the bias tensor.
1842 *
1843 * @return True if the shape of the bias tensor is to be broadcasted.
1844 */
1845 bool broadcast_bias() const
1846 {
1847 return _broadcast_bias;
1848 };
Gian Marco36a0a462018-01-12 10:21:40 +00001849
1850private:
Gian Marco Iodice68a3f562018-07-26 11:44:03 +01001851 const int _m;
1852 const int _n;
1853 const int _k;
1854 const int _mult_transpose1xW_width;
1855 const int _mult_interleave4x4_height;
1856 const int _depth_output_gemm3d;
1857 const bool _reinterpret_input_as_3d;
Georgios Pinitasb0f342e2019-05-21 13:32:43 +01001858 const bool _broadcast_bias;
Gian Marco36a0a462018-01-12 10:21:40 +00001859};
1860
giuros016d109962019-01-07 17:47:19 +00001861struct DepthwiseConvolutionReshapeInfo
1862{
1863 unsigned int c0{ 1 }; /**< Number of channels processed by the depth-wise convolution */
1864 bool transpose{ false }; /**< True if the block MxC0 (where M is the area of the filter i.e. KwxKh) has to be transposed */
1865};
1866
Gian Marco Iodice4b908652018-10-18 10:21:02 +01001867/** GEMMLowp output stage type */
1868enum class GEMMLowpOutputStageType
1869{
1870 NONE, /**< No quantization to uint8 */
1871 QUANTIZE_DOWN, /**< Quantize to uint8 using an integer multiplication */
1872 QUANTIZE_DOWN_FIXEDPOINT, /**< Quantize to uint8 using a fixed point multiplication */
1873 QUANTIZE_DOWN_FLOAT /**< Quantize to uint8 using a floating point multiplication */
1874};
1875
1876/** GEMMLowp output stage info */
1877struct GEMMLowpOutputStageInfo
1878{
1879 GEMMLowpOutputStageType type{ GEMMLowpOutputStageType::NONE }; /**< GEMMLowp output stage type */
1880 int gemmlowp_offset{ 0 }; /**< GEMMLowp output stage offset used for quantizing to QASYMM8 */
1881 int gemmlowp_multiplier{ 0 }; /**< GEMMLowp output stage multiplier used for quantizing to QASYMM8 */
1882 int gemmlowp_shift{ 0 }; /**< GEMMLowp output stage shift used for quantizing to uint8 */
1883 int gemmlowp_min_bound{ 0 }; /**< GEMMLowp min value used to saturate down the output result before converting back to QASYMM8 */
1884 int gemmlowp_max_bound{ 0 }; /**< GEMMLowp max value used to saturate down the output result before converting back to QASYMM8 */
Georgios Pinitas68adf442019-11-07 11:46:09 +00001885 std::vector<int32_t> gemmlowp_multipliers{}; /**< GEMMLowp output stage multiplier used for quantizing to QASYMM8 */
1886 std::vector<int32_t> gemmlowp_shifts{}; /**< GEMMLowp output stage multiplier used for quantizing to QASYMM8 */
Gian Marco Iodice4b908652018-10-18 10:21:02 +01001887};
1888
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +00001889/** GEMM LHS (Left Hand Side) matrix information */
1890struct GEMMLHSMatrixInfo
1891{
1892 unsigned int m0{ 1 }; /**< Number of rows processed by the matrix multiplication */
1893 unsigned int k0{ 1 }; /**< Number of partial accumulations performed by the matrix multiplication */
1894 unsigned int v0{ 1 }; /**< Number of vertical blocks of size (m0xk0) stored on the same output row */
1895 bool transpose{ true }; /**< True if the (m0xk0) block has to be transposed before been stored */
1896 bool interleave{ true }; /**< True if the v0 (m0xk0) blocks have to be interleaved in the output row */
1897};
1898
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +00001899/** GEMM RHS (Right Hand Side) matrix information */
1900struct GEMMRHSMatrixInfo
1901{
1902 unsigned int n0{ 1 }; /**< Number of columns processed by the matrix multiplication */
1903 unsigned int k0{ 1 }; /**< Number of partial accumulations performed by the matrix multiplication */
1904 unsigned int h0{ 1 }; /**< Number of horizontal blocks of size (k0xn0) stored on the same output row */
1905 bool transpose{ true }; /**< True if the (k0xn0) block has to be transposed before been stored */
1906 bool interleave{ true }; /**< True if the h0 (k0xn0) blocks have to be interleaved in the output row */
1907};
1908
Gian Marco36a0a462018-01-12 10:21:40 +00001909/** GEMM information class. This class stores the necessary information to compute GEMM functions
1910 *
1911 * This object also contains the information about how matrix A and matrix B have been reshaped
1912 *
1913 */
Chunosov5124be52017-11-22 20:42:13 +07001914class GEMMInfo
1915{
1916public:
1917 /** Default constructor */
Georgios Pinitas37d080f2019-06-21 18:43:12 +01001918 GEMMInfo() noexcept
1919 : _is_a_reshaped(false),
1920 _is_b_reshaped(false),
1921 _reshape_b_only_on_first_run(true),
1922 _depth_output_gemm3d(0),
1923 _reinterpret_input_as_3d(false),
1924 _retain_internal_weights(false),
1925 _gemmlowp_output_stage(),
1926 _fp_mixed_precision(false),
1927 _broadcast_bias(false),
Gian Marco Iodicef3622be2019-07-29 14:27:16 +01001928 _pretranpose_B(true),
1929 _activation_info()
Chunosov5124be52017-11-22 20:42:13 +07001930 {
1931 }
1932 /** Constructor
1933 *
1934 * @param[in] is_a_reshaped True if the matrix A has been reshaped
1935 * @param[in] is_b_reshaped True if the matrix B has been reshaped
1936 * @param[in] reshape_b_only_on_first_run Reshape matrix B only for the first run
Isabella Gottardi8e74f442018-03-01 16:42:00 +00001937 * @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 +00001938 * If 0 the output will not be reinterpreted as 3D. Default 0
Gian Marco Iodice68a3f562018-07-26 11:44:03 +01001939 * @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
1940 * to perform 1x1 convolutions with the NHWC data layout)
Michele Di Giorgioba1ffe92018-08-22 14:28:30 +01001941 * @param[in] retain_internal_weights (Optional) Retain the weights tensor from previous run
Gian Marco Iodice4b908652018-10-18 10:21:02 +01001942 * @param[in] gemmlowp_output_stage (Optional) GEMMLowp Output stage info
Vidhya Sudhan Loganathana25d16c2018-11-16 11:33:12 +00001943 * @param[in] fp_mixed_precision (Optional) Use wider accumulators (32 bit instead of 16 for FP16) to improve accuracy.
Georgios Pinitasb0f342e2019-05-21 13:32:43 +01001944 * @param[in] broadcast_bias (Optional) Broadcast the shape of the bias tensor from a vector to a matrix.
Gian Marco Iodicef3622be2019-07-29 14:27:16 +01001945 * @param[in] activation_info (Optional) Activation to apply after the matrix multiplication
Chunosov5124be52017-11-22 20:42:13 +07001946 */
Gian Marco Iodice3139f032018-11-05 14:26:32 +00001947 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,
Gian Marco Iodicef3622be2019-07-29 14:27:16 +01001948 GEMMLowpOutputStageInfo gemmlowp_output_stage = GEMMLowpOutputStageInfo(), bool fp_mixed_precision = false, bool broadcast_bias = false,
1949 const ActivationLayerInfo &activation_info = ActivationLayerInfo()) noexcept
Georgios Pinitas37d080f2019-06-21 18:43:12 +01001950 : _is_a_reshaped(is_a_reshaped),
1951 _is_b_reshaped(is_b_reshaped),
1952 _reshape_b_only_on_first_run(reshape_b_only_on_first_run),
1953 _depth_output_gemm3d(depth_output_gemm3d),
1954 _reinterpret_input_as_3d(reinterpret_input_as_3d),
1955 _retain_internal_weights(retain_internal_weights),
1956 _gemmlowp_output_stage(gemmlowp_output_stage),
1957 _fp_mixed_precision(fp_mixed_precision),
1958 _broadcast_bias(broadcast_bias),
Gian Marco Iodicef3622be2019-07-29 14:27:16 +01001959 _pretranpose_B(reshape_b_only_on_first_run),
1960 _activation_info(activation_info)
Chunosov5124be52017-11-22 20:42:13 +07001961 {
1962 }
1963 /** Flag which specifies if the matrix A has been reshaped
1964 *
1965 * @return True if the matrix A has been reshaped
1966 */
1967 bool is_a_reshaped() const
1968 {
1969 return _is_a_reshaped;
1970 };
1971 /** Flag which specifies if the matrix B has been reshaped
1972 *
1973 * @return True if the matrix B has been reshaped
1974 */
1975 bool is_b_reshaped() const
1976 {
1977 return _is_b_reshaped;
1978 };
1979 /** Flag which specifies if the reshape of matrix B should executed only for the first
1980 *
1981 * @note This flag could be set to TRUE when GEMM is used to accelerate convolution layer
1982 *
1983 * @return True if the reshaped of matrix B happens only for the first run
1984 */
1985 bool reshape_b_only_on_first_run() const
1986 {
1987 return _reshape_b_only_on_first_run;
1988 };
Isabella Gottardi8e74f442018-03-01 16:42:00 +00001989 /** Depth of the output when GEMM output is reinterpreted as 3D tensor
Gian Marco36a0a462018-01-12 10:21:40 +00001990 *
Isabella Gottardi8e74f442018-03-01 16:42:00 +00001991 * @return the depth of the output tensor
Gian Marco36a0a462018-01-12 10:21:40 +00001992 */
Isabella Gottardi8e74f442018-03-01 16:42:00 +00001993 int depth_output_gemm3d() const
Gian Marco36a0a462018-01-12 10:21:40 +00001994 {
Isabella Gottardi8e74f442018-03-01 16:42:00 +00001995 return _depth_output_gemm3d;
1996 };
Gian Marco Iodice68a3f562018-07-26 11:44:03 +01001997 /** Flag which specifies if the input tensor has to be reinterpreted as 3D
1998 *
1999 * @return True if the input tensor has to be reinterpreted as 3D tensor
2000 */
2001 bool reinterpret_input_as_3d() const
2002 {
2003 return _reinterpret_input_as_3d;
2004 };
Michele Di Giorgioba1ffe92018-08-22 14:28:30 +01002005 /** Flag which specifies if the weights tensor has to be retained from previous run
2006 *
2007 * @return True if the weights tensor has to be retained
2008 */
2009 bool retain_internal_weights() const
2010 {
2011 return _retain_internal_weights;
2012 };
Gian Marco Iodice4b908652018-10-18 10:21:02 +01002013 /** GEMMLowp output stage
2014 *
2015 * @return the GEMMLowp output stage info
2016 */
2017 GEMMLowpOutputStageInfo gemmlowp_output_stage() const
2018 {
2019 return _gemmlowp_output_stage;
2020 };
Georgios Pinitasdbdea0d2019-10-16 19:21:40 +01002021 /** Sets GEMMLowp output stage
2022 *
2023 * @param[in] output_stage Output stage to set
2024 */
2025 void set_gemmlowp_output_stage(GEMMLowpOutputStageInfo &output_stage)
2026 {
2027 _gemmlowp_output_stage = output_stage;
2028 };
Vidhya Sudhan Loganathana25d16c2018-11-16 11:33:12 +00002029 /** Flag which specifies if a wider accumulator should be used.
2030 *
2031 * @return True if a wider accumulator has to be used
2032 */
2033 bool fp_mixed_precision() const
2034 {
2035 return _fp_mixed_precision;
2036 };
Georgios Pinitasb0f342e2019-05-21 13:32:43 +01002037 /** Flag which specifies whether to broadcast the shape of the bias tensor.
2038 *
2039 * @return True if the shape of the bias tensor is to be broadcasted.
2040 */
2041 bool broadcast_bias() const
2042 {
2043 return _broadcast_bias;
2044 };
Georgios Pinitas37d080f2019-06-21 18:43:12 +01002045 /** Flag which specifies whether b should be pre-transposed if supported.
2046 *
2047 * @return True if b should be pre-transposed else false.
2048 */
2049 bool pretranpose_B() const
2050 {
2051 return _pretranpose_B;
2052 };
2053 /** Set pre-transpose b flag
2054 *
2055 * @param[in] flag Flag to set
2056 */
2057 void set_pretranpose_B(bool flag)
2058 {
2059 _pretranpose_B = flag;
2060 }
Gian Marco Iodicef3622be2019-07-29 14:27:16 +01002061 /** Activation layer to apply after the matrix multiplication
2062 *
2063 * @return ActivationLayerInfo object
2064 */
2065 ActivationLayerInfo activation_info() const
2066 {
2067 return _activation_info;
2068 }
Chunosov5124be52017-11-22 20:42:13 +07002069
2070private:
Georgios Pinitas37d080f2019-06-21 18:43:12 +01002071 bool _is_a_reshaped;
2072 bool _is_b_reshaped;
2073 bool _reshape_b_only_on_first_run;
2074 int _depth_output_gemm3d;
2075 bool _reinterpret_input_as_3d;
2076 bool _retain_internal_weights;
2077 GEMMLowpOutputStageInfo _gemmlowp_output_stage;
2078 bool _fp_mixed_precision;
2079 bool _broadcast_bias;
2080 bool _pretranpose_B;
Gian Marco Iodicef3622be2019-07-29 14:27:16 +01002081 ActivationLayerInfo _activation_info;
Chunosov5124be52017-11-22 20:42:13 +07002082};
2083
Gian Marco Iodice247f52c2018-03-22 11:24:56 +00002084/** Winograd information */
2085struct WinogradInfo
2086{
2087 /** Default constructor
2088 *
2089 * @param[in] output_tile_sz Width and height of the output tile
2090 * @param[in] kernel_sz Width and height of the kernel
2091 * @param[in] input_dims Width and height of the input tensor before the convolution is applied
2092 * @param[in] conv_info Convolution info (Pads, strides)
2093 * @param[in] data_layout Data layout to use for the output tensor once the convolution has been applied
2094 */
2095 WinogradInfo(Size2D output_tile_sz, Size2D kernel_sz, Size2D input_dims, PadStrideInfo conv_info, DataLayout data_layout)
2096 : output_tile_size(output_tile_sz), kernel_size(kernel_sz), input_dimensions(input_dims), convolution_info(conv_info), output_data_layout(data_layout)
2097 {
2098 }
2099
2100 Size2D output_tile_size{}; /**< Width and height of the output tile */
2101 Size2D kernel_size{}; /**< Width and height of the kernel*/
2102 Size2D input_dimensions{}; /**< Width and height of the input tensor before the convolution is applied */
2103 PadStrideInfo convolution_info{}; /**< Convolution info (Pads, strides,...) */
2104 DataLayout output_data_layout{ DataLayout::NCHW }; /**< Data layout to use for the output tensor once the convolution has been applied (NCHW or NHWC) */
2105};
2106
Anthony Barbier6ff3b192017-09-04 18:44:23 +01002107/** IO formatting information class*/
2108struct IOFormatInfo
2109{
2110 /** Precision type used when printing floating point numbers */
2111 enum class PrecisionType
2112 {
2113 Default, /**< Default precision to the one that the current stream has */
2114 Custom, /**< Custom precision specified by the user using the precision parameter */
2115 Full /**< The maximum precision of the floating point representation */
2116 };
2117
2118 /** Specifies the area to be printed, used by Tensor objects */
2119 enum class PrintRegion
2120 {
2121 ValidRegion, /**< Prints the valid region of the Tensor object */
2122 NoPadding, /**< Prints the Tensor object without the padding */
2123 Full /**< Print the tensor object including padding */
2124 };
2125
Alex Gildayc357c472018-03-21 13:54:09 +00002126 /** Construct a set of IO formatting information.
2127 *
2128 * @param[in] print_region Area to be printed. Used by Tensor objects. Default: ValidRegion.
2129 * @param[in] precision_type Precision type for floating point numbers. Default: stream default.
2130 * @param[in] precision Precision value for float point numbers. Default: 10.
2131 * @param[in] align_columns Whether to align columns when printed. Default: true.
2132 * @param[in] element_delim Delimeter between elements. Default: " ".
2133 * @param[in] row_delim Delimenter between rows. Default: "\n".
2134 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01002135 IOFormatInfo(PrintRegion print_region = PrintRegion::ValidRegion,
2136 PrecisionType precision_type = PrecisionType::Default,
2137 unsigned int precision = 10,
2138 bool align_columns = true,
2139 std::string element_delim = " ",
2140 std::string row_delim = "\n")
2141 : print_region(print_region),
2142 precision_type(precision_type),
2143 precision(precision),
2144 element_delim(element_delim),
2145 row_delim(row_delim),
2146 align_columns(align_columns)
2147 {
2148 }
2149
Alex Gildayc357c472018-03-21 13:54:09 +00002150 /** Area to be printed by Tensor objects */
2151 PrintRegion print_region;
2152 /** Floating point precision type */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01002153 PrecisionType precision_type;
Alex Gildayc357c472018-03-21 13:54:09 +00002154 /** Floating point precision */
2155 unsigned int precision;
2156 /** Element delimeter */
2157 std::string element_delim;
2158 /** Row delimeter */
2159 std::string row_delim;
2160 /** Align columns */
2161 bool align_columns;
Anthony Barbier6ff3b192017-09-04 18:44:23 +01002162};
Georgios Pinitasd8734b52017-12-22 15:27:52 +00002163} // namespace arm_compute
Anthony Barbier6ff3b192017-09-04 18:44:23 +01002164#endif /* __ARM_COMPUTE_TYPES_H__ */