40 template <typename T, typename ACC_T, typename std::enable_if<is_floating_point<T>::value,
int>
::type>
62 const auto w_src =
static_cast<int>(src.
shape()[0]);
63 const auto h_src =
static_cast<int>(src.
shape()[1]);
64 const auto z_src =
static_cast<int>(src.
shape()[2]);
65 const auto b_src =
static_cast<int>(src.
shape()[3]);
67 const int upper_dims = src.
shape().total_size() / (w_src * h_src);
69 const auto w_dst =
static_cast<int>(
dst.shape()[0]);
70 const auto h_dst =
static_cast<int>(
dst.shape()[1]);
71 const auto z_dst =
static_cast<int>(
dst.shape()[2]);
77 for(
int b = 0;
b < b_src; ++
b)
79 for(
int r = 0; r < z_src; ++r)
81 for(
int h = 0; h < h_dst; ++h)
83 for(
int w = 0;
w < w_dst; ++
w)
85 int wstart =
w * pool_stride_x - pad_left;
86 int hstart = h * pool_stride_y - pad_top;
87 int wend = std::min(wstart + pool_size_x, w_src);
88 int hend = std::min(hstart + pool_size_y, h_src);
89 wstart = std::max(wstart, 0);
90 hstart = std::max(hstart, 0);
93 for(
int y = hstart; y < hend; ++y)
95 for(
int x = wstart; x < wend; ++x)
97 const auto val =
static_cast<ACC_T
>(src[
b * z_src * h_src * w_src + r * h_src * w_src + y * w_src + x]);
113 dst[
b * z_dst * h_dst * w_dst + r * h_dst * w_dst + h * w_dst +
w] =
static_cast<T
>(max_val);
116 (*indices)[
b * z_dst * h_dst * w_dst + r * h_dst * w_dst + h * w_dst +
w] = max_index;
125 for(
int r = 0; r < upper_dims; ++r)
127 for(
int h = 0; h < h_dst; ++h)
129 for(
int w = 0;
w < w_dst; ++
w)
132 int wstart =
w * pool_stride_x - pad_left;
133 int hstart = h * pool_stride_y - pad_top;
134 int wend = std::min(wstart + pool_size_x, w_src + pad_right);
135 int hend = std::min(hstart + pool_size_y, h_src + pad_bottom);
136 int pool = (hend - hstart) * (wend - wstart);
137 wstart = std::max(wstart, 0);
138 hstart = std::max(hstart, 0);
139 wend = std::min(wend, w_src);
140 hend = std::min(hend, h_src);
144 pool = (hend - hstart) * (wend - wstart);
149 for(
int y = hstart; y < hend; ++y)
151 for(
int x = wstart; x < wend; ++x)
153 avg_val +=
static_cast<ACC_T
>(src[r * h_src * w_src + y * w_src + x]);
156 dst[r * h_dst * w_dst + h * w_dst +
w] = avg_val / pool;
160 for(
int y = hstart; y < hend; ++y)
162 for(
int x = wstart; x < wend; ++x)
164 const auto val =
static_cast<ACC_T
>(src[r * h_src * w_src + y * w_src + x]);
165 avg_val += val * val;
168 dst[r * h_dst * w_dst + h * w_dst +
w] =
static_cast<T
>(std::sqrt(avg_val / pool));
183 template <
typename T>
DataType data_type() const override
Data type of the tensor.
Strides PermutationVector
Permutation vector.
SimpleTensor< T > permute(const SimpleTensor< T > &src, PermutationVector perm)
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
const DataLayout data_layout
SimpleTensor< float > convert_from_asymmetric(const SimpleTensor< uint8_t > &src)
TensorShape shape() const override
Shape of the tensor.
unsigned int pad_top() const
Get the top padding.
decltype(strategy::transforms) typedef type
SimpleTensor< float > src
Copyright (c) 2017-2021 Arm Limited.
int coord2index(const TensorShape &shape, const Coordinates &coord)
Linearise the given coordinate.
size_t height
Height of the image region or rectangle.
1 channel, 1 F16 per channel
TensorShape compute_pool_shape(const ITensorInfo &input, PoolingLayerInfo pool_info)
Calculate the output pool shape of a tensor.
template SimpleTensor< half > pooling_layer_internal< half >(const SimpleTensor< half > &src, const PoolingLayerInfo &info, SimpleTensor< uint32_t > *indices, DataLayout data_layout)
Quantization information.
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
1 channel, 1 U32 per channel
std::pair< unsigned int, unsigned int > stride() const
Get the stride.
Pooling Layer Information struct.
unsigned int pad_right() const
Get the right padding.
template SimpleTensor< float > pooling_layer_internal< float >(const SimpleTensor< float > &src, const PoolingLayerInfo &info, SimpleTensor< uint32_t > *indices, DataLayout data_layout)
template SimpleTensor< half > pooling_layer_internal< half, float >(const SimpleTensor< half > &src, const PoolingLayerInfo &info, SimpleTensor< uint32_t > *indices, DataLayout data_layout)
SimpleTensor< uint8_t > pooling_layer< uint8_t >(const SimpleTensor< uint8_t > &src, const PoolingLayerInfo &info, const QuantizationInfo &output_qinfo, SimpleTensor< uint32_t > *indices, DataLayout data_layout)
Num samples, channels, height, width.
Simple tensor object that stores elements in a consecutive chunk of memory.
SimpleTensor< T > pooling_layer_internal(const SimpleTensor< T > &src, const PoolingLayerInfo &info, SimpleTensor< uint32_t > *indices, DataLayout data_layout)
PoolingType
Available pooling types.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
PadStrideInfo pad_stride_info
SimpleTensor< int8_t > pooling_layer< int8_t >(const SimpleTensor< int8_t > &src, const PoolingLayerInfo &info, const QuantizationInfo &output_qinfo, SimpleTensor< uint32_t > *indices, DataLayout data_layout)
size_t width
Width of the image region or rectangle.
SimpleTensor< T > pooling_layer(const SimpleTensor< T > &src, const PoolingLayerInfo &info, const QuantizationInfo &output_qinfo, SimpleTensor< uint32_t > *indices, DataLayout data_layout)
Store the tensor's metadata.
unsigned int pad_bottom() const
Get the bottom padding.
unsigned int pad_left() const
Get the left padding.
DataLayout
[DataLayout enum definition]