Compute Library
 19.08
NEHOGDescriptor Class Reference

Basic function to calculate HOG descriptor. More...

#include <NEHOGDescriptor.h>

Collaboration diagram for NEHOGDescriptor:
[legend]

Public Member Functions

 NEHOGDescriptor (std::shared_ptr< IMemoryManager > memory_manager=nullptr)
 Default constructor. More...
 
void configure (ITensor *input, ITensor *output, const IHOG *hog, BorderMode border_mode, uint8_t constant_border_value=0)
 Initialise the function's source, destination, HOG data-object and border mode. More...
 
void run () override
 Run the kernels contained in the function. More...
 
- Public Member Functions inherited from IFunction
virtual ~IFunction ()=default
 Destructor. More...
 
virtual void prepare ()
 Prepare the function for executing. More...
 

Detailed Description

Basic function to calculate HOG descriptor.

This function calls the following NEON kernels:

  1. NEHOGGradient
  2. NEHOGOrientationBinningKernel
  3. NEHOGBlockNormalizationKernel

Definition at line 46 of file NEHOGDescriptor.h.

Constructor & Destructor Documentation

◆ NEHOGDescriptor()

NEHOGDescriptor ( std::shared_ptr< IMemoryManager memory_manager = nullptr)

Default constructor.

Definition at line 34 of file NEHOGDescriptor.cpp.

35  : _memory_group(std::move(memory_manager)), _gradient(), _orient_bin(), _block_norm(), _mag(), _phase(), _hog_space()
36 {
37 }

Member Function Documentation

◆ configure()

void configure ( ITensor input,
ITensor output,
const IHOG hog,
BorderMode  border_mode,
uint8_t  constant_border_value = 0 
)

Initialise the function's source, destination, HOG data-object and border mode.

Parameters
[in,out]inputInput tensor. Data type supported: U8 (Written to only for border_mode != UNDEFINED)
[out]outputOutput tensor which stores the HOG descriptor. DataType supported: F32. The number of channels is equal to the number of histogram bins per block
[in]hogHOG data object which describes the HOG descriptor
[in]border_modeBorder mode to use.
[in]constant_border_value(Optional) Constant value to use for borders if border_mode is set to CONSTANT.

Definition at line 39 of file NEHOGDescriptor.cpp.

40 {
42  ARM_COMPUTE_ERROR_ON(nullptr == output);
43  ARM_COMPUTE_ERROR_ON(nullptr == hog);
44 
45  const HOGInfo *hog_info = hog->info();
46  const size_t width = input->info()->dimension(Window::DimX);
47  const size_t height = input->info()->dimension(Window::DimY);
48  const size_t num_bins = hog_info->num_bins();
49 
50  Size2D cell_size = hog_info->cell_size();
51 
52  // Calculate number of cells along the x and y directions for the hog_space
53  const size_t num_cells_x = width / cell_size.width;
54  const size_t num_cells_y = height / cell_size.height;
55 
56  // TensorShape of the input image
57  const TensorShape &shape_img = input->info()->tensor_shape();
58 
59  // TensorShape of the hog space
60  TensorShape shape_hog_space = input->info()->tensor_shape();
61  shape_hog_space.set(Window::DimX, num_cells_x);
62  shape_hog_space.set(Window::DimY, num_cells_y);
63 
64  // Allocate memory for magnitude, phase and hog space
65  TensorInfo info_mag(shape_img, Format::S16);
66  _mag.allocator()->init(info_mag);
67 
68  TensorInfo info_phase(shape_img, Format::U8);
69  _phase.allocator()->init(info_phase);
70 
71  TensorInfo info_space(shape_hog_space, num_bins, DataType::F32);
72  _hog_space.allocator()->init(info_space);
73 
74  // Manage intermediate buffers
75  _memory_group.manage(&_mag);
76  _memory_group.manage(&_phase);
77 
78  // Initialise gradient kernel
79  _gradient.configure(input, &_mag, &_phase, hog_info->phase_type(), border_mode, constant_border_value);
80 
81  // Manage intermediate buffers
82  _memory_group.manage(&_hog_space);
83 
84  // Initialise orientation binning kernel
85  _orient_bin.configure(&_mag, &_phase, &_hog_space, hog->info());
86 
87  // Initialize HOG norm kernel
88  _block_norm.configure(&_hog_space, output, hog->info());
89 
90  // Allocate intermediate tensors
91  _mag.allocator()->allocate();
92  _phase.allocator()->allocate();
93  _hog_space.allocator()->allocate();
94 }
size_t num_bins() const
The number of histogram bins for each cell.
Definition: HOGInfo.cpp:111
Shape of a tensor.
Definition: TensorShape.h:39
void init(const TensorAllocator &allocator, const Coordinates &coords, TensorInfo &sub_info)
Shares the same backing memory with another tensor allocator, while the tensor info might be differen...
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
const Size2D & cell_size() const
The cell size in pixels.
Definition: HOGInfo.cpp:91
1 channel, 1 U8 per channel
Store the HOG's metadata.
Definition: HOGInfo.h:35
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
PhaseType phase_type() const
The type of PhaseType.
Definition: HOGInfo.cpp:126
size_t height
Height of the image region or rectangle.
Definition: Size2D.h:93
TensorAllocator * allocator()
Return a pointer to the tensor's allocator.
Definition: Tensor.cpp:48
void configure(ITensor *input, ITensor *output_magnitude, ITensor *output_phase, PhaseType phase_type, BorderMode border_mode, uint8_t constant_border_value=0)
Initialise the function's source, destinations, phase type and border mode.
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43
void manage(TensorType *obj)
Sets a object to be managed by the given memory group.
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
void allocate() override
Allocate size specified by TensorInfo of CPU memory.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
1 channel, 1 S16 per channel
#define ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:789
void configure(const ITensor *input, ITensor *output, const HOGInfo *hog_info)
Initialise the kernel's input, output and HOG's metadata.
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
Class for specifying the size of an image or rectangle.
Definition: Size2D.h:34
void configure(const ITensor *input_magnitude, const ITensor *input_phase, ITensor *output, const HOGInfo *hog_info)
Initialise the kernel's inputs, output and HOG's metadata.
TensorShape & set(size_t dimension, size_t value, bool apply_dim_correction=true)
Accessor to set the value of one of the dimensions.
Definition: TensorShape.h:78
Store the tensor's metadata.
Definition: TensorInfo.h:45
virtual const HOGInfo * info() const =0
Interface to be implemented by the child class to return the HOG's metadata.

References TensorAllocator::allocate(), Tensor::allocator(), ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, arm_compute::test::validation::border_mode, HOGInfo::cell_size(), NEHOGGradient::configure(), NEHOGOrientationBinningKernel::configure(), NEHOGBlockNormalizationKernel::configure(), ITensorInfo::dimension(), Window::DimX, Window::DimY, arm_compute::F32, Size2D::height, IHOG::info(), ITensor::info(), TensorAllocator::init(), MemoryGroupBase< TensorType >::manage(), HOGInfo::num_bins(), HOGInfo::phase_type(), arm_compute::S16, TensorShape::set(), ITensorInfo::tensor_shape(), arm_compute::U8, and Size2D::width.

◆ run()

void run ( )
overridevirtual

Run the kernels contained in the function.

For NEON kernels:

  • Multi-threading is used for the kernels which are parallelisable.
  • By default std::thread::hardware_concurrency() threads are used.
Note
CPPScheduler::set_num_threads() can be used to manually set the number of threads

For OpenCL kernels:

  • All the kernels are enqueued on the queue associated with CLScheduler.
  • The queue is then flushed.
Note
The function will not block until the kernels are executed. It is the user's responsibility to wait.
Will call prepare() on first run if hasn't been done

Implements IFunction.

Definition at line 96 of file NEHOGDescriptor.cpp.

97 {
98  MemoryGroupResourceScope scope_mg(_memory_group);
99 
100  // Run gradient
101  _gradient.run();
102 
103  // Run orientation binning kernel
104  NEScheduler::get().schedule(&_orient_bin, Window::DimY);
105 
106  // Run block normalization kernel
107  NEScheduler::get().schedule(&_block_norm, Window::DimY);
108 }
void run() override
Run the kernels contained in the function.
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45
Memory group resources scope handling class.
Definition: IMemoryGroup.h:46
virtual void schedule(ICPPKernel *kernel, const Hints &hints)=0
Runs the kernel in the same thread as the caller synchronously.
static IScheduler & get()
Access the scheduler singleton.
Definition: Scheduler.cpp:96

References Window::DimY, Scheduler::get(), NEHOGGradient::run(), and IScheduler::schedule().


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