blob: 37f85086745dd032eaedd63806798bf1cc129fee [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
Daniil Efremoveed841c2017-11-09 19:05:25 +0700107 bool operator==(const QuantizationInfo &other)
108 {
109 return scale == other.scale && offset == other.offset;
110 }
111
112 bool operator!=(const QuantizationInfo &other)
113 {
114 return !(*this == other);
115 }
116
Michel Iwaniec00633802017-10-12 14:14:15 +0100117 float scale; /**< scale */
118 int offset; /**< offset */
119
120 /** Quantizes a value using the scale/offset in this QuantizationInfo */
121 uint8_t quantize(float value) const
122 {
123 ARM_COMPUTE_ERROR_ON_MSG(scale == 0, "QuantizationInfo::quantize: scale == 0");
124 int quantized = static_cast<int>(value / scale + offset);
125 quantized = std::max(0, std::min(quantized, 255));
126 return quantized;
127 }
128
129 /** Dequantizes a value using the scale/offset in this QuantizationInfo */
130 float dequantize(uint8_t value) const
131 {
132 ARM_COMPUTE_ERROR_ON_MSG(scale == 0, "QuantizationInfo::dequantize: scale == 0");
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +0000133 float dequantized = (static_cast<int>(value) - offset) * scale;
Michel Iwaniec00633802017-10-12 14:14:15 +0100134 return dequantized;
135 }
136
137 /** Indicates whether this QuantizationInfo has valid settings or not */
138 bool empty() const
139 {
140 return scale == 0;
141 }
142};
143
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100144struct ValidRegion
145{
146 ValidRegion()
147 : anchor{}, shape{}
148 {
149 }
150
151 ValidRegion(const ValidRegion &) = default;
152 ValidRegion(ValidRegion &&) = default;
153 ValidRegion &operator=(const ValidRegion &) = default;
154 ValidRegion &operator=(ValidRegion &&) = default;
155 ~ValidRegion() = default;
156
157 ValidRegion(Coordinates anchor, TensorShape shape)
158 : anchor{ anchor }, shape{ shape }
159 {
160 }
161
162 /** Return the start of the valid region for the given dimension @p d */
163 int start(unsigned int d) const
164 {
165 return anchor[d];
166 }
167
168 /** Return the end of the valid region for the given dimension @p d */
169 int end(unsigned int d) const
170 {
171 return anchor[d] + shape[d];
172 }
173
174 Coordinates anchor;
175 TensorShape shape;
176};
177
178/** Methods available to handle borders */
179enum class BorderMode
180{
181 UNDEFINED, /**< Borders are left undefined */
182 CONSTANT, /**< Pixels outside the image are assumed to have a constant value */
183 REPLICATE /**< Pixels outside the image are assumed to have the same value as the closest image pixel */
184};
185
186/** Container for 2D border size */
187struct BorderSize
188{
189 /** Empty border, i.e. no border */
190 constexpr BorderSize()
191 : top{ 0 }, right{ 0 }, bottom{ 0 }, left{ 0 }
192 {
193 }
194
195 /** Border with equal size around the 2D plane */
Moritz Pflanzer7655a672017-09-23 11:57:33 +0100196 explicit constexpr BorderSize(unsigned int size)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100197 : top{ size }, right{ size }, bottom{ size }, left{ size }
198 {
199 }
200
201 /** Border with same size for top/bottom and left/right */
202 constexpr BorderSize(unsigned int top_bottom, unsigned int left_right)
203 : top{ top_bottom }, right{ left_right }, bottom{ top_bottom }, left{ left_right }
204 {
205 }
206
207 /** Border with different sizes */
208 constexpr BorderSize(unsigned int top, unsigned int right, unsigned int bottom, unsigned int left)
209 : top{ top }, right{ right }, bottom{ bottom }, left{ left }
210 {
211 }
212
213 /** Check if the entire border is zero */
214 constexpr bool empty() const
215 {
216 return top == 0 && right == 0 && bottom == 0 && left == 0;
217 }
218
219 /** Check if the border is the same size on all sides */
220 constexpr bool uniform() const
221 {
222 return top == right && top == bottom && top == left;
223 }
224
225 BorderSize &operator*=(float scale)
226 {
227 top *= scale;
228 right *= scale;
229 bottom *= scale;
230 left *= scale;
231
232 return *this;
233 }
234
235 BorderSize operator*(float scale)
236 {
237 BorderSize size = *this;
238 size *= scale;
239
240 return size;
241 }
242
243 void limit(const BorderSize &limit)
244 {
245 top = std::min(top, limit.top);
246 right = std::min(right, limit.right);
247 bottom = std::min(bottom, limit.bottom);
248 left = std::min(left, limit.left);
249 }
250
251 unsigned int top;
252 unsigned int right;
253 unsigned int bottom;
254 unsigned int left;
255};
256
257using PaddingSize = BorderSize;
258
259/** Policy to handle overflow */
260enum class ConvertPolicy
261{
262 WRAP, /**< Wrap around */
263 SATURATE /**< Saturate */
264};
265
266/** Interpolation method */
267enum class InterpolationPolicy
268{
269 NEAREST_NEIGHBOR, /**< Output values are defined to match the source pixel whose center is nearest to the sample position */
270 BILINEAR, /**< Output values are defined by bilinear interpolation between the pixels */
271 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 */
272};
273
274/** Bilinear Interpolation method used by LKTracker */
275enum class BilinearInterpolation
276{
277 BILINEAR_OLD_NEW,
278 BILINEAR_SCHARR
279};
280
281/** Threshold mode */
282enum class ThresholdType
283{
284 BINARY, /**< Threshold with one value */
285 RANGE /**< Threshold with two values*/
286};
287
288/** Rounding method */
289enum class RoundingPolicy
290{
291 TO_ZERO, /**< Truncates the least significand values that are lost in operations. */
292 TO_NEAREST_UP, /**< Rounds to nearest value; half rounds up */
293 TO_NEAREST_EVEN /**< Rounds to nearest value; half rounds to nearest even */
294};
295
296/** Termination criteria */
297enum class Termination
298{
299 TERM_CRITERIA_EPSILON,
300 TERM_CRITERIA_ITERATIONS,
301 TERM_CRITERIA_BOTH
302};
303
304/** Magnitude calculation type. */
305enum class MagnitudeType
306{
307 L1NORM, /**< L1 normalization type */
308 L2NORM /**< L2 normalization type */
309};
310
311/** Phase calculation type.
312 *
313 * @note When PhaseType == SIGNED, each angle is mapped to the range 0 to 255 inclusive otherwise angles between 0 and 180
314 */
315enum class PhaseType
316{
317 SIGNED, /**< Angle range: [0, 360] */
318 UNSIGNED /**< Angle range: [0, 180] */
319};
320
321/** Keypoint type */
322struct KeyPoint
323{
324 int32_t x{ 0 }; /**< X coordinates */
325 int32_t y{ 0 }; /**< Y coordinates */
326 float strength{ 0.f }; /**< Strength of the point */
327 float scale{ 0.f }; /**< Scale initialized to 0 by the corner detector */
328 float orientation{ 0.f }; /**< Orientation initialized to 0 by the corner detector */
329 int32_t tracking_status{ 0 }; /**< Status initialized to 1 by the corner detector, set to 0 when the point is lost */
330 float error{ 0.f }; /**< Tracking error initialized to 0 by the corner detector */
331};
332
333using InternalKeypoint = std::tuple<float, float, float>; /* x,y,strength */
334
335/** Rectangle type */
336struct Rectangle
337{
338 uint16_t x; /**< Top-left x coordinate */
339 uint16_t y; /**< Top-left y coordinate */
340 uint16_t width; /**< Width of the rectangle */
341 uint16_t height; /**< Height of the rectangle */
342};
343
344/** Coordinate type */
345struct Coordinates2D
346{
347 int32_t x; /**< X coordinates */
348 int32_t y; /**< Y coordinates */
349};
350
351/** Coordinate type */
352struct Coordinates3D
353{
354 uint32_t x; /**< X coordinates */
355 uint32_t y; /**< Y coordinates */
356 uint32_t z; /**< Z coordinates */
357};
358
Georgios Pinitas7b7858d2017-06-21 16:44:24 +0100359/** Region of interest */
360struct ROI
361{
362 Rectangle rect; /**< Rectangle specifying the region of interest */
363 uint16_t batch_idx; /**< The batch index of the region of interest */
364};
365
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100366/** Available channels */
367enum class Channel
368{
369 UNKNOWN, /** Unknown channel format */
370 C0, /**< First channel (used by formats with unknown channel types). */
371 C1, /**< Second channel (used by formats with unknown channel types). */
372 C2, /**< Third channel (used by formats with unknown channel types). */
373 C3, /**< Fourth channel (used by formats with unknown channel types). */
374 R, /**< Red channel. */
375 G, /**< Green channel. */
376 B, /**< Blue channel. */
377 A, /**< Alpha channel. */
378 Y, /**< Luma channel. */
379 U, /**< Cb/U channel. */
380 V /**< Cr/V/Value channel. */
381};
382
383/** Available matrix patterns */
384enum class MatrixPattern
385{
386 BOX, /**< Box pattern matrix. */
387 CROSS, /**< Cross pattern matrix. */
388 DISK, /**< Disk pattern matrix. */
389 OTHER /**< Any other matrix pattern. */
390};
391
392/** Available non linear functions. */
393enum class NonLinearFilterFunction : unsigned
394{
395 MEDIAN = 0, /**< Non linear median filter. */
396 MIN = 1, /**< Non linear erode. */
397 MAX = 2, /**< Non linear dilate. */
398};
399
Georgios Pinitasd9769582017-08-03 10:19:40 +0100400/** Available reduction operations */
401enum class ReductionOperation
402{
403 SUM_SQUARE, /**< Sum of squares */
Michalis Spyrou04f089c2017-08-08 17:42:38 +0100404 SUM, /**< Sum */
Georgios Pinitasd9769582017-08-03 10:19:40 +0100405};
406
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100407/** The normalization type used for the normalization layer */
408enum class NormType
409{
410 IN_MAP_1D, /**< Normalization applied within the same map in 1D region */
411 IN_MAP_2D, /**< Normalization applied within the same map in 2D region */
412 CROSS_MAP /**< Normalization applied cross maps */
413};
414
415/** Normalization type for Histogram of Oriented Gradients (HOG) */
416enum class HOGNormType
417{
418 L2_NORM = 1, /**< L2-norm */
419 L2HYS_NORM = 2, /**< L2-norm followed by clipping */
420 L1_NORM = 3 /**< L1 norm */
421};
422
423/** Detection window used for the object detection. The detection window keeps the following information:
424 *
425 * -# Geometry of the rectangular window (x/y of top-left corner and width/height)
426 * -# Index of the class used for evaluating which class the detection window belongs to
427 * -# Confidence value (score) obtained with the classifier
428 */
429struct DetectionWindow
430{
431 uint16_t x{ 0 }; /**< Top-left x coordinate */
432 uint16_t y{ 0 }; /**< Top-left y coordinate */
433 uint16_t width{ 0 }; /**< Width of the detection window */
434 uint16_t height{ 0 }; /**< Height of the detection window */
435 uint16_t idx_class{ 0 }; /**< Index of the class */
436 float score{ 0.f }; /**< Confidence value for the detection window */
437};
438
439/** Dimension rounding type when down-scaling on CNNs
440 * @note Used in pooling and convolution layer
441 */
442enum class DimensionRoundingType
443{
444 FLOOR, /**< Floor rounding */
445 CEIL /**< Ceil rounding */
446};
447
448/** Available pooling types */
449enum class PoolingType
450{
451 MAX, /**< Max Pooling */
Georgios Pinitascdf51452017-08-31 14:21:36 +0100452 AVG, /**< Average Pooling */
453 L2 /**< L2 Pooling */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100454};
455
456/** Padding and stride information class */
457class PadStrideInfo
458{
459public:
460 /** Constructor
461 *
462 * @param[in] stride_x (Optional) Stride, in elements, across x. Defaults to 1.
463 * @param[in] stride_y (Optional) Stride, in elements, across y. Defaults to 1.
464 * @param[in] pad_x (Optional) Padding, in elements, across x. Defaults to 0.
465 * @param[in] pad_y (Optional) Padding, in elements, across y. Defaults to 0.
466 * @param[in] round (Optional) Dimensions rounding. Defaults to @ref FLOOR.
467 */
468 PadStrideInfo(unsigned int stride_x = 1, unsigned int stride_y = 1,
469 unsigned int pad_x = 0, unsigned int pad_y = 0,
470 DimensionRoundingType round = DimensionRoundingType::FLOOR)
471 : _stride(std::make_pair(stride_x, stride_y)),
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100472 _pad_left(pad_x),
473 _pad_top(pad_y),
474 _pad_right(pad_x),
475 _pad_bottom(pad_y),
476 _round_type(round)
477 {
478 }
479 /** Constructor
480 *
481 * @param[in] stride_x Stride, in elements, across x.
482 * @param[in] stride_y Stride, in elements, across y.
483 * @param[in] pad_left Padding across x on the left, in elements.
484 * @param[in] pad_top Padding across y on the top, in elements.
485 * @param[in] pad_right Padding across x on the right, in elements.
486 * @param[in] pad_bottom Padding across y on the bottom, in elements.
487 * @param[in] round Dimensions rounding.
488 */
489 PadStrideInfo(unsigned int stride_x, unsigned int stride_y,
490 unsigned int pad_left, unsigned int pad_right,
491 unsigned int pad_top, unsigned int pad_bottom,
492 DimensionRoundingType round)
493 : _stride(std::make_pair(stride_x, stride_y)),
494 _pad_left(pad_left),
495 _pad_top(pad_top),
496 _pad_right(pad_right),
497 _pad_bottom(pad_bottom),
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100498 _round_type(round)
499 {
500 }
501 std::pair<unsigned int, unsigned int> stride() const
502 {
503 return _stride;
504 }
505 std::pair<unsigned int, unsigned int> pad() const
506 {
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100507 //this accessor should be used only when padding is symmetric
508 ARM_COMPUTE_ERROR_ON(_pad_left != _pad_right || _pad_top != _pad_bottom);
509 return std::make_pair(_pad_left, _pad_top);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100510 }
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100511
512 unsigned int pad_left() const
513 {
514 return _pad_left;
515 }
516 unsigned int pad_right() const
517 {
518 return _pad_right;
519 }
520 unsigned int pad_top() const
521 {
522 return _pad_top;
523 }
524 unsigned int pad_bottom() const
525 {
526 return _pad_bottom;
527 }
528
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100529 DimensionRoundingType round() const
530 {
531 return _round_type;
532 }
533
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100534 bool has_padding() const
535 {
536 return (_pad_left != 0 || _pad_top != 0 || _pad_right != 0 || _pad_bottom != 0);
537 }
538
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100539private:
540 std::pair<unsigned int, unsigned int> _stride;
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100541 unsigned int _pad_left;
542 unsigned int _pad_top;
543 unsigned int _pad_right;
544 unsigned int _pad_bottom;
545
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100546 DimensionRoundingType _round_type;
547};
548
549/** Pooling Layer Information class */
550class PoolingLayerInfo
551{
552public:
Georgios Pinitas4c2dd542017-11-13 12:58:41 +0000553 /** Default Constructor */
554 PoolingLayerInfo()
555 : _pool_type(PoolingType::MAX), _pool_size(0), _pad_stride_info(PadStrideInfo()), _exclude_padding(false), _is_global_pooling(false)
556 {
557 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100558 /** Default Constructor
559 *
Georgios Pinitas4c2dd542017-11-13 12:58:41 +0000560 * @param[in] pool_type Pooling type @ref PoolingType.
561 * @param[in] pool_size Pooling size, in elements, across x and y.
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100562 * @param[in] pad_stride_info (Optional) Padding and stride information @ref PadStrideInfo
Georgios Pinitasadaae7e2017-10-30 15:56:32 +0000563 * @param[in] exclude_padding (Optional) Strategy when accounting padding in calculations.
564 * True will exclude padding while false will not (Used in AVG/L2 pooling to determine the pooling area).
565 * Defaults to false;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100566 */
Georgios Pinitas4c2dd542017-11-13 12:58:41 +0000567 explicit PoolingLayerInfo(PoolingType pool_type,
568 unsigned int pool_size,
569 PadStrideInfo pad_stride_info = PadStrideInfo(),
570 bool exclude_padding = false)
571 : _pool_type(pool_type), _pool_size(pool_size), _pad_stride_info(pad_stride_info), _exclude_padding(exclude_padding), _is_global_pooling(false)
572 {
573 }
574 /** Default Constructor
575 *
576 * @note This constructor is used for global pooling
577 *
578 * @param[in] pool_type Pooling type @ref PoolingType.
579 */
580 explicit PoolingLayerInfo(PoolingType pool_type)
581 : _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 +0100582 {
583 }
584 PoolingType pool_type() const
585 {
586 return _pool_type;
587 }
588 unsigned int pool_size() const
589 {
590 return _pool_size;
591 }
592 PadStrideInfo pad_stride_info() const
593 {
594 return _pad_stride_info;
595 }
Georgios Pinitasadaae7e2017-10-30 15:56:32 +0000596 bool exclude_padding() const
597 {
598 return _exclude_padding;
599 }
Georgios Pinitas4c2dd542017-11-13 12:58:41 +0000600 bool is_global_pooling() const
601 {
602 return _is_global_pooling;
603 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100604
605private:
606 PoolingType _pool_type;
607 unsigned int _pool_size;
608 PadStrideInfo _pad_stride_info;
Georgios Pinitasadaae7e2017-10-30 15:56:32 +0000609 bool _exclude_padding;
Georgios Pinitas4c2dd542017-11-13 12:58:41 +0000610 bool _is_global_pooling;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100611};
612
Georgios Pinitas7b7858d2017-06-21 16:44:24 +0100613/** ROI Pooling Layer Information class */
614class ROIPoolingLayerInfo
615{
616public:
617 /** Default Constructor
618 *
619 * @param[in] pooled_width Pooled width of the layer.
620 * @param[in] pooled_height Pooled height of the layer.
621 * @param[in] spatial_scale Spatial scale to be applied to the ROI coordinates and dimensions.
622 */
623 ROIPoolingLayerInfo(unsigned int pooled_width, unsigned int pooled_height, float spatial_scale)
624 : _pooled_width(pooled_width), _pooled_height(pooled_height), _spatial_scale(spatial_scale)
625 {
626 }
627 unsigned int pooled_width() const
628 {
629 return _pooled_width;
630 }
631 unsigned int pooled_height() const
632 {
633 return _pooled_height;
634 }
635 float spatial_scale() const
636 {
637 return _spatial_scale;
638 }
639
640private:
641 unsigned int _pooled_width;
642 unsigned int _pooled_height;
643 float _spatial_scale;
644};
645
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100646/** Activation Layer Information class */
647class ActivationLayerInfo
648{
649public:
650 /** Available activation functions */
651 enum class ActivationFunction
652 {
Georgios Pinitas64ebe5b2017-09-01 17:44:24 +0100653 LOGISTIC, /**< Logistic ( \f$ f(x) = \frac{1}{1 + e^{-x}} \f$ ) */
654 TANH, /**< Hyperbolic tangent ( \f$ f(x) = a \cdot tanh(b \cdot x) \f$ ) */
655 RELU, /**< Rectifier ( \f$ f(x) = max(0,x) \f$ ) */
656 BOUNDED_RELU, /**< Upper Bounded Rectifier ( \f$ f(x) = min(a, max(0,x)) \f$ ) */
657 LU_BOUNDED_RELU, /**< Lower and Upper Bounded Rectifier ( \f$ f(x) = min(a, max(b,x)) \f$ ) */
658 LEAKY_RELU, /**< Leaky Rectifier ( \f$ f(x)= log(1+e^x) \f$ ) */
659 SOFT_RELU, /**< Soft Rectifier ( \f$ f(x)= log(1+e^x) \f$ ) */
660 ABS, /**< Absolute ( \f$ f(x)= |x| \f$ ) */
661 SQUARE, /**< Square ( \f$ f(x)= x^2 \f$ )*/
662 SQRT, /**< Square root ( \f$ f(x) = \sqrt{x} \f$ )*/
663 LINEAR /**< Linear ( \f$ f(x)= ax + b \f$ ) */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100664 };
665
666 /** Default Constructor
667 *
668 * @param[in] f The activation function to use.
669 * @param[in] a (Optional) The alpha parameter used by some activation functions
Georgios Pinitas64ebe5b2017-09-01 17:44:24 +0100670 * (@ref ActivationFunction::BOUNDED_RELU, @ref ActivationFunction::LU_BOUNDED_RELU, @ref ActivationFunction::LINEAR, @ref ActivationFunction::TANH).
671 * @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 +0100672 */
673 ActivationLayerInfo(ActivationFunction f, float a = 0.0f, float b = 0.0f)
674 : _act(f), _a(a), _b(b)
675 {
676 }
677 ActivationFunction activation() const
678 {
679 return _act;
680 }
681 float a() const
682 {
683 return _a;
684 }
685 float b() const
686 {
687 return _b;
688 }
689
690private:
691 ActivationFunction _act;
692 float _a;
693 float _b;
694};
695
696/** Normalization Layer Information class */
697class NormalizationLayerInfo
698{
699public:
700 /** Default Constructor
701 *
702 * @param[in] type The normalization type. Can be @ref NormType::IN_MAP_1D, @ref NormType::IN_MAP_2D or @ref NORM_TYPE::CROSS_MAP
703 * @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 +0000704 * @param[in] alpha (Optional) Alpha parameter used by normalization equation. Defaults to 0.0001.
705 * @param[in] beta (Optional) Beta parameter used by normalization equation. Defaults to 0.5.
706 * @param[in] kappa (Optional) Kappa parameter used by [Krichevksy 2012] Across Channel Local Brightness Normalization equation.
707 * @param[in] is_scaled (Optional) Boolean that specifies if alpha will be scaled by the normalization size or not.
708 * Should be false to follow [Krichevksy 2012].
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100709 */
Georgios Pinitas41caa622017-11-16 14:37:08 +0000710 NormalizationLayerInfo(NormType type, uint32_t norm_size = 5, float alpha = 0.0001f, float beta = 0.5f, float kappa = 1.f, bool is_scaled = true)
711 : _type(type), _norm_size(norm_size), _alpha(alpha), _beta(beta), _kappa(kappa), _is_scaled(is_scaled)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100712 {
713 }
714 NormType type() const
715 {
716 return _type;
717 }
718 uint32_t norm_size() const
719 {
720 return _norm_size;
721 }
722 float alpha() const
723 {
724 return _alpha;
725 }
726 float beta() const
727 {
728 return _beta;
729 }
730 float kappa() const
731 {
732 return _kappa;
733 }
Georgios Pinitas41caa622017-11-16 14:37:08 +0000734 bool is_cross_map() const
735 {
736 return _type == NormType::CROSS_MAP;
737 }
738 bool is_in_map() const
739 {
740 return !is_cross_map();
741 }
742 /** Return the scaling factor of the normalization function.
743 *
744 * If is_scaled is set to false then [Krichevksy 2012] normalization scaling is performed,
745 * 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 +0100746 *
747 * @return The normalization scaling factor.
748 */
749 float scale_coeff() const
750 {
751 const uint32_t size = (_type == NormType::IN_MAP_2D) ? _norm_size * _norm_size : _norm_size;
Georgios Pinitas41caa622017-11-16 14:37:08 +0000752 return (_is_scaled) ? (_alpha / size) : _alpha;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100753 }
754
755private:
756 NormType _type;
757 uint32_t _norm_size;
758 float _alpha;
759 float _beta;
760 float _kappa;
Georgios Pinitas41caa622017-11-16 14:37:08 +0000761 bool _is_scaled;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100762};
763
Gian Marco Iodice559d7712017-08-08 08:38:09 +0100764/** 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 +0100765class WeightsInfo
766{
767public:
Gian Marco Iodice4e288692017-06-27 11:41:59 +0100768 /** Default constructor */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100769 WeightsInfo()
Gian Marco Iodice559d7712017-08-08 08:38:09 +0100770 : _are_reshaped(false), _kernel_width(0), _kernel_height(0), _num_kernels(0)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100771 {
772 }
773 /** Constructor
774 *
Gian Marco Iodice4e288692017-06-27 11:41:59 +0100775 * @param[in] are_reshaped True if the weights have been reshaped
776 * @param[in] kernel_width Kernel width.
777 * @param[in] kernel_height Kernel height.
Gian Marco Iodice559d7712017-08-08 08:38:09 +0100778 * @param[in] num_kernels Number of convolution kernels.
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100779 */
Gian Marco Iodice559d7712017-08-08 08:38:09 +0100780 WeightsInfo(bool are_reshaped, unsigned int kernel_width, unsigned int kernel_height, unsigned int num_kernels)
781 : _are_reshaped(are_reshaped), _kernel_width(kernel_width), _kernel_height(kernel_height), _num_kernels(num_kernels)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100782 {
783 }
Gian Marco Iodice4e288692017-06-27 11:41:59 +0100784 /** Flag which specifies if the weights tensor has been reshaped.
785 *
786 * @return True if the weights tensors has been reshaped
787 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100788 bool are_reshaped() const
789 {
790 return _are_reshaped;
791 };
Gian Marco Iodice559d7712017-08-08 08:38:09 +0100792 /** Return the number of convolution kernels
793 *
794 * @return The number of convolution kernels
795 */
796 unsigned int num_kernels() const
797 {
798 return _num_kernels;
799 };
Gian Marco Iodice4e288692017-06-27 11:41:59 +0100800 /** Return the width and height of the kernel
801 *
802 * @return The width and height of the kernel
803 */
804 std::pair<unsigned int, unsigned int> kernel_size() const
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100805 {
Gian Marco Iodice4e288692017-06-27 11:41:59 +0100806 return std::make_pair(_kernel_width, _kernel_height);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100807 }
808
809private:
810 const bool _are_reshaped;
Gian Marco Iodice4e288692017-06-27 11:41:59 +0100811 const unsigned int _kernel_width;
812 const unsigned int _kernel_height;
Gian Marco Iodice559d7712017-08-08 08:38:09 +0100813 const unsigned int _num_kernels;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100814};
815
816/** IO formatting information class*/
817struct IOFormatInfo
818{
819 /** Precision type used when printing floating point numbers */
820 enum class PrecisionType
821 {
822 Default, /**< Default precision to the one that the current stream has */
823 Custom, /**< Custom precision specified by the user using the precision parameter */
824 Full /**< The maximum precision of the floating point representation */
825 };
826
827 /** Specifies the area to be printed, used by Tensor objects */
828 enum class PrintRegion
829 {
830 ValidRegion, /**< Prints the valid region of the Tensor object */
831 NoPadding, /**< Prints the Tensor object without the padding */
832 Full /**< Print the tensor object including padding */
833 };
834
835 IOFormatInfo(PrintRegion print_region = PrintRegion::ValidRegion,
836 PrecisionType precision_type = PrecisionType::Default,
837 unsigned int precision = 10,
838 bool align_columns = true,
839 std::string element_delim = " ",
840 std::string row_delim = "\n")
841 : print_region(print_region),
842 precision_type(precision_type),
843 precision(precision),
844 element_delim(element_delim),
845 row_delim(row_delim),
846 align_columns(align_columns)
847 {
848 }
849
850 PrintRegion print_region;
851 PrecisionType precision_type;
852 unsigned int precision;
853 std::string element_delim;
854 std::string row_delim;
855 bool align_columns;
856};
857}
858#endif /* __ARM_COMPUTE_TYPES_H__ */