ArmNN
 20.02
RefDetectionPostProcessTests.cpp File Reference
#include <reference/workloads/DetectionPostProcess.hpp>
#include <armnn/Descriptors.hpp>
#include <armnn/Types.hpp>
#include <boost/test/unit_test.hpp>

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (TopKSortTest)
 
 BOOST_AUTO_TEST_CASE (FullTopKSortTest)
 
 BOOST_AUTO_TEST_CASE (IouTest)
 
 BOOST_AUTO_TEST_CASE (NmsFunction)
 
void DetectionPostProcessTestImpl (bool useRegularNms, const std::vector< float > &expectedDetectionBoxes, const std::vector< float > &expectedDetectionClasses, const std::vector< float > &expectedDetectionScores, const std::vector< float > &expectedNumDetections)
 
 BOOST_AUTO_TEST_CASE (RegularNmsDetectionPostProcess)
 
 BOOST_AUTO_TEST_CASE (FastNmsDetectionPostProcess)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/6]

BOOST_AUTO_TEST_CASE ( TopKSortTest  )

Definition at line 15 of file RefDetectionPostProcessTests.cpp.

References armnn::TopKSort().

16 {
17  unsigned int k = 3;
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 };
20  armnn::TopKSort(k, indices, values, 8);
21  BOOST_TEST(indices[0] == 7);
22  BOOST_TEST(indices[1] == 1);
23  BOOST_TEST(indices[2] == 2);
24 }
void TopKSort(unsigned int k, unsigned int *indices, const float *values, unsigned int numElement)

◆ BOOST_AUTO_TEST_CASE() [2/6]

BOOST_AUTO_TEST_CASE ( FullTopKSortTest  )

Definition at line 26 of file RefDetectionPostProcessTests.cpp.

References armnn::TopKSort().

27 {
28  unsigned int k = 8;
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 };
31  armnn::TopKSort(k, indices, values, 8);
32  BOOST_TEST(indices[0] == 7);
33  BOOST_TEST(indices[1] == 1);
34  BOOST_TEST(indices[2] == 2);
35  BOOST_TEST(indices[3] == 3);
36  BOOST_TEST(indices[4] == 4);
37  BOOST_TEST(indices[5] == 5);
38  BOOST_TEST(indices[6] == 6);
39  BOOST_TEST(indices[7] == 0);
40 }
void TopKSort(unsigned int k, unsigned int *indices, const float *values, unsigned int numElement)

◆ BOOST_AUTO_TEST_CASE() [3/6]

BOOST_AUTO_TEST_CASE ( IouTest  )

Definition at line 42 of file RefDetectionPostProcessTests.cpp.

References armnn::IntersectionOverUnion().

43 {
44  float boxI[4] = { 0.0f, 0.0f, 10.0f, 10.0f };
45  float boxJ[4] = { 1.0f, 1.0f, 11.0f, 11.0f };
46  float iou = armnn::IntersectionOverUnion(boxI, boxJ);
47  BOOST_TEST(iou == 0.68, boost::test_tools::tolerance(0.001));
48 }
float IntersectionOverUnion(const float *boxI, const float *boxJ)

◆ BOOST_AUTO_TEST_CASE() [4/6]

BOOST_AUTO_TEST_CASE ( NmsFunction  )

Definition at line 50 of file RefDetectionPostProcessTests.cpp.

References armnn::NonMaxSuppression(), and scores().

51 {
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
59  });
60 
61  std::vector<float> scores({ 0.9f, 0.75f, 0.6f, 0.93f, 0.5f, 0.3f });
62 
63  std::vector<unsigned int> result =
64  armnn::NonMaxSuppression(6, boxCorners, scores, 0.0, 3, 0.5);
65 
66  BOOST_TEST(result.size() == 3);
67  BOOST_TEST(result[0] == 3);
68  BOOST_TEST(result[1] == 0);
69  BOOST_TEST(result[2] == 5);
70 }
std::vector< float > scores({ 0.0f, 0.9f, 0.8f, 0.0f, 0.75f, 0.72f, 0.0f, 0.6f, 0.5f, 0.0f, 0.93f, 0.95f, 0.0f, 0.5f, 0.4f, 0.0f, 0.3f, 0.2f })
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)

◆ BOOST_AUTO_TEST_CASE() [5/6]

BOOST_AUTO_TEST_CASE ( RegularNmsDetectionPostProcess  )

Definition at line 173 of file RefDetectionPostProcessTests.cpp.

References DetectionPostProcessTestImpl().

174 {
175  std::vector<float> expectedDetectionBoxes({
176  0.0f, 10.0f, 1.0f, 11.0f,
177  0.0f, 10.0f, 1.0f, 11.0f,
178  0.0f, 0.0f, 0.0f, 0.0f
179  });
180 
181  std::vector<float> expectedDetectionScores({ 0.95f, 0.93f, 0.0f });
182  std::vector<float> expectedDetectionClasses({ 1.0f, 0.0f, 0.0f });
183  std::vector<float> expectedNumDetections({ 2.0f });
184 
185  DetectionPostProcessTestImpl(true, expectedDetectionBoxes, expectedDetectionClasses,
186  expectedDetectionScores, expectedNumDetections);
187 }
void DetectionPostProcessTestImpl(bool useRegularNms, const std::vector< float > &expectedDetectionBoxes, const std::vector< float > &expectedDetectionClasses, const std::vector< float > &expectedDetectionScores, const std::vector< float > &expectedNumDetections)

◆ BOOST_AUTO_TEST_CASE() [6/6]

BOOST_AUTO_TEST_CASE ( FastNmsDetectionPostProcess  )

Definition at line 189 of file RefDetectionPostProcessTests.cpp.

References BOOST_AUTO_TEST_SUITE_END(), and DetectionPostProcessTestImpl().

190 {
191  std::vector<float> expectedDetectionBoxes({
192  0.0f, 10.0f, 1.0f, 11.0f,
193  0.0f, 0.0f, 1.0f, 1.0f,
194  0.0f, 100.0f, 1.0f, 101.0f
195  });
196  std::vector<float> expectedDetectionScores({ 0.95f, 0.9f, 0.3f });
197  std::vector<float> expectedDetectionClasses({ 1.0f, 0.0f, 0.0f });
198  std::vector<float> expectedNumDetections({ 3.0f });
199 
200  DetectionPostProcessTestImpl(false, expectedDetectionBoxes, expectedDetectionClasses,
201  expectedDetectionScores, expectedNumDetections);
202 }
void DetectionPostProcessTestImpl(bool useRegularNms, const std::vector< float > &expectedDetectionBoxes, const std::vector< float > &expectedDetectionClasses, const std::vector< float > &expectedDetectionScores, const std::vector< float > &expectedNumDetections)

◆ DetectionPostProcessTestImpl()

void DetectionPostProcessTestImpl ( bool  useRegularNms,
const std::vector< float > &  expectedDetectionBoxes,
const std::vector< float > &  expectedDetectionClasses,
const std::vector< float > &  expectedDetectionScores,
const std::vector< float > &  expectedNumDetections 
)

Definition at line 72 of file RefDetectionPostProcessTests.cpp.

References anchors(), anchorsInfo, boxEncodings(), armnn::DetectionPostProcess(), armnn::Float32, DetectionPostProcessDescriptor::m_UseRegularNms, scores(), and scoresInfo.

Referenced by BOOST_AUTO_TEST_CASE().

77 {
78  armnn::TensorInfo boxEncodingsInfo({ 1, 6, 4 }, armnn::DataType::Float32);
81 
82  armnn::TensorInfo detectionBoxesInfo({ 1, 3, 4 }, armnn::DataType::Float32);
83  armnn::TensorInfo detectionScoresInfo({ 1, 3 }, armnn::DataType::Float32);
84  armnn::TensorInfo detectionClassesInfo({ 1, 3 }, armnn::DataType::Float32);
85  armnn::TensorInfo numDetectionInfo({ 1 }, armnn::DataType::Float32);
86 
88  desc.m_UseRegularNms = useRegularNms;
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;
95  desc.m_ScaleY = 10.0;
96  desc.m_ScaleX = 10.0;
97  desc.m_ScaleH = 5.0;
98  desc.m_ScaleW = 5.0;
99 
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
107  });
108 
109  std::vector<float> scores({
110  0.0f, 0.9f, 0.8f,
111  0.0f, 0.75f, 0.72f,
112  0.0f, 0.6f, 0.5f,
113  0.0f, 0.93f, 0.95f,
114  0.0f, 0.5f, 0.4f,
115  0.0f, 0.3f, 0.2f
116  });
117 
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
125  });
126 
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());
130 
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);
135 
136  armnn::DetectionPostProcess(boxEncodingsInfo,
137  scoresInfo,
138  anchorsInfo,
139  detectionBoxesInfo,
140  detectionClassesInfo,
141  detectionScoresInfo,
142  numDetectionInfo,
143  desc,
144  *boxEncodingsDecoder,
145  *scoresDecoder,
146  *anchorsDecoder,
147  detectionBoxes.data(),
148  detectionClasses.data(),
149  detectionScores.data(),
150  numDetections.data());
151 
152  BOOST_CHECK_EQUAL_COLLECTIONS(detectionBoxes.begin(),
153  detectionBoxes.end(),
154  expectedDetectionBoxes.begin(),
155  expectedDetectionBoxes.end());
156 
157  BOOST_CHECK_EQUAL_COLLECTIONS(detectionScores.begin(),
158  detectionScores.end(),
159  expectedDetectionScores.begin(),
160  expectedDetectionScores.end());
161 
162  BOOST_CHECK_EQUAL_COLLECTIONS(detectionClasses.begin(),
163  detectionClasses.end(),
164  expectedDetectionClasses.begin(),
165  expectedDetectionClasses.end());
166 
167  BOOST_CHECK_EQUAL_COLLECTIONS(numDetections.begin(),
168  numDetections.end(),
169  expectedNumDetections.begin(),
170  expectedNumDetections.end());
171 }
armnn::TensorInfo anchorsInfo({ 6, 4 }, armnn::DataType::Float32)
std::vector< float > boxEncodings({ 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f })
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)
bool m_UseRegularNms
Use Regular NMS.
std::vector< float > scores({ 0.0f, 0.9f, 0.8f, 0.0f, 0.75f, 0.72f, 0.0f, 0.6f, 0.5f, 0.0f, 0.93f, 0.95f, 0.0f, 0.5f, 0.4f, 0.0f, 0.3f, 0.2f })
armnn::TensorInfo scoresInfo({ 1, 6, 3 }, armnn::DataType::Float32)
std::vector< float > anchors({ 0.5f, 0.5f, 1.0f, 1.0f, 0.5f, 0.5f, 1.0f, 1.0f, 0.5f, 0.5f, 1.0f, 1.0f, 0.5f, 10.5f, 1.0f, 1.0f, 0.5f, 10.5f, 1.0f, 1.0f, 0.5f, 100.5f, 1.0f, 1.0f })