ArmNN
 20.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

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

◆ 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 100 of file NMS.cpp.

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

101  {
102  // Get detections that comply with the expected confidence threshold
103  std::vector<Detection> detections =
104  convert_to_detections(config, detected_boxes);
105 
106  const unsigned int num_detections = static_cast<unsigned int>(detections.size());
107  for (unsigned int c = 0; c < config.num_classes; ++c)
108  {
109  // Sort classes
110  std::sort(detections.begin(), detections.begin() + static_cast<std::ptrdiff_t>(num_detections),
111  [c](Detection& detection1, Detection& detection2)
112  {
113  return (detection1.classes[c] - detection2.classes[c]) > 0;
114  });
115  // Clear detections with high IoU
116  for (unsigned int d = 0; d < num_detections; ++d)
117  {
118  // Check if class is already cleared/invalidated
119  if (detections[d].classes[c] == 0.f)
120  {
121  continue;
122  }
123 
124  // Filter out boxes on IoU threshold
125  const Box& box1 = detections[d].box;
126  for (unsigned int b = d + 1; b < num_detections; ++b)
127  {
128  const Box& box2 = detections[b].box;
129  if (iou(box1, box2) > config.iou_threshold)
130  {
131  detections[b].classes[c] = 0.f;
132  }
133  }
134  }
135  }
136  return detections;
137 }

◆ 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 83 of file NMS.cpp.

85 {
86  for (const auto& detection : detections)
87  {
88  for (unsigned int c = 0; c < detection.classes.size(); ++c)
89  {
90  if (detection.classes[c] != 0.0f)
91  {
92  os << c << " " << detection.classes[c] << " " << detection.box.xmin
93  << " " << detection.box.ymin << " " << detection.box.xmax << " "
94  << detection.box.ymax << std::endl;
95  }
96  }
97  }
98 }