ArmNN
 20.02
InferenceTestImage.cpp File Reference
#include "InferenceTestImage.hpp"
#include <armnn/utility/IgnoreUnused.hpp>
#include <boost/format.hpp>
#include <boost/numeric/conversion/cast.hpp>
#include <array>
#include <stb/stb_image.h>
#include <stb/stb_image_resize.h>
#include <stb/stb_image_write.h>

Go to the source code of this file.

Macros

#define STB_IMAGE_IMPLEMENTATION
 
#define STB_IMAGE_RESIZE_IMPLEMENTATION
 
#define STB_IMAGE_WRITE_IMPLEMENTATION
 

Functions

template<typename TProcessValueCallable >
std::vector< float > GetImageDataInArmNnLayoutAsFloats (ImageChannelLayout channelLayout, const InferenceTestImage &image, TProcessValueCallable processValue)
 
std::vector< float > GetImageDataInArmNnLayoutAsNormalizedFloats (ImageChannelLayout layout, const InferenceTestImage &image)
 
std::vector< float > GetImageDataInArmNnLayoutAsFloatsSubtractingMean (ImageChannelLayout layout, const InferenceTestImage &image, const std::array< float, 3 > &mean)
 
std::vector< float > GetImageDataAsNormalizedFloats (ImageChannelLayout layout, const InferenceTestImage &image)
 

Macro Definition Documentation

◆ STB_IMAGE_IMPLEMENTATION

#define STB_IMAGE_IMPLEMENTATION

Definition at line 14 of file InferenceTestImage.cpp.

◆ STB_IMAGE_RESIZE_IMPLEMENTATION

#define STB_IMAGE_RESIZE_IMPLEMENTATION

Definition at line 17 of file InferenceTestImage.cpp.

◆ STB_IMAGE_WRITE_IMPLEMENTATION

#define STB_IMAGE_WRITE_IMPLEMENTATION

Definition at line 20 of file InferenceTestImage.cpp.

Function Documentation

◆ GetImageDataAsNormalizedFloats()

std::vector<float> GetImageDataAsNormalizedFloats ( ImageChannelLayout  layout,
const InferenceTestImage image 
)

Definition at line 334 of file InferenceTestImage.cpp.

References B, G, InferenceTestImage::GetHeight(), InferenceTestImage::GetPixelAs3Channels(), InferenceTestImage::GetWidth(), and R.

336 {
337  std::vector<float> imageData;
338  const unsigned int h = image.GetHeight();
339  const unsigned int w = image.GetWidth();
340 
341  const unsigned int rDstIndex = GetImageChannelIndex(layout, ImageChannel::R);
342  const unsigned int gDstIndex = GetImageChannelIndex(layout, ImageChannel::G);
343  const unsigned int bDstIndex = GetImageChannelIndex(layout, ImageChannel::B);
344 
345  imageData.resize(h * w * 3);
346  unsigned int offset = 0;
347 
348  for (unsigned int j = 0; j < h; ++j)
349  {
350  for (unsigned int i = 0; i < w; ++i)
351  {
352  uint8_t r, g, b;
353  std::tie(r, g, b) = image.GetPixelAs3Channels(i, j);
354 
355  imageData[offset+rDstIndex] = float(r) / 255.0f;
356  imageData[offset+gDstIndex] = float(g) / 255.0f;
357  imageData[offset+bDstIndex] = float(b) / 255.0f;
358  offset += 3;
359  }
360  }
361 
362  return imageData;
363 }
unsigned int GetWidth() const
std::tuple< uint8_t, uint8_t, uint8_t > GetPixelAs3Channels(unsigned int x, unsigned int y) const
unsigned int GetHeight() const

◆ GetImageDataInArmNnLayoutAsFloats()

std::vector<float> GetImageDataInArmNnLayoutAsFloats ( ImageChannelLayout  channelLayout,
const InferenceTestImage image,
TProcessValueCallable  processValue 
)

Definition at line 280 of file InferenceTestImage.cpp.

References B, G, InferenceTestImage::GetHeight(), InferenceTestImage::GetPixelAs3Channels(), InferenceTestImage::GetWidth(), and R.

Referenced by GetImageDataInArmNnLayoutAsFloatsSubtractingMean(), and GetImageDataInArmNnLayoutAsNormalizedFloats().

283 {
284  const unsigned int h = image.GetHeight();
285  const unsigned int w = image.GetWidth();
286 
287  std::vector<float> imageData;
288  imageData.resize(h * w * 3);
289 
290  for (unsigned int j = 0; j < h; ++j)
291  {
292  for (unsigned int i = 0; i < w; ++i)
293  {
294  uint8_t r, g, b;
295  std::tie(r, g, b) = image.GetPixelAs3Channels(i, j);
296 
297  // ArmNN order: C, H, W
298  const unsigned int rDstIndex = GetImageChannelIndex(channelLayout, ImageChannel::R) * h * w + j * w + i;
299  const unsigned int gDstIndex = GetImageChannelIndex(channelLayout, ImageChannel::G) * h * w + j * w + i;
300  const unsigned int bDstIndex = GetImageChannelIndex(channelLayout, ImageChannel::B) * h * w + j * w + i;
301 
302  imageData[rDstIndex] = processValue(ImageChannel::R, float(r));
303  imageData[gDstIndex] = processValue(ImageChannel::G, float(g));
304  imageData[bDstIndex] = processValue(ImageChannel::B, float(b));
305  }
306  }
307 
308  return imageData;
309 }
unsigned int GetWidth() const
std::tuple< uint8_t, uint8_t, uint8_t > GetPixelAs3Channels(unsigned int x, unsigned int y) const
unsigned int GetHeight() const

◆ GetImageDataInArmNnLayoutAsFloatsSubtractingMean()

std::vector<float> GetImageDataInArmNnLayoutAsFloatsSubtractingMean ( ImageChannelLayout  layout,
const InferenceTestImage image,
const std::array< float, 3 > &  mean 
)

Definition at line 322 of file InferenceTestImage.cpp.

References GetImageDataInArmNnLayoutAsFloats().

Referenced by CaffePreprocessor::GetTestCaseData().

325 {
326  return GetImageDataInArmNnLayoutAsFloats(layout, image,
327  [layout, &mean](ImageChannel channel, float value)
328  {
329  const unsigned int channelIndex = GetImageChannelIndex(layout, channel);
330  return value - mean[channelIndex];
331  });
332 }
std::vector< float > GetImageDataInArmNnLayoutAsFloats(ImageChannelLayout channelLayout, const InferenceTestImage &image, TProcessValueCallable processValue)

◆ GetImageDataInArmNnLayoutAsNormalizedFloats()

std::vector<float> GetImageDataInArmNnLayoutAsNormalizedFloats ( ImageChannelLayout  layout,
const InferenceTestImage image 
)

Definition at line 311 of file InferenceTestImage.cpp.

References GetImageDataInArmNnLayoutAsFloats(), and armnn::IgnoreUnused().

Referenced by YoloDatabase::GetTestCaseData().

313 {
314  return GetImageDataInArmNnLayoutAsFloats(layout, image,
315  [](ImageChannel channel, float value)
316  {
317  armnn::IgnoreUnused(channel);
318  return value / 255.f;
319  });
320 }
void IgnoreUnused(Ts &&...)
std::vector< float > GetImageDataInArmNnLayoutAsFloats(ImageChannelLayout channelLayout, const InferenceTestImage &image, TProcessValueCallable processValue)