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 | #include "InferenceTestImage.hpp" |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 6 | #include "CaffePreprocessor.hpp" |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 7 | |
Matthew Sloyan | 80c6b14 | 2020-09-08 12:00:32 +0100 | [diff] [blame] | 8 | #include <armnn/utility/NumericCast.hpp> |
| 9 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 10 | #include <iostream> |
| 11 | #include <fcntl.h> |
| 12 | #include <array> |
| 13 | |
| 14 | const std::vector<ImageSet> g_DefaultImageSet = |
| 15 | { |
| 16 | {"shark.jpg", 2} |
| 17 | }; |
| 18 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 19 | CaffePreprocessor::CaffePreprocessor(const std::string& binaryFileDirectory, unsigned int width, unsigned int height, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 20 | const std::vector<ImageSet>& imageSet) |
| 21 | : m_BinaryDirectory(binaryFileDirectory) |
| 22 | , m_Height(height) |
| 23 | , m_Width(width) |
| 24 | , m_ImageSet(imageSet.empty() ? g_DefaultImageSet : imageSet) |
| 25 | { |
| 26 | } |
| 27 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 28 | std::unique_ptr<CaffePreprocessor::TTestCaseData> CaffePreprocessor::GetTestCaseData(unsigned int testCaseId) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 29 | { |
Matthew Sloyan | 80c6b14 | 2020-09-08 12:00:32 +0100 | [diff] [blame] | 30 | testCaseId = testCaseId % armnn::numeric_cast<unsigned int>(m_ImageSet.size()); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 31 | const ImageSet& imageSet = m_ImageSet[testCaseId]; |
| 32 | const std::string fullPath = m_BinaryDirectory + imageSet.first; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 33 | |
| 34 | InferenceTestImage image(fullPath.c_str()); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 35 | image.Resize(m_Width, m_Height, CHECK_LOCATION()); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 36 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 37 | // The model expects image data in BGR format. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 38 | std::vector<float> inputImageData = GetImageDataInArmNnLayoutAsFloatsSubtractingMean(ImageChannelLayout::Bgr, |
| 39 | image, m_MeanBgr); |
| 40 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 41 | // List of labels: https://gist.github.com/yrevar/942d3a0ac09ec9e5eb3a |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 42 | const unsigned int label = imageSet.second; |
| 43 | return std::make_unique<TTestCaseData>(label, std::move(inputImageData)); |
| 44 | } |