Compute Library
 21.02
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...
 
 NEHOGDescriptor (const NEHOGDescriptor &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEHOGDescriptoroperator= (const NEHOGDescriptor &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEHOGDescriptor (NEHOGDescriptor &&)=delete
 Prevent instances of this class from being moved (As this class contains non movable objects) More...
 
NEHOGDescriptoroperator= (NEHOGDescriptor &&)=delete
 Prevent instances of this class from being moved (As this class contains non movable objects) More...
 
 ~NEHOGDescriptor ()
 Default destructor. 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
Deprecated:
This function is deprecated and is intended to be removed in 21.05 release

Definition at line 50 of file NEHOGDescriptor.h.

Constructor & Destructor Documentation

◆ NEHOGDescriptor() [1/3]

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

Default constructor.

Definition at line 39 of file NEHOGDescriptor.cpp.

40  : _memory_group(std::move(memory_manager)), _gradient(), _orient_bin(), _block_norm(), _mag(), _phase(), _hog_space()
41 {
42 }

◆ NEHOGDescriptor() [2/3]

NEHOGDescriptor ( const NEHOGDescriptor )
delete

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

◆ NEHOGDescriptor() [3/3]

Prevent instances of this class from being moved (As this class contains non movable objects)

◆ ~NEHOGDescriptor()

~NEHOGDescriptor ( )
default

Default destructor.

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 44 of file NEHOGDescriptor.cpp.

References TensorAllocator::allocate(), Tensor::allocator(), ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, HOGInfo::cell_size(), NEHOGGradient::configure(), ITensorInfo::dimension(), Window::DimX, Window::DimY, arm_compute::F32, Size2D::height, IHOG::info(), ITensor::info(), TensorAllocator::init(), MemoryGroup::manage(), HOGInfo::num_bins(), HOGInfo::phase_type(), arm_compute::S16, TensorShape::set(), ITensorInfo::tensor_shape(), arm_compute::U8, and Size2D::width.

45 {
47  ARM_COMPUTE_ERROR_ON(nullptr == output);
48  ARM_COMPUTE_ERROR_ON(nullptr == hog);
49 
50  const HOGInfo *hog_info = hog->info();
51  const size_t width = input->info()->dimension(Window::DimX);
52  const size_t height = input->info()->dimension(Window::DimY);
53  const size_t num_bins = hog_info->num_bins();
54 
55  Size2D cell_size = hog_info->cell_size();
56 
57  // Calculate number of cells along the x and y directions for the hog_space
58  const size_t num_cells_x = width / cell_size.width;
59  const size_t num_cells_y = height / cell_size.height;
60 
61  // TensorShape of the input image
62  const TensorShape &shape_img = input->info()->tensor_shape();
63 
64  // TensorShape of the hog space
65  TensorShape shape_hog_space = input->info()->tensor_shape();
66  shape_hog_space.set(Window::DimX, num_cells_x);
67  shape_hog_space.set(Window::DimY, num_cells_y);
68 
69  // Allocate memory for magnitude, phase and hog space
70  TensorInfo info_mag(shape_img, Format::S16);
71  _mag.allocator()->init(info_mag);
72 
73  TensorInfo info_phase(shape_img, Format::U8);
74  _phase.allocator()->init(info_phase);
75 
76  TensorInfo info_space(shape_hog_space, num_bins, DataType::F32);
77  _hog_space.allocator()->init(info_space);
78 
79  // Manage intermediate buffers
80  _memory_group.manage(&_mag);
81  _memory_group.manage(&_phase);
82 
83  // Initialise gradient kernel
84  _gradient.configure(input, &_mag, &_phase, hog_info->phase_type(), border_mode, constant_border_value);
85 
86  // Manage intermediate buffers
87  _memory_group.manage(&_hog_space);
88 
89  // Initialise orientation binning kernel
90  _orient_bin = std::make_unique<NEHOGOrientationBinningKernel>();
91  _orient_bin->configure(&_mag, &_phase, &_hog_space, hog->info());
92 
93  // Initialize HOG norm kernel
94  _block_norm = std::make_unique<NEHOGBlockNormalizationKernel>();
95  _block_norm->configure(&_hog_space, output, hog->info());
96 
97  // Allocate intermediate tensors
98  _mag.allocator()->allocate();
99  _phase.allocator()->allocate();
100  _hog_space.allocator()->allocate();
101 }
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...
1 channel, 1 U8 per channel
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:466
TensorAllocator * allocator()
Return a pointer to the tensor&#39;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&#39;s source, destinations, phase type and border mode.
void manage(IMemoryManageable *obj) override
Sets a object to be managed by the given memory group.
Definition: MemoryGroup.h:79
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43
void allocate() override
Allocate size specified by TensorInfo of CPU memory.
1 channel, 1 S16 per channel
#define ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:790
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45

◆ operator=() [1/2]

NEHOGDescriptor& operator= ( const NEHOGDescriptor )
delete

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

◆ operator=() [2/2]

NEHOGDescriptor& operator= ( NEHOGDescriptor &&  )
delete

Prevent instances of this class from being moved (As this class contains non movable objects)

◆ 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 103 of file NEHOGDescriptor.cpp.

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

104 {
105  MemoryGroupResourceScope scope_mg(_memory_group);
106 
107  // Run gradient
108  _gradient.run();
109 
110  // Run orientation binning kernel
111  NEScheduler::get().schedule(_orient_bin.get(), Window::DimY);
112 
113  // Run block normalization kernel
114  NEScheduler::get().schedule(_block_norm.get(), Window::DimY);
115 }
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
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:94

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