blob: 6df74e7b8852321219b14811575ac25f288403c6 [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{
Georgios Pinitas4c5469b2019-05-21 13:32:43 +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 U16, /**< unsigned 16-bit number */
83 S16, /**< signed 16-bit number */
Manuel Bottini3689fcd2019-06-14 17:18:12 +010084 QSYMM16, /**< quantized, symmetric fixed-point 16-bit number */
Georgios Pinitas4c5469b2019-05-21 13:32:43 +010085 U32, /**< unsigned 32-bit number */
86 S32, /**< signed 32-bit number */
87 U64, /**< unsigned 64-bit number */
88 S64, /**< signed 64-bit number */
89 F16, /**< 16-bit floating-point number */
90 F32, /**< 32-bit floating-point number */
91 F64, /**< 64-bit floating-point number */
92 SIZET /**< size_t */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010093};
94
Daniil Efremov02bf80d2017-11-22 00:26:51 +070095/** Available Sampling Policies */
96enum class SamplingPolicy
97{
98 CENTER, /**< Samples are taken at pixel center */
99 TOP_LEFT /**< Samples are taken at pixel top left corner */
100};
101
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100102/** Constant value of the border pixels when using BorderMode::CONSTANT */
103constexpr uint8_t CONSTANT_BORDER_VALUE = 199;
104
Alex Gildayc357c472018-03-21 13:54:09 +0000105/** Constant value used to indicate a half-scale pyramid */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100106constexpr float SCALE_PYRAMID_HALF = 0.5f;
107
Alex Gildayc357c472018-03-21 13:54:09 +0000108/** Constant value used to indicate a ORB scaled pyramid */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100109constexpr float SCALE_PYRAMID_ORB = 8.408964152537146130583778358414e-01;
110
Vidhya Sudhan Loganathand646ae12018-11-19 15:18:20 +0000111/** [DataLayout enum definition] **/
112
Georgios Pinitas4074c992018-01-30 18:13:46 +0000113/** Supported tensor data layouts */
114enum class DataLayout
115{
Alex Gildayc357c472018-03-21 13:54:09 +0000116 UNKNOWN, /**< Unknown data layout */
117 NCHW, /**< Num samples, channels, height, width */
118 NHWC /**< Num samples, height, width, channels */
Georgios Pinitas4074c992018-01-30 18:13:46 +0000119};
Vidhya Sudhan Loganathand646ae12018-11-19 15:18:20 +0000120/** [DataLayout enum definition] **/
Georgios Pinitas4074c992018-01-30 18:13:46 +0000121
Isabella Gottardid17a6772018-02-27 17:41:55 +0000122/** Supported tensor data layout dimensions */
123enum class DataLayoutDimension
124{
Alex Gildayc357c472018-03-21 13:54:09 +0000125 CHANNEL, /**< channel */
126 HEIGHT, /**< height */
127 WIDTH, /**< width */
128 BATCHES /**< batches */
Isabella Gottardid17a6772018-02-27 17:41:55 +0000129};
130
Georgios Pinitas7900a9e2018-11-23 11:44:58 +0000131/** Available ConvolutionMethod*/
132enum class ConvolutionMethod
133{
Vidhya Sudhan Loganathan8ec0bb62019-04-23 10:40:44 +0100134 GEMM, /**< Convolution using GEMM */
135 DIRECT, /**< Direct convolution */
136 WINOGRAD, /**< Convolution using Winograd */
137 FFT /**< Convolution using FFT */
Georgios Pinitas7900a9e2018-11-23 11:44:58 +0000138};
139
giuros0146a49a02019-04-01 13:50:22 +0100140/** Available DeconvolutionMethod*/
141enum class DeconvolutionMethod
142{
143 GEMM, /**< Deconvolution using GEMM */
144 DIRECT, /**< Direct deconvolution */
145};
146
Manuel Bottini2732cca2019-05-28 11:44:41 +0100147/** Available FuseBatchNormalizationType*/
148enum class FuseBatchNormalizationType
149{
150 CONVOLUTION, /**< For Convolution weights */
151 DEPTHWISECONVOLUTION /**< For Depthwise Convolution weights*/
152};
153
Usama Arif89890c62019-03-19 10:57:05 +0000154/** Padding mode to use for PadLayer */
155enum class PaddingMode
156{
157 CONSTANT,
158 REFLECT,
159 SYMMETRIC
160};
161
Georgios Pinitas7900a9e2018-11-23 11:44:58 +0000162/** Supported comparison operations */
163enum class ComparisonOperation
164{
165 Equal, /**< Equal comparison ( \f$ x == y \f$ ) */
166 NotEqual, /**< NotEqual comparison ( \f$ x != y \f$ ) */
167 Greater, /**< Greater comparison ( \f$ x > y \f$ ) */
168 GreaterEqual, /**< Greater equal comparison ( \f$ x >= y \f$ ) */
169 Less, /**< Less comparison ( \f$ x < y \f$ ) */
170 LessEqual /**< Less equal comparison ( \f$ x <= y \f$ ) */
171};
172
Alex Gildayc357c472018-03-21 13:54:09 +0000173/** Container for valid region of a window */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100174struct ValidRegion
175{
Alex Gildayc357c472018-03-21 13:54:09 +0000176 /** Default constructor */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100177 ValidRegion()
178 : anchor{}, shape{}
179 {
180 }
181
Alex Gildayc357c472018-03-21 13:54:09 +0000182 /** Allow instances of this class to be copy constructed */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100183 ValidRegion(const ValidRegion &) = default;
Alex Gildayc357c472018-03-21 13:54:09 +0000184 /** Allow instances of this class to be move constructed */
185 ValidRegion(ValidRegion &&) = default;
186 /** Allow instances of this class to be copied */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100187 ValidRegion &operator=(const ValidRegion &) = default;
Alex Gildayc357c472018-03-21 13:54:09 +0000188 /** Allow instances of this class to be moved */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100189 ValidRegion &operator=(ValidRegion &&) = default;
Alex Gildayc357c472018-03-21 13:54:09 +0000190 /** Default destructor */
191 ~ValidRegion() = default;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100192
Alex Gildayc357c472018-03-21 13:54:09 +0000193 /** Constructor for a valid region with default number of dimensions
194 *
195 * @param[in] an_anchor Anchor for the start of the valid region.
196 * @param[in] a_shape Shape of the valid region.
197 *
198 */
Diego Lopez Recasbcbc9702017-12-18 11:28:27 +0000199 ValidRegion(const Coordinates &an_anchor, const TensorShape &a_shape)
200 : anchor{ an_anchor }, shape{ a_shape }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100201 {
Diego Lopez Recasbcbc9702017-12-18 11:28:27 +0000202 anchor.set_num_dimensions(std::max(anchor.num_dimensions(), shape.num_dimensions()));
203 }
204
Alex Gildayc357c472018-03-21 13:54:09 +0000205 /** Constructor for a valid region with specified number of dimensions
206 *
207 * @param[in] an_anchor Anchor for the start of the valid region.
208 * @param[in] a_shape Shape of the valid region.
209 * @param[in] num_dimensions Number of dimensions (must be >= number of dimensions of anchor and shape).
210 *
211 */
Diego Lopez Recasbcbc9702017-12-18 11:28:27 +0000212 ValidRegion(const Coordinates &an_anchor, const TensorShape &a_shape, size_t num_dimensions)
213 : anchor{ an_anchor }, shape{ a_shape }
214 {
215 ARM_COMPUTE_ERROR_ON(num_dimensions < std::max(anchor.num_dimensions(), shape.num_dimensions()));
216 anchor.set_num_dimensions(num_dimensions);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100217 }
218
219 /** Return the start of the valid region for the given dimension @p d */
220 int start(unsigned int d) const
221 {
222 return anchor[d];
223 }
224
225 /** Return the end of the valid region for the given dimension @p d */
226 int end(unsigned int d) const
227 {
228 return anchor[d] + shape[d];
229 }
230
Diego Lopez Recas35ceeb22017-12-04 18:56:10 +0000231 /** Accessor to set the value of anchor and shape for one of the dimensions.
232 *
233 * @param[in] dimension Dimension for which the value is set.
234 * @param[in] start Value to be set in anchor for the dimension.
235 * @param[in] size Value to be set in shape for the dimension.
236 *
237 * @return *this.
238 */
239 ValidRegion &set(size_t dimension, int start, size_t size)
240 {
241 anchor.set(dimension, start);
242 shape.set(dimension, size);
243 return *this;
244 }
245
Alex Gildayc357c472018-03-21 13:54:09 +0000246 Coordinates anchor; /**< Anchor for the start of the valid region. */
247 TensorShape shape; /**< Shape of the valid region. */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100248};
249
250/** Methods available to handle borders */
251enum class BorderMode
252{
253 UNDEFINED, /**< Borders are left undefined */
254 CONSTANT, /**< Pixels outside the image are assumed to have a constant value */
255 REPLICATE /**< Pixels outside the image are assumed to have the same value as the closest image pixel */
256};
257
258/** Container for 2D border size */
259struct BorderSize
260{
261 /** Empty border, i.e. no border */
262 constexpr BorderSize()
263 : top{ 0 }, right{ 0 }, bottom{ 0 }, left{ 0 }
264 {
265 }
266
267 /** Border with equal size around the 2D plane */
Moritz Pflanzer7655a672017-09-23 11:57:33 +0100268 explicit constexpr BorderSize(unsigned int size)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100269 : top{ size }, right{ size }, bottom{ size }, left{ size }
270 {
271 }
272
273 /** Border with same size for top/bottom and left/right */
274 constexpr BorderSize(unsigned int top_bottom, unsigned int left_right)
275 : top{ top_bottom }, right{ left_right }, bottom{ top_bottom }, left{ left_right }
276 {
277 }
278
279 /** Border with different sizes */
280 constexpr BorderSize(unsigned int top, unsigned int right, unsigned int bottom, unsigned int left)
281 : top{ top }, right{ right }, bottom{ bottom }, left{ left }
282 {
283 }
284
285 /** Check if the entire border is zero */
286 constexpr bool empty() const
287 {
288 return top == 0 && right == 0 && bottom == 0 && left == 0;
289 }
290
291 /** Check if the border is the same size on all sides */
292 constexpr bool uniform() const
293 {
294 return top == right && top == bottom && top == left;
295 }
296
Alex Gildayc357c472018-03-21 13:54:09 +0000297 /** Scale this border size.
298 *
299 * @param[in] scale Scale to multiply border size by.
300 *
301 * @return *this.
302 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100303 BorderSize &operator*=(float scale)
304 {
305 top *= scale;
306 right *= scale;
307 bottom *= scale;
308 left *= scale;
309
310 return *this;
311 }
312
Alex Gildayc357c472018-03-21 13:54:09 +0000313 /** Scale a copy of this border size.
314 *
315 * @param[in] scale Scale to multiply border size by.
316 *
317 * @return a scaled copy of this.
318 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100319 BorderSize operator*(float scale)
320 {
321 BorderSize size = *this;
322 size *= scale;
323
324 return size;
325 }
326
Alex Gildayc357c472018-03-21 13:54:09 +0000327 /** Limit this border size.
328 *
329 * @param[in] limit Border size to limit this border size to.
330 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100331 void limit(const BorderSize &limit)
332 {
333 top = std::min(top, limit.top);
334 right = std::min(right, limit.right);
335 bottom = std::min(bottom, limit.bottom);
336 left = std::min(left, limit.left);
337 }
338
Alex Gildayc357c472018-03-21 13:54:09 +0000339 unsigned int top; /**< top of the border */
340 unsigned int right; /**< right of the border */
341 unsigned int bottom; /**< bottom of the border */
342 unsigned int left; /**< left of the border */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100343};
344
Alex Gildayc357c472018-03-21 13:54:09 +0000345/** Container for 2D padding size */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100346using PaddingSize = BorderSize;
347
348/** Policy to handle overflow */
349enum class ConvertPolicy
350{
351 WRAP, /**< Wrap around */
352 SATURATE /**< Saturate */
353};
354
355/** Interpolation method */
356enum class InterpolationPolicy
357{
358 NEAREST_NEIGHBOR, /**< Output values are defined to match the source pixel whose center is nearest to the sample position */
359 BILINEAR, /**< Output values are defined by bilinear interpolation between the pixels */
360 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 */
361};
362
363/** Bilinear Interpolation method used by LKTracker */
364enum class BilinearInterpolation
365{
Alex Gildayc357c472018-03-21 13:54:09 +0000366 BILINEAR_OLD_NEW, /**< Old-new method */
367 BILINEAR_SCHARR /**< Scharr method */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100368};
369
370/** Threshold mode */
371enum class ThresholdType
372{
373 BINARY, /**< Threshold with one value */
374 RANGE /**< Threshold with two values*/
375};
376
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100377/** Termination criteria */
378enum class Termination
379{
Alex Gildayc357c472018-03-21 13:54:09 +0000380 TERM_CRITERIA_EPSILON, /**< Terminate when within epsilon of a threshold */
381 TERM_CRITERIA_ITERATIONS, /**< Terminate after a maximum number of iterations */
382 TERM_CRITERIA_BOTH /**< Terminate on whichever of the other conditions occurs first */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100383};
384
385/** Magnitude calculation type. */
386enum class MagnitudeType
387{
388 L1NORM, /**< L1 normalization type */
389 L2NORM /**< L2 normalization type */
390};
391
392/** Phase calculation type.
393 *
394 * @note When PhaseType == SIGNED, each angle is mapped to the range 0 to 255 inclusive otherwise angles between 0 and 180
395 */
396enum class PhaseType
397{
398 SIGNED, /**< Angle range: [0, 360] */
399 UNSIGNED /**< Angle range: [0, 180] */
400};
401
402/** Keypoint type */
403struct KeyPoint
404{
405 int32_t x{ 0 }; /**< X coordinates */
406 int32_t y{ 0 }; /**< Y coordinates */
407 float strength{ 0.f }; /**< Strength of the point */
408 float scale{ 0.f }; /**< Scale initialized to 0 by the corner detector */
409 float orientation{ 0.f }; /**< Orientation initialized to 0 by the corner detector */
410 int32_t tracking_status{ 0 }; /**< Status initialized to 1 by the corner detector, set to 0 when the point is lost */
411 float error{ 0.f }; /**< Tracking error initialized to 0 by the corner detector */
412};
413
Alex Gildayc357c472018-03-21 13:54:09 +0000414/** Internal key point */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100415using InternalKeypoint = std::tuple<float, float, float>; /* x,y,strength */
416
417/** Rectangle type */
418struct Rectangle
419{
420 uint16_t x; /**< Top-left x coordinate */
421 uint16_t y; /**< Top-left y coordinate */
422 uint16_t width; /**< Width of the rectangle */
423 uint16_t height; /**< Height of the rectangle */
424};
425
426/** Coordinate type */
427struct Coordinates2D
428{
429 int32_t x; /**< X coordinates */
430 int32_t y; /**< Y coordinates */
431};
432
433/** Coordinate type */
434struct Coordinates3D
435{
436 uint32_t x; /**< X coordinates */
437 uint32_t y; /**< Y coordinates */
438 uint32_t z; /**< Z coordinates */
439};
440
Giuseppe Rossinid7647d42018-07-17 18:13:13 +0100441/** Padding information as a pair of unsigned int start/end */
442using PaddingInfo = std::pair<uint32_t, uint32_t>;
443
444/** List of padding information */
445using PaddingList = std::vector<PaddingInfo>;
446
giuros013175fcf2018-11-21 09:59:17 +0000447/** Information to produce a tiled version of a Tensor */
448using Multiples = std::vector<uint32_t>;
449
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100450/** Available channels */
451enum class Channel
452{
453 UNKNOWN, /** Unknown channel format */
454 C0, /**< First channel (used by formats with unknown channel types). */
455 C1, /**< Second channel (used by formats with unknown channel types). */
456 C2, /**< Third channel (used by formats with unknown channel types). */
457 C3, /**< Fourth channel (used by formats with unknown channel types). */
458 R, /**< Red channel. */
459 G, /**< Green channel. */
460 B, /**< Blue channel. */
461 A, /**< Alpha channel. */
462 Y, /**< Luma channel. */
463 U, /**< Cb/U channel. */
464 V /**< Cr/V/Value channel. */
465};
466
467/** Available matrix patterns */
468enum class MatrixPattern
469{
470 BOX, /**< Box pattern matrix. */
471 CROSS, /**< Cross pattern matrix. */
472 DISK, /**< Disk pattern matrix. */
473 OTHER /**< Any other matrix pattern. */
474};
475
476/** Available non linear functions. */
477enum class NonLinearFilterFunction : unsigned
478{
479 MEDIAN = 0, /**< Non linear median filter. */
480 MIN = 1, /**< Non linear erode. */
481 MAX = 2, /**< Non linear dilate. */
482};
483
Georgios Pinitasd9769582017-08-03 10:19:40 +0100484/** Available reduction operations */
485enum class ReductionOperation
486{
Michalis Spyrou7930db42018-11-22 17:36:28 +0000487 ARG_IDX_MAX, /**< Index of the max value */
Manuel Bottinib412fab2018-12-10 17:40:23 +0000488 ARG_IDX_MIN, /**< Index of the min value */
489 MEAN_SUM, /**< Mean of sum */
490 PROD, /**< Product */
491 SUM_SQUARE, /**< Sum of squares */
Usama Arifa4a08ad2019-05-20 12:38:33 +0100492 SUM, /**< Sum */
493 MIN, /**< Min */
Usama Arif28f0dd92019-05-20 13:44:34 +0100494 MAX, /**< Max */
Georgios Pinitasd9769582017-08-03 10:19:40 +0100495};
496
giuros01164a2722018-11-20 18:34:46 +0000497/** Available element-wise operations */
498enum class ArithmeticOperation
499{
500 ADD, /**< (x + y) */
501 SUB, /**< (x - y) */
502 DIV, /**< (x / y) */
503 MIN, /**< Min(x, y) */
504 MAX, /**< Max(x, y) */
505 SQUARED_DIFF, /**< (x - y)^2 */
Usama Arif81e671e2019-05-13 13:33:14 +0100506 POWER, /**< x ^ y */
giuros011e6e1b82019-05-14 16:12:53 +0100507 PRELU, /**< y*x if x < 0, x otherwise */
giuros01164a2722018-11-20 18:34:46 +0000508};
509
Michalis Spyroue9362622018-11-23 17:41:37 +0000510/** Available element wise unary operations */
511enum class ElementWiseUnary
512{
513 RSQRT, /**< Reverse square root */
514 EXP, /**< Exponential */
Usama Ariff6e475c2019-05-10 12:06:28 +0100515 NEG, /**< Negate */
Usama Arifc255aa72019-05-13 16:26:29 +0100516 LOG, /**< Natural Logarithm */
Manuel Bottini6ac59922019-05-15 14:06:02 +0100517 ABS, /**< Absolute value */
Michalis Spyrou0af44182019-05-17 14:04:47 +0100518 SIN, /**< Sine */
Usama Arif0a5a57a2019-05-23 14:20:33 +0100519 ROUND, /**< Round */
Michalis Spyroue9362622018-11-23 17:41:37 +0000520};
521
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100522/** The normalization type used for the normalization layer */
523enum class NormType
524{
525 IN_MAP_1D, /**< Normalization applied within the same map in 1D region */
526 IN_MAP_2D, /**< Normalization applied within the same map in 2D region */
527 CROSS_MAP /**< Normalization applied cross maps */
528};
529
530/** Normalization type for Histogram of Oriented Gradients (HOG) */
531enum class HOGNormType
532{
533 L2_NORM = 1, /**< L2-norm */
534 L2HYS_NORM = 2, /**< L2-norm followed by clipping */
535 L1_NORM = 3 /**< L1 norm */
536};
537
538/** Detection window used for the object detection. The detection window keeps the following information:
539 *
540 * -# Geometry of the rectangular window (x/y of top-left corner and width/height)
541 * -# Index of the class used for evaluating which class the detection window belongs to
542 * -# Confidence value (score) obtained with the classifier
543 */
544struct DetectionWindow
545{
546 uint16_t x{ 0 }; /**< Top-left x coordinate */
547 uint16_t y{ 0 }; /**< Top-left y coordinate */
548 uint16_t width{ 0 }; /**< Width of the detection window */
549 uint16_t height{ 0 }; /**< Height of the detection window */
550 uint16_t idx_class{ 0 }; /**< Index of the class */
551 float score{ 0.f }; /**< Confidence value for the detection window */
552};
553
554/** Dimension rounding type when down-scaling on CNNs
555 * @note Used in pooling and convolution layer
556 */
557enum class DimensionRoundingType
558{
559 FLOOR, /**< Floor rounding */
560 CEIL /**< Ceil rounding */
561};
562
563/** Available pooling types */
564enum class PoolingType
565{
566 MAX, /**< Max Pooling */
Georgios Pinitascdf51452017-08-31 14:21:36 +0100567 AVG, /**< Average Pooling */
568 L2 /**< L2 Pooling */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100569};
570
Michalis Spyrou2709d612018-09-19 09:46:47 +0100571/** Available non maxima suppression types */
572enum class NMSType
573{
574 LINEAR, /**< Linear NMS */
575 GAUSSIAN, /**< Gaussian NMS */
576 ORIGINAL /**< Original NMS */
577};
578
579/** BoxWithNonMaximaSuppressionLimit Information class */
580class BoxNMSLimitInfo final
581{
582public:
583 /** Constructor
584 *
585 * @param[in] score_thresh (Optional) Score threshold.
586 * @param[in] nms (Optional) NMS value
587 * @param[in] detections (Optional) Number of detections
588 * @param[in] soft_nms_enabled (Optional) Enable SoftNMS
589 * @param[in] soft_nms_method (Optional) Soft NMS method
590 * @param[in] soft_nms_sigma (Optional) Soft NMS sigma value
591 * @param[in] soft_nms_min_score_thres (Optional) Soft NMS minimum score threshold
Manuel Bottini5209be52019-02-13 16:34:56 +0000592 * @param[in] suppress_size (Optional) Filter out boxes based on their size. Defaults to false
593 * @param[in] min_size (Optional) Smaller boxes than min_size will be filtered out. Defaults to 1
594 * @param[in] im_width (Optional) Boxes whose centers (on the x axis) is beyond im_width will be filtered. Defaults to 1
595 * @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 +0100596 */
597 BoxNMSLimitInfo(float score_thresh = 0.05f, float nms = 0.3f,
598 int detections = 100, bool soft_nms_enabled = false,
599 NMSType soft_nms_method = NMSType::LINEAR,
Manuel Bottini5209be52019-02-13 16:34:56 +0000600 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 +0100601 : _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 +0000602 _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 +0100603 {
604 }
605 /** Get the score threshold */
606 float score_thresh() const
607 {
608 return _score_thresh;
609 }
610 /** Get the NMS */
611 float nms() const
612 {
613 return _nms;
614 }
615 /** Get the number of detections */
616 int detections_per_im() const
617 {
618 return _detections_per_im;
619 }
620 /** Check if soft NMS is enabled */
621 bool soft_nms_enabled() const
622 {
623 return _soft_nms_enabled;
624 }
625 /** Get soft NMS method */
626 NMSType soft_nms_method() const
627 {
628 return _soft_nms_method;
629 }
630 /** Get soft NMS sigma */
631 float soft_nms_sigma() const
632 {
633 return _soft_nms_sigma;
634 }
635 /** Get soft nms min score threshold */
636 float soft_nms_min_score_thres() const
637 {
638 return _soft_nms_min_score_thres;
639 }
Manuel Bottini5209be52019-02-13 16:34:56 +0000640 /** Get if NMS will suppress boxes based on their size/position */
641 bool suppress_size() const
642 {
643 return _suppress_size;
644 }
645 /** Get size suppression threshold */
646 float min_size() const
647 {
648 return _min_size;
649 }
650 /** Get image width (NMS may suppress boxes whose center sits beyond the image width) */
651 float im_width() const
652 {
653 return _im_width;
654 }
655 /** Get image height (NMS may suppress boxes whose center sits beyond the image height) */
656 float im_height() const
657 {
658 return _im_height;
659 }
Michalis Spyrou2709d612018-09-19 09:46:47 +0100660
661private:
662 float _score_thresh;
663 float _nms;
664 int _detections_per_im;
665 bool _soft_nms_enabled;
666 NMSType _soft_nms_method;
667 float _soft_nms_sigma;
668 float _soft_nms_min_score_thres;
Manuel Bottini5209be52019-02-13 16:34:56 +0000669 bool _suppress_size;
670 float _min_size;
671 float _im_width;
672 float _im_height;
Michalis Spyrou2709d612018-09-19 09:46:47 +0100673};
674
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100675/** Padding and stride information class */
676class PadStrideInfo
677{
678public:
679 /** Constructor
680 *
681 * @param[in] stride_x (Optional) Stride, in elements, across x. Defaults to 1.
682 * @param[in] stride_y (Optional) Stride, in elements, across y. Defaults to 1.
683 * @param[in] pad_x (Optional) Padding, in elements, across x. Defaults to 0.
684 * @param[in] pad_y (Optional) Padding, in elements, across y. Defaults to 0.
685 * @param[in] round (Optional) Dimensions rounding. Defaults to @ref FLOOR.
686 */
687 PadStrideInfo(unsigned int stride_x = 1, unsigned int stride_y = 1,
688 unsigned int pad_x = 0, unsigned int pad_y = 0,
689 DimensionRoundingType round = DimensionRoundingType::FLOOR)
690 : _stride(std::make_pair(stride_x, stride_y)),
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100691 _pad_left(pad_x),
692 _pad_top(pad_y),
693 _pad_right(pad_x),
694 _pad_bottom(pad_y),
695 _round_type(round)
696 {
697 }
698 /** Constructor
699 *
700 * @param[in] stride_x Stride, in elements, across x.
701 * @param[in] stride_y Stride, in elements, across y.
702 * @param[in] pad_left Padding across x on the left, in elements.
703 * @param[in] pad_top Padding across y on the top, in elements.
704 * @param[in] pad_right Padding across x on the right, in elements.
705 * @param[in] pad_bottom Padding across y on the bottom, in elements.
706 * @param[in] round Dimensions rounding.
707 */
708 PadStrideInfo(unsigned int stride_x, unsigned int stride_y,
709 unsigned int pad_left, unsigned int pad_right,
710 unsigned int pad_top, unsigned int pad_bottom,
711 DimensionRoundingType round)
712 : _stride(std::make_pair(stride_x, stride_y)),
713 _pad_left(pad_left),
714 _pad_top(pad_top),
715 _pad_right(pad_right),
716 _pad_bottom(pad_bottom),
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100717 _round_type(round)
718 {
719 }
Alex Gildayc357c472018-03-21 13:54:09 +0000720 /** Get the stride.
721 *
722 * @return a pair: stride x, stride y.
723 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100724 std::pair<unsigned int, unsigned int> stride() const
725 {
726 return _stride;
727 }
Alex Gildayc357c472018-03-21 13:54:09 +0000728 /** Check whether the padding is symmetric.
729 *
730 * @return True if the padding is symmetric.
731 */
Anthony Barbier21f67d62018-02-16 15:17:48 +0000732 bool padding_is_symmetric() const
733 {
734 return (_pad_left == _pad_right) && (_pad_top == _pad_bottom);
735 }
Alex Gildayc357c472018-03-21 13:54:09 +0000736 /** Get the padding.
737 *
738 * @note This should only be used when the padding is symmetric.
739 *
740 * @return a pair: padding left/right, padding top/bottom
741 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100742 std::pair<unsigned int, unsigned int> pad() const
743 {
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100744 //this accessor should be used only when padding is symmetric
Anthony Barbier21f67d62018-02-16 15:17:48 +0000745 ARM_COMPUTE_ERROR_ON(!padding_is_symmetric());
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100746 return std::make_pair(_pad_left, _pad_top);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100747 }
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100748
Alex Gildayc357c472018-03-21 13:54:09 +0000749 /** Get the left padding */
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100750 unsigned int pad_left() const
751 {
752 return _pad_left;
753 }
Alex Gildayc357c472018-03-21 13:54:09 +0000754 /** Get the right padding */
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100755 unsigned int pad_right() const
756 {
757 return _pad_right;
758 }
Alex Gildayc357c472018-03-21 13:54:09 +0000759 /** Get the top padding */
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100760 unsigned int pad_top() const
761 {
762 return _pad_top;
763 }
Alex Gildayc357c472018-03-21 13:54:09 +0000764 /** Get the bottom padding */
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100765 unsigned int pad_bottom() const
766 {
767 return _pad_bottom;
768 }
769
Alex Gildayc357c472018-03-21 13:54:09 +0000770 /** Get the rounding type */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100771 DimensionRoundingType round() const
772 {
773 return _round_type;
774 }
775
Alex Gildayc357c472018-03-21 13:54:09 +0000776 /** Check whether this has any padding */
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100777 bool has_padding() const
778 {
779 return (_pad_left != 0 || _pad_top != 0 || _pad_right != 0 || _pad_bottom != 0);
780 }
781
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100782private:
783 std::pair<unsigned int, unsigned int> _stride;
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100784 unsigned int _pad_left;
785 unsigned int _pad_top;
786 unsigned int _pad_right;
787 unsigned int _pad_bottom;
788
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100789 DimensionRoundingType _round_type;
790};
791
Georgios Pinitas7d66a8e2018-07-17 12:28:42 +0100792/** Fully connected layer info */
793struct FullyConnectedLayerInfo
794{
795 DataLayout weights_trained_layout{ DataLayout::NCHW }; /**< Layout that the weights have been trained with. */
796 bool transpose_weights{ true }; /**< Transpose weights if true. */
797 bool are_weights_reshaped{ false }; /**< Reshape the weights tensor if false. */
798 bool retain_internal_weights{ false }; /**< Retain internal reshaped weights. */
Georgios Pinitasc55cef12018-08-01 15:24:18 +0100799
800 /** Sets the weights trained data layout
801 *
802 * @param[in] layout Data layout that the weights were trained with
803 *
804 * @return Updated object
805 */
806 FullyConnectedLayerInfo &set_weights_trained_layout(DataLayout layout)
807 {
808 weights_trained_layout = layout;
809 return *this;
810 }
Georgios Pinitas195b0ba2018-08-02 17:18:51 +0100811 /** Sets the transpose weights flag
812 *
813 * @param[in] should_transpose_weights Boolean flag indicating if weights should be transposed
814 *
815 * @return Updated object
816 */
817 FullyConnectedLayerInfo &set_transpose_weights(bool should_transpose_weights)
818 {
819 transpose_weights = should_transpose_weights;
820 return *this;
821 }
Georgios Pinitas7d66a8e2018-07-17 12:28:42 +0100822};
823
Michalis Spyrou6c7c38e2018-08-29 16:28:11 +0100824/** PriorBox layer info */
825class PriorBoxLayerInfo final
826{
827public:
828 /** Default Constructor */
829 PriorBoxLayerInfo()
830 : _min_sizes(),
831 _variances(),
832 _offset(),
833 _flip(true),
834 _clip(false),
835 _max_sizes(),
836 _aspect_ratios(),
837 _img_size(),
838 _steps()
839 {
840 }
841 /** Constructor
842 *
843 * @param[in] min_sizes Min sizes vector.
Michalis Spyrou721c4cb2018-09-04 15:27:25 +0100844 * @param[in] variances Variances vector.
Michalis Spyrou6c7c38e2018-08-29 16:28:11 +0100845 * @param[in] offset Offset value.
846 * @param[in] flip (Optional) Flip the aspect ratios.
847 * @param[in] clip (Optional) Clip coordinates so that they're within [0,1].
848 * @param[in] max_sizes (Optional) Max sizes vector.
849 * @param[in] aspect_ratios (Optional) Aspect ratios of the boxes.
850 * @param[in] img_size (Optional) Image size.
851 * @param[in] steps (Optional) Step values.
852 */
853 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 +0000854 const std::vector<float> &max_sizes = {}, const std::vector<float> &aspect_ratios = {},
855 const Coordinates2D &img_size = Coordinates2D{ 0, 0 }, const std::array<float, 2> &steps = { { 0.f, 0.f } })
Michalis Spyrou6c7c38e2018-08-29 16:28:11 +0100856 : _min_sizes(min_sizes),
857 _variances(variances),
858 _offset(offset),
859 _flip(flip),
860 _clip(clip),
861 _max_sizes(max_sizes),
Michalis Spyrou721c4cb2018-09-04 15:27:25 +0100862 _aspect_ratios(),
Michalis Spyrou6c7c38e2018-08-29 16:28:11 +0100863 _img_size(img_size),
864 _steps(steps)
865 {
866 _aspect_ratios.push_back(1.);
867 for(unsigned int i = 0; i < aspect_ratios.size(); ++i)
868 {
869 float ar = aspect_ratios[i];
870 bool already_exist = false;
871 for(auto ar_new : _aspect_ratios)
872 {
873 if(fabs(ar - ar_new) < 1e-6)
874 {
875 already_exist = true;
876 break;
877 }
878 }
879 if(!already_exist)
880 {
881 _aspect_ratios.push_back(ar);
882 if(flip)
883 {
884 _aspect_ratios.push_back(1.f / ar);
885 }
886 }
887 }
888 }
889 /** Get min sizes. */
890 std::vector<float> min_sizes() const
891 {
892 return _min_sizes;
893 }
894 /** Get min variances. */
895 std::vector<float> variances() const
896 {
897 return _variances;
898 }
899 /** Get the step coordinates */
900 std::array<float, 2> steps() const
901 {
902 return _steps;
903 }
904 /** Get the image size coordinates */
905 Coordinates2D img_size() const
906 {
907 return _img_size;
908 }
909 /** Get the offset */
910 float offset() const
911 {
912 return _offset;
913 }
914 /** Get the flip value */
915 bool flip() const
916 {
917 return _flip;
918 }
919 /** Get the clip value */
920 bool clip() const
921 {
922 return _clip;
923 }
924 /** Get max sizes. */
925 std::vector<float> max_sizes() const
926 {
927 return _max_sizes;
928 }
929 /** Get aspect ratios. */
930 std::vector<float> aspect_ratios() const
931 {
932 return _aspect_ratios;
933 }
934
935private:
936 std::vector<float> _min_sizes;
937 std::vector<float> _variances;
938 float _offset;
939 bool _flip;
940 bool _clip;
941 std::vector<float> _max_sizes;
942 std::vector<float> _aspect_ratios;
943 Coordinates2D _img_size;
944 std::array<float, 2> _steps;
945};
946
Isabella Gottardia7acb3c2019-01-08 13:48:44 +0000947// Bounding Box [xmin, ymin, xmax, ymax]
948using BBox = std::array<float, 4>;
949// LabelBBox used for map label and bounding box
950using LabelBBox = std::map<int, std::vector<BBox>>;
951
Isabella Gottardi05e56442018-11-16 11:26:52 +0000952/** Available Detection Output code types */
953enum class DetectionOutputLayerCodeType
954{
955 CORNER, /**< Use box corners */
956 CENTER_SIZE, /**< Use box centers and size */
957 CORNER_SIZE, /**< Use box centers and size */
958 TF_CENTER /**< Use box centers and size but flip x and y co-ordinates */
959};
960
961/** Detection Output layer info */
962class DetectionOutputLayerInfo final
963{
964public:
965 /** Default Constructor */
966 DetectionOutputLayerInfo()
967 : _num_classes(),
968 _share_location(),
969 _code_type(DetectionOutputLayerCodeType::CORNER),
970 _keep_top_k(),
971 _nms_threshold(),
972 _top_k(),
973 _background_label_id(),
974 _confidence_threshold(),
975 _variance_encoded_in_target(false),
976 _eta(),
977 _num_loc_classes()
978 {
979 _num_loc_classes = _share_location ? 1 : _num_classes;
980 }
981 /** Constructor
982 *
983 * @param[in] num_classes Number of classes to be predicted.
984 * @param[in] share_location If true, bounding box are shared among different classes.
985 * @param[in] code_type Type of coding method for bbox.
986 * @param[in] keep_top_k Number of total bounding boxes to be kept per image after NMS step.
987 * @param[in] nms_threshold Threshold to be used in NMS.
988 * @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.
989 * @param[in] background_label_id (Optional) Background label ID. If there is no background class, set it as -1.
990 * @param[in] confidence_threshold (Optional) Only consider detections whose confidences are larger than a threshold. Default set to -FLT_MAX.
991 * @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.
992 * @param[in] eta (Optional) Eta.
993 */
994 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,
995 float confidence_threshold = std::numeric_limits<float>::lowest(), bool variance_encoded_in_target = false, float eta = 1)
996 : _num_classes(num_classes),
997 _share_location(share_location),
998 _code_type(code_type),
999 _keep_top_k(keep_top_k),
1000 _nms_threshold(nms_threshold),
1001 _top_k(top_k),
1002 _background_label_id(background_label_id),
1003 _confidence_threshold(confidence_threshold),
1004 _variance_encoded_in_target(variance_encoded_in_target),
1005 _eta(eta),
1006 _num_loc_classes()
1007 {
1008 _num_loc_classes = _share_location ? 1 : _num_classes;
1009 }
1010 /** Get num classes. */
1011 int num_classes() const
1012 {
1013 return _num_classes;
1014 }
1015 /** Get share location. */
1016 bool share_location() const
1017 {
1018 return _share_location;
1019 }
1020 /** Get detection output code type. */
1021 DetectionOutputLayerCodeType code_type() const
1022 {
1023 return _code_type;
1024 }
1025 /** Get if variance encoded in target. */
1026 bool variance_encoded_in_target() const
1027 {
1028 return _variance_encoded_in_target;
1029 }
1030 /** Get the number of total bounding boxes to be kept per image. */
1031 int keep_top_k() const
1032 {
1033 return _keep_top_k;
1034 }
1035 /** Get nms threshold. */
1036 float nms_threshold() const
1037 {
1038 return _nms_threshold;
1039 }
1040 /** Get eta. */
1041 float eta() const
1042 {
1043 return _eta;
1044 }
1045 /** Get background label ID. */
1046 int background_label_id() const
1047 {
1048 return _background_label_id;
1049 }
1050 /** Get confidence threshold. */
1051 float confidence_threshold() const
1052 {
1053 return _confidence_threshold;
1054 }
1055 /** Get top K. */
1056 int top_k() const
1057 {
1058 return _top_k;
1059 }
1060 /** Get number of location classes. */
1061 int num_loc_classes() const
1062 {
1063 return _num_loc_classes;
1064 }
1065
1066private:
1067 int _num_classes;
1068 bool _share_location;
1069 DetectionOutputLayerCodeType _code_type;
1070 int _keep_top_k;
1071 float _nms_threshold;
1072 int _top_k;
1073 int _background_label_id;
1074 float _confidence_threshold;
1075 bool _variance_encoded_in_target;
1076 float _eta;
1077 int _num_loc_classes;
1078};
1079
Isabella Gottardia7acb3c2019-01-08 13:48:44 +00001080/** Detection Output layer info */
1081class DetectionPostProcessLayerInfo final
1082{
1083public:
1084 /** Default Constructor */
1085 DetectionPostProcessLayerInfo()
1086 : _max_detections(),
1087 _max_classes_per_detection(),
1088 _nms_score_threshold(),
1089 _iou_threshold(),
1090 _num_classes(),
1091 _scales_values(),
1092 _use_regular_nms(),
1093 _detection_per_class()
1094 {
1095 }
1096 /** Constructor
1097 *
1098 * @param[in] max_detections Number of total detection.
1099 * @param[in] max_classes_per_detection Number of total classes to be kept after NMS step. Used in the Fast Non-Max-Suppression
1100 * @param[in] nms_score_threshold Threshold to be used in NMS
1101 * @param[in] iou_threshold Threshold to be used during the intersection over union.
1102 * @param[in] num_classes Number of classes.
1103 * @param[in] scales_values Scales values used for decode center size boxes.
1104 * @param[in] use_regular_nms (Optional) Boolean to determinate if use regular or fast nms.
1105 * @param[in] detection_per_class (Optional) Number of detection per class. Used in the Regular Non-Max-Suppression
1106 */
1107 DetectionPostProcessLayerInfo(unsigned int max_detections, unsigned int max_classes_per_detection, float nms_score_threshold, float iou_threshold, unsigned int num_classes,
1108 std::array<float, 4> scales_values, bool use_regular_nms = false, unsigned int detection_per_class = 100)
1109 : _max_detections(max_detections),
1110 _max_classes_per_detection(max_classes_per_detection),
1111 _nms_score_threshold(nms_score_threshold),
1112 _iou_threshold(iou_threshold),
1113 _num_classes(num_classes),
1114 _scales_values(scales_values),
1115 _use_regular_nms(use_regular_nms),
1116 _detection_per_class(detection_per_class)
1117 {
1118 }
1119 /** Get max detections. */
1120 unsigned int max_detections() const
1121 {
1122 return _max_detections;
1123 }
1124 /** Get max_classes per detection. Used in the Fast Non-Max-Suppression.*/
1125 unsigned int max_classes_per_detection() const
1126 {
1127 return _max_classes_per_detection;
1128 }
1129 /** Get detection per class. Used in the Regular Non-Max-Suppression */
1130 unsigned int detection_per_class() const
1131 {
1132 return _detection_per_class;
1133 }
1134 /** Get nms threshold. */
1135 float nms_score_threshold() const
1136 {
1137 return _nms_score_threshold;
1138 }
1139 /** Get intersection over union threshold. */
1140 float iou_threshold() const
1141 {
1142 return _iou_threshold;
1143 }
1144 /** Get num classes. */
1145 unsigned int num_classes() const
1146 {
1147 return _num_classes;
1148 }
1149 /** Get if use regular nms. */
1150 bool use_regular_nms() const
1151 {
1152 return _use_regular_nms;
1153 }
1154 /** Get y scale value. */
1155 float scale_value_y() const
1156 {
1157 // Saved as [y,x,h,w]
1158 return _scales_values[0];
1159 }
1160 /** Get x scale value. */
1161 float scale_value_x() const
1162 {
1163 // Saved as [y,x,h,w]
1164 return _scales_values[1];
1165 }
1166 /** Get h scale value. */
1167 float scale_value_h() const
1168 {
1169 // Saved as [y,x,h,w]
1170 return _scales_values[2];
1171 }
1172 /** Get w scale value. */
1173 float scale_value_w() const
1174 {
1175 // Saved as [y,x,h,w]
1176 return _scales_values[3];
1177 }
1178
1179private:
1180 unsigned int _max_detections;
1181 unsigned int _max_classes_per_detection;
1182 float _nms_score_threshold;
1183 float _iou_threshold;
1184 unsigned int _num_classes;
1185 std::array<float, 4> _scales_values;
1186 bool _use_regular_nms;
1187 unsigned int _detection_per_class;
1188};
1189
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001190/** Pooling Layer Information class */
1191class PoolingLayerInfo
1192{
1193public:
Georgios Pinitas4c2dd542017-11-13 12:58:41 +00001194 /** Default Constructor */
1195 PoolingLayerInfo()
Isabella Gottardi6e464c32018-01-26 12:32:45 +00001196 : _pool_type(PoolingType::MAX), _pool_size(Size2D()), _pad_stride_info(PadStrideInfo()), _exclude_padding(false), _is_global_pooling(false)
Georgios Pinitas4c2dd542017-11-13 12:58:41 +00001197 {
1198 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001199 /** Default Constructor
1200 *
Georgios Pinitas4c2dd542017-11-13 12:58:41 +00001201 * @param[in] pool_type Pooling type @ref PoolingType.
1202 * @param[in] pool_size Pooling size, in elements, across x and y.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001203 * @param[in] pad_stride_info (Optional) Padding and stride information @ref PadStrideInfo
Georgios Pinitasadaae7e2017-10-30 15:56:32 +00001204 * @param[in] exclude_padding (Optional) Strategy when accounting padding in calculations.
1205 * True will exclude padding while false will not (Used in AVG/L2 pooling to determine the pooling area).
1206 * Defaults to false;
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001207 */
Georgios Pinitas4c2dd542017-11-13 12:58:41 +00001208 explicit PoolingLayerInfo(PoolingType pool_type,
1209 unsigned int pool_size,
1210 PadStrideInfo pad_stride_info = PadStrideInfo(),
1211 bool exclude_padding = false)
Isabella Gottardi6e464c32018-01-26 12:32:45 +00001212 : _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)
1213 {
1214 }
1215 /** Default Constructor
1216 *
1217 * @param[in] pool_type Pooling type @ref PoolingType.
1218 * @param[in] pool_size Pooling size, in elements, across x and y.
1219 * @param[in] pad_stride_info (Optional) Padding and stride information @ref PadStrideInfo
1220 * @param[in] exclude_padding (Optional) Strategy when accounting padding in calculations.
1221 * True will exclude padding while false will not (Used in AVG/L2 pooling to determine the pooling area).
1222 * Defaults to false;
1223 */
1224 explicit PoolingLayerInfo(PoolingType pool_type,
1225 Size2D pool_size,
1226 PadStrideInfo pad_stride_info = PadStrideInfo(),
1227 bool exclude_padding = false)
Georgios Pinitas4c2dd542017-11-13 12:58:41 +00001228 : _pool_type(pool_type), _pool_size(pool_size), _pad_stride_info(pad_stride_info), _exclude_padding(exclude_padding), _is_global_pooling(false)
1229 {
1230 }
1231 /** Default Constructor
1232 *
1233 * @note This constructor is used for global pooling
1234 *
1235 * @param[in] pool_type Pooling type @ref PoolingType.
1236 */
1237 explicit PoolingLayerInfo(PoolingType pool_type)
Isabella Gottardi6e464c32018-01-26 12:32:45 +00001238 : _pool_type(pool_type), _pool_size(Size2D()), _pad_stride_info(PadStrideInfo(1, 1, 0, 0)), _exclude_padding(false), _is_global_pooling(true)
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001239 {
1240 }
Alex Gildayc357c472018-03-21 13:54:09 +00001241 /** Get the pooling type */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001242 PoolingType pool_type() const
1243 {
1244 return _pool_type;
1245 }
Alex Gildayc357c472018-03-21 13:54:09 +00001246 /** Get the pooling size */
Isabella Gottardi6e464c32018-01-26 12:32:45 +00001247 const Size2D &pool_size() const
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001248 {
1249 return _pool_size;
1250 }
Alex Gildayc357c472018-03-21 13:54:09 +00001251 /** Get the padding and stride */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001252 PadStrideInfo pad_stride_info() const
1253 {
1254 return _pad_stride_info;
1255 }
Alex Gildayc357c472018-03-21 13:54:09 +00001256 /** Check if padding is excluded in calculations */
Georgios Pinitasadaae7e2017-10-30 15:56:32 +00001257 bool exclude_padding() const
1258 {
1259 return _exclude_padding;
1260 }
Alex Gildayc357c472018-03-21 13:54:09 +00001261 /** Check if is global pooling */
Georgios Pinitas4c2dd542017-11-13 12:58:41 +00001262 bool is_global_pooling() const
1263 {
1264 return _is_global_pooling;
1265 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001266
1267private:
1268 PoolingType _pool_type;
Isabella Gottardi6e464c32018-01-26 12:32:45 +00001269 Size2D _pool_size;
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001270 PadStrideInfo _pad_stride_info;
Georgios Pinitasadaae7e2017-10-30 15:56:32 +00001271 bool _exclude_padding;
Georgios Pinitas4c2dd542017-11-13 12:58:41 +00001272 bool _is_global_pooling;
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001273};
1274
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001275/** ROI Pooling Layer Information class */
giuros0118870812018-09-13 09:31:40 +01001276class ROIPoolingLayerInfo final
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001277{
1278public:
giuros0118870812018-09-13 09:31:40 +01001279 /** Constructor
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001280 *
giuros0118870812018-09-13 09:31:40 +01001281 * @param[in] pooled_width Pooled width of the layer.
1282 * @param[in] pooled_height Pooled height of the layer.
1283 * @param[in] spatial_scale Spatial scale to be applied to the ROI coordinates and dimensions.
1284 * @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 +01001285 */
giuros0118870812018-09-13 09:31:40 +01001286 ROIPoolingLayerInfo(unsigned int pooled_width, unsigned int pooled_height, float spatial_scale, unsigned int sampling_ratio = 0)
1287 : _pooled_width(pooled_width), _pooled_height(pooled_height), _spatial_scale(spatial_scale), _sampling_ratio(sampling_ratio)
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001288 {
1289 }
Alex Gildayc357c472018-03-21 13:54:09 +00001290 /** Get the pooled width of the layer */
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001291 unsigned int pooled_width() const
1292 {
1293 return _pooled_width;
1294 }
Alex Gildayc357c472018-03-21 13:54:09 +00001295 /** Get the pooled height of the layer */
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001296 unsigned int pooled_height() const
1297 {
1298 return _pooled_height;
1299 }
Alex Gildayc357c472018-03-21 13:54:09 +00001300 /** Get the spatial scale */
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001301 float spatial_scale() const
1302 {
1303 return _spatial_scale;
1304 }
giuros0118870812018-09-13 09:31:40 +01001305 /** Get sampling ratio */
1306 unsigned int sampling_ratio() const
1307 {
1308 return _sampling_ratio;
1309 }
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001310
1311private:
1312 unsigned int _pooled_width;
1313 unsigned int _pooled_height;
1314 float _spatial_scale;
giuros0118870812018-09-13 09:31:40 +01001315 unsigned int _sampling_ratio;
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001316};
1317
Manuel Bottini5209be52019-02-13 16:34:56 +00001318/** Generate Proposals Information class */
1319class GenerateProposalsInfo
1320{
1321public:
1322 /** Constructor
1323 *
1324 * @param[in] im_width Width of the original image
1325 * @param[in] im_height Height of the original image
1326 * @param[in] im_scale Scale applied to the original image
1327 * @param[in] spatial_scale (Optional)Scale applied to the feature map. Defaults to 1.0
1328 * @param[in] pre_nms_topN (Optional)Number of the best scores to be selected from the transformations. Defaults to 6000.
1329 * @param[in] post_nms_topN (Optional)Number of the best scores to be selected from the NMS operation. Defaults to 300.
1330 * @param[in] nms_thres (Optional)NMS overlap threshold. Defaults to 0.7.
1331 * @param[in] min_size (Optional)Size used to validate the anchors produced. Defaults to 16.
1332 * @param[in] values_per_roi (Optional)Values used to represent a ROI(Region of interest). Defaults to 4.
1333 */
1334 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,
1335 size_t values_per_roi = 4)
1336 : _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),
1337 _min_size(min_size), _values_per_roi(values_per_roi)
1338 {
1339 }
1340
1341 /* Get the original height */
1342 float im_height() const
1343 {
1344 return _im_height;
1345 }
1346 /* Get the original width */
1347 float im_width() const
1348 {
1349 return _im_width;
1350 }
1351 /* Get the image scale */
1352 float im_scale() const
1353 {
1354 return _im_scale;
1355 }
1356 /* Get the value of how many best scores to select (before NMS) */
1357 int pre_nms_topN() const
1358 {
1359 return _pre_nms_topN;
1360 }
1361 /* Get the value of how many best scores to select (after NMS) */
1362 int post_nms_topN() const
1363 {
1364 return _post_nms_topN;
1365 }
1366 /* Get the NMS overlap threshold */
1367 float nms_thres() const
1368 {
1369 return _nms_thres;
1370 }
1371 /* Get the minimal size */
1372 float min_size() const
1373 {
1374 return _min_size;
1375 }
1376 /* Get the spatial scale to be applied to the feature maps */
1377 float spatial_scale() const
1378 {
1379 return _spatial_scale;
1380 }
1381 /* Get the values used to represent a ROI(Region of interest)*/
1382 size_t values_per_roi() const
1383 {
1384 return _values_per_roi;
1385 }
1386
1387private:
1388 float _im_height;
1389 float _im_width;
1390 float _im_scale;
1391 float _spatial_scale;
1392 int _pre_nms_topN;
1393 int _post_nms_topN;
1394 float _nms_thres;
1395 float _min_size;
1396 size_t _values_per_roi;
1397};
1398
1399/** ComputeAnchors information class */
1400class ComputeAnchorsInfo
1401{
1402public:
1403 /** Constructor
1404 *
1405 * @param[in] feat_width Feature map width
1406 * @param[in] feat_height Feature map height
1407 * @param[in] spatial_scale Feature map scale
1408 * @param[in] values_per_roi (Optional)Values used to represent a ROI(Region Of Interest). Defaults to 4
1409 */
1410 ComputeAnchorsInfo(float feat_width, float feat_height, float spatial_scale, size_t values_per_roi = 4)
1411 : _feat_height(feat_height),
1412 _feat_width(feat_width),
1413 _spatial_scale(spatial_scale),
1414 _values_per_roi(values_per_roi)
1415 {
1416 }
1417
1418 /* Get the height of the feature map */
1419 float feat_height() const
1420 {
1421 return _feat_height;
1422 }
1423
1424 /* Get the width of the feature map */
1425 float feat_width() const
1426 {
1427 return _feat_width;
1428 }
1429
1430 /* Get the scale of the feature map */
1431 float spatial_scale() const
1432 {
1433 return _spatial_scale;
1434 }
1435
1436 /* Get the values used to represent a ROI(Region Of Interest)*/
1437 size_t values_per_roi() const
1438 {
1439 return _values_per_roi;
1440 }
1441
1442private:
1443 float _feat_height;
1444 float _feat_width;
1445 float _spatial_scale;
1446 size_t _values_per_roi;
1447};
1448
giuros01c04a0e82018-10-03 12:44:35 +01001449/** Bounding Box Transform information class */
giuros01d696cb62018-11-16 10:39:59 +00001450class BoundingBoxTransformInfo final
giuros01c04a0e82018-10-03 12:44:35 +01001451{
1452public:
1453 /** Constructor
1454 *
giuros01d696cb62018-11-16 10:39:59 +00001455 * @param[in] img_width Width of the original image
1456 * @param[in] img_height Height, of the original image
1457 * @param[in] scale Scale of the original image
1458 * @param[in] apply_scale (Optional)Re-apply scaling after transforming the boxes. Defaults to false
1459 * @param[in] weights (Optional)Weights [wx, wy, ww, wh] for the deltas. Defaults to all ones
1460 * @param[in] correct_transform_coords (Optional)Correct bounding box transform coordinates. Defaults to false
1461 * @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 +01001462 */
giuros01d696cb62018-11-16 10:39:59 +00001463 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 =
1464 false,
1465 float bbox_xform_clip =
1466 4.135166556742356f)
1467 : _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 +01001468 {
1469 }
1470
1471 std::array<float, 4> weights() const
1472 {
1473 return _weights;
1474 }
1475
1476 float bbox_xform_clip() const
1477 {
1478 return _bbox_xform_clip;
1479 }
1480
1481 float img_height() const
1482 {
1483 return _img_height;
1484 }
1485
1486 float img_width() const
1487 {
1488 return _img_width;
1489 }
1490
1491 float scale() const
1492 {
1493 return _scale;
1494 }
1495
1496 bool apply_scale() const
1497 {
1498 return _apply_scale;
1499 }
1500
giuros01d696cb62018-11-16 10:39:59 +00001501 bool correct_transform_coords() const
1502 {
1503 return _correct_transform_coords;
1504 }
1505
giuros01c04a0e82018-10-03 12:44:35 +01001506private:
1507 float _img_width;
1508 float _img_height;
1509 float _scale;
1510 bool _apply_scale;
giuros01d696cb62018-11-16 10:39:59 +00001511 bool _correct_transform_coords;
giuros01c04a0e82018-10-03 12:44:35 +01001512 std::array<float, 4> _weights;
1513 float _bbox_xform_clip;
1514};
1515
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001516/** Activation Layer Information class */
1517class ActivationLayerInfo
1518{
1519public:
1520 /** Available activation functions */
1521 enum class ActivationFunction
1522 {
Georgios Pinitas64ebe5b2017-09-01 17:44:24 +01001523 LOGISTIC, /**< Logistic ( \f$ f(x) = \frac{1}{1 + e^{-x}} \f$ ) */
1524 TANH, /**< Hyperbolic tangent ( \f$ f(x) = a \cdot tanh(b \cdot x) \f$ ) */
1525 RELU, /**< Rectifier ( \f$ f(x) = max(0,x) \f$ ) */
1526 BOUNDED_RELU, /**< Upper Bounded Rectifier ( \f$ f(x) = min(a, max(0,x)) \f$ ) */
1527 LU_BOUNDED_RELU, /**< Lower and Upper Bounded Rectifier ( \f$ f(x) = min(a, max(b,x)) \f$ ) */
Manuel Bottini581c8982019-02-07 10:31:57 +00001528 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 +01001529 SOFT_RELU, /**< Soft Rectifier ( \f$ f(x)= log(1+e^x) \f$ ) */
1530 ABS, /**< Absolute ( \f$ f(x)= |x| \f$ ) */
1531 SQUARE, /**< Square ( \f$ f(x)= x^2 \f$ )*/
1532 SQRT, /**< Square root ( \f$ f(x) = \sqrt{x} \f$ )*/
Usama Arif6a98a6e2019-05-10 17:07:27 +01001533 LINEAR, /**< Linear ( \f$ f(x)= ax + b \f$ ) */
1534 IDENTITY /**< Identity ( \f$ f(x)= x \f$ ) */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001535 };
1536
Giorgio Arena11674872018-02-07 15:38:12 +00001537 ActivationLayerInfo() = default;
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001538 /** Default Constructor
1539 *
1540 * @param[in] f The activation function to use.
1541 * @param[in] a (Optional) The alpha parameter used by some activation functions
Georgios Pinitas64ebe5b2017-09-01 17:44:24 +01001542 * (@ref ActivationFunction::BOUNDED_RELU, @ref ActivationFunction::LU_BOUNDED_RELU, @ref ActivationFunction::LINEAR, @ref ActivationFunction::TANH).
1543 * @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 +01001544 */
1545 ActivationLayerInfo(ActivationFunction f, float a = 0.0f, float b = 0.0f)
Giorgio Arena11674872018-02-07 15:38:12 +00001546 : _act(f), _a(a), _b(b), _enabled(true)
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001547 {
1548 }
Alex Gildayc357c472018-03-21 13:54:09 +00001549 /** Get the type of activation function */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001550 ActivationFunction activation() const
1551 {
1552 return _act;
1553 }
Alex Gildayc357c472018-03-21 13:54:09 +00001554 /** Get the alpha value */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001555 float a() const
1556 {
1557 return _a;
1558 }
Alex Gildayc357c472018-03-21 13:54:09 +00001559 /** Get the beta value */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001560 float b() const
1561 {
1562 return _b;
1563 }
Alex Gildayc357c472018-03-21 13:54:09 +00001564 /** Check if initialised */
Giorgio Arena11674872018-02-07 15:38:12 +00001565 bool enabled() const
1566 {
1567 return _enabled;
1568 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001569
1570private:
Usama Arif6a98a6e2019-05-10 17:07:27 +01001571 ActivationFunction _act = { ActivationLayerInfo::ActivationFunction::IDENTITY };
Giorgio Arena11674872018-02-07 15:38:12 +00001572 float _a = {};
1573 float _b = {};
1574 bool _enabled = { false };
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001575};
1576
1577/** Normalization Layer Information class */
1578class NormalizationLayerInfo
1579{
1580public:
1581 /** Default Constructor
1582 *
Michele Di Giorgio9d3a8312018-11-20 12:31:24 +00001583 * @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 +01001584 * @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 +00001585 * @param[in] alpha (Optional) Alpha parameter used by normalization equation. Defaults to 0.0001.
1586 * @param[in] beta (Optional) Beta parameter used by normalization equation. Defaults to 0.5.
1587 * @param[in] kappa (Optional) Kappa parameter used by [Krichevksy 2012] Across Channel Local Brightness Normalization equation.
1588 * @param[in] is_scaled (Optional) Boolean that specifies if alpha will be scaled by the normalization size or not.
1589 * Should be false to follow [Krichevksy 2012].
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001590 */
Georgios Pinitas41caa622017-11-16 14:37:08 +00001591 NormalizationLayerInfo(NormType type, uint32_t norm_size = 5, float alpha = 0.0001f, float beta = 0.5f, float kappa = 1.f, bool is_scaled = true)
1592 : _type(type), _norm_size(norm_size), _alpha(alpha), _beta(beta), _kappa(kappa), _is_scaled(is_scaled)
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001593 {
1594 }
Alex Gildayc357c472018-03-21 13:54:09 +00001595 /** Get the normalization type */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001596 NormType type() const
1597 {
1598 return _type;
1599 }
Alex Gildayc357c472018-03-21 13:54:09 +00001600 /** Get the normalization size */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001601 uint32_t norm_size() const
1602 {
1603 return _norm_size;
1604 }
Alex Gildayc357c472018-03-21 13:54:09 +00001605 /** Get the alpha value */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001606 float alpha() const
1607 {
1608 return _alpha;
1609 }
Alex Gildayc357c472018-03-21 13:54:09 +00001610 /** Get the beta value */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001611 float beta() const
1612 {
1613 return _beta;
1614 }
Alex Gildayc357c472018-03-21 13:54:09 +00001615 /** Get the kappa value */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001616 float kappa() const
1617 {
1618 return _kappa;
1619 }
Michele Di Giorgio9d3a8312018-11-20 12:31:24 +00001620 /** Get the is_scaled value */
1621 bool is_scaled() const
1622 {
1623 return _is_scaled;
1624 }
Alex Gildayc357c472018-03-21 13:54:09 +00001625 /** Check if normalization is cross map */
Georgios Pinitas41caa622017-11-16 14:37:08 +00001626 bool is_cross_map() const
1627 {
1628 return _type == NormType::CROSS_MAP;
1629 }
Alex Gildayc357c472018-03-21 13:54:09 +00001630 /** Check if normalization is not cross map */
Georgios Pinitas41caa622017-11-16 14:37:08 +00001631 bool is_in_map() const
1632 {
1633 return !is_cross_map();
1634 }
1635 /** Return the scaling factor of the normalization function.
1636 *
1637 * If is_scaled is set to false then [Krichevksy 2012] normalization scaling is performed,
1638 * 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 +01001639 *
1640 * @return The normalization scaling factor.
1641 */
1642 float scale_coeff() const
1643 {
1644 const uint32_t size = (_type == NormType::IN_MAP_2D) ? _norm_size * _norm_size : _norm_size;
Georgios Pinitas41caa622017-11-16 14:37:08 +00001645 return (_is_scaled) ? (_alpha / size) : _alpha;
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001646 }
1647
1648private:
1649 NormType _type;
1650 uint32_t _norm_size;
1651 float _alpha;
1652 float _beta;
1653 float _kappa;
Georgios Pinitas41caa622017-11-16 14:37:08 +00001654 bool _is_scaled;
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001655};
1656
Gian Marco Iodice559d7712017-08-08 08:38:09 +01001657/** 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 +01001658class WeightsInfo
1659{
1660public:
Gian Marco Iodice4e288692017-06-27 11:41:59 +01001661 /** Default constructor */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001662 WeightsInfo()
Michele Di Giorgiob62280a2018-05-31 17:31:05 +01001663 : _are_reshaped(false), _kernel_width(0), _kernel_height(0), _num_kernels(0), _retain_internal_weights(false)
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001664 {
1665 }
1666 /** Constructor
1667 *
Michele Di Giorgiob62280a2018-05-31 17:31:05 +01001668 * @param[in] are_reshaped True if the weights have been reshaped
1669 * @param[in] kernel_width Kernel width.
1670 * @param[in] kernel_height Kernel height.
1671 * @param[in] num_kernels Number of convolution kernels.
1672 * @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 +01001673 */
Michele Di Giorgiob62280a2018-05-31 17:31:05 +01001674 WeightsInfo(bool are_reshaped, unsigned int kernel_width, unsigned int kernel_height, unsigned int num_kernels, bool retain_internal_weights = false)
1675 : _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 +01001676 {
1677 }
Gian Marco Iodice4e288692017-06-27 11:41:59 +01001678 /** Flag which specifies if the weights tensor has been reshaped.
1679 *
1680 * @return True if the weights tensors has been reshaped
1681 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001682 bool are_reshaped() const
1683 {
1684 return _are_reshaped;
1685 };
Gian Marco Iodice559d7712017-08-08 08:38:09 +01001686 /** Return the number of convolution kernels
1687 *
1688 * @return The number of convolution kernels
1689 */
1690 unsigned int num_kernels() const
1691 {
1692 return _num_kernels;
1693 };
Gian Marco Iodice4e288692017-06-27 11:41:59 +01001694 /** Return the width and height of the kernel
1695 *
1696 * @return The width and height of the kernel
1697 */
1698 std::pair<unsigned int, unsigned int> kernel_size() const
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001699 {
Gian Marco Iodice4e288692017-06-27 11:41:59 +01001700 return std::make_pair(_kernel_width, _kernel_height);
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001701 }
Michele Di Giorgiob62280a2018-05-31 17:31:05 +01001702 bool retain_internal_weights() const
1703 {
1704 return _retain_internal_weights;
1705 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001706
1707private:
1708 const bool _are_reshaped;
Gian Marco Iodice4e288692017-06-27 11:41:59 +01001709 const unsigned int _kernel_width;
1710 const unsigned int _kernel_height;
Gian Marco Iodice559d7712017-08-08 08:38:09 +01001711 const unsigned int _num_kernels;
Michele Di Giorgiob62280a2018-05-31 17:31:05 +01001712 const bool _retain_internal_weights;
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001713};
1714
Gian Marco36a0a462018-01-12 10:21:40 +00001715/** GEMM reshape information class. This class stores the necessary information about matrix A and matrix B reshape.
1716 *
Gian Marco Iodice5fc07aa2019-05-15 17:08:02 +01001717 * The matrix A can only be reshaped through @ref CLGEMMReshapeLHSMatrixKernel or @ref NEGEMMInterleave4x4Kernel or @ref GCGEMMInterleave4x4Kernel
1718 * 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 +00001719 *
giuros018b6b4a92018-12-18 19:01:33 +00001720 * The matrix B can only be reshaped through @ref CLGEMMReshapeRHSMatrixKernel or @ref NEGEMMTranspose1xWKernel or @ref GCGEMMTranspose1xWKernel
1721 * 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 +00001722 *
1723 */
1724class GEMMReshapeInfo final
1725{
1726public:
1727 /** Default constructor */
1728 GEMMReshapeInfo()
Georgios Pinitasb0f342e2019-05-21 13:32:43 +01001729 : _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 +00001730 {
1731 }
1732 /** Constructor
1733 *
1734 * @param[in] m Number of matrix A rows
1735 * @param[in] n Number of matrix B columns
1736 * @param[in] k Number of matrix A columns or matrix B rows
1737 * @param[in] mult_transpose1xW_width (Optional) Multiplication factor for the width of the 1xW transposed block
1738 * @param[in] mult_interleave4x4_height (Optional) Multiplication factor for the height of the 4x4 interleaved block
Gian Marco Iodice3139f032018-11-05 14:26:32 +00001739 * @param[in] depth_output_gemm3d (Optional) Depth (third dimension) of the output tensor to be used with the GEMM3D kernel.
1740 * If 0 the output will not be reinterpreted as 3D. Default 0
Gian Marco Iodice68a3f562018-07-26 11:44:03 +01001741 * @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 +01001742 * to perform 1x1 convolutions with the NHWC data layout)
1743 * @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 +00001744 */
Georgios Pinitasb0f342e2019-05-21 13:32:43 +01001745 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 +01001746 : _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 +01001747 _reinterpret_input_as_3d(reinterpret_input_as_3d), _broadcast_bias(broadcast_bias)
Gian Marco36a0a462018-01-12 10:21:40 +00001748 {
1749 }
1750 /** Number of matrix A rows
1751 *
1752 * @return the number of matrix A rows
1753 */
1754 int m() const
1755 {
1756 return _m;
1757 }
1758 /** Number of matrix B columns
1759 *
1760 * @return the number of matrix B columns
1761 */
1762 int n() const
1763 {
1764 return _n;
1765 }
1766 /** Number of matrix A columns or matrix B rows
1767 *
1768 * @return the number of matrix A columns or matrix B rows
1769 */
1770 int k() const
1771 {
1772 return _k;
1773 }
1774 /** Multiplication factor for the width of the 1xW transposed block
1775 *
1776 * @return the multiplication factor for the width of the 1xW transposed block
1777 */
1778 int mult_transpose1xW_width() const
1779 {
1780 return _mult_transpose1xW_width;
1781 }
1782 /** Multiplication factor for the height of the 4x4 interleaved block
1783 *
1784 * @return the multiplication factor for the height of the 4x4 interleaved block
1785 */
1786 int mult_interleave4x4_height() const
1787 {
1788 return _mult_interleave4x4_height;
1789 }
Isabella Gottardi8e74f442018-03-01 16:42:00 +00001790 /** Depth (third dimension) of the output tensor to be used with the GEMM3D kernel
1791 *
1792 * @note GEMM3D kernel is used when the output has to be reinterpret as 3D tensor. In that case:
1793 * m = depth_output_gemm3d * output_height
1794 *
1795 * @return the depth of the output tensor to be used with the GEMM3D kernel
1796 */
1797 int depth_output_gemm3d() const
1798 {
1799 return _depth_output_gemm3d;
1800 }
Gian Marco Iodice68a3f562018-07-26 11:44:03 +01001801 /** Flag which specifies if the input tensor has to be reinterpreted as 3D
1802 *
1803 * @return True if the input tensor has to be reinterpreted as 3D tensor
1804 */
1805 bool reinterpret_input_as_3d() const
1806 {
1807 return _reinterpret_input_as_3d;
1808 };
Georgios Pinitasb0f342e2019-05-21 13:32:43 +01001809 /** Flag which specifies whether to broadcast the shape of the bias tensor.
1810 *
1811 * @return True if the shape of the bias tensor is to be broadcasted.
1812 */
1813 bool broadcast_bias() const
1814 {
1815 return _broadcast_bias;
1816 };
Gian Marco36a0a462018-01-12 10:21:40 +00001817
1818private:
Gian Marco Iodice68a3f562018-07-26 11:44:03 +01001819 const int _m;
1820 const int _n;
1821 const int _k;
1822 const int _mult_transpose1xW_width;
1823 const int _mult_interleave4x4_height;
1824 const int _depth_output_gemm3d;
1825 const bool _reinterpret_input_as_3d;
Georgios Pinitasb0f342e2019-05-21 13:32:43 +01001826 const bool _broadcast_bias;
Gian Marco36a0a462018-01-12 10:21:40 +00001827};
1828
giuros016d109962019-01-07 17:47:19 +00001829struct DepthwiseConvolutionReshapeInfo
1830{
1831 unsigned int c0{ 1 }; /**< Number of channels processed by the depth-wise convolution */
1832 bool transpose{ false }; /**< True if the block MxC0 (where M is the area of the filter i.e. KwxKh) has to be transposed */
1833};
1834
Gian Marco Iodice4b908652018-10-18 10:21:02 +01001835/** GEMMLowp output stage type */
1836enum class GEMMLowpOutputStageType
1837{
1838 NONE, /**< No quantization to uint8 */
1839 QUANTIZE_DOWN, /**< Quantize to uint8 using an integer multiplication */
1840 QUANTIZE_DOWN_FIXEDPOINT, /**< Quantize to uint8 using a fixed point multiplication */
1841 QUANTIZE_DOWN_FLOAT /**< Quantize to uint8 using a floating point multiplication */
1842};
1843
1844/** GEMMLowp output stage info */
1845struct GEMMLowpOutputStageInfo
1846{
1847 GEMMLowpOutputStageType type{ GEMMLowpOutputStageType::NONE }; /**< GEMMLowp output stage type */
1848 int gemmlowp_offset{ 0 }; /**< GEMMLowp output stage offset used for quantizing to QASYMM8 */
1849 int gemmlowp_multiplier{ 0 }; /**< GEMMLowp output stage multiplier used for quantizing to QASYMM8 */
1850 int gemmlowp_shift{ 0 }; /**< GEMMLowp output stage shift used for quantizing to uint8 */
1851 int gemmlowp_min_bound{ 0 }; /**< GEMMLowp min value used to saturate down the output result before converting back to QASYMM8 */
1852 int gemmlowp_max_bound{ 0 }; /**< GEMMLowp max value used to saturate down the output result before converting back to QASYMM8 */
1853};
1854
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +00001855/** GEMM LHS (Left Hand Side) matrix information */
1856struct GEMMLHSMatrixInfo
1857{
1858 unsigned int m0{ 1 }; /**< Number of rows processed by the matrix multiplication */
1859 unsigned int k0{ 1 }; /**< Number of partial accumulations performed by the matrix multiplication */
1860 unsigned int v0{ 1 }; /**< Number of vertical blocks of size (m0xk0) stored on the same output row */
1861 bool transpose{ true }; /**< True if the (m0xk0) block has to be transposed before been stored */
1862 bool interleave{ true }; /**< True if the v0 (m0xk0) blocks have to be interleaved in the output row */
1863};
1864
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +00001865/** GEMM RHS (Right Hand Side) matrix information */
1866struct GEMMRHSMatrixInfo
1867{
1868 unsigned int n0{ 1 }; /**< Number of columns processed by the matrix multiplication */
1869 unsigned int k0{ 1 }; /**< Number of partial accumulations performed by the matrix multiplication */
1870 unsigned int h0{ 1 }; /**< Number of horizontal blocks of size (k0xn0) stored on the same output row */
1871 bool transpose{ true }; /**< True if the (k0xn0) block has to be transposed before been stored */
1872 bool interleave{ true }; /**< True if the h0 (k0xn0) blocks have to be interleaved in the output row */
1873};
1874
Gian Marco36a0a462018-01-12 10:21:40 +00001875/** GEMM information class. This class stores the necessary information to compute GEMM functions
1876 *
1877 * This object also contains the information about how matrix A and matrix B have been reshaped
1878 *
1879 */
Chunosov5124be52017-11-22 20:42:13 +07001880class GEMMInfo
1881{
1882public:
1883 /** Default constructor */
Georgios Pinitas37d080f2019-06-21 18:43:12 +01001884 GEMMInfo() noexcept
1885 : _is_a_reshaped(false),
1886 _is_b_reshaped(false),
1887 _reshape_b_only_on_first_run(true),
1888 _depth_output_gemm3d(0),
1889 _reinterpret_input_as_3d(false),
1890 _retain_internal_weights(false),
1891 _gemmlowp_output_stage(),
1892 _fp_mixed_precision(false),
1893 _broadcast_bias(false),
Gian Marco Iodicef3622be2019-07-29 14:27:16 +01001894 _pretranpose_B(true),
1895 _activation_info()
Chunosov5124be52017-11-22 20:42:13 +07001896 {
1897 }
1898 /** Constructor
1899 *
1900 * @param[in] is_a_reshaped True if the matrix A has been reshaped
1901 * @param[in] is_b_reshaped True if the matrix B has been reshaped
1902 * @param[in] reshape_b_only_on_first_run Reshape matrix B only for the first run
Isabella Gottardi8e74f442018-03-01 16:42:00 +00001903 * @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 +00001904 * If 0 the output will not be reinterpreted as 3D. Default 0
Gian Marco Iodice68a3f562018-07-26 11:44:03 +01001905 * @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
1906 * to perform 1x1 convolutions with the NHWC data layout)
Michele Di Giorgioba1ffe92018-08-22 14:28:30 +01001907 * @param[in] retain_internal_weights (Optional) Retain the weights tensor from previous run
Gian Marco Iodice4b908652018-10-18 10:21:02 +01001908 * @param[in] gemmlowp_output_stage (Optional) GEMMLowp Output stage info
Vidhya Sudhan Loganathana25d16c2018-11-16 11:33:12 +00001909 * @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 +01001910 * @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 +01001911 * @param[in] activation_info (Optional) Activation to apply after the matrix multiplication
Chunosov5124be52017-11-22 20:42:13 +07001912 */
Gian Marco Iodice3139f032018-11-05 14:26:32 +00001913 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 +01001914 GEMMLowpOutputStageInfo gemmlowp_output_stage = GEMMLowpOutputStageInfo(), bool fp_mixed_precision = false, bool broadcast_bias = false,
1915 const ActivationLayerInfo &activation_info = ActivationLayerInfo()) noexcept
Georgios Pinitas37d080f2019-06-21 18:43:12 +01001916 : _is_a_reshaped(is_a_reshaped),
1917 _is_b_reshaped(is_b_reshaped),
1918 _reshape_b_only_on_first_run(reshape_b_only_on_first_run),
1919 _depth_output_gemm3d(depth_output_gemm3d),
1920 _reinterpret_input_as_3d(reinterpret_input_as_3d),
1921 _retain_internal_weights(retain_internal_weights),
1922 _gemmlowp_output_stage(gemmlowp_output_stage),
1923 _fp_mixed_precision(fp_mixed_precision),
1924 _broadcast_bias(broadcast_bias),
Gian Marco Iodicef3622be2019-07-29 14:27:16 +01001925 _pretranpose_B(reshape_b_only_on_first_run),
1926 _activation_info(activation_info)
Chunosov5124be52017-11-22 20:42:13 +07001927 {
1928 }
1929 /** Flag which specifies if the matrix A has been reshaped
1930 *
1931 * @return True if the matrix A has been reshaped
1932 */
1933 bool is_a_reshaped() const
1934 {
1935 return _is_a_reshaped;
1936 };
1937 /** Flag which specifies if the matrix B has been reshaped
1938 *
1939 * @return True if the matrix B has been reshaped
1940 */
1941 bool is_b_reshaped() const
1942 {
1943 return _is_b_reshaped;
1944 };
1945 /** Flag which specifies if the reshape of matrix B should executed only for the first
1946 *
1947 * @note This flag could be set to TRUE when GEMM is used to accelerate convolution layer
1948 *
1949 * @return True if the reshaped of matrix B happens only for the first run
1950 */
1951 bool reshape_b_only_on_first_run() const
1952 {
1953 return _reshape_b_only_on_first_run;
1954 };
Isabella Gottardi8e74f442018-03-01 16:42:00 +00001955 /** Depth of the output when GEMM output is reinterpreted as 3D tensor
Gian Marco36a0a462018-01-12 10:21:40 +00001956 *
Isabella Gottardi8e74f442018-03-01 16:42:00 +00001957 * @return the depth of the output tensor
Gian Marco36a0a462018-01-12 10:21:40 +00001958 */
Isabella Gottardi8e74f442018-03-01 16:42:00 +00001959 int depth_output_gemm3d() const
Gian Marco36a0a462018-01-12 10:21:40 +00001960 {
Isabella Gottardi8e74f442018-03-01 16:42:00 +00001961 return _depth_output_gemm3d;
1962 };
Gian Marco Iodice68a3f562018-07-26 11:44:03 +01001963 /** Flag which specifies if the input tensor has to be reinterpreted as 3D
1964 *
1965 * @return True if the input tensor has to be reinterpreted as 3D tensor
1966 */
1967 bool reinterpret_input_as_3d() const
1968 {
1969 return _reinterpret_input_as_3d;
1970 };
Michele Di Giorgioba1ffe92018-08-22 14:28:30 +01001971 /** Flag which specifies if the weights tensor has to be retained from previous run
1972 *
1973 * @return True if the weights tensor has to be retained
1974 */
1975 bool retain_internal_weights() const
1976 {
1977 return _retain_internal_weights;
1978 };
Gian Marco Iodice4b908652018-10-18 10:21:02 +01001979 /** GEMMLowp output stage
1980 *
1981 * @return the GEMMLowp output stage info
1982 */
1983 GEMMLowpOutputStageInfo gemmlowp_output_stage() const
1984 {
1985 return _gemmlowp_output_stage;
1986 };
Vidhya Sudhan Loganathana25d16c2018-11-16 11:33:12 +00001987 /** Flag which specifies if a wider accumulator should be used.
1988 *
1989 * @return True if a wider accumulator has to be used
1990 */
1991 bool fp_mixed_precision() const
1992 {
1993 return _fp_mixed_precision;
1994 };
Georgios Pinitasb0f342e2019-05-21 13:32:43 +01001995 /** Flag which specifies whether to broadcast the shape of the bias tensor.
1996 *
1997 * @return True if the shape of the bias tensor is to be broadcasted.
1998 */
1999 bool broadcast_bias() const
2000 {
2001 return _broadcast_bias;
2002 };
Georgios Pinitas37d080f2019-06-21 18:43:12 +01002003 /** Flag which specifies whether b should be pre-transposed if supported.
2004 *
2005 * @return True if b should be pre-transposed else false.
2006 */
2007 bool pretranpose_B() const
2008 {
2009 return _pretranpose_B;
2010 };
2011 /** Set pre-transpose b flag
2012 *
2013 * @param[in] flag Flag to set
2014 */
2015 void set_pretranpose_B(bool flag)
2016 {
2017 _pretranpose_B = flag;
2018 }
Gian Marco Iodicef3622be2019-07-29 14:27:16 +01002019 /** Activation layer to apply after the matrix multiplication
2020 *
2021 * @return ActivationLayerInfo object
2022 */
2023 ActivationLayerInfo activation_info() const
2024 {
2025 return _activation_info;
2026 }
Chunosov5124be52017-11-22 20:42:13 +07002027
2028private:
Georgios Pinitas37d080f2019-06-21 18:43:12 +01002029 bool _is_a_reshaped;
2030 bool _is_b_reshaped;
2031 bool _reshape_b_only_on_first_run;
2032 int _depth_output_gemm3d;
2033 bool _reinterpret_input_as_3d;
2034 bool _retain_internal_weights;
2035 GEMMLowpOutputStageInfo _gemmlowp_output_stage;
2036 bool _fp_mixed_precision;
2037 bool _broadcast_bias;
2038 bool _pretranpose_B;
Gian Marco Iodicef3622be2019-07-29 14:27:16 +01002039 ActivationLayerInfo _activation_info;
Chunosov5124be52017-11-22 20:42:13 +07002040};
2041
Gian Marco Iodice247f52c2018-03-22 11:24:56 +00002042/** Winograd information */
2043struct WinogradInfo
2044{
2045 /** Default constructor
2046 *
2047 * @param[in] output_tile_sz Width and height of the output tile
2048 * @param[in] kernel_sz Width and height of the kernel
2049 * @param[in] input_dims Width and height of the input tensor before the convolution is applied
2050 * @param[in] conv_info Convolution info (Pads, strides)
2051 * @param[in] data_layout Data layout to use for the output tensor once the convolution has been applied
2052 */
2053 WinogradInfo(Size2D output_tile_sz, Size2D kernel_sz, Size2D input_dims, PadStrideInfo conv_info, DataLayout data_layout)
2054 : output_tile_size(output_tile_sz), kernel_size(kernel_sz), input_dimensions(input_dims), convolution_info(conv_info), output_data_layout(data_layout)
2055 {
2056 }
2057
2058 Size2D output_tile_size{}; /**< Width and height of the output tile */
2059 Size2D kernel_size{}; /**< Width and height of the kernel*/
2060 Size2D input_dimensions{}; /**< Width and height of the input tensor before the convolution is applied */
2061 PadStrideInfo convolution_info{}; /**< Convolution info (Pads, strides,...) */
2062 DataLayout output_data_layout{ DataLayout::NCHW }; /**< Data layout to use for the output tensor once the convolution has been applied (NCHW or NHWC) */
2063};
2064
Anthony Barbier6ff3b192017-09-04 18:44:23 +01002065/** IO formatting information class*/
2066struct IOFormatInfo
2067{
2068 /** Precision type used when printing floating point numbers */
2069 enum class PrecisionType
2070 {
2071 Default, /**< Default precision to the one that the current stream has */
2072 Custom, /**< Custom precision specified by the user using the precision parameter */
2073 Full /**< The maximum precision of the floating point representation */
2074 };
2075
2076 /** Specifies the area to be printed, used by Tensor objects */
2077 enum class PrintRegion
2078 {
2079 ValidRegion, /**< Prints the valid region of the Tensor object */
2080 NoPadding, /**< Prints the Tensor object without the padding */
2081 Full /**< Print the tensor object including padding */
2082 };
2083
Alex Gildayc357c472018-03-21 13:54:09 +00002084 /** Construct a set of IO formatting information.
2085 *
2086 * @param[in] print_region Area to be printed. Used by Tensor objects. Default: ValidRegion.
2087 * @param[in] precision_type Precision type for floating point numbers. Default: stream default.
2088 * @param[in] precision Precision value for float point numbers. Default: 10.
2089 * @param[in] align_columns Whether to align columns when printed. Default: true.
2090 * @param[in] element_delim Delimeter between elements. Default: " ".
2091 * @param[in] row_delim Delimenter between rows. Default: "\n".
2092 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01002093 IOFormatInfo(PrintRegion print_region = PrintRegion::ValidRegion,
2094 PrecisionType precision_type = PrecisionType::Default,
2095 unsigned int precision = 10,
2096 bool align_columns = true,
2097 std::string element_delim = " ",
2098 std::string row_delim = "\n")
2099 : print_region(print_region),
2100 precision_type(precision_type),
2101 precision(precision),
2102 element_delim(element_delim),
2103 row_delim(row_delim),
2104 align_columns(align_columns)
2105 {
2106 }
2107
Alex Gildayc357c472018-03-21 13:54:09 +00002108 /** Area to be printed by Tensor objects */
2109 PrintRegion print_region;
2110 /** Floating point precision type */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01002111 PrecisionType precision_type;
Alex Gildayc357c472018-03-21 13:54:09 +00002112 /** Floating point precision */
2113 unsigned int precision;
2114 /** Element delimeter */
2115 std::string element_delim;
2116 /** Row delimeter */
2117 std::string row_delim;
2118 /** Align columns */
2119 bool align_columns;
Anthony Barbier6ff3b192017-09-04 18:44:23 +01002120};
Georgios Pinitasd8734b52017-12-22 15:27:52 +00002121} // namespace arm_compute
Anthony Barbier6ff3b192017-09-04 18:44:23 +01002122#endif /* __ARM_COMPUTE_TYPES_H__ */