From 4fcda0101ec3d110c1d6d7bee5c83416b645528a Mon Sep 17 00:00:00 2001 From: telsoa01 Date: Fri, 9 Mar 2018 14:13:49 +0000 Subject: Release 18.02 Change-Id: Id3c11dc5ee94ef664374a988fcc6901e9a232fa6 --- tests/ImageNetDatabase.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 tests/ImageNetDatabase.cpp (limited to 'tests/ImageNetDatabase.cpp') diff --git a/tests/ImageNetDatabase.cpp b/tests/ImageNetDatabase.cpp new file mode 100644 index 0000000000..0a235c9a3e --- /dev/null +++ b/tests/ImageNetDatabase.cpp @@ -0,0 +1,54 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// See LICENSE file in the project root for full license information. +// +#include "InferenceTestImage.hpp" +#include "ImageNetDatabase.hpp" + +#include +#include +#include +#include + +#include +#include +#include + +const std::vector g_DefaultImageSet = +{ + {"shark.jpg", 2} +}; + +ImageNetDatabase::ImageNetDatabase(const std::string& binaryFileDirectory, unsigned int width, unsigned int height, + const std::vector& imageSet) +: m_BinaryDirectory(binaryFileDirectory) +, m_Height(height) +, m_Width(width) +, m_ImageSet(imageSet.empty() ? g_DefaultImageSet : imageSet) +{ +} + +std::unique_ptr ImageNetDatabase::GetTestCaseData(unsigned int testCaseId) +{ + testCaseId = testCaseId % boost::numeric_cast(m_ImageSet.size()); + const ImageSet& imageSet = m_ImageSet[testCaseId]; + const std::string fullPath = m_BinaryDirectory + imageSet.first; + FILE* file = fopen(fullPath.c_str(), "rb"); + + if (file == nullptr) + { + BOOST_LOG_TRIVIAL(fatal) << "Failed to load " << fullPath; + return nullptr; + } + + InferenceTestImage image(fullPath.c_str()); + image.Resize(m_Width, m_Height); + + // The model expects image data in BGR format + std::vector inputImageData = GetImageDataInArmNnLayoutAsFloatsSubtractingMean(ImageChannelLayout::Bgr, + image, m_MeanBgr); + + // list of labels: https://gist.github.com/yrevar/942d3a0ac09ec9e5eb3a + const unsigned int label = imageSet.second; + return std::make_unique(label, std::move(inputImageData)); +} -- cgit v1.2.1