Compute Library
 21.02
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...
 
 ~CPPDetectionWindowNonMaximaSuppressionKernel ()=default
 Default destructor. 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...
 
virtual void run_nd (const Window &window, const ThreadInfo &info, const Window &thread_locator)
 legacy compatibility layer for implemantions which do not support thread_locator In these cases we simply narrow the interface down the legacy version More...
 
virtual void run_op (ITensorPack &tensors, const Window &window, const ThreadInfo &info)
 Execute the kernel on the passed window. 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 60 of file CPPDetectionWindowNonMaximaSuppressionKernel.cpp.

Referenced by CPPDetectionWindowNonMaximaSuppressionKernel::name().

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

◆ 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.

◆ ~CPPDetectionWindowNonMaximaSuppressionKernel()

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

References ARM_COMPUTE_ERROR_ON.

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

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

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

Referenced by CPPDetectionWindowNonMaximaSuppressionKernel::name().

66 {
67  return false;
68 }

◆ name()

◆ operator=() [1/2]

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

Referenced by CPPDetectionWindowNonMaximaSuppressionKernel::name().

◆ 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.

Reimplemented from ICPPKernel.

Definition at line 80 of file CPPDetectionWindowNonMaximaSuppressionKernel.cpp.

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, IArray< T >::num_values(), IArray< T >::resize(), DetectionWindow::score, DetectionWindow::width, IKernel::window(), DetectionWindow::x, and DetectionWindow::y.

Referenced by CPPDetectionWindowNonMaximaSuppressionKernel::name().

81 {
82  ARM_COMPUTE_UNUSED(info);
83  ARM_COMPUTE_UNUSED(window);
86  ARM_COMPUTE_ERROR_ON(_input_output->buffer() == nullptr);
87 
88  const size_t num_candidates = _input_output->num_values();
89  size_t num_detections = 0;
90 
91  // Sort list of candidates by idx_class and then score
92  std::sort(_input_output->buffer(), _input_output->buffer() + num_candidates, compare_detection_window);
93 
94  const float min_distance_pow2 = _min_distance * _min_distance;
95 
96  // Euclidean distance
97  for(size_t i = 0; i < num_candidates; ++i)
98  {
99  if(0.0f != _input_output->at(i).score)
100  {
101  DetectionWindow cur;
102  cur.x = _input_output->at(i).x;
103  cur.y = _input_output->at(i).y;
104  cur.width = _input_output->at(i).width;
105  cur.height = _input_output->at(i).height;
106  cur.idx_class = _input_output->at(i).idx_class;
107  cur.score = _input_output->at(i).score;
108 
109  // Store window
110  _input_output->at(num_detections) = cur;
111 
112  ++num_detections;
113 
114  const float xc = cur.x + cur.width * 0.5f;
115  const float yc = cur.y + cur.height * 0.5f;
116 
117  for(size_t k = i + 1; k < (num_candidates) && (cur.idx_class == _input_output->at(k).idx_class); ++k)
118  {
119  const float xn = _input_output->at(k).x + _input_output->at(k).width * 0.5f;
120  const float yn = _input_output->at(k).y + _input_output->at(k).height * 0.5f;
121 
122  const float dx = std::fabs(xn - xc);
123  const float dy = std::fabs(yn - yc);
124 
125  if(dx < _min_distance && dy < _min_distance)
126  {
127  const float d = dx * dx + dy * dy;
128 
129  if(d < min_distance_pow2)
130  {
131  // Invalidate detection window
132  _input_output->at(k).score = 0.0f;
133  }
134  }
135  }
136  }
137  }
138 
139  _input_output->resize(num_detections);
140 }
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:592
float score
Confidence value for the detection window.
Definition: Types.h:597
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:466
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
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
#define ARM_COMPUTE_ERROR_ON_MISMATCHING_WINDOWS(f, w)
Definition: Validate.h:183
uint16_t width
Width of the detection window.
Definition: Types.h:594
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:941
uint16_t idx_class
Index of the class.
Definition: Types.h:596
uint16_t height
Height of the detection window.
Definition: Types.h:595
Detection window used for the object detection.
Definition: Types.h:590
uint16_t y
Top-left y coordinate.
Definition: Types.h:593
virtual T & at(size_t index) const
Reference to the element of the array located at the given index.
Definition: IArray.h:117

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