41 template <typename T, typename std::enable_if<is_floating_point<T>::value,
int>::type>
60 const auto w_src =
static_cast<int>(src.
shape()[0]);
61 const auto h_src =
static_cast<int>(src.
shape()[1]);
62 const int upper_dims = src.
shape().total_size() / (w_src * h_src);
64 const auto w_dst =
static_cast<int>(
dst.shape()[0]);
65 const auto h_dst =
static_cast<int>(
dst.shape()[1]);
69 for(
int r = 0; r < upper_dims; ++r)
71 for(
int h = 0; h < h_dst; ++h)
73 for(
int w = 0; w < w_dst; ++w)
75 int wstart = w * pool_stride_x - pad_left;
76 int hstart = h * pool_stride_y - pad_top;
77 int wend =
std::min(wstart + pool_size_x, w_src);
78 int hend =
std::min(hstart + pool_size_y, h_src);
82 T max_val = std::numeric_limits<T>::lowest();
83 for(
int y = hstart; y < hend; ++y)
85 for(
int x = wstart; x < wend; ++x)
87 const T val = src[r * h_src * w_src + y * w_src + x];
95 dst[r * h_dst * w_dst + h * w_dst + w] = max_val;
102 for(
int r = 0; r < upper_dims; ++r)
104 for(
int h = 0; h < h_dst; ++h)
106 for(
int w = 0; w < w_dst; ++w)
109 int wstart = w * pool_stride_x - pad_left;
110 int hstart = h * pool_stride_y - pad_top;
111 int wend =
std::min(wstart + pool_size_x, w_src + pad_right);
112 int hend =
std::min(hstart + pool_size_y, h_src + pad_bottom);
113 int pool = (hend - hstart) * (wend - wstart);
121 pool = (hend - hstart) * (wend - wstart);
126 for(
int y = hstart; y < hend; ++y)
128 for(
int x = wstart; x < wend; ++x)
130 avg_val += src[r * h_src * w_src + y * w_src + x];
133 dst[r * h_dst * w_dst + h * w_dst + w] = avg_val / pool;
137 for(
int y = hstart; y < hend; ++y)
139 for(
int x = wstart; x < wend; ++x)
141 const T val = src[r * h_src * w_src + y * w_src + x];
142 avg_val += val * val;
145 dst[r * h_dst * w_dst + h * w_dst + w] = std::sqrt(avg_val / pool);
155 template <typename T, typename std::enable_if<std::is_integral<T>::value,
int>::type>
160 const auto w_src =
static_cast<int>(src.
shape()[0]);
161 const auto h_src =
static_cast<int>(src.
shape()[1]);
162 const int upper_dims = src.
shape().total_size() / (w_src * h_src);
178 const auto w_dst =
static_cast<int>(
dst.shape()[0]);
179 const auto h_dst =
static_cast<int>(
dst.shape()[1]);
183 for(
int r = 0; r < upper_dims; ++r)
185 for(
int h = 0; h < h_dst; ++h)
187 for(
int w = 0; w < w_dst; ++w)
189 int wstart = w * pool_stride_x - pad_left;
190 int hstart = h * pool_stride_y - pad_top;
191 int wend =
std::min(wstart + pool_size_x, w_src);
192 int hend =
std::min(hstart + pool_size_y, h_src);
196 T max_val = std::numeric_limits<T>::lowest();
197 for(
int y = hstart; y < hend; ++y)
199 for(
int x = wstart; x < wend; ++x)
201 const T val = src[r * h_src * w_src + y * w_src + x];
209 dst[r * h_dst * w_dst + h * w_dst + w] = max_val;
216 for(
int r = 0; r < upper_dims; ++r)
218 for(
int h = 0; h < h_dst; ++h)
220 for(
int w = 0; w < w_dst; ++w)
222 int wstart = w * pool_stride_x - pad_left;
223 int hstart = h * pool_stride_y - pad_top;
224 int wend =
std::min(wstart + pool_size_x, w_src + pad_right);
225 int hend =
std::min(hstart + pool_size_y, h_src + pad_bottom);
226 int pool = (hend - hstart) * (wend - wstart);
234 pool = (hend - hstart) * (wend - wstart);
237 using namespace fixed_point_arithmetic;
240 const fixed_point<T> const_1(1, fixed_point_position);
241 const fixed_point<T> invpool_fp(1.f / static_cast<float>(pool), fixed_point_position);
242 fixed_point<T> avg_val(0, fixed_point_position,
true);
246 for(
int y = hstart; y < hend; ++y)
248 for(
int x = wstart; x < wend; ++x)
250 const fixed_point<T> in_fp(src[r * h_src * w_src + y * w_src + x], fixed_point_position,
true);
251 avg_val =
add(avg_val, in_fp);
254 dst[r * h_dst * w_dst + h * w_dst + w] =
mul(avg_val, invpool_fp).raw();
258 for(
int y = hstart; y < hend; ++y)
260 for(
int x = wstart; x < wend; ++x)
262 const fixed_point<T> in_fp(src[r * h_src * w_src + y * w_src + x], fixed_point_position,
true);
263 avg_val =
add(avg_val,
mul(in_fp, in_fp));
267 dst[r * h_dst * w_dst + h * w_dst + w] = res.raw();
fixed_point< T > mul(fixed_point< T > x, fixed_point< T > y)
fixed_point< T > min(fixed_point< T > x, fixed_point< T > y)
const Size2D & pool_size() const
Get the pooling size.
DataType data_type() const override
Data type of the tensor.
PadStrideInfo pad_stride_info() const
Get the padding and stride.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
TensorShape shape() const override
Shape of the tensor.
src info() -> set_format(Format::S16)
This file contains all available output stages for GEMMLowp on OpenCL.
size_t height
Height of the image region or rectangle.
bool exclude_padding() const
Check if padding is excluded in calculations.
fixed_point< T > add(fixed_point< T > x, fixed_point< T > y)
TensorShape compute_pool_shape(const ITensorInfo &input, PoolingLayerInfo pool_info)
SimpleTensor< uint8_t > convert_to_asymmetric(const SimpleTensor< float > &src, const QuantizationInfo &quantization_info)
Convert float simple tensor into quantized using specified quantization information.
SimpleTensor< uint8_t > pooling_layer< uint8_t >(const SimpleTensor< uint8_t > &src, const PoolingLayerInfo &info)
SimpleTensor< T > pooling_layer(const SimpleTensor< T > &src, const PoolingLayerInfo &info)
std::pair< unsigned int, unsigned int > stride() const
Get the stride.
unsigned int pad_bottom() const
Get the bottom padding.
fixed_point< T > inv_sqrt(fixed_point< T > x)
unsigned int pad_right() const
Get the right padding.
Simple tensor object that stores elements in a consecutive chunk of memory.
PoolingType
Available pooling types.
size_t width
Width of the image region or rectangle.
unsigned int pad_left() const
Get the left padding.
PoolingType pool_type() const
Get the pooling type.
SimpleTensor< float > convert_from_asymmetric(const SimpleTensor< uint8_t > &src)
Convert quantized simple tensor into float using tensor quantization information. ...
fixed_point< T > div(fixed_point< T > x, fixed_point< T > y)
Store the tensor's metadata.
fixed_point< T > max(fixed_point< T > x, fixed_point< T > y)
QuantizationInfo quantization_info() const override
Quantization info in case of asymmetric quantized type.
bool is_global_pooling() const
Check if is global pooling.
Pooling Layer Information class.
int fixed_point_position() const override
Number of bits for the fractional part.
convolution configure & src
unsigned int pad_top() const
Get the top padding.