MCPcopy Create free account
hub / github.com/ARM-software/armnn / NonMaxSuppression

Function NonMaxSuppression

samples/ObjectDetection/src/NonMaxSuppression.cpp:48–90  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46}
47
48std::vector<int> NonMaxSuppression(DetectedObjects& inputDetections, float iouThresh)
49{
50 // Sort indicies of detections by highest score to lowest.
51 std::vector<unsigned int> sortedIndicies = GenerateRangeK(inputDetections.size());
52 std::sort(sortedIndicies.begin(), sortedIndicies.end(),
53 [&inputDetections](int idx1, int idx2)
54 {
55 return inputDetections[idx1].GetScore() > inputDetections[idx2].GetScore();
56 });
57
58 std::vector<bool> visited(inputDetections.size(), false);
59 std::vector<int> outputIndiciesAfterNMS;
60
61 for (int i=0; i < inputDetections.size(); ++i)
62 {
63 // Each new unvisited detect should be kept.
64 if (!visited[sortedIndicies[i]])
65 {
66 outputIndiciesAfterNMS.emplace_back(sortedIndicies[i]);
67 visited[sortedIndicies[i]] = true;
68 }
69
70 // Look for detections to suppress.
71 for (int j=i+1; j<inputDetections.size(); ++j)
72 {
73 // Skip if already kept or suppressed.
74 if (!visited[sortedIndicies[j]])
75 {
76 // Detects must have the same label to be suppressed.
77 if (inputDetections[sortedIndicies[j]].GetLabel() == inputDetections[sortedIndicies[i]].GetLabel())
78 {
79 auto iou = IntersectionOverUnion(inputDetections[sortedIndicies[i]],
80 inputDetections[sortedIndicies[j]]);
81 if (iou > iouThresh)
82 {
83 visited[sortedIndicies[j]] = true;
84 }
85 }
86 }
87 }
88 }
89 return outputIndiciesAfterNMS;
90}
91
92} // namespace od

Callers 2

DecodeMethod · 0.70
NMSTests.cppFile · 0.50

Calls 6

GetScoreMethod · 0.80
GenerateRangeKFunction · 0.70
IntersectionOverUnionFunction · 0.70
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected