blob: 54ce833b72a1e19681285d952afb9ed46ea90447 [file] [log] [blame]
Laurent Carlier749294b2020-06-01 09:03:17 +01001//
telsoa014fcda012018-03-09 14:13:49 +00002// 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
Matthew Sloyan80c6b142020-09-08 12:00:32 +01008#include <armnn/utility/NumericCast.hpp>
9
telsoa014fcda012018-03-09 14:13:49 +000010#include <iostream>
11#include <fcntl.h>
12#include <array>
13
14const std::vector<ImageSet> g_DefaultImageSet =
15{
16 {"shark.jpg", 2}
17};
18
telsoa01c577f2c2018-08-31 09:22:23 +010019CaffePreprocessor::CaffePreprocessor(const std::string& binaryFileDirectory, unsigned int width, unsigned int height,
telsoa014fcda012018-03-09 14:13:49 +000020 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
telsoa01c577f2c2018-08-31 09:22:23 +010028std::unique_ptr<CaffePreprocessor::TTestCaseData> CaffePreprocessor::GetTestCaseData(unsigned int testCaseId)
telsoa014fcda012018-03-09 14:13:49 +000029{
Matthew Sloyan80c6b142020-09-08 12:00:32 +010030 testCaseId = testCaseId % armnn::numeric_cast<unsigned int>(m_ImageSet.size());
telsoa014fcda012018-03-09 14:13:49 +000031 const ImageSet& imageSet = m_ImageSet[testCaseId];
32 const std::string fullPath = m_BinaryDirectory + imageSet.first;
telsoa014fcda012018-03-09 14:13:49 +000033
34 InferenceTestImage image(fullPath.c_str());
telsoa01c577f2c2018-08-31 09:22:23 +010035 image.Resize(m_Width, m_Height, CHECK_LOCATION());
telsoa014fcda012018-03-09 14:13:49 +000036
telsoa01c577f2c2018-08-31 09:22:23 +010037 // The model expects image data in BGR format.
telsoa014fcda012018-03-09 14:13:49 +000038 std::vector<float> inputImageData = GetImageDataInArmNnLayoutAsFloatsSubtractingMean(ImageChannelLayout::Bgr,
39 image, m_MeanBgr);
40
telsoa01c577f2c2018-08-31 09:22:23 +010041 // List of labels: https://gist.github.com/yrevar/942d3a0ac09ec9e5eb3a
telsoa014fcda012018-03-09 14:13:49 +000042 const unsigned int label = imageSet.second;
43 return std::make_unique<TTestCaseData>(label, std::move(inputImageData));
44}