Compute Library
 19.08
NEHOGBlockNormalizationKernel Class Reference

NEON kernel to perform HOG block normalization. More...

#include <NEHOGDescriptorKernel.h>

Collaboration diagram for NEHOGBlockNormalizationKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NEHOGBlockNormalizationKernel ()
 Default constructor. More...
 
 NEHOGBlockNormalizationKernel (const NEHOGBlockNormalizationKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEHOGBlockNormalizationKerneloperator= (const NEHOGBlockNormalizationKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEHOGBlockNormalizationKernel (NEHOGBlockNormalizationKernel &&)=default
 Allow instances of this class to be moved. More...
 
NEHOGBlockNormalizationKerneloperator= (NEHOGBlockNormalizationKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~NEHOGBlockNormalizationKernel ()=default
 Default destructor. More...
 
void configure (const ITensor *input, ITensor *output, const HOGInfo *hog_info)
 Initialise the kernel's input, output and HOG's metadata. 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...
 
- 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...
 

Detailed Description

NEON kernel to perform HOG block normalization.

Definition at line 95 of file NEHOGDescriptorKernel.h.

Constructor & Destructor Documentation

◆ NEHOGBlockNormalizationKernel() [1/3]

Default constructor.

Definition at line 709 of file NEHOGDescriptorKernel.cpp.

710  : _func(nullptr), _input(nullptr), _output(nullptr), _num_cells_per_block(), _num_cells_per_block_stride(), _num_bins(0), _l2_hyst_threshold(0.0f)
711 {
712 }

◆ NEHOGBlockNormalizationKernel() [2/3]

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

◆ NEHOGBlockNormalizationKernel() [3/3]

Allow instances of this class to be moved.

◆ ~NEHOGBlockNormalizationKernel()

Default destructor.

Member Function Documentation

◆ configure()

void configure ( const ITensor input,
ITensor output,
const HOGInfo hog_info 
)

Initialise the kernel's input, output and HOG's metadata.

Parameters
[in]inputInput tensor which stores the local HOG for each cell. Data type supported: F32. Number of channels supported: equal to the number of histogram bins per cell
[out]outputOutput tensor which stores the normalised blocks. Data type supported: F32. Number of channels supported: equal to the number of histogram bins per block
[in]hog_infoHOG's metadata

Definition at line 714 of file NEHOGDescriptorKernel.cpp.

715 {
716  ARM_COMPUTE_ERROR_ON(hog_info == nullptr);
719 
720  // Number of cells per block
721  const Size2D num_cells_per_block(hog_info->block_size().width / hog_info->cell_size().width,
722  hog_info->block_size().height / hog_info->cell_size().height);
723 
724  // Number of cells per block stride
725  const Size2D num_cells_per_block_stride(hog_info->block_stride().width / hog_info->cell_size().width,
726  hog_info->block_stride().height / hog_info->cell_size().height);
727 
728  _input = input;
729  _output = output;
730  _l2_hyst_threshold = hog_info->l2_hyst_threshold();
731  _num_cells_per_block = num_cells_per_block;
732  _num_cells_per_block_stride = num_cells_per_block_stride;
733  _num_bins = hog_info->num_bins();
734 
735  ARM_COMPUTE_ERROR_ON((output->info()->num_channels() != (_num_bins * num_cells_per_block.width * num_cells_per_block.height)));
736 
737  switch(hog_info->normalization_type())
738  {
740  _func = &l2_norm;
741  break;
743  _func = &l2hys_norm;
744  break;
746  _func = &l1_norm;
747  break;
748  default:
749  ARM_COMPUTE_ERROR_ON("Normalisation type not supported");
750  break;
751  }
752 
753  constexpr unsigned int num_elems_processed_per_iteration = 1;
754  const unsigned int num_elems_read_per_iteration = 1;
755  const unsigned int num_rows_read_per_iteration = _num_cells_per_block.height;
756  const unsigned int num_elems_written_per_iteration = 1;
757  const unsigned int num_rows_written_per_iteration = _num_cells_per_block.height;
758 
759  // Configure kernel window
760  Window win = calculate_max_window(*output->info(), Steps(num_elems_processed_per_iteration));
761  AccessWindowRectangle output_access(output->info(), 0, 0, num_elems_written_per_iteration, num_rows_written_per_iteration);
762 
764  AccessWindowRectangle(input->info(), 0, 0, num_elems_read_per_iteration, num_rows_read_per_iteration),
765  output_access);
766 
767  output_access.set_valid_region(win, ValidRegion(Coordinates(), output->info()->tensor_shape()));
768 
769  INEKernel::configure(win);
770 }
L2-norm followed by clipping.
size_t num_bins() const
The number of histogram bins for each cell.
Definition: HOGInfo.cpp:111
const Size2D & cell_size() const
The cell size in pixels.
Definition: HOGInfo.cpp:91
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.
Definition: Error.h:337
const Size2D & block_stride() const
The block stride in pixels.
Definition: HOGInfo.cpp:106
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps=Steps(), bool skip_border=false, BorderSize border_size=BorderSize())
Calculate the maximum window for a given tensor shape and border setting.
Definition: Helpers.cpp:28
HOGNormType normalization_type() const
The normalization type.
Definition: HOGInfo.cpp:116
size_t height
Height of the image region or rectangle.
Definition: Size2D.h:93
Implementation of a rectangular access pattern.
bool update_window_and_padding(Window &win, Ts &&... patterns)
Update window and padding size for each of the access patterns.
Definition: Helpers.h:402
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
Class to describe a number of elements in each dimension.
Definition: Steps.h:40
const Size2D & block_size() const
The block size in pixels.
Definition: HOGInfo.cpp:96
Coordinates of an item.
Definition: Coordinates.h:37
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
float l2_hyst_threshold() const
Threshold used for L2HYS_NORM normalization type.
Definition: HOGInfo.cpp:121
#define ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:789
size_t width
Width of the image region or rectangle.
Definition: Size2D.h:92
Class for specifying the size of an image or rectangle.
Definition: Size2D.h:34
Container for valid region of a window.
Definition: Types.h:174
Describe a multidimensional execution window.
Definition: Window.h:39
virtual size_t num_channels() const =0
The number of channels for each tensor element.
#define ARM_COMPUTE_ERROR_ON_DATA_TYPE_NOT_IN(t,...)
Definition: Validate.h:691

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, ARM_COMPUTE_ERROR_ON_DATA_TYPE_NOT_IN, HOGInfo::block_size(), HOGInfo::block_stride(), arm_compute::calculate_max_window(), HOGInfo::cell_size(), arm_compute::F32, Size2D::height, ITensor::info(), arm_compute::L1_NORM, HOGInfo::l2_hyst_threshold(), arm_compute::L2_NORM, arm_compute::L2HYS_NORM, HOGInfo::normalization_type(), HOGInfo::num_bins(), ITensorInfo::num_channels(), ITensorInfo::tensor_shape(), arm_compute::update_window_and_padding(), and Size2D::width.

Referenced by NEHOGDescriptor::configure().

◆ name()

const char* name ( ) const
inlineoverridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 98 of file NEHOGDescriptorKernel.h.

99  {
100  return "NEHOGBlockNormalizationKernel";
101  }

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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.

Implements ICPPKernel.

Definition at line 772 of file NEHOGDescriptorKernel.cpp.

773 {
776  ARM_COMPUTE_ERROR_ON(_func == nullptr);
778 
779  // Get number of bins per block
780  const size_t num_bins_per_block = _output->info()->num_channels();
781 
782  // Number of bins on the same row of the block
783  const int32_t num_bins_per_block_x = _num_cells_per_block.width * _num_bins;
784 
785  const size_t input_stride = _input->info()->strides_in_bytes()[Window::DimY] / data_size_from_type(_input->info()->data_type());
786 
787  Window win_in(window);
788  win_in.set_dimension_step(Window::DimX, _num_cells_per_block_stride.width);
789  win_in.set(Window::DimY, Window::Dimension(0, 0, 0));
790 
791  Iterator in(_input, win_in);
792  Iterator out(_output, window);
793 
794  // Normalises blocks
795  execute_window_loop(window, [&](const Coordinates & id)
796  {
797  const auto input_row_ptr = reinterpret_cast<const float *>(in.ptr() + id.y() * _num_cells_per_block_stride.height * _input->info()->strides_in_bytes()[Window::DimY]);
798  const auto out_row_ptr = reinterpret_cast<float *>(out.ptr());
799 
800  // Execute normalization function
801  (*_func)(input_row_ptr, out_row_ptr, input_stride, _num_cells_per_block.height, num_bins_per_block_x, num_bins_per_block, _l2_hyst_threshold);
802  },
803  in, out);
804 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
virtual DataType data_type() const =0
Data type used for each element of the tensor.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:337
Describe one of the image's dimensions with a start, end and step.
Definition: Window.h:75
size_t height
Height of the image region or rectangle.
Definition: Size2D.h:93
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:160
Coordinates of an item.
Definition: Coordinates.h:37
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
size_t data_size_from_type(DataType data_type)
The size in bytes of the data type.
Definition: Utils.h:109
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45
size_t width
Width of the image region or rectangle.
Definition: Size2D.h:92
void execute_window_loop(const Window &w, L &&lambda_function, Ts &&... iterators)
Iterate through the passed window, automatically adjusting the iterators and calling the lambda_funct...
Definition: Helpers.inl:122
virtual const Strides & strides_in_bytes() const =0
The strides in bytes for accessing each dimension of the tensor.
Iterator updated by execute_window_loop for each window element.
Definition: Helpers.h:318
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205
Describe a multidimensional execution window.
Definition: Window.h:39
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:940
virtual size_t num_channels() const =0
The number of channels for each tensor element.

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, arm_compute::data_size_from_type(), ITensorInfo::data_type(), Window::DimX, Window::DimY, arm_compute::execute_window_loop(), Size2D::height, ITensor::info(), arm_compute::test::validation::info, ITensorInfo::num_channels(), Iterator::ptr(), ITensorInfo::strides_in_bytes(), Size2D::width, and IKernel::window().


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