15 TEST_CASE(
"TopKSortTest")
18 unsigned int indices[8] = { 0, 1, 2, 3, 4, 5, 6, 7 };
19 float values[8] = { 0, 7, 6, 5, 4, 3, 2, 500 };
21 CHECK(indices[0] == 7);
22 CHECK(indices[1] == 1);
23 CHECK(indices[2] == 2);
26 TEST_CASE(
"FullTopKSortTest")
29 unsigned int indices[8] = { 0, 1, 2, 3, 4, 5, 6, 7 };
30 float values[8] = { 0, 7, 6, 5, 4, 3, 2, 500 };
32 CHECK(indices[0] == 7);
33 CHECK(indices[1] == 1);
34 CHECK(indices[2] == 2);
35 CHECK(indices[3] == 3);
36 CHECK(indices[4] == 4);
37 CHECK(indices[5] == 5);
38 CHECK(indices[6] == 6);
39 CHECK(indices[7] == 0);
44 float boxI[4] = { 0.0f, 0.0f, 10.0f, 10.0f };
45 float boxJ[4] = { 1.0f, 1.0f, 11.0f, 11.0f };
47 CHECK(iou == doctest::Approx(0.68).epsilon(0.001f));
50 TEST_CASE(
"NmsFunction")
52 std::vector<float> boxCorners({
53 0.0f, 0.0f, 1.0f, 1.0f,
54 0.0f, 0.1f, 1.0f, 1.1f,
55 0.0f, -0.1f, 1.0f, 0.9f,
56 0.0f, 10.0f, 1.0f, 11.0f,
57 0.0f, 10.1f, 1.0f, 11.1f,
58 0.0f, 100.0f, 1.0f, 101.0f
61 std::vector<float> scores({ 0.9f, 0.75f, 0.6f, 0.93f, 0.5f, 0.3f });
63 std::vector<unsigned int> result =
66 CHECK(result.size() == 3);
67 CHECK(result[0] == 3);
68 CHECK(result[1] == 0);
69 CHECK(result[2] == 5);
72 void DetectionPostProcessTestImpl(
bool useRegularNms,
73 const std::vector<float>& expectedDetectionBoxes,
74 const std::vector<float>& expectedDetectionClasses,
75 const std::vector<float>& expectedDetectionScores,
76 const std::vector<float>& expectedNumDetections)
89 desc.m_MaxDetections = 3;
90 desc.m_MaxClassesPerDetection = 1;
91 desc.m_DetectionsPerClass =1;
92 desc.m_NmsScoreThreshold = 0.0;
93 desc.m_NmsIouThreshold = 0.5;
94 desc.m_NumClasses = 2;
100 std::vector<float> boxEncodings({
101 0.0f, 0.0f, 0.0f, 0.0f,
102 0.0f, 1.0f, 0.0f, 0.0f,
103 0.0f, -1.0f, 0.0f, 0.0f,
104 0.0f, 0.0f, 0.0f, 0.0f,
105 0.0f, 1.0f, 0.0f, 0.0f,
106 0.0f, 0.0f, 0.0f, 0.0f
109 std::vector<float> scores({
118 std::vector<float> anchors({
119 0.5f, 0.5f, 1.0f, 1.0f,
120 0.5f, 0.5f, 1.0f, 1.0f,
121 0.5f, 0.5f, 1.0f, 1.0f,
122 0.5f, 10.5f, 1.0f, 1.0f,
123 0.5f, 10.5f, 1.0f, 1.0f,
124 0.5f, 100.5f, 1.0f, 1.0f
127 auto boxEncodingsDecoder = armnn::MakeDecoder<float>(boxEncodingsInfo, boxEncodings.data());
128 auto scoresDecoder = armnn::MakeDecoder<float>(scoresInfo, scores.data());
129 auto anchorsDecoder = armnn::MakeDecoder<float>(anchorsInfo, anchors.data());
131 std::vector<float> detectionBoxes(detectionBoxesInfo.GetNumElements());
132 std::vector<float> detectionScores(detectionScoresInfo.GetNumElements());
133 std::vector<float> detectionClasses(detectionClassesInfo.GetNumElements());
134 std::vector<float> numDetections(1);
140 detectionClassesInfo,
144 *boxEncodingsDecoder,
147 detectionBoxes.data(),
148 detectionClasses.data(),
149 detectionScores.data(),
150 numDetections.data());
152 CHECK(std::equal(detectionBoxes.begin(),
153 detectionBoxes.end(),
154 expectedDetectionBoxes.begin(),
155 expectedDetectionBoxes.end()));
157 CHECK(std::equal(detectionScores.begin(), detectionScores.end(),
158 expectedDetectionScores.begin(), expectedDetectionScores.end()));
160 CHECK(std::equal(detectionClasses.begin(), detectionClasses.end(),
161 expectedDetectionClasses.begin(), expectedDetectionClasses.end()));
163 CHECK(std::equal(numDetections.begin(), numDetections.end(),
164 expectedNumDetections.begin(), expectedNumDetections.end()));
167 TEST_CASE(
"RegularNmsDetectionPostProcess")
169 std::vector<float> expectedDetectionBoxes({
170 0.0f, 10.0f, 1.0f, 11.0f,
171 0.0f, 10.0f, 1.0f, 11.0f,
172 0.0f, 0.0f, 0.0f, 0.0f
175 std::vector<float> expectedDetectionScores({ 0.95f, 0.93f, 0.0f });
176 std::vector<float> expectedDetectionClasses({ 1.0f, 0.0f, 0.0f });
177 std::vector<float> expectedNumDetections({ 2.0f });
179 DetectionPostProcessTestImpl(
true, expectedDetectionBoxes, expectedDetectionClasses,
180 expectedDetectionScores, expectedNumDetections);
183 TEST_CASE(
"FastNmsDetectionPostProcess")
185 std::vector<float> expectedDetectionBoxes({
186 0.0f, 10.0f, 1.0f, 11.0f,
187 0.0f, 0.0f, 1.0f, 1.0f,
188 0.0f, 100.0f, 1.0f, 101.0f
190 std::vector<float> expectedDetectionScores({ 0.95f, 0.9f, 0.3f });
191 std::vector<float> expectedDetectionClasses({ 1.0f, 0.0f, 0.0f });
192 std::vector<float> expectedNumDetections({ 3.0f });
194 DetectionPostProcessTestImpl(
false, expectedDetectionBoxes, expectedDetectionClasses,
195 expectedDetectionScores, expectedNumDetections);
float IntersectionOverUnion(const float *boxI, const float *boxJ)
void DetectionPostProcess(const TensorInfo &boxEncodingsInfo, const TensorInfo &scoresInfo, const TensorInfo &anchorsInfo, const TensorInfo &detectionBoxesInfo, const TensorInfo &detectionClassesInfo, const TensorInfo &detectionScoresInfo, const TensorInfo &numDetectionsInfo, const DetectionPostProcessDescriptor &desc, Decoder< float > &boxEncodings, Decoder< float > &scores, Decoder< float > &anchors, float *detectionBoxes, float *detectionClasses, float *detectionScores, float *numDetections)
void TopKSort(unsigned int k, unsigned int *indices, const float *values, unsigned int numElement)
bool m_UseRegularNms
Use Regular NMS.
std::vector< unsigned int > NonMaxSuppression(unsigned int numBoxes, const std::vector< float > &boxCorners, const std::vector< float > &scores, float nmsScoreThreshold, unsigned int maxDetection, float nmsIouThreshold)