2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // See LICENSE file in the project root for full license information.
5 #include "InferenceTestImage.hpp"
6 #include "ImageNetDatabase.hpp"
8 #include <boost/numeric/conversion/cast.hpp>
9 #include <boost/log/trivial.hpp>
10 #include <boost/assert.hpp>
11 #include <boost/format.hpp>
17 const std::vector<ImageSet> g_DefaultImageSet =
22 ImageNetDatabase::ImageNetDatabase(const std::string& binaryFileDirectory, unsigned int width, unsigned int height,
23 const std::vector<ImageSet>& imageSet)
24 : m_BinaryDirectory(binaryFileDirectory)
27 , m_ImageSet(imageSet.empty() ? g_DefaultImageSet : imageSet)
31 std::unique_ptr<ImageNetDatabase::TTestCaseData> ImageNetDatabase::GetTestCaseData(unsigned int testCaseId)
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;
37 InferenceTestImage image(fullPath.c_str());
38 image.Resize(m_Width, m_Height);
40 // The model expects image data in BGR format
41 std::vector<float> inputImageData = GetImageDataInArmNnLayoutAsFloatsSubtractingMean(ImageChannelLayout::Bgr,
44 // list of labels: https://gist.github.com/yrevar/942d3a0ac09ec9e5eb3a
45 const unsigned int label = imageSet.second;
46 return std::make_unique<TTestCaseData>(label, std::move(inputImageData));