blob: e567bac860a36488042ea49571b963c8d89a8e3e [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,
Michel Iwaniec00633802017-10-12 14:14:15 +010070 QASYMM8,
Anthony Barbier6ff3b192017-09-04 18:44:23 +010071 U16,
72 S16,
73 QS16,
74 U32,
75 S32,
Pablo Tellof87cc7f2017-07-26 10:28:40 +010076 QS32,
Anthony Barbier6ff3b192017-09-04 18:44:23 +010077 U64,
78 S64,
79 F16,
80 F32,
81 F64,
82 SIZET
83};
84
85/** Constant value of the border pixels when using BorderMode::CONSTANT */
86constexpr uint8_t CONSTANT_BORDER_VALUE = 199;
87
88/* Constant value used to indicate a half-scale pyramid */
89constexpr float SCALE_PYRAMID_HALF = 0.5f;
90
91/* Constant value used to indicate a ORB scaled pyramid */
92constexpr float SCALE_PYRAMID_ORB = 8.408964152537146130583778358414e-01;
93
Michel Iwaniec00633802017-10-12 14:14:15 +010094/** Quantization settings (used for QASYMM8 data type) */
95struct QuantizationInfo
96{
97 QuantizationInfo()
98 : scale(0.0f), offset(0)
99 {
100 }
101
102 QuantizationInfo(float scale, int offset)
103 : scale(scale), offset(offset)
104 {
105 }
106
107 float scale; /**< scale */
108 int offset; /**< offset */
109
110 /** Quantizes a value using the scale/offset in this QuantizationInfo */
111 uint8_t quantize(float value) const
112 {
113 ARM_COMPUTE_ERROR_ON_MSG(scale == 0, "QuantizationInfo::quantize: scale == 0");
114 int quantized = static_cast<int>(value / scale + offset);
115 quantized = std::max(0, std::min(quantized, 255));
116 return quantized;
117 }
118
119 /** Dequantizes a value using the scale/offset in this QuantizationInfo */
120 float dequantize(uint8_t value) const
121 {
122 ARM_COMPUTE_ERROR_ON_MSG(scale == 0, "QuantizationInfo::dequantize: scale == 0");
123 float dequantized = (value - offset) * scale;
124 return dequantized;
125 }
126
127 /** Indicates whether this QuantizationInfo has valid settings or not */
128 bool empty() const
129 {
130 return scale == 0;
131 }
132};
133
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100134struct ValidRegion
135{
136 ValidRegion()
137 : anchor{}, shape{}
138 {
139 }
140
141 ValidRegion(const ValidRegion &) = default;
142 ValidRegion(ValidRegion &&) = default;
143 ValidRegion &operator=(const ValidRegion &) = default;
144 ValidRegion &operator=(ValidRegion &&) = default;
145 ~ValidRegion() = default;
146
147 ValidRegion(Coordinates anchor, TensorShape shape)
148 : anchor{ anchor }, shape{ shape }
149 {
150 }
151
152 /** Return the start of the valid region for the given dimension @p d */
153 int start(unsigned int d) const
154 {
155 return anchor[d];
156 }
157
158 /** Return the end of the valid region for the given dimension @p d */
159 int end(unsigned int d) const
160 {
161 return anchor[d] + shape[d];
162 }
163
164 Coordinates anchor;
165 TensorShape shape;
166};
167
168/** Methods available to handle borders */
169enum class BorderMode
170{
171 UNDEFINED, /**< Borders are left undefined */
172 CONSTANT, /**< Pixels outside the image are assumed to have a constant value */
173 REPLICATE /**< Pixels outside the image are assumed to have the same value as the closest image pixel */
174};
175
176/** Container for 2D border size */
177struct BorderSize
178{
179 /** Empty border, i.e. no border */
180 constexpr BorderSize()
181 : top{ 0 }, right{ 0 }, bottom{ 0 }, left{ 0 }
182 {
183 }
184
185 /** Border with equal size around the 2D plane */
Moritz Pflanzer7655a672017-09-23 11:57:33 +0100186 explicit constexpr BorderSize(unsigned int size)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100187 : top{ size }, right{ size }, bottom{ size }, left{ size }
188 {
189 }
190
191 /** Border with same size for top/bottom and left/right */
192 constexpr BorderSize(unsigned int top_bottom, unsigned int left_right)
193 : top{ top_bottom }, right{ left_right }, bottom{ top_bottom }, left{ left_right }
194 {
195 }
196
197 /** Border with different sizes */
198 constexpr BorderSize(unsigned int top, unsigned int right, unsigned int bottom, unsigned int left)
199 : top{ top }, right{ right }, bottom{ bottom }, left{ left }
200 {
201 }
202
203 /** Check if the entire border is zero */
204 constexpr bool empty() const
205 {
206 return top == 0 && right == 0 && bottom == 0 && left == 0;
207 }
208
209 /** Check if the border is the same size on all sides */
210 constexpr bool uniform() const
211 {
212 return top == right && top == bottom && top == left;
213 }
214
215 BorderSize &operator*=(float scale)
216 {
217 top *= scale;
218 right *= scale;
219 bottom *= scale;
220 left *= scale;
221
222 return *this;
223 }
224
225 BorderSize operator*(float scale)
226 {
227 BorderSize size = *this;
228 size *= scale;
229
230 return size;
231 }
232
233 void limit(const BorderSize &limit)
234 {
235 top = std::min(top, limit.top);
236 right = std::min(right, limit.right);
237 bottom = std::min(bottom, limit.bottom);
238 left = std::min(left, limit.left);
239 }
240
241 unsigned int top;
242 unsigned int right;
243 unsigned int bottom;
244 unsigned int left;
245};
246
247using PaddingSize = BorderSize;
248
249/** Policy to handle overflow */
250enum class ConvertPolicy
251{
252 WRAP, /**< Wrap around */
253 SATURATE /**< Saturate */
254};
255
256/** Interpolation method */
257enum class InterpolationPolicy
258{
259 NEAREST_NEIGHBOR, /**< Output values are defined to match the source pixel whose center is nearest to the sample position */
260 BILINEAR, /**< Output values are defined by bilinear interpolation between the pixels */
261 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 */
262};
263
264/** Bilinear Interpolation method used by LKTracker */
265enum class BilinearInterpolation
266{
267 BILINEAR_OLD_NEW,
268 BILINEAR_SCHARR
269};
270
271/** Threshold mode */
272enum class ThresholdType
273{
274 BINARY, /**< Threshold with one value */
275 RANGE /**< Threshold with two values*/
276};
277
278/** Rounding method */
279enum class RoundingPolicy
280{
281 TO_ZERO, /**< Truncates the least significand values that are lost in operations. */
282 TO_NEAREST_UP, /**< Rounds to nearest value; half rounds up */
283 TO_NEAREST_EVEN /**< Rounds to nearest value; half rounds to nearest even */
284};
285
286/** Termination criteria */
287enum class Termination
288{
289 TERM_CRITERIA_EPSILON,
290 TERM_CRITERIA_ITERATIONS,
291 TERM_CRITERIA_BOTH
292};
293
294/** Magnitude calculation type. */
295enum class MagnitudeType
296{
297 L1NORM, /**< L1 normalization type */
298 L2NORM /**< L2 normalization type */
299};
300
301/** Phase calculation type.
302 *
303 * @note When PhaseType == SIGNED, each angle is mapped to the range 0 to 255 inclusive otherwise angles between 0 and 180
304 */
305enum class PhaseType
306{
307 SIGNED, /**< Angle range: [0, 360] */
308 UNSIGNED /**< Angle range: [0, 180] */
309};
310
311/** Keypoint type */
312struct KeyPoint
313{
314 int32_t x{ 0 }; /**< X coordinates */
315 int32_t y{ 0 }; /**< Y coordinates */
316 float strength{ 0.f }; /**< Strength of the point */
317 float scale{ 0.f }; /**< Scale initialized to 0 by the corner detector */
318 float orientation{ 0.f }; /**< Orientation initialized to 0 by the corner detector */
319 int32_t tracking_status{ 0 }; /**< Status initialized to 1 by the corner detector, set to 0 when the point is lost */
320 float error{ 0.f }; /**< Tracking error initialized to 0 by the corner detector */
321};
322
323using InternalKeypoint = std::tuple<float, float, float>; /* x,y,strength */
324
325/** Rectangle type */
326struct Rectangle
327{
328 uint16_t x; /**< Top-left x coordinate */
329 uint16_t y; /**< Top-left y coordinate */
330 uint16_t width; /**< Width of the rectangle */
331 uint16_t height; /**< Height of the rectangle */
332};
333
334/** Coordinate type */
335struct Coordinates2D
336{
337 int32_t x; /**< X coordinates */
338 int32_t y; /**< Y coordinates */
339};
340
341/** Coordinate type */
342struct Coordinates3D
343{
344 uint32_t x; /**< X coordinates */
345 uint32_t y; /**< Y coordinates */
346 uint32_t z; /**< Z coordinates */
347};
348
Georgios Pinitas7b7858d2017-06-21 16:44:24 +0100349/** Region of interest */
350struct ROI
351{
352 Rectangle rect; /**< Rectangle specifying the region of interest */
353 uint16_t batch_idx; /**< The batch index of the region of interest */
354};
355
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100356/** Available channels */
357enum class Channel
358{
359 UNKNOWN, /** Unknown channel format */
360 C0, /**< First channel (used by formats with unknown channel types). */
361 C1, /**< Second channel (used by formats with unknown channel types). */
362 C2, /**< Third channel (used by formats with unknown channel types). */
363 C3, /**< Fourth channel (used by formats with unknown channel types). */
364 R, /**< Red channel. */
365 G, /**< Green channel. */
366 B, /**< Blue channel. */
367 A, /**< Alpha channel. */
368 Y, /**< Luma channel. */
369 U, /**< Cb/U channel. */
370 V /**< Cr/V/Value channel. */
371};
372
373/** Available matrix patterns */
374enum class MatrixPattern
375{
376 BOX, /**< Box pattern matrix. */
377 CROSS, /**< Cross pattern matrix. */
378 DISK, /**< Disk pattern matrix. */
379 OTHER /**< Any other matrix pattern. */
380};
381
382/** Available non linear functions. */
383enum class NonLinearFilterFunction : unsigned
384{
385 MEDIAN = 0, /**< Non linear median filter. */
386 MIN = 1, /**< Non linear erode. */
387 MAX = 2, /**< Non linear dilate. */
388};
389
Georgios Pinitasd9769582017-08-03 10:19:40 +0100390/** Available reduction operations */
391enum class ReductionOperation
392{
393 SUM_SQUARE, /**< Sum of squares */
Michalis Spyrou04f089c2017-08-08 17:42:38 +0100394 SUM, /**< Sum */
Georgios Pinitasd9769582017-08-03 10:19:40 +0100395};
396
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100397/** The normalization type used for the normalization layer */
398enum class NormType
399{
400 IN_MAP_1D, /**< Normalization applied within the same map in 1D region */
401 IN_MAP_2D, /**< Normalization applied within the same map in 2D region */
402 CROSS_MAP /**< Normalization applied cross maps */
403};
404
405/** Normalization type for Histogram of Oriented Gradients (HOG) */
406enum class HOGNormType
407{
408 L2_NORM = 1, /**< L2-norm */
409 L2HYS_NORM = 2, /**< L2-norm followed by clipping */
410 L1_NORM = 3 /**< L1 norm */
411};
412
413/** Detection window used for the object detection. The detection window keeps the following information:
414 *
415 * -# Geometry of the rectangular window (x/y of top-left corner and width/height)
416 * -# Index of the class used for evaluating which class the detection window belongs to
417 * -# Confidence value (score) obtained with the classifier
418 */
419struct DetectionWindow
420{
421 uint16_t x{ 0 }; /**< Top-left x coordinate */
422 uint16_t y{ 0 }; /**< Top-left y coordinate */
423 uint16_t width{ 0 }; /**< Width of the detection window */
424 uint16_t height{ 0 }; /**< Height of the detection window */
425 uint16_t idx_class{ 0 }; /**< Index of the class */
426 float score{ 0.f }; /**< Confidence value for the detection window */
427};
428
429/** Dimension rounding type when down-scaling on CNNs
430 * @note Used in pooling and convolution layer
431 */
432enum class DimensionRoundingType
433{
434 FLOOR, /**< Floor rounding */
435 CEIL /**< Ceil rounding */
436};
437
438/** Available pooling types */
439enum class PoolingType
440{
441 MAX, /**< Max Pooling */
Georgios Pinitascdf51452017-08-31 14:21:36 +0100442 AVG, /**< Average Pooling */
443 L2 /**< L2 Pooling */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100444};
445
446/** Padding and stride information class */
447class PadStrideInfo
448{
449public:
450 /** Constructor
451 *
452 * @param[in] stride_x (Optional) Stride, in elements, across x. Defaults to 1.
453 * @param[in] stride_y (Optional) Stride, in elements, across y. Defaults to 1.
454 * @param[in] pad_x (Optional) Padding, in elements, across x. Defaults to 0.
455 * @param[in] pad_y (Optional) Padding, in elements, across y. Defaults to 0.
456 * @param[in] round (Optional) Dimensions rounding. Defaults to @ref FLOOR.
457 */
458 PadStrideInfo(unsigned int stride_x = 1, unsigned int stride_y = 1,
459 unsigned int pad_x = 0, unsigned int pad_y = 0,
460 DimensionRoundingType round = DimensionRoundingType::FLOOR)
461 : _stride(std::make_pair(stride_x, stride_y)),
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100462 _pad_left(pad_x),
463 _pad_top(pad_y),
464 _pad_right(pad_x),
465 _pad_bottom(pad_y),
466 _round_type(round)
467 {
468 }
469 /** Constructor
470 *
471 * @param[in] stride_x Stride, in elements, across x.
472 * @param[in] stride_y Stride, in elements, across y.
473 * @param[in] pad_left Padding across x on the left, in elements.
474 * @param[in] pad_top Padding across y on the top, in elements.
475 * @param[in] pad_right Padding across x on the right, in elements.
476 * @param[in] pad_bottom Padding across y on the bottom, in elements.
477 * @param[in] round Dimensions rounding.
478 */
479 PadStrideInfo(unsigned int stride_x, unsigned int stride_y,
480 unsigned int pad_left, unsigned int pad_right,
481 unsigned int pad_top, unsigned int pad_bottom,
482 DimensionRoundingType round)
483 : _stride(std::make_pair(stride_x, stride_y)),
484 _pad_left(pad_left),
485 _pad_top(pad_top),
486 _pad_right(pad_right),
487 _pad_bottom(pad_bottom),
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100488 _round_type(round)
489 {
490 }
491 std::pair<unsigned int, unsigned int> stride() const
492 {
493 return _stride;
494 }
495 std::pair<unsigned int, unsigned int> pad() const
496 {
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100497 //this accessor should be used only when padding is symmetric
498 ARM_COMPUTE_ERROR_ON(_pad_left != _pad_right || _pad_top != _pad_bottom);
499 return std::make_pair(_pad_left, _pad_top);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100500 }
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100501
502 unsigned int pad_left() const
503 {
504 return _pad_left;
505 }
506 unsigned int pad_right() const
507 {
508 return _pad_right;
509 }
510 unsigned int pad_top() const
511 {
512 return _pad_top;
513 }
514 unsigned int pad_bottom() const
515 {
516 return _pad_bottom;
517 }
518
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100519 DimensionRoundingType round() const
520 {
521 return _round_type;
522 }
523
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100524 bool has_padding() const
525 {
526 return (_pad_left != 0 || _pad_top != 0 || _pad_right != 0 || _pad_bottom != 0);
527 }
528
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100529private:
530 std::pair<unsigned int, unsigned int> _stride;
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100531 unsigned int _pad_left;
532 unsigned int _pad_top;
533 unsigned int _pad_right;
534 unsigned int _pad_bottom;
535
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100536 DimensionRoundingType _round_type;
537};
538
539/** Pooling Layer Information class */
540class PoolingLayerInfo
541{
542public:
543 /** Default Constructor
544 *
545 * @param[in] pool_type Pooling type @ref PoolingType. Defaults to @ref PoolingType::MAX
546 * @param[in] pool_size (Optional) Pooling size, in elements, across x and y. Defaults to 2.
547 * @param[in] pad_stride_info (Optional) Padding and stride information @ref PadStrideInfo
548 */
549 PoolingLayerInfo(PoolingType pool_type = PoolingType::MAX, unsigned int pool_size = 2, PadStrideInfo pad_stride_info = PadStrideInfo())
550 : _pool_type(pool_type), _pool_size(pool_size), _pad_stride_info(pad_stride_info)
551 {
552 }
553 PoolingType pool_type() const
554 {
555 return _pool_type;
556 }
557 unsigned int pool_size() const
558 {
559 return _pool_size;
560 }
561 PadStrideInfo pad_stride_info() const
562 {
563 return _pad_stride_info;
564 }
565
566private:
567 PoolingType _pool_type;
568 unsigned int _pool_size;
569 PadStrideInfo _pad_stride_info;
570};
571
Georgios Pinitas7b7858d2017-06-21 16:44:24 +0100572/** ROI Pooling Layer Information class */
573class ROIPoolingLayerInfo
574{
575public:
576 /** Default Constructor
577 *
578 * @param[in] pooled_width Pooled width of the layer.
579 * @param[in] pooled_height Pooled height of the layer.
580 * @param[in] spatial_scale Spatial scale to be applied to the ROI coordinates and dimensions.
581 */
582 ROIPoolingLayerInfo(unsigned int pooled_width, unsigned int pooled_height, float spatial_scale)
583 : _pooled_width(pooled_width), _pooled_height(pooled_height), _spatial_scale(spatial_scale)
584 {
585 }
586 unsigned int pooled_width() const
587 {
588 return _pooled_width;
589 }
590 unsigned int pooled_height() const
591 {
592 return _pooled_height;
593 }
594 float spatial_scale() const
595 {
596 return _spatial_scale;
597 }
598
599private:
600 unsigned int _pooled_width;
601 unsigned int _pooled_height;
602 float _spatial_scale;
603};
604
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100605/** Activation Layer Information class */
606class ActivationLayerInfo
607{
608public:
609 /** Available activation functions */
610 enum class ActivationFunction
611 {
Georgios Pinitas64ebe5b2017-09-01 17:44:24 +0100612 LOGISTIC, /**< Logistic ( \f$ f(x) = \frac{1}{1 + e^{-x}} \f$ ) */
613 TANH, /**< Hyperbolic tangent ( \f$ f(x) = a \cdot tanh(b \cdot x) \f$ ) */
614 RELU, /**< Rectifier ( \f$ f(x) = max(0,x) \f$ ) */
615 BOUNDED_RELU, /**< Upper Bounded Rectifier ( \f$ f(x) = min(a, max(0,x)) \f$ ) */
616 LU_BOUNDED_RELU, /**< Lower and Upper Bounded Rectifier ( \f$ f(x) = min(a, max(b,x)) \f$ ) */
617 LEAKY_RELU, /**< Leaky Rectifier ( \f$ f(x)= log(1+e^x) \f$ ) */
618 SOFT_RELU, /**< Soft Rectifier ( \f$ f(x)= log(1+e^x) \f$ ) */
619 ABS, /**< Absolute ( \f$ f(x)= |x| \f$ ) */
620 SQUARE, /**< Square ( \f$ f(x)= x^2 \f$ )*/
621 SQRT, /**< Square root ( \f$ f(x) = \sqrt{x} \f$ )*/
622 LINEAR /**< Linear ( \f$ f(x)= ax + b \f$ ) */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100623 };
624
625 /** Default Constructor
626 *
627 * @param[in] f The activation function to use.
628 * @param[in] a (Optional) The alpha parameter used by some activation functions
Georgios Pinitas64ebe5b2017-09-01 17:44:24 +0100629 * (@ref ActivationFunction::BOUNDED_RELU, @ref ActivationFunction::LU_BOUNDED_RELU, @ref ActivationFunction::LINEAR, @ref ActivationFunction::TANH).
630 * @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 +0100631 */
632 ActivationLayerInfo(ActivationFunction f, float a = 0.0f, float b = 0.0f)
633 : _act(f), _a(a), _b(b)
634 {
635 }
636 ActivationFunction activation() const
637 {
638 return _act;
639 }
640 float a() const
641 {
642 return _a;
643 }
644 float b() const
645 {
646 return _b;
647 }
648
649private:
650 ActivationFunction _act;
651 float _a;
652 float _b;
653};
654
655/** Normalization Layer Information class */
656class NormalizationLayerInfo
657{
658public:
659 /** Default Constructor
660 *
661 * @param[in] type The normalization type. Can be @ref NormType::IN_MAP_1D, @ref NormType::IN_MAP_2D or @ref NORM_TYPE::CROSS_MAP
662 * @param[in] norm_size The normalization size is the number of elements to normalize across. Defaults to 5.
663 * @param[in] alpha Alpha parameter used by normalization equation. Defaults to 0.0001.
664 * @param[in] beta Beta parameter used by normalization equation. Defaults to 0.5.
665 * @param[in] kappa Kappa parameter used by [Krichevksy 2012] Across Channel Local Brightness Normalization equation.
666 */
667 NormalizationLayerInfo(NormType type, uint32_t norm_size = 5, float alpha = 0.0001f, float beta = 0.5f, float kappa = 1.f)
668 : _type(type), _norm_size(norm_size), _alpha(alpha), _beta(beta), _kappa(kappa)
669 {
670 }
671 NormType type() const
672 {
673 return _type;
674 }
675 uint32_t norm_size() const
676 {
677 return _norm_size;
678 }
679 float alpha() const
680 {
681 return _alpha;
682 }
683 float beta() const
684 {
685 return _beta;
686 }
687 float kappa() const
688 {
689 return _kappa;
690 }
691 /** Return the scaling factor of the normalization function. If kappa is not
692 * 1 then [Krichevksy 2012] normalization scaling is specified. Scaling
693 * factor takes into account the total number of elements used for the
694 * normalization, so in case of 2 dimensions this is _norm_size^2.
695 *
696 * @return The normalization scaling factor.
697 */
698 float scale_coeff() const
699 {
700 const uint32_t size = (_type == NormType::IN_MAP_2D) ? _norm_size * _norm_size : _norm_size;
701 return (_kappa == 1.f) ? (_alpha / size) : _alpha;
702 }
703
704private:
705 NormType _type;
706 uint32_t _norm_size;
707 float _alpha;
708 float _beta;
709 float _kappa;
710};
711
Gian Marco Iodice559d7712017-08-08 08:38:09 +0100712/** 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 +0100713class WeightsInfo
714{
715public:
Gian Marco Iodice4e288692017-06-27 11:41:59 +0100716 /** Default constructor */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100717 WeightsInfo()
Gian Marco Iodice559d7712017-08-08 08:38:09 +0100718 : _are_reshaped(false), _kernel_width(0), _kernel_height(0), _num_kernels(0)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100719 {
720 }
721 /** Constructor
722 *
Gian Marco Iodice4e288692017-06-27 11:41:59 +0100723 * @param[in] are_reshaped True if the weights have been reshaped
724 * @param[in] kernel_width Kernel width.
725 * @param[in] kernel_height Kernel height.
Gian Marco Iodice559d7712017-08-08 08:38:09 +0100726 * @param[in] num_kernels Number of convolution kernels.
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100727 */
Gian Marco Iodice559d7712017-08-08 08:38:09 +0100728 WeightsInfo(bool are_reshaped, unsigned int kernel_width, unsigned int kernel_height, unsigned int num_kernels)
729 : _are_reshaped(are_reshaped), _kernel_width(kernel_width), _kernel_height(kernel_height), _num_kernels(num_kernels)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100730 {
731 }
Gian Marco Iodice4e288692017-06-27 11:41:59 +0100732 /** Flag which specifies if the weights tensor has been reshaped.
733 *
734 * @return True if the weights tensors has been reshaped
735 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100736 bool are_reshaped() const
737 {
738 return _are_reshaped;
739 };
Gian Marco Iodice559d7712017-08-08 08:38:09 +0100740 /** Return the number of convolution kernels
741 *
742 * @return The number of convolution kernels
743 */
744 unsigned int num_kernels() const
745 {
746 return _num_kernels;
747 };
Gian Marco Iodice4e288692017-06-27 11:41:59 +0100748 /** Return the width and height of the kernel
749 *
750 * @return The width and height of the kernel
751 */
752 std::pair<unsigned int, unsigned int> kernel_size() const
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100753 {
Gian Marco Iodice4e288692017-06-27 11:41:59 +0100754 return std::make_pair(_kernel_width, _kernel_height);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100755 }
756
757private:
758 const bool _are_reshaped;
Gian Marco Iodice4e288692017-06-27 11:41:59 +0100759 const unsigned int _kernel_width;
760 const unsigned int _kernel_height;
Gian Marco Iodice559d7712017-08-08 08:38:09 +0100761 const unsigned int _num_kernels;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100762};
763
764/** IO formatting information class*/
765struct IOFormatInfo
766{
767 /** Precision type used when printing floating point numbers */
768 enum class PrecisionType
769 {
770 Default, /**< Default precision to the one that the current stream has */
771 Custom, /**< Custom precision specified by the user using the precision parameter */
772 Full /**< The maximum precision of the floating point representation */
773 };
774
775 /** Specifies the area to be printed, used by Tensor objects */
776 enum class PrintRegion
777 {
778 ValidRegion, /**< Prints the valid region of the Tensor object */
779 NoPadding, /**< Prints the Tensor object without the padding */
780 Full /**< Print the tensor object including padding */
781 };
782
783 IOFormatInfo(PrintRegion print_region = PrintRegion::ValidRegion,
784 PrecisionType precision_type = PrecisionType::Default,
785 unsigned int precision = 10,
786 bool align_columns = true,
787 std::string element_delim = " ",
788 std::string row_delim = "\n")
789 : print_region(print_region),
790 precision_type(precision_type),
791 precision(precision),
792 element_delim(element_delim),
793 row_delim(row_delim),
794 align_columns(align_columns)
795 {
796 }
797
798 PrintRegion print_region;
799 PrecisionType precision_type;
800 unsigned int precision;
801 std::string element_delim;
802 std::string row_delim;
803 bool align_columns;
804};
805}
806#endif /* __ARM_COMPUTE_TYPES_H__ */