blob: 9264cefe3e12bee55c197e82341d9c4078914fbc [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Mohammed Suhail Munshid538d162023-02-16 16:22:32 +00002 * Copyright (c) 2016-2023 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 */
Jakub Sujak0d27b2e2023-08-24 14:01:20 +010024#ifndef ACL_ARM_COMPUTE_CORE_TYPES_H
25#define ACL_ARM_COMPUTE_CORE_TYPES_H
SiCong Li91295492023-07-21 18:16:13 +010026
27/** The following symbols have been moved to:
28 * half
29 * PermutationVector
30 * Format
31 * DataType
32 * DataLayout
33 * DataLayoutDimension
34 * PadStrideInfo
35 * WeightFormat
36 * Channel
37 * DimensionRoundingType
38 */
39#include "arm_compute/core/CoreTypes.h"
40/** The following symbols have been moved to:
41 * ActivationFunction
42 * ActivationLayerInfo
43 */
44#include "arm_compute/function_info/ActivationLayerInfo.h"
45/** The following symbols have been moved to:
46 * ConvolutionInfo
47 */
48#include "arm_compute/function_info/ConvolutionInfo.h"
49/** The following symbols have been moved to:
50 * FullyConnectedLayerInfo
51 */
52#include "arm_compute/function_info/FullyConnectedLayerInfo.h"
53/** The following symbols have been moved to:
54 * GEMMLowpOutputStageType
55 * GEMMLowpOutputStageInfo
56 * GEMMInfo
57 */
58#include "arm_compute/function_info/GEMMInfo.h"
59/** The following symbols have been moved to:
60 * MatMulInfo
61 */
62#include "arm_compute/function_info/MatMulInfo.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010063
64#include "arm_compute/core/Coordinates.h"
Isabella Gottardi6e464c32018-01-26 12:32:45 +000065#include "arm_compute/core/Size2D.h"
Adnan AlSinane4563a02021-09-01 15:32:03 +010066#include "arm_compute/core/Size3D.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010067#include "arm_compute/core/TensorShape.h"
Sang-Hoon Park11fedda2020-01-15 14:44:04 +000068#include "arm_compute/core/utils/misc/Macros.h"
Georgios Pinitase8291ac2020-02-26 09:58:13 +000069#include "support/Bfloat16.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010070
Michel Iwaniec5dfeae62017-11-29 10:48:23 +000071#include <cmath>
Anthony Barbier6ff3b192017-09-04 18:44:23 +010072#include <cstddef>
73#include <cstdint>
Isabella Gottardia7acb3c2019-01-08 13:48:44 +000074#include <map>
Anthony Barbier6ff3b192017-09-04 18:44:23 +010075#include <string>
76#include <utility>
77
78namespace arm_compute
79{
Georgios Pinitas77589b52018-08-21 14:41:35 +010080/** Bidirectional strides */
81using BiStrides = Coordinates;
Georgios Pinitas8795ffb2017-12-01 16:13:40 +000082
Daniil Efremov02bf80d2017-11-22 00:26:51 +070083/** Available Sampling Policies */
84enum class SamplingPolicy
85{
86 CENTER, /**< Samples are taken at pixel center */
87 TOP_LEFT /**< Samples are taken at pixel top left corner */
88};
89
Georgios Pinitas7900a9e2018-11-23 11:44:58 +000090/** Available ConvolutionMethod*/
91enum class ConvolutionMethod
92{
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000093 GEMM, /**< Convolution using GEMM */
94 GEMM_CONV2D, /**< Direct 2D GEMM convolution */
95 DIRECT, /**< Direct convolution */
Gian Marco Iodicea5cb79f2022-12-28 13:53:51 +000096 INDIRECT, /**< Indirect convolution */
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000097 WINOGRAD, /**< Convolution using Winograd */
98 FFT /**< Convolution using FFT */
Georgios Pinitas7900a9e2018-11-23 11:44:58 +000099};
100
Manuel Bottini05069f02019-09-26 17:18:26 +0100101/** Available DepthwiseConvolutionFunction*/
102enum class DepthwiseConvolutionFunction
103{
104 OPTIMIZED, /**< Optimized Depthwise Convolution */
105 GENERIC, /**< Generic Depthwise Convolution */
106};
107
giuros0146a49a02019-04-01 13:50:22 +0100108/** Available DeconvolutionMethod*/
109enum class DeconvolutionMethod
110{
SiCong Li4ceb4532023-03-13 15:02:23 +0000111 GEMM, /**< Deconvolution using GEMM */
112 DIRECT, /**< Direct deconvolution */
113 UPSCALE_CONV2D /**< Deconvolution with Upscaling */
giuros0146a49a02019-04-01 13:50:22 +0100114};
115
Manuel Bottini2732cca2019-05-28 11:44:41 +0100116/** Available FuseBatchNormalizationType*/
117enum class FuseBatchNormalizationType
118{
119 CONVOLUTION, /**< For Convolution weights */
120 DEPTHWISECONVOLUTION /**< For Depthwise Convolution weights*/
121};
122
Usama Arif89890c62019-03-19 10:57:05 +0000123/** Padding mode to use for PadLayer */
124enum class PaddingMode
125{
126 CONSTANT,
127 REFLECT,
128 SYMMETRIC
129};
130
Georgios Pinitas7900a9e2018-11-23 11:44:58 +0000131/** Supported comparison operations */
132enum class ComparisonOperation
133{
134 Equal, /**< Equal comparison ( \f$ x == y \f$ ) */
135 NotEqual, /**< NotEqual comparison ( \f$ x != y \f$ ) */
136 Greater, /**< Greater comparison ( \f$ x > y \f$ ) */
137 GreaterEqual, /**< Greater equal comparison ( \f$ x >= y \f$ ) */
138 Less, /**< Less comparison ( \f$ x < y \f$ ) */
139 LessEqual /**< Less equal comparison ( \f$ x <= y \f$ ) */
140};
141
Alex Gildayc357c472018-03-21 13:54:09 +0000142/** Container for valid region of a window */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100143struct ValidRegion
144{
Alex Gildayc357c472018-03-21 13:54:09 +0000145 /** Default constructor */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100146 ValidRegion()
147 : anchor{}, shape{}
148 {
149 }
150
Alex Gildayc357c472018-03-21 13:54:09 +0000151 /** Allow instances of this class to be copy constructed */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100152 ValidRegion(const ValidRegion &) = default;
Alex Gildayc357c472018-03-21 13:54:09 +0000153 /** Allow instances of this class to be move constructed */
154 ValidRegion(ValidRegion &&) = default;
155 /** Allow instances of this class to be copied */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100156 ValidRegion &operator=(const ValidRegion &) = default;
Alex Gildayc357c472018-03-21 13:54:09 +0000157 /** Allow instances of this class to be moved */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100158 ValidRegion &operator=(ValidRegion &&) = default;
Alex Gildayc357c472018-03-21 13:54:09 +0000159 /** Default destructor */
160 ~ValidRegion() = default;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100161
Alex Gildayc357c472018-03-21 13:54:09 +0000162 /** Constructor for a valid region with default number of dimensions
163 *
164 * @param[in] an_anchor Anchor for the start of the valid region.
165 * @param[in] a_shape Shape of the valid region.
166 *
167 */
Diego Lopez Recasbcbc9702017-12-18 11:28:27 +0000168 ValidRegion(const Coordinates &an_anchor, const TensorShape &a_shape)
169 : anchor{ an_anchor }, shape{ a_shape }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100170 {
Diego Lopez Recasbcbc9702017-12-18 11:28:27 +0000171 anchor.set_num_dimensions(std::max(anchor.num_dimensions(), shape.num_dimensions()));
172 }
173
Alex Gildayc357c472018-03-21 13:54:09 +0000174 /** Constructor for a valid region with specified number of dimensions
175 *
176 * @param[in] an_anchor Anchor for the start of the valid region.
177 * @param[in] a_shape Shape of the valid region.
178 * @param[in] num_dimensions Number of dimensions (must be >= number of dimensions of anchor and shape).
179 *
180 */
Diego Lopez Recasbcbc9702017-12-18 11:28:27 +0000181 ValidRegion(const Coordinates &an_anchor, const TensorShape &a_shape, size_t num_dimensions)
182 : anchor{ an_anchor }, shape{ a_shape }
183 {
184 ARM_COMPUTE_ERROR_ON(num_dimensions < std::max(anchor.num_dimensions(), shape.num_dimensions()));
185 anchor.set_num_dimensions(num_dimensions);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100186 }
187
188 /** Return the start of the valid region for the given dimension @p d */
189 int start(unsigned int d) const
190 {
191 return anchor[d];
192 }
193
194 /** Return the end of the valid region for the given dimension @p d */
195 int end(unsigned int d) const
196 {
197 return anchor[d] + shape[d];
198 }
199
Diego Lopez Recas35ceeb22017-12-04 18:56:10 +0000200 /** Accessor to set the value of anchor and shape for one of the dimensions.
201 *
202 * @param[in] dimension Dimension for which the value is set.
203 * @param[in] start Value to be set in anchor for the dimension.
204 * @param[in] size Value to be set in shape for the dimension.
205 *
206 * @return *this.
207 */
208 ValidRegion &set(size_t dimension, int start, size_t size)
209 {
210 anchor.set(dimension, start);
211 shape.set(dimension, size);
212 return *this;
213 }
214
SiCong Lib63b1192022-01-28 18:24:39 +0000215 /** Check whether two valid regions are equal.
216 *
217 * @param[in] lhs LHS valid region
218 * @param[in] rhs RHS valid region
219 *
220 * @return True if the valid regions are the same.
221 */
222 inline friend bool operator==(const ValidRegion &lhs, const ValidRegion &rhs);
223
Alex Gildayc357c472018-03-21 13:54:09 +0000224 Coordinates anchor; /**< Anchor for the start of the valid region. */
225 TensorShape shape; /**< Shape of the valid region. */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100226};
SiCong Lib63b1192022-01-28 18:24:39 +0000227inline bool operator==(const ValidRegion &lhs, const ValidRegion &rhs)
228{
229 return (lhs.anchor == rhs.anchor) && (lhs.shape == rhs.shape);
230}
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100231
232/** Methods available to handle borders */
233enum class BorderMode
234{
235 UNDEFINED, /**< Borders are left undefined */
236 CONSTANT, /**< Pixels outside the image are assumed to have a constant value */
237 REPLICATE /**< Pixels outside the image are assumed to have the same value as the closest image pixel */
238};
239
240/** Container for 2D border size */
241struct BorderSize
242{
243 /** Empty border, i.e. no border */
Pablo Marquez Tello383de022021-03-18 11:31:13 +0000244 constexpr BorderSize() noexcept
245 : top{ 0 },
246 right{ 0 },
247 bottom{ 0 },
248 left{ 0 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100249 {
250 }
251
252 /** Border with equal size around the 2D plane */
Pablo Marquez Tello383de022021-03-18 11:31:13 +0000253 explicit constexpr BorderSize(unsigned int size) noexcept
254 : top{ size },
255 right{ size },
256 bottom{ size },
257 left{ size }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100258 {
259 }
260
261 /** Border with same size for top/bottom and left/right */
262 constexpr BorderSize(unsigned int top_bottom, unsigned int left_right)
263 : top{ top_bottom }, right{ left_right }, bottom{ top_bottom }, left{ left_right }
264 {
265 }
266
267 /** Border with different sizes */
268 constexpr BorderSize(unsigned int top, unsigned int right, unsigned int bottom, unsigned int left)
269 : top{ top }, right{ right }, bottom{ bottom }, left{ left }
270 {
271 }
272
273 /** Check if the entire border is zero */
274 constexpr bool empty() const
275 {
276 return top == 0 && right == 0 && bottom == 0 && left == 0;
277 }
278
279 /** Check if the border is the same size on all sides */
280 constexpr bool uniform() const
281 {
282 return top == right && top == bottom && top == left;
283 }
284
Alex Gildayc357c472018-03-21 13:54:09 +0000285 /** Scale this border size.
286 *
287 * @param[in] scale Scale to multiply border size by.
288 *
289 * @return *this.
290 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100291 BorderSize &operator*=(float scale)
292 {
293 top *= scale;
294 right *= scale;
295 bottom *= scale;
296 left *= scale;
297
298 return *this;
299 }
300
Alex Gildayc357c472018-03-21 13:54:09 +0000301 /** Scale a copy of this border size.
302 *
303 * @param[in] scale Scale to multiply border size by.
304 *
305 * @return a scaled copy of this.
306 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100307 BorderSize operator*(float scale)
308 {
309 BorderSize size = *this;
310 size *= scale;
311
312 return size;
313 }
314
Giorgio Arena1e2af2a2020-10-15 17:39:41 +0100315 /** Check equality with another BorderSize struct
316 *
317 * @param[in] rhs other struct to check against
318 *
319 * @return true if they are equal
320 */
SiCong Lib63b1192022-01-28 18:24:39 +0000321 bool operator==(const BorderSize &rhs) const
Giorgio Arena1e2af2a2020-10-15 17:39:41 +0100322 {
323 return (top == rhs.top) && (right == rhs.right) && (bottom == rhs.bottom) && (left == rhs.left);
324 }
325
326 /** Check non-equality with another BorderSize struct
327 *
328 * @param[in] rhs other struct to check against
329 *
330 * @return true if they are different
331 */
SiCong Lib63b1192022-01-28 18:24:39 +0000332 bool operator!=(const BorderSize &rhs) const
Giorgio Arena1e2af2a2020-10-15 17:39:41 +0100333 {
334 return !(*this == rhs);
335 }
336
Alex Gildayc357c472018-03-21 13:54:09 +0000337 /** Limit this border size.
338 *
339 * @param[in] limit Border size to limit this border size to.
340 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100341 void limit(const BorderSize &limit)
342 {
343 top = std::min(top, limit.top);
344 right = std::min(right, limit.right);
345 bottom = std::min(bottom, limit.bottom);
346 left = std::min(left, limit.left);
347 }
348
Alex Gildayc357c472018-03-21 13:54:09 +0000349 unsigned int top; /**< top of the border */
350 unsigned int right; /**< right of the border */
351 unsigned int bottom; /**< bottom of the border */
352 unsigned int left; /**< left of the border */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100353};
354
Alex Gildayc357c472018-03-21 13:54:09 +0000355/** Container for 2D padding size */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100356using PaddingSize = BorderSize;
357
SiCongLi1af54162021-10-06 15:25:57 +0100358/** Policy to handle integer overflow
359 * @note: This is ignored by floating point operations where the overflow behavior adheres to the IEEE-754 standard
360 * which states that in case of overflow ±infinity is returned for the round-to-nearest modes (and follows the
361 * rounding rules for the directed rounding modes) by default.
362 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100363enum class ConvertPolicy
364{
365 WRAP, /**< Wrap around */
366 SATURATE /**< Saturate */
367};
368
369/** Interpolation method */
370enum class InterpolationPolicy
371{
372 NEAREST_NEIGHBOR, /**< Output values are defined to match the source pixel whose center is nearest to the sample position */
373 BILINEAR, /**< Output values are defined by bilinear interpolation between the pixels */
374 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 */
375};
376
377/** Bilinear Interpolation method used by LKTracker */
378enum class BilinearInterpolation
379{
Alex Gildayc357c472018-03-21 13:54:09 +0000380 BILINEAR_OLD_NEW, /**< Old-new method */
381 BILINEAR_SCHARR /**< Scharr method */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100382};
383
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100384/** Rectangle type */
385struct Rectangle
386{
387 uint16_t x; /**< Top-left x coordinate */
388 uint16_t y; /**< Top-left y coordinate */
389 uint16_t width; /**< Width of the rectangle */
390 uint16_t height; /**< Height of the rectangle */
391};
392
393/** Coordinate type */
394struct Coordinates2D
395{
396 int32_t x; /**< X coordinates */
397 int32_t y; /**< Y coordinates */
398};
399
400/** Coordinate type */
401struct Coordinates3D
402{
403 uint32_t x; /**< X coordinates */
404 uint32_t y; /**< Y coordinates */
405 uint32_t z; /**< Z coordinates */
406};
407
Giuseppe Rossinid7647d42018-07-17 18:13:13 +0100408/** Padding information as a pair of unsigned int start/end */
409using PaddingInfo = std::pair<uint32_t, uint32_t>;
410
411/** List of padding information */
412using PaddingList = std::vector<PaddingInfo>;
413
giuros013175fcf2018-11-21 09:59:17 +0000414/** Information to produce a tiled version of a Tensor */
415using Multiples = std::vector<uint32_t>;
416
Georgios Pinitasd9769582017-08-03 10:19:40 +0100417/** Available reduction operations */
418enum class ReductionOperation
419{
Michalis Spyrou7930db42018-11-22 17:36:28 +0000420 ARG_IDX_MAX, /**< Index of the max value */
Manuel Bottinib412fab2018-12-10 17:40:23 +0000421 ARG_IDX_MIN, /**< Index of the min value */
422 MEAN_SUM, /**< Mean of sum */
423 PROD, /**< Product */
424 SUM_SQUARE, /**< Sum of squares */
Usama Arifa4a08ad2019-05-20 12:38:33 +0100425 SUM, /**< Sum */
426 MIN, /**< Min */
Usama Arif28f0dd92019-05-20 13:44:34 +0100427 MAX, /**< Max */
Georgios Pinitasd9769582017-08-03 10:19:40 +0100428};
429
giuros01164a2722018-11-20 18:34:46 +0000430/** Available element-wise operations */
431enum class ArithmeticOperation
432{
433 ADD, /**< (x + y) */
434 SUB, /**< (x - y) */
435 DIV, /**< (x / y) */
436 MIN, /**< Min(x, y) */
437 MAX, /**< Max(x, y) */
438 SQUARED_DIFF, /**< (x - y)^2 */
Usama Arif81e671e2019-05-13 13:33:14 +0100439 POWER, /**< x ^ y */
giuros011e6e1b82019-05-14 16:12:53 +0100440 PRELU, /**< y*x if x < 0, x otherwise */
giuros01164a2722018-11-20 18:34:46 +0000441};
442
Michalis Spyroue9362622018-11-23 17:41:37 +0000443/** Available element wise unary operations */
444enum class ElementWiseUnary
445{
Sang-Hoon Park75eea332020-11-13 13:44:13 +0000446 RSQRT, /**< Reverse square root */
447 EXP, /**< Exponential */
448 NEG, /**< Negate */
449 LOG, /**< Natural Logarithm */
450 ABS, /**< Absolute value */
451 SIN, /**< Sine */
452 ROUND, /**< Round */
453 LOGICAL_NOT, /**< Logical Not */
Michalis Spyroue9362622018-11-23 17:41:37 +0000454};
455
Manuel Bottini63bb7ca2020-12-02 13:22:14 +0000456/** Available bitwise operations */
457enum class BitwiseOperation
458{
459 AND, /**< Bitwise AND operation */
460 NOT, /**< Bitwise NOT operation */
461 OR, /**< Bitwise OR operation */
462 XOR, /**< Bitwise XOR operation */
463};
464
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100465/** The normalization type used for the normalization layer */
466enum class NormType
467{
468 IN_MAP_1D, /**< Normalization applied within the same map in 1D region */
469 IN_MAP_2D, /**< Normalization applied within the same map in 2D region */
470 CROSS_MAP /**< Normalization applied cross maps */
471};
472
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100473/** Detection window used for the object detection. The detection window keeps the following information:
474 *
475 * -# Geometry of the rectangular window (x/y of top-left corner and width/height)
476 * -# Index of the class used for evaluating which class the detection window belongs to
477 * -# Confidence value (score) obtained with the classifier
478 */
479struct DetectionWindow
480{
481 uint16_t x{ 0 }; /**< Top-left x coordinate */
482 uint16_t y{ 0 }; /**< Top-left y coordinate */
483 uint16_t width{ 0 }; /**< Width of the detection window */
484 uint16_t height{ 0 }; /**< Height of the detection window */
485 uint16_t idx_class{ 0 }; /**< Index of the class */
486 float score{ 0.f }; /**< Confidence value for the detection window */
487};
488
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100489/** Available pooling types */
490enum class PoolingType
491{
492 MAX, /**< Max Pooling */
Georgios Pinitascdf51452017-08-31 14:21:36 +0100493 AVG, /**< Average Pooling */
494 L2 /**< L2 Pooling */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100495};
496
Michalis Spyrou2709d612018-09-19 09:46:47 +0100497/** Available non maxima suppression types */
498enum class NMSType
499{
500 LINEAR, /**< Linear NMS */
501 GAUSSIAN, /**< Gaussian NMS */
502 ORIGINAL /**< Original NMS */
503};
504
505/** BoxWithNonMaximaSuppressionLimit Information class */
506class BoxNMSLimitInfo final
507{
508public:
509 /** Constructor
510 *
511 * @param[in] score_thresh (Optional) Score threshold.
512 * @param[in] nms (Optional) NMS value
513 * @param[in] detections (Optional) Number of detections
514 * @param[in] soft_nms_enabled (Optional) Enable SoftNMS
515 * @param[in] soft_nms_method (Optional) Soft NMS method
516 * @param[in] soft_nms_sigma (Optional) Soft NMS sigma value
517 * @param[in] soft_nms_min_score_thres (Optional) Soft NMS minimum score threshold
Manuel Bottini5209be52019-02-13 16:34:56 +0000518 * @param[in] suppress_size (Optional) Filter out boxes based on their size. Defaults to false
519 * @param[in] min_size (Optional) Smaller boxes than min_size will be filtered out. Defaults to 1
520 * @param[in] im_width (Optional) Boxes whose centers (on the x axis) is beyond im_width will be filtered. Defaults to 1
521 * @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 +0100522 */
523 BoxNMSLimitInfo(float score_thresh = 0.05f, float nms = 0.3f,
524 int detections = 100, bool soft_nms_enabled = false,
525 NMSType soft_nms_method = NMSType::LINEAR,
Manuel Bottini5209be52019-02-13 16:34:56 +0000526 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 +0100527 : _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 +0000528 _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 +0100529 {
530 }
531 /** Get the score threshold */
532 float score_thresh() const
533 {
534 return _score_thresh;
535 }
536 /** Get the NMS */
537 float nms() const
538 {
539 return _nms;
540 }
541 /** Get the number of detections */
542 int detections_per_im() const
543 {
544 return _detections_per_im;
545 }
546 /** Check if soft NMS is enabled */
547 bool soft_nms_enabled() const
548 {
549 return _soft_nms_enabled;
550 }
551 /** Get soft NMS method */
552 NMSType soft_nms_method() const
553 {
554 return _soft_nms_method;
555 }
556 /** Get soft NMS sigma */
557 float soft_nms_sigma() const
558 {
559 return _soft_nms_sigma;
560 }
561 /** Get soft nms min score threshold */
562 float soft_nms_min_score_thres() const
563 {
564 return _soft_nms_min_score_thres;
565 }
Manuel Bottini5209be52019-02-13 16:34:56 +0000566 /** Get if NMS will suppress boxes based on their size/position */
567 bool suppress_size() const
568 {
569 return _suppress_size;
570 }
571 /** Get size suppression threshold */
572 float min_size() const
573 {
574 return _min_size;
575 }
576 /** Get image width (NMS may suppress boxes whose center sits beyond the image width) */
577 float im_width() const
578 {
579 return _im_width;
580 }
581 /** Get image height (NMS may suppress boxes whose center sits beyond the image height) */
582 float im_height() const
583 {
584 return _im_height;
585 }
Michalis Spyrou2709d612018-09-19 09:46:47 +0100586
587private:
588 float _score_thresh;
589 float _nms;
590 int _detections_per_im;
591 bool _soft_nms_enabled;
592 NMSType _soft_nms_method;
593 float _soft_nms_sigma;
594 float _soft_nms_min_score_thres;
Manuel Bottini5209be52019-02-13 16:34:56 +0000595 bool _suppress_size;
596 float _min_size;
597 float _im_width;
598 float _im_height;
Michalis Spyrou2709d612018-09-19 09:46:47 +0100599};
600
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100601/** Padding and stride information class */
SiCong Lif44bbc52022-08-29 18:25:51 +0100602/** Padding information for 2D operations like Conv2d */
603struct Padding2D
604{
605 Padding2D() = default;
606 Padding2D(size_t left, size_t right, size_t top, size_t bottom)
607 : left(left), right(right), top(top), bottom(bottom)
608 {
609 }
610 size_t left = { 0 }; /**< Padding across the width dimension on the left, in elements. */
611 size_t right = { 0 }; /**< Padding across the width dimension on the right, in elements. */
612 size_t top = { 0 }; /**< Padding across the height dimension on the top, in elements. */
613 size_t bottom = { 0 }; /**< Padding across the height dimension on the bottom, in elements. */
614};
615
Adnan AlSinane4563a02021-09-01 15:32:03 +0100616/** Padding information for 3D operations like Conv3d */
617struct Padding3D
618{
Freddie Liardetebefe522021-11-25 16:19:28 +0000619 Padding3D() noexcept
Giorgio Arenac9fe9fc2021-10-06 12:54:29 +0100620 {
621 }
622
623 Padding3D(size_t pad_x, size_t pad_y, size_t pad_z)
624 : left(pad_x), right(pad_x), top(pad_y), bottom(pad_y), front(pad_z), back(pad_z)
625 {
626 }
627
628 Padding3D(size_t left, size_t right, size_t top, size_t bottom, size_t front, size_t back)
629 : left(left), right(right), top(top), bottom(bottom), front(front), back(back)
630 {
631 }
632
Adnan AlSinane4563a02021-09-01 15:32:03 +0100633 size_t left = { 0 }; /**< Padding across the width dimenstion on the left, in elements. */
634 size_t right = { 0 }; /**< Padding across the width dimenstion on the right, in elements. */
635 size_t top = { 0 }; /**< Padding across the height dimenstion on the top, in elements. */
636 size_t bottom = { 0 }; /**< Padding across the height dimenstion on the bottom, in elements. */
637 size_t front = { 0 }; /**< Padding across the depth dimenstion on the front, in elements. */
638 size_t back = { 0 }; /**< Padding across the depth dimenstion on the back, in elements. */
639};
640
Michalis Spyrou6c7c38e2018-08-29 16:28:11 +0100641/** PriorBox layer info */
642class PriorBoxLayerInfo final
643{
644public:
645 /** Default Constructor */
646 PriorBoxLayerInfo()
647 : _min_sizes(),
648 _variances(),
649 _offset(),
650 _flip(true),
651 _clip(false),
652 _max_sizes(),
653 _aspect_ratios(),
654 _img_size(),
655 _steps()
656 {
657 }
658 /** Constructor
659 *
660 * @param[in] min_sizes Min sizes vector.
Michalis Spyrou721c4cb2018-09-04 15:27:25 +0100661 * @param[in] variances Variances vector.
Michalis Spyrou6c7c38e2018-08-29 16:28:11 +0100662 * @param[in] offset Offset value.
663 * @param[in] flip (Optional) Flip the aspect ratios.
664 * @param[in] clip (Optional) Clip coordinates so that they're within [0,1].
665 * @param[in] max_sizes (Optional) Max sizes vector.
666 * @param[in] aspect_ratios (Optional) Aspect ratios of the boxes.
667 * @param[in] img_size (Optional) Image size.
668 * @param[in] steps (Optional) Step values.
669 */
670 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 +0000671 const std::vector<float> &max_sizes = {}, const std::vector<float> &aspect_ratios = {},
672 const Coordinates2D &img_size = Coordinates2D{ 0, 0 }, const std::array<float, 2> &steps = { { 0.f, 0.f } })
Michalis Spyrou6c7c38e2018-08-29 16:28:11 +0100673 : _min_sizes(min_sizes),
674 _variances(variances),
675 _offset(offset),
676 _flip(flip),
677 _clip(clip),
678 _max_sizes(max_sizes),
Michalis Spyrou721c4cb2018-09-04 15:27:25 +0100679 _aspect_ratios(),
Michalis Spyrou6c7c38e2018-08-29 16:28:11 +0100680 _img_size(img_size),
681 _steps(steps)
682 {
683 _aspect_ratios.push_back(1.);
684 for(unsigned int i = 0; i < aspect_ratios.size(); ++i)
685 {
686 float ar = aspect_ratios[i];
687 bool already_exist = false;
688 for(auto ar_new : _aspect_ratios)
689 {
690 if(fabs(ar - ar_new) < 1e-6)
691 {
692 already_exist = true;
693 break;
694 }
695 }
696 if(!already_exist)
697 {
698 _aspect_ratios.push_back(ar);
699 if(flip)
700 {
701 _aspect_ratios.push_back(1.f / ar);
702 }
703 }
704 }
705 }
706 /** Get min sizes. */
707 std::vector<float> min_sizes() const
708 {
709 return _min_sizes;
710 }
711 /** Get min variances. */
712 std::vector<float> variances() const
713 {
714 return _variances;
715 }
716 /** Get the step coordinates */
717 std::array<float, 2> steps() const
718 {
719 return _steps;
720 }
721 /** Get the image size coordinates */
722 Coordinates2D img_size() const
723 {
724 return _img_size;
725 }
726 /** Get the offset */
727 float offset() const
728 {
729 return _offset;
730 }
731 /** Get the flip value */
732 bool flip() const
733 {
734 return _flip;
735 }
736 /** Get the clip value */
737 bool clip() const
738 {
739 return _clip;
740 }
741 /** Get max sizes. */
742 std::vector<float> max_sizes() const
743 {
744 return _max_sizes;
745 }
746 /** Get aspect ratios. */
747 std::vector<float> aspect_ratios() const
748 {
749 return _aspect_ratios;
750 }
751
752private:
Jakub Sujak0d27b2e2023-08-24 14:01:20 +0100753 std::vector<float> _min_sizes;
754 std::vector<float> _variances;
755 float _offset;
756 bool _flip;
757 bool _clip;
758 std::vector<float> _max_sizes;
759 std::vector<float> _aspect_ratios;
760 Coordinates2D _img_size;
Michalis Spyrou6c7c38e2018-08-29 16:28:11 +0100761 std::array<float, 2> _steps;
762};
763
Isabella Gottardia7acb3c2019-01-08 13:48:44 +0000764// Bounding Box [xmin, ymin, xmax, ymax]
765using BBox = std::array<float, 4>;
766// LabelBBox used for map label and bounding box
767using LabelBBox = std::map<int, std::vector<BBox>>;
768
Isabella Gottardi05e56442018-11-16 11:26:52 +0000769/** Available Detection Output code types */
770enum class DetectionOutputLayerCodeType
771{
772 CORNER, /**< Use box corners */
773 CENTER_SIZE, /**< Use box centers and size */
774 CORNER_SIZE, /**< Use box centers and size */
775 TF_CENTER /**< Use box centers and size but flip x and y co-ordinates */
776};
777
778/** Detection Output layer info */
779class DetectionOutputLayerInfo final
780{
781public:
782 /** Default Constructor */
783 DetectionOutputLayerInfo()
784 : _num_classes(),
785 _share_location(),
786 _code_type(DetectionOutputLayerCodeType::CORNER),
787 _keep_top_k(),
788 _nms_threshold(),
789 _top_k(),
790 _background_label_id(),
791 _confidence_threshold(),
792 _variance_encoded_in_target(false),
793 _eta(),
794 _num_loc_classes()
795 {
796 _num_loc_classes = _share_location ? 1 : _num_classes;
797 }
798 /** Constructor
799 *
800 * @param[in] num_classes Number of classes to be predicted.
801 * @param[in] share_location If true, bounding box are shared among different classes.
802 * @param[in] code_type Type of coding method for bbox.
803 * @param[in] keep_top_k Number of total bounding boxes to be kept per image after NMS step.
804 * @param[in] nms_threshold Threshold to be used in NMS.
805 * @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.
806 * @param[in] background_label_id (Optional) Background label ID. If there is no background class, set it as -1.
807 * @param[in] confidence_threshold (Optional) Only consider detections whose confidences are larger than a threshold. Default set to -FLT_MAX.
808 * @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.
809 * @param[in] eta (Optional) Eta.
810 */
811 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,
812 float confidence_threshold = std::numeric_limits<float>::lowest(), bool variance_encoded_in_target = false, float eta = 1)
813 : _num_classes(num_classes),
814 _share_location(share_location),
815 _code_type(code_type),
816 _keep_top_k(keep_top_k),
817 _nms_threshold(nms_threshold),
818 _top_k(top_k),
819 _background_label_id(background_label_id),
820 _confidence_threshold(confidence_threshold),
821 _variance_encoded_in_target(variance_encoded_in_target),
822 _eta(eta),
823 _num_loc_classes()
824 {
825 _num_loc_classes = _share_location ? 1 : _num_classes;
826 }
827 /** Get num classes. */
828 int num_classes() const
829 {
830 return _num_classes;
831 }
832 /** Get share location. */
833 bool share_location() const
834 {
835 return _share_location;
836 }
837 /** Get detection output code type. */
838 DetectionOutputLayerCodeType code_type() const
839 {
840 return _code_type;
841 }
842 /** Get if variance encoded in target. */
843 bool variance_encoded_in_target() const
844 {
845 return _variance_encoded_in_target;
846 }
847 /** Get the number of total bounding boxes to be kept per image. */
848 int keep_top_k() const
849 {
850 return _keep_top_k;
851 }
852 /** Get nms threshold. */
853 float nms_threshold() const
854 {
855 return _nms_threshold;
856 }
857 /** Get eta. */
858 float eta() const
859 {
860 return _eta;
861 }
862 /** Get background label ID. */
863 int background_label_id() const
864 {
865 return _background_label_id;
866 }
867 /** Get confidence threshold. */
868 float confidence_threshold() const
869 {
870 return _confidence_threshold;
871 }
872 /** Get top K. */
873 int top_k() const
874 {
875 return _top_k;
876 }
877 /** Get number of location classes. */
878 int num_loc_classes() const
879 {
880 return _num_loc_classes;
881 }
882
883private:
884 int _num_classes;
885 bool _share_location;
886 DetectionOutputLayerCodeType _code_type;
887 int _keep_top_k;
888 float _nms_threshold;
889 int _top_k;
890 int _background_label_id;
891 float _confidence_threshold;
892 bool _variance_encoded_in_target;
893 float _eta;
894 int _num_loc_classes;
895};
896
Isabella Gottardia7acb3c2019-01-08 13:48:44 +0000897/** Detection Output layer info */
898class DetectionPostProcessLayerInfo final
899{
900public:
901 /** Default Constructor */
902 DetectionPostProcessLayerInfo()
903 : _max_detections(),
904 _max_classes_per_detection(),
905 _nms_score_threshold(),
906 _iou_threshold(),
907 _num_classes(),
908 _scales_values(),
909 _use_regular_nms(),
Giuseppe Rossinid9853782019-10-25 11:11:44 +0100910 _detection_per_class(),
911 _dequantize_scores()
Isabella Gottardia7acb3c2019-01-08 13:48:44 +0000912 {
913 }
914 /** Constructor
915 *
916 * @param[in] max_detections Number of total detection.
917 * @param[in] max_classes_per_detection Number of total classes to be kept after NMS step. Used in the Fast Non-Max-Suppression
918 * @param[in] nms_score_threshold Threshold to be used in NMS
919 * @param[in] iou_threshold Threshold to be used during the intersection over union.
920 * @param[in] num_classes Number of classes.
921 * @param[in] scales_values Scales values used for decode center size boxes.
Giuseppe Rossinid9853782019-10-25 11:11:44 +0100922 * @param[in] use_regular_nms (Optional) Boolean to determinate if use regular or fast nms. Defaults to false.
923 * @param[in] detection_per_class (Optional) Number of detection per class. Used in the Regular Non-Max-Suppression. Defaults to 100.
924 * @param[in] dequantize_scores (Optional) If the scores need to be dequantized. Defaults to true.
Isabella Gottardia7acb3c2019-01-08 13:48:44 +0000925 */
926 DetectionPostProcessLayerInfo(unsigned int max_detections, unsigned int max_classes_per_detection, float nms_score_threshold, float iou_threshold, unsigned int num_classes,
Giuseppe Rossinid9853782019-10-25 11:11:44 +0100927 std::array<float, 4> scales_values, bool use_regular_nms = false, unsigned int detection_per_class = 100, bool dequantize_scores = true)
Isabella Gottardia7acb3c2019-01-08 13:48:44 +0000928 : _max_detections(max_detections),
929 _max_classes_per_detection(max_classes_per_detection),
930 _nms_score_threshold(nms_score_threshold),
931 _iou_threshold(iou_threshold),
932 _num_classes(num_classes),
933 _scales_values(scales_values),
934 _use_regular_nms(use_regular_nms),
Giuseppe Rossinid9853782019-10-25 11:11:44 +0100935 _detection_per_class(detection_per_class),
936 _dequantize_scores(dequantize_scores)
Isabella Gottardia7acb3c2019-01-08 13:48:44 +0000937 {
938 }
939 /** Get max detections. */
940 unsigned int max_detections() const
941 {
942 return _max_detections;
943 }
944 /** Get max_classes per detection. Used in the Fast Non-Max-Suppression.*/
945 unsigned int max_classes_per_detection() const
946 {
947 return _max_classes_per_detection;
948 }
949 /** Get detection per class. Used in the Regular Non-Max-Suppression */
950 unsigned int detection_per_class() const
951 {
952 return _detection_per_class;
953 }
954 /** Get nms threshold. */
955 float nms_score_threshold() const
956 {
957 return _nms_score_threshold;
958 }
959 /** Get intersection over union threshold. */
960 float iou_threshold() const
961 {
962 return _iou_threshold;
963 }
964 /** Get num classes. */
965 unsigned int num_classes() const
966 {
967 return _num_classes;
968 }
969 /** Get if use regular nms. */
970 bool use_regular_nms() const
971 {
972 return _use_regular_nms;
973 }
974 /** Get y scale value. */
975 float scale_value_y() const
976 {
977 // Saved as [y,x,h,w]
978 return _scales_values[0];
979 }
980 /** Get x scale value. */
981 float scale_value_x() const
982 {
983 // Saved as [y,x,h,w]
984 return _scales_values[1];
985 }
986 /** Get h scale value. */
987 float scale_value_h() const
988 {
989 // Saved as [y,x,h,w]
990 return _scales_values[2];
991 }
992 /** Get w scale value. */
993 float scale_value_w() const
994 {
995 // Saved as [y,x,h,w]
996 return _scales_values[3];
997 }
Giuseppe Rossinid9853782019-10-25 11:11:44 +0100998 /** Get dequantize_scores value. */
999 bool dequantize_scores() const
1000 {
1001 return _dequantize_scores;
1002 }
Isabella Gottardia7acb3c2019-01-08 13:48:44 +00001003
1004private:
Jakub Sujak0d27b2e2023-08-24 14:01:20 +01001005 unsigned int _max_detections;
1006 unsigned int _max_classes_per_detection;
1007 float _nms_score_threshold;
1008 float _iou_threshold;
1009 unsigned int _num_classes;
Isabella Gottardia7acb3c2019-01-08 13:48:44 +00001010 std::array<float, 4> _scales_values;
Jakub Sujak0d27b2e2023-08-24 14:01:20 +01001011 bool _use_regular_nms;
1012 unsigned int _detection_per_class;
1013 bool _dequantize_scores;
Isabella Gottardia7acb3c2019-01-08 13:48:44 +00001014};
1015
Sang-Hoon Park0cb3da62020-01-15 12:39:56 +00001016/** Pooling Layer Information struct*/
1017struct PoolingLayerInfo
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001018{
Georgios Pinitas4c2dd542017-11-13 12:58:41 +00001019 /** Default Constructor */
1020 PoolingLayerInfo()
Sang-Hoon Park11fedda2020-01-15 14:44:04 +00001021 : pool_type(PoolingType::MAX),
1022 pool_size(Size2D()),
1023 data_layout(DataLayout::UNKNOWN),
1024 pad_stride_info(PadStrideInfo()),
1025 exclude_padding(false),
1026 is_global_pooling(false),
Adnan AlSinan227db8d2023-02-14 14:24:09 +00001027 fp_mixed_precision(false),
Adnan AlSinanbbf2e742023-02-22 12:15:14 +00001028 use_inf_as_limit(true),
1029 use_kernel_indices(false)
Georgios Pinitas4c2dd542017-11-13 12:58:41 +00001030 {
1031 }
Sang-Hoon Park11fedda2020-01-15 14:44:04 +00001032 /** Constructor
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001033 *
Sang-Hoon Park2aa7fd02019-09-18 13:39:00 +01001034 * @param[in] pool_type Pooling type @ref PoolingType.
1035 * @param[in] pool_size Pooling size, in elements, across x and y.
Sang-Hoon Park11fedda2020-01-15 14:44:04 +00001036 * @param[in] data_layout Data layout used by the layer @ref DataLayout
1037 * @param[in] pad_stride_info (Optional) Padding and stride information @ref PadStrideInfo
1038 * @param[in] exclude_padding (Optional) Strategy when accounting padding in calculations.
1039 * True will exclude padding while false will not (Used in AVG/L2 pooling to determine the pooling area).
1040 * Defaults to false;
1041 * @param[in] fp_mixed_precision (Optional) Use wider accumulators (32 bit instead of 16 for FP16) to improve accuracy.
Adnan AlSinan227db8d2023-02-14 14:24:09 +00001042 * @param[in] use_inf_as_limit (Optional) Use inf to represent the limits of datatypes range, instead of using "lowest" property of the data type.
Adnan AlSinanbbf2e742023-02-22 12:15:14 +00001043 * @param[in] use_kernel_indices (Optional) Use kernel indices instead of using source indices while computing indices tensor.
Sang-Hoon Park11fedda2020-01-15 14:44:04 +00001044 */
Georgios Pinitas4c2dd542017-11-13 12:58:41 +00001045 explicit PoolingLayerInfo(PoolingType pool_type,
1046 unsigned int pool_size,
Sang-Hoon Park11fedda2020-01-15 14:44:04 +00001047 DataLayout data_layout,
Sang-Hoon Park2aa7fd02019-09-18 13:39:00 +01001048 PadStrideInfo pad_stride_info = PadStrideInfo(),
1049 bool exclude_padding = false,
Adnan AlSinan227db8d2023-02-14 14:24:09 +00001050 bool fp_mixed_precision = false,
Adnan AlSinanbbf2e742023-02-22 12:15:14 +00001051 bool use_inf_as_limit = true,
1052 bool use_kernel_indices = false)
Sang-Hoon Park11fedda2020-01-15 14:44:04 +00001053 : pool_type(pool_type),
1054 pool_size(Size2D(pool_size, pool_size)),
1055 data_layout(data_layout),
1056 pad_stride_info(pad_stride_info),
1057 exclude_padding(exclude_padding),
1058 is_global_pooling(false),
Adnan AlSinan227db8d2023-02-14 14:24:09 +00001059 fp_mixed_precision(fp_mixed_precision),
Adnan AlSinanbbf2e742023-02-22 12:15:14 +00001060 use_inf_as_limit(use_inf_as_limit),
1061 use_kernel_indices(use_kernel_indices)
Isabella Gottardi6e464c32018-01-26 12:32:45 +00001062 {
1063 }
Sang-Hoon Park11fedda2020-01-15 14:44:04 +00001064
1065 /** Constructor
Isabella Gottardi6e464c32018-01-26 12:32:45 +00001066 *
Sang-Hoon Park2aa7fd02019-09-18 13:39:00 +01001067 * @param[in] pool_type Pooling type @ref PoolingType.
1068 * @param[in] pool_size Pooling size, in elements, across x and y.
Sang-Hoon Park11fedda2020-01-15 14:44:04 +00001069 * @param[in] data_layout Data layout used by the layer @ref DataLayout
Sang-Hoon Park2aa7fd02019-09-18 13:39:00 +01001070 * @param[in] pad_stride_info (Optional) Padding and stride information @ref PadStrideInfo
1071 * @param[in] exclude_padding (Optional) Strategy when accounting padding in calculations.
1072 * True will exclude padding while false will not (Used in AVG/L2 pooling to determine the pooling area).
1073 * Defaults to false;
1074 * @param[in] fp_mixed_precision (Optional) Use wider accumulators (32 bit instead of 16 for FP16) to improve accuracy.
Adnan AlSinan227db8d2023-02-14 14:24:09 +00001075 * @param[in] use_inf_as_limit (Optional) Use inf to represent the limits of datatypes range, instead of using "lowest" property of the data type.
Adnan AlSinanbbf2e742023-02-22 12:15:14 +00001076 * @param[in] use_kernel_indices (Optional) Use kernel indices instead of using source indices while computing indices tensor.
Isabella Gottardi6e464c32018-01-26 12:32:45 +00001077 */
1078 explicit PoolingLayerInfo(PoolingType pool_type,
1079 Size2D pool_size,
Sang-Hoon Park11fedda2020-01-15 14:44:04 +00001080 DataLayout data_layout,
Sang-Hoon Park2aa7fd02019-09-18 13:39:00 +01001081 PadStrideInfo pad_stride_info = PadStrideInfo(),
1082 bool exclude_padding = false,
Adnan AlSinan227db8d2023-02-14 14:24:09 +00001083 bool fp_mixed_precision = false,
Adnan AlSinanbbf2e742023-02-22 12:15:14 +00001084 bool use_inf_as_limit = true,
1085 bool use_kernel_indices = false)
Sang-Hoon Park11fedda2020-01-15 14:44:04 +00001086 : pool_type(pool_type),
1087 pool_size(pool_size),
1088 data_layout(data_layout),
1089 pad_stride_info(pad_stride_info),
1090 exclude_padding(exclude_padding),
1091 is_global_pooling(false),
Adnan AlSinan227db8d2023-02-14 14:24:09 +00001092 fp_mixed_precision(fp_mixed_precision),
Adnan AlSinanbbf2e742023-02-22 12:15:14 +00001093 use_inf_as_limit(use_inf_as_limit),
1094 use_kernel_indices(use_kernel_indices)
Georgios Pinitas4c2dd542017-11-13 12:58:41 +00001095 {
1096 }
Sang-Hoon Park11fedda2020-01-15 14:44:04 +00001097
1098 /** Constructor
Georgios Pinitas4c2dd542017-11-13 12:58:41 +00001099 *
1100 * @note This constructor is used for global pooling
1101 *
Sang-Hoon Park11fedda2020-01-15 14:44:04 +00001102 * @param[in] pool_type Pooling type @ref PoolingType.
1103 * @param[in] data_layout Data layout used by the layer @ref DataLayout
Georgios Pinitas4c2dd542017-11-13 12:58:41 +00001104 */
Sang-Hoon Park11fedda2020-01-15 14:44:04 +00001105 explicit PoolingLayerInfo(PoolingType pool_type, DataLayout data_layout)
1106 : pool_type(pool_type),
1107 pool_size(Size2D()),
1108 data_layout(data_layout),
1109 pad_stride_info(PadStrideInfo(1, 1, 0, 0)),
1110 exclude_padding(false),
1111 is_global_pooling(true),
Adnan AlSinan227db8d2023-02-14 14:24:09 +00001112 fp_mixed_precision(false),
Adnan AlSinanbbf2e742023-02-22 12:15:14 +00001113 use_inf_as_limit(true),
1114 use_kernel_indices(false)
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001115 {
1116 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001117
Sang-Hoon Park0cb3da62020-01-15 12:39:56 +00001118 PoolingType pool_type;
1119 Size2D pool_size;
Sang-Hoon Park11fedda2020-01-15 14:44:04 +00001120 DataLayout data_layout;
Sang-Hoon Park0cb3da62020-01-15 12:39:56 +00001121 PadStrideInfo pad_stride_info;
1122 bool exclude_padding;
1123 bool is_global_pooling;
1124 bool fp_mixed_precision;
Adnan AlSinan227db8d2023-02-14 14:24:09 +00001125 bool use_inf_as_limit;
Adnan AlSinanbbf2e742023-02-22 12:15:14 +00001126 bool use_kernel_indices;
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001127};
1128
ramelg0137515692022-02-26 22:06:20 +00001129/** Pooling Layer Information struct*/
1130struct Pooling3dLayerInfo
1131{
1132 /** Default Constructor */
Michalis Spyrou50e48aa2022-04-21 16:42:56 +01001133 Pooling3dLayerInfo() noexcept
ramelg0137515692022-02-26 22:06:20 +00001134 : pool_type(PoolingType::MAX),
1135 pool_size(Size3D()),
1136 stride(Size3D()),
1137 padding(Padding3D()),
1138 exclude_padding(false),
1139 is_global_pooling(false),
1140 fp_mixed_precision(false),
1141 round_type(DimensionRoundingType::FLOOR)
1142 {
1143 }
1144 /** Constructor
1145 *
1146 * @param[in] pool_type Pooling type @ref PoolingType.
1147 * @param[in] pool_size Pooling size, in elements, across x, y and z.
1148 * @param[in] stride (Optional) stride information @ref Size3D
1149 * @param[in] padding (Optional) padding information @ref Padding3D
1150 * @param[in] exclude_padding (Optional) Strategy when accounting padding in calculations.
1151 * True will exclude padding while false will not (Used in AVG/L2 pooling to determine the pooling area).
1152 * Defaults to false;
1153 * @param[in] fp_mixed_precision (Optional) Use wider accumulators (32 bit instead of 16 for FP16) to improve accuracy.
ramy.elgammal@arm.coma2561f02023-06-16 20:45:48 +01001154 * @param[in] round_type (Optional) Dimensions rounding. Defaults to @ref DimensionRoundingType::FLOOR
ramelg0137515692022-02-26 22:06:20 +00001155 */
1156 explicit Pooling3dLayerInfo(PoolingType pool_type,
1157 unsigned int pool_size,
1158 Size3D stride = Size3D(1U, 1U, 1U),
1159 Padding3D padding = Padding3D(),
1160 bool exclude_padding = false,
1161 bool fp_mixed_precision = false,
1162 DimensionRoundingType round_type = DimensionRoundingType::FLOOR)
1163 : pool_type(pool_type),
1164 pool_size(Size3D(pool_size, pool_size, pool_size)),
1165 stride(stride),
1166 padding(padding),
1167 exclude_padding(exclude_padding),
1168 is_global_pooling(false),
1169 fp_mixed_precision(fp_mixed_precision),
1170 round_type(round_type)
1171 {
1172 }
1173
1174 /** Constructor
1175 *
1176 * @param[in] pool_type Pooling type @ref PoolingType.
1177 * @param[in] pool_size Pooling size, in elements, across x, y and z.
1178 * @param[in] stride (Optional) stride information @ref Size3D
1179 * @param[in] padding (Optional) padding information @ref Padding3D
1180 * @param[in] exclude_padding (Optional) Strategy when accounting padding in calculations.
1181 * True will exclude padding while false will not (Used in AVG/L2 pooling to determine the pooling area).
1182 * Defaults to false;
1183 * @param[in] fp_mixed_precision (Optional) Use wider accumulators (32 bit instead of 16 for FP16) to improve accuracy.
ramy.elgammal@arm.coma2561f02023-06-16 20:45:48 +01001184 * @param[in] round_type (Optional) Dimensions rounding. Defaults to @ref DimensionRoundingType::FLOOR
ramelg0137515692022-02-26 22:06:20 +00001185 */
1186 explicit Pooling3dLayerInfo(PoolingType pool_type,
1187 Size3D pool_size,
1188 Size3D stride = Size3D(1U, 1U, 1U),
1189 Padding3D padding = Padding3D(),
1190 bool exclude_padding = false,
1191 bool fp_mixed_precision = false,
1192 DimensionRoundingType round_type = DimensionRoundingType::FLOOR)
1193 : pool_type(pool_type),
1194 pool_size(pool_size),
1195 stride(stride),
1196 padding(padding),
1197 exclude_padding(exclude_padding),
1198 is_global_pooling(false),
1199 fp_mixed_precision(fp_mixed_precision),
1200 round_type(round_type)
1201 {
1202 }
1203
1204 /** Constructor
1205 *
1206 * @note This constructor is used for global pooling
1207 *
1208 * @param[in] pool_type Pooling type @ref PoolingType.
1209 */
1210 explicit Pooling3dLayerInfo(PoolingType pool_type)
1211 : pool_type(pool_type),
1212 pool_size(Size3D()),
1213 stride(Size3D(1U, 1U, 1U)),
1214 padding(Padding3D(0, 0, 0)),
1215 exclude_padding(false),
1216 is_global_pooling(true),
1217 fp_mixed_precision(false),
1218 round_type(DimensionRoundingType::FLOOR)
1219 {
1220 }
1221
1222 PoolingType pool_type;
1223 Size3D pool_size;
1224 Size3D stride;
1225 Padding3D padding;
1226 bool exclude_padding;
1227 bool is_global_pooling;
1228 bool fp_mixed_precision;
1229 DimensionRoundingType round_type;
1230};
1231
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001232/** ROI Pooling Layer Information class */
giuros0118870812018-09-13 09:31:40 +01001233class ROIPoolingLayerInfo final
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001234{
1235public:
giuros0118870812018-09-13 09:31:40 +01001236 /** Constructor
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001237 *
giuros0118870812018-09-13 09:31:40 +01001238 * @param[in] pooled_width Pooled width of the layer.
1239 * @param[in] pooled_height Pooled height of the layer.
1240 * @param[in] spatial_scale Spatial scale to be applied to the ROI coordinates and dimensions.
1241 * @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 +01001242 */
giuros0118870812018-09-13 09:31:40 +01001243 ROIPoolingLayerInfo(unsigned int pooled_width, unsigned int pooled_height, float spatial_scale, unsigned int sampling_ratio = 0)
1244 : _pooled_width(pooled_width), _pooled_height(pooled_height), _spatial_scale(spatial_scale), _sampling_ratio(sampling_ratio)
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001245 {
1246 }
Alex Gildayc357c472018-03-21 13:54:09 +00001247 /** Get the pooled width of the layer */
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001248 unsigned int pooled_width() const
1249 {
1250 return _pooled_width;
1251 }
Alex Gildayc357c472018-03-21 13:54:09 +00001252 /** Get the pooled height of the layer */
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001253 unsigned int pooled_height() const
1254 {
1255 return _pooled_height;
1256 }
Alex Gildayc357c472018-03-21 13:54:09 +00001257 /** Get the spatial scale */
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001258 float spatial_scale() const
1259 {
1260 return _spatial_scale;
1261 }
giuros0118870812018-09-13 09:31:40 +01001262 /** Get sampling ratio */
1263 unsigned int sampling_ratio() const
1264 {
1265 return _sampling_ratio;
1266 }
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001267
1268private:
1269 unsigned int _pooled_width;
1270 unsigned int _pooled_height;
1271 float _spatial_scale;
giuros0118870812018-09-13 09:31:40 +01001272 unsigned int _sampling_ratio;
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001273};
1274
Manuel Bottini5209be52019-02-13 16:34:56 +00001275/** Generate Proposals Information class */
1276class GenerateProposalsInfo
1277{
1278public:
1279 /** Constructor
1280 *
1281 * @param[in] im_width Width of the original image
1282 * @param[in] im_height Height of the original image
1283 * @param[in] im_scale Scale applied to the original image
1284 * @param[in] spatial_scale (Optional)Scale applied to the feature map. Defaults to 1.0
1285 * @param[in] pre_nms_topN (Optional)Number of the best scores to be selected from the transformations. Defaults to 6000.
1286 * @param[in] post_nms_topN (Optional)Number of the best scores to be selected from the NMS operation. Defaults to 300.
1287 * @param[in] nms_thres (Optional)NMS overlap threshold. Defaults to 0.7.
1288 * @param[in] min_size (Optional)Size used to validate the anchors produced. Defaults to 16.
1289 * @param[in] values_per_roi (Optional)Values used to represent a ROI(Region of interest). Defaults to 4.
1290 */
1291 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,
1292 size_t values_per_roi = 4)
1293 : _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),
1294 _min_size(min_size), _values_per_roi(values_per_roi)
1295 {
1296 }
1297
1298 /* Get the original height */
1299 float im_height() const
1300 {
1301 return _im_height;
1302 }
1303 /* Get the original width */
1304 float im_width() const
1305 {
1306 return _im_width;
1307 }
1308 /* Get the image scale */
1309 float im_scale() const
1310 {
1311 return _im_scale;
1312 }
1313 /* Get the value of how many best scores to select (before NMS) */
1314 int pre_nms_topN() const
1315 {
1316 return _pre_nms_topN;
1317 }
1318 /* Get the value of how many best scores to select (after NMS) */
1319 int post_nms_topN() const
1320 {
1321 return _post_nms_topN;
1322 }
1323 /* Get the NMS overlap threshold */
1324 float nms_thres() const
1325 {
1326 return _nms_thres;
1327 }
1328 /* Get the minimal size */
1329 float min_size() const
1330 {
1331 return _min_size;
1332 }
1333 /* Get the spatial scale to be applied to the feature maps */
1334 float spatial_scale() const
1335 {
1336 return _spatial_scale;
1337 }
1338 /* Get the values used to represent a ROI(Region of interest)*/
1339 size_t values_per_roi() const
1340 {
1341 return _values_per_roi;
1342 }
1343
1344private:
1345 float _im_height;
1346 float _im_width;
1347 float _im_scale;
1348 float _spatial_scale;
1349 int _pre_nms_topN;
1350 int _post_nms_topN;
1351 float _nms_thres;
1352 float _min_size;
1353 size_t _values_per_roi;
1354};
1355
1356/** ComputeAnchors information class */
1357class ComputeAnchorsInfo
1358{
1359public:
1360 /** Constructor
1361 *
1362 * @param[in] feat_width Feature map width
1363 * @param[in] feat_height Feature map height
1364 * @param[in] spatial_scale Feature map scale
1365 * @param[in] values_per_roi (Optional)Values used to represent a ROI(Region Of Interest). Defaults to 4
1366 */
1367 ComputeAnchorsInfo(float feat_width, float feat_height, float spatial_scale, size_t values_per_roi = 4)
1368 : _feat_height(feat_height),
1369 _feat_width(feat_width),
1370 _spatial_scale(spatial_scale),
1371 _values_per_roi(values_per_roi)
1372 {
1373 }
1374
1375 /* Get the height of the feature map */
1376 float feat_height() const
1377 {
1378 return _feat_height;
1379 }
1380
1381 /* Get the width of the feature map */
1382 float feat_width() const
1383 {
1384 return _feat_width;
1385 }
1386
1387 /* Get the scale of the feature map */
1388 float spatial_scale() const
1389 {
1390 return _spatial_scale;
1391 }
1392
1393 /* Get the values used to represent a ROI(Region Of Interest)*/
1394 size_t values_per_roi() const
1395 {
1396 return _values_per_roi;
1397 }
1398
1399private:
1400 float _feat_height;
1401 float _feat_width;
1402 float _spatial_scale;
1403 size_t _values_per_roi;
1404};
1405
giuros01c04a0e82018-10-03 12:44:35 +01001406/** Bounding Box Transform information class */
giuros01d696cb62018-11-16 10:39:59 +00001407class BoundingBoxTransformInfo final
giuros01c04a0e82018-10-03 12:44:35 +01001408{
1409public:
1410 /** Constructor
1411 *
giuros01d696cb62018-11-16 10:39:59 +00001412 * @param[in] img_width Width of the original image
1413 * @param[in] img_height Height, of the original image
1414 * @param[in] scale Scale of the original image
1415 * @param[in] apply_scale (Optional)Re-apply scaling after transforming the boxes. Defaults to false
1416 * @param[in] weights (Optional)Weights [wx, wy, ww, wh] for the deltas. Defaults to all ones
1417 * @param[in] correct_transform_coords (Optional)Correct bounding box transform coordinates. Defaults to false
1418 * @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 +01001419 */
giuros01d696cb62018-11-16 10:39:59 +00001420 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 =
1421 false,
1422 float bbox_xform_clip =
1423 4.135166556742356f)
1424 : _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 +01001425 {
1426 }
1427
1428 std::array<float, 4> weights() const
1429 {
1430 return _weights;
1431 }
1432
1433 float bbox_xform_clip() const
1434 {
1435 return _bbox_xform_clip;
1436 }
1437
1438 float img_height() const
1439 {
1440 return _img_height;
1441 }
1442
1443 float img_width() const
1444 {
1445 return _img_width;
1446 }
1447
1448 float scale() const
1449 {
1450 return _scale;
1451 }
1452
1453 bool apply_scale() const
1454 {
1455 return _apply_scale;
1456 }
1457
giuros01d696cb62018-11-16 10:39:59 +00001458 bool correct_transform_coords() const
1459 {
1460 return _correct_transform_coords;
1461 }
1462
giuros01c04a0e82018-10-03 12:44:35 +01001463private:
Jakub Sujak0d27b2e2023-08-24 14:01:20 +01001464 float _img_width;
1465 float _img_height;
1466 float _scale;
1467 bool _apply_scale;
1468 bool _correct_transform_coords;
giuros01c04a0e82018-10-03 12:44:35 +01001469 std::array<float, 4> _weights;
Jakub Sujak0d27b2e2023-08-24 14:01:20 +01001470 float _bbox_xform_clip;
giuros01c04a0e82018-10-03 12:44:35 +01001471};
1472
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001473/** Normalization Layer Information class */
1474class NormalizationLayerInfo
1475{
1476public:
1477 /** Default Constructor
1478 *
Michele Di Giorgio9d3a8312018-11-20 12:31:24 +00001479 * @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 +01001480 * @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 +00001481 * @param[in] alpha (Optional) Alpha parameter used by normalization equation. Defaults to 0.0001.
1482 * @param[in] beta (Optional) Beta parameter used by normalization equation. Defaults to 0.5.
1483 * @param[in] kappa (Optional) Kappa parameter used by [Krichevksy 2012] Across Channel Local Brightness Normalization equation.
1484 * @param[in] is_scaled (Optional) Boolean that specifies if alpha will be scaled by the normalization size or not.
1485 * Should be false to follow [Krichevksy 2012].
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001486 */
Georgios Pinitas41caa622017-11-16 14:37:08 +00001487 NormalizationLayerInfo(NormType type, uint32_t norm_size = 5, float alpha = 0.0001f, float beta = 0.5f, float kappa = 1.f, bool is_scaled = true)
1488 : _type(type), _norm_size(norm_size), _alpha(alpha), _beta(beta), _kappa(kappa), _is_scaled(is_scaled)
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001489 {
1490 }
Alex Gildayc357c472018-03-21 13:54:09 +00001491 /** Get the normalization type */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001492 NormType type() const
1493 {
1494 return _type;
1495 }
Alex Gildayc357c472018-03-21 13:54:09 +00001496 /** Get the normalization size */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001497 uint32_t norm_size() const
1498 {
1499 return _norm_size;
1500 }
Alex Gildayc357c472018-03-21 13:54:09 +00001501 /** Get the alpha value */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001502 float alpha() const
1503 {
1504 return _alpha;
1505 }
Alex Gildayc357c472018-03-21 13:54:09 +00001506 /** Get the beta value */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001507 float beta() const
1508 {
1509 return _beta;
1510 }
Alex Gildayc357c472018-03-21 13:54:09 +00001511 /** Get the kappa value */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001512 float kappa() const
1513 {
1514 return _kappa;
1515 }
Michele Di Giorgio9d3a8312018-11-20 12:31:24 +00001516 /** Get the is_scaled value */
1517 bool is_scaled() const
1518 {
1519 return _is_scaled;
1520 }
Alex Gildayc357c472018-03-21 13:54:09 +00001521 /** Check if normalization is cross map */
Georgios Pinitas41caa622017-11-16 14:37:08 +00001522 bool is_cross_map() const
1523 {
1524 return _type == NormType::CROSS_MAP;
1525 }
Alex Gildayc357c472018-03-21 13:54:09 +00001526 /** Check if normalization is not cross map */
Georgios Pinitas41caa622017-11-16 14:37:08 +00001527 bool is_in_map() const
1528 {
1529 return !is_cross_map();
1530 }
1531 /** Return the scaling factor of the normalization function.
1532 *
1533 * If is_scaled is set to false then [Krichevksy 2012] normalization scaling is performed,
1534 * 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 +01001535 *
1536 * @return The normalization scaling factor.
1537 */
1538 float scale_coeff() const
1539 {
1540 const uint32_t size = (_type == NormType::IN_MAP_2D) ? _norm_size * _norm_size : _norm_size;
Georgios Pinitas41caa622017-11-16 14:37:08 +00001541 return (_is_scaled) ? (_alpha / size) : _alpha;
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001542 }
1543
1544private:
1545 NormType _type;
1546 uint32_t _norm_size;
1547 float _alpha;
1548 float _beta;
1549 float _kappa;
Georgios Pinitas41caa622017-11-16 14:37:08 +00001550 bool _is_scaled;
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001551};
1552
thecha012bfadd92020-08-12 17:25:51 +01001553class StridedSliceLayerInfo
1554{
1555public:
1556 /** Default Constructor
1557 *
1558 * @param[in] begin_mask (Optional) If the ith bit of begin_mask is set, starts[i] is ignored and the fullest possible range in that dimension is used instead.
1559 * @param[in] end_mask (Optional) If the ith bit of end_mask is set, ends[i] is ignored and the fullest possible range in that dimension is used instead.
1560 * @param[in] shrink_axis_mask (Optional) If the ith bit of shrink_axis_mask is set, it implies that the ith specification shrinks the dimensionality by 1.
1561 */
1562 StridedSliceLayerInfo(int32_t begin_mask = 0, int32_t end_mask = 0, int32_t shrink_axis_mask = 0)
1563 : _begin_mask(begin_mask), _end_mask(end_mask), _shrink_axis_mask(shrink_axis_mask)
1564 {
1565 }
1566
1567 /* Get the begin mask value */
1568 int32_t begin_mask() const
1569 {
1570 return _begin_mask;
1571 }
1572
1573 /* Get the end mask value */
1574 int32_t end_mask() const
1575 {
1576 return _end_mask;
1577 }
1578
1579 /* Get the shrink axis mask value */
1580 int32_t shrink_axis_mask() const
1581 {
1582 return _shrink_axis_mask;
1583 }
1584
1585private:
1586 int32_t _begin_mask;
1587 int32_t _end_mask;
1588 int32_t _shrink_axis_mask;
1589};
1590
Ramy Elgammal91780022022-07-20 14:57:37 +01001591// OHWIo<interleave_by>i<block_by>
1592inline int interleave_by(const WeightFormat wf)
1593{
Pablo Marquez Tello93581a52022-07-21 13:55:27 +01001594 return (static_cast<int>(wf) >> 8) & 0xFFF;
Ramy Elgammal91780022022-07-20 14:57:37 +01001595}
1596inline int block_by(const WeightFormat wf)
1597{
Pablo Marquez Tello93581a52022-07-21 13:55:27 +01001598 return (static_cast<int>(wf) >> 20) & 0xF;
Ramy Elgammal91780022022-07-20 14:57:37 +01001599}
Pablo Marquez Tello93581a52022-07-21 13:55:27 +01001600inline bool is_fixed_format(const WeightFormat &wf)
Ramy Elgammal91780022022-07-20 14:57:37 +01001601{
1602 return wf != WeightFormat::UNSPECIFIED && wf != WeightFormat::ANY;
1603}
Pablo Marquez Tello93581a52022-07-21 13:55:27 +01001604inline bool is_fixed_format_fast_math(const WeightFormat &wf)
1605{
1606 return (static_cast<int>(wf) >> 4) & 0x1;
1607}
Ramy Elgammal91780022022-07-20 14:57:37 +01001608
Gian Marco Iodice559d7712017-08-08 08:38:09 +01001609/** 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 +01001610class WeightsInfo
1611{
1612public:
Gian Marco Iodice4e288692017-06-27 11:41:59 +01001613 /** Default constructor */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001614 WeightsInfo()
Ramy Elgammal91780022022-07-20 14:57:37 +01001615 : _are_reshaped(false), _kernel_width(0), _kernel_height(0), _num_kernels(0), _retain_internal_weights(false), _weight_format(arm_compute::WeightFormat::UNSPECIFIED)
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001616 {
1617 }
1618 /** Constructor
1619 *
Michele Di Giorgiob62280a2018-05-31 17:31:05 +01001620 * @param[in] are_reshaped True if the weights have been reshaped
1621 * @param[in] kernel_width Kernel width.
1622 * @param[in] kernel_height Kernel height.
1623 * @param[in] num_kernels Number of convolution kernels.
1624 * @param[in] retain_internal_weights (Optional) True if internal reshaped weights must be retained. Used for reconfiguration purposes. Default is false.
Ramy Elgammal91780022022-07-20 14:57:37 +01001625 * @param[in] weight_format (Optional) arm_gemm:WeightFormat enumeration requested by the user. Default is arm_compute::WeightFormat::UNSPECIFIED.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001626 */
Francesco Petrogalli553f6952022-06-30 10:22:01 +00001627 WeightsInfo(bool are_reshaped, unsigned int kernel_width, unsigned int kernel_height, unsigned int num_kernels, bool retain_internal_weights = false,
Ramy Elgammal91780022022-07-20 14:57:37 +01001628 arm_compute::WeightFormat weight_format = arm_compute::WeightFormat::UNSPECIFIED)
Francesco Petrogalli553f6952022-06-30 10:22:01 +00001629 : _are_reshaped(are_reshaped), _kernel_width(kernel_width), _kernel_height(kernel_height), _num_kernels(num_kernels), _retain_internal_weights(retain_internal_weights), _weight_format(weight_format)
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001630 {
1631 }
Gian Marco Iodice4e288692017-06-27 11:41:59 +01001632 /** Flag which specifies if the weights tensor has been reshaped.
1633 *
1634 * @return True if the weights tensors has been reshaped
1635 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001636 bool are_reshaped() const
1637 {
1638 return _are_reshaped;
1639 };
Gian Marco Iodice559d7712017-08-08 08:38:09 +01001640 /** Return the number of convolution kernels
1641 *
1642 * @return The number of convolution kernels
1643 */
1644 unsigned int num_kernels() const
1645 {
1646 return _num_kernels;
1647 };
Gian Marco Iodice4e288692017-06-27 11:41:59 +01001648 /** Return the width and height of the kernel
1649 *
1650 * @return The width and height of the kernel
1651 */
1652 std::pair<unsigned int, unsigned int> kernel_size() const
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001653 {
Gian Marco Iodice4e288692017-06-27 11:41:59 +01001654 return std::make_pair(_kernel_width, _kernel_height);
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001655 }
Michele Di Giorgiob62280a2018-05-31 17:31:05 +01001656 bool retain_internal_weights() const
1657 {
1658 return _retain_internal_weights;
1659 }
Ramy Elgammal91780022022-07-20 14:57:37 +01001660 arm_compute::WeightFormat weight_format() const
Francesco Petrogalli553f6952022-06-30 10:22:01 +00001661 {
1662 return _weight_format;
1663 }
Milos Puzovic13b623e2022-07-27 17:53:21 +00001664 void set_weight_format(arm_compute::WeightFormat weight_format)
1665 {
1666 _weight_format = weight_format;
1667 }
1668
Francesco Petrogalli553f6952022-06-30 10:22:01 +00001669 unsigned int kernel_width() const
1670 {
1671 return _kernel_width;
1672 }
1673 unsigned int kernel_height() const
1674 {
1675 return _kernel_height;
1676 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001677
1678private:
Ramy Elgammal91780022022-07-20 14:57:37 +01001679 bool _are_reshaped;
1680 unsigned int _kernel_width;
1681 unsigned int _kernel_height;
1682 unsigned int _num_kernels;
1683 bool _retain_internal_weights;
1684 arm_compute::WeightFormat _weight_format;
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001685};
1686
Gian Marco36a0a462018-01-12 10:21:40 +00001687/** GEMM reshape information class. This class stores the necessary information about matrix A and matrix B reshape.
1688 *
Michele Di Giorgio93b75e02021-06-21 12:00:43 +01001689 * The matrix A can only be reshaped through @ref opencl::kernels::ClGemmReshapeLhsMatrixKernel or @ref cpu::kernels::CpuGemmInterleave4x4Kernel
Georgios Pinitas856f66e2021-04-22 21:13:21 +01001690 * Note: Optionally just for @ref opencl::kernels::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 +00001691 *
Michele Di Giorgio93b75e02021-06-21 12:00:43 +01001692 * The matrix B can only be reshaped through @ref opencl::kernels::ClGemmReshapeRhsMatrixKernel or @ref cpu::kernels::CpuGemmTranspose1xWKernel
Georgios Pinitas856f66e2021-04-22 21:13:21 +01001693 * Note: Optionally just for @ref opencl::kernels::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 +00001694 *
1695 */
1696class GEMMReshapeInfo final
1697{
1698public:
1699 /** Default constructor */
1700 GEMMReshapeInfo()
Georgios Pinitasb0f342e2019-05-21 13:32:43 +01001701 : _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 +00001702 {
1703 }
1704 /** Constructor
1705 *
1706 * @param[in] m Number of matrix A rows
1707 * @param[in] n Number of matrix B columns
1708 * @param[in] k Number of matrix A columns or matrix B rows
1709 * @param[in] mult_transpose1xW_width (Optional) Multiplication factor for the width of the 1xW transposed block
1710 * @param[in] mult_interleave4x4_height (Optional) Multiplication factor for the height of the 4x4 interleaved block
Gian Marco Iodice3139f032018-11-05 14:26:32 +00001711 * @param[in] depth_output_gemm3d (Optional) Depth (third dimension) of the output tensor to be used with the GEMM3D kernel.
1712 * If 0 the output will not be reinterpreted as 3D. Default 0
Gian Marco Iodice68a3f562018-07-26 11:44:03 +01001713 * @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 +01001714 * to perform 1x1 convolutions with the NHWC data layout)
1715 * @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 +00001716 */
Georgios Pinitasb0f342e2019-05-21 13:32:43 +01001717 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 +01001718 : _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 +01001719 _reinterpret_input_as_3d(reinterpret_input_as_3d), _broadcast_bias(broadcast_bias)
Gian Marco36a0a462018-01-12 10:21:40 +00001720 {
1721 }
1722 /** Number of matrix A rows
1723 *
1724 * @return the number of matrix A rows
1725 */
1726 int m() const
1727 {
1728 return _m;
1729 }
1730 /** Number of matrix B columns
1731 *
1732 * @return the number of matrix B columns
1733 */
1734 int n() const
1735 {
1736 return _n;
1737 }
1738 /** Number of matrix A columns or matrix B rows
1739 *
1740 * @return the number of matrix A columns or matrix B rows
1741 */
1742 int k() const
1743 {
1744 return _k;
1745 }
1746 /** Multiplication factor for the width of the 1xW transposed block
1747 *
1748 * @return the multiplication factor for the width of the 1xW transposed block
1749 */
1750 int mult_transpose1xW_width() const
1751 {
1752 return _mult_transpose1xW_width;
1753 }
1754 /** Multiplication factor for the height of the 4x4 interleaved block
1755 *
1756 * @return the multiplication factor for the height of the 4x4 interleaved block
1757 */
1758 int mult_interleave4x4_height() const
1759 {
1760 return _mult_interleave4x4_height;
1761 }
Isabella Gottardi8e74f442018-03-01 16:42:00 +00001762 /** Depth (third dimension) of the output tensor to be used with the GEMM3D kernel
1763 *
1764 * @note GEMM3D kernel is used when the output has to be reinterpret as 3D tensor. In that case:
1765 * m = depth_output_gemm3d * output_height
1766 *
1767 * @return the depth of the output tensor to be used with the GEMM3D kernel
1768 */
1769 int depth_output_gemm3d() const
1770 {
1771 return _depth_output_gemm3d;
1772 }
Gian Marco Iodice68a3f562018-07-26 11:44:03 +01001773 /** Flag which specifies if the input tensor has to be reinterpreted as 3D
1774 *
1775 * @return True if the input tensor has to be reinterpreted as 3D tensor
1776 */
1777 bool reinterpret_input_as_3d() const
1778 {
1779 return _reinterpret_input_as_3d;
1780 };
Georgios Pinitasb0f342e2019-05-21 13:32:43 +01001781 /** Flag which specifies whether to broadcast the shape of the bias tensor.
1782 *
1783 * @return True if the shape of the bias tensor is to be broadcasted.
1784 */
1785 bool broadcast_bias() const
1786 {
1787 return _broadcast_bias;
1788 };
Gian Marco36a0a462018-01-12 10:21:40 +00001789
1790private:
SiCong Liebd8fb42020-08-18 11:03:14 +01001791 int _m;
1792 int _n;
1793 int _k;
1794 int _mult_transpose1xW_width;
1795 int _mult_interleave4x4_height;
1796 int _depth_output_gemm3d;
1797 bool _reinterpret_input_as_3d;
1798 bool _broadcast_bias;
Gian Marco36a0a462018-01-12 10:21:40 +00001799};
1800
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +00001801/** GEMM LHS (Left Hand Side) matrix information */
1802struct GEMMLHSMatrixInfo
1803{
morgolockaba2f912020-05-05 16:28:19 +01001804 GEMMLHSMatrixInfo() = default;
1805 GEMMLHSMatrixInfo(unsigned int m, unsigned int k, unsigned int v, bool trans, bool inter)
1806 : m0(m), k0(k), v0(v), transpose(trans), interleave(inter)
1807 {
1808 }
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +00001809 unsigned int m0{ 1 }; /**< Number of rows processed by the matrix multiplication */
1810 unsigned int k0{ 1 }; /**< Number of partial accumulations performed by the matrix multiplication */
1811 unsigned int v0{ 1 }; /**< Number of vertical blocks of size (m0xk0) stored on the same output row */
1812 bool transpose{ true }; /**< True if the (m0xk0) block has to be transposed before been stored */
1813 bool interleave{ true }; /**< True if the v0 (m0xk0) blocks have to be interleaved in the output row */
1814};
1815
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +00001816/** GEMM RHS (Right Hand Side) matrix information */
1817struct GEMMRHSMatrixInfo
1818{
morgolockaba2f912020-05-05 16:28:19 +01001819 GEMMRHSMatrixInfo() = default;
Gian Marco Iodicee3a849a2020-06-10 17:59:30 +01001820 GEMMRHSMatrixInfo(unsigned int n, unsigned int k, unsigned int h, bool trans, bool inter, bool export_to_cl_img)
1821 : n0(n), k0(k), h0(h), transpose(trans), interleave(inter), export_to_cl_image(export_to_cl_img)
morgolockaba2f912020-05-05 16:28:19 +01001822 {
1823 }
Gian Marco Iodicedd717c32020-05-28 10:22:03 +01001824 unsigned int n0{ 1 }; /**< Number of columns processed by the matrix multiplication */
1825 unsigned int k0{ 1 }; /**< Number of partial accumulations performed by the matrix multiplication */
1826 unsigned int h0{ 1 }; /**< Number of horizontal blocks of size (k0xn0) stored on the same output row */
1827 bool transpose{ true }; /**< True if the (k0xn0) block has to be transposed before been stored */
1828 bool interleave{ true }; /**< True if the h0 (k0xn0) blocks have to be interleaved in the output row */
1829 bool export_to_cl_image{ false }; /**< True if the reshaped rhs has to be exported to cl_image. n0 must be equal to 4 */
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +00001830};
1831
SiCongLi579ca842021-10-18 09:38:33 +01001832class ITensorInfo;
Chunosov5124be52017-11-22 20:42:13 +07001833
Gian Marco Iodice247f52c2018-03-22 11:24:56 +00001834/** Winograd information */
1835struct WinogradInfo
1836{
1837 /** Default constructor
1838 *
1839 * @param[in] output_tile_sz Width and height of the output tile
1840 * @param[in] kernel_sz Width and height of the kernel
1841 * @param[in] input_dims Width and height of the input tensor before the convolution is applied
1842 * @param[in] conv_info Convolution info (Pads, strides)
1843 * @param[in] data_layout Data layout to use for the output tensor once the convolution has been applied
1844 */
1845 WinogradInfo(Size2D output_tile_sz, Size2D kernel_sz, Size2D input_dims, PadStrideInfo conv_info, DataLayout data_layout)
1846 : output_tile_size(output_tile_sz), kernel_size(kernel_sz), input_dimensions(input_dims), convolution_info(conv_info), output_data_layout(data_layout)
1847 {
1848 }
1849
1850 Size2D output_tile_size{}; /**< Width and height of the output tile */
1851 Size2D kernel_size{}; /**< Width and height of the kernel*/
1852 Size2D input_dimensions{}; /**< Width and height of the input tensor before the convolution is applied */
1853 PadStrideInfo convolution_info{}; /**< Convolution info (Pads, strides,...) */
1854 DataLayout output_data_layout{ DataLayout::NCHW }; /**< Data layout to use for the output tensor once the convolution has been applied (NCHW or NHWC) */
1855};
1856
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001857/** IO formatting information class*/
1858struct IOFormatInfo
1859{
1860 /** Precision type used when printing floating point numbers */
1861 enum class PrecisionType
1862 {
1863 Default, /**< Default precision to the one that the current stream has */
1864 Custom, /**< Custom precision specified by the user using the precision parameter */
1865 Full /**< The maximum precision of the floating point representation */
1866 };
1867
1868 /** Specifies the area to be printed, used by Tensor objects */
1869 enum class PrintRegion
1870 {
1871 ValidRegion, /**< Prints the valid region of the Tensor object */
1872 NoPadding, /**< Prints the Tensor object without the padding */
1873 Full /**< Print the tensor object including padding */
1874 };
1875
Alex Gildayc357c472018-03-21 13:54:09 +00001876 /** Construct a set of IO formatting information.
1877 *
1878 * @param[in] print_region Area to be printed. Used by Tensor objects. Default: ValidRegion.
1879 * @param[in] precision_type Precision type for floating point numbers. Default: stream default.
1880 * @param[in] precision Precision value for float point numbers. Default: 10.
1881 * @param[in] align_columns Whether to align columns when printed. Default: true.
1882 * @param[in] element_delim Delimeter between elements. Default: " ".
1883 * @param[in] row_delim Delimenter between rows. Default: "\n".
1884 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001885 IOFormatInfo(PrintRegion print_region = PrintRegion::ValidRegion,
1886 PrecisionType precision_type = PrecisionType::Default,
1887 unsigned int precision = 10,
1888 bool align_columns = true,
1889 std::string element_delim = " ",
1890 std::string row_delim = "\n")
1891 : print_region(print_region),
1892 precision_type(precision_type),
1893 precision(precision),
1894 element_delim(element_delim),
1895 row_delim(row_delim),
1896 align_columns(align_columns)
1897 {
1898 }
1899
Alex Gildayc357c472018-03-21 13:54:09 +00001900 /** Area to be printed by Tensor objects */
1901 PrintRegion print_region;
1902 /** Floating point precision type */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001903 PrecisionType precision_type;
Alex Gildayc357c472018-03-21 13:54:09 +00001904 /** Floating point precision */
1905 unsigned int precision;
1906 /** Element delimeter */
1907 std::string element_delim;
1908 /** Row delimeter */
1909 std::string row_delim;
1910 /** Align columns */
1911 bool align_columns;
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001912};
Mohammed Suhail Munshid538d162023-02-16 16:22:32 +00001913
SiCong Li4ceb4532023-03-13 15:02:23 +00001914/** Class for holding information related to cropping */
1915using CropInfo = Padding2D;
Georgios Pinitasd8734b52017-12-22 15:27:52 +00001916} // namespace arm_compute
Jakub Sujak0d27b2e2023-08-24 14:01:20 +01001917#endif // ACL_ARM_COMPUTE_CORE_TYPES_H