blob: f52dd1259730ff791ddece4255f8ad97a3c36dc0 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
2 * Copyright (c) 2016, 2017 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
27#include "arm_compute/core/Coordinates.h"
28#include "arm_compute/core/TensorShape.h"
Georgios Pinitas583137c2017-08-31 18:12:42 +010029#include "support/Half.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010030
31#include <cstddef>
32#include <cstdint>
33#include <string>
34#include <utility>
35
36namespace arm_compute
37{
Georgios Pinitas583137c2017-08-31 18:12:42 +010038/** 16-bit floating point type */
39using half = half_float::half;
40
Anthony Barbier6ff3b192017-09-04 18:44:23 +010041/** Image colour formats */
42enum class Format
43{
44 UNKNOWN, /** Unknown image format */
45 U8, /** 1 channel, 1 U8 per channel */
46 S16, /** 1 channel, 1 S16 per channel */
47 U16, /** 1 channel, 1 U16 per channel */
48 S32, /** 1 channel, 1 S32 per channel */
49 U32, /** 1 channel, 1 U32 per channel */
50 F16, /** 1 channel, 1 F16 per channel */
51 F32, /** 1 channel, 1 F32 per channel */
52 UV88, /** 2 channel, 1 U8 per channel */
53 RGB888, /** 3 channels, 1 U8 per channel */
54 RGBA8888, /** 4 channels, 1 U8 per channel */
55 YUV444, /** A 3 plane of 8 bit 4:4:4 sampled Y, U, V planes */
56 YUYV422, /** A single plane of 32-bit macro pixel of Y0, U0, Y1, V0 bytes */
57 NV12, /** A 2 plane YUV format of Luma (Y) and interleaved UV data at 4:2:0 sampling */
58 NV21, /** A 2 plane YUV format of Luma (Y) and interleaved VU data at 4:2:0 sampling */
59 IYUV, /** A 3 plane of 8-bit 4:2:0 sampled Y, U, V planes */
60 UYVY422 /** A single plane of 32-bit macro pixel of U0, Y0, V0, Y1 byte */
61};
62
63/** Available data types */
64enum class DataType
65{
66 UNKNOWN,
67 U8,
68 S8,
69 QS8,
70 U16,
71 S16,
72 QS16,
73 U32,
74 S32,
Pablo Tellof87cc7f2017-07-26 10:28:40 +010075 QS32,
Anthony Barbier6ff3b192017-09-04 18:44:23 +010076 U64,
77 S64,
78 F16,
79 F32,
80 F64,
81 SIZET
82};
83
84/** Constant value of the border pixels when using BorderMode::CONSTANT */
85constexpr uint8_t CONSTANT_BORDER_VALUE = 199;
86
87/* Constant value used to indicate a half-scale pyramid */
88constexpr float SCALE_PYRAMID_HALF = 0.5f;
89
90/* Constant value used to indicate a ORB scaled pyramid */
91constexpr float SCALE_PYRAMID_ORB = 8.408964152537146130583778358414e-01;
92
93struct ValidRegion
94{
95 ValidRegion()
96 : anchor{}, shape{}
97 {
98 }
99
100 ValidRegion(const ValidRegion &) = default;
101 ValidRegion(ValidRegion &&) = default;
102 ValidRegion &operator=(const ValidRegion &) = default;
103 ValidRegion &operator=(ValidRegion &&) = default;
104 ~ValidRegion() = default;
105
106 ValidRegion(Coordinates anchor, TensorShape shape)
107 : anchor{ anchor }, shape{ shape }
108 {
109 }
110
111 /** Return the start of the valid region for the given dimension @p d */
112 int start(unsigned int d) const
113 {
114 return anchor[d];
115 }
116
117 /** Return the end of the valid region for the given dimension @p d */
118 int end(unsigned int d) const
119 {
120 return anchor[d] + shape[d];
121 }
122
123 Coordinates anchor;
124 TensorShape shape;
125};
126
127/** Methods available to handle borders */
128enum class BorderMode
129{
130 UNDEFINED, /**< Borders are left undefined */
131 CONSTANT, /**< Pixels outside the image are assumed to have a constant value */
132 REPLICATE /**< Pixels outside the image are assumed to have the same value as the closest image pixel */
133};
134
135/** Container for 2D border size */
136struct BorderSize
137{
138 /** Empty border, i.e. no border */
139 constexpr BorderSize()
140 : top{ 0 }, right{ 0 }, bottom{ 0 }, left{ 0 }
141 {
142 }
143
144 /** Border with equal size around the 2D plane */
Moritz Pflanzer7655a672017-09-23 11:57:33 +0100145 explicit constexpr BorderSize(unsigned int size)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100146 : top{ size }, right{ size }, bottom{ size }, left{ size }
147 {
148 }
149
150 /** Border with same size for top/bottom and left/right */
151 constexpr BorderSize(unsigned int top_bottom, unsigned int left_right)
152 : top{ top_bottom }, right{ left_right }, bottom{ top_bottom }, left{ left_right }
153 {
154 }
155
156 /** Border with different sizes */
157 constexpr BorderSize(unsigned int top, unsigned int right, unsigned int bottom, unsigned int left)
158 : top{ top }, right{ right }, bottom{ bottom }, left{ left }
159 {
160 }
161
162 /** Check if the entire border is zero */
163 constexpr bool empty() const
164 {
165 return top == 0 && right == 0 && bottom == 0 && left == 0;
166 }
167
168 /** Check if the border is the same size on all sides */
169 constexpr bool uniform() const
170 {
171 return top == right && top == bottom && top == left;
172 }
173
174 BorderSize &operator*=(float scale)
175 {
176 top *= scale;
177 right *= scale;
178 bottom *= scale;
179 left *= scale;
180
181 return *this;
182 }
183
184 BorderSize operator*(float scale)
185 {
186 BorderSize size = *this;
187 size *= scale;
188
189 return size;
190 }
191
192 void limit(const BorderSize &limit)
193 {
194 top = std::min(top, limit.top);
195 right = std::min(right, limit.right);
196 bottom = std::min(bottom, limit.bottom);
197 left = std::min(left, limit.left);
198 }
199
200 unsigned int top;
201 unsigned int right;
202 unsigned int bottom;
203 unsigned int left;
204};
205
206using PaddingSize = BorderSize;
207
208/** Policy to handle overflow */
209enum class ConvertPolicy
210{
211 WRAP, /**< Wrap around */
212 SATURATE /**< Saturate */
213};
214
215/** Interpolation method */
216enum class InterpolationPolicy
217{
218 NEAREST_NEIGHBOR, /**< Output values are defined to match the source pixel whose center is nearest to the sample position */
219 BILINEAR, /**< Output values are defined by bilinear interpolation between the pixels */
220 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 */
221};
222
223/** Bilinear Interpolation method used by LKTracker */
224enum class BilinearInterpolation
225{
226 BILINEAR_OLD_NEW,
227 BILINEAR_SCHARR
228};
229
230/** Threshold mode */
231enum class ThresholdType
232{
233 BINARY, /**< Threshold with one value */
234 RANGE /**< Threshold with two values*/
235};
236
237/** Rounding method */
238enum class RoundingPolicy
239{
240 TO_ZERO, /**< Truncates the least significand values that are lost in operations. */
241 TO_NEAREST_UP, /**< Rounds to nearest value; half rounds up */
242 TO_NEAREST_EVEN /**< Rounds to nearest value; half rounds to nearest even */
243};
244
245/** Termination criteria */
246enum class Termination
247{
248 TERM_CRITERIA_EPSILON,
249 TERM_CRITERIA_ITERATIONS,
250 TERM_CRITERIA_BOTH
251};
252
253/** Magnitude calculation type. */
254enum class MagnitudeType
255{
256 L1NORM, /**< L1 normalization type */
257 L2NORM /**< L2 normalization type */
258};
259
260/** Phase calculation type.
261 *
262 * @note When PhaseType == SIGNED, each angle is mapped to the range 0 to 255 inclusive otherwise angles between 0 and 180
263 */
264enum class PhaseType
265{
266 SIGNED, /**< Angle range: [0, 360] */
267 UNSIGNED /**< Angle range: [0, 180] */
268};
269
270/** Keypoint type */
271struct KeyPoint
272{
273 int32_t x{ 0 }; /**< X coordinates */
274 int32_t y{ 0 }; /**< Y coordinates */
275 float strength{ 0.f }; /**< Strength of the point */
276 float scale{ 0.f }; /**< Scale initialized to 0 by the corner detector */
277 float orientation{ 0.f }; /**< Orientation initialized to 0 by the corner detector */
278 int32_t tracking_status{ 0 }; /**< Status initialized to 1 by the corner detector, set to 0 when the point is lost */
279 float error{ 0.f }; /**< Tracking error initialized to 0 by the corner detector */
280};
281
282using InternalKeypoint = std::tuple<float, float, float>; /* x,y,strength */
283
284/** Rectangle type */
285struct Rectangle
286{
287 uint16_t x; /**< Top-left x coordinate */
288 uint16_t y; /**< Top-left y coordinate */
289 uint16_t width; /**< Width of the rectangle */
290 uint16_t height; /**< Height of the rectangle */
291};
292
293/** Coordinate type */
294struct Coordinates2D
295{
296 int32_t x; /**< X coordinates */
297 int32_t y; /**< Y coordinates */
298};
299
300/** Coordinate type */
301struct Coordinates3D
302{
303 uint32_t x; /**< X coordinates */
304 uint32_t y; /**< Y coordinates */
305 uint32_t z; /**< Z coordinates */
306};
307
Georgios Pinitas7b7858d2017-06-21 16:44:24 +0100308/** Region of interest */
309struct ROI
310{
311 Rectangle rect; /**< Rectangle specifying the region of interest */
312 uint16_t batch_idx; /**< The batch index of the region of interest */
313};
314
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100315/** Available channels */
316enum class Channel
317{
318 UNKNOWN, /** Unknown channel format */
319 C0, /**< First channel (used by formats with unknown channel types). */
320 C1, /**< Second channel (used by formats with unknown channel types). */
321 C2, /**< Third channel (used by formats with unknown channel types). */
322 C3, /**< Fourth channel (used by formats with unknown channel types). */
323 R, /**< Red channel. */
324 G, /**< Green channel. */
325 B, /**< Blue channel. */
326 A, /**< Alpha channel. */
327 Y, /**< Luma channel. */
328 U, /**< Cb/U channel. */
329 V /**< Cr/V/Value channel. */
330};
331
332/** Available matrix patterns */
333enum class MatrixPattern
334{
335 BOX, /**< Box pattern matrix. */
336 CROSS, /**< Cross pattern matrix. */
337 DISK, /**< Disk pattern matrix. */
338 OTHER /**< Any other matrix pattern. */
339};
340
341/** Available non linear functions. */
342enum class NonLinearFilterFunction : unsigned
343{
344 MEDIAN = 0, /**< Non linear median filter. */
345 MIN = 1, /**< Non linear erode. */
346 MAX = 2, /**< Non linear dilate. */
347};
348
Georgios Pinitasd9769582017-08-03 10:19:40 +0100349/** Available reduction operations */
350enum class ReductionOperation
351{
352 SUM_SQUARE, /**< Sum of squares */
Michalis Spyrou04f089c2017-08-08 17:42:38 +0100353 SUM, /**< Sum */
Georgios Pinitasd9769582017-08-03 10:19:40 +0100354};
355
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100356/** The normalization type used for the normalization layer */
357enum class NormType
358{
359 IN_MAP_1D, /**< Normalization applied within the same map in 1D region */
360 IN_MAP_2D, /**< Normalization applied within the same map in 2D region */
361 CROSS_MAP /**< Normalization applied cross maps */
362};
363
364/** Normalization type for Histogram of Oriented Gradients (HOG) */
365enum class HOGNormType
366{
367 L2_NORM = 1, /**< L2-norm */
368 L2HYS_NORM = 2, /**< L2-norm followed by clipping */
369 L1_NORM = 3 /**< L1 norm */
370};
371
372/** Detection window used for the object detection. The detection window keeps the following information:
373 *
374 * -# Geometry of the rectangular window (x/y of top-left corner and width/height)
375 * -# Index of the class used for evaluating which class the detection window belongs to
376 * -# Confidence value (score) obtained with the classifier
377 */
378struct DetectionWindow
379{
380 uint16_t x{ 0 }; /**< Top-left x coordinate */
381 uint16_t y{ 0 }; /**< Top-left y coordinate */
382 uint16_t width{ 0 }; /**< Width of the detection window */
383 uint16_t height{ 0 }; /**< Height of the detection window */
384 uint16_t idx_class{ 0 }; /**< Index of the class */
385 float score{ 0.f }; /**< Confidence value for the detection window */
386};
387
388/** Dimension rounding type when down-scaling on CNNs
389 * @note Used in pooling and convolution layer
390 */
391enum class DimensionRoundingType
392{
393 FLOOR, /**< Floor rounding */
394 CEIL /**< Ceil rounding */
395};
396
397/** Available pooling types */
398enum class PoolingType
399{
400 MAX, /**< Max Pooling */
Georgios Pinitascdf51452017-08-31 14:21:36 +0100401 AVG, /**< Average Pooling */
402 L2 /**< L2 Pooling */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100403};
404
405/** Padding and stride information class */
406class PadStrideInfo
407{
408public:
409 /** Constructor
410 *
411 * @param[in] stride_x (Optional) Stride, in elements, across x. Defaults to 1.
412 * @param[in] stride_y (Optional) Stride, in elements, across y. Defaults to 1.
413 * @param[in] pad_x (Optional) Padding, in elements, across x. Defaults to 0.
414 * @param[in] pad_y (Optional) Padding, in elements, across y. Defaults to 0.
415 * @param[in] round (Optional) Dimensions rounding. Defaults to @ref FLOOR.
416 */
417 PadStrideInfo(unsigned int stride_x = 1, unsigned int stride_y = 1,
418 unsigned int pad_x = 0, unsigned int pad_y = 0,
419 DimensionRoundingType round = DimensionRoundingType::FLOOR)
420 : _stride(std::make_pair(stride_x, stride_y)),
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100421 _pad_left(pad_x),
422 _pad_top(pad_y),
423 _pad_right(pad_x),
424 _pad_bottom(pad_y),
425 _round_type(round)
426 {
427 }
428 /** Constructor
429 *
430 * @param[in] stride_x Stride, in elements, across x.
431 * @param[in] stride_y Stride, in elements, across y.
432 * @param[in] pad_left Padding across x on the left, in elements.
433 * @param[in] pad_top Padding across y on the top, in elements.
434 * @param[in] pad_right Padding across x on the right, in elements.
435 * @param[in] pad_bottom Padding across y on the bottom, in elements.
436 * @param[in] round Dimensions rounding.
437 */
438 PadStrideInfo(unsigned int stride_x, unsigned int stride_y,
439 unsigned int pad_left, unsigned int pad_right,
440 unsigned int pad_top, unsigned int pad_bottom,
441 DimensionRoundingType round)
442 : _stride(std::make_pair(stride_x, stride_y)),
443 _pad_left(pad_left),
444 _pad_top(pad_top),
445 _pad_right(pad_right),
446 _pad_bottom(pad_bottom),
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100447 _round_type(round)
448 {
449 }
450 std::pair<unsigned int, unsigned int> stride() const
451 {
452 return _stride;
453 }
454 std::pair<unsigned int, unsigned int> pad() const
455 {
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100456 //this accessor should be used only when padding is symmetric
457 ARM_COMPUTE_ERROR_ON(_pad_left != _pad_right || _pad_top != _pad_bottom);
458 return std::make_pair(_pad_left, _pad_top);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100459 }
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100460
461 unsigned int pad_left() const
462 {
463 return _pad_left;
464 }
465 unsigned int pad_right() const
466 {
467 return _pad_right;
468 }
469 unsigned int pad_top() const
470 {
471 return _pad_top;
472 }
473 unsigned int pad_bottom() const
474 {
475 return _pad_bottom;
476 }
477
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100478 DimensionRoundingType round() const
479 {
480 return _round_type;
481 }
482
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100483 bool has_padding() const
484 {
485 return (_pad_left != 0 || _pad_top != 0 || _pad_right != 0 || _pad_bottom != 0);
486 }
487
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100488private:
489 std::pair<unsigned int, unsigned int> _stride;
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100490 unsigned int _pad_left;
491 unsigned int _pad_top;
492 unsigned int _pad_right;
493 unsigned int _pad_bottom;
494
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100495 DimensionRoundingType _round_type;
496};
497
498/** Pooling Layer Information class */
499class PoolingLayerInfo
500{
501public:
502 /** Default Constructor
503 *
504 * @param[in] pool_type Pooling type @ref PoolingType. Defaults to @ref PoolingType::MAX
505 * @param[in] pool_size (Optional) Pooling size, in elements, across x and y. Defaults to 2.
506 * @param[in] pad_stride_info (Optional) Padding and stride information @ref PadStrideInfo
507 */
508 PoolingLayerInfo(PoolingType pool_type = PoolingType::MAX, unsigned int pool_size = 2, PadStrideInfo pad_stride_info = PadStrideInfo())
509 : _pool_type(pool_type), _pool_size(pool_size), _pad_stride_info(pad_stride_info)
510 {
511 }
512 PoolingType pool_type() const
513 {
514 return _pool_type;
515 }
516 unsigned int pool_size() const
517 {
518 return _pool_size;
519 }
520 PadStrideInfo pad_stride_info() const
521 {
522 return _pad_stride_info;
523 }
524
525private:
526 PoolingType _pool_type;
527 unsigned int _pool_size;
528 PadStrideInfo _pad_stride_info;
529};
530
Georgios Pinitas7b7858d2017-06-21 16:44:24 +0100531/** ROI Pooling Layer Information class */
532class ROIPoolingLayerInfo
533{
534public:
535 /** Default Constructor
536 *
537 * @param[in] pooled_width Pooled width of the layer.
538 * @param[in] pooled_height Pooled height of the layer.
539 * @param[in] spatial_scale Spatial scale to be applied to the ROI coordinates and dimensions.
540 */
541 ROIPoolingLayerInfo(unsigned int pooled_width, unsigned int pooled_height, float spatial_scale)
542 : _pooled_width(pooled_width), _pooled_height(pooled_height), _spatial_scale(spatial_scale)
543 {
544 }
545 unsigned int pooled_width() const
546 {
547 return _pooled_width;
548 }
549 unsigned int pooled_height() const
550 {
551 return _pooled_height;
552 }
553 float spatial_scale() const
554 {
555 return _spatial_scale;
556 }
557
558private:
559 unsigned int _pooled_width;
560 unsigned int _pooled_height;
561 float _spatial_scale;
562};
563
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100564/** Activation Layer Information class */
565class ActivationLayerInfo
566{
567public:
568 /** Available activation functions */
569 enum class ActivationFunction
570 {
Georgios Pinitas64ebe5b2017-09-01 17:44:24 +0100571 LOGISTIC, /**< Logistic ( \f$ f(x) = \frac{1}{1 + e^{-x}} \f$ ) */
572 TANH, /**< Hyperbolic tangent ( \f$ f(x) = a \cdot tanh(b \cdot x) \f$ ) */
573 RELU, /**< Rectifier ( \f$ f(x) = max(0,x) \f$ ) */
574 BOUNDED_RELU, /**< Upper Bounded Rectifier ( \f$ f(x) = min(a, max(0,x)) \f$ ) */
575 LU_BOUNDED_RELU, /**< Lower and Upper Bounded Rectifier ( \f$ f(x) = min(a, max(b,x)) \f$ ) */
576 LEAKY_RELU, /**< Leaky Rectifier ( \f$ f(x)= log(1+e^x) \f$ ) */
577 SOFT_RELU, /**< Soft Rectifier ( \f$ f(x)= log(1+e^x) \f$ ) */
578 ABS, /**< Absolute ( \f$ f(x)= |x| \f$ ) */
579 SQUARE, /**< Square ( \f$ f(x)= x^2 \f$ )*/
580 SQRT, /**< Square root ( \f$ f(x) = \sqrt{x} \f$ )*/
581 LINEAR /**< Linear ( \f$ f(x)= ax + b \f$ ) */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100582 };
583
584 /** Default Constructor
585 *
586 * @param[in] f The activation function to use.
587 * @param[in] a (Optional) The alpha parameter used by some activation functions
Georgios Pinitas64ebe5b2017-09-01 17:44:24 +0100588 * (@ref ActivationFunction::BOUNDED_RELU, @ref ActivationFunction::LU_BOUNDED_RELU, @ref ActivationFunction::LINEAR, @ref ActivationFunction::TANH).
589 * @param[in] b (Optional) The beta parameter used by some activation functions (@ref ActivationFunction::LINEAR, @ref ActivationFunction::LU_BOUNDED_RELU, @ref ActivationFunction::TANH).
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100590 */
591 ActivationLayerInfo(ActivationFunction f, float a = 0.0f, float b = 0.0f)
592 : _act(f), _a(a), _b(b)
593 {
594 }
595 ActivationFunction activation() const
596 {
597 return _act;
598 }
599 float a() const
600 {
601 return _a;
602 }
603 float b() const
604 {
605 return _b;
606 }
607
608private:
609 ActivationFunction _act;
610 float _a;
611 float _b;
612};
613
614/** Normalization Layer Information class */
615class NormalizationLayerInfo
616{
617public:
618 /** Default Constructor
619 *
620 * @param[in] type The normalization type. Can be @ref NormType::IN_MAP_1D, @ref NormType::IN_MAP_2D or @ref NORM_TYPE::CROSS_MAP
621 * @param[in] norm_size The normalization size is the number of elements to normalize across. Defaults to 5.
622 * @param[in] alpha Alpha parameter used by normalization equation. Defaults to 0.0001.
623 * @param[in] beta Beta parameter used by normalization equation. Defaults to 0.5.
624 * @param[in] kappa Kappa parameter used by [Krichevksy 2012] Across Channel Local Brightness Normalization equation.
625 */
626 NormalizationLayerInfo(NormType type, uint32_t norm_size = 5, float alpha = 0.0001f, float beta = 0.5f, float kappa = 1.f)
627 : _type(type), _norm_size(norm_size), _alpha(alpha), _beta(beta), _kappa(kappa)
628 {
629 }
630 NormType type() const
631 {
632 return _type;
633 }
634 uint32_t norm_size() const
635 {
636 return _norm_size;
637 }
638 float alpha() const
639 {
640 return _alpha;
641 }
642 float beta() const
643 {
644 return _beta;
645 }
646 float kappa() const
647 {
648 return _kappa;
649 }
650 /** Return the scaling factor of the normalization function. If kappa is not
651 * 1 then [Krichevksy 2012] normalization scaling is specified. Scaling
652 * factor takes into account the total number of elements used for the
653 * normalization, so in case of 2 dimensions this is _norm_size^2.
654 *
655 * @return The normalization scaling factor.
656 */
657 float scale_coeff() const
658 {
659 const uint32_t size = (_type == NormType::IN_MAP_2D) ? _norm_size * _norm_size : _norm_size;
660 return (_kappa == 1.f) ? (_alpha / size) : _alpha;
661 }
662
663private:
664 NormType _type;
665 uint32_t _norm_size;
666 float _alpha;
667 float _beta;
668 float _kappa;
669};
670
Gian Marco Iodice559d7712017-08-08 08:38:09 +0100671/** Convolution Layer Weights Information class. This class stores the necessary information to compute convolution layer when the weights are already reshaped */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100672class WeightsInfo
673{
674public:
Gian Marco Iodice4e288692017-06-27 11:41:59 +0100675 /** Default constructor */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100676 WeightsInfo()
Gian Marco Iodice559d7712017-08-08 08:38:09 +0100677 : _are_reshaped(false), _kernel_width(0), _kernel_height(0), _num_kernels(0)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100678 {
679 }
680 /** Constructor
681 *
Gian Marco Iodice4e288692017-06-27 11:41:59 +0100682 * @param[in] are_reshaped True if the weights have been reshaped
683 * @param[in] kernel_width Kernel width.
684 * @param[in] kernel_height Kernel height.
Gian Marco Iodice559d7712017-08-08 08:38:09 +0100685 * @param[in] num_kernels Number of convolution kernels.
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100686 */
Gian Marco Iodice559d7712017-08-08 08:38:09 +0100687 WeightsInfo(bool are_reshaped, unsigned int kernel_width, unsigned int kernel_height, unsigned int num_kernels)
688 : _are_reshaped(are_reshaped), _kernel_width(kernel_width), _kernel_height(kernel_height), _num_kernels(num_kernels)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100689 {
690 }
Gian Marco Iodice4e288692017-06-27 11:41:59 +0100691 /** Flag which specifies if the weights tensor has been reshaped.
692 *
693 * @return True if the weights tensors has been reshaped
694 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100695 bool are_reshaped() const
696 {
697 return _are_reshaped;
698 };
Gian Marco Iodice559d7712017-08-08 08:38:09 +0100699 /** Return the number of convolution kernels
700 *
701 * @return The number of convolution kernels
702 */
703 unsigned int num_kernels() const
704 {
705 return _num_kernels;
706 };
Gian Marco Iodice4e288692017-06-27 11:41:59 +0100707 /** Return the width and height of the kernel
708 *
709 * @return The width and height of the kernel
710 */
711 std::pair<unsigned int, unsigned int> kernel_size() const
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100712 {
Gian Marco Iodice4e288692017-06-27 11:41:59 +0100713 return std::make_pair(_kernel_width, _kernel_height);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100714 }
715
716private:
717 const bool _are_reshaped;
Gian Marco Iodice4e288692017-06-27 11:41:59 +0100718 const unsigned int _kernel_width;
719 const unsigned int _kernel_height;
Gian Marco Iodice559d7712017-08-08 08:38:09 +0100720 const unsigned int _num_kernels;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100721};
722
723/** IO formatting information class*/
724struct IOFormatInfo
725{
726 /** Precision type used when printing floating point numbers */
727 enum class PrecisionType
728 {
729 Default, /**< Default precision to the one that the current stream has */
730 Custom, /**< Custom precision specified by the user using the precision parameter */
731 Full /**< The maximum precision of the floating point representation */
732 };
733
734 /** Specifies the area to be printed, used by Tensor objects */
735 enum class PrintRegion
736 {
737 ValidRegion, /**< Prints the valid region of the Tensor object */
738 NoPadding, /**< Prints the Tensor object without the padding */
739 Full /**< Print the tensor object including padding */
740 };
741
742 IOFormatInfo(PrintRegion print_region = PrintRegion::ValidRegion,
743 PrecisionType precision_type = PrecisionType::Default,
744 unsigned int precision = 10,
745 bool align_columns = true,
746 std::string element_delim = " ",
747 std::string row_delim = "\n")
748 : print_region(print_region),
749 precision_type(precision_type),
750 precision(precision),
751 element_delim(element_delim),
752 row_delim(row_delim),
753 align_columns(align_columns)
754 {
755 }
756
757 PrintRegion print_region;
758 PrecisionType precision_type;
759 unsigned int precision;
760 std::string element_delim;
761 std::string row_delim;
762 bool align_columns;
763};
764}
765#endif /* __ARM_COMPUTE_TYPES_H__ */