aboutsummaryrefslogtreecommitdiff
path: root/tests/ImagePreprocessor.hpp
diff options
context:
space:
mode:
authortelsoa01 <telmo.soares@arm.com>2018-08-31 09:22:23 +0100
committertelsoa01 <telmo.soares@arm.com>2018-08-31 09:22:23 +0100
commitc577f2c6a3b4ddb6ba87a882723c53a248afbeba (patch)
treebd7d4c148df27f8be6649d313efb24f536b7cf34 /tests/ImagePreprocessor.hpp
parent4c7098bfeab1ffe1cdc77f6c15548d3e73274746 (diff)
downloadarmnn-c577f2c6a3b4ddb6ba87a882723c53a248afbeba.tar.gz
Release 18.08
Diffstat (limited to 'tests/ImagePreprocessor.hpp')
-rw-r--r--tests/ImagePreprocessor.hpp73
1 files changed, 73 insertions, 0 deletions
diff --git a/tests/ImagePreprocessor.hpp b/tests/ImagePreprocessor.hpp
new file mode 100644
index 0000000000..b8a473d92c
--- /dev/null
+++ b/tests/ImagePreprocessor.hpp
@@ -0,0 +1,73 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// See LICENSE file in the project root for full license information.
+//
+#pragma once
+
+#include "ClassifierTestCaseData.hpp"
+
+#include <array>
+#include <string>
+#include <vector>
+#include <memory>
+
+///Tf requires RGB images, normalized in range [0, 1] and resized using Bilinear algorithm
+
+
+using ImageSet = std::pair<const std::string, unsigned int>;
+
+template <typename TDataType>
+class ImagePreprocessor
+{
+public:
+ using DataType = TDataType;
+ using TTestCaseData = ClassifierTestCaseData<DataType>;
+
+ enum DataFormat
+ {
+ NHWC,
+ NCHW
+ };
+
+ explicit ImagePreprocessor(const std::string& binaryFileDirectory,
+ unsigned int width,
+ unsigned int height,
+ const std::vector<ImageSet>& imageSet,
+ float scale=1.0,
+ int32_t offset=0,
+ const std::array<float, 3> mean={{0, 0, 0}},
+ const std::array<float, 3> stddev={{1, 1, 1}},
+ DataFormat dataFormat=DataFormat::NHWC)
+ : m_BinaryDirectory(binaryFileDirectory)
+ , m_Height(height)
+ , m_Width(width)
+ , m_Scale(scale)
+ , m_Offset(offset)
+ , m_ImageSet(imageSet)
+ , m_Mean(mean)
+ , m_Stddev(stddev)
+ , m_DataFormat(dataFormat)
+ {
+ }
+
+ std::unique_ptr<TTestCaseData> GetTestCaseData(unsigned int testCaseId);
+
+private:
+ unsigned int GetNumImageElements() const { return 3 * m_Width * m_Height; }
+ unsigned int GetNumImageBytes() const { return sizeof(DataType) * GetNumImageElements(); }
+ unsigned int GetLabelAndResizedImageAsFloat(unsigned int testCaseId,
+ std::vector<float> & result);
+
+ std::string m_BinaryDirectory;
+ unsigned int m_Height;
+ unsigned int m_Width;
+ // Quantization parameters
+ float m_Scale;
+ int32_t m_Offset;
+ const std::vector<ImageSet> m_ImageSet;
+
+ const std::array<float, 3> m_Mean;
+ const std::array<float, 3> m_Stddev;
+
+ DataFormat m_DataFormat;
+};