Compute Library
 21.02
CLHOGDescriptor Class Reference

Basic function to calculate HOG descriptor. More...

#include <CLHOGDescriptor.h>

Collaboration diagram for CLHOGDescriptor:
[legend]

Public Member Functions

 CLHOGDescriptor (std::shared_ptr< IMemoryManager > memory_manager=nullptr)
 Default constructor. More...
 
 CLHOGDescriptor (const CLHOGDescriptor &)=delete
 Prevent instances of this class from being copied. More...
 
CLHOGDescriptoroperator= (const CLHOGDescriptor &)=delete
 Prevent instances of this class from being copied. More...
 
 ~CLHOGDescriptor ()
 Default destructor. More...
 
void configure (ICLTensor *input, ICLTensor *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 configure (const CLCompileContext &compile_context, ICLTensor *input, ICLTensor *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 OpenCL kernels:

  1. CLHOGGradient
  2. CLHOGOrientationBinningKernel
  3. CLHOGBlockNormalizationKernel
Deprecated:
This function is deprecated and is intended to be removed in 21.05 release

Definition at line 50 of file CLHOGDescriptor.h.

Constructor & Destructor Documentation

◆ CLHOGDescriptor() [1/2]

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

Default constructor.

Definition at line 37 of file CLHOGDescriptor.cpp.

References CLHOGDescriptor::~CLHOGDescriptor().

38  : _memory_group(std::move(memory_manager)),
39  _gradient(),
40  _orient_bin(std::make_unique<CLHOGOrientationBinningKernel>()),
41  _block_norm(std::make_unique<CLHOGBlockNormalizationKernel>()),
42  _mag(),
43  _phase(),
44  _hog_space()
45 {
46 }

◆ CLHOGDescriptor() [2/2]

CLHOGDescriptor ( const CLHOGDescriptor )
delete

Prevent instances of this class from being copied.

◆ ~CLHOGDescriptor()

~CLHOGDescriptor ( )
default

Default destructor.

Referenced by CLHOGDescriptor::CLHOGDescriptor().

Member Function Documentation

◆ configure() [1/2]

void configure ( ICLTensor input,
ICLTensor 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 50 of file CLHOGDescriptor.cpp.

References CLKernelLibrary::get().

51 {
52  configure(CLKernelLibrary::get().get_compile_context(), input, output, hog, border_mode, constant_border_value);
53 }
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
void configure(ICLTensor *input, ICLTensor *output, const IHOG *hog, BorderMode border_mode, uint8_t constant_border_value=0)
Initialise the function&#39;s source, destination, HOG data-object and border mode.

◆ configure() [2/2]

void configure ( const CLCompileContext compile_context,
ICLTensor input,
ICLTensor 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]compile_contextThe compile context to be used.
[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 55 of file CLHOGDescriptor.cpp.

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

56 {
58  ARM_COMPUTE_ERROR_ON(nullptr == output);
59  ARM_COMPUTE_ERROR_ON(nullptr == hog);
60 
61  const HOGInfo *hog_info = hog->info();
62  const size_t width = input->info()->dimension(Window::DimX);
63  const size_t height = input->info()->dimension(Window::DimY);
64  const size_t num_bins = hog_info->num_bins();
65 
66  Size2D cell_size = hog_info->cell_size();
67 
68  // Calculate number of cells along the x and y directions for the hog_space
69  const size_t num_cells_x = width / cell_size.width;
70  const size_t num_cells_y = height / cell_size.height;
71 
72  // TensorShape of the input image
73  const TensorShape &shape_img = input->info()->tensor_shape();
74 
75  // TensorShape of the hog space
76  TensorShape shape_hog_space = input->info()->tensor_shape();
77  shape_hog_space.set(Window::DimX, num_cells_x);
78  shape_hog_space.set(Window::DimY, num_cells_y);
79 
80  // Intitialize tensors for magnitude, phase and hog space
81  TensorInfo info_mag(shape_img, Format::S16);
82  _mag.allocator()->init(info_mag);
83 
84  TensorInfo info_phase(shape_img, Format::U8);
85  _phase.allocator()->init(info_phase);
86 
87  TensorInfo info_space(shape_hog_space, num_bins, DataType::F32);
88  _hog_space.allocator()->init(info_space);
89 
90  // Manage intermediate buffers
91  _memory_group.manage(&_mag);
92  _memory_group.manage(&_phase);
93 
94  // Initialise gradient kernel
95  _gradient.configure(compile_context, input, &_mag, &_phase, hog_info->phase_type(), border_mode, constant_border_value);
96 
97  // Manage intermediate buffers
98  _memory_group.manage(&_hog_space);
99 
100  // Initialise orientation binning kernel
101  _orient_bin->configure(compile_context, &_mag, &_phase, &_hog_space, hog->info());
102 
103  // Initialize HOG norm kernel
104  _block_norm->configure(compile_context, &_hog_space, output, hog->info());
105 
106  // Allocate intermediate tensors
107  _mag.allocator()->allocate();
108  _phase.allocator()->allocate();
109  _hog_space.allocator()->allocate();
110 }
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
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
void configure(ICLTensor *input, ICLTensor *output_magnitude, ICLTensor *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.
1 channel, 1 U8 per channel
Store the HOG&#39;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:466
CLTensorAllocator * allocator()
Return a pointer to the tensor&#39;s allocator.
Definition: CLTensor.cpp:61
PhaseType phase_type() const
The type of PhaseType.
Definition: HOGInfo.cpp:126
void init(const TensorInfo &input, size_t alignment=0)
Initialize a tensor based on the passed TensorInfo.
size_t height
Height of the image region or rectangle.
Definition: Size2D.h:90
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
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
1 channel, 1 S16 per channel
#define ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:790
void allocate() override
Allocate size specified by TensorInfo of OpenCL memory.
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:89
Class for specifying the size of an image or rectangle.
Definition: Size2D.h:34
Store the tensor&#39;s metadata.
Definition: TensorInfo.h:45
virtual const HOGInfo * info() const =0
Interface to be implemented by the child class to return the HOG&#39;s metadata.
TensorShape & set(size_t dimension, size_t value, bool apply_dim_correction=true, bool increase_dim_unit=true)
Accessor to set the value of one of the dimensions.
Definition: TensorShape.h:79

◆ operator=()

CLHOGDescriptor& operator= ( const CLHOGDescriptor )
delete

Prevent instances of this class from being copied.

◆ 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 112 of file CLHOGDescriptor.cpp.

References CLScheduler::enqueue(), CLScheduler::get(), and CLHOGGradient::run().

113 {
114  MemoryGroupResourceScope scope_mg(_memory_group);
115 
116  // Run gradient
117  _gradient.run();
118 
119  // Run orientation binning
120  CLScheduler::get().enqueue(*_orient_bin, false);
121 
122  // Run block normalization
123  CLScheduler::get().enqueue(*_block_norm);
124 }
static CLScheduler & get()
Access the scheduler singleton.
void enqueue(ICLKernel &kernel, bool flush=true)
Schedule the execution of the passed kernel if possible.
Memory group resources scope handling class.
Definition: IMemoryGroup.h:82
void run() override
Run the kernels contained in the function.

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