blob: 7dd6e6955c9804f5311549d2a38774062906337a [file] [log] [blame]
telsoa014fcda012018-03-09 14:13:49 +00001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa014fcda012018-03-09 14:13:49 +00004//
5#include "InferenceTestImage.hpp"
telsoa01c577f2c2018-08-31 09:22:23 +01006#include "CaffePreprocessor.hpp"
telsoa014fcda012018-03-09 14:13:49 +00007
8#include <boost/numeric/conversion/cast.hpp>
9#include <boost/log/trivial.hpp>
10#include <boost/assert.hpp>
11#include <boost/format.hpp>
12
13#include <iostream>
14#include <fcntl.h>
15#include <array>
16
17const std::vector<ImageSet> g_DefaultImageSet =
18{
19 {"shark.jpg", 2}
20};
21
telsoa01c577f2c2018-08-31 09:22:23 +010022CaffePreprocessor::CaffePreprocessor(const std::string& binaryFileDirectory, unsigned int width, unsigned int height,
telsoa014fcda012018-03-09 14:13:49 +000023 const std::vector<ImageSet>& imageSet)
24: m_BinaryDirectory(binaryFileDirectory)
25, m_Height(height)
26, m_Width(width)
27, m_ImageSet(imageSet.empty() ? g_DefaultImageSet : imageSet)
28{
29}
30
telsoa01c577f2c2018-08-31 09:22:23 +010031std::unique_ptr<CaffePreprocessor::TTestCaseData> CaffePreprocessor::GetTestCaseData(unsigned int testCaseId)
telsoa014fcda012018-03-09 14:13:49 +000032{
33 testCaseId = testCaseId % boost::numeric_cast<unsigned int>(m_ImageSet.size());
34 const ImageSet& imageSet = m_ImageSet[testCaseId];
35 const std::string fullPath = m_BinaryDirectory + imageSet.first;
telsoa014fcda012018-03-09 14:13:49 +000036
37 InferenceTestImage image(fullPath.c_str());
telsoa01c577f2c2018-08-31 09:22:23 +010038 image.Resize(m_Width, m_Height, CHECK_LOCATION());
telsoa014fcda012018-03-09 14:13:49 +000039
telsoa01c577f2c2018-08-31 09:22:23 +010040 // The model expects image data in BGR format.
telsoa014fcda012018-03-09 14:13:49 +000041 std::vector<float> inputImageData = GetImageDataInArmNnLayoutAsFloatsSubtractingMean(ImageChannelLayout::Bgr,
42 image, m_MeanBgr);
43
telsoa01c577f2c2018-08-31 09:22:23 +010044 // List of labels: https://gist.github.com/yrevar/942d3a0ac09ec9e5eb3a
telsoa014fcda012018-03-09 14:13:49 +000045 const unsigned int label = imageSet.second;
46 return std::make_unique<TTestCaseData>(label, std::move(inputImageData));
47}