39 Status validate_arguments(
const ITensorInfo *
input,
const ITensorInfo *rois,
const ITensorInfo *output,
const ROIPoolingLayerInfo &pool_info)
50 if(output->total_size() != 0)
53 ARM_COMPUTE_RETURN_ERROR_ON((output->dimension(0) != pool_info.pooled_width()) || (output->dimension(1) != pool_info.pooled_height()));
76 void template_eval(
const ITensor *input,
const ITensor *output,
int region_start_x,
int region_start_y,
77 int region_end_x,
int region_end_y,
int fm,
int px,
int py,
int roi_batch,
int roi_indx)
79 if((region_end_x <= region_start_x) || (region_end_y <= region_start_y))
81 *
reinterpret_cast<T *
>(output->ptr_to_element(Coordinates(px, py, fm, roi_indx))) = 0;
86 for(
int j = region_start_y; j < region_end_y; ++j)
88 for(
int i = region_start_x; i < region_end_x; ++i)
90 const auto val = *
reinterpret_cast<const T *
>(input->ptr_to_element(Coordinates(i, j, fm, roi_batch)));
91 curr_max = std::max(val, curr_max);
100 *
reinterpret_cast<T *
>(output->ptr_to_element(Coordinates(px, py, fm, roi_indx))) =
quantize_qasymm8(curr_max, uqinfo);
104 *
reinterpret_cast<T *
>(output->ptr_to_element(Coordinates(px, py, fm, roi_indx))) = curr_max;
111 : _input(nullptr), _rois(nullptr), _output(nullptr), _pool_info(0, 0, 0.f)
140 _pool_info = pool_info;
147 INEKernel::configure(window);
158 const int roi_list_start = window.
x().
start();
159 const int roi_list_end = window.
x().
end();
167 const auto *rois_ptr =
reinterpret_cast<const uint16_t *
>(_rois->
buffer());
170 for(
int roi_indx = roi_list_start; roi_indx < roi_list_end; ++roi_indx)
172 const unsigned int roi_batch = rois_ptr[values_per_roi * roi_indx];
173 const auto x1 = rois_ptr[values_per_roi * roi_indx + 1];
174 const auto y1 = rois_ptr[values_per_roi * roi_indx + 2];
175 const auto x2 = rois_ptr[values_per_roi * roi_indx + 3];
176 const auto y2 = rois_ptr[values_per_roi * roi_indx + 4];
185 for(
int fm = 0; fm < fms; ++fm)
188 for(
int py = 0; py < pooled_h; ++py)
190 for(
int px = 0; px < pooled_w; ++px)
192 auto region_start_x =
static_cast<int>(std::floor((static_cast<float>(px) / pooled_w) * roi_width));
193 auto region_end_x =
static_cast<int>(std::floor((static_cast<float>(px + 1) / pooled_w) * roi_width));
194 auto region_start_y =
static_cast<int>(std::floor((static_cast<float>(py) / pooled_h) * roi_height));
195 auto region_end_y =
static_cast<int>(std::floor((static_cast<float>(py + 1) / pooled_h) * roi_height));
197 region_start_x = std::min(std::max(region_start_x + roi_anchor_x, 0), width);
198 region_end_x = std::min(std::max(region_end_x + roi_anchor_x, 0), width);
199 region_start_y = std::min(std::max(region_start_y + roi_anchor_y, 0), height);
200 region_end_y = std::min(std::max(region_end_y + roi_anchor_y, 0), height);
205 template_eval<float>(_input, _output, region_start_x, region_start_y, region_end_x, region_end_y, fm, px, py, roi_batch, roi_indx);
208 template_eval<qasymm8_t>(_input, _output, region_start_x, region_start_y, region_end_x, region_end_y, fm, px, py, roi_batch, roi_indx);
bool is_data_type_quantized(DataType dt)
Check if a given data type is of quantized type.
const Window & window() const
The maximum window the kernel can be executed on.
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.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
void configure(const ITensor *input, const ITensor *rois, const ITensor *output, const ROIPoolingLayerInfo &pool_info)
Set the input and output tensors.
#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
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Store the tensor's metadata.
static Status validate(const ITensorInfo *input, const ITensorInfo *rois, const ITensorInfo *output, const ROIPoolingLayerInfo &pool_info)
Static function to check if given info will lead to a valid configuration of NEROIPoolingLayerKernel...
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Describe one of the image's dimensions with a start, end and step.
1 channel, 1 U16 per channel
unsigned int pooled_width() const
Get the pooled width of the layer.
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
Interface for CPU tensor.
Copyright (c) 2017-2021 Arm Limited.
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
#define ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(...)
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. ...
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.
UniformQuantizationInfo compute_requantization_scale_offset(const UniformQuantizationInfo &uqinfo_in, const UniformQuantizationInfo &uqinfo_out)
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)
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)
Information about executing thread and CPU.
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
unsigned int pooled_height() const
Get the pooled height of the layer.
ROI Pooling Layer Information class.
T round(T value)
Round floating-point value with half value rounding away from zero.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
float spatial_scale() const
Get the spatial scale.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
NEROIPoolingLayerKernel()
Default constructor.
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_NOT_IN(t,...)
constexpr int end() const
Return the end of the dimension.
constexpr int start() const
Return the start of the dimension.
void run(const Window &window, const ThreadInfo &info) override
Execute the kernel on the passed window.
Describe a multidimensional execution window.
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
constexpr const Dimension & x() const
Alias to access the first dimension of the window.