2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // See LICENSE file in the project root for full license information.
5 #include "YoloDatabase.hpp"
7 #include <armnn/Exceptions.hpp>
14 #include <boost/assert.hpp>
15 #include <boost/format.hpp>
16 #include <boost/log/trivial.hpp>
17 #include <boost/numeric/conversion/cast.hpp>
19 #include "InferenceTestImage.hpp"
23 enum class YoloVocClass : unsigned int
48 constexpr auto to_underlying(E e) noexcept
50 return static_cast<std::underlying_type_t<E>>(e);
53 class ImageNotFoundException : public armnn::Exception
55 using Exception::Exception;
58 using YoloInputOutput = std::pair<const char* const, YoloDetectedObject>;
60 const std::array<YoloInputOutput,1> g_PerTestCaseInputOutput =
63 "yolo_dog_448x448.png",
64 { to_underlying(YoloVocClass::Dog), YoloBoundingBox{ 233.0f, 256.0f, 299.0f, 462.0f }, 0.5088733434677124f }
70 YoloDatabase::YoloDatabase(const std::string& imageDir)
71 : m_ImageDir(imageDir)
75 std::unique_ptr<YoloDatabase::TTestCaseData> YoloDatabase::GetTestCaseData(unsigned int testCaseId)
77 testCaseId = testCaseId % boost::numeric_cast<unsigned int>(g_PerTestCaseInputOutput.size());
78 const auto& testCaseInputOutput = g_PerTestCaseInputOutput[testCaseId];
79 const std::string imagePath = m_ImageDir + testCaseInputOutput.first;
81 // Load test case input image
82 std::vector<float> imageData;
85 InferenceTestImage image(imagePath.c_str());
86 image.Resize(YoloImageWidth, YoloImageHeight);
87 imageData = GetImageDataInArmNnLayoutAsNormalizedFloats(ImageChannelLayout::Rgb, image);
89 catch (const InferenceTestImageException& e)
91 BOOST_LOG_TRIVIAL(fatal) << "Failed to load test case " << testCaseId << " with error: " << e.what();
95 // Prepare test case output
96 std::vector<YoloDetectedObject> topObjectDetections;
97 topObjectDetections.reserve(1);
98 topObjectDetections.push_back(testCaseInputOutput.second);
100 return std::make_unique<YoloTestCaseData>(std::move(imageData), std::move(topObjectDetections));