45 Status
validate_arguments(
const ITensorInfo *
input,
const ITensorInfo *rois, ITensorInfo *output,
const ROIPoolingLayerInfo &pool_info)
55 if(output->total_size() != 0)
66 const UniformQuantizationInfo rois_qinfo = rois->quantization_info().uniform();
80 : _input(nullptr), _output(nullptr), _rois(nullptr), _pool_info(0, 0, 0.f)
107 _pool_info = pool_info;
109 INEKernel::configure(window);
119 template <
typename input_data_type>
121 unsigned int roi_batch,
122 float region_start_x,
126 float region_start_y,
132 if((region_end_x <= region_start_x) || (region_end_y <= region_start_y))
134 return input_data_type(0);
141 for(
int iy = 0; iy < grid_size_y; ++iy)
143 for(
int ix = 0; ix < grid_size_x; ++ix)
146 float y = region_start_y + (iy + 0.5) * bin_size_y / float(grid_size_y);
147 float x = region_start_x + (ix + 0.5) * bin_size_x / float(grid_size_x);
152 const int y_high = y_low + 1;
153 const int x_high = x_low + 1;
155 const float ly = y - y_low;
156 const float lx = x - x_low;
157 const float hy = 1. - ly;
158 const float hx = 1. - lx;
160 const float w1 = hy * hx;
161 const float w2 = hy * lx;
162 const float w3 = ly * hx;
163 const float w4 = ly * lx;
166 const auto data1 = *
reinterpret_cast<const input_data_type *
>(input->
ptr_to_element(
Coordinates(x_low, y_low, pz, roi_batch)));
167 const auto data2 = *
reinterpret_cast<const input_data_type *
>(input->
ptr_to_element(
Coordinates(x_high, y_low, pz, roi_batch)));
168 const auto data3 = *
reinterpret_cast<const input_data_type *
>(input->
ptr_to_element(
Coordinates(x_low, y_high, pz, roi_batch)));
169 const auto data4 = *
reinterpret_cast<const input_data_type *
>(input->
ptr_to_element(
Coordinates(x_high, y_high, pz, roi_batch)));
170 avg += w1 * data1 + w2 * data2 + w3 * data3 + w4 * data4;
174 const auto data1 = *
reinterpret_cast<const input_data_type *
>(input->
ptr_to_element(
Coordinates(pz, x_low, y_low, roi_batch)));
175 const auto data2 = *
reinterpret_cast<const input_data_type *
>(input->
ptr_to_element(
Coordinates(pz, x_high, y_low, roi_batch)));
176 const auto data3 = *
reinterpret_cast<const input_data_type *
>(input->
ptr_to_element(
Coordinates(pz, x_low, y_high, roi_batch)));
177 const auto data4 = *
reinterpret_cast<const input_data_type *
>(input->
ptr_to_element(
Coordinates(pz, x_high, y_high, roi_batch)));
178 avg += w1 * data1 + w2 * data2 + w3 * data3 + w4 * data4;
183 avg /= grid_size_x * grid_size_y;
184 return input_data_type(avg);
189 template <
typename input_data_type>
191 unsigned int roi_batch,
192 float region_start_x,
196 float region_start_y,
203 if((region_end_x <= region_start_x) || (region_end_y <= region_start_y))
215 for(
int iy = 0; iy < grid_size_y; ++iy)
217 for(
int ix = 0; ix < grid_size_x; ++ix)
220 float y = region_start_y + (iy + 0.5) * bin_size_y / float(grid_size_y);
221 float x = region_start_x + (ix + 0.5) * bin_size_x / float(grid_size_x);
226 const int y_high = y_low + 1;
227 const int x_high = x_low + 1;
229 const float ly = y - y_low;
230 const float lx = x - x_low;
231 const float hy = 1. - ly;
232 const float hx = 1. - lx;
234 const float w1 = hy * hx;
235 const float w2 = hy * lx;
236 const float w3 = ly * hx;
237 const float w4 = ly * lx;
247 avg += w1 * data1 + w2 * data2 + w3 * data3 + w4 * data4;
255 avg += w1 * data1 + w2 * data2 + w3 * data3 + w4 * data4;
266 avg += w1 * data1 + w2 * data2 + w3 * data3 + w4 * data4;
274 avg += w1 * data1 + w2 * data2 + w3 * data3 + w4 * data4;
280 avg /= grid_size_x * grid_size_y;
282 input_data_type res = 0;
297 const float region_start = p * bin_size + roi_anchor;
310 NEROIAlignLayerKernel::internal_run<uint8_t, uint16_t>(
window,
info);
315 NEROIAlignLayerKernel::internal_run<int8_t, uint16_t>(
window,
info);
320 NEROIAlignLayerKernel::internal_run<float>(
window,
info);
323 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC 326 NEROIAlignLayerKernel::internal_run<float16_t>(
window,
info);
329 #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC 343 template <
typename input_data_type,
typename roi_data_type>
353 const int roi_list_start = window.
x().
start();
354 const int roi_list_end = window.
x().
end();
362 const int input_chanels = _input->
info()->
dimension(idx_depth);
369 const auto *rois_ptr =
reinterpret_cast<const roi_data_type *
>(_rois->
buffer());
371 for(
int roi_indx = roi_list_start; roi_indx < roi_list_end; ++roi_indx)
373 const unsigned int roi_batch = rois_ptr[values_per_roi * roi_indx];
375 roi_data_type qx1 = rois_ptr[values_per_roi * roi_indx + 1];
376 roi_data_type qy1 = rois_ptr[values_per_roi * roi_indx + 2];
377 roi_data_type qx2 = rois_ptr[values_per_roi * roi_indx + 3];
378 roi_data_type qy2 = rois_ptr[values_per_roi * roi_indx + 4];
392 const float roi_dims_x = std::max((x2 - x1) * _pool_info.
spatial_scale(), 1.0f);
393 const float roi_dims_y = std::max((y2 - y1) * _pool_info.
spatial_scale(), 1.0f);
394 float bin_size_x = roi_dims_x / _pool_info.
pooled_width();
398 for(
int ch = 0; ch < input_chanels; ++ch)
401 for(
int py = 0; py < pooled_h; ++py)
403 for(
int px = 0; px < pooled_w; ++px)
411 input_data_type out_val(0);
414 out_val = roi_align_1x1_qasymm8<input_data_type>(
415 _input, roi_batch, region_start_x, bin_size_x,
416 roi_bin_grid_x, region_end_x, region_start_y, bin_size_y,
421 out_val = roi_align_1x1<input_data_type>(
422 _input, roi_batch, region_start_x, bin_size_x,
423 roi_bin_grid_x, region_end_x, region_start_y, bin_size_y,
424 roi_bin_grid_y, region_end_y, ch);
virtual size_t num_dimensions() const =0
The number of dimensions of the tensor (rank)
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.
const Window & window() const
The maximum window the kernel can be executed on.
uint8_t * ptr_to_element(const Coordinates &id) const
Return a pointer to the element at the passed coordinates.
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_LAYOUT_NOT_IN(t,...)
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_LAYOUT(...)
#define ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(tensor)
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.
TensorShape compute_roi_align_shape(const ITensorInfo &input, const ITensorInfo &rois, ROIPoolingLayerInfo pool_info)
Calculate the output roi align shape of a tensor.
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.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
virtual DataType data_type() const =0
Data type used for each element of the tensor.
1 channel, 1 F32 per channel
const size_t input_height
const DataLayout data_layout
Store the tensor's metadata.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Describe one of the image's dimensions with a start, end and step.
quantized, asymmetric fixed-point 16-bit number
unsigned int pooled_width() const
Get the pooled width of the layer.
float compute_region_coordinate(int p, float bin_size, float roi_anchor, float max_value)
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
Interface for Neon tensor.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DIMENSIONS(...)
Copyright (c) 2017-2021 Arm Limited.
virtual void set_valid_region(const ValidRegion &valid_region)=0
Set the valid region of the tensor.
1 channel, 1 F16 per channel
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
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.
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
virtual ITensorInfo & set_data_layout(const DataLayout &data_layout)=0
Set the data layout of the tensor.
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.
quantized, asymmetric fixed-point 8-bit number unsigned
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.
bool auto_init_if_empty(ITensorInfo &info, const TensorShape &shape, int num_channels, DataType data_type, QuantizationInfo quantization_info=QuantizationInfo())
Auto initialize the tensor info (shape, number of channels and data type) if the current assignment i...
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
virtual QuantizationInfo quantization_info() const =0
Get the quantization settings (scale and offset) of the tensor.
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
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.
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
void run(const Window &window, const ThreadInfo &info) override
Execute the kernel on the passed window.
Information about executing thread and CPU.
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.
unsigned int pooled_height() const
Get the pooled height of the layer.
ROI Pooling Layer Information class.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
Num samples, height, width, channels.
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Status validate_arguments(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo *output_stage)
float spatial_scale() const
Get the spatial scale.
float dequantize_qasymm8_signed(int8_t value, const INFO_TYPE &qinfo)
Dequantize a value given a signed 8-bit asymmetric quantization scheme.
NEROIAlignLayerKernel()
Constructor.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
void set_num_dimensions(size_t num_dimensions)
Set number of dimensions.
quantized, asymmetric fixed-point 8-bit number signed
Container for valid region of a window.
size_t get_data_layout_dimension_index(const DataLayout data_layout, const DataLayoutDimension data_layout_dimension)
Get the index of the given dimension.
constexpr int end() const
Return the end of the dimension.
DataType
Available data types.
DataLayout
[DataLayout enum definition]
void configure(const ITensor *input, const ITensor *rois, ITensor *output, const ROIPoolingLayerInfo &pool_info)
Set the input and output tensors.
constexpr int start() const
Return the start of the dimension.
Describe a multidimensional execution window.
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
virtual DataLayout data_layout() const =0
Get the data layout of the tensor.
static Status validate(const ITensorInfo *input, const ITensorInfo *rois, ITensorInfo *output, const ROIPoolingLayerInfo &pool_info)
Static function to check if given info will lead to a valid configuration of NEROIAlignLayerKernel.
constexpr const Dimension & x() const
Alias to access the first dimension of the window.