ArmNN
 22.05
yolov3 Namespace Reference

Classes

struct  Box
 Box representation structure. More...
 
struct  Detection
 Detection structure. More...
 
struct  NMSConfig
 Non Maxima Suprresion configuration meta-data. More...
 

Functions

bool compare_detection (const yolov3::Detection &detection, const std::vector< float > &expected)
 Compare a detection object with a vector of float values. More...
 
void print_detection (std::ostream &os, const std::vector< Detection > &detections)
 Print identified yolo detections. More...
 
std::vector< Detectionnms (const NMSConfig &config, const std::vector< float > &detected_boxes)
 Perform Non-Maxima Supression on a list of given detections. More...
 

Function Documentation

◆ compare_detection()

bool compare_detection ( const yolov3::Detection detection,
const std::vector< float > &  expected 
)

Compare a detection object with a vector of float values.

Parameters
detection[in] Detection object
expected[in] Vector of expected float values
Returns
Boolean to represent if they match or not

Definition at line 84 of file NMS.cpp.

References Detection::box, Detection::classes, Detection::confidence, Box::xmax, Box::xmin, Box::ymax, and Box::ymin.

Referenced by CheckAccuracy().

86 {
87  float tolerance = 0.001f;
88  return (std::fabs(detection.classes[0] - expected[0]) < tolerance &&
89  std::fabs(detection.box.xmin - expected[1]) < tolerance &&
90  std::fabs(detection.box.ymin - expected[2]) < tolerance &&
91  std::fabs(detection.box.xmax - expected[3]) < tolerance &&
92  std::fabs(detection.box.ymax - expected[4]) < tolerance &&
93  std::fabs(detection.confidence - expected[5]) < tolerance );
94 }
float confidence
Confidence of detection.
Definition: NMS.hpp:31
float ymin
Y-pos position of the low left coordinate.
Definition: NMS.hpp:24
float xmin
X-pos position of the low left coordinate.
Definition: NMS.hpp:22
float xmax
X-pos position of the top right coordinate.
Definition: NMS.hpp:23
std::vector< float > classes
Probability of classes.
Definition: NMS.hpp:32
Box box
Detection box.
Definition: NMS.hpp:30
float ymax
Y-pos position of the top right coordinate.
Definition: NMS.hpp:25

◆ nms()

std::vector< Detection > nms ( const NMSConfig config,
const std::vector< float > &  detected_boxes 
)

Perform Non-Maxima Supression on a list of given detections.

Parameters
[in]configConfiguration metadata for NMS
[in]detected_boxesDetected boxes
Returns
A vector with the final detections

Definition at line 113 of file NMS.cpp.

References Detection::classes, NMSConfig::iou_threshold, and NMSConfig::num_classes.

114  {
115  // Get detections that comply with the expected confidence threshold
116  std::vector<Detection> detections =
117  convert_to_detections(config, detected_boxes);
118 
119  const unsigned int num_detections = static_cast<unsigned int>(detections.size());
120  for (unsigned int c = 0; c < config.num_classes; ++c)
121  {
122  // Sort classes
123  std::sort(detections.begin(), detections.begin() + static_cast<std::ptrdiff_t>(num_detections),
124  [c](Detection& detection1, Detection& detection2)
125  {
126  return (detection1.classes[c] - detection2.classes[c]) > 0;
127  });
128  // Clear detections with high IoU
129  for (unsigned int d = 0; d < num_detections; ++d)
130  {
131  // Check if class is already cleared/invalidated
132  if (detections[d].classes[c] == 0.f)
133  {
134  continue;
135  }
136 
137  // Filter out boxes on IoU threshold
138  const Box& box1 = detections[d].box;
139  for (unsigned int b = d + 1; b < num_detections; ++b)
140  {
141  const Box& box2 = detections[b].box;
142  if (iou(box1, box2) > config.iou_threshold)
143  {
144  detections[b].classes[c] = 0.f;
145  }
146  }
147  }
148  }
149  return detections;
150 }

◆ print_detection()

void print_detection ( std::ostream &  os,
const std::vector< Detection > &  detections 
)

Print identified yolo detections.

Parameters
[in,out]osOutput stream to print to
[in]detectionsDetections to print

Definition at line 96 of file NMS.cpp.

98 {
99  for (const auto& detection : detections)
100  {
101  for (unsigned int c = 0; c < detection.classes.size(); ++c)
102  {
103  if (detection.classes[c] != 0.0f)
104  {
105  os << c << " " << detection.classes[c] << " " << detection.box.xmin
106  << " " << detection.box.ymin << " " << detection.box.xmax << " "
107  << detection.box.ymax << std::endl;
108  }
109  }
110  }
111 }