// // Copyright © 2017 Arm Ltd. All rights reserved. // SPDX-License-Identifier: MIT // #include "InferenceTestImage.hpp" #include "ImagePreprocessor.hpp" #include #include #include #include #include #include template unsigned int ImagePreprocessor::GetLabelAndResizedImageAsFloat(unsigned int testCaseId, std::vector & result) { testCaseId = testCaseId % armnn::numeric_cast(m_ImageSet.size()); const ImageSet& imageSet = m_ImageSet[testCaseId]; const std::string fullPath = m_BinaryDirectory + imageSet.first; InferenceTestImage image(fullPath.c_str()); // this ResizeBilinear result is closer to the tensorflow one than STB. // there is still some difference though, but the inference results are // similar to tensorflow for MobileNet result = image.Resize(m_Width, m_Height, CHECK_LOCATION(), InferenceTestImage::ResizingMethods::BilinearAndNormalized, m_Mean, m_Stddev, m_Scale); // duplicate data across the batch for (unsigned int i = 1; i < m_BatchSize; i++) { result.insert(result.end(), result.begin(), result.begin() + armnn::numeric_cast(GetNumImageElements())); } if (m_DataFormat == DataFormat::NCHW) { const armnn::PermutationVector NHWCToArmNN = { 0, 2, 3, 1 }; armnn::TensorShape dstShape({m_BatchSize, 3, m_Height, m_Width}); std::vector tempImage(result.size()); armnnUtils::Permute(dstShape, NHWCToArmNN, result.data(), tempImage.data(), sizeof(float)); result.swap(tempImage); } return imageSet.second; } template <> std::unique_ptr::TTestCaseData> ImagePreprocessor::GetTestCaseData(unsigned int testCaseId) { std::vector resized; auto label = GetLabelAndResizedImageAsFloat(testCaseId, resized); return std::make_unique(label, std::move(resized)); } template <> std::unique_ptr::TTestCaseData> ImagePreprocessor::GetTestCaseData(unsigned int testCaseId) { std::vector resized; auto label = GetLabelAndResizedImageAsFloat(testCaseId, resized); size_t resizedSize = resized.size(); std::vector quantized(resized.size()); for (size_t i=0; i(resized[i]); } return std::make_unique(label, std::move(quantized)); }