blob: 7e7028966c8c5bb659f709dd8692758e13b1986d [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>
telsoa014fcda012018-03-09 14:13:49 +00009#include <boost/format.hpp>
10
11#include <iostream>
12#include <fcntl.h>
13#include <array>
14
15const std::vector<ImageSet> g_DefaultImageSet =
16{
17 {"shark.jpg", 2}
18};
19
telsoa01c577f2c2018-08-31 09:22:23 +010020CaffePreprocessor::CaffePreprocessor(const std::string& binaryFileDirectory, unsigned int width, unsigned int height,
telsoa014fcda012018-03-09 14:13:49 +000021 const std::vector<ImageSet>& imageSet)
22: m_BinaryDirectory(binaryFileDirectory)
23, m_Height(height)
24, m_Width(width)
25, m_ImageSet(imageSet.empty() ? g_DefaultImageSet : imageSet)
26{
27}
28
telsoa01c577f2c2018-08-31 09:22:23 +010029std::unique_ptr<CaffePreprocessor::TTestCaseData> CaffePreprocessor::GetTestCaseData(unsigned int testCaseId)
telsoa014fcda012018-03-09 14:13:49 +000030{
31 testCaseId = testCaseId % boost::numeric_cast<unsigned int>(m_ImageSet.size());
32 const ImageSet& imageSet = m_ImageSet[testCaseId];
33 const std::string fullPath = m_BinaryDirectory + imageSet.first;
telsoa014fcda012018-03-09 14:13:49 +000034
35 InferenceTestImage image(fullPath.c_str());
telsoa01c577f2c2018-08-31 09:22:23 +010036 image.Resize(m_Width, m_Height, CHECK_LOCATION());
telsoa014fcda012018-03-09 14:13:49 +000037
telsoa01c577f2c2018-08-31 09:22:23 +010038 // The model expects image data in BGR format.
telsoa014fcda012018-03-09 14:13:49 +000039 std::vector<float> inputImageData = GetImageDataInArmNnLayoutAsFloatsSubtractingMean(ImageChannelLayout::Bgr,
40 image, m_MeanBgr);
41
telsoa01c577f2c2018-08-31 09:22:23 +010042 // List of labels: https://gist.github.com/yrevar/942d3a0ac09ec9e5eb3a
telsoa014fcda012018-03-09 14:13:49 +000043 const unsigned int label = imageSet.second;
44 return std::make_unique<TTestCaseData>(label, std::move(inputImageData));
45}