blob: 9641089e7b720d2023a07411d7252d12863ab670 [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 */
80 QASYMM8, /**< quantized, asymmetric fixed-point 8-bit number */
81 QSYMM8_PER_CHANNEL, /**< quantized, symmetric per channel fixed-point 8-bit number */
82 QASYMM8_PER_CHANNEL, /**< quantized, asymmetric per channel fixed-point 8-bit number */
83 U16, /**< unsigned 16-bit number */
84 S16, /**< signed 16-bit number */
85 QSYMM16, /**< quantized, symmetric fixed-point 16-bit number */
Michele Di Giorgio35ea9a72019-08-23 12:02:06 +010086 QASYMM16, /**< quantized, asymmetric fixed-point 16-bit number */
Michalis Spyrouc8530212019-08-22 11:44:04 +010087 U32, /**< unsigned 32-bit number */
88 S32, /**< signed 32-bit number */
89 U64, /**< unsigned 64-bit number */
90 S64, /**< signed 64-bit number */
91 F16, /**< 16-bit floating-point number */
92 F32, /**< 32-bit floating-point number */
93 F64, /**< 64-bit floating-point number */
94 SIZET /**< size_t */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010095};
96
Daniil Efremov02bf80d2017-11-22 00:26:51 +070097/** Available Sampling Policies */
98enum class SamplingPolicy
99{
100 CENTER, /**< Samples are taken at pixel center */
101 TOP_LEFT /**< Samples are taken at pixel top left corner */
102};
103
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100104/** Constant value of the border pixels when using BorderMode::CONSTANT */
105constexpr uint8_t CONSTANT_BORDER_VALUE = 199;
106
Alex Gildayc357c472018-03-21 13:54:09 +0000107/** Constant value used to indicate a half-scale pyramid */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100108constexpr float SCALE_PYRAMID_HALF = 0.5f;
109
Alex Gildayc357c472018-03-21 13:54:09 +0000110/** Constant value used to indicate a ORB scaled pyramid */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100111constexpr float SCALE_PYRAMID_ORB = 8.408964152537146130583778358414e-01;
112
Vidhya Sudhan Loganathand646ae12018-11-19 15:18:20 +0000113/** [DataLayout enum definition] **/
114
Georgios Pinitas4074c992018-01-30 18:13:46 +0000115/** Supported tensor data layouts */
116enum class DataLayout
117{
Alex Gildayc357c472018-03-21 13:54:09 +0000118 UNKNOWN, /**< Unknown data layout */
119 NCHW, /**< Num samples, channels, height, width */
120 NHWC /**< Num samples, height, width, channels */
Georgios Pinitas4074c992018-01-30 18:13:46 +0000121};
Vidhya Sudhan Loganathand646ae12018-11-19 15:18:20 +0000122/** [DataLayout enum definition] **/
Georgios Pinitas4074c992018-01-30 18:13:46 +0000123
Isabella Gottardid17a6772018-02-27 17:41:55 +0000124/** Supported tensor data layout dimensions */
125enum class DataLayoutDimension
126{
Alex Gildayc357c472018-03-21 13:54:09 +0000127 CHANNEL, /**< channel */
128 HEIGHT, /**< height */
129 WIDTH, /**< width */
130 BATCHES /**< batches */
Isabella Gottardid17a6772018-02-27 17:41:55 +0000131};
132
Georgios Pinitas7900a9e2018-11-23 11:44:58 +0000133/** Available ConvolutionMethod*/
134enum class ConvolutionMethod
135{
Vidhya Sudhan Loganathan8ec0bb62019-04-23 10:40:44 +0100136 GEMM, /**< Convolution using GEMM */
137 DIRECT, /**< Direct convolution */
138 WINOGRAD, /**< Convolution using Winograd */
139 FFT /**< Convolution using FFT */
Georgios Pinitas7900a9e2018-11-23 11:44:58 +0000140};
141
giuros0146a49a02019-04-01 13:50:22 +0100142/** Available DeconvolutionMethod*/
143enum class DeconvolutionMethod
144{
145 GEMM, /**< Deconvolution using GEMM */
146 DIRECT, /**< Direct deconvolution */
147};
148
Manuel Bottini2732cca2019-05-28 11:44:41 +0100149/** Available FuseBatchNormalizationType*/
150enum class FuseBatchNormalizationType
151{
152 CONVOLUTION, /**< For Convolution weights */
153 DEPTHWISECONVOLUTION /**< For Depthwise Convolution weights*/
154};
155
Usama Arif89890c62019-03-19 10:57:05 +0000156/** Padding mode to use for PadLayer */
157enum class PaddingMode
158{
159 CONSTANT,
160 REFLECT,
161 SYMMETRIC
162};
163
Georgios Pinitas7900a9e2018-11-23 11:44:58 +0000164/** Supported comparison operations */
165enum class ComparisonOperation
166{
167 Equal, /**< Equal comparison ( \f$ x == y \f$ ) */
168 NotEqual, /**< NotEqual comparison ( \f$ x != y \f$ ) */
169 Greater, /**< Greater comparison ( \f$ x > y \f$ ) */
170 GreaterEqual, /**< Greater equal comparison ( \f$ x >= y \f$ ) */
171 Less, /**< Less comparison ( \f$ x < y \f$ ) */
172 LessEqual /**< Less equal comparison ( \f$ x <= y \f$ ) */
173};
174
Alex Gildayc357c472018-03-21 13:54:09 +0000175/** Container for valid region of a window */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100176struct ValidRegion
177{
Alex Gildayc357c472018-03-21 13:54:09 +0000178 /** Default constructor */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100179 ValidRegion()
180 : anchor{}, shape{}
181 {
182 }
183
Alex Gildayc357c472018-03-21 13:54:09 +0000184 /** Allow instances of this class to be copy constructed */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100185 ValidRegion(const ValidRegion &) = default;
Alex Gildayc357c472018-03-21 13:54:09 +0000186 /** Allow instances of this class to be move constructed */
187 ValidRegion(ValidRegion &&) = default;
188 /** Allow instances of this class to be copied */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100189 ValidRegion &operator=(const ValidRegion &) = default;
Alex Gildayc357c472018-03-21 13:54:09 +0000190 /** Allow instances of this class to be moved */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100191 ValidRegion &operator=(ValidRegion &&) = default;
Alex Gildayc357c472018-03-21 13:54:09 +0000192 /** Default destructor */
193 ~ValidRegion() = default;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100194
Alex Gildayc357c472018-03-21 13:54:09 +0000195 /** Constructor for a valid region with default number of dimensions
196 *
197 * @param[in] an_anchor Anchor for the start of the valid region.
198 * @param[in] a_shape Shape of the valid region.
199 *
200 */
Diego Lopez Recasbcbc9702017-12-18 11:28:27 +0000201 ValidRegion(const Coordinates &an_anchor, const TensorShape &a_shape)
202 : anchor{ an_anchor }, shape{ a_shape }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100203 {
Diego Lopez Recasbcbc9702017-12-18 11:28:27 +0000204 anchor.set_num_dimensions(std::max(anchor.num_dimensions(), shape.num_dimensions()));
205 }
206
Alex Gildayc357c472018-03-21 13:54:09 +0000207 /** Constructor for a valid region with specified number of dimensions
208 *
209 * @param[in] an_anchor Anchor for the start of the valid region.
210 * @param[in] a_shape Shape of the valid region.
211 * @param[in] num_dimensions Number of dimensions (must be >= number of dimensions of anchor and shape).
212 *
213 */
Diego Lopez Recasbcbc9702017-12-18 11:28:27 +0000214 ValidRegion(const Coordinates &an_anchor, const TensorShape &a_shape, size_t num_dimensions)
215 : anchor{ an_anchor }, shape{ a_shape }
216 {
217 ARM_COMPUTE_ERROR_ON(num_dimensions < std::max(anchor.num_dimensions(), shape.num_dimensions()));
218 anchor.set_num_dimensions(num_dimensions);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100219 }
220
221 /** Return the start of the valid region for the given dimension @p d */
222 int start(unsigned int d) const
223 {
224 return anchor[d];
225 }
226
227 /** Return the end of the valid region for the given dimension @p d */
228 int end(unsigned int d) const
229 {
230 return anchor[d] + shape[d];
231 }
232
Diego Lopez Recas35ceeb22017-12-04 18:56:10 +0000233 /** Accessor to set the value of anchor and shape for one of the dimensions.
234 *
235 * @param[in] dimension Dimension for which the value is set.
236 * @param[in] start Value to be set in anchor for the dimension.
237 * @param[in] size Value to be set in shape for the dimension.
238 *
239 * @return *this.
240 */
241 ValidRegion &set(size_t dimension, int start, size_t size)
242 {
243 anchor.set(dimension, start);
244 shape.set(dimension, size);
245 return *this;
246 }
247
Alex Gildayc357c472018-03-21 13:54:09 +0000248 Coordinates anchor; /**< Anchor for the start of the valid region. */
249 TensorShape shape; /**< Shape of the valid region. */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100250};
251
252/** Methods available to handle borders */
253enum class BorderMode
254{
255 UNDEFINED, /**< Borders are left undefined */
256 CONSTANT, /**< Pixels outside the image are assumed to have a constant value */
257 REPLICATE /**< Pixels outside the image are assumed to have the same value as the closest image pixel */
258};
259
260/** Container for 2D border size */
261struct BorderSize
262{
263 /** Empty border, i.e. no border */
264 constexpr BorderSize()
265 : top{ 0 }, right{ 0 }, bottom{ 0 }, left{ 0 }
266 {
267 }
268
269 /** Border with equal size around the 2D plane */
Moritz Pflanzer7655a672017-09-23 11:57:33 +0100270 explicit constexpr BorderSize(unsigned int size)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100271 : top{ size }, right{ size }, bottom{ size }, left{ size }
272 {
273 }
274
275 /** Border with same size for top/bottom and left/right */
276 constexpr BorderSize(unsigned int top_bottom, unsigned int left_right)
277 : top{ top_bottom }, right{ left_right }, bottom{ top_bottom }, left{ left_right }
278 {
279 }
280
281 /** Border with different sizes */
282 constexpr BorderSize(unsigned int top, unsigned int right, unsigned int bottom, unsigned int left)
283 : top{ top }, right{ right }, bottom{ bottom }, left{ left }
284 {
285 }
286
287 /** Check if the entire border is zero */
288 constexpr bool empty() const
289 {
290 return top == 0 && right == 0 && bottom == 0 && left == 0;
291 }
292
293 /** Check if the border is the same size on all sides */
294 constexpr bool uniform() const
295 {
296 return top == right && top == bottom && top == left;
297 }
298
Alex Gildayc357c472018-03-21 13:54:09 +0000299 /** Scale this border size.
300 *
301 * @param[in] scale Scale to multiply border size by.
302 *
303 * @return *this.
304 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100305 BorderSize &operator*=(float scale)
306 {
307 top *= scale;
308 right *= scale;
309 bottom *= scale;
310 left *= scale;
311
312 return *this;
313 }
314
Alex Gildayc357c472018-03-21 13:54:09 +0000315 /** Scale a copy of this border size.
316 *
317 * @param[in] scale Scale to multiply border size by.
318 *
319 * @return a scaled copy of this.
320 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100321 BorderSize operator*(float scale)
322 {
323 BorderSize size = *this;
324 size *= scale;
325
326 return size;
327 }
328
Alex Gildayc357c472018-03-21 13:54:09 +0000329 /** Limit this border size.
330 *
331 * @param[in] limit Border size to limit this border size to.
332 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100333 void limit(const BorderSize &limit)
334 {
335 top = std::min(top, limit.top);
336 right = std::min(right, limit.right);
337 bottom = std::min(bottom, limit.bottom);
338 left = std::min(left, limit.left);
339 }
340
Alex Gildayc357c472018-03-21 13:54:09 +0000341 unsigned int top; /**< top of the border */
342 unsigned int right; /**< right of the border */
343 unsigned int bottom; /**< bottom of the border */
344 unsigned int left; /**< left of the border */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100345};
346
Alex Gildayc357c472018-03-21 13:54:09 +0000347/** Container for 2D padding size */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100348using PaddingSize = BorderSize;
349
350/** Policy to handle overflow */
351enum class ConvertPolicy
352{
353 WRAP, /**< Wrap around */
354 SATURATE /**< Saturate */
355};
356
357/** Interpolation method */
358enum class InterpolationPolicy
359{
360 NEAREST_NEIGHBOR, /**< Output values are defined to match the source pixel whose center is nearest to the sample position */
361 BILINEAR, /**< Output values are defined by bilinear interpolation between the pixels */
362 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 */
363};
364
365/** Bilinear Interpolation method used by LKTracker */
366enum class BilinearInterpolation
367{
Alex Gildayc357c472018-03-21 13:54:09 +0000368 BILINEAR_OLD_NEW, /**< Old-new method */
369 BILINEAR_SCHARR /**< Scharr method */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100370};
371
372/** Threshold mode */
373enum class ThresholdType
374{
375 BINARY, /**< Threshold with one value */
376 RANGE /**< Threshold with two values*/
377};
378
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100379/** Termination criteria */
380enum class Termination
381{
Alex Gildayc357c472018-03-21 13:54:09 +0000382 TERM_CRITERIA_EPSILON, /**< Terminate when within epsilon of a threshold */
383 TERM_CRITERIA_ITERATIONS, /**< Terminate after a maximum number of iterations */
384 TERM_CRITERIA_BOTH /**< Terminate on whichever of the other conditions occurs first */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100385};
386
387/** Magnitude calculation type. */
388enum class MagnitudeType
389{
390 L1NORM, /**< L1 normalization type */
391 L2NORM /**< L2 normalization type */
392};
393
394/** Phase calculation type.
395 *
396 * @note When PhaseType == SIGNED, each angle is mapped to the range 0 to 255 inclusive otherwise angles between 0 and 180
397 */
398enum class PhaseType
399{
400 SIGNED, /**< Angle range: [0, 360] */
401 UNSIGNED /**< Angle range: [0, 180] */
402};
403
404/** Keypoint type */
405struct KeyPoint
406{
407 int32_t x{ 0 }; /**< X coordinates */
408 int32_t y{ 0 }; /**< Y coordinates */
409 float strength{ 0.f }; /**< Strength of the point */
410 float scale{ 0.f }; /**< Scale initialized to 0 by the corner detector */
411 float orientation{ 0.f }; /**< Orientation initialized to 0 by the corner detector */
412 int32_t tracking_status{ 0 }; /**< Status initialized to 1 by the corner detector, set to 0 when the point is lost */
413 float error{ 0.f }; /**< Tracking error initialized to 0 by the corner detector */
414};
415
Alex Gildayc357c472018-03-21 13:54:09 +0000416/** Internal key point */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100417using InternalKeypoint = std::tuple<float, float, float>; /* x,y,strength */
418
419/** Rectangle type */
420struct Rectangle
421{
422 uint16_t x; /**< Top-left x coordinate */
423 uint16_t y; /**< Top-left y coordinate */
424 uint16_t width; /**< Width of the rectangle */
425 uint16_t height; /**< Height of the rectangle */
426};
427
428/** Coordinate type */
429struct Coordinates2D
430{
431 int32_t x; /**< X coordinates */
432 int32_t y; /**< Y coordinates */
433};
434
435/** Coordinate type */
436struct Coordinates3D
437{
438 uint32_t x; /**< X coordinates */
439 uint32_t y; /**< Y coordinates */
440 uint32_t z; /**< Z coordinates */
441};
442
Giuseppe Rossinid7647d42018-07-17 18:13:13 +0100443/** Padding information as a pair of unsigned int start/end */
444using PaddingInfo = std::pair<uint32_t, uint32_t>;
445
446/** List of padding information */
447using PaddingList = std::vector<PaddingInfo>;
448
giuros013175fcf2018-11-21 09:59:17 +0000449/** Information to produce a tiled version of a Tensor */
450using Multiples = std::vector<uint32_t>;
451
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100452/** Available channels */
453enum class Channel
454{
455 UNKNOWN, /** Unknown channel format */
456 C0, /**< First channel (used by formats with unknown channel types). */
457 C1, /**< Second channel (used by formats with unknown channel types). */
458 C2, /**< Third channel (used by formats with unknown channel types). */
459 C3, /**< Fourth channel (used by formats with unknown channel types). */
460 R, /**< Red channel. */
461 G, /**< Green channel. */
462 B, /**< Blue channel. */
463 A, /**< Alpha channel. */
464 Y, /**< Luma channel. */
465 U, /**< Cb/U channel. */
466 V /**< Cr/V/Value channel. */
467};
468
469/** Available matrix patterns */
470enum class MatrixPattern
471{
472 BOX, /**< Box pattern matrix. */
473 CROSS, /**< Cross pattern matrix. */
474 DISK, /**< Disk pattern matrix. */
475 OTHER /**< Any other matrix pattern. */
476};
477
478/** Available non linear functions. */
479enum class NonLinearFilterFunction : unsigned
480{
481 MEDIAN = 0, /**< Non linear median filter. */
482 MIN = 1, /**< Non linear erode. */
483 MAX = 2, /**< Non linear dilate. */
484};
485
Georgios Pinitasd9769582017-08-03 10:19:40 +0100486/** Available reduction operations */
487enum class ReductionOperation
488{
Michalis Spyrou7930db42018-11-22 17:36:28 +0000489 ARG_IDX_MAX, /**< Index of the max value */
Manuel Bottinib412fab2018-12-10 17:40:23 +0000490 ARG_IDX_MIN, /**< Index of the min value */
491 MEAN_SUM, /**< Mean of sum */
492 PROD, /**< Product */
493 SUM_SQUARE, /**< Sum of squares */
Usama Arifa4a08ad2019-05-20 12:38:33 +0100494 SUM, /**< Sum */
495 MIN, /**< Min */
Usama Arif28f0dd92019-05-20 13:44:34 +0100496 MAX, /**< Max */
Georgios Pinitasd9769582017-08-03 10:19:40 +0100497};
498
giuros01164a2722018-11-20 18:34:46 +0000499/** Available element-wise operations */
500enum class ArithmeticOperation
501{
502 ADD, /**< (x + y) */
503 SUB, /**< (x - y) */
504 DIV, /**< (x / y) */
505 MIN, /**< Min(x, y) */
506 MAX, /**< Max(x, y) */
507 SQUARED_DIFF, /**< (x - y)^2 */
Usama Arif81e671e2019-05-13 13:33:14 +0100508 POWER, /**< x ^ y */
giuros011e6e1b82019-05-14 16:12:53 +0100509 PRELU, /**< y*x if x < 0, x otherwise */
giuros01164a2722018-11-20 18:34:46 +0000510};
511
Michalis Spyroue9362622018-11-23 17:41:37 +0000512/** Available element wise unary operations */
513enum class ElementWiseUnary
514{
515 RSQRT, /**< Reverse square root */
516 EXP, /**< Exponential */
Usama Ariff6e475c2019-05-10 12:06:28 +0100517 NEG, /**< Negate */
Usama Arifc255aa72019-05-13 16:26:29 +0100518 LOG, /**< Natural Logarithm */
Manuel Bottini6ac59922019-05-15 14:06:02 +0100519 ABS, /**< Absolute value */
Michalis Spyrou0af44182019-05-17 14:04:47 +0100520 SIN, /**< Sine */
Usama Arif0a5a57a2019-05-23 14:20:33 +0100521 ROUND, /**< Round */
Michalis Spyroue9362622018-11-23 17:41:37 +0000522};
523
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100524/** The normalization type used for the normalization layer */
525enum class NormType
526{
527 IN_MAP_1D, /**< Normalization applied within the same map in 1D region */
528 IN_MAP_2D, /**< Normalization applied within the same map in 2D region */
529 CROSS_MAP /**< Normalization applied cross maps */
530};
531
532/** Normalization type for Histogram of Oriented Gradients (HOG) */
533enum class HOGNormType
534{
535 L2_NORM = 1, /**< L2-norm */
536 L2HYS_NORM = 2, /**< L2-norm followed by clipping */
537 L1_NORM = 3 /**< L1 norm */
538};
539
540/** Detection window used for the object detection. The detection window keeps the following information:
541 *
542 * -# Geometry of the rectangular window (x/y of top-left corner and width/height)
543 * -# Index of the class used for evaluating which class the detection window belongs to
544 * -# Confidence value (score) obtained with the classifier
545 */
546struct DetectionWindow
547{
548 uint16_t x{ 0 }; /**< Top-left x coordinate */
549 uint16_t y{ 0 }; /**< Top-left y coordinate */
550 uint16_t width{ 0 }; /**< Width of the detection window */
551 uint16_t height{ 0 }; /**< Height of the detection window */
552 uint16_t idx_class{ 0 }; /**< Index of the class */
553 float score{ 0.f }; /**< Confidence value for the detection window */
554};
555
556/** Dimension rounding type when down-scaling on CNNs
557 * @note Used in pooling and convolution layer
558 */
559enum class DimensionRoundingType
560{
561 FLOOR, /**< Floor rounding */
562 CEIL /**< Ceil rounding */
563};
564
565/** Available pooling types */
566enum class PoolingType
567{
568 MAX, /**< Max Pooling */
Georgios Pinitascdf51452017-08-31 14:21:36 +0100569 AVG, /**< Average Pooling */
570 L2 /**< L2 Pooling */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100571};
572
Michalis Spyrou2709d612018-09-19 09:46:47 +0100573/** Available non maxima suppression types */
574enum class NMSType
575{
576 LINEAR, /**< Linear NMS */
577 GAUSSIAN, /**< Gaussian NMS */
578 ORIGINAL /**< Original NMS */
579};
580
581/** BoxWithNonMaximaSuppressionLimit Information class */
582class BoxNMSLimitInfo final
583{
584public:
585 /** Constructor
586 *
587 * @param[in] score_thresh (Optional) Score threshold.
588 * @param[in] nms (Optional) NMS value
589 * @param[in] detections (Optional) Number of detections
590 * @param[in] soft_nms_enabled (Optional) Enable SoftNMS
591 * @param[in] soft_nms_method (Optional) Soft NMS method
592 * @param[in] soft_nms_sigma (Optional) Soft NMS sigma value
593 * @param[in] soft_nms_min_score_thres (Optional) Soft NMS minimum score threshold
Manuel Bottini5209be52019-02-13 16:34:56 +0000594 * @param[in] suppress_size (Optional) Filter out boxes based on their size. Defaults to false
595 * @param[in] min_size (Optional) Smaller boxes than min_size will be filtered out. Defaults to 1
596 * @param[in] im_width (Optional) Boxes whose centers (on the x axis) is beyond im_width will be filtered. Defaults to 1
597 * @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 +0100598 */
599 BoxNMSLimitInfo(float score_thresh = 0.05f, float nms = 0.3f,
600 int detections = 100, bool soft_nms_enabled = false,
601 NMSType soft_nms_method = NMSType::LINEAR,
Manuel Bottini5209be52019-02-13 16:34:56 +0000602 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 +0100603 : _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 +0000604 _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 +0100605 {
606 }
607 /** Get the score threshold */
608 float score_thresh() const
609 {
610 return _score_thresh;
611 }
612 /** Get the NMS */
613 float nms() const
614 {
615 return _nms;
616 }
617 /** Get the number of detections */
618 int detections_per_im() const
619 {
620 return _detections_per_im;
621 }
622 /** Check if soft NMS is enabled */
623 bool soft_nms_enabled() const
624 {
625 return _soft_nms_enabled;
626 }
627 /** Get soft NMS method */
628 NMSType soft_nms_method() const
629 {
630 return _soft_nms_method;
631 }
632 /** Get soft NMS sigma */
633 float soft_nms_sigma() const
634 {
635 return _soft_nms_sigma;
636 }
637 /** Get soft nms min score threshold */
638 float soft_nms_min_score_thres() const
639 {
640 return _soft_nms_min_score_thres;
641 }
Manuel Bottini5209be52019-02-13 16:34:56 +0000642 /** Get if NMS will suppress boxes based on their size/position */
643 bool suppress_size() const
644 {
645 return _suppress_size;
646 }
647 /** Get size suppression threshold */
648 float min_size() const
649 {
650 return _min_size;
651 }
652 /** Get image width (NMS may suppress boxes whose center sits beyond the image width) */
653 float im_width() const
654 {
655 return _im_width;
656 }
657 /** Get image height (NMS may suppress boxes whose center sits beyond the image height) */
658 float im_height() const
659 {
660 return _im_height;
661 }
Michalis Spyrou2709d612018-09-19 09:46:47 +0100662
663private:
664 float _score_thresh;
665 float _nms;
666 int _detections_per_im;
667 bool _soft_nms_enabled;
668 NMSType _soft_nms_method;
669 float _soft_nms_sigma;
670 float _soft_nms_min_score_thres;
Manuel Bottini5209be52019-02-13 16:34:56 +0000671 bool _suppress_size;
672 float _min_size;
673 float _im_width;
674 float _im_height;
Michalis Spyrou2709d612018-09-19 09:46:47 +0100675};
676
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100677/** Padding and stride information class */
678class PadStrideInfo
679{
680public:
681 /** Constructor
682 *
683 * @param[in] stride_x (Optional) Stride, in elements, across x. Defaults to 1.
684 * @param[in] stride_y (Optional) Stride, in elements, across y. Defaults to 1.
685 * @param[in] pad_x (Optional) Padding, in elements, across x. Defaults to 0.
686 * @param[in] pad_y (Optional) Padding, in elements, across y. Defaults to 0.
687 * @param[in] round (Optional) Dimensions rounding. Defaults to @ref FLOOR.
688 */
689 PadStrideInfo(unsigned int stride_x = 1, unsigned int stride_y = 1,
690 unsigned int pad_x = 0, unsigned int pad_y = 0,
691 DimensionRoundingType round = DimensionRoundingType::FLOOR)
692 : _stride(std::make_pair(stride_x, stride_y)),
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100693 _pad_left(pad_x),
694 _pad_top(pad_y),
695 _pad_right(pad_x),
696 _pad_bottom(pad_y),
697 _round_type(round)
698 {
699 }
700 /** Constructor
701 *
702 * @param[in] stride_x Stride, in elements, across x.
703 * @param[in] stride_y Stride, in elements, across y.
704 * @param[in] pad_left Padding across x on the left, in elements.
705 * @param[in] pad_top Padding across y on the top, in elements.
706 * @param[in] pad_right Padding across x on the right, in elements.
707 * @param[in] pad_bottom Padding across y on the bottom, in elements.
708 * @param[in] round Dimensions rounding.
709 */
710 PadStrideInfo(unsigned int stride_x, unsigned int stride_y,
711 unsigned int pad_left, unsigned int pad_right,
712 unsigned int pad_top, unsigned int pad_bottom,
713 DimensionRoundingType round)
714 : _stride(std::make_pair(stride_x, stride_y)),
715 _pad_left(pad_left),
716 _pad_top(pad_top),
717 _pad_right(pad_right),
718 _pad_bottom(pad_bottom),
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100719 _round_type(round)
720 {
721 }
Alex Gildayc357c472018-03-21 13:54:09 +0000722 /** Get the stride.
723 *
724 * @return a pair: stride x, stride y.
725 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100726 std::pair<unsigned int, unsigned int> stride() const
727 {
728 return _stride;
729 }
Alex Gildayc357c472018-03-21 13:54:09 +0000730 /** Check whether the padding is symmetric.
731 *
732 * @return True if the padding is symmetric.
733 */
Anthony Barbier21f67d62018-02-16 15:17:48 +0000734 bool padding_is_symmetric() const
735 {
736 return (_pad_left == _pad_right) && (_pad_top == _pad_bottom);
737 }
Alex Gildayc357c472018-03-21 13:54:09 +0000738 /** Get the padding.
739 *
740 * @note This should only be used when the padding is symmetric.
741 *
742 * @return a pair: padding left/right, padding top/bottom
743 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100744 std::pair<unsigned int, unsigned int> pad() const
745 {
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100746 //this accessor should be used only when padding is symmetric
Anthony Barbier21f67d62018-02-16 15:17:48 +0000747 ARM_COMPUTE_ERROR_ON(!padding_is_symmetric());
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100748 return std::make_pair(_pad_left, _pad_top);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100749 }
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100750
Alex Gildayc357c472018-03-21 13:54:09 +0000751 /** Get the left padding */
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100752 unsigned int pad_left() const
753 {
754 return _pad_left;
755 }
Alex Gildayc357c472018-03-21 13:54:09 +0000756 /** Get the right padding */
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100757 unsigned int pad_right() const
758 {
759 return _pad_right;
760 }
Alex Gildayc357c472018-03-21 13:54:09 +0000761 /** Get the top padding */
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100762 unsigned int pad_top() const
763 {
764 return _pad_top;
765 }
Alex Gildayc357c472018-03-21 13:54:09 +0000766 /** Get the bottom padding */
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100767 unsigned int pad_bottom() const
768 {
769 return _pad_bottom;
770 }
771
Alex Gildayc357c472018-03-21 13:54:09 +0000772 /** Get the rounding type */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100773 DimensionRoundingType round() const
774 {
775 return _round_type;
776 }
777
Alex Gildayc357c472018-03-21 13:54:09 +0000778 /** Check whether this has any padding */
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100779 bool has_padding() const
780 {
781 return (_pad_left != 0 || _pad_top != 0 || _pad_right != 0 || _pad_bottom != 0);
782 }
783
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100784private:
785 std::pair<unsigned int, unsigned int> _stride;
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100786 unsigned int _pad_left;
787 unsigned int _pad_top;
788 unsigned int _pad_right;
789 unsigned int _pad_bottom;
790
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100791 DimensionRoundingType _round_type;
792};
793
Georgios Pinitas7d66a8e2018-07-17 12:28:42 +0100794/** Fully connected layer info */
795struct FullyConnectedLayerInfo
796{
797 DataLayout weights_trained_layout{ DataLayout::NCHW }; /**< Layout that the weights have been trained with. */
798 bool transpose_weights{ true }; /**< Transpose weights if true. */
799 bool are_weights_reshaped{ false }; /**< Reshape the weights tensor if false. */
800 bool retain_internal_weights{ false }; /**< Retain internal reshaped weights. */
Georgios Pinitasc55cef12018-08-01 15:24:18 +0100801
802 /** Sets the weights trained data layout
803 *
804 * @param[in] layout Data layout that the weights were trained with
805 *
806 * @return Updated object
807 */
808 FullyConnectedLayerInfo &set_weights_trained_layout(DataLayout layout)
809 {
810 weights_trained_layout = layout;
811 return *this;
812 }
Georgios Pinitas195b0ba2018-08-02 17:18:51 +0100813 /** Sets the transpose weights flag
814 *
815 * @param[in] should_transpose_weights Boolean flag indicating if weights should be transposed
816 *
817 * @return Updated object
818 */
819 FullyConnectedLayerInfo &set_transpose_weights(bool should_transpose_weights)
820 {
821 transpose_weights = should_transpose_weights;
822 return *this;
823 }
Georgios Pinitas7d66a8e2018-07-17 12:28:42 +0100824};
825
Michalis Spyrou6c7c38e2018-08-29 16:28:11 +0100826/** PriorBox layer info */
827class PriorBoxLayerInfo final
828{
829public:
830 /** Default Constructor */
831 PriorBoxLayerInfo()
832 : _min_sizes(),
833 _variances(),
834 _offset(),
835 _flip(true),
836 _clip(false),
837 _max_sizes(),
838 _aspect_ratios(),
839 _img_size(),
840 _steps()
841 {
842 }
843 /** Constructor
844 *
845 * @param[in] min_sizes Min sizes vector.
Michalis Spyrou721c4cb2018-09-04 15:27:25 +0100846 * @param[in] variances Variances vector.
Michalis Spyrou6c7c38e2018-08-29 16:28:11 +0100847 * @param[in] offset Offset value.
848 * @param[in] flip (Optional) Flip the aspect ratios.
849 * @param[in] clip (Optional) Clip coordinates so that they're within [0,1].
850 * @param[in] max_sizes (Optional) Max sizes vector.
851 * @param[in] aspect_ratios (Optional) Aspect ratios of the boxes.
852 * @param[in] img_size (Optional) Image size.
853 * @param[in] steps (Optional) Step values.
854 */
855 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 +0000856 const std::vector<float> &max_sizes = {}, const std::vector<float> &aspect_ratios = {},
857 const Coordinates2D &img_size = Coordinates2D{ 0, 0 }, const std::array<float, 2> &steps = { { 0.f, 0.f } })
Michalis Spyrou6c7c38e2018-08-29 16:28:11 +0100858 : _min_sizes(min_sizes),
859 _variances(variances),
860 _offset(offset),
861 _flip(flip),
862 _clip(clip),
863 _max_sizes(max_sizes),
Michalis Spyrou721c4cb2018-09-04 15:27:25 +0100864 _aspect_ratios(),
Michalis Spyrou6c7c38e2018-08-29 16:28:11 +0100865 _img_size(img_size),
866 _steps(steps)
867 {
868 _aspect_ratios.push_back(1.);
869 for(unsigned int i = 0; i < aspect_ratios.size(); ++i)
870 {
871 float ar = aspect_ratios[i];
872 bool already_exist = false;
873 for(auto ar_new : _aspect_ratios)
874 {
875 if(fabs(ar - ar_new) < 1e-6)
876 {
877 already_exist = true;
878 break;
879 }
880 }
881 if(!already_exist)
882 {
883 _aspect_ratios.push_back(ar);
884 if(flip)
885 {
886 _aspect_ratios.push_back(1.f / ar);
887 }
888 }
889 }
890 }
891 /** Get min sizes. */
892 std::vector<float> min_sizes() const
893 {
894 return _min_sizes;
895 }
896 /** Get min variances. */
897 std::vector<float> variances() const
898 {
899 return _variances;
900 }
901 /** Get the step coordinates */
902 std::array<float, 2> steps() const
903 {
904 return _steps;
905 }
906 /** Get the image size coordinates */
907 Coordinates2D img_size() const
908 {
909 return _img_size;
910 }
911 /** Get the offset */
912 float offset() const
913 {
914 return _offset;
915 }
916 /** Get the flip value */
917 bool flip() const
918 {
919 return _flip;
920 }
921 /** Get the clip value */
922 bool clip() const
923 {
924 return _clip;
925 }
926 /** Get max sizes. */
927 std::vector<float> max_sizes() const
928 {
929 return _max_sizes;
930 }
931 /** Get aspect ratios. */
932 std::vector<float> aspect_ratios() const
933 {
934 return _aspect_ratios;
935 }
936
937private:
938 std::vector<float> _min_sizes;
939 std::vector<float> _variances;
940 float _offset;
941 bool _flip;
942 bool _clip;
943 std::vector<float> _max_sizes;
944 std::vector<float> _aspect_ratios;
945 Coordinates2D _img_size;
946 std::array<float, 2> _steps;
947};
948
Isabella Gottardia7acb3c2019-01-08 13:48:44 +0000949// Bounding Box [xmin, ymin, xmax, ymax]
950using BBox = std::array<float, 4>;
951// LabelBBox used for map label and bounding box
952using LabelBBox = std::map<int, std::vector<BBox>>;
953
Isabella Gottardi05e56442018-11-16 11:26:52 +0000954/** Available Detection Output code types */
955enum class DetectionOutputLayerCodeType
956{
957 CORNER, /**< Use box corners */
958 CENTER_SIZE, /**< Use box centers and size */
959 CORNER_SIZE, /**< Use box centers and size */
960 TF_CENTER /**< Use box centers and size but flip x and y co-ordinates */
961};
962
963/** Detection Output layer info */
964class DetectionOutputLayerInfo final
965{
966public:
967 /** Default Constructor */
968 DetectionOutputLayerInfo()
969 : _num_classes(),
970 _share_location(),
971 _code_type(DetectionOutputLayerCodeType::CORNER),
972 _keep_top_k(),
973 _nms_threshold(),
974 _top_k(),
975 _background_label_id(),
976 _confidence_threshold(),
977 _variance_encoded_in_target(false),
978 _eta(),
979 _num_loc_classes()
980 {
981 _num_loc_classes = _share_location ? 1 : _num_classes;
982 }
983 /** Constructor
984 *
985 * @param[in] num_classes Number of classes to be predicted.
986 * @param[in] share_location If true, bounding box are shared among different classes.
987 * @param[in] code_type Type of coding method for bbox.
988 * @param[in] keep_top_k Number of total bounding boxes to be kept per image after NMS step.
989 * @param[in] nms_threshold Threshold to be used in NMS.
990 * @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.
991 * @param[in] background_label_id (Optional) Background label ID. If there is no background class, set it as -1.
992 * @param[in] confidence_threshold (Optional) Only consider detections whose confidences are larger than a threshold. Default set to -FLT_MAX.
993 * @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.
994 * @param[in] eta (Optional) Eta.
995 */
996 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,
997 float confidence_threshold = std::numeric_limits<float>::lowest(), bool variance_encoded_in_target = false, float eta = 1)
998 : _num_classes(num_classes),
999 _share_location(share_location),
1000 _code_type(code_type),
1001 _keep_top_k(keep_top_k),
1002 _nms_threshold(nms_threshold),
1003 _top_k(top_k),
1004 _background_label_id(background_label_id),
1005 _confidence_threshold(confidence_threshold),
1006 _variance_encoded_in_target(variance_encoded_in_target),
1007 _eta(eta),
1008 _num_loc_classes()
1009 {
1010 _num_loc_classes = _share_location ? 1 : _num_classes;
1011 }
1012 /** Get num classes. */
1013 int num_classes() const
1014 {
1015 return _num_classes;
1016 }
1017 /** Get share location. */
1018 bool share_location() const
1019 {
1020 return _share_location;
1021 }
1022 /** Get detection output code type. */
1023 DetectionOutputLayerCodeType code_type() const
1024 {
1025 return _code_type;
1026 }
1027 /** Get if variance encoded in target. */
1028 bool variance_encoded_in_target() const
1029 {
1030 return _variance_encoded_in_target;
1031 }
1032 /** Get the number of total bounding boxes to be kept per image. */
1033 int keep_top_k() const
1034 {
1035 return _keep_top_k;
1036 }
1037 /** Get nms threshold. */
1038 float nms_threshold() const
1039 {
1040 return _nms_threshold;
1041 }
1042 /** Get eta. */
1043 float eta() const
1044 {
1045 return _eta;
1046 }
1047 /** Get background label ID. */
1048 int background_label_id() const
1049 {
1050 return _background_label_id;
1051 }
1052 /** Get confidence threshold. */
1053 float confidence_threshold() const
1054 {
1055 return _confidence_threshold;
1056 }
1057 /** Get top K. */
1058 int top_k() const
1059 {
1060 return _top_k;
1061 }
1062 /** Get number of location classes. */
1063 int num_loc_classes() const
1064 {
1065 return _num_loc_classes;
1066 }
1067
1068private:
1069 int _num_classes;
1070 bool _share_location;
1071 DetectionOutputLayerCodeType _code_type;
1072 int _keep_top_k;
1073 float _nms_threshold;
1074 int _top_k;
1075 int _background_label_id;
1076 float _confidence_threshold;
1077 bool _variance_encoded_in_target;
1078 float _eta;
1079 int _num_loc_classes;
1080};
1081
Isabella Gottardia7acb3c2019-01-08 13:48:44 +00001082/** Detection Output layer info */
1083class DetectionPostProcessLayerInfo final
1084{
1085public:
1086 /** Default Constructor */
1087 DetectionPostProcessLayerInfo()
1088 : _max_detections(),
1089 _max_classes_per_detection(),
1090 _nms_score_threshold(),
1091 _iou_threshold(),
1092 _num_classes(),
1093 _scales_values(),
1094 _use_regular_nms(),
1095 _detection_per_class()
1096 {
1097 }
1098 /** Constructor
1099 *
1100 * @param[in] max_detections Number of total detection.
1101 * @param[in] max_classes_per_detection Number of total classes to be kept after NMS step. Used in the Fast Non-Max-Suppression
1102 * @param[in] nms_score_threshold Threshold to be used in NMS
1103 * @param[in] iou_threshold Threshold to be used during the intersection over union.
1104 * @param[in] num_classes Number of classes.
1105 * @param[in] scales_values Scales values used for decode center size boxes.
1106 * @param[in] use_regular_nms (Optional) Boolean to determinate if use regular or fast nms.
1107 * @param[in] detection_per_class (Optional) Number of detection per class. Used in the Regular Non-Max-Suppression
1108 */
1109 DetectionPostProcessLayerInfo(unsigned int max_detections, unsigned int max_classes_per_detection, float nms_score_threshold, float iou_threshold, unsigned int num_classes,
1110 std::array<float, 4> scales_values, bool use_regular_nms = false, unsigned int detection_per_class = 100)
1111 : _max_detections(max_detections),
1112 _max_classes_per_detection(max_classes_per_detection),
1113 _nms_score_threshold(nms_score_threshold),
1114 _iou_threshold(iou_threshold),
1115 _num_classes(num_classes),
1116 _scales_values(scales_values),
1117 _use_regular_nms(use_regular_nms),
1118 _detection_per_class(detection_per_class)
1119 {
1120 }
1121 /** Get max detections. */
1122 unsigned int max_detections() const
1123 {
1124 return _max_detections;
1125 }
1126 /** Get max_classes per detection. Used in the Fast Non-Max-Suppression.*/
1127 unsigned int max_classes_per_detection() const
1128 {
1129 return _max_classes_per_detection;
1130 }
1131 /** Get detection per class. Used in the Regular Non-Max-Suppression */
1132 unsigned int detection_per_class() const
1133 {
1134 return _detection_per_class;
1135 }
1136 /** Get nms threshold. */
1137 float nms_score_threshold() const
1138 {
1139 return _nms_score_threshold;
1140 }
1141 /** Get intersection over union threshold. */
1142 float iou_threshold() const
1143 {
1144 return _iou_threshold;
1145 }
1146 /** Get num classes. */
1147 unsigned int num_classes() const
1148 {
1149 return _num_classes;
1150 }
1151 /** Get if use regular nms. */
1152 bool use_regular_nms() const
1153 {
1154 return _use_regular_nms;
1155 }
1156 /** Get y scale value. */
1157 float scale_value_y() const
1158 {
1159 // Saved as [y,x,h,w]
1160 return _scales_values[0];
1161 }
1162 /** Get x scale value. */
1163 float scale_value_x() const
1164 {
1165 // Saved as [y,x,h,w]
1166 return _scales_values[1];
1167 }
1168 /** Get h scale value. */
1169 float scale_value_h() const
1170 {
1171 // Saved as [y,x,h,w]
1172 return _scales_values[2];
1173 }
1174 /** Get w scale value. */
1175 float scale_value_w() const
1176 {
1177 // Saved as [y,x,h,w]
1178 return _scales_values[3];
1179 }
1180
1181private:
1182 unsigned int _max_detections;
1183 unsigned int _max_classes_per_detection;
1184 float _nms_score_threshold;
1185 float _iou_threshold;
1186 unsigned int _num_classes;
1187 std::array<float, 4> _scales_values;
1188 bool _use_regular_nms;
1189 unsigned int _detection_per_class;
1190};
1191
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001192/** Pooling Layer Information class */
1193class PoolingLayerInfo
1194{
1195public:
Georgios Pinitas4c2dd542017-11-13 12:58:41 +00001196 /** Default Constructor */
1197 PoolingLayerInfo()
Sang-Hoon Park2aa7fd02019-09-18 13:39:00 +01001198 : _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 +00001199 {
1200 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001201 /** Default Constructor
1202 *
Sang-Hoon Park2aa7fd02019-09-18 13:39:00 +01001203 * @param[in] pool_type Pooling type @ref PoolingType.
1204 * @param[in] pool_size Pooling size, in elements, across x and y.
1205 * @param[in] pad_stride_info (Optional) Padding and stride information @ref PadStrideInfo
1206 * @param[in] exclude_padding (Optional) Strategy when accounting padding in calculations.
1207 * True will exclude padding while false will not (Used in AVG/L2 pooling to determine the pooling area).
1208 * Defaults to false;
1209 * @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 +01001210 */
Georgios Pinitas4c2dd542017-11-13 12:58:41 +00001211 explicit PoolingLayerInfo(PoolingType pool_type,
1212 unsigned int pool_size,
Sang-Hoon Park2aa7fd02019-09-18 13:39:00 +01001213 PadStrideInfo pad_stride_info = PadStrideInfo(),
1214 bool exclude_padding = false,
1215 bool fp_mixed_precision = false)
1216 : _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),
1217 _fp_mixed_precision(fp_mixed_precision)
Isabella Gottardi6e464c32018-01-26 12:32:45 +00001218 {
1219 }
1220 /** Default Constructor
1221 *
Sang-Hoon Park2aa7fd02019-09-18 13:39:00 +01001222 * @param[in] pool_type Pooling type @ref PoolingType.
1223 * @param[in] pool_size Pooling size, in elements, across x and y.
1224 * @param[in] pad_stride_info (Optional) Padding and stride information @ref PadStrideInfo
1225 * @param[in] exclude_padding (Optional) Strategy when accounting padding in calculations.
1226 * True will exclude padding while false will not (Used in AVG/L2 pooling to determine the pooling area).
1227 * Defaults to false;
1228 * @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 +00001229 */
1230 explicit PoolingLayerInfo(PoolingType pool_type,
1231 Size2D pool_size,
Sang-Hoon Park2aa7fd02019-09-18 13:39:00 +01001232 PadStrideInfo pad_stride_info = PadStrideInfo(),
1233 bool exclude_padding = false,
1234 bool fp_mixed_precision = false)
1235 : _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 +00001236 {
1237 }
1238 /** Default Constructor
1239 *
1240 * @note This constructor is used for global pooling
1241 *
1242 * @param[in] pool_type Pooling type @ref PoolingType.
1243 */
1244 explicit PoolingLayerInfo(PoolingType pool_type)
Sang-Hoon Park2aa7fd02019-09-18 13:39:00 +01001245 : _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 +01001246 {
1247 }
Alex Gildayc357c472018-03-21 13:54:09 +00001248 /** Get the pooling type */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001249 PoolingType pool_type() const
1250 {
1251 return _pool_type;
1252 }
Alex Gildayc357c472018-03-21 13:54:09 +00001253 /** Get the pooling size */
Isabella Gottardi6e464c32018-01-26 12:32:45 +00001254 const Size2D &pool_size() const
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001255 {
1256 return _pool_size;
1257 }
Alex Gildayc357c472018-03-21 13:54:09 +00001258 /** Get the padding and stride */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001259 PadStrideInfo pad_stride_info() const
1260 {
1261 return _pad_stride_info;
1262 }
Alex Gildayc357c472018-03-21 13:54:09 +00001263 /** Check if padding is excluded in calculations */
Georgios Pinitasadaae7e2017-10-30 15:56:32 +00001264 bool exclude_padding() const
1265 {
1266 return _exclude_padding;
1267 }
Sang-Hoon Park2aa7fd02019-09-18 13:39:00 +01001268 /** Check if a wider accumulator should be used. */
1269 bool fp_mixed_precision() const
1270 {
1271 return _fp_mixed_precision;
1272 }
Alex Gildayc357c472018-03-21 13:54:09 +00001273 /** Check if is global pooling */
Georgios Pinitas4c2dd542017-11-13 12:58:41 +00001274 bool is_global_pooling() const
1275 {
1276 return _is_global_pooling;
1277 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001278
1279private:
1280 PoolingType _pool_type;
Isabella Gottardi6e464c32018-01-26 12:32:45 +00001281 Size2D _pool_size;
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001282 PadStrideInfo _pad_stride_info;
Georgios Pinitasadaae7e2017-10-30 15:56:32 +00001283 bool _exclude_padding;
Georgios Pinitas4c2dd542017-11-13 12:58:41 +00001284 bool _is_global_pooling;
Sang-Hoon Park2aa7fd02019-09-18 13:39:00 +01001285 bool _fp_mixed_precision;
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001286};
1287
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001288/** ROI Pooling Layer Information class */
giuros0118870812018-09-13 09:31:40 +01001289class ROIPoolingLayerInfo final
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001290{
1291public:
giuros0118870812018-09-13 09:31:40 +01001292 /** Constructor
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001293 *
giuros0118870812018-09-13 09:31:40 +01001294 * @param[in] pooled_width Pooled width of the layer.
1295 * @param[in] pooled_height Pooled height of the layer.
1296 * @param[in] spatial_scale Spatial scale to be applied to the ROI coordinates and dimensions.
1297 * @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 +01001298 */
giuros0118870812018-09-13 09:31:40 +01001299 ROIPoolingLayerInfo(unsigned int pooled_width, unsigned int pooled_height, float spatial_scale, unsigned int sampling_ratio = 0)
1300 : _pooled_width(pooled_width), _pooled_height(pooled_height), _spatial_scale(spatial_scale), _sampling_ratio(sampling_ratio)
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001301 {
1302 }
Alex Gildayc357c472018-03-21 13:54:09 +00001303 /** Get the pooled width of the layer */
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001304 unsigned int pooled_width() const
1305 {
1306 return _pooled_width;
1307 }
Alex Gildayc357c472018-03-21 13:54:09 +00001308 /** Get the pooled height of the layer */
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001309 unsigned int pooled_height() const
1310 {
1311 return _pooled_height;
1312 }
Alex Gildayc357c472018-03-21 13:54:09 +00001313 /** Get the spatial scale */
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001314 float spatial_scale() const
1315 {
1316 return _spatial_scale;
1317 }
giuros0118870812018-09-13 09:31:40 +01001318 /** Get sampling ratio */
1319 unsigned int sampling_ratio() const
1320 {
1321 return _sampling_ratio;
1322 }
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001323
1324private:
1325 unsigned int _pooled_width;
1326 unsigned int _pooled_height;
1327 float _spatial_scale;
giuros0118870812018-09-13 09:31:40 +01001328 unsigned int _sampling_ratio;
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001329};
1330
Manuel Bottini5209be52019-02-13 16:34:56 +00001331/** Generate Proposals Information class */
1332class GenerateProposalsInfo
1333{
1334public:
1335 /** Constructor
1336 *
1337 * @param[in] im_width Width of the original image
1338 * @param[in] im_height Height of the original image
1339 * @param[in] im_scale Scale applied to the original image
1340 * @param[in] spatial_scale (Optional)Scale applied to the feature map. Defaults to 1.0
1341 * @param[in] pre_nms_topN (Optional)Number of the best scores to be selected from the transformations. Defaults to 6000.
1342 * @param[in] post_nms_topN (Optional)Number of the best scores to be selected from the NMS operation. Defaults to 300.
1343 * @param[in] nms_thres (Optional)NMS overlap threshold. Defaults to 0.7.
1344 * @param[in] min_size (Optional)Size used to validate the anchors produced. Defaults to 16.
1345 * @param[in] values_per_roi (Optional)Values used to represent a ROI(Region of interest). Defaults to 4.
1346 */
1347 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,
1348 size_t values_per_roi = 4)
1349 : _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),
1350 _min_size(min_size), _values_per_roi(values_per_roi)
1351 {
1352 }
1353
1354 /* Get the original height */
1355 float im_height() const
1356 {
1357 return _im_height;
1358 }
1359 /* Get the original width */
1360 float im_width() const
1361 {
1362 return _im_width;
1363 }
1364 /* Get the image scale */
1365 float im_scale() const
1366 {
1367 return _im_scale;
1368 }
1369 /* Get the value of how many best scores to select (before NMS) */
1370 int pre_nms_topN() const
1371 {
1372 return _pre_nms_topN;
1373 }
1374 /* Get the value of how many best scores to select (after NMS) */
1375 int post_nms_topN() const
1376 {
1377 return _post_nms_topN;
1378 }
1379 /* Get the NMS overlap threshold */
1380 float nms_thres() const
1381 {
1382 return _nms_thres;
1383 }
1384 /* Get the minimal size */
1385 float min_size() const
1386 {
1387 return _min_size;
1388 }
1389 /* Get the spatial scale to be applied to the feature maps */
1390 float spatial_scale() const
1391 {
1392 return _spatial_scale;
1393 }
1394 /* Get the values used to represent a ROI(Region of interest)*/
1395 size_t values_per_roi() const
1396 {
1397 return _values_per_roi;
1398 }
1399
1400private:
1401 float _im_height;
1402 float _im_width;
1403 float _im_scale;
1404 float _spatial_scale;
1405 int _pre_nms_topN;
1406 int _post_nms_topN;
1407 float _nms_thres;
1408 float _min_size;
1409 size_t _values_per_roi;
1410};
1411
1412/** ComputeAnchors information class */
1413class ComputeAnchorsInfo
1414{
1415public:
1416 /** Constructor
1417 *
1418 * @param[in] feat_width Feature map width
1419 * @param[in] feat_height Feature map height
1420 * @param[in] spatial_scale Feature map scale
1421 * @param[in] values_per_roi (Optional)Values used to represent a ROI(Region Of Interest). Defaults to 4
1422 */
1423 ComputeAnchorsInfo(float feat_width, float feat_height, float spatial_scale, size_t values_per_roi = 4)
1424 : _feat_height(feat_height),
1425 _feat_width(feat_width),
1426 _spatial_scale(spatial_scale),
1427 _values_per_roi(values_per_roi)
1428 {
1429 }
1430
1431 /* Get the height of the feature map */
1432 float feat_height() const
1433 {
1434 return _feat_height;
1435 }
1436
1437 /* Get the width of the feature map */
1438 float feat_width() const
1439 {
1440 return _feat_width;
1441 }
1442
1443 /* Get the scale of the feature map */
1444 float spatial_scale() const
1445 {
1446 return _spatial_scale;
1447 }
1448
1449 /* Get the values used to represent a ROI(Region Of Interest)*/
1450 size_t values_per_roi() const
1451 {
1452 return _values_per_roi;
1453 }
1454
1455private:
1456 float _feat_height;
1457 float _feat_width;
1458 float _spatial_scale;
1459 size_t _values_per_roi;
1460};
1461
giuros01c04a0e82018-10-03 12:44:35 +01001462/** Bounding Box Transform information class */
giuros01d696cb62018-11-16 10:39:59 +00001463class BoundingBoxTransformInfo final
giuros01c04a0e82018-10-03 12:44:35 +01001464{
1465public:
1466 /** Constructor
1467 *
giuros01d696cb62018-11-16 10:39:59 +00001468 * @param[in] img_width Width of the original image
1469 * @param[in] img_height Height, of the original image
1470 * @param[in] scale Scale of the original image
1471 * @param[in] apply_scale (Optional)Re-apply scaling after transforming the boxes. Defaults to false
1472 * @param[in] weights (Optional)Weights [wx, wy, ww, wh] for the deltas. Defaults to all ones
1473 * @param[in] correct_transform_coords (Optional)Correct bounding box transform coordinates. Defaults to false
1474 * @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 +01001475 */
giuros01d696cb62018-11-16 10:39:59 +00001476 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 =
1477 false,
1478 float bbox_xform_clip =
1479 4.135166556742356f)
1480 : _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 +01001481 {
1482 }
1483
1484 std::array<float, 4> weights() const
1485 {
1486 return _weights;
1487 }
1488
1489 float bbox_xform_clip() const
1490 {
1491 return _bbox_xform_clip;
1492 }
1493
1494 float img_height() const
1495 {
1496 return _img_height;
1497 }
1498
1499 float img_width() const
1500 {
1501 return _img_width;
1502 }
1503
1504 float scale() const
1505 {
1506 return _scale;
1507 }
1508
1509 bool apply_scale() const
1510 {
1511 return _apply_scale;
1512 }
1513
giuros01d696cb62018-11-16 10:39:59 +00001514 bool correct_transform_coords() const
1515 {
1516 return _correct_transform_coords;
1517 }
1518
giuros01c04a0e82018-10-03 12:44:35 +01001519private:
1520 float _img_width;
1521 float _img_height;
1522 float _scale;
1523 bool _apply_scale;
giuros01d696cb62018-11-16 10:39:59 +00001524 bool _correct_transform_coords;
giuros01c04a0e82018-10-03 12:44:35 +01001525 std::array<float, 4> _weights;
1526 float _bbox_xform_clip;
1527};
1528
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001529/** Activation Layer Information class */
1530class ActivationLayerInfo
1531{
1532public:
1533 /** Available activation functions */
1534 enum class ActivationFunction
1535 {
Georgios Pinitas64ebe5b2017-09-01 17:44:24 +01001536 LOGISTIC, /**< Logistic ( \f$ f(x) = \frac{1}{1 + e^{-x}} \f$ ) */
1537 TANH, /**< Hyperbolic tangent ( \f$ f(x) = a \cdot tanh(b \cdot x) \f$ ) */
1538 RELU, /**< Rectifier ( \f$ f(x) = max(0,x) \f$ ) */
1539 BOUNDED_RELU, /**< Upper Bounded Rectifier ( \f$ f(x) = min(a, max(0,x)) \f$ ) */
1540 LU_BOUNDED_RELU, /**< Lower and Upper Bounded Rectifier ( \f$ f(x) = min(a, max(b,x)) \f$ ) */
Manuel Bottini581c8982019-02-07 10:31:57 +00001541 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 +01001542 SOFT_RELU, /**< Soft Rectifier ( \f$ f(x)= log(1+e^x) \f$ ) */
Georgios Pinitasfb0fdcd2019-08-22 17:10:04 +01001543 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 +01001544 ABS, /**< Absolute ( \f$ f(x)= |x| \f$ ) */
1545 SQUARE, /**< Square ( \f$ f(x)= x^2 \f$ )*/
1546 SQRT, /**< Square root ( \f$ f(x) = \sqrt{x} \f$ )*/
Usama Arif6a98a6e2019-05-10 17:07:27 +01001547 LINEAR, /**< Linear ( \f$ f(x)= ax + b \f$ ) */
1548 IDENTITY /**< Identity ( \f$ f(x)= x \f$ ) */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001549 };
1550
Giorgio Arena11674872018-02-07 15:38:12 +00001551 ActivationLayerInfo() = default;
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001552 /** Default Constructor
1553 *
1554 * @param[in] f The activation function to use.
1555 * @param[in] a (Optional) The alpha parameter used by some activation functions
Georgios Pinitas64ebe5b2017-09-01 17:44:24 +01001556 * (@ref ActivationFunction::BOUNDED_RELU, @ref ActivationFunction::LU_BOUNDED_RELU, @ref ActivationFunction::LINEAR, @ref ActivationFunction::TANH).
1557 * @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 +01001558 */
1559 ActivationLayerInfo(ActivationFunction f, float a = 0.0f, float b = 0.0f)
Giorgio Arena11674872018-02-07 15:38:12 +00001560 : _act(f), _a(a), _b(b), _enabled(true)
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001561 {
1562 }
Alex Gildayc357c472018-03-21 13:54:09 +00001563 /** Get the type of activation function */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001564 ActivationFunction activation() const
1565 {
1566 return _act;
1567 }
Alex Gildayc357c472018-03-21 13:54:09 +00001568 /** Get the alpha value */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001569 float a() const
1570 {
1571 return _a;
1572 }
Alex Gildayc357c472018-03-21 13:54:09 +00001573 /** Get the beta value */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001574 float b() const
1575 {
1576 return _b;
1577 }
Alex Gildayc357c472018-03-21 13:54:09 +00001578 /** Check if initialised */
Giorgio Arena11674872018-02-07 15:38:12 +00001579 bool enabled() const
1580 {
1581 return _enabled;
1582 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001583
1584private:
Usama Arif6a98a6e2019-05-10 17:07:27 +01001585 ActivationFunction _act = { ActivationLayerInfo::ActivationFunction::IDENTITY };
Giorgio Arena11674872018-02-07 15:38:12 +00001586 float _a = {};
1587 float _b = {};
1588 bool _enabled = { false };
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001589};
1590
1591/** Normalization Layer Information class */
1592class NormalizationLayerInfo
1593{
1594public:
1595 /** Default Constructor
1596 *
Michele Di Giorgio9d3a8312018-11-20 12:31:24 +00001597 * @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 +01001598 * @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 +00001599 * @param[in] alpha (Optional) Alpha parameter used by normalization equation. Defaults to 0.0001.
1600 * @param[in] beta (Optional) Beta parameter used by normalization equation. Defaults to 0.5.
1601 * @param[in] kappa (Optional) Kappa parameter used by [Krichevksy 2012] Across Channel Local Brightness Normalization equation.
1602 * @param[in] is_scaled (Optional) Boolean that specifies if alpha will be scaled by the normalization size or not.
1603 * Should be false to follow [Krichevksy 2012].
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001604 */
Georgios Pinitas41caa622017-11-16 14:37:08 +00001605 NormalizationLayerInfo(NormType type, uint32_t norm_size = 5, float alpha = 0.0001f, float beta = 0.5f, float kappa = 1.f, bool is_scaled = true)
1606 : _type(type), _norm_size(norm_size), _alpha(alpha), _beta(beta), _kappa(kappa), _is_scaled(is_scaled)
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001607 {
1608 }
Alex Gildayc357c472018-03-21 13:54:09 +00001609 /** Get the normalization type */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001610 NormType type() const
1611 {
1612 return _type;
1613 }
Alex Gildayc357c472018-03-21 13:54:09 +00001614 /** Get the normalization size */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001615 uint32_t norm_size() const
1616 {
1617 return _norm_size;
1618 }
Alex Gildayc357c472018-03-21 13:54:09 +00001619 /** Get the alpha value */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001620 float alpha() const
1621 {
1622 return _alpha;
1623 }
Alex Gildayc357c472018-03-21 13:54:09 +00001624 /** Get the beta value */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001625 float beta() const
1626 {
1627 return _beta;
1628 }
Alex Gildayc357c472018-03-21 13:54:09 +00001629 /** Get the kappa value */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001630 float kappa() const
1631 {
1632 return _kappa;
1633 }
Michele Di Giorgio9d3a8312018-11-20 12:31:24 +00001634 /** Get the is_scaled value */
1635 bool is_scaled() const
1636 {
1637 return _is_scaled;
1638 }
Alex Gildayc357c472018-03-21 13:54:09 +00001639 /** Check if normalization is cross map */
Georgios Pinitas41caa622017-11-16 14:37:08 +00001640 bool is_cross_map() const
1641 {
1642 return _type == NormType::CROSS_MAP;
1643 }
Alex Gildayc357c472018-03-21 13:54:09 +00001644 /** Check if normalization is not cross map */
Georgios Pinitas41caa622017-11-16 14:37:08 +00001645 bool is_in_map() const
1646 {
1647 return !is_cross_map();
1648 }
1649 /** Return the scaling factor of the normalization function.
1650 *
1651 * If is_scaled is set to false then [Krichevksy 2012] normalization scaling is performed,
1652 * 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 +01001653 *
1654 * @return The normalization scaling factor.
1655 */
1656 float scale_coeff() const
1657 {
1658 const uint32_t size = (_type == NormType::IN_MAP_2D) ? _norm_size * _norm_size : _norm_size;
Georgios Pinitas41caa622017-11-16 14:37:08 +00001659 return (_is_scaled) ? (_alpha / size) : _alpha;
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001660 }
1661
1662private:
1663 NormType _type;
1664 uint32_t _norm_size;
1665 float _alpha;
1666 float _beta;
1667 float _kappa;
Georgios Pinitas41caa622017-11-16 14:37:08 +00001668 bool _is_scaled;
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001669};
1670
Gian Marco Iodice559d7712017-08-08 08:38:09 +01001671/** 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 +01001672class WeightsInfo
1673{
1674public:
Gian Marco Iodice4e288692017-06-27 11:41:59 +01001675 /** Default constructor */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001676 WeightsInfo()
Michele Di Giorgiob62280a2018-05-31 17:31:05 +01001677 : _are_reshaped(false), _kernel_width(0), _kernel_height(0), _num_kernels(0), _retain_internal_weights(false)
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001678 {
1679 }
1680 /** Constructor
1681 *
Michele Di Giorgiob62280a2018-05-31 17:31:05 +01001682 * @param[in] are_reshaped True if the weights have been reshaped
1683 * @param[in] kernel_width Kernel width.
1684 * @param[in] kernel_height Kernel height.
1685 * @param[in] num_kernels Number of convolution kernels.
1686 * @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 +01001687 */
Michele Di Giorgiob62280a2018-05-31 17:31:05 +01001688 WeightsInfo(bool are_reshaped, unsigned int kernel_width, unsigned int kernel_height, unsigned int num_kernels, bool retain_internal_weights = false)
1689 : _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 +01001690 {
1691 }
Gian Marco Iodice4e288692017-06-27 11:41:59 +01001692 /** Flag which specifies if the weights tensor has been reshaped.
1693 *
1694 * @return True if the weights tensors has been reshaped
1695 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001696 bool are_reshaped() const
1697 {
1698 return _are_reshaped;
1699 };
Gian Marco Iodice559d7712017-08-08 08:38:09 +01001700 /** Return the number of convolution kernels
1701 *
1702 * @return The number of convolution kernels
1703 */
1704 unsigned int num_kernels() const
1705 {
1706 return _num_kernels;
1707 };
Gian Marco Iodice4e288692017-06-27 11:41:59 +01001708 /** Return the width and height of the kernel
1709 *
1710 * @return The width and height of the kernel
1711 */
1712 std::pair<unsigned int, unsigned int> kernel_size() const
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001713 {
Gian Marco Iodice4e288692017-06-27 11:41:59 +01001714 return std::make_pair(_kernel_width, _kernel_height);
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001715 }
Michele Di Giorgiob62280a2018-05-31 17:31:05 +01001716 bool retain_internal_weights() const
1717 {
1718 return _retain_internal_weights;
1719 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001720
1721private:
1722 const bool _are_reshaped;
Gian Marco Iodice4e288692017-06-27 11:41:59 +01001723 const unsigned int _kernel_width;
1724 const unsigned int _kernel_height;
Gian Marco Iodice559d7712017-08-08 08:38:09 +01001725 const unsigned int _num_kernels;
Michele Di Giorgiob62280a2018-05-31 17:31:05 +01001726 const bool _retain_internal_weights;
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001727};
1728
Gian Marco36a0a462018-01-12 10:21:40 +00001729/** GEMM reshape information class. This class stores the necessary information about matrix A and matrix B reshape.
1730 *
Gian Marco Iodice5fc07aa2019-05-15 17:08:02 +01001731 * The matrix A can only be reshaped through @ref CLGEMMReshapeLHSMatrixKernel or @ref NEGEMMInterleave4x4Kernel or @ref GCGEMMInterleave4x4Kernel
1732 * 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 +00001733 *
giuros018b6b4a92018-12-18 19:01:33 +00001734 * The matrix B can only be reshaped through @ref CLGEMMReshapeRHSMatrixKernel or @ref NEGEMMTranspose1xWKernel or @ref GCGEMMTranspose1xWKernel
1735 * 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 +00001736 *
1737 */
1738class GEMMReshapeInfo final
1739{
1740public:
1741 /** Default constructor */
1742 GEMMReshapeInfo()
Georgios Pinitasb0f342e2019-05-21 13:32:43 +01001743 : _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 +00001744 {
1745 }
1746 /** Constructor
1747 *
1748 * @param[in] m Number of matrix A rows
1749 * @param[in] n Number of matrix B columns
1750 * @param[in] k Number of matrix A columns or matrix B rows
1751 * @param[in] mult_transpose1xW_width (Optional) Multiplication factor for the width of the 1xW transposed block
1752 * @param[in] mult_interleave4x4_height (Optional) Multiplication factor for the height of the 4x4 interleaved block
Gian Marco Iodice3139f032018-11-05 14:26:32 +00001753 * @param[in] depth_output_gemm3d (Optional) Depth (third dimension) of the output tensor to be used with the GEMM3D kernel.
1754 * If 0 the output will not be reinterpreted as 3D. Default 0
Gian Marco Iodice68a3f562018-07-26 11:44:03 +01001755 * @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 +01001756 * to perform 1x1 convolutions with the NHWC data layout)
1757 * @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 +00001758 */
Georgios Pinitasb0f342e2019-05-21 13:32:43 +01001759 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 +01001760 : _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 +01001761 _reinterpret_input_as_3d(reinterpret_input_as_3d), _broadcast_bias(broadcast_bias)
Gian Marco36a0a462018-01-12 10:21:40 +00001762 {
1763 }
1764 /** Number of matrix A rows
1765 *
1766 * @return the number of matrix A rows
1767 */
1768 int m() const
1769 {
1770 return _m;
1771 }
1772 /** Number of matrix B columns
1773 *
1774 * @return the number of matrix B columns
1775 */
1776 int n() const
1777 {
1778 return _n;
1779 }
1780 /** Number of matrix A columns or matrix B rows
1781 *
1782 * @return the number of matrix A columns or matrix B rows
1783 */
1784 int k() const
1785 {
1786 return _k;
1787 }
1788 /** Multiplication factor for the width of the 1xW transposed block
1789 *
1790 * @return the multiplication factor for the width of the 1xW transposed block
1791 */
1792 int mult_transpose1xW_width() const
1793 {
1794 return _mult_transpose1xW_width;
1795 }
1796 /** Multiplication factor for the height of the 4x4 interleaved block
1797 *
1798 * @return the multiplication factor for the height of the 4x4 interleaved block
1799 */
1800 int mult_interleave4x4_height() const
1801 {
1802 return _mult_interleave4x4_height;
1803 }
Isabella Gottardi8e74f442018-03-01 16:42:00 +00001804 /** Depth (third dimension) of the output tensor to be used with the GEMM3D kernel
1805 *
1806 * @note GEMM3D kernel is used when the output has to be reinterpret as 3D tensor. In that case:
1807 * m = depth_output_gemm3d * output_height
1808 *
1809 * @return the depth of the output tensor to be used with the GEMM3D kernel
1810 */
1811 int depth_output_gemm3d() const
1812 {
1813 return _depth_output_gemm3d;
1814 }
Gian Marco Iodice68a3f562018-07-26 11:44:03 +01001815 /** Flag which specifies if the input tensor has to be reinterpreted as 3D
1816 *
1817 * @return True if the input tensor has to be reinterpreted as 3D tensor
1818 */
1819 bool reinterpret_input_as_3d() const
1820 {
1821 return _reinterpret_input_as_3d;
1822 };
Georgios Pinitasb0f342e2019-05-21 13:32:43 +01001823 /** Flag which specifies whether to broadcast the shape of the bias tensor.
1824 *
1825 * @return True if the shape of the bias tensor is to be broadcasted.
1826 */
1827 bool broadcast_bias() const
1828 {
1829 return _broadcast_bias;
1830 };
Gian Marco36a0a462018-01-12 10:21:40 +00001831
1832private:
Gian Marco Iodice68a3f562018-07-26 11:44:03 +01001833 const int _m;
1834 const int _n;
1835 const int _k;
1836 const int _mult_transpose1xW_width;
1837 const int _mult_interleave4x4_height;
1838 const int _depth_output_gemm3d;
1839 const bool _reinterpret_input_as_3d;
Georgios Pinitasb0f342e2019-05-21 13:32:43 +01001840 const bool _broadcast_bias;
Gian Marco36a0a462018-01-12 10:21:40 +00001841};
1842
giuros016d109962019-01-07 17:47:19 +00001843struct DepthwiseConvolutionReshapeInfo
1844{
1845 unsigned int c0{ 1 }; /**< Number of channels processed by the depth-wise convolution */
1846 bool transpose{ false }; /**< True if the block MxC0 (where M is the area of the filter i.e. KwxKh) has to be transposed */
1847};
1848
Gian Marco Iodice4b908652018-10-18 10:21:02 +01001849/** GEMMLowp output stage type */
1850enum class GEMMLowpOutputStageType
1851{
1852 NONE, /**< No quantization to uint8 */
1853 QUANTIZE_DOWN, /**< Quantize to uint8 using an integer multiplication */
1854 QUANTIZE_DOWN_FIXEDPOINT, /**< Quantize to uint8 using a fixed point multiplication */
1855 QUANTIZE_DOWN_FLOAT /**< Quantize to uint8 using a floating point multiplication */
1856};
1857
1858/** GEMMLowp output stage info */
1859struct GEMMLowpOutputStageInfo
1860{
1861 GEMMLowpOutputStageType type{ GEMMLowpOutputStageType::NONE }; /**< GEMMLowp output stage type */
1862 int gemmlowp_offset{ 0 }; /**< GEMMLowp output stage offset used for quantizing to QASYMM8 */
1863 int gemmlowp_multiplier{ 0 }; /**< GEMMLowp output stage multiplier used for quantizing to QASYMM8 */
1864 int gemmlowp_shift{ 0 }; /**< GEMMLowp output stage shift used for quantizing to uint8 */
1865 int gemmlowp_min_bound{ 0 }; /**< GEMMLowp min value used to saturate down the output result before converting back to QASYMM8 */
1866 int gemmlowp_max_bound{ 0 }; /**< GEMMLowp max value used to saturate down the output result before converting back to QASYMM8 */
1867};
1868
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +00001869/** GEMM LHS (Left Hand Side) matrix information */
1870struct GEMMLHSMatrixInfo
1871{
1872 unsigned int m0{ 1 }; /**< Number of rows processed by the matrix multiplication */
1873 unsigned int k0{ 1 }; /**< Number of partial accumulations performed by the matrix multiplication */
1874 unsigned int v0{ 1 }; /**< Number of vertical blocks of size (m0xk0) stored on the same output row */
1875 bool transpose{ true }; /**< True if the (m0xk0) block has to be transposed before been stored */
1876 bool interleave{ true }; /**< True if the v0 (m0xk0) blocks have to be interleaved in the output row */
1877};
1878
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +00001879/** GEMM RHS (Right Hand Side) matrix information */
1880struct GEMMRHSMatrixInfo
1881{
1882 unsigned int n0{ 1 }; /**< Number of columns processed by the matrix multiplication */
1883 unsigned int k0{ 1 }; /**< Number of partial accumulations performed by the matrix multiplication */
1884 unsigned int h0{ 1 }; /**< Number of horizontal blocks of size (k0xn0) stored on the same output row */
1885 bool transpose{ true }; /**< True if the (k0xn0) block has to be transposed before been stored */
1886 bool interleave{ true }; /**< True if the h0 (k0xn0) blocks have to be interleaved in the output row */
1887};
1888
Gian Marco36a0a462018-01-12 10:21:40 +00001889/** GEMM information class. This class stores the necessary information to compute GEMM functions
1890 *
1891 * This object also contains the information about how matrix A and matrix B have been reshaped
1892 *
1893 */
Chunosov5124be52017-11-22 20:42:13 +07001894class GEMMInfo
1895{
1896public:
1897 /** Default constructor */
Georgios Pinitas37d080f2019-06-21 18:43:12 +01001898 GEMMInfo() noexcept
1899 : _is_a_reshaped(false),
1900 _is_b_reshaped(false),
1901 _reshape_b_only_on_first_run(true),
1902 _depth_output_gemm3d(0),
1903 _reinterpret_input_as_3d(false),
1904 _retain_internal_weights(false),
1905 _gemmlowp_output_stage(),
1906 _fp_mixed_precision(false),
1907 _broadcast_bias(false),
Gian Marco Iodicef3622be2019-07-29 14:27:16 +01001908 _pretranpose_B(true),
1909 _activation_info()
Chunosov5124be52017-11-22 20:42:13 +07001910 {
1911 }
1912 /** Constructor
1913 *
1914 * @param[in] is_a_reshaped True if the matrix A has been reshaped
1915 * @param[in] is_b_reshaped True if the matrix B has been reshaped
1916 * @param[in] reshape_b_only_on_first_run Reshape matrix B only for the first run
Isabella Gottardi8e74f442018-03-01 16:42:00 +00001917 * @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 +00001918 * If 0 the output will not be reinterpreted as 3D. Default 0
Gian Marco Iodice68a3f562018-07-26 11:44:03 +01001919 * @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
1920 * to perform 1x1 convolutions with the NHWC data layout)
Michele Di Giorgioba1ffe92018-08-22 14:28:30 +01001921 * @param[in] retain_internal_weights (Optional) Retain the weights tensor from previous run
Gian Marco Iodice4b908652018-10-18 10:21:02 +01001922 * @param[in] gemmlowp_output_stage (Optional) GEMMLowp Output stage info
Vidhya Sudhan Loganathana25d16c2018-11-16 11:33:12 +00001923 * @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 +01001924 * @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 +01001925 * @param[in] activation_info (Optional) Activation to apply after the matrix multiplication
Chunosov5124be52017-11-22 20:42:13 +07001926 */
Gian Marco Iodice3139f032018-11-05 14:26:32 +00001927 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 +01001928 GEMMLowpOutputStageInfo gemmlowp_output_stage = GEMMLowpOutputStageInfo(), bool fp_mixed_precision = false, bool broadcast_bias = false,
1929 const ActivationLayerInfo &activation_info = ActivationLayerInfo()) noexcept
Georgios Pinitas37d080f2019-06-21 18:43:12 +01001930 : _is_a_reshaped(is_a_reshaped),
1931 _is_b_reshaped(is_b_reshaped),
1932 _reshape_b_only_on_first_run(reshape_b_only_on_first_run),
1933 _depth_output_gemm3d(depth_output_gemm3d),
1934 _reinterpret_input_as_3d(reinterpret_input_as_3d),
1935 _retain_internal_weights(retain_internal_weights),
1936 _gemmlowp_output_stage(gemmlowp_output_stage),
1937 _fp_mixed_precision(fp_mixed_precision),
1938 _broadcast_bias(broadcast_bias),
Gian Marco Iodicef3622be2019-07-29 14:27:16 +01001939 _pretranpose_B(reshape_b_only_on_first_run),
1940 _activation_info(activation_info)
Chunosov5124be52017-11-22 20:42:13 +07001941 {
1942 }
1943 /** Flag which specifies if the matrix A has been reshaped
1944 *
1945 * @return True if the matrix A has been reshaped
1946 */
1947 bool is_a_reshaped() const
1948 {
1949 return _is_a_reshaped;
1950 };
1951 /** Flag which specifies if the matrix B has been reshaped
1952 *
1953 * @return True if the matrix B has been reshaped
1954 */
1955 bool is_b_reshaped() const
1956 {
1957 return _is_b_reshaped;
1958 };
1959 /** Flag which specifies if the reshape of matrix B should executed only for the first
1960 *
1961 * @note This flag could be set to TRUE when GEMM is used to accelerate convolution layer
1962 *
1963 * @return True if the reshaped of matrix B happens only for the first run
1964 */
1965 bool reshape_b_only_on_first_run() const
1966 {
1967 return _reshape_b_only_on_first_run;
1968 };
Isabella Gottardi8e74f442018-03-01 16:42:00 +00001969 /** Depth of the output when GEMM output is reinterpreted as 3D tensor
Gian Marco36a0a462018-01-12 10:21:40 +00001970 *
Isabella Gottardi8e74f442018-03-01 16:42:00 +00001971 * @return the depth of the output tensor
Gian Marco36a0a462018-01-12 10:21:40 +00001972 */
Isabella Gottardi8e74f442018-03-01 16:42:00 +00001973 int depth_output_gemm3d() const
Gian Marco36a0a462018-01-12 10:21:40 +00001974 {
Isabella Gottardi8e74f442018-03-01 16:42:00 +00001975 return _depth_output_gemm3d;
1976 };
Gian Marco Iodice68a3f562018-07-26 11:44:03 +01001977 /** Flag which specifies if the input tensor has to be reinterpreted as 3D
1978 *
1979 * @return True if the input tensor has to be reinterpreted as 3D tensor
1980 */
1981 bool reinterpret_input_as_3d() const
1982 {
1983 return _reinterpret_input_as_3d;
1984 };
Michele Di Giorgioba1ffe92018-08-22 14:28:30 +01001985 /** Flag which specifies if the weights tensor has to be retained from previous run
1986 *
1987 * @return True if the weights tensor has to be retained
1988 */
1989 bool retain_internal_weights() const
1990 {
1991 return _retain_internal_weights;
1992 };
Gian Marco Iodice4b908652018-10-18 10:21:02 +01001993 /** GEMMLowp output stage
1994 *
1995 * @return the GEMMLowp output stage info
1996 */
1997 GEMMLowpOutputStageInfo gemmlowp_output_stage() const
1998 {
1999 return _gemmlowp_output_stage;
2000 };
Vidhya Sudhan Loganathana25d16c2018-11-16 11:33:12 +00002001 /** Flag which specifies if a wider accumulator should be used.
2002 *
2003 * @return True if a wider accumulator has to be used
2004 */
2005 bool fp_mixed_precision() const
2006 {
2007 return _fp_mixed_precision;
2008 };
Georgios Pinitasb0f342e2019-05-21 13:32:43 +01002009 /** Flag which specifies whether to broadcast the shape of the bias tensor.
2010 *
2011 * @return True if the shape of the bias tensor is to be broadcasted.
2012 */
2013 bool broadcast_bias() const
2014 {
2015 return _broadcast_bias;
2016 };
Georgios Pinitas37d080f2019-06-21 18:43:12 +01002017 /** Flag which specifies whether b should be pre-transposed if supported.
2018 *
2019 * @return True if b should be pre-transposed else false.
2020 */
2021 bool pretranpose_B() const
2022 {
2023 return _pretranpose_B;
2024 };
2025 /** Set pre-transpose b flag
2026 *
2027 * @param[in] flag Flag to set
2028 */
2029 void set_pretranpose_B(bool flag)
2030 {
2031 _pretranpose_B = flag;
2032 }
Gian Marco Iodicef3622be2019-07-29 14:27:16 +01002033 /** Activation layer to apply after the matrix multiplication
2034 *
2035 * @return ActivationLayerInfo object
2036 */
2037 ActivationLayerInfo activation_info() const
2038 {
2039 return _activation_info;
2040 }
Chunosov5124be52017-11-22 20:42:13 +07002041
2042private:
Georgios Pinitas37d080f2019-06-21 18:43:12 +01002043 bool _is_a_reshaped;
2044 bool _is_b_reshaped;
2045 bool _reshape_b_only_on_first_run;
2046 int _depth_output_gemm3d;
2047 bool _reinterpret_input_as_3d;
2048 bool _retain_internal_weights;
2049 GEMMLowpOutputStageInfo _gemmlowp_output_stage;
2050 bool _fp_mixed_precision;
2051 bool _broadcast_bias;
2052 bool _pretranpose_B;
Gian Marco Iodicef3622be2019-07-29 14:27:16 +01002053 ActivationLayerInfo _activation_info;
Chunosov5124be52017-11-22 20:42:13 +07002054};
2055
Gian Marco Iodice247f52c2018-03-22 11:24:56 +00002056/** Winograd information */
2057struct WinogradInfo
2058{
2059 /** Default constructor
2060 *
2061 * @param[in] output_tile_sz Width and height of the output tile
2062 * @param[in] kernel_sz Width and height of the kernel
2063 * @param[in] input_dims Width and height of the input tensor before the convolution is applied
2064 * @param[in] conv_info Convolution info (Pads, strides)
2065 * @param[in] data_layout Data layout to use for the output tensor once the convolution has been applied
2066 */
2067 WinogradInfo(Size2D output_tile_sz, Size2D kernel_sz, Size2D input_dims, PadStrideInfo conv_info, DataLayout data_layout)
2068 : output_tile_size(output_tile_sz), kernel_size(kernel_sz), input_dimensions(input_dims), convolution_info(conv_info), output_data_layout(data_layout)
2069 {
2070 }
2071
2072 Size2D output_tile_size{}; /**< Width and height of the output tile */
2073 Size2D kernel_size{}; /**< Width and height of the kernel*/
2074 Size2D input_dimensions{}; /**< Width and height of the input tensor before the convolution is applied */
2075 PadStrideInfo convolution_info{}; /**< Convolution info (Pads, strides,...) */
2076 DataLayout output_data_layout{ DataLayout::NCHW }; /**< Data layout to use for the output tensor once the convolution has been applied (NCHW or NHWC) */
2077};
2078
Anthony Barbier6ff3b192017-09-04 18:44:23 +01002079/** IO formatting information class*/
2080struct IOFormatInfo
2081{
2082 /** Precision type used when printing floating point numbers */
2083 enum class PrecisionType
2084 {
2085 Default, /**< Default precision to the one that the current stream has */
2086 Custom, /**< Custom precision specified by the user using the precision parameter */
2087 Full /**< The maximum precision of the floating point representation */
2088 };
2089
2090 /** Specifies the area to be printed, used by Tensor objects */
2091 enum class PrintRegion
2092 {
2093 ValidRegion, /**< Prints the valid region of the Tensor object */
2094 NoPadding, /**< Prints the Tensor object without the padding */
2095 Full /**< Print the tensor object including padding */
2096 };
2097
Alex Gildayc357c472018-03-21 13:54:09 +00002098 /** Construct a set of IO formatting information.
2099 *
2100 * @param[in] print_region Area to be printed. Used by Tensor objects. Default: ValidRegion.
2101 * @param[in] precision_type Precision type for floating point numbers. Default: stream default.
2102 * @param[in] precision Precision value for float point numbers. Default: 10.
2103 * @param[in] align_columns Whether to align columns when printed. Default: true.
2104 * @param[in] element_delim Delimeter between elements. Default: " ".
2105 * @param[in] row_delim Delimenter between rows. Default: "\n".
2106 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01002107 IOFormatInfo(PrintRegion print_region = PrintRegion::ValidRegion,
2108 PrecisionType precision_type = PrecisionType::Default,
2109 unsigned int precision = 10,
2110 bool align_columns = true,
2111 std::string element_delim = " ",
2112 std::string row_delim = "\n")
2113 : print_region(print_region),
2114 precision_type(precision_type),
2115 precision(precision),
2116 element_delim(element_delim),
2117 row_delim(row_delim),
2118 align_columns(align_columns)
2119 {
2120 }
2121
Alex Gildayc357c472018-03-21 13:54:09 +00002122 /** Area to be printed by Tensor objects */
2123 PrintRegion print_region;
2124 /** Floating point precision type */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01002125 PrecisionType precision_type;
Alex Gildayc357c472018-03-21 13:54:09 +00002126 /** Floating point precision */
2127 unsigned int precision;
2128 /** Element delimeter */
2129 std::string element_delim;
2130 /** Row delimeter */
2131 std::string row_delim;
2132 /** Align columns */
2133 bool align_columns;
Anthony Barbier6ff3b192017-09-04 18:44:23 +01002134};
Georgios Pinitasd8734b52017-12-22 15:27:52 +00002135} // namespace arm_compute
Anthony Barbier6ff3b192017-09-04 18:44:23 +01002136#endif /* __ARM_COMPUTE_TYPES_H__ */