31 template <
typename input_data_type>
33 unsigned int roi_batch,
44 if((region_end_x <= region_start_x) || (region_end_y <= region_start_y))
46 return input_data_type(0);
53 for(
int iy = 0; iy < grid_size_y; ++iy)
55 for(
int ix = 0; ix < grid_size_x; ++ix)
58 float y = region_start_y + (iy + 0.5) * bin_size_y / float(grid_size_y);
59 float x = region_start_x + (ix + 0.5) * bin_size_x / float(grid_size_x);
64 const int y_high = y_low + 1;
65 const int x_high = x_low + 1;
67 const float ly = y - y_low;
68 const float lx = x - x_low;
69 const float hy = 1. - ly;
70 const float hx = 1. - lx;
72 const float w1 = hy * hx;
73 const float w2 = hy * lx;
74 const float w3 = ly * hx;
75 const float w4 = ly * lx;
78 const auto data1 = *
reinterpret_cast<const input_data_type *
>(input->
ptr_to_element(
Coordinates(x_low, y_low, pz, roi_batch)));
79 const auto data2 = *
reinterpret_cast<const input_data_type *
>(input->
ptr_to_element(
Coordinates(x_high, y_low, pz, roi_batch)));
80 const auto data3 = *
reinterpret_cast<const input_data_type *
>(input->
ptr_to_element(
Coordinates(x_low, y_high, pz, roi_batch)));
81 const auto data4 = *
reinterpret_cast<const input_data_type *
>(input->
ptr_to_element(
Coordinates(x_high, y_high, pz, roi_batch)));
82 avg += w1 * data1 + w2 * data2 + w3 * data3 + w4 * data4;
86 const auto data1 = *
reinterpret_cast<const input_data_type *
>(input->
ptr_to_element(
Coordinates(pz, x_low, y_low, roi_batch)));
87 const auto data2 = *
reinterpret_cast<const input_data_type *
>(input->
ptr_to_element(
Coordinates(pz, x_high, y_low, roi_batch)));
88 const auto data3 = *
reinterpret_cast<const input_data_type *
>(input->
ptr_to_element(
Coordinates(pz, x_low, y_high, roi_batch)));
89 const auto data4 = *
reinterpret_cast<const input_data_type *
>(input->
ptr_to_element(
Coordinates(pz, x_high, y_high, roi_batch)));
90 avg += w1 * data1 + w2 * data2 + w3 * data3 + w4 * data4;
95 avg /= grid_size_x * grid_size_y;
96 return input_data_type(avg);
101 template <
typename input_data_type>
103 unsigned int roi_batch,
104 float region_start_x,
108 float region_start_y,
115 if((region_end_x <= region_start_x) || (region_end_y <= region_start_y))
127 for(
int iy = 0; iy < grid_size_y; ++iy)
129 for(
int ix = 0; ix < grid_size_x; ++ix)
132 float y = region_start_y + (iy + 0.5) * bin_size_y / float(grid_size_y);
133 float x = region_start_x + (ix + 0.5) * bin_size_x / float(grid_size_x);
138 const int y_high = y_low + 1;
139 const int x_high = x_low + 1;
141 const float ly = y - y_low;
142 const float lx = x - x_low;
143 const float hy = 1. - ly;
144 const float hx = 1. - lx;
146 const float w1 = hy * hx;
147 const float w2 = hy * lx;
148 const float w3 = ly * hx;
149 const float w4 = ly * lx;
159 avg += w1 * data1 + w2 * data2 + w3 * data3 + w4 * data4;
167 avg += w1 * data1 + w2 * data2 + w3 * data3 + w4 * data4;
178 avg += w1 * data1 + w2 * data2 + w3 * data3 + w4 * data4;
186 avg += w1 * data1 + w2 * data2 + w3 * data3 + w4 * data4;
192 avg /= grid_size_x * grid_size_y;
194 input_data_type res = 0;
208 const float region_start = p * bin_size + roi_anchor;
212 template <
typename input_data_type,
typename roi_data_type>
220 const int roi_list_start = window.
x().
start();
221 const int roi_list_end = window.
x().
end();
229 const int input_chanels = input->
info()->
dimension(idx_depth);
236 const auto *rois_ptr =
reinterpret_cast<const roi_data_type *
>(rois->
buffer());
238 for(
int roi_indx = roi_list_start; roi_indx < roi_list_end; ++roi_indx)
240 const unsigned int roi_batch = rois_ptr[values_per_roi * roi_indx];
242 roi_data_type qx1 = rois_ptr[values_per_roi * roi_indx + 1];
243 roi_data_type qy1 = rois_ptr[values_per_roi * roi_indx + 2];
244 roi_data_type qx2 = rois_ptr[values_per_roi * roi_indx + 3];
245 roi_data_type qy2 = rois_ptr[values_per_roi * roi_indx + 4];
259 const float roi_dims_x = std::max((x2 - x1) * pool_info.
spatial_scale(), 1.0f);
260 const float roi_dims_y = std::max((y2 - y1) * pool_info.
spatial_scale(), 1.0f);
261 float bin_size_x = roi_dims_x / pool_info.
pooled_width();
265 for(
int ch = 0; ch < input_chanels; ++ch)
268 for(
int py = 0; py < pooled_h; ++py)
270 for(
int px = 0; px < pooled_w; ++px)
278 input_data_type out_val(0);
281 out_val = roi_align_1x1_qasymm8<input_data_type>(
282 input, roi_batch, region_start_x, bin_size_x,
283 roi_bin_grid_x, region_end_x, region_start_y, bin_size_y,
288 out_val = roi_align_1x1<input_data_type>(
289 input, roi_batch, region_start_x, bin_size_x,
290 roi_bin_grid_x, region_end_x, region_start_y, bin_size_y,
291 roi_bin_grid_y, region_end_y, ch);
312 #if defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) && defined(ENABLE_FP16_KERNELS) 314 #endif //defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) && defined(ENABLE_FP16_KERNELS)
uint8_t * ptr_to_element(const Coordinates &id) const
Return a pointer to the element at the passed coordinates.
float dequantize_qasymm8(uint8_t value, const INFO_TYPE &qinfo)
Dequantize a value given an unsigned 8-bit asymmetric quantization scheme.
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
uint8_t quantize_qasymm8(float value, const INFO_TYPE &qinfo, RoundingPolicy rounding_policy=RoundingPolicy::TO_NEAREST_UP)
Quantize a value given an unsigned 8-bit asymmetric quantization scheme.
virtual DataType data_type() const =0
Data type used for each element of the tensor.
const size_t input_height
input_data_type roi_align_1x1(const ITensor *input, unsigned int roi_batch, float region_start_x, float bin_size_x, int grid_size_x, float region_end_x, float region_start_y, float bin_size_y, int grid_size_y, float region_end_y, int pz)
Average pooling over an aligned window.
unsigned int pooled_width() const
Get the pooled width of the layer.
Interface for CPU tensor.
Copyright (c) 2017-2023 Arm Limited.
input_data_type roi_align_1x1_qasymm8(const ITensor *input, unsigned int roi_batch, float region_start_x, float bin_size_x, int grid_size_x, float region_end_x, float region_start_y, float bin_size_y, int grid_size_y, float region_end_y, int pz, const QuantizationInfo &out_qinfo)
Average pooling over an aligned window.
DataType clamp(const DataType &n, const DataType &lower=std::numeric_limits< RangeType >::lowest(), const DataType &upper=std::numeric_limits< RangeType >::max())
Performs clamping among a lower and upper value.
float dequantize_qasymm16(uint16_t value, const UniformQuantizationInfo &qinfo)
Dequantize a value given a 16-bit asymmetric quantization scheme.
Quantization information.
float compute_region_coordinate(int p, float bin_size, float roi_anchor, float max_value)
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
template void roi_align< float, float >(const ITensor *input, ITensor *output, const ITensor *rois, ROIPoolingLayerInfo pool_info, const Window &window, const ThreadInfo &info)
int8_t quantize_qasymm8_signed(float value, const INFO_TYPE &qinfo, RoundingPolicy rounding_policy=RoundingPolicy::TO_NEAREST_UP)
Quantize a value given a signed 8-bit asymmetric quantization scheme.
virtual uint8_t * buffer() const =0
Interface to be implemented by the child class to return a pointer to CPU memory. ...
UniformQuantizationInfo uniform() const
Return per layer quantization info.
bool is_data_type_quantized_asymmetric_signed(DataType dt)
Check if a given data type is of asymmetric quantized signed type.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
virtual QuantizationInfo quantization_info() const =0
Get the quantization settings (scale and offset) of the tensor.
unsigned int sampling_ratio() const
Get sampling ratio.
Num samples, channels, height, width.
bool is_data_type_quantized_asymmetric(DataType dt)
Check if a given data type is of asymmetric quantized type.
template void roi_align< int8_t, uint16_t >(const ITensor *input, ITensor *output, const ITensor *rois, ROIPoolingLayerInfo pool_info, const Window &window, const ThreadInfo &info)
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
Information about executing thread and CPU.
unsigned int pooled_height() const
Get the pooled height of the layer.
ROI Pooling Layer Information class.
size_t get_data_layout_dimension_index(const DataLayout &data_layout, const DataLayoutDimension &data_layout_dimension)
Get the index of the given dimension.
float spatial_scale() const
Get the spatial scale.
void roi_align(const ITensor *input, ITensor *output, const ITensor *rois, ROIPoolingLayerInfo pool_info, const Window &window, const ThreadInfo &info)
float dequantize_qasymm8_signed(int8_t value, const INFO_TYPE &qinfo)
Dequantize a value given a signed 8-bit asymmetric quantization scheme.
constexpr int end() const
Return the end of the dimension.
template void roi_align< uint8_t, uint16_t >(const ITensor *input, ITensor *output, const ITensor *rois, ROIPoolingLayerInfo pool_info, const Window &window, const ThreadInfo &info)
DataType
Available data types.
DataLayout
[DataLayout enum definition]
constexpr int start() const
Return the start of the dimension.
Describe a multidimensional execution window.
virtual DataLayout data_layout() const =0
Get the data layout of the tensor.
constexpr const Dimension & x() const
Alias to access the first dimension of the window.