Compute Library
 19.08
CPPDetectionWindowNonMaximaSuppressionKernel Class Reference

CPP kernel to perform in-place computation of euclidean distance on IDetectionWindowArray. More...

#include <CPPDetectionWindowNonMaximaSuppressionKernel.h>

Collaboration diagram for CPPDetectionWindowNonMaximaSuppressionKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 CPPDetectionWindowNonMaximaSuppressionKernel ()
 Default constructor. More...
 
 CPPDetectionWindowNonMaximaSuppressionKernel (const CPPDetectionWindowNonMaximaSuppressionKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
CPPDetectionWindowNonMaximaSuppressionKerneloperator= (const CPPDetectionWindowNonMaximaSuppressionKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 CPPDetectionWindowNonMaximaSuppressionKernel (CPPDetectionWindowNonMaximaSuppressionKernel &&)=default
 Allow instances of this class to be moved. More...
 
CPPDetectionWindowNonMaximaSuppressionKerneloperator= (CPPDetectionWindowNonMaximaSuppressionKernel &&)=default
 Allow instances of this class to be moved. More...
 
void configure (IDetectionWindowArray *input_output, float min_distance)
 Initialise the kernel's input, output and the euclidean minimum distance. More...
 
void run (const Window &window, const ThreadInfo &info) override
 Execute the kernel on the passed window. More...
 
bool is_parallelisable () const override
 Indicates whether or not the kernel is parallelisable. 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 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

CPP kernel to perform in-place computation of euclidean distance on IDetectionWindowArray.

Note
This kernel is meant to be used alongside HOG or other object detection algorithms to perform a non-maxima suppression on a IDetectionWindowArray

Definition at line 39 of file CPPDetectionWindowNonMaximaSuppressionKernel.h.

Constructor & Destructor Documentation

◆ CPPDetectionWindowNonMaximaSuppressionKernel() [1/3]

Default constructor.

Definition at line 61 of file CPPDetectionWindowNonMaximaSuppressionKernel.cpp.

62  : _input_output(nullptr), _min_distance(0.0f)
63 {
64 }

◆ CPPDetectionWindowNonMaximaSuppressionKernel() [2/3]

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

◆ CPPDetectionWindowNonMaximaSuppressionKernel() [3/3]

Allow instances of this class to be moved.

Member Function Documentation

◆ configure()

void configure ( IDetectionWindowArray input_output,
float  min_distance 
)

Initialise the kernel's input, output and the euclidean minimum distance.

Attention
: If IDetectionWindowArray is passed to the kernel, the map() and unmap() methods IDetectionWindowArray must be called respectively before and after the run() method of CPPDetectionWindowNonMaximaSuppressionKernel
Parameters
[in,out]input_outputInput/Output array of DetectionWindow
[in]min_distanceRadial Euclidean distance for non-maxima suppression

Definition at line 71 of file CPPDetectionWindowNonMaximaSuppressionKernel.cpp.

72 {
73  ARM_COMPUTE_ERROR_ON(nullptr == input_output);
74 
75  _input_output = input_output;
76  _min_distance = min_distance;
77 
78  IKernel::configure(Window()); // Default 1 iteration window
79 }
#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 a multidimensional execution window.
Definition: Window.h:39

References ARM_COMPUTE_ERROR_ON.

Referenced by CLHOGMultiDetection::configure(), and NEHOGMultiDetection::configure().

◆ is_parallelisable()

bool is_parallelisable ( ) const
overridevirtual

Indicates whether or not the kernel is parallelisable.

If the kernel is parallelisable then the window returned by window() can be split into sub-windows which can then be run in parallel.

If the kernel is not parallelisable then only the window returned by window() can be passed to run()

Returns
True if the kernel is parallelisable

Reimplemented from IKernel.

Definition at line 66 of file CPPDetectionWindowNonMaximaSuppressionKernel.cpp.

67 {
68  return false;
69 }

◆ name()

const char* name ( ) const
inlineoverridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 42 of file CPPDetectionWindowNonMaximaSuppressionKernel.h.

43  {
44  return "CPPDetectionWindowNonMaximaSuppressionKernel";
45  }

◆ 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 81 of file CPPDetectionWindowNonMaximaSuppressionKernel.cpp.

82 {
87  ARM_COMPUTE_ERROR_ON(_input_output->buffer() == nullptr);
88 
89  const size_t num_candidates = _input_output->num_values();
90  size_t num_detections = 0;
91 
92  // Sort list of candidates by idx_class and then score
93  std::sort(_input_output->buffer(), _input_output->buffer() + num_candidates, compare_detection_window);
94 
95  const float min_distance_pow2 = _min_distance * _min_distance;
96 
97  // Euclidean distance
98  for(size_t i = 0; i < num_candidates; ++i)
99  {
100  if(0.0f != _input_output->at(i).score)
101  {
102  DetectionWindow cur;
103  cur.x = _input_output->at(i).x;
104  cur.y = _input_output->at(i).y;
105  cur.width = _input_output->at(i).width;
106  cur.height = _input_output->at(i).height;
107  cur.idx_class = _input_output->at(i).idx_class;
108  cur.score = _input_output->at(i).score;
109 
110  // Store window
111  _input_output->at(num_detections) = cur;
112 
113  ++num_detections;
114 
115  const float xc = cur.x + cur.width * 0.5f;
116  const float yc = cur.y + cur.height * 0.5f;
117 
118  for(size_t k = i + 1; k < (num_candidates) && (cur.idx_class == _input_output->at(k).idx_class); ++k)
119  {
120  const float xn = _input_output->at(k).x + _input_output->at(k).width * 0.5f;
121  const float yn = _input_output->at(k).y + _input_output->at(k).height * 0.5f;
122 
123  const float dx = std::fabs(xn - xc);
124  const float dy = std::fabs(yn - yc);
125 
126  if(dx < _min_distance && dy < _min_distance)
127  {
128  const float d = dx * dx + dy * dy;
129 
130  if(d < min_distance_pow2)
131  {
132  // Invalidate detection window
133  _input_output->at(k).score = 0.0f;
134  }
135  }
136  }
137  }
138  }
139 
140  _input_output->resize(num_detections);
141 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
uint16_t x
Top-left x coordinate.
Definition: Types.h:546
float score
Confidence value for the detection window.
Definition: Types.h:551
void resize(size_t num)
Resizes the array to contain "num" elements.
Definition: IArray.h:128
#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
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:160
virtual T * buffer() const =0
Pointer to the first element of the array.
size_t num_values() const
Number of values currently stored in the array.
Definition: IArray.h:68
uint16_t width
Width of the detection window.
Definition: Types.h:548
#define ARM_COMPUTE_ERROR_ON_MISMATCHING_WINDOWS(f, w)
Definition: Validate.h:183
uint16_t idx_class
Index of the class.
Definition: Types.h:550
uint16_t height
Height of the detection window.
Definition: Types.h:549
Detection window used for the object detection.
Definition: Types.h:544
uint16_t y
Top-left y coordinate.
Definition: Types.h:547
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:940
virtual T & at(size_t index) const
Reference to the element of the array located at the given index.
Definition: IArray.h:117

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_MISMATCHING_WINDOWS, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, IArray< T >::at(), IArray< T >::buffer(), DetectionWindow::height, DetectionWindow::idx_class, arm_compute::test::validation::info, IArray< T >::num_values(), IArray< T >::resize(), DetectionWindow::score, DetectionWindow::width, IKernel::window(), DetectionWindow::x, and DetectionWindow::y.


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