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