aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSiCong Li <sicong.li@arm.com>2019-07-18 16:33:42 +0100
committerMatteo Martincigh <matteo.martincigh@arm.com>2019-07-23 12:45:12 +0000
commit588973fa6f68660b2cdc0704bb452984b32e16fd (patch)
tree706b1548f0ac38540af997fcd43b02d55b4b62a1 /tests
parentf8c629701e760e2476582c91e6b7f5e1313dc02a (diff)
downloadarmnn-588973fa6f68660b2cdc0704bb452984b32e16fd.tar.gz
Fix and clean up ImageTensorGenerator
* Fix the issue that uint8_t image tensors are written out as characters. * Add doxygen comments. Signed-off-by: SiCong Li <sicong.li@arm.com> Change-Id: Ic5b3af489f405abcc1ed1e7dd76f56c5ae7ffbf4
Diffstat (limited to 'tests')
-rw-r--r--tests/ImageTensorGenerator/ImageTensorGenerator.hpp35
1 files changed, 30 insertions, 5 deletions
diff --git a/tests/ImageTensorGenerator/ImageTensorGenerator.hpp b/tests/ImageTensorGenerator/ImageTensorGenerator.hpp
index e5bc414c29..3e164bc9e0 100644
--- a/tests/ImageTensorGenerator/ImageTensorGenerator.hpp
+++ b/tests/ImageTensorGenerator/ImageTensorGenerator.hpp
@@ -12,6 +12,7 @@
#include <iterator>
#include <string>
+// Parameters used in normalizing images
struct NormalizationParameters
{
float scale{ 1.0 };
@@ -26,9 +27,13 @@ enum class SupportedFrontend
TFLite = 2,
};
-// Get normalization parameters.
-// Note that different flavours of models have different normalization methods.
-// This tool currently only supports Caffe, TF and TFLite models
+/** Get normalization parameters.
+ * Note that different flavours of models and different model data types have different normalization methods.
+ * This tool currently only supports Caffe, TF and TFLite models
+ *
+ * @param[in] modelFormat One of the supported frontends
+ * @param[in] outputType Output type of the image tensor, also the type of the intended model
+ */
NormalizationParameters GetNormalizationParameters(const SupportedFrontend& modelFormat,
const armnn::DataType& outputType)
{
@@ -62,7 +67,15 @@ NormalizationParameters GetNormalizationParameters(const SupportedFrontend& mode
return normParams;
}
-// Prepare raw image tensor data by loading the image from imagePath and preprocessing it.
+/** Prepare raw image tensor data by loading the image from imagePath and preprocessing it.
+ *
+ * @param[in] imagePath Path to the image file
+ * @param[in] newWidth The new width of the output image tensor
+ * @param[in] newHeight The new height of the output image tensor
+ * @param[in] normParams Normalization parameters for the normalization of the image
+ * @param[in] batchSize Batch size
+ * @param[in] outputLayout Data layout of the output image tensor
+ */
template <typename ElemType>
std::vector<ElemType> PrepareImageTensor(const std::string& imagePath,
unsigned int newWidth,
@@ -148,9 +161,21 @@ std::vector<uint8_t> PrepareImageTensor<uint8_t>(const std::string& imagePath,
return imageDataQasymm8;
}
-// Write image tensor to ofstream
+/** Write image tensor to ofstream
+ *
+ * @param[in] imageData Image tensor data
+ * @param[in] imageTensorFile Output filestream (ofstream) to which the image tensor data is written
+ */
template <typename ElemType>
void WriteImageTensorImpl(const std::vector<ElemType>& imageData, std::ofstream& imageTensorFile)
{
std::copy(imageData.begin(), imageData.end(), std::ostream_iterator<ElemType>(imageTensorFile, " "));
+}
+
+// For uint8_t image tensor, cast it to int before writing it to prevent writing data as characters instead of
+// numerical values
+template <>
+void WriteImageTensorImpl<uint8_t>(const std::vector<uint8_t>& imageData, std::ofstream& imageTensorFile)
+{
+ std::copy(imageData.begin(), imageData.end(), std::ostream_iterator<int>(imageTensorFile, " "));
} \ No newline at end of file