12 #include <boost/assert.hpp> 13 #include <boost/numeric/conversion/cast.hpp> 14 #include <boost/test/tools/floating_point_comparison.hpp> 21 template<
typename Model>
25 MobileNetSsdTestCase(Model& model,
26 unsigned int testCaseId,
27 const MobileNetSsdTestCaseData& testCaseData)
30 { std::move(testCaseData.m_InputData) },
31 { k_OutputSize1, k_OutputSize2, k_OutputSize3, k_OutputSize4 })
32 , m_FloatComparer(boost::math::fpc::percent_tolerance(1.0f))
33 , m_DetectedObjects(testCaseData.m_ExpectedDetectedObject)
40 const std::vector<float>& output1 = boost::get<std::vector<float>>(this->
GetOutputs()[0]);
41 BOOST_ASSERT(output1.size() == k_OutputSize1);
43 const std::vector<float>& output2 = boost::get<std::vector<float>>(this->
GetOutputs()[1]);
44 BOOST_ASSERT(output2.size() == k_OutputSize2);
46 const std::vector<float>& output3 = boost::get<std::vector<float>>(this->
GetOutputs()[2]);
47 BOOST_ASSERT(output3.size() == k_OutputSize3);
49 const std::vector<float>& output4 = boost::get<std::vector<float>>(this->
GetOutputs()[3]);
50 BOOST_ASSERT(output4.size() == k_OutputSize4);
55 const size_t expectedNumDetections = m_DetectedObjects.size();
56 if (numDetections != expectedNumDetections)
58 ARMNN_LOG(error) <<
"Number of detections is incorrect: Expected (" <<
59 expectedNumDetections <<
")" <<
" but got (" << numDetections <<
")";
64 std::vector<DetectedObject> detectedObjects;
65 const float* outputData = output1.data();
66 for (
unsigned int i = 0u; i < numDetections; i++)
69 float yMin = *outputData++;
70 float xMin = *outputData++;
71 float yMax = *outputData++;
72 float xMax = *outputData++;
74 DetectedObject detectedObject(
76 BoundingBox(xMin, yMin, xMax, yMax),
79 detectedObjects.push_back(detectedObject);
82 std::sort(detectedObjects.begin(), detectedObjects.end());
83 std::sort(m_DetectedObjects.begin(), m_DetectedObjects.end());
86 std::vector<DetectedObject>::const_iterator it = detectedObjects.begin();
87 for (
unsigned int i = 0; i < numDetections; i++)
89 if (it == detectedObjects.end())
91 ARMNN_LOG(error) <<
"No more detected objects found! Index out of bounds: " << i;
95 const DetectedObject& detectedObject = *it;
96 const DetectedObject& expectedObject = m_DetectedObjects[i];
98 if (detectedObject.m_Class != expectedObject.m_Class)
101 " is incorrect: Expected (" << expectedObject.m_Class <<
")" <<
102 " but predicted (" << detectedObject.m_Class <<
")";
106 if(!m_FloatComparer(detectedObject.m_Confidence, expectedObject.m_Confidence))
109 " is incorrect: Expected (" << expectedObject.m_Confidence <<
") +- 1.0 pc" <<
110 " but predicted (" << detectedObject.m_Confidence <<
")";
114 if (!m_FloatComparer(detectedObject.m_BoundingBox.m_XMin, expectedObject.m_BoundingBox.m_XMin) ||
115 !m_FloatComparer(detectedObject.m_BoundingBox.m_YMin, expectedObject.m_BoundingBox.m_YMin) ||
116 !m_FloatComparer(detectedObject.m_BoundingBox.m_XMax, expectedObject.m_BoundingBox.m_XMax) ||
117 !m_FloatComparer(detectedObject.m_BoundingBox.m_YMax, expectedObject.m_BoundingBox.m_YMax))
131 static constexpr
unsigned int k_Shape = 10u;
133 static constexpr
unsigned int k_OutputSize1 = k_Shape * 4u;
134 static constexpr
unsigned int k_OutputSize2 = k_Shape;
135 static constexpr
unsigned int k_OutputSize3 = k_Shape;
136 static constexpr
unsigned int k_OutputSize4 = 1u;
138 boost::math::fpc::close_at_tolerance<float> m_FloatComparer;
139 std::vector<DetectedObject> m_DetectedObjects;
142 template <
typename Model>
146 template <
typename TConstructModelCallable>
147 explicit MobileNetSsdTestCaseProvider(TConstructModelCallable constructModel)
148 : m_ConstructModel(constructModel)
151 virtual void AddCommandLineOptions(boost::program_options::options_description& options)
override 153 namespace po = boost::program_options;
155 options.add_options()
156 (
"data-dir,d", po::value<std::string>(&m_DataDir)->required(),
157 "Path to directory containing test data");
159 Model::AddCommandLineOptions(options, m_ModelCommandLineOptions);
169 m_Model = m_ConstructModel(commonOptions, m_ModelCommandLineOptions);
174 std::pair<float, int32_t> qParams = m_Model->GetInputQuantizationParams();
175 m_Database = std::make_unique<MobileNetSsdDatabase>(m_DataDir.c_str(), qParams.first, qParams.second);
184 std::unique_ptr<IInferenceTestCase> GetTestCase(
unsigned int testCaseId)
override 186 std::unique_ptr<MobileNetSsdTestCaseData> testCaseData = m_Database->GetTestCaseData(testCaseId);
192 return std::make_unique<MobileNetSsdTestCase<Model>>(*m_Model, testCaseId, *testCaseData);
196 typename Model::CommandLineOptions m_ModelCommandLineOptions;
198 typename Model::CommandLineOptions)> m_ConstructModel;
199 std::unique_ptr<Model> m_Model;
201 std::string m_DataDir;
202 std::unique_ptr<MobileNetSsdDatabase> m_Database;
const std::vector< TContainer > & GetOutputs() const
#define ARMNN_LOG(severity)
virtual TestCaseResult ProcessResult(const InferenceTestOptions &options)=0
void IgnoreUnused(Ts &&...)
unsigned int GetTestCaseId() const
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
The test failed with a fatal error. The remaining tests will not be run.
bool ValidateDirectory(std::string &dir)
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
The test completed without any errors.