MLCE-347 'REDUCE_MIN, REDUCE_MAX, REDUCE_SUM Support'
[platform/upstream/armnn.git] / tests / MobileNetSsdDatabase.hpp
index cac5587..9cd987d 100644 (file)
@@ -2,24 +2,21 @@
 // Copyright © 2017 Arm Ltd. All rights reserved.
 // SPDX-License-Identifier: MIT
 //
+
 #pragma once
 
+#include "InferenceTestImage.hpp"
 #include "ObjectDetectionCommon.hpp"
 
-#include <memory>
-#include <string>
-#include <vector>
+#include <QuantizeHelper.hpp>
 
 #include <armnn/TypesUtils.hpp>
-#include <backendsCommon/test/QuantizeHelper.hpp>
-
-#include <boost/log/trivial.hpp>
-#include <boost/numeric/conversion/cast.hpp>
+#include <armnn/utility/NumericCast.hpp>
 
 #include <array>
+#include <memory>
 #include <string>
-
-#include "InferenceTestImage.hpp"
+#include <vector>
 
 namespace
 {
@@ -27,14 +24,17 @@ namespace
 struct MobileNetSsdTestCaseData
 {
     MobileNetSsdTestCaseData(
-        std::vector<uint8_t> inputData,
-        std::vector<DetectedObject> expectedOutput)
-        : m_InputData(std::move(inputData))
-        , m_ExpectedOutput(std::move(expectedOutput))
+        const std::vector<uint8_t>& inputData,
+        const std::vector<DetectedObject>& expectedDetectedObject,
+        const std::vector<std::vector<float>>& expectedOutput)
+        : m_InputData(inputData)
+        , m_ExpectedDetectedObject(expectedDetectedObject)
+        , m_ExpectedOutput(expectedOutput)
     {}
 
-    std::vector<uint8_t>        m_InputData;
-    std::vector<DetectedObject> m_ExpectedOutput;
+    std::vector<uint8_t>            m_InputData;
+    std::vector<DetectedObject>     m_ExpectedDetectedObject;
+    std::vector<std::vector<float>> m_ExpectedOutput;
 };
 
 class MobileNetSsdDatabase
@@ -59,7 +59,9 @@ const std::array<ObjectDetectionInput, 1> g_PerTestCaseInput =
     ObjectDetectionInput
     {
         "Cat.jpg",
-        DetectedObject(16, BoundingBox(0.208961248f, 0.0852333307f, 0.92757535f, 0.940263629f), 0.79296875f)
+        {
+          DetectedObject(16.0f, BoundingBox(0.216785252f, 0.079726994f, 0.927124202f, 0.939067304f), 0.79296875f)
+        }
     }
 };
 
@@ -72,7 +74,7 @@ MobileNetSsdDatabase::MobileNetSsdDatabase(const std::string& imageDir, float sc
 std::unique_ptr<MobileNetSsdTestCaseData> MobileNetSsdDatabase::GetTestCaseData(unsigned int testCaseId)
 {
     const unsigned int safeTestCaseId =
-        testCaseId % boost::numeric_cast<unsigned int>(g_PerTestCaseInput.size());
+        testCaseId % armnn::numeric_cast<unsigned int>(g_PerTestCaseInput.size());
     const ObjectDetectionInput& testCaseInput = g_PerTestCaseInput[safeTestCaseId];
 
     // Load test case input
@@ -92,20 +94,41 @@ std::unique_ptr<MobileNetSsdTestCaseData> MobileNetSsdDatabase::GetTestCaseData(
 
         // Get image data as a vector of floats
         std::vector<float> floatImageData = GetImageDataAsNormalizedFloats(ImageChannelLayout::Rgb, image);
-        imageData = QuantizedVector<uint8_t>(m_Scale, m_Offset, floatImageData);
+        imageData = armnnUtils::QuantizedVector<uint8_t>(floatImageData, m_Scale, m_Offset);
     }
     catch (const InferenceTestImageException& e)
     {
-        BOOST_LOG_TRIVIAL(fatal) << "Failed to load image for test case " << testCaseId << ". Error: " << e.what();
+        ARMNN_LOG(fatal) << "Failed to load image for test case " << testCaseId << ". Error: " << e.what();
         return nullptr;
     }
 
-    // Prepare test case expected output
-    std::vector<DetectedObject> expectedOutput;
-    expectedOutput.reserve(1);
-    expectedOutput.push_back(testCaseInput.second);
+    std::vector<float> numDetections = { static_cast<float>(testCaseInput.second.size()) };
+
+    std::vector<float> detectionBoxes;
+    std::vector<float> detectionClasses;
+    std::vector<float> detectionScores;
+
+    for (DetectedObject expectedObject : testCaseInput.second)
+    {
+            detectionBoxes.push_back(expectedObject.m_BoundingBox.m_YMin);
+            detectionBoxes.push_back(expectedObject.m_BoundingBox.m_XMin);
+            detectionBoxes.push_back(expectedObject.m_BoundingBox.m_YMax);
+            detectionBoxes.push_back(expectedObject.m_BoundingBox.m_XMax);
+
+            detectionClasses.push_back(expectedObject.m_Class);
 
-    return std::make_unique<MobileNetSsdTestCaseData>(std::move(imageData), std::move(expectedOutput));
+            detectionScores.push_back(expectedObject.m_Confidence);
+    }
+
+    // Prepare test case expected output
+    std::vector<std::vector<float>> expectedOutputs;
+    expectedOutputs.reserve(4);
+    expectedOutputs.push_back(detectionBoxes);
+    expectedOutputs.push_back(detectionClasses);
+    expectedOutputs.push_back(detectionScores);
+    expectedOutputs.push_back(numDetections);
+
+    return std::make_unique<MobileNetSsdTestCaseData>(imageData, testCaseInput.second, expectedOutputs);
 }
 
 } // anonymous namespace