From c8bab1bf601b00242b44cdbc7d9510a753054803 Mon Sep 17 00:00:00 2001 From: Narumol Prangnawarat Date: Fri, 15 Feb 2019 17:34:51 +0000 Subject: IVGCVSW-2436 Modify MobileNet SSD inference test * change MobileNet SSD input to uint8 * get quantization scale and offset from the model * change data layout to NHWC as TensorFlow lite layout * update expected output as result from TfLite with quantized data Change-Id: I07104d56286893935779169356234de53f1c9492 Signed-off-by: Narumol Prangnawarat --- tests/MobileNetSsdDatabase.hpp | 20 +++++++++++++------- tests/MobileNetSsdInferenceTest.hpp | 6 +++--- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/tests/MobileNetSsdDatabase.hpp b/tests/MobileNetSsdDatabase.hpp index e3a28d13bd..cac558793f 100644 --- a/tests/MobileNetSsdDatabase.hpp +++ b/tests/MobileNetSsdDatabase.hpp @@ -11,6 +11,7 @@ #include #include +#include #include #include @@ -26,25 +27,27 @@ namespace struct MobileNetSsdTestCaseData { MobileNetSsdTestCaseData( - std::vector inputData, + std::vector inputData, std::vector expectedOutput) : m_InputData(std::move(inputData)) , m_ExpectedOutput(std::move(expectedOutput)) {} - std::vector m_InputData; + std::vector m_InputData; std::vector m_ExpectedOutput; }; class MobileNetSsdDatabase { public: - explicit MobileNetSsdDatabase(const std::string& imageDir); + explicit MobileNetSsdDatabase(const std::string& imageDir, float scale, int offset); std::unique_ptr GetTestCaseData(unsigned int testCaseId); private: std::string m_ImageDir; + float m_Scale; + int m_Offset; }; constexpr unsigned int k_MobileNetSsdImageWidth = 300u; @@ -56,12 +59,14 @@ const std::array g_PerTestCaseInput = ObjectDetectionInput { "Cat.jpg", - DetectedObject(16, BoundingBox(0.21678525f, 0.0859828f, 0.9271242f, 0.9453231f), 0.79296875f) + DetectedObject(16, BoundingBox(0.208961248f, 0.0852333307f, 0.92757535f, 0.940263629f), 0.79296875f) } }; -MobileNetSsdDatabase::MobileNetSsdDatabase(const std::string& imageDir) +MobileNetSsdDatabase::MobileNetSsdDatabase(const std::string& imageDir, float scale, int offset) : m_ImageDir(imageDir) + , m_Scale(scale) + , m_Offset(offset) {} std::unique_ptr MobileNetSsdDatabase::GetTestCaseData(unsigned int testCaseId) @@ -72,7 +77,7 @@ std::unique_ptr MobileNetSsdDatabase::GetTestCaseData( // Load test case input const std::string imagePath = m_ImageDir + testCaseInput.first; - std::vector imageData; + std::vector imageData; try { InferenceTestImage image(imagePath.c_str()); @@ -86,7 +91,8 @@ std::unique_ptr MobileNetSsdDatabase::GetTestCaseData( } // Get image data as a vector of floats - imageData = GetImageDataInArmNnLayoutAsNormalizedFloats(ImageChannelLayout::Rgb, image); + std::vector floatImageData = GetImageDataAsNormalizedFloats(ImageChannelLayout::Rgb, image); + imageData = QuantizedVector(m_Scale, m_Offset, floatImageData); } catch (const InferenceTestImageException& e) { diff --git a/tests/MobileNetSsdInferenceTest.hpp b/tests/MobileNetSsdInferenceTest.hpp index 0091009083..10ee1dcae6 100644 --- a/tests/MobileNetSsdInferenceTest.hpp +++ b/tests/MobileNetSsdInferenceTest.hpp @@ -126,7 +126,7 @@ public: } private: - static constexpr unsigned int k_NumDetections = 10u; + static constexpr unsigned int k_NumDetections = 1u; static constexpr unsigned int k_OutputSize1 = k_NumDetections * 4u; static constexpr unsigned int k_OutputSize2 = k_NumDetections; @@ -169,8 +169,8 @@ public: { return false; } - - m_Database = std::make_unique(m_DataDir.c_str()); + std::pair qParams = m_Model->GetQuantizationParams(); + m_Database = std::make_unique(m_DataDir.c_str(), qParams.first, qParams.second); if (!m_Database) { return false; -- cgit v1.2.1