Compute Library
 21.08
NEROIPoolingLayerKernel Class Reference

Interface for the ROI pooling layer kernel. More...

#include <NEROIPoolingLayerKernel.h>

Collaboration diagram for NEROIPoolingLayerKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NEROIPoolingLayerKernel ()
 Default constructor. More...
 
 NEROIPoolingLayerKernel (const NEROIPoolingLayerKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEROIPoolingLayerKerneloperator= (const NEROIPoolingLayerKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEROIPoolingLayerKernel (NEROIPoolingLayerKernel &&)=default
 Allow instances of this class to be moved. More...
 
NEROIPoolingLayerKerneloperator= (NEROIPoolingLayerKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~NEROIPoolingLayerKernel ()=default
 Default destructor. More...
 
void configure (const ITensor *input, const ITensor *rois, const ITensor *output, const ROIPoolingLayerInfo &pool_info)
 Set the input and output tensors. More...
 
void run (const Window &window, const ThreadInfo &info) override
 Execute the kernel on the passed window. More...
 
- Public Member Functions inherited from ICPPKernel
virtual ~ICPPKernel ()=default
 Default destructor. More...
 
virtual void run_nd (const Window &window, const ThreadInfo &info, const Window &thread_locator)
 legacy compatibility layer for implemantions which do not support thread_locator In these cases we simply narrow the interface down the legacy version More...
 
virtual void run_op (ITensorPack &tensors, const Window &window, const ThreadInfo &info)
 Execute the kernel on the passed window. More...
 
- Public Member Functions inherited from IKernel
 IKernel ()
 Constructor. More...
 
virtual ~IKernel ()=default
 Destructor. More...
 
virtual bool is_parallelisable () const
 Indicates whether or not the kernel is parallelisable. More...
 
virtual BorderSize border_size () const
 The size of the border for that kernel. More...
 
const Windowwindow () const
 The maximum window the kernel can be executed on. More...
 
bool is_window_configured () const
 Function to check if the embedded window of this kernel has been configured. More...
 

Static Public Member Functions

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. More...
 

Detailed Description

Interface for the ROI pooling layer kernel.

Definition at line 33 of file NEROIPoolingLayerKernel.h.

Constructor & Destructor Documentation

◆ NEROIPoolingLayerKernel() [1/3]

Default constructor.

Definition at line 110 of file NEROIPoolingLayerKernel.cpp.

Referenced by NEROIPoolingLayerKernel::name().

111  : _input(nullptr), _rois(nullptr), _output(nullptr), _pool_info(0, 0, 0.f)
112 {
113 }

◆ NEROIPoolingLayerKernel() [2/3]

Prevent instances of this class from being copied (As this class contains pointers)

◆ NEROIPoolingLayerKernel() [3/3]

Allow instances of this class to be moved.

◆ ~NEROIPoolingLayerKernel()

Default destructor.

Referenced by NEROIPoolingLayerKernel::name().

Member Function Documentation

◆ configure()

void configure ( const ITensor input,
const ITensor rois,
const ITensor output,
const ROIPoolingLayerInfo pool_info 
)

Set the input and output tensors.

Parameters
[in]inputSource tensor. Data types supported: QASYMM8/F32
[in]roisROIs tensor, it is a 2D tensor of size [5, N] (where N is the number of ROIs) containing top left and bottom right corner as coordinate of an image and batch_id of ROI [ batch_id, x1, y1, x2, y2 ]. Data types supported: U16
[out]outputDestination tensor. Data types supported: Same as input.
[in]pool_infoContains pooling operation information described in ROIPoolingLayerInfo.
Note
The x and y dimensions of output tensor must be the same as that specified by pool_info 's pooled width and pooled height.
The z dimensions of output tensor and input tensor must be the same.
The fourth dimension of output tensor must be the same as the number of elements in rois tensor.

Definition at line 121 of file NEROIPoolingLayerKernel.cpp.

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES, ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, arm_compute::auto_init_if_empty(), ITensorInfo::data_type(), ITensorInfo::dimension(), Window::DimX, Window::DimY, ITensor::info(), arm_compute::test::validation::input, arm_compute::test::validation::output_shape, ROIPoolingLayerInfo::pooled_height(), ROIPoolingLayerInfo::pooled_width(), ITensorInfo::quantization_info(), Window::set(), and IKernel::window().

Referenced by NEROIPoolingLayerKernel::name().

122 {
123  ARM_COMPUTE_ERROR_ON_NULLPTR(input, output, rois);
124 
125  //Validate arguments
126  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), rois->info(), output->info(), pool_info));
127 
128  // Output auto initialization if not yet initialized
129  TensorShape output_shape(pool_info.pooled_width(), pool_info.pooled_height(), input->info()->dimension(2), rois->info()->dimension(1));
130 
131  auto_init_if_empty(*output->info(), output_shape, 1, input->info()->data_type(), output->info()->quantization_info());
132 
134  ARM_COMPUTE_ERROR_ON((output->info()->dimension(0) != pool_info.pooled_width()) || (output->info()->dimension(1) != pool_info.pooled_height()));
135 
136  // Set instance variables
137  _input = input;
138  _rois = rois;
139  _output = output;
140  _pool_info = pool_info;
141 
142  // Configure kernel window
143  Window window;
144  window.set(Window::DimX, Window::Dimension(0, rois->info()->dimension(1)));
145  window.set(Window::DimY, Window::Dimension(0, 1));
146 
147  INEKernel::configure(window);
148 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43
#define ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(...)
Definition: Validate.h:539
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...
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
Definition: Window.inl:49
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157

◆ name()

◆ operator=() [1/2]

NEROIPoolingLayerKernel& operator= ( const NEROIPoolingLayerKernel )
delete

Prevent instances of this class from being copied (As this class contains pointers)

Referenced by NEROIPoolingLayerKernel::name().

◆ operator=() [2/2]

NEROIPoolingLayerKernel& operator= ( NEROIPoolingLayerKernel &&  )
default

Allow instances of this class to be moved.

◆ run()

void run ( const Window window,
const ThreadInfo info 
)
overridevirtual

Execute the kernel on the passed window.

Warning
If is_parallelisable() returns false then the passed window must be equal to window()
Note
The window has to be a region within the window returned by the window() method
The width of the window has to be a multiple of num_elems_processed_per_iteration().
Parameters
[in]windowRegion on which to execute the kernel. (Must be a region of the window returned by window())
[in]infoInfo about executing thread and CPU.

Reimplemented from ICPPKernel.

Definition at line 150 of file NEROIPoolingLayerKernel.cpp.

References ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, ITensor::buffer(), arm_compute::test::validation::data_type, ITensorInfo::data_type(), ITensorInfo::dimension(), Window::DimX, Window::DimY, Window::DimZ, Window::Dimension::end(), arm_compute::F32, ITensor::info(), ROIPoolingLayerInfo::pooled_height(), ROIPoolingLayerInfo::pooled_width(), arm_compute::QASYMM8, arm_compute::support::cpp11::round(), ROIPoolingLayerInfo::spatial_scale(), Window::Dimension::start(), IKernel::window(), and Window::x().

Referenced by NEROIPoolingLayerKernel::name().

151 {
155 
156  const size_t values_per_roi = _rois->info()->dimension(0);
157 
158  const int roi_list_start = window.x().start();
159  const int roi_list_end = window.x().end();
160  const int width = _input->info()->dimension(Window::DimX);
161  const int height = _input->info()->dimension(Window::DimY);
162  const int fms = _input->info()->dimension(Window::DimZ);
163  const int pooled_w = _pool_info.pooled_width();
164  const int pooled_h = _pool_info.pooled_height();
165  const float spatial_scale = _pool_info.spatial_scale();
166 
167  const auto *rois_ptr = reinterpret_cast<const uint16_t *>(_rois->buffer());
168  const auto data_type = _input->info()->data_type();
169 
170  for(int roi_indx = roi_list_start; roi_indx < roi_list_end; ++roi_indx)
171  {
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];
177 
178  // Scale ROI
179  const int roi_anchor_x = support::cpp11::round(x1 * spatial_scale);
180  const int roi_anchor_y = support::cpp11::round(y1 * spatial_scale);
181  const int roi_width = std::max(support::cpp11::round((x2 - x1) * spatial_scale), 1.f);
182  const int roi_height = std::max(support::cpp11::round((y2 - y1) * spatial_scale), 1.f);
183 
184  // Iterate through all feature maps
185  for(int fm = 0; fm < fms; ++fm)
186  {
187  // Iterate through all output pixels
188  for(int py = 0; py < pooled_h; ++py)
189  {
190  for(int px = 0; px < pooled_w; ++px)
191  {
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));
196 
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);
201 
202  switch(data_type)
203  {
204  case DataType::F32:
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);
206  break;
207  case DataType::QASYMM8:
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);
209  break;
210  default:
211  ARM_COMPUTE_ERROR("DataType not Supported");
212  break;
213  }
214  }
215  }
216  }
217  }
218 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
virtual DataType data_type() const =0
Data type used for each element of the tensor.
1 channel, 1 F32 per channel
unsigned int pooled_width() const
Get the pooled width of the layer.
Definition: Types.h:1249
const DataType data_type
Definition: Im2Col.cpp:150
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
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. ...
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:915
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
Definition: Window.h:47
unsigned int pooled_height() const
Get the pooled height of the layer.
Definition: Types.h:1254
T round(T value)
Round floating-point value with half value rounding away from zero.
float spatial_scale() const
Get the spatial scale.
Definition: Types.h:1259
constexpr int end() const
Return the end of the dimension.
Definition: Window.h:99
constexpr int start() const
Return the start of the dimension.
Definition: Window.h:94
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:201
constexpr const Dimension & x() const
Alias to access the first dimension of the window.
Definition: Window.h:145

◆ validate()

Status validate ( const ITensorInfo input,
const ITensorInfo rois,
const ITensorInfo output,
const ROIPoolingLayerInfo pool_info 
)
static

Static function to check if given info will lead to a valid configuration of NEROIPoolingLayerKernel.

Parameters
[in]inputSource tensor info. Data types supported: QASYMM8/F32.
[in]roisROIs tensor info. Data types supported: U16
[in]outputDestination tensor info. Data types supported: Same as input.
[in]pool_infoContains pooling operation information described in ROIPoolingLayerInfo.
Note
The x and y dimensions of output tensor must be the same as pool_info 's pooled width and pooled height.
The datatype of output should be the same as the datatype of input
The fourth dimension of output tensor must be the same as the number of elements in rois array.
Returns
a Status

Definition at line 115 of file NEROIPoolingLayerKernel.cpp.

References ARM_COMPUTE_RETURN_ON_ERROR.

Referenced by NEROIPoolingLayerKernel::name(), and NEROIPoolingLayer::validate().

116 {
117  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, rois, output, pool_info));
118  return Status{};
119 }
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204

The documentation for this class was generated from the following files: