Compute Library
 21.05
Types.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-2021 Arm Limited.
3  *
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 
33 #include "support/Bfloat16.h"
34 #include "support/Half.h"
35 
36 #include <cmath>
37 #include <cstddef>
38 #include <cstdint>
39 #include <map>
40 #include <string>
41 #include <utility>
42 
43 namespace arm_compute
44 {
45 /** 16-bit floating point type */
47 
48 /** Permutation vector */
50 /** Bidirectional strides */
52 
53 /** Image colour formats */
54 enum class Format
55 {
56  UNKNOWN, /**< Unknown image format */
57  U8, /**< 1 channel, 1 U8 per channel */
58  S16, /**< 1 channel, 1 S16 per channel */
59  U16, /**< 1 channel, 1 U16 per channel */
60  S32, /**< 1 channel, 1 S32 per channel */
61  U32, /**< 1 channel, 1 U32 per channel */
62  BFLOAT16, /**< 16-bit brain floating-point number */
63  F16, /**< 1 channel, 1 F16 per channel */
64  F32, /**< 1 channel, 1 F32 per channel */
65  UV88, /**< 2 channel, 1 U8 per channel */
66  RGB888, /**< 3 channels, 1 U8 per channel */
67  RGBA8888, /**< 4 channels, 1 U8 per channel */
68  YUV444, /**< A 3 plane of 8 bit 4:4:4 sampled Y, U, V planes */
69  YUYV422, /**< A single plane of 32-bit macro pixel of Y0, U0, Y1, V0 bytes */
70  NV12, /**< A 2 plane YUV format of Luma (Y) and interleaved UV data at 4:2:0 sampling */
71  NV21, /**< A 2 plane YUV format of Luma (Y) and interleaved VU data at 4:2:0 sampling */
72  IYUV, /**< A 3 plane of 8-bit 4:2:0 sampled Y, U, V planes */
73  UYVY422 /**< A single plane of 32-bit macro pixel of U0, Y0, V0, Y1 byte */
74 };
75 
76 /** Available data types */
77 enum class DataType
78 {
79  UNKNOWN, /**< Unknown data type */
80  U8, /**< unsigned 8-bit number */
81  S8, /**< signed 8-bit number */
82  QSYMM8, /**< quantized, symmetric fixed-point 8-bit number */
83  QASYMM8, /**< quantized, asymmetric fixed-point 8-bit number unsigned */
84  QASYMM8_SIGNED, /**< quantized, asymmetric fixed-point 8-bit number signed */
85  QSYMM8_PER_CHANNEL, /**< quantized, symmetric per channel fixed-point 8-bit number */
86  U16, /**< unsigned 16-bit number */
87  S16, /**< signed 16-bit number */
88  QSYMM16, /**< quantized, symmetric fixed-point 16-bit number */
89  QASYMM16, /**< quantized, asymmetric fixed-point 16-bit number */
90  U32, /**< unsigned 32-bit number */
91  S32, /**< signed 32-bit number */
92  U64, /**< unsigned 64-bit number */
93  S64, /**< signed 64-bit number */
94  BFLOAT16, /**< 16-bit brain floating-point number */
95  F16, /**< 16-bit floating-point number */
96  F32, /**< 32-bit floating-point number */
97  F64, /**< 64-bit floating-point number */
98  SIZET /**< size_t */
99 };
100 
101 /** Available Sampling Policies */
102 enum class SamplingPolicy
103 {
104  CENTER, /**< Samples are taken at pixel center */
105  TOP_LEFT /**< Samples are taken at pixel top left corner */
106 };
107 
108 /** Constant value of the border pixels when using BorderMode::CONSTANT */
109 constexpr uint8_t CONSTANT_BORDER_VALUE = 199;
110 
111 /** [DataLayout enum definition] **/
112 
113 /** Supported tensor data layouts */
114 enum class DataLayout
115 {
116  UNKNOWN, /**< Unknown data layout */
117  NCHW, /**< Num samples, channels, height, width */
118  NHWC /**< Num samples, height, width, channels */
119 };
120 /** [DataLayout enum definition] **/
121 
122 /** Supported tensor data layout dimensions */
124 {
125  CHANNEL, /**< channel */
126  HEIGHT, /**< height */
127  WIDTH, /**< width */
128  BATCHES /**< batches */
129 };
130 
131 /** Available ConvolutionMethod*/
133 {
134  GEMM, /**< Convolution using GEMM */
135  GEMM_CONV2D, /**< Direct 2D GEMM convolution */
136  DIRECT, /**< Direct convolution */
137  WINOGRAD, /**< Convolution using Winograd */
138  FFT /**< Convolution using FFT */
139 };
140 
141 /** Available DepthwiseConvolutionFunction*/
143 {
144  OPTIMIZED, /**< Optimized Depthwise Convolution */
145  GENERIC, /**< Generic Depthwise Convolution */
146 };
147 
148 /** Available DeconvolutionMethod*/
150 {
151  GEMM, /**< Deconvolution using GEMM */
152  DIRECT, /**< Direct deconvolution */
153 };
154 
155 /** Available FuseBatchNormalizationType*/
157 {
158  CONVOLUTION, /**< For Convolution weights */
159  DEPTHWISECONVOLUTION /**< For Depthwise Convolution weights*/
160 };
161 
162 /** Padding mode to use for PadLayer */
163 enum class PaddingMode
164 {
165  CONSTANT,
166  REFLECT,
167  SYMMETRIC
168 };
169 
170 /** Supported comparison operations */
172 {
173  Equal, /**< Equal comparison ( \f$ x == y \f$ ) */
174  NotEqual, /**< NotEqual comparison ( \f$ x != y \f$ ) */
175  Greater, /**< Greater comparison ( \f$ x > y \f$ ) */
176  GreaterEqual, /**< Greater equal comparison ( \f$ x >= y \f$ ) */
177  Less, /**< Less comparison ( \f$ x < y \f$ ) */
178  LessEqual /**< Less equal comparison ( \f$ x <= y \f$ ) */
179 };
180 
181 /** Container for valid region of a window */
183 {
184  /** Default constructor */
186  : anchor{}, shape{}
187  {
188  }
189 
190  /** Allow instances of this class to be copy constructed */
191  ValidRegion(const ValidRegion &) = default;
192  /** Allow instances of this class to be move constructed */
193  ValidRegion(ValidRegion &&) = default;
194  /** Allow instances of this class to be copied */
195  ValidRegion &operator=(const ValidRegion &) = default;
196  /** Allow instances of this class to be moved */
197  ValidRegion &operator=(ValidRegion &&) = default;
198  /** Default destructor */
199  ~ValidRegion() = default;
200 
201  /** Constructor for a valid region with default number of dimensions
202  *
203  * @param[in] an_anchor Anchor for the start of the valid region.
204  * @param[in] a_shape Shape of the valid region.
205  *
206  */
207  ValidRegion(const Coordinates &an_anchor, const TensorShape &a_shape)
208  : anchor{ an_anchor }, shape{ a_shape }
209  {
211  }
212 
213  /** Constructor for a valid region with specified number of dimensions
214  *
215  * @param[in] an_anchor Anchor for the start of the valid region.
216  * @param[in] a_shape Shape of the valid region.
217  * @param[in] num_dimensions Number of dimensions (must be >= number of dimensions of anchor and shape).
218  *
219  */
220  ValidRegion(const Coordinates &an_anchor, const TensorShape &a_shape, size_t num_dimensions)
221  : anchor{ an_anchor }, shape{ a_shape }
222  {
223  ARM_COMPUTE_ERROR_ON(num_dimensions < std::max(anchor.num_dimensions(), shape.num_dimensions()));
224  anchor.set_num_dimensions(num_dimensions);
225  }
226 
227  /** Return the start of the valid region for the given dimension @p d */
228  int start(unsigned int d) const
229  {
230  return anchor[d];
231  }
232 
233  /** Return the end of the valid region for the given dimension @p d */
234  int end(unsigned int d) const
235  {
236  return anchor[d] + shape[d];
237  }
238 
239  /** Accessor to set the value of anchor and shape for one of the dimensions.
240  *
241  * @param[in] dimension Dimension for which the value is set.
242  * @param[in] start Value to be set in anchor for the dimension.
243  * @param[in] size Value to be set in shape for the dimension.
244  *
245  * @return *this.
246  */
247  ValidRegion &set(size_t dimension, int start, size_t size)
248  {
249  anchor.set(dimension, start);
250  shape.set(dimension, size);
251  return *this;
252  }
253 
254  Coordinates anchor; /**< Anchor for the start of the valid region. */
255  TensorShape shape; /**< Shape of the valid region. */
256 };
257 
258 /** Methods available to handle borders */
259 enum class BorderMode
260 {
261  UNDEFINED, /**< Borders are left undefined */
262  CONSTANT, /**< Pixels outside the image are assumed to have a constant value */
263  REPLICATE /**< Pixels outside the image are assumed to have the same value as the closest image pixel */
264 };
265 
266 /** Container for 2D border size */
268 {
269  /** Empty border, i.e. no border */
270  constexpr BorderSize() noexcept
271  : top{ 0 },
272  right{ 0 },
273  bottom{ 0 },
274  left{ 0 }
275  {
276  }
277 
278  /** Border with equal size around the 2D plane */
279  explicit constexpr BorderSize(unsigned int size) noexcept
280  : top{ size },
281  right{ size },
282  bottom{ size },
283  left{ size }
284  {
285  }
286 
287  /** Border with same size for top/bottom and left/right */
288  constexpr BorderSize(unsigned int top_bottom, unsigned int left_right)
289  : top{ top_bottom }, right{ left_right }, bottom{ top_bottom }, left{ left_right }
290  {
291  }
292 
293  /** Border with different sizes */
294  constexpr BorderSize(unsigned int top, unsigned int right, unsigned int bottom, unsigned int left)
295  : top{ top }, right{ right }, bottom{ bottom }, left{ left }
296  {
297  }
298 
299  /** Check if the entire border is zero */
300  constexpr bool empty() const
301  {
302  return top == 0 && right == 0 && bottom == 0 && left == 0;
303  }
304 
305  /** Check if the border is the same size on all sides */
306  constexpr bool uniform() const
307  {
308  return top == right && top == bottom && top == left;
309  }
310 
311  /** Scale this border size.
312  *
313  * @param[in] scale Scale to multiply border size by.
314  *
315  * @return *this.
316  */
318  {
319  top *= scale;
320  right *= scale;
321  bottom *= scale;
322  left *= scale;
323 
324  return *this;
325  }
326 
327  /** Scale a copy of this border size.
328  *
329  * @param[in] scale Scale to multiply border size by.
330  *
331  * @return a scaled copy of this.
332  */
334  {
335  BorderSize size = *this;
336  size *= scale;
337 
338  return size;
339  }
340 
341  /** Check equality with another BorderSize struct
342  *
343  * @param[in] rhs other struct to check against
344  *
345  * @return true if they are equal
346  */
347  bool operator==(const BorderSize &rhs)
348  {
349  return (top == rhs.top) && (right == rhs.right) && (bottom == rhs.bottom) && (left == rhs.left);
350  }
351 
352  /** Check non-equality with another BorderSize struct
353  *
354  * @param[in] rhs other struct to check against
355  *
356  * @return true if they are different
357  */
358  bool operator!=(const BorderSize &rhs)
359  {
360  return !(*this == rhs);
361  }
362 
363  /** Limit this border size.
364  *
365  * @param[in] limit Border size to limit this border size to.
366  */
367  void limit(const BorderSize &limit)
368  {
369  top = std::min(top, limit.top);
370  right = std::min(right, limit.right);
371  bottom = std::min(bottom, limit.bottom);
372  left = std::min(left, limit.left);
373  }
374 
375  unsigned int top; /**< top of the border */
376  unsigned int right; /**< right of the border */
377  unsigned int bottom; /**< bottom of the border */
378  unsigned int left; /**< left of the border */
379 };
380 
381 /** Container for 2D padding size */
383 
384 /** Policy to handle overflow */
385 enum class ConvertPolicy
386 {
387  WRAP, /**< Wrap around */
388  SATURATE /**< Saturate */
389 };
390 
391 /** Interpolation method */
393 {
394  NEAREST_NEIGHBOR, /**< Output values are defined to match the source pixel whose center is nearest to the sample position */
395  BILINEAR, /**< Output values are defined by bilinear interpolation between the pixels */
396  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 */
397 };
398 
399 /** Bilinear Interpolation method used by LKTracker */
401 {
402  BILINEAR_OLD_NEW, /**< Old-new method */
403  BILINEAR_SCHARR /**< Scharr method */
404 };
405 
406 /** Rectangle type */
407 struct Rectangle
408 {
409  uint16_t x; /**< Top-left x coordinate */
410  uint16_t y; /**< Top-left y coordinate */
411  uint16_t width; /**< Width of the rectangle */
412  uint16_t height; /**< Height of the rectangle */
413 };
414 
415 /** Coordinate type */
417 {
418  int32_t x; /**< X coordinates */
419  int32_t y; /**< Y coordinates */
420 };
421 
422 /** Coordinate type */
424 {
425  uint32_t x; /**< X coordinates */
426  uint32_t y; /**< Y coordinates */
427  uint32_t z; /**< Z coordinates */
428 };
429 
430 /** Padding information as a pair of unsigned int start/end */
431 using PaddingInfo = std::pair<uint32_t, uint32_t>;
432 
433 /** List of padding information */
434 using PaddingList = std::vector<PaddingInfo>;
435 
436 /** Information to produce a tiled version of a Tensor */
437 using Multiples = std::vector<uint32_t>;
438 
439 /** Available channels */
440 enum class Channel
441 {
442  UNKNOWN, /** Unknown channel format */
443  C0, /**< First channel (used by formats with unknown channel types). */
444  C1, /**< Second channel (used by formats with unknown channel types). */
445  C2, /**< Third channel (used by formats with unknown channel types). */
446  C3, /**< Fourth channel (used by formats with unknown channel types). */
447  R, /**< Red channel. */
448  G, /**< Green channel. */
449  B, /**< Blue channel. */
450  A, /**< Alpha channel. */
451  Y, /**< Luma channel. */
452  U, /**< Cb/U channel. */
453  V /**< Cr/V/Value channel. */
454 };
455 
456 /** Available reduction operations */
458 {
459  ARG_IDX_MAX, /**< Index of the max value */
460  ARG_IDX_MIN, /**< Index of the min value */
461  MEAN_SUM, /**< Mean of sum */
462  PROD, /**< Product */
463  SUM_SQUARE, /**< Sum of squares */
464  SUM, /**< Sum */
465  MIN, /**< Min */
466  MAX, /**< Max */
467 };
468 
469 /** Available element-wise operations */
471 {
472  ADD, /**< (x + y) */
473  SUB, /**< (x - y) */
474  DIV, /**< (x / y) */
475  MIN, /**< Min(x, y) */
476  MAX, /**< Max(x, y) */
477  SQUARED_DIFF, /**< (x - y)^2 */
478  POWER, /**< x ^ y */
479  PRELU, /**< y*x if x < 0, x otherwise */
480 };
481 
482 /** Available element wise unary operations */
484 {
485  RSQRT, /**< Reverse square root */
486  EXP, /**< Exponential */
487  NEG, /**< Negate */
488  LOG, /**< Natural Logarithm */
489  ABS, /**< Absolute value */
490  SIN, /**< Sine */
491  ROUND, /**< Round */
492  LOGICAL_NOT, /**< Logical Not */
493 };
494 
495 /** Available bitwise operations */
497 {
498  AND, /**< Bitwise AND operation */
499  NOT, /**< Bitwise NOT operation */
500  OR, /**< Bitwise OR operation */
501  XOR, /**< Bitwise XOR operation */
502 };
503 
504 /** The normalization type used for the normalization layer */
505 enum class NormType
506 {
507  IN_MAP_1D, /**< Normalization applied within the same map in 1D region */
508  IN_MAP_2D, /**< Normalization applied within the same map in 2D region */
509  CROSS_MAP /**< Normalization applied cross maps */
510 };
511 
512 /** Detection window used for the object detection. The detection window keeps the following information:
513  *
514  * -# Geometry of the rectangular window (x/y of top-left corner and width/height)
515  * -# Index of the class used for evaluating which class the detection window belongs to
516  * -# Confidence value (score) obtained with the classifier
517  */
519 {
520  uint16_t x{ 0 }; /**< Top-left x coordinate */
521  uint16_t y{ 0 }; /**< Top-left y coordinate */
522  uint16_t width{ 0 }; /**< Width of the detection window */
523  uint16_t height{ 0 }; /**< Height of the detection window */
524  uint16_t idx_class{ 0 }; /**< Index of the class */
525  float score{ 0.f }; /**< Confidence value for the detection window */
526 };
527 
528 /** Dimension rounding type when down-scaling on CNNs
529  * @note Used in pooling and convolution layer
530  */
532 {
533  FLOOR, /**< Floor rounding */
534  CEIL /**< Ceil rounding */
535 };
536 
537 /** Available pooling types */
538 enum class PoolingType
539 {
540  MAX, /**< Max Pooling */
541  AVG, /**< Average Pooling */
542  L2 /**< L2 Pooling */
543 };
544 
545 /** Available non maxima suppression types */
546 enum class NMSType
547 {
548  LINEAR, /**< Linear NMS */
549  GAUSSIAN, /**< Gaussian NMS */
550  ORIGINAL /**< Original NMS */
551 };
552 
553 /** BoxWithNonMaximaSuppressionLimit Information class */
554 class BoxNMSLimitInfo final
555 {
556 public:
557  /** Constructor
558  *
559  * @param[in] score_thresh (Optional) Score threshold.
560  * @param[in] nms (Optional) NMS value
561  * @param[in] detections (Optional) Number of detections
562  * @param[in] soft_nms_enabled (Optional) Enable SoftNMS
563  * @param[in] soft_nms_method (Optional) Soft NMS method
564  * @param[in] soft_nms_sigma (Optional) Soft NMS sigma value
565  * @param[in] soft_nms_min_score_thres (Optional) Soft NMS minimum score threshold
566  * @param[in] suppress_size (Optional) Filter out boxes based on their size. Defaults to false
567  * @param[in] min_size (Optional) Smaller boxes than min_size will be filtered out. Defaults to 1
568  * @param[in] im_width (Optional) Boxes whose centers (on the x axis) is beyond im_width will be filtered. Defaults to 1
569  * @param[in] im_height (Optional) Boxes whose centers (on the y axis) is beyond im_height will be filtered. Defaults to 1
570  */
571  BoxNMSLimitInfo(float score_thresh = 0.05f, float nms = 0.3f,
572  int detections = 100, bool soft_nms_enabled = false,
574  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)
575  : _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),
576  _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)
577  {
578  }
579  /** Get the score threshold */
580  float score_thresh() const
581  {
582  return _score_thresh;
583  }
584  /** Get the NMS */
585  float nms() const
586  {
587  return _nms;
588  }
589  /** Get the number of detections */
590  int detections_per_im() const
591  {
592  return _detections_per_im;
593  }
594  /** Check if soft NMS is enabled */
595  bool soft_nms_enabled() const
596  {
597  return _soft_nms_enabled;
598  }
599  /** Get soft NMS method */
601  {
602  return _soft_nms_method;
603  }
604  /** Get soft NMS sigma */
605  float soft_nms_sigma() const
606  {
607  return _soft_nms_sigma;
608  }
609  /** Get soft nms min score threshold */
611  {
612  return _soft_nms_min_score_thres;
613  }
614  /** Get if NMS will suppress boxes based on their size/position */
615  bool suppress_size() const
616  {
617  return _suppress_size;
618  }
619  /** Get size suppression threshold */
620  float min_size() const
621  {
622  return _min_size;
623  }
624  /** Get image width (NMS may suppress boxes whose center sits beyond the image width) */
625  float im_width() const
626  {
627  return _im_width;
628  }
629  /** Get image height (NMS may suppress boxes whose center sits beyond the image height) */
630  float im_height() const
631  {
632  return _im_height;
633  }
634 
635 private:
636  float _score_thresh;
637  float _nms;
638  int _detections_per_im;
639  bool _soft_nms_enabled;
640  NMSType _soft_nms_method;
641  float _soft_nms_sigma;
642  float _soft_nms_min_score_thres;
643  bool _suppress_size;
644  float _min_size;
645  float _im_width;
646  float _im_height;
647 };
648 
649 /** Padding and stride information class */
651 {
652 public:
653  /** Constructor
654  *
655  * @param[in] stride_x (Optional) Stride, in elements, across x. Defaults to 1.
656  * @param[in] stride_y (Optional) Stride, in elements, across y. Defaults to 1.
657  * @param[in] pad_x (Optional) Padding, in elements, across x. Defaults to 0.
658  * @param[in] pad_y (Optional) Padding, in elements, across y. Defaults to 0.
659  * @param[in] round (Optional) Dimensions rounding. Defaults to @ref FLOOR.
660  */
661  PadStrideInfo(unsigned int stride_x = 1, unsigned int stride_y = 1,
662  unsigned int pad_x = 0, unsigned int pad_y = 0,
664  : _stride(std::make_pair(stride_x, stride_y)),
665  _pad_left(pad_x),
666  _pad_top(pad_y),
667  _pad_right(pad_x),
668  _pad_bottom(pad_y),
669  _round_type(round)
670  {
671  }
672  /** Constructor
673  *
674  * @param[in] stride_x Stride, in elements, across x.
675  * @param[in] stride_y Stride, in elements, across y.
676  * @param[in] pad_left Padding across x on the left, in elements.
677  * @param[in] pad_top Padding across y on the top, in elements.
678  * @param[in] pad_right Padding across x on the right, in elements.
679  * @param[in] pad_bottom Padding across y on the bottom, in elements.
680  * @param[in] round Dimensions rounding.
681  */
682  PadStrideInfo(unsigned int stride_x, unsigned int stride_y,
683  unsigned int pad_left, unsigned int pad_right,
684  unsigned int pad_top, unsigned int pad_bottom,
686  : _stride(std::make_pair(stride_x, stride_y)),
687  _pad_left(pad_left),
688  _pad_top(pad_top),
689  _pad_right(pad_right),
690  _pad_bottom(pad_bottom),
691  _round_type(round)
692  {
693  }
694  /** Get the stride.
695  *
696  * @return a pair: stride x, stride y.
697  */
698  std::pair<unsigned int, unsigned int> stride() const
699  {
700  return _stride;
701  }
702  /** Check whether the padding is symmetric.
703  *
704  * @return True if the padding is symmetric.
705  */
706  bool padding_is_symmetric() const
707  {
708  return (_pad_left == _pad_right) && (_pad_top == _pad_bottom);
709  }
710  /** Get the padding.
711  *
712  * @note This should only be used when the padding is symmetric.
713  *
714  * @return a pair: padding left/right, padding top/bottom
715  */
716  std::pair<unsigned int, unsigned int> pad() const
717  {
718  //this accessor should be used only when padding is symmetric
720  return std::make_pair(_pad_left, _pad_top);
721  }
722 
723  /** Get the left padding */
724  unsigned int pad_left() const
725  {
726  return _pad_left;
727  }
728  /** Get the right padding */
729  unsigned int pad_right() const
730  {
731  return _pad_right;
732  }
733  /** Get the top padding */
734  unsigned int pad_top() const
735  {
736  return _pad_top;
737  }
738  /** Get the bottom padding */
739  unsigned int pad_bottom() const
740  {
741  return _pad_bottom;
742  }
743 
744  /** Get the rounding type */
746  {
747  return _round_type;
748  }
749 
750  /** Check whether this has any padding */
751  bool has_padding() const
752  {
753  return (_pad_left != 0 || _pad_top != 0 || _pad_right != 0 || _pad_bottom != 0);
754  }
755 
756 private:
757  std::pair<unsigned int, unsigned int> _stride;
758  unsigned int _pad_left;
759  unsigned int _pad_top;
760  unsigned int _pad_right;
761  unsigned int _pad_bottom;
762 
763  DimensionRoundingType _round_type;
764 };
765 
766 /** PriorBox layer info */
767 class PriorBoxLayerInfo final
768 {
769 public:
770  /** Default Constructor */
772  : _min_sizes(),
773  _variances(),
774  _offset(),
775  _flip(true),
776  _clip(false),
777  _max_sizes(),
778  _aspect_ratios(),
779  _img_size(),
780  _steps()
781  {
782  }
783  /** Constructor
784  *
785  * @param[in] min_sizes Min sizes vector.
786  * @param[in] variances Variances vector.
787  * @param[in] offset Offset value.
788  * @param[in] flip (Optional) Flip the aspect ratios.
789  * @param[in] clip (Optional) Clip coordinates so that they're within [0,1].
790  * @param[in] max_sizes (Optional) Max sizes vector.
791  * @param[in] aspect_ratios (Optional) Aspect ratios of the boxes.
792  * @param[in] img_size (Optional) Image size.
793  * @param[in] steps (Optional) Step values.
794  */
795  PriorBoxLayerInfo(const std::vector<float> &min_sizes, const std::vector<float> &variances, float offset, bool flip = true, bool clip = false,
796  const std::vector<float> &max_sizes = {}, const std::vector<float> &aspect_ratios = {},
797  const Coordinates2D &img_size = Coordinates2D{ 0, 0 }, const std::array<float, 2> &steps = { { 0.f, 0.f } })
798  : _min_sizes(min_sizes),
799  _variances(variances),
800  _offset(offset),
801  _flip(flip),
802  _clip(clip),
803  _max_sizes(max_sizes),
804  _aspect_ratios(),
805  _img_size(img_size),
806  _steps(steps)
807  {
808  _aspect_ratios.push_back(1.);
809  for(unsigned int i = 0; i < aspect_ratios.size(); ++i)
810  {
811  float ar = aspect_ratios[i];
812  bool already_exist = false;
813  for(auto ar_new : _aspect_ratios)
814  {
815  if(fabs(ar - ar_new) < 1e-6)
816  {
817  already_exist = true;
818  break;
819  }
820  }
821  if(!already_exist)
822  {
823  _aspect_ratios.push_back(ar);
824  if(flip)
825  {
826  _aspect_ratios.push_back(1.f / ar);
827  }
828  }
829  }
830  }
831  /** Get min sizes. */
832  std::vector<float> min_sizes() const
833  {
834  return _min_sizes;
835  }
836  /** Get min variances. */
837  std::vector<float> variances() const
838  {
839  return _variances;
840  }
841  /** Get the step coordinates */
842  std::array<float, 2> steps() const
843  {
844  return _steps;
845  }
846  /** Get the image size coordinates */
848  {
849  return _img_size;
850  }
851  /** Get the offset */
852  float offset() const
853  {
854  return _offset;
855  }
856  /** Get the flip value */
857  bool flip() const
858  {
859  return _flip;
860  }
861  /** Get the clip value */
862  bool clip() const
863  {
864  return _clip;
865  }
866  /** Get max sizes. */
867  std::vector<float> max_sizes() const
868  {
869  return _max_sizes;
870  }
871  /** Get aspect ratios. */
872  std::vector<float> aspect_ratios() const
873  {
874  return _aspect_ratios;
875  }
876 
877 private:
878  std::vector<float> _min_sizes;
879  std::vector<float> _variances;
880  float _offset;
881  bool _flip;
882  bool _clip;
883  std::vector<float> _max_sizes;
884  std::vector<float> _aspect_ratios;
885  Coordinates2D _img_size;
886  std::array<float, 2> _steps;
887 };
888 
889 // Bounding Box [xmin, ymin, xmax, ymax]
890 using BBox = std::array<float, 4>;
891 // LabelBBox used for map label and bounding box
892 using LabelBBox = std::map<int, std::vector<BBox>>;
893 
894 /** Available Detection Output code types */
896 {
897  CORNER, /**< Use box corners */
898  CENTER_SIZE, /**< Use box centers and size */
899  CORNER_SIZE, /**< Use box centers and size */
900  TF_CENTER /**< Use box centers and size but flip x and y co-ordinates */
901 };
902 
903 /** Detection Output layer info */
905 {
906 public:
907  /** Default Constructor */
909  : _num_classes(),
910  _share_location(),
912  _keep_top_k(),
913  _nms_threshold(),
914  _top_k(),
915  _background_label_id(),
916  _confidence_threshold(),
917  _variance_encoded_in_target(false),
918  _eta(),
919  _num_loc_classes()
920  {
921  _num_loc_classes = _share_location ? 1 : _num_classes;
922  }
923  /** Constructor
924  *
925  * @param[in] num_classes Number of classes to be predicted.
926  * @param[in] share_location If true, bounding box are shared among different classes.
927  * @param[in] code_type Type of coding method for bbox.
928  * @param[in] keep_top_k Number of total bounding boxes to be kept per image after NMS step.
929  * @param[in] nms_threshold Threshold to be used in NMS.
930  * @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.
931  * @param[in] background_label_id (Optional) Background label ID. If there is no background class, set it as -1.
932  * @param[in] confidence_threshold (Optional) Only consider detections whose confidences are larger than a threshold. Default set to -FLT_MAX.
933  * @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.
934  * @param[in] eta (Optional) Eta.
935  */
938  : _num_classes(num_classes),
939  _share_location(share_location),
940  _code_type(code_type),
941  _keep_top_k(keep_top_k),
942  _nms_threshold(nms_threshold),
943  _top_k(top_k),
944  _background_label_id(background_label_id),
945  _confidence_threshold(confidence_threshold),
946  _variance_encoded_in_target(variance_encoded_in_target),
947  _eta(eta),
948  _num_loc_classes()
949  {
950  _num_loc_classes = _share_location ? 1 : _num_classes;
951  }
952  /** Get num classes. */
953  int num_classes() const
954  {
955  return _num_classes;
956  }
957  /** Get share location. */
958  bool share_location() const
959  {
960  return _share_location;
961  }
962  /** Get detection output code type. */
964  {
965  return _code_type;
966  }
967  /** Get if variance encoded in target. */
969  {
970  return _variance_encoded_in_target;
971  }
972  /** Get the number of total bounding boxes to be kept per image. */
973  int keep_top_k() const
974  {
975  return _keep_top_k;
976  }
977  /** Get nms threshold. */
978  float nms_threshold() const
979  {
980  return _nms_threshold;
981  }
982  /** Get eta. */
983  float eta() const
984  {
985  return _eta;
986  }
987  /** Get background label ID. */
989  {
990  return _background_label_id;
991  }
992  /** Get confidence threshold. */
993  float confidence_threshold() const
994  {
995  return _confidence_threshold;
996  }
997  /** Get top K. */
998  int top_k() const
999  {
1000  return _top_k;
1001  }
1002  /** Get number of location classes. */
1003  int num_loc_classes() const
1004  {
1005  return _num_loc_classes;
1006  }
1007 
1008 private:
1009  int _num_classes;
1010  bool _share_location;
1011  DetectionOutputLayerCodeType _code_type;
1012  int _keep_top_k;
1013  float _nms_threshold;
1014  int _top_k;
1015  int _background_label_id;
1016  float _confidence_threshold;
1017  bool _variance_encoded_in_target;
1018  float _eta;
1019  int _num_loc_classes;
1020 };
1021 
1022 /** Detection Output layer info */
1024 {
1025 public:
1026  /** Default Constructor */
1028  : _max_detections(),
1029  _max_classes_per_detection(),
1030  _nms_score_threshold(),
1031  _iou_threshold(),
1032  _num_classes(),
1033  _scales_values(),
1034  _use_regular_nms(),
1035  _detection_per_class(),
1036  _dequantize_scores()
1037  {
1038  }
1039  /** Constructor
1040  *
1041  * @param[in] max_detections Number of total detection.
1042  * @param[in] max_classes_per_detection Number of total classes to be kept after NMS step. Used in the Fast Non-Max-Suppression
1043  * @param[in] nms_score_threshold Threshold to be used in NMS
1044  * @param[in] iou_threshold Threshold to be used during the intersection over union.
1045  * @param[in] num_classes Number of classes.
1046  * @param[in] scales_values Scales values used for decode center size boxes.
1047  * @param[in] use_regular_nms (Optional) Boolean to determinate if use regular or fast nms. Defaults to false.
1048  * @param[in] detection_per_class (Optional) Number of detection per class. Used in the Regular Non-Max-Suppression. Defaults to 100.
1049  * @param[in] dequantize_scores (Optional) If the scores need to be dequantized. Defaults to true.
1050  */
1052  std::array<float, 4> scales_values, bool use_regular_nms = false, unsigned int detection_per_class = 100, bool dequantize_scores = true)
1053  : _max_detections(max_detections),
1054  _max_classes_per_detection(max_classes_per_detection),
1055  _nms_score_threshold(nms_score_threshold),
1056  _iou_threshold(iou_threshold),
1057  _num_classes(num_classes),
1058  _scales_values(scales_values),
1059  _use_regular_nms(use_regular_nms),
1060  _detection_per_class(detection_per_class),
1061  _dequantize_scores(dequantize_scores)
1062  {
1063  }
1064  /** Get max detections. */
1065  unsigned int max_detections() const
1066  {
1067  return _max_detections;
1068  }
1069  /** Get max_classes per detection. Used in the Fast Non-Max-Suppression.*/
1070  unsigned int max_classes_per_detection() const
1071  {
1072  return _max_classes_per_detection;
1073  }
1074  /** Get detection per class. Used in the Regular Non-Max-Suppression */
1075  unsigned int detection_per_class() const
1076  {
1077  return _detection_per_class;
1078  }
1079  /** Get nms threshold. */
1080  float nms_score_threshold() const
1081  {
1082  return _nms_score_threshold;
1083  }
1084  /** Get intersection over union threshold. */
1085  float iou_threshold() const
1086  {
1087  return _iou_threshold;
1088  }
1089  /** Get num classes. */
1090  unsigned int num_classes() const
1091  {
1092  return _num_classes;
1093  }
1094  /** Get if use regular nms. */
1095  bool use_regular_nms() const
1096  {
1097  return _use_regular_nms;
1098  }
1099  /** Get y scale value. */
1100  float scale_value_y() const
1101  {
1102  // Saved as [y,x,h,w]
1103  return _scales_values[0];
1104  }
1105  /** Get x scale value. */
1106  float scale_value_x() const
1107  {
1108  // Saved as [y,x,h,w]
1109  return _scales_values[1];
1110  }
1111  /** Get h scale value. */
1112  float scale_value_h() const
1113  {
1114  // Saved as [y,x,h,w]
1115  return _scales_values[2];
1116  }
1117  /** Get w scale value. */
1118  float scale_value_w() const
1119  {
1120  // Saved as [y,x,h,w]
1121  return _scales_values[3];
1122  }
1123  /** Get dequantize_scores value. */
1124  bool dequantize_scores() const
1125  {
1126  return _dequantize_scores;
1127  }
1128 
1129 private:
1130  unsigned int _max_detections;
1131  unsigned int _max_classes_per_detection;
1132  float _nms_score_threshold;
1133  float _iou_threshold;
1134  unsigned int _num_classes;
1135  std::array<float, 4> _scales_values;
1136  bool _use_regular_nms;
1137  unsigned int _detection_per_class;
1138  bool _dequantize_scores;
1139 };
1140 
1141 /** Pooling Layer Information struct*/
1143 {
1144  /** Default Constructor */
1147  pool_size(Size2D()),
1150  exclude_padding(false),
1151  is_global_pooling(false),
1152  fp_mixed_precision(false)
1153  {
1154  }
1155  /** Constructor
1156  *
1157  * @param[in] pool_type Pooling type @ref PoolingType.
1158  * @param[in] pool_size Pooling size, in elements, across x and y.
1159  * @param[in] data_layout Data layout used by the layer @ref DataLayout
1160  * @param[in] pad_stride_info (Optional) Padding and stride information @ref PadStrideInfo
1161  * @param[in] exclude_padding (Optional) Strategy when accounting padding in calculations.
1162  * True will exclude padding while false will not (Used in AVG/L2 pooling to determine the pooling area).
1163  * Defaults to false;
1164  * @param[in] fp_mixed_precision (Optional) Use wider accumulators (32 bit instead of 16 for FP16) to improve accuracy.
1165  */
1167  unsigned int pool_size,
1170  bool exclude_padding = false,
1171  bool fp_mixed_precision = false)
1172  : pool_type(pool_type),
1177  is_global_pooling(false),
1179  {
1180  }
1181 
1182  /** Constructor
1183  *
1184  * @param[in] pool_type Pooling type @ref PoolingType.
1185  * @param[in] pool_size Pooling size, in elements, across x and y.
1186  * @param[in] data_layout Data layout used by the layer @ref DataLayout
1187  * @param[in] pad_stride_info (Optional) Padding and stride information @ref PadStrideInfo
1188  * @param[in] exclude_padding (Optional) Strategy when accounting padding in calculations.
1189  * True will exclude padding while false will not (Used in AVG/L2 pooling to determine the pooling area).
1190  * Defaults to false;
1191  * @param[in] fp_mixed_precision (Optional) Use wider accumulators (32 bit instead of 16 for FP16) to improve accuracy.
1192  */
1194  Size2D pool_size,
1197  bool exclude_padding = false,
1198  bool fp_mixed_precision = false)
1199  : pool_type(pool_type),
1204  is_global_pooling(false),
1206  {
1207  }
1208 
1209  /** Constructor
1210  *
1211  * @note This constructor is used for global pooling
1212  *
1213  * @param[in] pool_type Pooling type @ref PoolingType.
1214  * @param[in] data_layout Data layout used by the layer @ref DataLayout
1215  */
1217  : pool_type(pool_type),
1218  pool_size(Size2D()),
1220  pad_stride_info(PadStrideInfo(1, 1, 0, 0)),
1221  exclude_padding(false),
1222  is_global_pooling(true),
1223  fp_mixed_precision(false)
1224  {
1225  }
1226 
1234 };
1235 
1236 /** ROI Pooling Layer Information class */
1238 {
1239 public:
1240  /** Constructor
1241  *
1242  * @param[in] pooled_width Pooled width of the layer.
1243  * @param[in] pooled_height Pooled height of the layer.
1244  * @param[in] spatial_scale Spatial scale to be applied to the ROI coordinates and dimensions.
1245  * @param[in] sampling_ratio Number of samples to include in each pooling region (if set to zero, a ceil(roi_dims/pooling_dims))
1246  */
1247  ROIPoolingLayerInfo(unsigned int pooled_width, unsigned int pooled_height, float spatial_scale, unsigned int sampling_ratio = 0)
1248  : _pooled_width(pooled_width), _pooled_height(pooled_height), _spatial_scale(spatial_scale), _sampling_ratio(sampling_ratio)
1249  {
1250  }
1251  /** Get the pooled width of the layer */
1252  unsigned int pooled_width() const
1253  {
1254  return _pooled_width;
1255  }
1256  /** Get the pooled height of the layer */
1257  unsigned int pooled_height() const
1258  {
1259  return _pooled_height;
1260  }
1261  /** Get the spatial scale */
1262  float spatial_scale() const
1263  {
1264  return _spatial_scale;
1265  }
1266  /** Get sampling ratio */
1267  unsigned int sampling_ratio() const
1268  {
1269  return _sampling_ratio;
1270  }
1271 
1272 private:
1273  unsigned int _pooled_width;
1274  unsigned int _pooled_height;
1275  float _spatial_scale;
1276  unsigned int _sampling_ratio;
1277 };
1278 
1279 /** Generate Proposals Information class */
1281 {
1282 public:
1283  /** Constructor
1284  *
1285  * @param[in] im_width Width of the original image
1286  * @param[in] im_height Height of the original image
1287  * @param[in] im_scale Scale applied to the original image
1288  * @param[in] spatial_scale (Optional)Scale applied to the feature map. Defaults to 1.0
1289  * @param[in] pre_nms_topN (Optional)Number of the best scores to be selected from the transformations. Defaults to 6000.
1290  * @param[in] post_nms_topN (Optional)Number of the best scores to be selected from the NMS operation. Defaults to 300.
1291  * @param[in] nms_thres (Optional)NMS overlap threshold. Defaults to 0.7.
1292  * @param[in] min_size (Optional)Size used to validate the anchors produced. Defaults to 16.
1293  * @param[in] values_per_roi (Optional)Values used to represent a ROI(Region of interest). Defaults to 4.
1294  */
1295  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,
1296  size_t values_per_roi = 4)
1297  : _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),
1298  _min_size(min_size), _values_per_roi(values_per_roi)
1299  {
1300  }
1301 
1302  /* Get the original height */
1303  float im_height() const
1304  {
1305  return _im_height;
1306  }
1307  /* Get the original width */
1308  float im_width() const
1309  {
1310  return _im_width;
1311  }
1312  /* Get the image scale */
1313  float im_scale() const
1314  {
1315  return _im_scale;
1316  }
1317  /* Get the value of how many best scores to select (before NMS) */
1318  int pre_nms_topN() const
1319  {
1320  return _pre_nms_topN;
1321  }
1322  /* Get the value of how many best scores to select (after NMS) */
1323  int post_nms_topN() const
1324  {
1325  return _post_nms_topN;
1326  }
1327  /* Get the NMS overlap threshold */
1328  float nms_thres() const
1329  {
1330  return _nms_thres;
1331  }
1332  /* Get the minimal size */
1333  float min_size() const
1334  {
1335  return _min_size;
1336  }
1337  /* Get the spatial scale to be applied to the feature maps */
1338  float spatial_scale() const
1339  {
1340  return _spatial_scale;
1341  }
1342  /* Get the values used to represent a ROI(Region of interest)*/
1343  size_t values_per_roi() const
1344  {
1345  return _values_per_roi;
1346  }
1347 
1348 private:
1349  float _im_height;
1350  float _im_width;
1351  float _im_scale;
1352  float _spatial_scale;
1353  int _pre_nms_topN;
1354  int _post_nms_topN;
1355  float _nms_thres;
1356  float _min_size;
1357  size_t _values_per_roi;
1358 };
1359 
1360 /** ComputeAnchors information class */
1362 {
1363 public:
1364  /** Constructor
1365  *
1366  * @param[in] feat_width Feature map width
1367  * @param[in] feat_height Feature map height
1368  * @param[in] spatial_scale Feature map scale
1369  * @param[in] values_per_roi (Optional)Values used to represent a ROI(Region Of Interest). Defaults to 4
1370  */
1372  : _feat_height(feat_height),
1373  _feat_width(feat_width),
1374  _spatial_scale(spatial_scale),
1375  _values_per_roi(values_per_roi)
1376  {
1377  }
1378 
1379  /* Get the height of the feature map */
1380  float feat_height() const
1381  {
1382  return _feat_height;
1383  }
1384 
1385  /* Get the width of the feature map */
1386  float feat_width() const
1387  {
1388  return _feat_width;
1389  }
1390 
1391  /* Get the scale of the feature map */
1392  float spatial_scale() const
1393  {
1394  return _spatial_scale;
1395  }
1396 
1397  /* Get the values used to represent a ROI(Region Of Interest)*/
1398  size_t values_per_roi() const
1399  {
1400  return _values_per_roi;
1401  }
1402 
1403 private:
1404  float _feat_height;
1405  float _feat_width;
1406  float _spatial_scale;
1407  size_t _values_per_roi;
1408 };
1409 
1410 /** Bounding Box Transform information class */
1412 {
1413 public:
1414  /** Constructor
1415  *
1416  * @param[in] img_width Width of the original image
1417  * @param[in] img_height Height, of the original image
1418  * @param[in] scale Scale of the original image
1419  * @param[in] apply_scale (Optional)Re-apply scaling after transforming the boxes. Defaults to false
1420  * @param[in] weights (Optional)Weights [wx, wy, ww, wh] for the deltas. Defaults to all ones
1421  * @param[in] correct_transform_coords (Optional)Correct bounding box transform coordinates. Defaults to false
1422  * @param[in] bbox_xform_clip (Optional)Minimum bounding box width and height after bounding box transformation in log-space. Defaults to log(1000/16)
1423  */
1424  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 =
1425  false,
1426  float bbox_xform_clip =
1427  4.135166556742356f)
1428  : _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)
1429  {
1430  }
1431 
1432  std::array<float, 4> weights() const
1433  {
1434  return _weights;
1435  }
1436 
1437  float bbox_xform_clip() const
1438  {
1439  return _bbox_xform_clip;
1440  }
1441 
1442  float img_height() const
1443  {
1444  return _img_height;
1445  }
1446 
1447  float img_width() const
1448  {
1449  return _img_width;
1450  }
1451 
1452  float scale() const
1453  {
1454  return _scale;
1455  }
1456 
1457  bool apply_scale() const
1458  {
1459  return _apply_scale;
1460  }
1461 
1463  {
1464  return _correct_transform_coords;
1465  }
1466 
1467 private:
1468  float _img_width;
1469  float _img_height;
1470  float _scale;
1471  bool _apply_scale;
1472  bool _correct_transform_coords;
1473  std::array<float, 4> _weights;
1474  float _bbox_xform_clip;
1475 };
1476 
1477 /** Activation Layer Information class */
1479 {
1480 public:
1481  /** Available activation functions */
1483  {
1484  LOGISTIC, /**< Logistic ( \f$ f(x) = \frac{1}{1 + e^{-x}} \f$ ) */
1485  TANH, /**< Hyperbolic tangent ( \f$ f(x) = a \cdot tanh(b \cdot x) \f$ ) */
1486  RELU, /**< Rectifier ( \f$ f(x) = max(0,x) \f$ ) */
1487  BOUNDED_RELU, /**< Upper Bounded Rectifier ( \f$ f(x) = min(a, max(0,x)) \f$ ) */
1488  LU_BOUNDED_RELU, /**< Lower and Upper Bounded Rectifier ( \f$ f(x) = min(a, max(b,x)) \f$ ) */
1489  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$ ) */
1490  SOFT_RELU, /**< Soft Rectifier ( \f$ f(x)= log(1+e^x) \f$ ) */
1491  ELU, /**< Exponential Linear Unit ( \f$ f(x) = \begin{cases} \alpha (exp(x) - 1) & \quad \text{if } x \text{ < 0}\\ x & \quad \text{if } x \geq \text{ 0 } \end{cases} \f$ ) */
1492  ABS, /**< Absolute ( \f$ f(x)= |x| \f$ ) */
1493  SQUARE, /**< Square ( \f$ f(x)= x^2 \f$ )*/
1494  SQRT, /**< Square root ( \f$ f(x) = \sqrt{x} \f$ )*/
1495  LINEAR, /**< Linear ( \f$ f(x)= ax + b \f$ ) */
1496  IDENTITY, /**< Identity ( \f$ f(x)= x \f$ ) */
1497  HARD_SWISH /**< Hard-swish ( \f$ f(x) = (x * relu6(x+3))/6 \f$ ) */
1498  };
1499 
1500  ActivationLayerInfo() = default;
1501  /** Default Constructor
1502  *
1503  * @param[in] f The activation function to use.
1504  * @param[in] a (Optional) The alpha parameter used by some activation functions
1505  * (@ref ActivationFunction::BOUNDED_RELU, @ref ActivationFunction::LU_BOUNDED_RELU, @ref ActivationFunction::LINEAR, @ref ActivationFunction::TANH).
1506  * @param[in] b (Optional) The beta parameter used by some activation functions (@ref ActivationFunction::LINEAR, @ref ActivationFunction::LU_BOUNDED_RELU, @ref ActivationFunction::TANH).
1507  */
1508  ActivationLayerInfo(ActivationFunction f, float a = 0.0f, float b = 0.0f)
1509  : _act(f), _a(a), _b(b), _enabled(true)
1510  {
1511  }
1512  /** Get the type of activation function */
1514  {
1515  return _act;
1516  }
1517  /** Get the alpha value */
1518  float a() const
1519  {
1520  return _a;
1521  }
1522  /** Get the beta value */
1523  float b() const
1524  {
1525  return _b;
1526  }
1527  /** Check if initialised */
1528  bool enabled() const
1529  {
1530  return _enabled;
1531  }
1532 
1533 private:
1535  float _a = {};
1536  float _b = {};
1537  bool _enabled = { false };
1538 };
1539 
1540 /** Fully connected layer info */
1542 {
1543  DataLayout weights_trained_layout{ DataLayout::NCHW }; /**< Layout that the weights have been trained with. */
1544  bool transpose_weights{ true }; /**< Transpose weights if true. */
1545  bool are_weights_reshaped{ false }; /**< Reshape the weights tensor if false. */
1546  bool retain_internal_weights{ false }; /**< Retain internal reshaped weights. */
1547  bool fp_mixed_precision{ false }; /**< Use wider accumulators (32 bit instead of 16 for FP16) to improve accuracy. */
1548  ActivationLayerInfo activation_info{}; /**< Fused activation to apply after the matrix multiplication. */
1549 
1550  /** Sets the weights trained data layout
1551  *
1552  * @param[in] layout Data layout that the weights were trained with
1553  *
1554  * @return Updated object
1555  */
1557  {
1558  weights_trained_layout = layout;
1559  return *this;
1560  }
1561  /** Sets the transpose weights flag
1562  *
1563  * @param[in] should_transpose_weights Boolean flag indicating if weights should be transposed
1564  *
1565  * @return Updated object
1566  */
1567  FullyConnectedLayerInfo &set_transpose_weights(bool should_transpose_weights)
1568  {
1569  transpose_weights = should_transpose_weights;
1570  return *this;
1571  }
1572 };
1573 
1574 /** Normalization Layer Information class */
1576 {
1577 public:
1578  /** Default Constructor
1579  *
1580  * @param[in] type The normalization type. Can be @ref NormType::IN_MAP_1D, @ref NormType::IN_MAP_2D or @ref NormType::CROSS_MAP
1581  * @param[in] norm_size The normalization size is the number of elements to normalize across. Defaults to 5.
1582  * @param[in] alpha (Optional) Alpha parameter used by normalization equation. Defaults to 0.0001.
1583  * @param[in] beta (Optional) Beta parameter used by normalization equation. Defaults to 0.5.
1584  * @param[in] kappa (Optional) Kappa parameter used by [Krichevksy 2012] Across Channel Local Brightness Normalization equation.
1585  * @param[in] is_scaled (Optional) Boolean that specifies if alpha will be scaled by the normalization size or not.
1586  * Should be false to follow [Krichevksy 2012].
1587  */
1588  NormalizationLayerInfo(NormType type, uint32_t norm_size = 5, float alpha = 0.0001f, float beta = 0.5f, float kappa = 1.f, bool is_scaled = true)
1589  : _type(type), _norm_size(norm_size), _alpha(alpha), _beta(beta), _kappa(kappa), _is_scaled(is_scaled)
1590  {
1591  }
1592  /** Get the normalization type */
1593  NormType type() const
1594  {
1595  return _type;
1596  }
1597  /** Get the normalization size */
1598  uint32_t norm_size() const
1599  {
1600  return _norm_size;
1601  }
1602  /** Get the alpha value */
1603  float alpha() const
1604  {
1605  return _alpha;
1606  }
1607  /** Get the beta value */
1608  float beta() const
1609  {
1610  return _beta;
1611  }
1612  /** Get the kappa value */
1613  float kappa() const
1614  {
1615  return _kappa;
1616  }
1617  /** Get the is_scaled value */
1618  bool is_scaled() const
1619  {
1620  return _is_scaled;
1621  }
1622  /** Check if normalization is cross map */
1623  bool is_cross_map() const
1624  {
1625  return _type == NormType::CROSS_MAP;
1626  }
1627  /** Check if normalization is not cross map */
1628  bool is_in_map() const
1629  {
1630  return !is_cross_map();
1631  }
1632  /** Return the scaling factor of the normalization function.
1633  *
1634  * If is_scaled is set to false then [Krichevksy 2012] normalization scaling is performed,
1635  * where alpha is returned plainly, else alpha is scaled by the total number of elements used for the normalization.
1636  *
1637  * @return The normalization scaling factor.
1638  */
1639  float scale_coeff() const
1640  {
1641  const uint32_t size = (_type == NormType::IN_MAP_2D) ? _norm_size * _norm_size : _norm_size;
1642  return (_is_scaled) ? (_alpha / size) : _alpha;
1643  }
1644 
1645 private:
1646  NormType _type;
1647  uint32_t _norm_size;
1648  float _alpha;
1649  float _beta;
1650  float _kappa;
1651  bool _is_scaled;
1652 };
1653 
1655 {
1656 public:
1657  /** Default Constructor
1658  *
1659  * @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.
1660  * @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.
1661  * @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.
1662  */
1663  StridedSliceLayerInfo(int32_t begin_mask = 0, int32_t end_mask = 0, int32_t shrink_axis_mask = 0)
1664  : _begin_mask(begin_mask), _end_mask(end_mask), _shrink_axis_mask(shrink_axis_mask)
1665  {
1666  }
1667 
1668  /* Get the begin mask value */
1669  int32_t begin_mask() const
1670  {
1671  return _begin_mask;
1672  }
1673 
1674  /* Get the end mask value */
1675  int32_t end_mask() const
1676  {
1677  return _end_mask;
1678  }
1679 
1680  /* Get the shrink axis mask value */
1681  int32_t shrink_axis_mask() const
1682  {
1683  return _shrink_axis_mask;
1684  }
1685 
1686 private:
1687  int32_t _begin_mask;
1688  int32_t _end_mask;
1689  int32_t _shrink_axis_mask;
1690 };
1691 
1692 /** Convolution Layer Weights Information class. This class stores the necessary information to compute convolution layer when the weights are already reshaped */
1694 {
1695 public:
1696  /** Default constructor */
1698  : _are_reshaped(false), _kernel_width(0), _kernel_height(0), _num_kernels(0), _retain_internal_weights(false)
1699  {
1700  }
1701  /** Constructor
1702  *
1703  * @param[in] are_reshaped True if the weights have been reshaped
1704  * @param[in] kernel_width Kernel width.
1705  * @param[in] kernel_height Kernel height.
1706  * @param[in] num_kernels Number of convolution kernels.
1707  * @param[in] retain_internal_weights (Optional) True if internal reshaped weights must be retained. Used for reconfiguration purposes. Default is false.
1708  */
1709  WeightsInfo(bool are_reshaped, unsigned int kernel_width, unsigned int kernel_height, unsigned int num_kernels, bool retain_internal_weights = false)
1710  : _are_reshaped(are_reshaped), _kernel_width(kernel_width), _kernel_height(kernel_height), _num_kernels(num_kernels), _retain_internal_weights(retain_internal_weights)
1711  {
1712  }
1713  /** Flag which specifies if the weights tensor has been reshaped.
1714  *
1715  * @return True if the weights tensors has been reshaped
1716  */
1717  bool are_reshaped() const
1718  {
1719  return _are_reshaped;
1720  };
1721  /** Return the number of convolution kernels
1722  *
1723  * @return The number of convolution kernels
1724  */
1725  unsigned int num_kernels() const
1726  {
1727  return _num_kernels;
1728  };
1729  /** Return the width and height of the kernel
1730  *
1731  * @return The width and height of the kernel
1732  */
1733  std::pair<unsigned int, unsigned int> kernel_size() const
1734  {
1735  return std::make_pair(_kernel_width, _kernel_height);
1736  }
1738  {
1739  return _retain_internal_weights;
1740  }
1741 
1742 private:
1743  bool _are_reshaped;
1744  unsigned int _kernel_width;
1745  unsigned int _kernel_height;
1746  unsigned int _num_kernels;
1747  bool _retain_internal_weights;
1748 };
1749 
1750 /** GEMM reshape information class. This class stores the necessary information about matrix A and matrix B reshape.
1751  *
1752  * The matrix A can only be reshaped through @ref CLGEMMReshapeLHSMatrixKernel or @ref NEGEMMInterleave4x4Kernel
1753  * 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
1754  *
1755  * The matrix B can only be reshaped through @ref CLGEMMReshapeRHSMatrixKernel or @ref NEGEMMTranspose1xWKernel
1756  * 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
1757  *
1758  */
1759 class GEMMReshapeInfo final
1760 {
1761 public:
1762  /** Default constructor */
1764  : _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)
1765  {
1766  }
1767  /** Constructor
1768  *
1769  * @param[in] m Number of matrix A rows
1770  * @param[in] n Number of matrix B columns
1771  * @param[in] k Number of matrix A columns or matrix B rows
1772  * @param[in] mult_transpose1xW_width (Optional) Multiplication factor for the width of the 1xW transposed block
1773  * @param[in] mult_interleave4x4_height (Optional) Multiplication factor for the height of the 4x4 interleaved block
1774  * @param[in] depth_output_gemm3d (Optional) Depth (third dimension) of the output tensor to be used with the GEMM3D kernel.
1775  * If 0 the output will not be reinterpreted as 3D. Default 0
1776  * @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
1777  * to perform 1x1 convolutions with the NHWC data layout)
1778  * @param[in] broadcast_bias (Optional) Broadcast the shape of the bias tensor from a vector to a matrix.
1779  */
1781  : _m(m), _n(n), _k(k), _mult_transpose1xW_width(mult_transpose1xW_width), _mult_interleave4x4_height(mult_interleave4x4_height), _depth_output_gemm3d(depth_output_gemm3d),
1782  _reinterpret_input_as_3d(reinterpret_input_as_3d), _broadcast_bias(broadcast_bias)
1783  {
1784  }
1785  /** Number of matrix A rows
1786  *
1787  * @return the number of matrix A rows
1788  */
1789  int m() const
1790  {
1791  return _m;
1792  }
1793  /** Number of matrix B columns
1794  *
1795  * @return the number of matrix B columns
1796  */
1797  int n() const
1798  {
1799  return _n;
1800  }
1801  /** Number of matrix A columns or matrix B rows
1802  *
1803  * @return the number of matrix A columns or matrix B rows
1804  */
1805  int k() const
1806  {
1807  return _k;
1808  }
1809  /** Multiplication factor for the width of the 1xW transposed block
1810  *
1811  * @return the multiplication factor for the width of the 1xW transposed block
1812  */
1814  {
1815  return _mult_transpose1xW_width;
1816  }
1817  /** Multiplication factor for the height of the 4x4 interleaved block
1818  *
1819  * @return the multiplication factor for the height of the 4x4 interleaved block
1820  */
1822  {
1823  return _mult_interleave4x4_height;
1824  }
1825  /** Depth (third dimension) of the output tensor to be used with the GEMM3D kernel
1826  *
1827  * @note GEMM3D kernel is used when the output has to be reinterpret as 3D tensor. In that case:
1828  * m = depth_output_gemm3d * output_height
1829  *
1830  * @return the depth of the output tensor to be used with the GEMM3D kernel
1831  */
1833  {
1834  return _depth_output_gemm3d;
1835  }
1836  /** Flag which specifies if the input tensor has to be reinterpreted as 3D
1837  *
1838  * @return True if the input tensor has to be reinterpreted as 3D tensor
1839  */
1841  {
1842  return _reinterpret_input_as_3d;
1843  };
1844  /** Flag which specifies whether to broadcast the shape of the bias tensor.
1845  *
1846  * @return True if the shape of the bias tensor is to be broadcasted.
1847  */
1848  bool broadcast_bias() const
1849  {
1850  return _broadcast_bias;
1851  };
1852 
1853 private:
1854  int _m;
1855  int _n;
1856  int _k;
1857  int _mult_transpose1xW_width;
1858  int _mult_interleave4x4_height;
1859  int _depth_output_gemm3d;
1860  bool _reinterpret_input_as_3d;
1861  bool _broadcast_bias;
1862 };
1863 
1865 {
1866  ConvolutionInfo() = default;
1869  {
1870  }
1871  PadStrideInfo pad_stride_info{}; /**< Convolution info (Pads, strides,...) */
1872  unsigned int depth_multiplier{ 1 }; /**< Multiplier to apply to input's depth to retrieve the output depth. Defaults to 1 */
1873  ActivationLayerInfo act_info{}; /**< Fused activation to apply after convolution. */
1874  Size2D dilation{ Size2D(1, 1) }; /**< Dilation, in elements, across x and y. Defaults to (1, 1). */
1875 };
1876 
1877 /** GEMMLowp output stage type */
1879 {
1880  NONE, /**< No quantization */
1881  QUANTIZE_DOWN, /**< Quantize using an integer multiplication */
1882  QUANTIZE_DOWN_FIXEDPOINT, /**< Quantize using a fixed point multiplication */
1883  QUANTIZE_DOWN_FLOAT /**< Quantize using a floating point multiplication */
1884 };
1885 
1886 /** GEMMLowp output stage info */
1888 {
1889  GEMMLowpOutputStageType type{ GEMMLowpOutputStageType::NONE }; /**< GEMMLowp output stage type */
1890  int32_t gemmlowp_offset{ 0 }; /**< GEMMLowp output stage offset used for quantizing to QASYMM8 */
1891  int32_t gemmlowp_multiplier{ 0 }; /**< GEMMLowp output stage multiplier used for quantizing to QASYMM8 */
1892  int32_t gemmlowp_shift{ 0 }; /**< GEMMLowp output stage shift used for quantizing to uint8 */
1893  int32_t gemmlowp_min_bound{ std::numeric_limits<int32_t>::lowest() }; /**< GEMMLowp min value used to saturate down the output result before converting back to QASYMM8 */
1894  int32_t gemmlowp_max_bound{ std::numeric_limits<int32_t>::max() }; /**< GEMMLowp max value used to saturate down the output result before converting back to QASYMM8 */
1895  std::vector<int32_t> gemmlowp_multipliers{}; /**< GEMMLowp output stage multiplier used for quantizing to QASYMM8 */
1896  std::vector<int32_t> gemmlowp_shifts{}; /**< GEMMLowp output stage multiplier used for quantizing to QASYMM8 */
1897  float gemmlowp_real_multiplier{ 0 }; /**< GEMMLowp output stage real multiplier used for quantizing to QASYMM8 */
1898  bool is_quantized_per_channel{ false }; /**< GEMMLowp quantized per-channel flag */
1899  DataType output_data_type{ DataType::UNKNOWN }; /**< Output tensor data type to use if the output is not initialized */
1900 };
1901 
1902 /** GEMM LHS (Left Hand Side) matrix information */
1904 {
1905  GEMMLHSMatrixInfo() = default;
1906  GEMMLHSMatrixInfo(unsigned int m, unsigned int k, unsigned int v, bool trans, bool inter)
1907  : m0(m), k0(k), v0(v), transpose(trans), interleave(inter)
1908  {
1909  }
1910  unsigned int m0{ 1 }; /**< Number of rows processed by the matrix multiplication */
1911  unsigned int k0{ 1 }; /**< Number of partial accumulations performed by the matrix multiplication */
1912  unsigned int v0{ 1 }; /**< Number of vertical blocks of size (m0xk0) stored on the same output row */
1913  bool transpose{ true }; /**< True if the (m0xk0) block has to be transposed before been stored */
1914  bool interleave{ true }; /**< True if the v0 (m0xk0) blocks have to be interleaved in the output row */
1915 };
1916 
1917 /** GEMM RHS (Right Hand Side) matrix information */
1919 {
1920  GEMMRHSMatrixInfo() = default;
1921  GEMMRHSMatrixInfo(unsigned int n, unsigned int k, unsigned int h, bool trans, bool inter, bool export_to_cl_img)
1922  : n0(n), k0(k), h0(h), transpose(trans), interleave(inter), export_to_cl_image(export_to_cl_img)
1923  {
1924  }
1925  unsigned int n0{ 1 }; /**< Number of columns processed by the matrix multiplication */
1926  unsigned int k0{ 1 }; /**< Number of partial accumulations performed by the matrix multiplication */
1927  unsigned int h0{ 1 }; /**< Number of horizontal blocks of size (k0xn0) stored on the same output row */
1928  bool transpose{ true }; /**< True if the (k0xn0) block has to be transposed before been stored */
1929  bool interleave{ true }; /**< True if the h0 (k0xn0) blocks have to be interleaved in the output row */
1930  bool export_to_cl_image{ false }; /**< True if the reshaped rhs has to be exported to cl_image. n0 must be equal to 4 */
1931 };
1932 
1933 /** GEMM information class. This class stores the necessary information to compute GEMM functions
1934  *
1935  * This object also contains the information about how matrix A and matrix B have been reshaped
1936  *
1937  */
1939 {
1940 public:
1941  /** Default constructor */
1942  GEMMInfo() noexcept
1943  : _is_a_reshaped(false),
1944  _is_b_reshaped(false),
1945  _reshape_b_only_on_first_run(true),
1946  _depth_output_gemm3d(0),
1947  _reinterpret_input_as_3d(false),
1948  _retain_internal_weights(false),
1949  _gemmlowp_output_stage(),
1950  _fp_mixed_precision(false),
1951  _broadcast_bias(false),
1952  _pretranpose_B(true),
1953  _activation_info()
1954  {
1955  }
1956  /** Constructor
1957  *
1958  * @param[in] is_a_reshaped True if the matrix A has been reshaped
1959  * @param[in] is_b_reshaped True if the matrix B has been reshaped
1960  * @param[in] reshape_b_only_on_first_run Reshape matrix B only for the first run
1961  * @param[in] depth_output_gemm3d (Optional) Depth (third dimension) of the output tensor to be used with the GEMM3D kernel
1962  * If 0 the output will not be reinterpreted as 3D. Default 0
1963  * @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
1964  * to perform 1x1 convolutions with the NHWC data layout)
1965  * @param[in] retain_internal_weights (Optional) Retain the weights tensor from previous run
1966  * @param[in] gemmlowp_output_stage (Optional) GEMMLowp Output stage info
1967  * @param[in] fp_mixed_precision (Optional) Use wider accumulators (32 bit instead of 16 for FP16) to improve accuracy.
1968  * @param[in] broadcast_bias (Optional) Broadcast the shape of the bias tensor from a vector to a matrix.
1969  * @param[in] activation_info (Optional) Activation to apply after the matrix multiplication
1970  */
1974  : _is_a_reshaped(is_a_reshaped),
1975  _is_b_reshaped(is_b_reshaped),
1976  _reshape_b_only_on_first_run(reshape_b_only_on_first_run),
1977  _depth_output_gemm3d(depth_output_gemm3d),
1978  _reinterpret_input_as_3d(reinterpret_input_as_3d),
1979  _retain_internal_weights(retain_internal_weights),
1980  _gemmlowp_output_stage(gemmlowp_output_stage),
1981  _fp_mixed_precision(fp_mixed_precision),
1982  _broadcast_bias(broadcast_bias),
1983  _pretranpose_B(reshape_b_only_on_first_run),
1984  _activation_info(activation_info)
1985  {
1986  }
1987  /** Flag which specifies if the matrix A has been reshaped
1988  *
1989  * @return True if the matrix A has been reshaped
1990  */
1991  bool is_a_reshaped() const
1992  {
1993  return _is_a_reshaped;
1994  };
1995  /** Flag which specifies if the matrix B has been reshaped
1996  *
1997  * @return True if the matrix B has been reshaped
1998  */
1999  bool is_b_reshaped() const
2000  {
2001  return _is_b_reshaped;
2002  };
2003  /** Flag which specifies if the reshape of matrix B should executed only for the first
2004  *
2005  * @note This flag could be set to TRUE when GEMM is used to accelerate convolution layer
2006  *
2007  * @return True if the reshaped of matrix B happens only for the first run
2008  */
2010  {
2011  return _reshape_b_only_on_first_run;
2012  };
2013  /** Depth of the output when GEMM output is reinterpreted as 3D tensor
2014  *
2015  * @return the depth of the output tensor
2016  */
2018  {
2019  return _depth_output_gemm3d;
2020  };
2021  /** Flag which specifies if the input tensor has to be reinterpreted as 3D
2022  *
2023  * @return True if the input tensor has to be reinterpreted as 3D tensor
2024  */
2026  {
2027  return _reinterpret_input_as_3d;
2028  };
2029  /** Flag which specifies if the weights tensor has to be retained from previous run
2030  *
2031  * @return True if the weights tensor has to be retained
2032  */
2034  {
2035  return _retain_internal_weights;
2036  };
2037  /** GEMMLowp output stage
2038  *
2039  * @return the GEMMLowp output stage info
2040  */
2042  {
2043  return _gemmlowp_output_stage;
2044  };
2045  /** Sets GEMMLowp output stage
2046  *
2047  * @param[in] output_stage Output stage to set
2048  */
2050  {
2051  _gemmlowp_output_stage = output_stage;
2052  };
2053  /** Flag which specifies if a wider accumulator should be used.
2054  *
2055  * @return True if a wider accumulator has to be used
2056  */
2057  bool fp_mixed_precision() const
2058  {
2059  return _fp_mixed_precision;
2060  };
2061  /** Flag which specifies whether to broadcast the shape of the bias tensor.
2062  *
2063  * @return True if the shape of the bias tensor is to be broadcasted.
2064  */
2065  bool broadcast_bias() const
2066  {
2067  return _broadcast_bias;
2068  };
2069  /** Flag which specifies whether b should be pre-transposed if supported.
2070  *
2071  * @return True if b should be pre-transposed else false.
2072  */
2073  bool pretranpose_B() const
2074  {
2075  return _pretranpose_B;
2076  };
2077  /** Set pre-transpose b flag
2078  *
2079  * @param[in] flag Flag to set
2080  */
2081  void set_pretranpose_B(bool flag)
2082  {
2083  _pretranpose_B = flag;
2084  }
2085  /** Activation layer to apply after the matrix multiplication
2086  *
2087  * @return ActivationLayerInfo object
2088  */
2090  {
2091  return _activation_info;
2092  }
2093  /** Set activation layer info
2094  *
2095  * @param[in] activation_info ActivationLayerInfo object to set
2096  */
2098  {
2099  _activation_info = activation_info;
2100  }
2101 
2102 private:
2103  bool _is_a_reshaped;
2104  bool _is_b_reshaped;
2105  bool _reshape_b_only_on_first_run;
2106  int _depth_output_gemm3d;
2107  bool _reinterpret_input_as_3d;
2108  bool _retain_internal_weights;
2109  GEMMLowpOutputStageInfo _gemmlowp_output_stage;
2110  bool _fp_mixed_precision;
2111  bool _broadcast_bias;
2112  bool _pretranpose_B;
2113  ActivationLayerInfo _activation_info;
2114 };
2115 
2116 /** Winograd information */
2118 {
2119  /** Default constructor
2120  *
2121  * @param[in] output_tile_sz Width and height of the output tile
2122  * @param[in] kernel_sz Width and height of the kernel
2123  * @param[in] input_dims Width and height of the input tensor before the convolution is applied
2124  * @param[in] conv_info Convolution info (Pads, strides)
2125  * @param[in] data_layout Data layout to use for the output tensor once the convolution has been applied
2126  */
2129  {
2130  }
2131 
2132  Size2D output_tile_size{}; /**< Width and height of the output tile */
2133  Size2D kernel_size{}; /**< Width and height of the kernel*/
2134  Size2D input_dimensions{}; /**< Width and height of the input tensor before the convolution is applied */
2135  PadStrideInfo convolution_info{}; /**< Convolution info (Pads, strides,...) */
2136  DataLayout output_data_layout{ DataLayout::NCHW }; /**< Data layout to use for the output tensor once the convolution has been applied (NCHW or NHWC) */
2137 };
2138 
2139 /** IO formatting information class*/
2141 {
2142  /** Precision type used when printing floating point numbers */
2143  enum class PrecisionType
2144  {
2145  Default, /**< Default precision to the one that the current stream has */
2146  Custom, /**< Custom precision specified by the user using the precision parameter */
2147  Full /**< The maximum precision of the floating point representation */
2148  };
2149 
2150  /** Specifies the area to be printed, used by Tensor objects */
2151  enum class PrintRegion
2152  {
2153  ValidRegion, /**< Prints the valid region of the Tensor object */
2154  NoPadding, /**< Prints the Tensor object without the padding */
2155  Full /**< Print the tensor object including padding */
2156  };
2157 
2158  /** Construct a set of IO formatting information.
2159  *
2160  * @param[in] print_region Area to be printed. Used by Tensor objects. Default: ValidRegion.
2161  * @param[in] precision_type Precision type for floating point numbers. Default: stream default.
2162  * @param[in] precision Precision value for float point numbers. Default: 10.
2163  * @param[in] align_columns Whether to align columns when printed. Default: true.
2164  * @param[in] element_delim Delimeter between elements. Default: " ".
2165  * @param[in] row_delim Delimenter between rows. Default: "\n".
2166  */
2169  unsigned int precision = 10,
2170  bool align_columns = true,
2171  std::string element_delim = " ",
2172  std::string row_delim = "\n")
2179  {
2180  }
2181 
2182  /** Area to be printed by Tensor objects */
2184  /** Floating point precision type */
2186  /** Floating point precision */
2187  unsigned int precision;
2188  /** Element delimeter */
2189  std::string element_delim;
2190  /** Row delimeter */
2191  std::string row_delim;
2192  /** Align columns */
2194 };
2195 } // namespace arm_compute
2196 #endif /* ARM_COMPUTE_TYPES_H */
float scale_coeff() const
Return the scaling factor of the normalization function.
Definition: Types.h:1639
BorderMode
Methods available to handle borders.
Definition: Types.h:259
ValidRegion(const Coordinates &an_anchor, const TensorShape &a_shape, size_t num_dimensions)
Constructor for a valid region with specified number of dimensions.
Definition: Types.h:220
Rectangle type.
Definition: Types.h:407
PrecisionType precision_type
Floating point precision type.
Definition: Types.h:2185
void set_pretranpose_B(bool flag)
Set pre-transpose b flag.
Definition: Types.h:2081
Coordinate type.
Definition: Types.h:423
DeconvolutionMethod
Available DeconvolutionMethod.
Definition: Types.h:149
void set(size_t dimension, T value, bool increase_dim_unit=true)
Accessor to set the value of one of the dimensions.
Definition: Dimensions.h:76
ValidRegion & set(size_t dimension, int start, size_t size)
Accessor to set the value of anchor and shape for one of the dimensions.
Definition: Types.h:247
ValidRegion & operator=(const ValidRegion &)=default
Allow instances of this class to be copied.
GEMMLHSMatrixInfo(unsigned int m, unsigned int k, unsigned int v, bool trans, bool inter)
Definition: Types.h:1906
unsigned int top
top of the border
Definition: Types.h:375
A single plane of 32-bit macro pixel of U0, Y0, V0, Y1 byte.
ArithmeticOperation
Available element-wise operations.
Definition: Types.h:470
InterpolationPolicy
Interpolation method.
Definition: Types.h:392
int num_classes() const
Get num classes.
Definition: Types.h:953
int mult_interleave4x4_height() const
Multiplication factor for the height of the 4x4 interleaved block.
Definition: Types.h:1821
int32_t gemmlowp_multiplier
GEMMLowp output stage multiplier used for quantizing to QASYMM8.
Definition: Types.h:1891
Generate Proposals Information class.
Definition: Types.h:1280
Second channel (used by formats with unknown channel types).
DepthwiseConvolutionFunction
Available DepthwiseConvolutionFunction.
Definition: Types.h:142
Shape of a tensor.
Definition: TensorShape.h:39
float kappa() const
Get the kappa value.
Definition: Types.h:1613
Quantize using a fixed point multiplication.
uint32_t x
X coordinates.
Definition: Types.h:425
bool share_location() const
Get share location.
Definition: Types.h:958
float im_width() const
Get image width (NMS may suppress boxes whose center sits beyond the image width)
Definition: Types.h:625
FullyConnectedLayerInfo & set_weights_trained_layout(DataLayout layout)
Sets the weights trained data layout.
Definition: Types.h:1556
DetectionPostProcessLayerInfo(unsigned int max_detections, unsigned int max_classes_per_detection, float nms_score_threshold, float iou_threshold, unsigned int num_classes, std::array< float, 4 > scales_values, bool use_regular_nms=false, unsigned int detection_per_class=100, bool dequantize_scores=true)
Constructor.
Definition: Types.h:1051
float scale_value_x() const
Get x scale value.
Definition: Types.h:1106
float score_thresh() const
Get the score threshold.
Definition: Types.h:580
DataLayout output_data_layout
Data layout to use for the output tensor once the convolution has been applied (NCHW or NHWC)
Definition: Types.h:2136
DimensionRoundingType round() const
Get the rounding type.
Definition: Types.h:745
quantized, symmetric fixed-point 16-bit number
void set_activation_info(const ActivationLayerInfo &activation_info)
Set activation layer info.
Definition: Types.h:2097
BorderSize operator *(float scale)
Scale a copy of this border size.
Definition: Types.h:333
~ValidRegion()=default
Default destructor.
ROIPoolingLayerInfo(unsigned int pooled_width, unsigned int pooled_height, float spatial_scale, unsigned int sampling_ratio=0)
Constructor.
Definition: Types.h:1247
uint16_t x
Top-left x coordinate.
Definition: Types.h:520
TensorShape shape
Shape of the valid region.
Definition: Types.h:255
WinogradInfo(Size2D output_tile_sz, Size2D kernel_sz, Size2D input_dims, PadStrideInfo conv_info, DataLayout data_layout)
Default constructor.
Definition: Types.h:2127
float score
Confidence value for the detection window.
Definition: Types.h:525
bool is_in_map() const
Check if normalization is not cross map.
Definition: Types.h:1628
bool enabled() const
Check if initialised.
Definition: Types.h:1528
GEMMRHSMatrixInfo(unsigned int n, unsigned int k, unsigned int h, bool trans, bool inter, bool export_to_cl_img)
Definition: Types.h:1921
std::vector< PaddingInfo > PaddingList
List of padding information.
Definition: Types.h:434
ReductionOperation
Available reduction operations.
Definition: Types.h:457
Container for 2D border size.
Definition: Types.h:267
bool retain_internal_weights
Retain internal reshaped weights.
Definition: Types.h:1546
size_t values_per_roi() const
Definition: Types.h:1398
ActivationLayerInfo(ActivationFunction f, float a=0.0f, float b=0.0f)
Default Constructor.
Definition: Types.h:1508
std::map< int, std::vector< BBox > > LabelBBox
Definition: Types.h:892
unsigned int max_detections() const
Get max detections.
Definition: Types.h:1065
Cr/V/Value channel.
unsigned int v0
Number of vertical blocks of size (m0xk0) stored on the same output row.
Definition: Types.h:1912
Prints the Tensor object without the padding.
DataLayoutDimension
[DataLayout enum definition]
Definition: Types.h:123
BoxWithNonMaximaSuppressionLimit Information class.
Definition: Types.h:554
PoolingLayerInfo(PoolingType pool_type, DataLayout data_layout)
Constructor.
Definition: Types.h:1216
Winograd information.
Definition: Types.h:2117
uint32_t norm_size() const
Get the normalization size.
Definition: Types.h:1598
1 channel, 1 U8 per channel
NormType type() const
Get the normalization type.
Definition: Types.h:1593
int mult_transpose1xW_width() const
Multiplication factor for the width of the 1xW transposed block.
Definition: Types.h:1813
float a() const
Get the alpha value.
Definition: Types.h:1518
GEMM reshape information class.
Definition: Types.h:1759
PadStrideInfo convolution_info
Convolution info (Pads, strides,...)
Definition: Types.h:2135
2D Coordinates structure
Definition: types.h:28
std::vector< float > aspect_ratios() const
Get aspect ratios.
Definition: Types.h:872
PriorBoxLayerInfo(const std::vector< float > &min_sizes, const std::vector< float > &variances, float offset, bool flip=true, bool clip=false, const std::vector< float > &max_sizes={}, const std::vector< float > &aspect_ratios={}, const Coordinates2D &img_size=Coordinates2D{ 0, 0 }, const std::array< float, 2 > &steps={ { 0.f, 0.f } })
Constructor.
Definition: Types.h:795
FullyConnectedLayerInfo & set_transpose_weights(bool should_transpose_weights)
Sets the transpose weights flag.
Definition: Types.h:1567
GEMMLowpOutputStageInfo gemmlowp_output_stage() const
GEMMLowp output stage.
Definition: Types.h:2041
bool are_reshaped() const
Flag which specifies if the weights tensor has been reshaped.
Definition: Types.h:1717
half_float::half half
16-bit floating point type
Definition: Types.h:46
1 channel, 1 F32 per channel
Custom precision specified by the user using the precision parameter.
DimensionRoundingType
Dimension rounding type when down-scaling on CNNs.
Definition: Types.h:531
Normalization Layer Information class.
Definition: Types.h:1575
Unknown channel format.
Output values are defined by bilinear interpolation between the pixels.
unsigned int h0
Number of horizontal blocks of size (k0xn0) stored on the same output row.
Definition: Types.h:1927
unsigned int precision
Floating point precision.
Definition: Types.h:2187
bool is_cross_map() const
Check if normalization is cross map.
Definition: Types.h:1623
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
const DataLayout data_layout
Definition: Im2Col.cpp:151
Fully connected layer info.
Definition: Types.h:1541
bool fp_mixed_precision() const
Flag which specifies if a wider accumulator should be used.
Definition: Types.h:2057
BilinearInterpolation
Bilinear Interpolation method used by LKTracker.
Definition: Types.h:400
GEMM LHS (Left Hand Side) matrix information.
Definition: Types.h:1903
bool pretranpose_B() const
Flag which specifies whether b should be pre-transposed if supported.
Definition: Types.h:2073
A 2 plane YUV format of Luma (Y) and interleaved UV data at 4:2:0 sampling.
constexpr uint8_t CONSTANT_BORDER_VALUE
Constant value of the border pixels when using BorderMode::CONSTANT.
Definition: Types.h:109
PoolingLayerInfo()
Default Constructor.
Definition: Types.h:1145
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)
Constructor.
Definition: Types.h:1780
quantized, asymmetric fixed-point 16-bit number
1 channel, 1 U16 per channel
unsigned int bottom
bottom of the border
Definition: Types.h:377
int32_t gemmlowp_offset
GEMMLowp output stage offset used for quantizing to QASYMM8.
Definition: Types.h:1890
float eta() const
Get eta.
Definition: Types.h:983
int depth_output_gemm3d() const
Depth of the output when GEMM output is reinterpreted as 3D tensor.
Definition: Types.h:2017
PrintRegion print_region
Area to be printed by Tensor objects.
Definition: Types.h:2183
unsigned int pooled_width() const
Get the pooled width of the layer.
Definition: Types.h:1252
unsigned int pad_top() const
Get the top padding.
Definition: Types.h:734
Output values are defined to match the source pixel whose center is nearest to the sample position.
BorderSize & operator *=(float scale)
Scale this border size.
Definition: Types.h:317
int32_t gemmlowp_max_bound
GEMMLowp max value used to saturate down the output result before converting back to QASYMM8.
Definition: Types.h:1894
DetectionPostProcessLayerInfo()
Default Constructor.
Definition: Types.h:1027
bool retain_internal_weights() const
Flag which specifies if the weights tensor has to be retained from previous run.
Definition: Types.h:2033
DetectionOutputLayerCodeType
Available Detection Output code types.
Definition: Types.h:895
ConvolutionMethod
Available ConvolutionMethod.
Definition: Types.h:132
Activation Layer Information class.
Definition: Types.h:1478
GEMMLowpOutputStageType type
GEMMLowp output stage type.
Definition: Types.h:1889
float spatial_scale() const
Definition: Types.h:1392
A 2 plane YUV format of Luma (Y) and interleaved VU data at 4:2:0 sampling.
bool use_regular_nms() const
Get if use regular nms.
Definition: Types.h:1095
bool transpose
True if the (k0xn0) block has to be transposed before been stored.
Definition: Types.h:1928
bool interleave
True if the v0 (m0xk0) blocks have to be interleaved in the output row.
Definition: Types.h:1914
bool export_to_cl_image
True if the reshaped rhs has to be exported to cl_image.
Definition: Types.h:1930
int top_k() const
Get top K.
Definition: Types.h:998
constexpr BorderSize(unsigned int top_bottom, unsigned int left_right)
Border with same size for top/bottom and left/right.
Definition: Types.h:288
Copyright (c) 2017-2021 Arm Limited.
WeightsInfo()
Default constructor.
Definition: Types.h:1697
bool suppress_size() const
Get if NMS will suppress boxes based on their size/position.
Definition: Types.h:615
bool is_b_reshaped() const
Flag which specifies if the matrix B has been reshaped.
Definition: Types.h:1999
int32_t x
X coordinates.
Definition: Types.h:418
ActivationFunction
Available activation functions.
Definition: Types.h:1482
1 channel, 1 F16 per channel
Samples are taken at pixel center.
float iou_threshold() const
Get intersection over union threshold.
Definition: Types.h:1085
BoxNMSLimitInfo(float score_thresh=0.05f, float nms=0.3f, int detections=100, bool soft_nms_enabled=false, NMSType soft_nms_method=NMSType::LINEAR, 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)
Constructor.
Definition: Types.h:571
uint32_t z
Z coordinates.
Definition: Types.h:427
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, size_t values_per_roi=4)
Constructor.
Definition: Types.h:1295
NMSType
Available non maxima suppression types.
Definition: Types.h:546
bool is_quantized_per_channel
GEMMLowp quantized per-channel flag.
Definition: Types.h:1898
Convolution Layer Weights Information class.
Definition: Types.h:1693
std::vector< int32_t > gemmlowp_shifts
GEMMLowp output stage multiplier used for quantizing to QASYMM8.
Definition: Types.h:1896
DetectionOutputLayerInfo()
Default Constructor.
Definition: Types.h:908
1 channel, 1 S32 per channel
bool variance_encoded_in_target() const
Get if variance encoded in target.
Definition: Types.h:968
16-bit brain floating-point number
bool transpose
True if the (m0xk0) block has to be transposed before been stored.
Definition: Types.h:1913
signed 64-bit number
int n() const
Number of matrix B columns.
Definition: Types.h:1797
3 channels, 1 U8 per channel
unsigned int depth_multiplier
Multiplier to apply to input's depth to retrieve the output depth.
Definition: Types.h:1872
NormalizationLayerInfo(NormType type, uint32_t norm_size=5, float alpha=0.0001f, float beta=0.5f, float kappa=1.f, bool is_scaled=true)
Default Constructor.
Definition: Types.h:1588
FuseBatchNormalizationType
Available FuseBatchNormalizationType.
Definition: Types.h:156
unsigned int k0
Number of partial accumulations performed by the matrix multiplication.
Definition: Types.h:1926
IOFormatInfo(PrintRegion print_region=PrintRegion::ValidRegion, PrecisionType precision_type=PrecisionType::Default, unsigned int precision=10, bool align_columns=true, std::string element_delim=" ", std::string row_delim="\n")
Construct a set of IO formatting information.
Definition: Types.h:2167
int32_t y
Y coordinates.
Definition: Types.h:419
PoolingLayerInfo(PoolingType pool_type, Size2D pool_size, DataLayout data_layout, PadStrideInfo pad_stride_info=PadStrideInfo(), bool exclude_padding=false, bool fp_mixed_precision=false)
Constructor.
Definition: Types.h:1193
std::array< float, 2 > steps() const
Get the step coordinates.
Definition: Types.h:842
float nms() const
Get the NMS.
Definition: Types.h:585
float nms_threshold() const
Get nms threshold.
Definition: Types.h:978
ConvolutionInfo(const PadStrideInfo &pad_stride_info, unsigned int depth_multiplier, const ActivationLayerInfo &act_info, const Size2D &dilation)
Definition: Types.h:1867
Third channel (used by formats with unknown channel types).
bool padding_is_symmetric() const
Check whether the padding is symmetric.
Definition: Types.h:706
bool is_scaled() const
Get the is_scaled value.
Definition: Types.h:1618
1 channel, 1 U32 per channel
GEMM RHS (Right Hand Side) matrix information.
Definition: Types.h:1918
Normalization applied within the same map in 1D region.
Size2D output_tile_size
Width and height of the output tile.
Definition: Types.h:2132
Channel
Available channels.
Definition: Types.h:440
Format
Image colour formats.
Definition: Types.h:54
std::string row_delim
Row delimeter.
Definition: Types.h:2191
PaddingMode
Padding mode to use for PadLayer.
Definition: Types.h:163
Print the tensor object including padding.
IO formatting information class.
Definition: Types.h:2140
uint16_t width
Width of the detection window.
Definition: Types.h:522
PadStrideInfo pad_stride_info
Convolution info (Pads, strides,...)
Definition: Types.h:1871
unsigned int n0
Number of columns processed by the matrix multiplication.
Definition: Types.h:1925
ActivationLayerInfo act_info
Fused activation to apply after convolution.
Definition: Types.h:1873
quantized, asymmetric fixed-point 8-bit number unsigned
bool are_weights_reshaped
Reshape the weights tensor if false.
Definition: Types.h:1545
int start(unsigned int d) const
Return the start of the valid region for the given dimension d.
Definition: Types.h:228
Coordinates of an item.
Definition: Coordinates.h:37
float scale_value_h() const
Get h scale value.
Definition: Types.h:1112
std::pair< unsigned int, unsigned int > stride() const
Get the stride.
Definition: Types.h:698
float scale_value_w() const
Get w scale value.
Definition: Types.h:1118
Pooling Layer Information struct.
Definition: Types.h:1142
std::vector< int32_t > gemmlowp_multipliers
GEMMLowp output stage multiplier used for quantizing to QASYMM8.
Definition: Types.h:1895
Size2D dilation
Dilation, in elements, across x and y.
Definition: Types.h:1874
float nms_score_threshold() const
Get nms threshold.
Definition: Types.h:1080
float soft_nms_min_score_thres() const
Get soft nms min score threshold.
Definition: Types.h:610
BitwiseOperation
Available bitwise operations.
Definition: Types.h:496
WeightsInfo(bool are_reshaped, unsigned int kernel_width, unsigned int kernel_height, unsigned int num_kernels, bool retain_internal_weights=false)
Constructor.
Definition: Types.h:1709
std::array< float, 4 > BBox
Definition: Types.h:890
float gemmlowp_real_multiplier
GEMMLowp output stage real multiplier used for quantizing to QASYMM8.
Definition: Types.h:1897
bool dequantize_scores() const
Get dequantize_scores value.
Definition: Types.h:1124
GEMMLowp output stage info.
Definition: Types.h:1887
A 3 plane of 8 bit 4:4:4 sampled Y, U, V planes.
Samples are taken at pixel top left corner.
PriorBox layer info.
Definition: Types.h:767
float offset() const
Get the offset.
Definition: Types.h:852
Fourth channel (used by formats with unknown channel types).
DetectionOutputLayerCodeType code_type() const
Get detection output code type.
Definition: Types.h:963
unsigned int pad_right() const
Get the right padding.
Definition: Types.h:729
float beta() const
Get the beta value.
Definition: Types.h:1608
int k() const
Number of matrix A columns or matrix B rows.
Definition: Types.h:1805
Quantize using a floating point multiplication.
Padding and stride information class.
Definition: Types.h:650
ComparisonOperation
Supported comparison operations.
Definition: Types.h:171
PoolingLayerInfo(PoolingType pool_type, unsigned int pool_size, DataLayout data_layout, PadStrideInfo pad_stride_info=PadStrideInfo(), bool exclude_padding=false, bool fp_mixed_precision=false)
Constructor.
Definition: Types.h:1166
GEMMLowpOutputStageType
GEMMLowp output stage type.
Definition: Types.h:1878
Coordinates2D img_size() const
Get the image size coordinates.
Definition: Types.h:847
ActivationLayerInfo activation_info
Fused activation to apply after the matrix multiplication.
Definition: Types.h:1548
bool align_columns
Align columns.
Definition: Types.h:2193
unsigned int num_kernels() const
Return the number of convolution kernels.
Definition: Types.h:1725
bool reinterpret_input_as_3d() const
Flag which specifies if the input tensor has to be reinterpreted as 3D.
Definition: Types.h:2025
Bounding Box Transform information class.
Definition: Types.h:1411
unsigned int left
left of the border
Definition: Types.h:378
constexpr BorderSize(unsigned int size) noexcept
Border with equal size around the 2D plane.
Definition: Types.h:279
GEMMInfo() noexcept
Default constructor.
Definition: Types.h:1942
bool operator!=(const BorderSize &rhs)
Check non-equality with another BorderSize struct.
Definition: Types.h:358
PriorBoxLayerInfo()
Default Constructor.
Definition: Types.h:771
unsigned int right
right of the border
Definition: Types.h:376
Quantize using an integer multiplication.
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=false, float bbox_xform_clip=4.135166556742356f)
Constructor.
Definition: Types.h:1424
1 channel, 1 S16 per channel
bool broadcast_bias() const
Flag which specifies whether to broadcast the shape of the bias tensor.
Definition: Types.h:2065
uint16_t idx_class
Index of the class.
Definition: Types.h:524
int keep_top_k() const
Get the number of total bounding boxes to be kept per image.
Definition: Types.h:973
Output values are determined by averaging the source pixels whose areas fall under the area of the de...
quantized, symmetric fixed-point 8-bit number
unsigned int sampling_ratio() const
Get sampling ratio.
Definition: Types.h:1267
Num samples, channels, height, width.
PrecisionType
Precision type used when printing floating point numbers.
Definition: Types.h:2143
unsigned int max_classes_per_detection() const
Get max_classes per detection.
Definition: Types.h:1070
bool broadcast_bias() const
Flag which specifies whether to broadcast the shape of the bias tensor.
Definition: Types.h:1848
bool is_a_reshaped() const
Flag which specifies if the matrix A has been reshaped.
Definition: Types.h:1991
float scale_value_y() const
Get y scale value.
Definition: Types.h:1100
uint16_t height
Height of the detection window.
Definition: Types.h:523
PadStrideInfo(unsigned int stride_x, unsigned int stride_y, unsigned int pad_left, unsigned int pad_right, unsigned int pad_top, unsigned int pad_bottom, DimensionRoundingType round)
Constructor.
Definition: Types.h:682
Strides of an item in bytes.
Definition: Strides.h:37
quantized, symmetric per channel fixed-point 8-bit number
Convolution using Winograd.
A 3 plane of 8-bit 4:2:0 sampled Y, U, V planes.
float min_size() const
Get size suppression threshold.
Definition: Types.h:620
int32_t gemmlowp_shift
GEMMLowp output stage shift used for quantizing to uint8.
Definition: Types.h:1892
PadStrideInfo(unsigned int stride_x=1, unsigned int stride_y=1, unsigned int pad_x=0, unsigned int pad_y=0, DimensionRoundingType round=DimensionRoundingType::FLOOR)
Constructor.
Definition: Types.h:661
Detection Output layer info.
Definition: Types.h:904
4 channels, 1 U8 per channel
uint32_t y
Y coordinates.
Definition: Types.h:426
ValidRegion(const Coordinates &an_anchor, const TensorShape &a_shape)
Constructor for a valid region with default number of dimensions.
Definition: Types.h:207
PoolingType
Available pooling types.
Definition: Types.h:538
PadStrideInfo pad_stride_info
Definition: Types.h:1230
GEMMReshapeInfo()
Default constructor.
Definition: Types.h:1763
void set_gemmlowp_output_stage(GEMMLowpOutputStageInfo &output_stage)
Sets GEMMLowp output stage.
Definition: Types.h:2049
constexpr bool empty() const
Check if the entire border is zero.
Definition: Types.h:300
int32_t shrink_axis_mask() const
Definition: Types.h:1681
std::pair< uint32_t, uint32_t > PaddingInfo
Padding information as a pair of unsigned int start/end.
Definition: Types.h:431
Coordinate type.
Definition: Types.h:416
int end(unsigned int d) const
Return the end of the valid region for the given dimension d.
Definition: Types.h:234
unsigned int pooled_height() const
Get the pooled height of the layer.
Definition: Types.h:1257
int m() const
Number of matrix A rows.
Definition: Types.h:1789
Borders are left undefined.
ROI Pooling Layer Information class.
Definition: Types.h:1237
Pixels outside the image are assumed to have the same value as the closest image pixel.
Class for specifying the size of an image or rectangle.
Definition: Size2D.h:34
Detection window used for the object detection.
Definition: Types.h:518
DataLayout weights_trained_layout
Layout that the weights have been trained with.
Definition: Types.h:1543
unsigned int num_dimensions() const
Returns the effective dimensionality of the tensor.
Definition: Dimensions.h:143
std::vector< float > max_sizes() const
Get max sizes.
Definition: Types.h:867
ComputeAnchors information class.
Definition: Types.h:1361
uint16_t width
Width of the rectangle.
Definition: Types.h:411
Num samples, height, width, channels.
unsigned int detection_per_class() const
Get detection per class.
Definition: Types.h:1075
bool flip() const
Get the flip value.
Definition: Types.h:857
2 channel, 1 U8 per channel
uint16_t y
Top-left y coordinate.
Definition: Types.h:521
bool fp_mixed_precision
Use wider accumulators (32 bit instead of 16 for FP16) to improve accuracy.
Definition: Types.h:1547
float spatial_scale() const
Get the spatial scale.
Definition: Types.h:1262
uint16_t y
Top-left y coordinate.
Definition: Types.h:410
Detection Output layer info.
Definition: Types.h:1023
int depth_output_gemm3d() const
Depth (third dimension) of the output tensor to be used with the GEMM3D kernel.
Definition: Types.h:1832
constexpr bool uniform() const
Check if the border is the same size on all sides.
Definition: Types.h:306
bool interleave
True if the h0 (k0xn0) blocks have to be interleaved in the output row.
Definition: Types.h:1929
unsigned int num_classes() const
Get num classes.
Definition: Types.h:1090
Use box centers and size but flip x and y co-ordinates.
PrintRegion
Specifies the area to be printed, used by Tensor objects.
Definition: Types.h:2151
std::vector< float > variances() const
Get min variances.
Definition: Types.h:837
bool transpose_weights
Transpose weights if true.
Definition: Types.h:1544
Size2D kernel_size
Width and height of the kernel.
Definition: Types.h:2133
bool operator==(const BorderSize &rhs)
Check equality with another BorderSize struct.
Definition: Types.h:347
std::array< float, 4 > weights() const
Definition: Types.h:1432
bool reshape_b_only_on_first_run() const
Flag which specifies if the reshape of matrix B should executed only for the first.
Definition: Types.h:2009
constexpr BorderSize(unsigned int top, unsigned int right, unsigned int bottom, unsigned int left)
Border with different sizes.
Definition: Types.h:294
unsigned int k0
Number of partial accumulations performed by the matrix multiplication.
Definition: Types.h:1911
uint16_t x
Top-left x coordinate.
Definition: Types.h:409
float alpha() const
Get the alpha value.
Definition: Types.h:1603
GEMM information class.
Definition: Types.h:1938
unsigned int m0
Number of rows processed by the matrix multiplication.
Definition: Types.h:1910
std::pair< unsigned int, unsigned int > pad() const
Get the padding.
Definition: Types.h:716
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, float confidence_threshold=std::numeric_limits< float >::lowest(), bool variance_encoded_in_target=false, float eta=1)
Constructor.
Definition: Types.h:936
void set_num_dimensions(size_t num_dimensions)
Set number of dimensions.
Definition: Dimensions.h:149
ActivationFunction activation() const
Get the type of activation function.
Definition: Types.h:1513
float b() const
Get the beta value.
Definition: Types.h:1523
quantized, asymmetric fixed-point 8-bit number signed
Prints the valid region of the Tensor object.
64-bit floating-point number
Container for valid region of a window.
Definition: Types.h:182
constexpr BorderSize() noexcept
Empty border, i.e.
Definition: Types.h:270
int32_t gemmlowp_min_bound
GEMMLowp min value used to saturate down the output result before converting back to QASYMM8.
Definition: Types.h:1893
uint16_t height
Height of the rectangle.
Definition: Types.h:412
unsigned int pad_bottom() const
Get the bottom padding.
Definition: Types.h:739
A single plane of 32-bit macro pixel of Y0, U0, Y1, V0 bytes.
bool clip() const
Get the clip value.
Definition: Types.h:862
Default precision to the one that the current stream has.
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, GEMMLowpOutputStageInfo gemmlowp_output_stage=GEMMLowpOutputStageInfo(), bool fp_mixed_precision=false, bool broadcast_bias=false, const ActivationLayerInfo &activation_info=ActivationLayerInfo()) noexcept
Constructor.
Definition: Types.h:1971
unsigned 64-bit number
DataType output_data_type
Output tensor data type to use if the output is not initialized.
Definition: Types.h:1899
Size2D input_dimensions
Width and height of the input tensor before the convolution is applied.
Definition: Types.h:2134
DataType
Available data types.
Definition: Types.h:77
bool reinterpret_input_as_3d() const
Flag which specifies if the input tensor has to be reinterpreted as 3D.
Definition: Types.h:1840
The maximum precision of the floating point representation.
ActivationLayerInfo activation_info() const
Activation layer to apply after the matrix multiplication.
Definition: Types.h:2089
unsigned int pad_left() const
Get the left padding.
Definition: Types.h:724
ElementWiseUnary
Available element wise unary operations.
Definition: Types.h:483
DataLayout
[DataLayout enum definition]
Definition: Types.h:114
std::vector< uint32_t > Multiples
Information to produce a tiled version of a Tensor.
Definition: Types.h:437
NormType
The normalization type used for the normalization layer.
Definition: Types.h:505
signed 8-bit number
Normalization applied cross maps.
ConvertPolicy
Policy to handle overflow.
Definition: Types.h:385
NMSType soft_nms_method() const
Get soft NMS method.
Definition: Types.h:600
void limit(const BorderSize &limit)
Limit this border size.
Definition: Types.h:367
int background_label_id() const
Get background label ID.
Definition: Types.h:988
float im_height() const
Get image height (NMS may suppress boxes whose center sits beyond the image height)
Definition: Types.h:630
TensorShape & set(size_t dimension, size_t value, bool apply_dim_correction=true, bool increase_dim_unit=true)
Accessor to set the value of one of the dimensions.
Definition: TensorShape.h:79
Coordinates anchor
Anchor for the start of the valid region.
Definition: Types.h:254
ValidRegion()
Default constructor.
Definition: Types.h:185
float confidence_threshold() const
Get confidence threshold.
Definition: Types.h:993
Normalization applied within the same map in 2D region.
bool retain_internal_weights() const
Definition: Types.h:1737
StridedSliceLayerInfo(int32_t begin_mask=0, int32_t end_mask=0, int32_t shrink_axis_mask=0)
Default Constructor.
Definition: Types.h:1663
SamplingPolicy
Available Sampling Policies.
Definition: Types.h:102
float soft_nms_sigma() const
Get soft NMS sigma.
Definition: Types.h:605
std::pair< unsigned int, unsigned int > kernel_size() const
Return the width and height of the kernel.
Definition: Types.h:1733
int num_loc_classes() const
Get number of location classes.
Definition: Types.h:1003
bool soft_nms_enabled() const
Check if soft NMS is enabled.
Definition: Types.h:595
int detections_per_im() const
Get the number of detections.
Definition: Types.h:590
std::string element_delim
Element delimeter.
Definition: Types.h:2189
std::vector< float > min_sizes() const
Get min sizes.
Definition: Types.h:832
bool has_padding() const
Check whether this has any padding.
Definition: Types.h:751
ComputeAnchorsInfo(float feat_width, float feat_height, float spatial_scale, size_t values_per_roi=4)
Constructor.
Definition: Types.h:1371