aboutsummaryrefslogtreecommitdiff
path: root/tests/InferenceTestImage.hpp
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/InferenceTestImage.hpp
downloadarmnn-4fcda0101ec3d110c1d6d7bee5c83416b645528a.tar.gz
Release 18.02
Change-Id: Id3c11dc5ee94ef664374a988fcc6901e9a232fa6
Diffstat (limited to 'tests/InferenceTestImage.hpp')
-rw-r--r--tests/InferenceTestImage.hpp121
1 files changed, 121 insertions, 0 deletions
diff --git a/tests/InferenceTestImage.hpp b/tests/InferenceTestImage.hpp
new file mode 100644
index 0000000000..45dd8bf4e2
--- /dev/null
+++ b/tests/InferenceTestImage.hpp
@@ -0,0 +1,121 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// See LICENSE file in the project root for full license information.
+//
+#pragma once
+
+#include <armnn/Exceptions.hpp>
+
+#include <array>
+#include <cstdint>
+#include <vector>
+#include <utility>
+
+class InferenceTestImageException : public armnn::Exception
+{
+public:
+ using Exception::Exception;
+};
+
+class InferenceTestImageLoadFailed : public InferenceTestImageException
+{
+public:
+ using InferenceTestImageException::InferenceTestImageException;
+};
+
+class InferenceTestImageOutOfBoundsAccess : public InferenceTestImageException
+{
+public:
+ using InferenceTestImageException::InferenceTestImageException;
+};
+
+class InferenceTestImageResizeFailed : public InferenceTestImageException
+{
+public:
+ using InferenceTestImageException::InferenceTestImageException;
+};
+
+class InferenceTestImageWriteFailed : public InferenceTestImageException
+{
+public:
+ using InferenceTestImageException::InferenceTestImageException;
+};
+
+class UnknownImageChannelLayout : public InferenceTestImageException
+{
+public:
+ using InferenceTestImageException::InferenceTestImageException;
+};
+
+class InferenceTestImage
+{
+public:
+ enum class WriteFormat
+ {
+ Png,
+ Bmp,
+ Tga
+ };
+
+ explicit InferenceTestImage(const char* filePath);
+
+ InferenceTestImage(InferenceTestImage&&) = delete;
+ InferenceTestImage(const InferenceTestImage&) = delete;
+ InferenceTestImage& operator=(const InferenceTestImage&) = delete;
+ InferenceTestImage& operator=(InferenceTestImage&&) = delete;
+
+ unsigned int GetWidth() const { return m_Width; }
+ unsigned int GetHeight() const { return m_Height; }
+ unsigned int GetNumChannels() const { return m_NumChannels; }
+ unsigned int GetNumElements() const { return GetWidth() * GetHeight() * GetNumChannels(); }
+ unsigned int GetSizeInBytes() const { return GetNumElements() * GetSingleElementSizeInBytes(); }
+
+ // Returns the pixel identified by the given coordinates as a 3-channel value.
+ // Channels beyond the third are dropped. If the image provides less than 3 channels, the non-existent
+ // channels of the pixel will be filled with 0. Channels are returned in RGB order (that is, the first element
+ // of the tuple corresponds to the Red channel, whereas the last element is the Blue channel).
+ std::tuple<uint8_t, uint8_t, uint8_t> GetPixelAs3Channels(unsigned int x, unsigned int y) const;
+
+ void Resize(unsigned int newWidth, unsigned int newHeight);
+ void Write(WriteFormat format, const char* filePath) const;
+
+private:
+ static unsigned int GetSingleElementSizeInBytes()
+ {
+ return sizeof(decltype(std::declval<InferenceTestImage>().m_Data[0]));
+ }
+
+ std::vector<uint8_t> m_Data;
+ unsigned int m_Width;
+ unsigned int m_Height;
+ unsigned int m_NumChannels;
+};
+
+// Common names used to identify a channel in a pixel
+enum class ImageChannel
+{
+ R,
+ G,
+ B
+};
+
+// Channel layouts handled by the test framework
+enum class ImageChannelLayout
+{
+ Rgb,
+ Bgr
+};
+
+// Reads the contents of an inference test image as 3-channel pixels whose channel values have been normalized (scaled)
+// and now lie in the range [0,1]. Channel data is stored according to the ArmNN layout (CHW). The order in which
+// channels appear in the resulting vector is defined by the provided layout.
+std::vector<float> GetImageDataInArmNnLayoutAsNormalizedFloats(ImageChannelLayout layout,
+ const InferenceTestImage& image);
+
+// Reads the contents of an inference test image as 3-channel pixels whose value is the result of subtracting the mean
+// from the values in the original image. Channel data is stored according to the ArmNN layout (CHW). The order in
+// which channels appear in the resulting vector is defined by the provided layout. The order of the channels of the
+// provided mean should also match the given layout.
+std::vector<float> GetImageDataInArmNnLayoutAsFloatsSubtractingMean(ImageChannelLayout layout,
+ const InferenceTestImage& image,
+ const std::array<float, 3>& mean);