20 template<
typename Model>
24 MobileNetSsdTestCase(Model& model,
25 unsigned int testCaseId,
26 const MobileNetSsdTestCaseData& testCaseData)
29 { std::move(testCaseData.m_InputData) },
30 { k_OutputSize1, k_OutputSize2, k_OutputSize3, k_OutputSize4 })
31 , m_DetectedObjects(testCaseData.m_ExpectedDetectedObject)
39 const std::vector<float>& output1 = mapbox::util::get<std::vector<float>>(this->
GetOutputs()[0]);
43 const std::vector<float>& output2 = mapbox::util::get<std::vector<float>>(this->
GetOutputs()[1]);
47 const std::vector<float>& output3 = mapbox::util::get<std::vector<float>>(this->
GetOutputs()[2]);
51 const std::vector<float>& output4 = mapbox::util::get<std::vector<float>>(this->
GetOutputs()[3]);
57 const size_t expectedNumDetections = m_DetectedObjects.size();
58 if (numDetections != expectedNumDetections)
60 ARMNN_LOG(error) <<
"Number of detections is incorrect: Expected (" <<
61 expectedNumDetections <<
")" <<
" but got (" << numDetections <<
")";
66 std::vector<DetectedObject> detectedObjects;
67 const float* outputData = output1.data();
68 for (
unsigned int i = 0u; i < numDetections; i++)
71 float yMin = *outputData++;
72 float xMin = *outputData++;
73 float yMax = *outputData++;
74 float xMax = *outputData++;
76 DetectedObject detectedObject(
78 BoundingBox(xMin, yMin, xMax, yMax),
81 detectedObjects.push_back(detectedObject);
84 std::sort(detectedObjects.begin(), detectedObjects.end());
85 std::sort(m_DetectedObjects.begin(), m_DetectedObjects.end());
88 std::vector<DetectedObject>::const_iterator it = detectedObjects.begin();
89 for (
unsigned int i = 0; i < numDetections; i++)
91 if (it == detectedObjects.end())
93 ARMNN_LOG(error) <<
"No more detected objects found! Index out of bounds: " << i;
97 const DetectedObject& detectedObject = *it;
98 const DetectedObject& expectedObject = m_DetectedObjects[i];
100 if (detectedObject.m_Class != expectedObject.m_Class)
103 " is incorrect: Expected (" << expectedObject.m_Class <<
")" <<
104 " but predicted (" << detectedObject.m_Class <<
")";
111 " is incorrect: Expected (" << expectedObject.m_Confidence <<
") +- 1.0 pc" <<
112 " but predicted (" << detectedObject.m_Confidence <<
")";
117 expectedObject.m_BoundingBox.m_XMin) ||
119 expectedObject.m_BoundingBox.m_YMin) ||
121 expectedObject.m_BoundingBox.m_XMax) ||
123 expectedObject.m_BoundingBox.m_YMax))
137 static constexpr
unsigned int k_Shape = 10u;
139 static constexpr
unsigned int k_OutputSize1 = k_Shape * 4u;
140 static constexpr
unsigned int k_OutputSize2 = k_Shape;
141 static constexpr
unsigned int k_OutputSize3 = k_Shape;
142 static constexpr
unsigned int k_OutputSize4 = 1u;
144 std::vector<DetectedObject> m_DetectedObjects;
147 template <
typename Model>
151 template <
typename TConstructModelCallable>
152 explicit MobileNetSsdTestCaseProvider(TConstructModelCallable constructModel)
153 : m_ConstructModel(constructModel)
156 virtual void AddCommandLineOptions(cxxopts::Options& options, std::vector<std::string>& required)
override 159 .allow_unrecognised_options()
161 (
"d,data-dir",
"Path to directory containing test data", cxxopts::value<std::string>(m_DataDir));
163 required.emplace_back(
"data-dir");
165 Model::AddCommandLineOptions(options, m_ModelCommandLineOptions, required);
175 m_Model = m_ConstructModel(commonOptions, m_ModelCommandLineOptions);
180 std::pair<float, int32_t> qParams = m_Model->GetInputQuantizationParams();
181 m_Database = std::make_unique<MobileNetSsdDatabase>(m_DataDir.c_str(), qParams.first, qParams.second);
190 std::unique_ptr<IInferenceTestCase> GetTestCase(
unsigned int testCaseId)
override 192 std::unique_ptr<MobileNetSsdTestCaseData> testCaseData = m_Database->GetTestCaseData(testCaseId);
198 return std::make_unique<MobileNetSsdTestCase<Model>>(*m_Model, testCaseId, *testCaseData);
202 typename Model::CommandLineOptions m_ModelCommandLineOptions;
204 typename Model::CommandLineOptions)> m_ConstructModel;
205 std::unique_ptr<Model> m_Model;
207 std::string m_DataDir;
208 std::unique_ptr<MobileNetSsdDatabase> m_Database;
#define ARMNN_LOG(severity)
virtual TestCaseResult ProcessResult(const InferenceTestOptions &options)=0
void IgnoreUnused(Ts &&...)
const std::vector< armnnUtils::TContainer > & GetOutputs() const
unsigned int GetTestCaseId() const
#define ARMNN_ASSERT(COND)
The test failed with a fatal error. The remaining tests will not be run.
bool ValidateDirectory(std::string &dir)
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
bool within_percentage_tolerance(float a, float b, float tolerancePercent=1.0f)
Compare two floats and return true if their values are within a specified tolerance of each other...
The test completed without any errors.