blob: e8be6127a8cab5b1f47579130ed129d12cba73fa [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
Georgios Pinitasadaae7e2017-10-30 15:56:32 +0000548 * @param[in] exclude_padding (Optional) Strategy when accounting padding in calculations.
549 * True will exclude padding while false will not (Used in AVG/L2 pooling to determine the pooling area).
550 * Defaults to false;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100551 */
Georgios Pinitasadaae7e2017-10-30 15:56:32 +0000552 PoolingLayerInfo(PoolingType pool_type = PoolingType::MAX,
553 unsigned int pool_size = 2,
554 PadStrideInfo pad_stride_info = PadStrideInfo(),
555 bool exclude_padding = false)
556 : _pool_type(pool_type), _pool_size(pool_size), _pad_stride_info(pad_stride_info), _exclude_padding(exclude_padding)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100557 {
558 }
559 PoolingType pool_type() const
560 {
561 return _pool_type;
562 }
563 unsigned int pool_size() const
564 {
565 return _pool_size;
566 }
567 PadStrideInfo pad_stride_info() const
568 {
569 return _pad_stride_info;
570 }
Georgios Pinitasadaae7e2017-10-30 15:56:32 +0000571 bool exclude_padding() const
572 {
573 return _exclude_padding;
574 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100575
576private:
577 PoolingType _pool_type;
578 unsigned int _pool_size;
579 PadStrideInfo _pad_stride_info;
Georgios Pinitasadaae7e2017-10-30 15:56:32 +0000580 bool _exclude_padding;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100581};
582
Georgios Pinitas7b7858d2017-06-21 16:44:24 +0100583/** ROI Pooling Layer Information class */
584class ROIPoolingLayerInfo
585{
586public:
587 /** Default Constructor
588 *
589 * @param[in] pooled_width Pooled width of the layer.
590 * @param[in] pooled_height Pooled height of the layer.
591 * @param[in] spatial_scale Spatial scale to be applied to the ROI coordinates and dimensions.
592 */
593 ROIPoolingLayerInfo(unsigned int pooled_width, unsigned int pooled_height, float spatial_scale)
594 : _pooled_width(pooled_width), _pooled_height(pooled_height), _spatial_scale(spatial_scale)
595 {
596 }
597 unsigned int pooled_width() const
598 {
599 return _pooled_width;
600 }
601 unsigned int pooled_height() const
602 {
603 return _pooled_height;
604 }
605 float spatial_scale() const
606 {
607 return _spatial_scale;
608 }
609
610private:
611 unsigned int _pooled_width;
612 unsigned int _pooled_height;
613 float _spatial_scale;
614};
615
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100616/** Activation Layer Information class */
617class ActivationLayerInfo
618{
619public:
620 /** Available activation functions */
621 enum class ActivationFunction
622 {
Georgios Pinitas64ebe5b2017-09-01 17:44:24 +0100623 LOGISTIC, /**< Logistic ( \f$ f(x) = \frac{1}{1 + e^{-x}} \f$ ) */
624 TANH, /**< Hyperbolic tangent ( \f$ f(x) = a \cdot tanh(b \cdot x) \f$ ) */
625 RELU, /**< Rectifier ( \f$ f(x) = max(0,x) \f$ ) */
626 BOUNDED_RELU, /**< Upper Bounded Rectifier ( \f$ f(x) = min(a, max(0,x)) \f$ ) */
627 LU_BOUNDED_RELU, /**< Lower and Upper Bounded Rectifier ( \f$ f(x) = min(a, max(b,x)) \f$ ) */
628 LEAKY_RELU, /**< Leaky Rectifier ( \f$ f(x)= log(1+e^x) \f$ ) */
629 SOFT_RELU, /**< Soft Rectifier ( \f$ f(x)= log(1+e^x) \f$ ) */
630 ABS, /**< Absolute ( \f$ f(x)= |x| \f$ ) */
631 SQUARE, /**< Square ( \f$ f(x)= x^2 \f$ )*/
632 SQRT, /**< Square root ( \f$ f(x) = \sqrt{x} \f$ )*/
633 LINEAR /**< Linear ( \f$ f(x)= ax + b \f$ ) */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100634 };
635
636 /** Default Constructor
637 *
638 * @param[in] f The activation function to use.
639 * @param[in] a (Optional) The alpha parameter used by some activation functions
Georgios Pinitas64ebe5b2017-09-01 17:44:24 +0100640 * (@ref ActivationFunction::BOUNDED_RELU, @ref ActivationFunction::LU_BOUNDED_RELU, @ref ActivationFunction::LINEAR, @ref ActivationFunction::TANH).
641 * @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 +0100642 */
643 ActivationLayerInfo(ActivationFunction f, float a = 0.0f, float b = 0.0f)
644 : _act(f), _a(a), _b(b)
645 {
646 }
647 ActivationFunction activation() const
648 {
649 return _act;
650 }
651 float a() const
652 {
653 return _a;
654 }
655 float b() const
656 {
657 return _b;
658 }
659
660private:
661 ActivationFunction _act;
662 float _a;
663 float _b;
664};
665
666/** Normalization Layer Information class */
667class NormalizationLayerInfo
668{
669public:
670 /** Default Constructor
671 *
672 * @param[in] type The normalization type. Can be @ref NormType::IN_MAP_1D, @ref NormType::IN_MAP_2D or @ref NORM_TYPE::CROSS_MAP
673 * @param[in] norm_size The normalization size is the number of elements to normalize across. Defaults to 5.
674 * @param[in] alpha Alpha parameter used by normalization equation. Defaults to 0.0001.
675 * @param[in] beta Beta parameter used by normalization equation. Defaults to 0.5.
676 * @param[in] kappa Kappa parameter used by [Krichevksy 2012] Across Channel Local Brightness Normalization equation.
677 */
678 NormalizationLayerInfo(NormType type, uint32_t norm_size = 5, float alpha = 0.0001f, float beta = 0.5f, float kappa = 1.f)
679 : _type(type), _norm_size(norm_size), _alpha(alpha), _beta(beta), _kappa(kappa)
680 {
681 }
682 NormType type() const
683 {
684 return _type;
685 }
686 uint32_t norm_size() const
687 {
688 return _norm_size;
689 }
690 float alpha() const
691 {
692 return _alpha;
693 }
694 float beta() const
695 {
696 return _beta;
697 }
698 float kappa() const
699 {
700 return _kappa;
701 }
702 /** Return the scaling factor of the normalization function. If kappa is not
703 * 1 then [Krichevksy 2012] normalization scaling is specified. Scaling
704 * factor takes into account the total number of elements used for the
705 * normalization, so in case of 2 dimensions this is _norm_size^2.
706 *
707 * @return The normalization scaling factor.
708 */
709 float scale_coeff() const
710 {
711 const uint32_t size = (_type == NormType::IN_MAP_2D) ? _norm_size * _norm_size : _norm_size;
712 return (_kappa == 1.f) ? (_alpha / size) : _alpha;
713 }
714
715private:
716 NormType _type;
717 uint32_t _norm_size;
718 float _alpha;
719 float _beta;
720 float _kappa;
721};
722
Gian Marco Iodice559d7712017-08-08 08:38:09 +0100723/** 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 +0100724class WeightsInfo
725{
726public:
Gian Marco Iodice4e288692017-06-27 11:41:59 +0100727 /** Default constructor */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100728 WeightsInfo()
Gian Marco Iodice559d7712017-08-08 08:38:09 +0100729 : _are_reshaped(false), _kernel_width(0), _kernel_height(0), _num_kernels(0)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100730 {
731 }
732 /** Constructor
733 *
Gian Marco Iodice4e288692017-06-27 11:41:59 +0100734 * @param[in] are_reshaped True if the weights have been reshaped
735 * @param[in] kernel_width Kernel width.
736 * @param[in] kernel_height Kernel height.
Gian Marco Iodice559d7712017-08-08 08:38:09 +0100737 * @param[in] num_kernels Number of convolution kernels.
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100738 */
Gian Marco Iodice559d7712017-08-08 08:38:09 +0100739 WeightsInfo(bool are_reshaped, unsigned int kernel_width, unsigned int kernel_height, unsigned int num_kernels)
740 : _are_reshaped(are_reshaped), _kernel_width(kernel_width), _kernel_height(kernel_height), _num_kernels(num_kernels)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100741 {
742 }
Gian Marco Iodice4e288692017-06-27 11:41:59 +0100743 /** Flag which specifies if the weights tensor has been reshaped.
744 *
745 * @return True if the weights tensors has been reshaped
746 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100747 bool are_reshaped() const
748 {
749 return _are_reshaped;
750 };
Gian Marco Iodice559d7712017-08-08 08:38:09 +0100751 /** Return the number of convolution kernels
752 *
753 * @return The number of convolution kernels
754 */
755 unsigned int num_kernels() const
756 {
757 return _num_kernels;
758 };
Gian Marco Iodice4e288692017-06-27 11:41:59 +0100759 /** Return the width and height of the kernel
760 *
761 * @return The width and height of the kernel
762 */
763 std::pair<unsigned int, unsigned int> kernel_size() const
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100764 {
Gian Marco Iodice4e288692017-06-27 11:41:59 +0100765 return std::make_pair(_kernel_width, _kernel_height);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100766 }
767
768private:
769 const bool _are_reshaped;
Gian Marco Iodice4e288692017-06-27 11:41:59 +0100770 const unsigned int _kernel_width;
771 const unsigned int _kernel_height;
Gian Marco Iodice559d7712017-08-08 08:38:09 +0100772 const unsigned int _num_kernels;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100773};
774
775/** IO formatting information class*/
776struct IOFormatInfo
777{
778 /** Precision type used when printing floating point numbers */
779 enum class PrecisionType
780 {
781 Default, /**< Default precision to the one that the current stream has */
782 Custom, /**< Custom precision specified by the user using the precision parameter */
783 Full /**< The maximum precision of the floating point representation */
784 };
785
786 /** Specifies the area to be printed, used by Tensor objects */
787 enum class PrintRegion
788 {
789 ValidRegion, /**< Prints the valid region of the Tensor object */
790 NoPadding, /**< Prints the Tensor object without the padding */
791 Full /**< Print the tensor object including padding */
792 };
793
794 IOFormatInfo(PrintRegion print_region = PrintRegion::ValidRegion,
795 PrecisionType precision_type = PrecisionType::Default,
796 unsigned int precision = 10,
797 bool align_columns = true,
798 std::string element_delim = " ",
799 std::string row_delim = "\n")
800 : print_region(print_region),
801 precision_type(precision_type),
802 precision(precision),
803 element_delim(element_delim),
804 row_delim(row_delim),
805 align_columns(align_columns)
806 {
807 }
808
809 PrintRegion print_region;
810 PrecisionType precision_type;
811 unsigned int precision;
812 std::string element_delim;
813 std::string row_delim;
814 bool align_columns;
815};
816}
817#endif /* __ARM_COMPUTE_TYPES_H__ */