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