Compute Library
 21.02
CLHOGDetector Class Reference

Basic function to execute HOG detector based on linear SVM. More...

#include <CLHOGDetector.h>

Collaboration diagram for CLHOGDetector:
[legend]

Public Member Functions

 CLHOGDetector ()
 Default constructor. More...
 
 CLHOGDetector (const CLHOGDetector &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
CLHOGDetectoroperator= (const CLHOGDetector &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 CLHOGDetector (CLHOGDetector &&)=default
 Allow instances of this class to be moved. More...
 
CLHOGDetectoroperator= (CLHOGDetector &&)=default
 Allow instances of this class to be moved. More...
 
 ~CLHOGDetector ()
 Default destructor. More...
 
void configure (const ICLTensor *input, const ICLHOG *hog, ICLDetectionWindowArray *detection_windows, const Size2D &detection_window_stride, float threshold=0.0f, size_t idx_class=0)
 Initialise the kernel's input, output, HOG data object, detection window stride, threshold and index class. More...
 
void configure (const CLCompileContext &compile_context, const ICLTensor *input, const ICLHOG *hog, ICLDetectionWindowArray *detection_windows, const Size2D &detection_window_stride, float threshold=0.0f, size_t idx_class=0)
 Initialise the kernel's input, output, HOG data object, detection window stride, threshold and index class. 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 execute HOG detector based on linear SVM.

This function calls the following OpenCL kernel:

  1. CLHOGDetectorKernel
Deprecated:
This function is deprecated and is intended to be removed in 21.05 release

Definition at line 48 of file CLHOGDetector.h.

Constructor & Destructor Documentation

◆ CLHOGDetector() [1/3]

Default constructor.

Definition at line 34 of file CLHOGDetector.cpp.

References CLHOGDetector::~CLHOGDetector().

35  : _hog_detector_kernel(std::make_unique<CLHOGDetectorKernel>()), _detection_windows(nullptr), _num_detection_windows()
36 {
37 }

◆ CLHOGDetector() [2/3]

CLHOGDetector ( const CLHOGDetector )
delete

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

◆ CLHOGDetector() [3/3]

CLHOGDetector ( CLHOGDetector &&  )
default

Allow instances of this class to be moved.

◆ ~CLHOGDetector()

~CLHOGDetector ( )
default

Default destructor.

Referenced by CLHOGDetector::CLHOGDetector().

Member Function Documentation

◆ configure() [1/2]

void configure ( const ICLTensor input,
const ICLHOG hog,
ICLDetectionWindowArray detection_windows,
const Size2D detection_window_stride,
float  threshold = 0.0f,
size_t  idx_class = 0 
)

Initialise the kernel's input, output, HOG data object, detection window stride, threshold and index class.

Attention
The function does not reset the number of values in IDetectionWindowArray so it is caller's responsibility to clear it.
Parameters
[in]inputInput tensor. It is the output of CLHOGDescriptor. Data type supported: F32
[in]hogHOG data-object that describes the HOG descriptor
[out]detection_windowsArray of DetectionWindow used to store the detected objects
[in]detection_window_strideDistance in pixels between 2 consecutive detection windows in x and y directions. It must be multiple of the block stride stored in hog
[in]threshold(Optional) Threshold for the distance between features and SVM classifying plane
[in]idx_class(Optional) Index of the class used for evaluating which class the detection window belongs to

Definition at line 41 of file CLHOGDetector.cpp.

References CLKernelLibrary::get().

42 {
43  configure(CLKernelLibrary::get().get_compile_context(), input, hog, detection_windows, detection_window_stride, threshold, idx_class);
44 }
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
void configure(const ICLTensor *input, const ICLHOG *hog, ICLDetectionWindowArray *detection_windows, const Size2D &detection_window_stride, float threshold=0.0f, size_t idx_class=0)
Initialise the kernel&#39;s input, output, HOG data object, detection window stride, threshold and index ...
SimpleTensor< T > threshold(const SimpleTensor< T > &src, T threshold, T false_value, T true_value, ThresholdType type, T upper)
Definition: Threshold.cpp:35

◆ configure() [2/2]

void configure ( const CLCompileContext compile_context,
const ICLTensor input,
const ICLHOG hog,
ICLDetectionWindowArray detection_windows,
const Size2D detection_window_stride,
float  threshold = 0.0f,
size_t  idx_class = 0 
)

Initialise the kernel's input, output, HOG data object, detection window stride, threshold and index class.

Attention
The function does not reset the number of values in IDetectionWindowArray so it is caller's responsibility to clear it.
Parameters
[in]compile_contextThe compile context to be used.
[in]inputInput tensor. It is the output of CLHOGDescriptor. Data type supported: F32
[in]hogHOG data-object that describes the HOG descriptor
[out]detection_windowsArray of DetectionWindow used to store the detected objects
[in]detection_window_strideDistance in pixels between 2 consecutive detection windows in x and y directions. It must be multiple of the block stride stored in hog
[in]threshold(Optional) Threshold for the distance between features and SVM classifying plane
[in]idx_class(Optional) Index of the class used for evaluating which class the detection window belongs to

Definition at line 46 of file CLHOGDetector.cpp.

References CLScheduler::get().

48 {
49  _detection_windows = detection_windows;
50 
51  // Allocate buffer for storing the number of detected objects
52  _num_detection_windows = cl::Buffer(CLScheduler::get().context(), CL_MEM_ALLOC_HOST_PTR | CL_MEM_READ_WRITE, sizeof(unsigned int));
53 
54  // Configure HOGDetectorKernel
55  _hog_detector_kernel->configure(compile_context, input, hog, detection_windows, &_num_detection_windows, detection_window_stride, threshold, idx_class);
56 }
static CLScheduler & get()
Access the scheduler singleton.
SimpleTensor< T > threshold(const SimpleTensor< T > &src, T threshold, T false_value, T true_value, ThresholdType type, T upper)
Definition: Threshold.cpp:35

◆ operator=() [1/2]

CLHOGDetector& operator= ( const CLHOGDetector )
delete

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

◆ operator=() [2/2]

CLHOGDetector& operator= ( CLHOGDetector &&  )
default

Allow instances of this class to be moved.

◆ 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 58 of file CLHOGDetector.cpp.

References CLScheduler::enqueue(), CLScheduler::get(), IArray< T >::num_values(), CLScheduler::queue(), and IArray< T >::resize().

59 {
60  cl::CommandQueue q = CLScheduler::get().queue();
61 
62  // Reset number of detections
63  const unsigned int init_num_detection_windows = _detection_windows->num_values();
64  q.enqueueWriteBuffer(_num_detection_windows, CL_FALSE, 0, sizeof(unsigned int), &init_num_detection_windows);
65 
66  // Run CLHOGDetectorKernel
67  CLScheduler::get().enqueue(*_hog_detector_kernel);
68 
69  // Read number of detections
70  unsigned int num_detection_windows = 0;
71  q.enqueueReadBuffer(_num_detection_windows, CL_TRUE, 0, sizeof(unsigned int), &num_detection_windows);
72 
73  // Update the number of values stored in _detection_windows
74  _detection_windows->resize(static_cast<size_t>(num_detection_windows));
75 
76  q.flush();
77 }
static CLScheduler & get()
Access the scheduler singleton.
void resize(size_t num)
Resizes the array to contain "num" elements.
Definition: IArray.h:128
size_t num_values() const
Number of values currently stored in the array.
Definition: IArray.h:68
cl::CommandQueue & queue()
Accessor for the associated CL command queue.
Definition: CLScheduler.cpp:41
void enqueue(ICLKernel &kernel, bool flush=true)
Schedule the execution of the passed kernel if possible.

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