2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
7 #include "ClassifierTestCaseData.hpp"
14 ///Tf requires RGB images, normalized in range [0, 1] and resized using Bilinear algorithm
17 using ImageSet = std::pair<const std::string, unsigned int>;
19 template <typename TDataType>
20 class ImagePreprocessor
23 using DataType = TDataType;
24 using TTestCaseData = ClassifierTestCaseData<DataType>;
32 explicit ImagePreprocessor(const std::string& binaryFileDirectory,
35 const std::vector<ImageSet>& imageSet,
37 const std::array<float, 3> mean={{0, 0, 0}},
38 const std::array<float, 3> stddev={{1, 1, 1}},
39 DataFormat dataFormat=DataFormat::NHWC,
40 unsigned int batchSize=1)
41 : m_BinaryDirectory(binaryFileDirectory)
44 , m_BatchSize(batchSize)
46 , m_ImageSet(imageSet)
49 , m_DataFormat(dataFormat)
53 std::unique_ptr<TTestCaseData> GetTestCaseData(unsigned int testCaseId);
56 unsigned int GetNumImageElements() const { return 3 * m_Width * m_Height; }
57 unsigned int GetNumImageBytes() const { return sizeof(DataType) * GetNumImageElements(); }
58 unsigned int GetLabelAndResizedImageAsFloat(unsigned int testCaseId,
59 std::vector<float> & result);
61 std::string m_BinaryDirectory;
62 unsigned int m_Height;
64 unsigned int m_BatchSize;
65 // Quantization parameters
67 const std::vector<ImageSet> m_ImageSet;
69 const std::array<float, 3> m_Mean;
70 const std::array<float, 3> m_Stddev;
72 DataFormat m_DataFormat;