10 #include <boost/assert.hpp> 11 #include <boost/numeric/conversion/cast.hpp> 12 #include <boost/test/tools/floating_point_comparison.hpp> 19 template<
typename Model>
23 MobileNetSsdTestCase(
Model& model,
24 unsigned int testCaseId,
25 const MobileNetSsdTestCaseData& testCaseData)
28 { std::move(testCaseData.m_InputData) },
29 { k_OutputSize1, k_OutputSize2, k_OutputSize3, k_OutputSize4 })
30 , m_FloatComparer(boost::math::fpc::percent_tolerance(1.0f))
31 , m_DetectedObjects(testCaseData.m_ExpectedDetectedObject)
36 boost::ignore_unused(options);
38 const std::vector<float>& output1 = boost::get<std::vector<float>>(this->
GetOutputs()[0]);
39 BOOST_ASSERT(output1.size() == k_OutputSize1);
41 const std::vector<float>& output2 = boost::get<std::vector<float>>(this->
GetOutputs()[1]);
42 BOOST_ASSERT(output2.size() == k_OutputSize2);
44 const std::vector<float>& output3 = boost::get<std::vector<float>>(this->
GetOutputs()[2]);
45 BOOST_ASSERT(output3.size() == k_OutputSize3);
47 const std::vector<float>& output4 = boost::get<std::vector<float>>(this->
GetOutputs()[3]);
48 BOOST_ASSERT(output4.size() == k_OutputSize4);
50 const size_t numDetections = boost::numeric_cast<
size_t>(output4[0]);
53 const size_t expectedNumDetections = m_DetectedObjects.size();
54 if (numDetections != expectedNumDetections)
56 ARMNN_LOG(error) <<
"Number of detections is incorrect: Expected (" <<
57 expectedNumDetections <<
")" <<
" but got (" << numDetections <<
")";
62 std::vector<DetectedObject> detectedObjects;
63 const float* outputData = output1.data();
64 for (
unsigned int i = 0u; i < numDetections; i++)
67 float yMin = *outputData++;
68 float xMin = *outputData++;
69 float yMax = *outputData++;
70 float xMax = *outputData++;
72 DetectedObject detectedObject(
74 BoundingBox(xMin, yMin, xMax, yMax),
77 detectedObjects.push_back(detectedObject);
80 std::sort(detectedObjects.begin(), detectedObjects.end());
81 std::sort(m_DetectedObjects.begin(), m_DetectedObjects.end());
84 std::vector<DetectedObject>::const_iterator it = detectedObjects.begin();
85 for (
unsigned int i = 0; i < numDetections; i++)
87 if (it == detectedObjects.end())
89 ARMNN_LOG(error) <<
"No more detected objects found! Index out of bounds: " << i;
93 const DetectedObject& detectedObject = *it;
94 const DetectedObject& expectedObject = m_DetectedObjects[i];
96 if (detectedObject.m_Class != expectedObject.m_Class)
99 " is incorrect: Expected (" << expectedObject.m_Class <<
")" <<
100 " but predicted (" << detectedObject.m_Class <<
")";
104 if(!m_FloatComparer(detectedObject.m_Confidence, expectedObject.m_Confidence))
107 " is incorrect: Expected (" << expectedObject.m_Confidence <<
") +- 1.0 pc" <<
108 " but predicted (" << detectedObject.m_Confidence <<
")";
112 if (!m_FloatComparer(detectedObject.m_BoundingBox.m_XMin, expectedObject.m_BoundingBox.m_XMin) ||
113 !m_FloatComparer(detectedObject.m_BoundingBox.m_YMin, expectedObject.m_BoundingBox.m_YMin) ||
114 !m_FloatComparer(detectedObject.m_BoundingBox.m_XMax, expectedObject.m_BoundingBox.m_XMax) ||
115 !m_FloatComparer(detectedObject.m_BoundingBox.m_YMax, expectedObject.m_BoundingBox.m_YMax))
129 static constexpr
unsigned int k_Shape = 10u;
131 static constexpr
unsigned int k_OutputSize1 = k_Shape * 4u;
132 static constexpr
unsigned int k_OutputSize2 = k_Shape;
133 static constexpr
unsigned int k_OutputSize3 = k_Shape;
134 static constexpr
unsigned int k_OutputSize4 = 1u;
136 boost::math::fpc::close_at_tolerance<float> m_FloatComparer;
137 std::vector<DetectedObject> m_DetectedObjects;
140 template <
typename Model>
144 template <
typename TConstructModelCallable>
145 explicit MobileNetSsdTestCaseProvider(TConstructModelCallable constructModel)
146 : m_ConstructModel(constructModel)
149 virtual void AddCommandLineOptions(boost::program_options::options_description& options)
override 151 namespace po = boost::program_options;
153 options.add_options()
154 (
"data-dir,d", po::value<std::string>(&m_DataDir)->required(),
155 "Path to directory containing test data");
157 Model::AddCommandLineOptions(options, m_ModelCommandLineOptions);
167 m_Model = m_ConstructModel(commonOptions, m_ModelCommandLineOptions);
172 std::pair<float, int32_t> qParams = m_Model->GetInputQuantizationParams();
173 m_Database = std::make_unique<MobileNetSsdDatabase>(m_DataDir.c_str(), qParams.first, qParams.second);
182 std::unique_ptr<IInferenceTestCase> GetTestCase(
unsigned int testCaseId)
override 184 std::unique_ptr<MobileNetSsdTestCaseData> testCaseData = m_Database->GetTestCaseData(testCaseId);
190 return std::make_unique<MobileNetSsdTestCase<Model>>(*m_Model, testCaseId, *testCaseData);
194 typename Model::CommandLineOptions m_ModelCommandLineOptions;
196 typename Model::CommandLineOptions)> m_ConstructModel;
197 std::unique_ptr<Model> m_Model;
199 std::string m_DataDir;
200 std::unique_ptr<MobileNetSsdDatabase> m_Database;
#define ARMNN_LOG(severity)
The test completed without any errors.
const std::vector< TContainer > & GetOutputs() const
virtual TestCaseResult ProcessResult(const InferenceTestOptions &options)=0
unsigned int GetTestCaseId() const
The test failed with a fatal error. The remaining tests will not be run.
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
bool ValidateDirectory(std::string &dir)