From 6940dd720ebb6b3d1df8ca203ab696daefe58189 Mon Sep 17 00:00:00 2001 From: Jim Flynn Date: Fri, 20 Mar 2020 12:25:56 +0000 Subject: renamed Documentation folder 20.02 and added .nojekyll file Signed-off-by: Jim Flynn --- 20.02/_image_tensor_generator_8cpp.xhtml | 185 +++++++++++++++++++++++++++++++ 1 file changed, 185 insertions(+) create mode 100644 20.02/_image_tensor_generator_8cpp.xhtml (limited to '20.02/_image_tensor_generator_8cpp.xhtml') diff --git a/20.02/_image_tensor_generator_8cpp.xhtml b/20.02/_image_tensor_generator_8cpp.xhtml new file mode 100644 index 0000000000..600cc04684 --- /dev/null +++ b/20.02/_image_tensor_generator_8cpp.xhtml @@ -0,0 +1,185 @@ + + + + + + + + + + + + + +ArmNN: tests/ImageTensorGenerator/ImageTensorGenerator.cpp File Reference + + + + + + + + + + + + + + + + +
+
+ + + + ArmNN + + + +
+
+  20.02 +
+
+
+ + + + + + + +
+
+ +
+
+
+ +
+ +
+
+ + +
+ +
+ +
+ +
+
ImageTensorGenerator.cpp File Reference
+
+
+
#include "ImageTensorGenerator.hpp"
+#include "../InferenceTestImage.hpp"
+#include <armnn/Logging.hpp>
+#include <armnn/TypesUtils.hpp>
+#include <boost/filesystem.hpp>
+#include <boost/filesystem/operations.hpp>
+#include <boost/filesystem/path.hpp>
+#include <boost/program_options.hpp>
+#include <boost/variant.hpp>
+#include <algorithm>
+#include <fstream>
+#include <iostream>
+#include <string>
+
+

Go to the source code of this file.

+ + + + +

+Functions

int main (int argc, char *argv[])
 
+

Function Documentation

+ +

◆ main()

+ +
+
+ + + + + + + + + + + + + + + + + + +
int main (int argc,
char * argv[] 
)
+
+ +

Definition at line 248 of file ImageTensorGenerator.cpp.

+ +

References ARMNN_LOG, armnn::Float32, GetNormalizationParameters(), PrepareImageTensor< float >(), PrepareImageTensor< int >(), PrepareImageTensor< uint8_t >(), armnn::QAsymmU8, armnn::Signed32, Exception::what(), and WriteImageTensorImpl().

+
249 {
250  CommandLineProcessor cmdline;
251  if (!cmdline.ProcessCommandLine(argc, argv))
252  {
253  return -1;
254  }
255  const std::string imagePath(cmdline.GetInputFileName());
256  const std::string outputPath(cmdline.GetOutputFileName());
257  const SupportedFrontend& modelFormat(cmdline.GetModelFormat());
258  const armnn::DataType outputType(cmdline.GetOutputType());
259  const unsigned int newWidth = cmdline.GetNewWidth();
260  const unsigned int newHeight = cmdline.GetNewHeight();
261  const unsigned int batchSize = 1;
262  const armnn::DataLayout outputLayout(cmdline.GetLayout());
263 
264  using TContainer = boost::variant<std::vector<float>, std::vector<int>, std::vector<uint8_t>>;
265  std::vector<TContainer> imageDataContainers;
266  const NormalizationParameters& normParams = GetNormalizationParameters(modelFormat, outputType);
267  try
268  {
269  switch (outputType)
270  {
272  imageDataContainers.push_back(PrepareImageTensor<int>(
273  imagePath, newWidth, newHeight, normParams, batchSize, outputLayout));
274  break;
276  imageDataContainers.push_back(PrepareImageTensor<uint8_t>(
277  imagePath, newWidth, newHeight, normParams, batchSize, outputLayout));
278  break;
280  default:
281  imageDataContainers.push_back(PrepareImageTensor<float>(
282  imagePath, newWidth, newHeight, normParams, batchSize, outputLayout));
283  break;
284  }
285  }
286  catch (const InferenceTestImageException& e)
287  {
288  ARMNN_LOG(fatal) << "Failed to load image file " << imagePath << " with error: " << e.what();
289  return -1;
290  }
291 
292  std::ofstream imageTensorFile;
293  imageTensorFile.open(outputPath, std::ofstream::out);
294  if (imageTensorFile.is_open())
295  {
296  boost::apply_visitor([&imageTensorFile](auto&& imageData) { WriteImageTensorImpl(imageData, imageTensorFile); },
297  imageDataContainers[0]);
298  if (!imageTensorFile)
299  {
300  ARMNN_LOG(fatal) << "Failed to write to output file" << outputPath;
301  imageTensorFile.close();
302  return -1;
303  }
304  imageTensorFile.close();
305  }
306  else
307  {
308  ARMNN_LOG(fatal) << "Failed to open output file" << outputPath;
309  return -1;
310  }
311 
312  return 0;
313 }
DataLayout
Definition: Types.hpp:49
+ +
NormalizationParameters GetNormalizationParameters(const SupportedFrontend &modelFormat, const armnn::DataType &outputType)
Get normalization parameters.
+
virtual const char * what() const noexcept override
Definition: Exceptions.cpp:32
+
#define ARMNN_LOG(severity)
Definition: Logging.hpp:163
+
void WriteImageTensorImpl(const std::vector< ElemType > &imageData, std::ofstream &imageTensorFile)
Write image tensor to ofstream.
+
std::vector< uint8_t > PrepareImageTensor< uint8_t >(const std::string &imagePath, unsigned int newWidth, unsigned int newHeight, const NormalizationParameters &normParams, unsigned int batchSize, const armnn::DataLayout &outputLayout)
+
boost::variant< std::vector< float >, std::vector< int >, std::vector< unsigned char > > TContainer
+ + +
DataType
Definition: Types.hpp:32
+ +
std::vector< int > PrepareImageTensor< int >(const std::string &imagePath, unsigned int newWidth, unsigned int newHeight, const NormalizationParameters &normParams, unsigned int batchSize, const armnn::DataLayout &outputLayout)
+ + +
std::vector< float > PrepareImageTensor< float >(const std::string &imagePath, unsigned int newWidth, unsigned int newHeight, const NormalizationParameters &normParams, unsigned int batchSize, const armnn::DataLayout &outputLayout)
+
+
+
+
+
+ + + + -- cgit v1.2.1