Laurent Carlier | 749294b | 2020-06-01 09:03:17 +0100 | [diff] [blame] | 1 | // |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
David Beck | ecb56cd | 2018-09-05 12:52:57 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 4 | // |
| 5 | #pragma once |
| 6 | |
| 7 | #include "ClassifierTestCaseData.hpp" |
| 8 | |
| 9 | #include <array> |
| 10 | #include <string> |
| 11 | #include <vector> |
| 12 | #include <memory> |
| 13 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 14 | /// Caffe requires BGR images, not normalized, mean adjusted and resized using smooth resize of STB library |
| 15 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 16 | using ImageSet = std::pair<const std::string, unsigned int>; |
| 17 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 18 | class CaffePreprocessor |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 19 | { |
| 20 | public: |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 21 | using DataType = float; |
| 22 | using TTestCaseData = ClassifierTestCaseData<DataType>; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 23 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 24 | explicit CaffePreprocessor(const std::string& binaryFileDirectory, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 25 | unsigned int width = 227, |
| 26 | unsigned int height = 227, |
| 27 | const std::vector<ImageSet>& imageSet = std::vector<ImageSet>()); |
| 28 | std::unique_ptr<TTestCaseData> GetTestCaseData(unsigned int testCaseId); |
| 29 | |
| 30 | private: |
| 31 | unsigned int GetNumImageElements() const { return 3 * m_Width * m_Height; } |
| 32 | unsigned int GetNumImageBytes() const { return 4 * GetNumImageElements(); } |
| 33 | |
| 34 | std::string m_BinaryDirectory; |
| 35 | unsigned int m_Height; |
| 36 | unsigned int m_Width; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 37 | // Mean value of the database [B, G, R]. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 38 | const std::array<float, 3> m_MeanBgr = {{104.007965f, 116.669472f, 122.675102f}}; |
| 39 | const std::vector<ImageSet> m_ImageSet; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 40 | }; |