aboutsummaryrefslogtreecommitdiff
path: root/tests/YoloDatabase.cpp
diff options
context:
space:
mode:
authortelsoa01 <telmo.soares@arm.com>2018-03-09 14:13:49 +0000
committertelsoa01 <telmo.soares@arm.com>2018-03-09 14:13:49 +0000
commit4fcda0101ec3d110c1d6d7bee5c83416b645528a (patch)
treec9a70aeb2887006160c1b3d265c27efadb7bdbae /tests/YoloDatabase.cpp
downloadarmnn-4fcda0101ec3d110c1d6d7bee5c83416b645528a.tar.gz
Release 18.02
Change-Id: Id3c11dc5ee94ef664374a988fcc6901e9a232fa6
Diffstat (limited to 'tests/YoloDatabase.cpp')
-rw-r--r--tests/YoloDatabase.cpp101
1 files changed, 101 insertions, 0 deletions
diff --git a/tests/YoloDatabase.cpp b/tests/YoloDatabase.cpp
new file mode 100644
index 0000000000..4c91384073
--- /dev/null
+++ b/tests/YoloDatabase.cpp
@@ -0,0 +1,101 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// See LICENSE file in the project root for full license information.
+//
+#include "YoloDatabase.hpp"
+
+#include <armnn/Exceptions.hpp>
+
+#include <array>
+#include <cstdint>
+#include <tuple>
+#include <utility>
+
+#include <boost/assert.hpp>
+#include <boost/format.hpp>
+#include <boost/log/trivial.hpp>
+#include <boost/numeric/conversion/cast.hpp>
+
+#include "InferenceTestImage.hpp"
+
+namespace
+{
+enum class YoloVocClass : unsigned int
+{
+ Aeroplane,
+ Bicycle,
+ Bird,
+ Boat,
+ Bottle,
+ Bus,
+ Car,
+ Cat,
+ Chair,
+ Cow,
+ DiningTable,
+ Dog,
+ Horse,
+ Motorbike,
+ Person,
+ PottedPlant,
+ Sheep,
+ Sofa,
+ Train,
+ TvMonitor
+};
+
+template <typename E>
+constexpr auto to_underlying(E e) noexcept
+{
+ return static_cast<std::underlying_type_t<E>>(e);
+}
+
+class ImageNotFoundException : public armnn::Exception
+{
+ using Exception::Exception;
+};
+
+using YoloInputOutput = std::pair<const char* const, YoloDetectedObject>;
+
+const std::array<YoloInputOutput,1> g_PerTestCaseInputOutput =
+{
+ YoloInputOutput{
+ "yolo_dog_448x448.png",
+ { to_underlying(YoloVocClass::Dog), YoloBoundingBox{ 233.0f, 256.0f, 299.0f, 462.0f }, 0.5088733434677124f }
+ },
+};
+
+} // namespace
+
+YoloDatabase::YoloDatabase(const std::string& imageDir)
+ : m_ImageDir(imageDir)
+{
+}
+
+std::unique_ptr<YoloDatabase::TTestCaseData> YoloDatabase::GetTestCaseData(unsigned int testCaseId)
+{
+ testCaseId = testCaseId % boost::numeric_cast<unsigned int>(g_PerTestCaseInputOutput.size());
+ const auto& testCaseInputOutput = g_PerTestCaseInputOutput[testCaseId];
+ const std::string imagePath = m_ImageDir + testCaseInputOutput.first;
+
+ // Load test case input image
+ std::vector<float> imageData;
+ try
+ {
+ InferenceTestImage image(imagePath.c_str());
+ image.Resize(YoloImageWidth, YoloImageHeight);
+ imageData = GetImageDataInArmNnLayoutAsNormalizedFloats(ImageChannelLayout::Rgb, image);
+ }
+ catch (const InferenceTestImageException& e)
+ {
+ BOOST_LOG_TRIVIAL(fatal) << "Failed to load test case " << testCaseId << " with error: " << e.what();
+ return nullptr;
+ }
+
+ // Prepare test case output
+ std::vector<YoloDetectedObject> topObjectDetections;
+ topObjectDetections.reserve(1);
+ topObjectDetections.push_back(testCaseInputOutput.second);
+
+ return std::make_unique<YoloTestCaseData>(std::move(imageData), std::move(topObjectDetections));
+} \ No newline at end of file