11 #include <boost/test/unit_test.hpp> 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 BOOST_TEST(indices[0] == 7);
22 BOOST_TEST(indices[1] == 1);
23 BOOST_TEST(indices[2] == 2);
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 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);
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 BOOST_TEST(iou == 0.68, boost::test_tools::tolerance(0.001));
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 BOOST_TEST(result.size() == 3);
67 BOOST_TEST(result[0] == 3);
68 BOOST_TEST(result[1] == 0);
69 BOOST_TEST(result[2] == 5);
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;
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({
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());
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 BOOST_CHECK_EQUAL_COLLECTIONS(detectionBoxes.begin(),
153 detectionBoxes.end(),
154 expectedDetectionBoxes.begin(),
155 expectedDetectionBoxes.end());
157 BOOST_CHECK_EQUAL_COLLECTIONS(detectionScores.begin(),
158 detectionScores.end(),
159 expectedDetectionScores.begin(),
160 expectedDetectionScores.end());
162 BOOST_CHECK_EQUAL_COLLECTIONS(detectionClasses.begin(),
163 detectionClasses.end(),
164 expectedDetectionClasses.begin(),
165 expectedDetectionClasses.end());
167 BOOST_CHECK_EQUAL_COLLECTIONS(numDetections.begin(),
169 expectedNumDetections.begin(),
170 expectedNumDetections.end());
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
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 });
186 expectedDetectionScores, expectedNumDetections);
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
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 });
201 expectedDetectionScores, expectedNumDetections);
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
float IntersectionOverUnion(const float *boxI, const float *boxJ)
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 DetectionPostProcessTestImpl(bool useRegularNms, const std::vector< float > &expectedDetectionBoxes, const std::vector< float > &expectedDetectionClasses, const std::vector< float > &expectedDetectionScores, const std::vector< float > &expectedNumDetections)
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.
BOOST_AUTO_TEST_CASE(TopKSortTest)
BOOST_AUTO_TEST_SUITE_END()
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< unsigned int > NonMaxSuppression(unsigned int numBoxes, const std::vector< float > &boxCorners, const std::vector< float > &scores, float nmsScoreThreshold, unsigned int maxDetection, float nmsIouThreshold)
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 })