blob: 36ec38ff683a8b3761ef3f3f70edb5b0aaacc50c [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"
Georgios Pinitas8795ffb2017-12-01 16:13:40 +000028#include "arm_compute/core/Strides.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010029#include "arm_compute/core/TensorShape.h"
Georgios Pinitas583137c2017-08-31 18:12:42 +010030#include "support/Half.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010031
32#include <cstddef>
33#include <cstdint>
34#include <string>
35#include <utility>
36
37namespace arm_compute
38{
Georgios Pinitas583137c2017-08-31 18:12:42 +010039/** 16-bit floating point type */
40using half = half_float::half;
41
Georgios Pinitas8795ffb2017-12-01 16:13:40 +000042/** Permutation vector */
43using PermutationVector = Strides;
44
Anthony Barbier6ff3b192017-09-04 18:44:23 +010045/** Image colour formats */
46enum class Format
47{
Daniil Efremov02bf80d2017-11-22 00:26:51 +070048 UNKNOWN, /**< Unknown image format */
49 U8, /**< 1 channel, 1 U8 per channel */
50 S16, /**< 1 channel, 1 S16 per channel */
51 U16, /**< 1 channel, 1 U16 per channel */
52 S32, /**< 1 channel, 1 S32 per channel */
53 U32, /**< 1 channel, 1 U32 per channel */
54 F16, /**< 1 channel, 1 F16 per channel */
55 F32, /**< 1 channel, 1 F32 per channel */
56 UV88, /**< 2 channel, 1 U8 per channel */
57 RGB888, /**< 3 channels, 1 U8 per channel */
58 RGBA8888, /**< 4 channels, 1 U8 per channel */
59 YUV444, /**< A 3 plane of 8 bit 4:4:4 sampled Y, U, V planes */
60 YUYV422, /**< A single plane of 32-bit macro pixel of Y0, U0, Y1, V0 bytes */
61 NV12, /**< A 2 plane YUV format of Luma (Y) and interleaved UV data at 4:2:0 sampling */
62 NV21, /**< A 2 plane YUV format of Luma (Y) and interleaved VU data at 4:2:0 sampling */
63 IYUV, /**< A 3 plane of 8-bit 4:2:0 sampled Y, U, V planes */
64 UYVY422 /**< A single plane of 32-bit macro pixel of U0, Y0, V0, Y1 byte */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010065};
66
67/** Available data types */
68enum class DataType
69{
70 UNKNOWN,
71 U8,
72 S8,
73 QS8,
Michel Iwaniec00633802017-10-12 14:14:15 +010074 QASYMM8,
Anthony Barbier6ff3b192017-09-04 18:44:23 +010075 U16,
76 S16,
77 QS16,
78 U32,
79 S32,
Pablo Tellof87cc7f2017-07-26 10:28:40 +010080 QS32,
Anthony Barbier6ff3b192017-09-04 18:44:23 +010081 U64,
82 S64,
83 F16,
84 F32,
85 F64,
86 SIZET
87};
88
Daniil Efremov02bf80d2017-11-22 00:26:51 +070089/** Available Sampling Policies */
90enum class SamplingPolicy
91{
92 CENTER, /**< Samples are taken at pixel center */
93 TOP_LEFT /**< Samples are taken at pixel top left corner */
94};
95
Anthony Barbier6ff3b192017-09-04 18:44:23 +010096/** Constant value of the border pixels when using BorderMode::CONSTANT */
97constexpr uint8_t CONSTANT_BORDER_VALUE = 199;
98
99/* Constant value used to indicate a half-scale pyramid */
100constexpr float SCALE_PYRAMID_HALF = 0.5f;
101
102/* Constant value used to indicate a ORB scaled pyramid */
103constexpr float SCALE_PYRAMID_ORB = 8.408964152537146130583778358414e-01;
104
Michel Iwaniec00633802017-10-12 14:14:15 +0100105/** Quantization settings (used for QASYMM8 data type) */
106struct QuantizationInfo
107{
108 QuantizationInfo()
109 : scale(0.0f), offset(0)
110 {
111 }
112
113 QuantizationInfo(float scale, int offset)
114 : scale(scale), offset(offset)
115 {
116 }
117
Daniil Efremoveed841c2017-11-09 19:05:25 +0700118 bool operator==(const QuantizationInfo &other)
119 {
120 return scale == other.scale && offset == other.offset;
121 }
122
123 bool operator!=(const QuantizationInfo &other)
124 {
125 return !(*this == other);
126 }
127
Michel Iwaniec00633802017-10-12 14:14:15 +0100128 float scale; /**< scale */
129 int offset; /**< offset */
130
131 /** Quantizes a value using the scale/offset in this QuantizationInfo */
132 uint8_t quantize(float value) const
133 {
134 ARM_COMPUTE_ERROR_ON_MSG(scale == 0, "QuantizationInfo::quantize: scale == 0");
135 int quantized = static_cast<int>(value / scale + offset);
136 quantized = std::max(0, std::min(quantized, 255));
137 return quantized;
138 }
139
140 /** Dequantizes a value using the scale/offset in this QuantizationInfo */
141 float dequantize(uint8_t value) const
142 {
143 ARM_COMPUTE_ERROR_ON_MSG(scale == 0, "QuantizationInfo::dequantize: scale == 0");
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +0000144 float dequantized = (static_cast<int>(value) - offset) * scale;
Michel Iwaniec00633802017-10-12 14:14:15 +0100145 return dequantized;
146 }
147
148 /** Indicates whether this QuantizationInfo has valid settings or not */
149 bool empty() const
150 {
151 return scale == 0;
152 }
153};
154
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100155struct ValidRegion
156{
157 ValidRegion()
158 : anchor{}, shape{}
159 {
160 }
161
162 ValidRegion(const ValidRegion &) = default;
163 ValidRegion(ValidRegion &&) = default;
164 ValidRegion &operator=(const ValidRegion &) = default;
165 ValidRegion &operator=(ValidRegion &&) = default;
166 ~ValidRegion() = default;
167
168 ValidRegion(Coordinates anchor, TensorShape shape)
169 : anchor{ anchor }, shape{ shape }
170 {
171 }
172
173 /** Return the start of the valid region for the given dimension @p d */
174 int start(unsigned int d) const
175 {
176 return anchor[d];
177 }
178
179 /** Return the end of the valid region for the given dimension @p d */
180 int end(unsigned int d) const
181 {
182 return anchor[d] + shape[d];
183 }
184
185 Coordinates anchor;
186 TensorShape shape;
187};
188
189/** Methods available to handle borders */
190enum class BorderMode
191{
192 UNDEFINED, /**< Borders are left undefined */
193 CONSTANT, /**< Pixels outside the image are assumed to have a constant value */
194 REPLICATE /**< Pixels outside the image are assumed to have the same value as the closest image pixel */
195};
196
197/** Container for 2D border size */
198struct BorderSize
199{
200 /** Empty border, i.e. no border */
201 constexpr BorderSize()
202 : top{ 0 }, right{ 0 }, bottom{ 0 }, left{ 0 }
203 {
204 }
205
206 /** Border with equal size around the 2D plane */
Moritz Pflanzer7655a672017-09-23 11:57:33 +0100207 explicit constexpr BorderSize(unsigned int size)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100208 : top{ size }, right{ size }, bottom{ size }, left{ size }
209 {
210 }
211
212 /** Border with same size for top/bottom and left/right */
213 constexpr BorderSize(unsigned int top_bottom, unsigned int left_right)
214 : top{ top_bottom }, right{ left_right }, bottom{ top_bottom }, left{ left_right }
215 {
216 }
217
218 /** Border with different sizes */
219 constexpr BorderSize(unsigned int top, unsigned int right, unsigned int bottom, unsigned int left)
220 : top{ top }, right{ right }, bottom{ bottom }, left{ left }
221 {
222 }
223
224 /** Check if the entire border is zero */
225 constexpr bool empty() const
226 {
227 return top == 0 && right == 0 && bottom == 0 && left == 0;
228 }
229
230 /** Check if the border is the same size on all sides */
231 constexpr bool uniform() const
232 {
233 return top == right && top == bottom && top == left;
234 }
235
236 BorderSize &operator*=(float scale)
237 {
238 top *= scale;
239 right *= scale;
240 bottom *= scale;
241 left *= scale;
242
243 return *this;
244 }
245
246 BorderSize operator*(float scale)
247 {
248 BorderSize size = *this;
249 size *= scale;
250
251 return size;
252 }
253
254 void limit(const BorderSize &limit)
255 {
256 top = std::min(top, limit.top);
257 right = std::min(right, limit.right);
258 bottom = std::min(bottom, limit.bottom);
259 left = std::min(left, limit.left);
260 }
261
262 unsigned int top;
263 unsigned int right;
264 unsigned int bottom;
265 unsigned int left;
266};
267
268using PaddingSize = BorderSize;
269
270/** Policy to handle overflow */
271enum class ConvertPolicy
272{
273 WRAP, /**< Wrap around */
274 SATURATE /**< Saturate */
275};
276
277/** Interpolation method */
278enum class InterpolationPolicy
279{
280 NEAREST_NEIGHBOR, /**< Output values are defined to match the source pixel whose center is nearest to the sample position */
281 BILINEAR, /**< Output values are defined by bilinear interpolation between the pixels */
282 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 */
283};
284
285/** Bilinear Interpolation method used by LKTracker */
286enum class BilinearInterpolation
287{
288 BILINEAR_OLD_NEW,
289 BILINEAR_SCHARR
290};
291
292/** Threshold mode */
293enum class ThresholdType
294{
295 BINARY, /**< Threshold with one value */
296 RANGE /**< Threshold with two values*/
297};
298
299/** Rounding method */
300enum class RoundingPolicy
301{
302 TO_ZERO, /**< Truncates the least significand values that are lost in operations. */
303 TO_NEAREST_UP, /**< Rounds to nearest value; half rounds up */
304 TO_NEAREST_EVEN /**< Rounds to nearest value; half rounds to nearest even */
305};
306
307/** Termination criteria */
308enum class Termination
309{
310 TERM_CRITERIA_EPSILON,
311 TERM_CRITERIA_ITERATIONS,
312 TERM_CRITERIA_BOTH
313};
314
315/** Magnitude calculation type. */
316enum class MagnitudeType
317{
318 L1NORM, /**< L1 normalization type */
319 L2NORM /**< L2 normalization type */
320};
321
322/** Phase calculation type.
323 *
324 * @note When PhaseType == SIGNED, each angle is mapped to the range 0 to 255 inclusive otherwise angles between 0 and 180
325 */
326enum class PhaseType
327{
328 SIGNED, /**< Angle range: [0, 360] */
329 UNSIGNED /**< Angle range: [0, 180] */
330};
331
332/** Keypoint type */
333struct KeyPoint
334{
335 int32_t x{ 0 }; /**< X coordinates */
336 int32_t y{ 0 }; /**< Y coordinates */
337 float strength{ 0.f }; /**< Strength of the point */
338 float scale{ 0.f }; /**< Scale initialized to 0 by the corner detector */
339 float orientation{ 0.f }; /**< Orientation initialized to 0 by the corner detector */
340 int32_t tracking_status{ 0 }; /**< Status initialized to 1 by the corner detector, set to 0 when the point is lost */
341 float error{ 0.f }; /**< Tracking error initialized to 0 by the corner detector */
342};
343
344using InternalKeypoint = std::tuple<float, float, float>; /* x,y,strength */
345
346/** Rectangle type */
347struct Rectangle
348{
349 uint16_t x; /**< Top-left x coordinate */
350 uint16_t y; /**< Top-left y coordinate */
351 uint16_t width; /**< Width of the rectangle */
352 uint16_t height; /**< Height of the rectangle */
353};
354
355/** Coordinate type */
356struct Coordinates2D
357{
358 int32_t x; /**< X coordinates */
359 int32_t y; /**< Y coordinates */
360};
361
362/** Coordinate type */
363struct Coordinates3D
364{
365 uint32_t x; /**< X coordinates */
366 uint32_t y; /**< Y coordinates */
367 uint32_t z; /**< Z coordinates */
368};
369
Georgios Pinitas7b7858d2017-06-21 16:44:24 +0100370/** Region of interest */
371struct ROI
372{
373 Rectangle rect; /**< Rectangle specifying the region of interest */
374 uint16_t batch_idx; /**< The batch index of the region of interest */
375};
376
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100377/** Available channels */
378enum class Channel
379{
380 UNKNOWN, /** Unknown channel format */
381 C0, /**< First channel (used by formats with unknown channel types). */
382 C1, /**< Second channel (used by formats with unknown channel types). */
383 C2, /**< Third channel (used by formats with unknown channel types). */
384 C3, /**< Fourth channel (used by formats with unknown channel types). */
385 R, /**< Red channel. */
386 G, /**< Green channel. */
387 B, /**< Blue channel. */
388 A, /**< Alpha channel. */
389 Y, /**< Luma channel. */
390 U, /**< Cb/U channel. */
391 V /**< Cr/V/Value channel. */
392};
393
394/** Available matrix patterns */
395enum class MatrixPattern
396{
397 BOX, /**< Box pattern matrix. */
398 CROSS, /**< Cross pattern matrix. */
399 DISK, /**< Disk pattern matrix. */
400 OTHER /**< Any other matrix pattern. */
401};
402
403/** Available non linear functions. */
404enum class NonLinearFilterFunction : unsigned
405{
406 MEDIAN = 0, /**< Non linear median filter. */
407 MIN = 1, /**< Non linear erode. */
408 MAX = 2, /**< Non linear dilate. */
409};
410
Georgios Pinitasd9769582017-08-03 10:19:40 +0100411/** Available reduction operations */
412enum class ReductionOperation
413{
414 SUM_SQUARE, /**< Sum of squares */
Michalis Spyrou04f089c2017-08-08 17:42:38 +0100415 SUM, /**< Sum */
Georgios Pinitasd9769582017-08-03 10:19:40 +0100416};
417
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100418/** The normalization type used for the normalization layer */
419enum class NormType
420{
421 IN_MAP_1D, /**< Normalization applied within the same map in 1D region */
422 IN_MAP_2D, /**< Normalization applied within the same map in 2D region */
423 CROSS_MAP /**< Normalization applied cross maps */
424};
425
426/** Normalization type for Histogram of Oriented Gradients (HOG) */
427enum class HOGNormType
428{
429 L2_NORM = 1, /**< L2-norm */
430 L2HYS_NORM = 2, /**< L2-norm followed by clipping */
431 L1_NORM = 3 /**< L1 norm */
432};
433
434/** Detection window used for the object detection. The detection window keeps the following information:
435 *
436 * -# Geometry of the rectangular window (x/y of top-left corner and width/height)
437 * -# Index of the class used for evaluating which class the detection window belongs to
438 * -# Confidence value (score) obtained with the classifier
439 */
440struct DetectionWindow
441{
442 uint16_t x{ 0 }; /**< Top-left x coordinate */
443 uint16_t y{ 0 }; /**< Top-left y coordinate */
444 uint16_t width{ 0 }; /**< Width of the detection window */
445 uint16_t height{ 0 }; /**< Height of the detection window */
446 uint16_t idx_class{ 0 }; /**< Index of the class */
447 float score{ 0.f }; /**< Confidence value for the detection window */
448};
449
450/** Dimension rounding type when down-scaling on CNNs
451 * @note Used in pooling and convolution layer
452 */
453enum class DimensionRoundingType
454{
455 FLOOR, /**< Floor rounding */
456 CEIL /**< Ceil rounding */
457};
458
459/** Available pooling types */
460enum class PoolingType
461{
462 MAX, /**< Max Pooling */
Georgios Pinitascdf51452017-08-31 14:21:36 +0100463 AVG, /**< Average Pooling */
464 L2 /**< L2 Pooling */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100465};
466
467/** Padding and stride information class */
468class PadStrideInfo
469{
470public:
471 /** Constructor
472 *
473 * @param[in] stride_x (Optional) Stride, in elements, across x. Defaults to 1.
474 * @param[in] stride_y (Optional) Stride, in elements, across y. Defaults to 1.
475 * @param[in] pad_x (Optional) Padding, in elements, across x. Defaults to 0.
476 * @param[in] pad_y (Optional) Padding, in elements, across y. Defaults to 0.
477 * @param[in] round (Optional) Dimensions rounding. Defaults to @ref FLOOR.
478 */
479 PadStrideInfo(unsigned int stride_x = 1, unsigned int stride_y = 1,
480 unsigned int pad_x = 0, unsigned int pad_y = 0,
481 DimensionRoundingType round = DimensionRoundingType::FLOOR)
482 : _stride(std::make_pair(stride_x, stride_y)),
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100483 _pad_left(pad_x),
484 _pad_top(pad_y),
485 _pad_right(pad_x),
486 _pad_bottom(pad_y),
487 _round_type(round)
488 {
489 }
490 /** Constructor
491 *
492 * @param[in] stride_x Stride, in elements, across x.
493 * @param[in] stride_y Stride, in elements, across y.
494 * @param[in] pad_left Padding across x on the left, in elements.
495 * @param[in] pad_top Padding across y on the top, in elements.
496 * @param[in] pad_right Padding across x on the right, in elements.
497 * @param[in] pad_bottom Padding across y on the bottom, in elements.
498 * @param[in] round Dimensions rounding.
499 */
500 PadStrideInfo(unsigned int stride_x, unsigned int stride_y,
501 unsigned int pad_left, unsigned int pad_right,
502 unsigned int pad_top, unsigned int pad_bottom,
503 DimensionRoundingType round)
504 : _stride(std::make_pair(stride_x, stride_y)),
505 _pad_left(pad_left),
506 _pad_top(pad_top),
507 _pad_right(pad_right),
508 _pad_bottom(pad_bottom),
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100509 _round_type(round)
510 {
511 }
512 std::pair<unsigned int, unsigned int> stride() const
513 {
514 return _stride;
515 }
516 std::pair<unsigned int, unsigned int> pad() const
517 {
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100518 //this accessor should be used only when padding is symmetric
519 ARM_COMPUTE_ERROR_ON(_pad_left != _pad_right || _pad_top != _pad_bottom);
520 return std::make_pair(_pad_left, _pad_top);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100521 }
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100522
523 unsigned int pad_left() const
524 {
525 return _pad_left;
526 }
527 unsigned int pad_right() const
528 {
529 return _pad_right;
530 }
531 unsigned int pad_top() const
532 {
533 return _pad_top;
534 }
535 unsigned int pad_bottom() const
536 {
537 return _pad_bottom;
538 }
539
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100540 DimensionRoundingType round() const
541 {
542 return _round_type;
543 }
544
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100545 bool has_padding() const
546 {
547 return (_pad_left != 0 || _pad_top != 0 || _pad_right != 0 || _pad_bottom != 0);
548 }
549
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100550private:
551 std::pair<unsigned int, unsigned int> _stride;
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100552 unsigned int _pad_left;
553 unsigned int _pad_top;
554 unsigned int _pad_right;
555 unsigned int _pad_bottom;
556
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100557 DimensionRoundingType _round_type;
558};
559
560/** Pooling Layer Information class */
561class PoolingLayerInfo
562{
563public:
Georgios Pinitas4c2dd542017-11-13 12:58:41 +0000564 /** Default Constructor */
565 PoolingLayerInfo()
566 : _pool_type(PoolingType::MAX), _pool_size(0), _pad_stride_info(PadStrideInfo()), _exclude_padding(false), _is_global_pooling(false)
567 {
568 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100569 /** Default Constructor
570 *
Georgios Pinitas4c2dd542017-11-13 12:58:41 +0000571 * @param[in] pool_type Pooling type @ref PoolingType.
572 * @param[in] pool_size Pooling size, in elements, across x and y.
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100573 * @param[in] pad_stride_info (Optional) Padding and stride information @ref PadStrideInfo
Georgios Pinitasadaae7e2017-10-30 15:56:32 +0000574 * @param[in] exclude_padding (Optional) Strategy when accounting padding in calculations.
575 * True will exclude padding while false will not (Used in AVG/L2 pooling to determine the pooling area).
576 * Defaults to false;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100577 */
Georgios Pinitas4c2dd542017-11-13 12:58:41 +0000578 explicit PoolingLayerInfo(PoolingType pool_type,
579 unsigned int pool_size,
580 PadStrideInfo pad_stride_info = PadStrideInfo(),
581 bool exclude_padding = false)
582 : _pool_type(pool_type), _pool_size(pool_size), _pad_stride_info(pad_stride_info), _exclude_padding(exclude_padding), _is_global_pooling(false)
583 {
584 }
585 /** Default Constructor
586 *
587 * @note This constructor is used for global pooling
588 *
589 * @param[in] pool_type Pooling type @ref PoolingType.
590 */
591 explicit PoolingLayerInfo(PoolingType pool_type)
592 : _pool_type(pool_type), _pool_size(0), _pad_stride_info(PadStrideInfo(1, 1, 0, 0)), _exclude_padding(false), _is_global_pooling(true)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100593 {
594 }
595 PoolingType pool_type() const
596 {
597 return _pool_type;
598 }
599 unsigned int pool_size() const
600 {
601 return _pool_size;
602 }
603 PadStrideInfo pad_stride_info() const
604 {
605 return _pad_stride_info;
606 }
Georgios Pinitasadaae7e2017-10-30 15:56:32 +0000607 bool exclude_padding() const
608 {
609 return _exclude_padding;
610 }
Georgios Pinitas4c2dd542017-11-13 12:58:41 +0000611 bool is_global_pooling() const
612 {
613 return _is_global_pooling;
614 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100615
616private:
617 PoolingType _pool_type;
618 unsigned int _pool_size;
619 PadStrideInfo _pad_stride_info;
Georgios Pinitasadaae7e2017-10-30 15:56:32 +0000620 bool _exclude_padding;
Georgios Pinitas4c2dd542017-11-13 12:58:41 +0000621 bool _is_global_pooling;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100622};
623
Georgios Pinitas7b7858d2017-06-21 16:44:24 +0100624/** ROI Pooling Layer Information class */
625class ROIPoolingLayerInfo
626{
627public:
628 /** Default Constructor
629 *
630 * @param[in] pooled_width Pooled width of the layer.
631 * @param[in] pooled_height Pooled height of the layer.
632 * @param[in] spatial_scale Spatial scale to be applied to the ROI coordinates and dimensions.
633 */
634 ROIPoolingLayerInfo(unsigned int pooled_width, unsigned int pooled_height, float spatial_scale)
635 : _pooled_width(pooled_width), _pooled_height(pooled_height), _spatial_scale(spatial_scale)
636 {
637 }
638 unsigned int pooled_width() const
639 {
640 return _pooled_width;
641 }
642 unsigned int pooled_height() const
643 {
644 return _pooled_height;
645 }
646 float spatial_scale() const
647 {
648 return _spatial_scale;
649 }
650
651private:
652 unsigned int _pooled_width;
653 unsigned int _pooled_height;
654 float _spatial_scale;
655};
656
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100657/** Activation Layer Information class */
658class ActivationLayerInfo
659{
660public:
661 /** Available activation functions */
662 enum class ActivationFunction
663 {
Georgios Pinitas64ebe5b2017-09-01 17:44:24 +0100664 LOGISTIC, /**< Logistic ( \f$ f(x) = \frac{1}{1 + e^{-x}} \f$ ) */
665 TANH, /**< Hyperbolic tangent ( \f$ f(x) = a \cdot tanh(b \cdot x) \f$ ) */
666 RELU, /**< Rectifier ( \f$ f(x) = max(0,x) \f$ ) */
667 BOUNDED_RELU, /**< Upper Bounded Rectifier ( \f$ f(x) = min(a, max(0,x)) \f$ ) */
668 LU_BOUNDED_RELU, /**< Lower and Upper Bounded Rectifier ( \f$ f(x) = min(a, max(b,x)) \f$ ) */
669 LEAKY_RELU, /**< Leaky Rectifier ( \f$ f(x)= log(1+e^x) \f$ ) */
670 SOFT_RELU, /**< Soft Rectifier ( \f$ f(x)= log(1+e^x) \f$ ) */
671 ABS, /**< Absolute ( \f$ f(x)= |x| \f$ ) */
672 SQUARE, /**< Square ( \f$ f(x)= x^2 \f$ )*/
673 SQRT, /**< Square root ( \f$ f(x) = \sqrt{x} \f$ )*/
674 LINEAR /**< Linear ( \f$ f(x)= ax + b \f$ ) */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100675 };
676
677 /** Default Constructor
678 *
679 * @param[in] f The activation function to use.
680 * @param[in] a (Optional) The alpha parameter used by some activation functions
Georgios Pinitas64ebe5b2017-09-01 17:44:24 +0100681 * (@ref ActivationFunction::BOUNDED_RELU, @ref ActivationFunction::LU_BOUNDED_RELU, @ref ActivationFunction::LINEAR, @ref ActivationFunction::TANH).
682 * @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 +0100683 */
684 ActivationLayerInfo(ActivationFunction f, float a = 0.0f, float b = 0.0f)
685 : _act(f), _a(a), _b(b)
686 {
687 }
688 ActivationFunction activation() const
689 {
690 return _act;
691 }
692 float a() const
693 {
694 return _a;
695 }
696 float b() const
697 {
698 return _b;
699 }
700
701private:
702 ActivationFunction _act;
703 float _a;
704 float _b;
705};
706
707/** Normalization Layer Information class */
708class NormalizationLayerInfo
709{
710public:
711 /** Default Constructor
712 *
713 * @param[in] type The normalization type. Can be @ref NormType::IN_MAP_1D, @ref NormType::IN_MAP_2D or @ref NORM_TYPE::CROSS_MAP
714 * @param[in] norm_size The normalization size is the number of elements to normalize across. Defaults to 5.
Georgios Pinitas41caa622017-11-16 14:37:08 +0000715 * @param[in] alpha (Optional) Alpha parameter used by normalization equation. Defaults to 0.0001.
716 * @param[in] beta (Optional) Beta parameter used by normalization equation. Defaults to 0.5.
717 * @param[in] kappa (Optional) Kappa parameter used by [Krichevksy 2012] Across Channel Local Brightness Normalization equation.
718 * @param[in] is_scaled (Optional) Boolean that specifies if alpha will be scaled by the normalization size or not.
719 * Should be false to follow [Krichevksy 2012].
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100720 */
Georgios Pinitas41caa622017-11-16 14:37:08 +0000721 NormalizationLayerInfo(NormType type, uint32_t norm_size = 5, float alpha = 0.0001f, float beta = 0.5f, float kappa = 1.f, bool is_scaled = true)
722 : _type(type), _norm_size(norm_size), _alpha(alpha), _beta(beta), _kappa(kappa), _is_scaled(is_scaled)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100723 {
724 }
725 NormType type() const
726 {
727 return _type;
728 }
729 uint32_t norm_size() const
730 {
731 return _norm_size;
732 }
733 float alpha() const
734 {
735 return _alpha;
736 }
737 float beta() const
738 {
739 return _beta;
740 }
741 float kappa() const
742 {
743 return _kappa;
744 }
Georgios Pinitas41caa622017-11-16 14:37:08 +0000745 bool is_cross_map() const
746 {
747 return _type == NormType::CROSS_MAP;
748 }
749 bool is_in_map() const
750 {
751 return !is_cross_map();
752 }
753 /** Return the scaling factor of the normalization function.
754 *
755 * If is_scaled is set to false then [Krichevksy 2012] normalization scaling is performed,
756 * where alpha is returned plainly, else alpha is scaled by the total number of elements used for the normalization.
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100757 *
758 * @return The normalization scaling factor.
759 */
760 float scale_coeff() const
761 {
762 const uint32_t size = (_type == NormType::IN_MAP_2D) ? _norm_size * _norm_size : _norm_size;
Georgios Pinitas41caa622017-11-16 14:37:08 +0000763 return (_is_scaled) ? (_alpha / size) : _alpha;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100764 }
765
766private:
767 NormType _type;
768 uint32_t _norm_size;
769 float _alpha;
770 float _beta;
771 float _kappa;
Georgios Pinitas41caa622017-11-16 14:37:08 +0000772 bool _is_scaled;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100773};
774
Gian Marco Iodice559d7712017-08-08 08:38:09 +0100775/** 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 +0100776class WeightsInfo
777{
778public:
Gian Marco Iodice4e288692017-06-27 11:41:59 +0100779 /** Default constructor */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100780 WeightsInfo()
Gian Marco Iodice559d7712017-08-08 08:38:09 +0100781 : _are_reshaped(false), _kernel_width(0), _kernel_height(0), _num_kernels(0)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100782 {
783 }
784 /** Constructor
785 *
Gian Marco Iodice4e288692017-06-27 11:41:59 +0100786 * @param[in] are_reshaped True if the weights have been reshaped
787 * @param[in] kernel_width Kernel width.
788 * @param[in] kernel_height Kernel height.
Gian Marco Iodice559d7712017-08-08 08:38:09 +0100789 * @param[in] num_kernels Number of convolution kernels.
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100790 */
Gian Marco Iodice559d7712017-08-08 08:38:09 +0100791 WeightsInfo(bool are_reshaped, unsigned int kernel_width, unsigned int kernel_height, unsigned int num_kernels)
792 : _are_reshaped(are_reshaped), _kernel_width(kernel_width), _kernel_height(kernel_height), _num_kernels(num_kernels)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100793 {
794 }
Gian Marco Iodice4e288692017-06-27 11:41:59 +0100795 /** Flag which specifies if the weights tensor has been reshaped.
796 *
797 * @return True if the weights tensors has been reshaped
798 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100799 bool are_reshaped() const
800 {
801 return _are_reshaped;
802 };
Gian Marco Iodice559d7712017-08-08 08:38:09 +0100803 /** Return the number of convolution kernels
804 *
805 * @return The number of convolution kernels
806 */
807 unsigned int num_kernels() const
808 {
809 return _num_kernels;
810 };
Gian Marco Iodice4e288692017-06-27 11:41:59 +0100811 /** Return the width and height of the kernel
812 *
813 * @return The width and height of the kernel
814 */
815 std::pair<unsigned int, unsigned int> kernel_size() const
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100816 {
Gian Marco Iodice4e288692017-06-27 11:41:59 +0100817 return std::make_pair(_kernel_width, _kernel_height);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100818 }
819
820private:
821 const bool _are_reshaped;
Gian Marco Iodice4e288692017-06-27 11:41:59 +0100822 const unsigned int _kernel_width;
823 const unsigned int _kernel_height;
Gian Marco Iodice559d7712017-08-08 08:38:09 +0100824 const unsigned int _num_kernels;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100825};
826
827/** IO formatting information class*/
828struct IOFormatInfo
829{
830 /** Precision type used when printing floating point numbers */
831 enum class PrecisionType
832 {
833 Default, /**< Default precision to the one that the current stream has */
834 Custom, /**< Custom precision specified by the user using the precision parameter */
835 Full /**< The maximum precision of the floating point representation */
836 };
837
838 /** Specifies the area to be printed, used by Tensor objects */
839 enum class PrintRegion
840 {
841 ValidRegion, /**< Prints the valid region of the Tensor object */
842 NoPadding, /**< Prints the Tensor object without the padding */
843 Full /**< Print the tensor object including padding */
844 };
845
846 IOFormatInfo(PrintRegion print_region = PrintRegion::ValidRegion,
847 PrecisionType precision_type = PrecisionType::Default,
848 unsigned int precision = 10,
849 bool align_columns = true,
850 std::string element_delim = " ",
851 std::string row_delim = "\n")
852 : print_region(print_region),
853 precision_type(precision_type),
854 precision(precision),
855 element_delim(element_delim),
856 row_delim(row_delim),
857 align_columns(align_columns)
858 {
859 }
860
861 PrintRegion print_region;
862 PrecisionType precision_type;
863 unsigned int precision;
864 std::string element_delim;
865 std::string row_delim;
866 bool align_columns;
867};
868}
869#endif /* __ARM_COMPUTE_TYPES_H__ */