ArmNN
 20.05
armnnUtils Namespace Reference

Namespaces

 Filesystem
 
 Processes
 

Classes

class  CsvReader
 
struct  CsvRow
 
class  DataLayoutIndexed
 Provides access to the appropriate indexes for Channels, Height and Width based on DataLayout. More...
 
class  FloatingPointConverter
 
struct  IsFloatingPointIterator
 
class  ModelAccuracyChecker
 
struct  ParserPrototxtFixture
 
struct  SelectiveQuantizer
 
struct  SelectiveQuantizer< armnn::BFloat16, false >
 
struct  SelectiveQuantizer< armnn::Half, false >
 
struct  SelectiveQuantizer< T, false >
 

Typedefs

using LabelCategoryNames = std::vector< std::string >
 

Functions

bool operator== (const armnn::DataLayout &dataLayout, const DataLayoutIndexed &indexed)
 Equality methods. More...
 
bool operator== (const DataLayoutIndexed &indexed, const armnn::DataLayout &dataLayout)
 
armnn::TensorShape Permuted (const armnn::TensorShape &srcShape, const armnn::PermutationVector &mappings)
 
armnn::TensorInfo Permuted (const armnn::TensorInfo &info, const armnn::PermutationVector &mappings)
 
void Permute (const armnn::TensorShape &dstShape, const armnn::PermutationVector &mappings, const void *src, void *dst, size_t dataTypeSize)
 
armnn::TensorShape GetTensorShape (unsigned int numberOfBatches, unsigned int numberOfChannels, unsigned int height, unsigned int width, const armnn::DataLayout dataLayout)
 
armnn::TensorInfo GetTensorInfo (unsigned int numberOfBatches, unsigned int numberOfChannels, unsigned int height, unsigned int width, const armnn::DataLayout dataLayout, const armnn::DataType dataType)
 
std::pair< float, float > FindMinMax (armnn::ITensorHandle *tensorHandle)
 
armnn::TensorShape ExpandDims (const armnn::TensorShape &tensorShape, int axis)
 
unsigned int GetNumElementsBetween (const armnn::TensorShape &shape, unsigned int firstAxisInclusive, unsigned int lastAxisExclusive)
 
unsigned int GetUnsignedAxis (const unsigned int inputDimension, const int axis)
 
unsigned int GetNumElementsAfter (const armnn::TensorShape &shape, unsigned int axis)
 
std::pair< unsigned int, std::vector< float > > GetPerAxisParams (const armnn::TensorInfo &info)
 
armnn::TensorShape TransposeTensorShape (const armnn::TensorShape &srcShape, const armnn::PermutationVector &mappings)
 
armnn::TensorInfo TransposeTensorShape (const armnn::TensorInfo &info, const armnn::PermutationVector &mappings)
 
void Transpose (const armnn::TensorShape &dstShape, const armnn::PermutationVector &mappings, const void *src, void *dst, size_t dataTypeSize)
 
CsvRow ParseLine (const std::string &csvLine)
 
template<typename TNodeId , typename TTargetNodes >
bool GraphTopologicalSort (const TTargetNodes &targetNodes, std::function< std::vector< TNodeId >(TNodeId)> getIncomingEdges, std::vector< TNodeId > &outSorted)
 
std::vector< std::string > SplitBy (const std::string &originalString, const std::string &delimiter=" ", bool includeEmptyToken=false)
 Split a string into tokens by a delimiter. More...
 
std::string Strip (const std::string &originalString, const std::string &characterSet=" ")
 Remove any preceding and trailing character specified in the characterSet. More...
 
void ProcessConcatInputTensorInfo (armnn::TensorInfo &inputTensorInfo, armnn::OriginsDescriptor &concatDescriptor, const unsigned int &concatAxis, unsigned int inputIndex, unsigned int &mergeDimOrigin)
 
void CalculateReducedOutputTensoInfo (const armnn::TensorInfo &inputTensorInfo, const std::set< unsigned int > &axisSet, bool keepDims, armnn::TensorInfo &outputTensorInfo)
 Creates a tensor info after reducing the dimensions mentioned in axisData. More...
 
void CalculateStridedSliceOutputTensorInfo (const armnn::TensorInfo &inputTensorInfo, const armnn::StridedSliceDescriptor &desc, armnn::TensorInfo &outputTensorInfo)
 Create output tensor info for a StridedSlice operator. More...
 
std::string ConvertInt32ToOctalString (int value)
 Converts an int value into the Prototxt octal representation. More...
 
std::string ConvertTensorShapeToString (const armnn::TensorShape &shape)
 Converts an TensorShape into Prototxt representation. More...
 
template<typename T >
SelectiveQuantize (float value, float scale, int32_t offset)
 
template<typename T >
float SelectiveDequantize (T value, float scale, int32_t offset)
 
template<typename T , typename FloatIt , typename std::enable_if< IsFloatingPointIterator< FloatIt >::value, int >::type = 0>
std::vector< T > QuantizedVector (FloatIt first, FloatIt last, float qScale, int32_t qOffset)
 
template<typename T >
std::vector< T > QuantizedVector (const std::vector< float > &array, float qScale=1.f, int32_t qOffset=0)
 
template<typename T >
std::vector< T > QuantizedVector (std::initializer_list< float > array, float qScale=1.f, int32_t qOffset=0)
 
template<typename TContainer >
armnn::InputTensors MakeInputTensors (const std::vector< armnn::BindingPointInfo > &inputBindings, const std::vector< TContainer > &inputDataContainers)
 
template<typename TContainer >
armnn::OutputTensors MakeOutputTensors (const std::vector< armnn::BindingPointInfo > &outputBindings, std::vector< TContainer > &outputDataContainers)
 
void CheckValidSize (std::initializer_list< size_t > validInputCounts, size_t actualValue, const char *validExpr, const char *actualExpr, const CheckLocation &location)
 
uint32_t NonNegative (const char *expr, int32_t value, const CheckLocation &location)
 
int32_t VerifyInt32 (const char *expr, int64_t value, const armnn::CheckLocation &location)
 

Variables

const armnn::PermutationVector NHWCToArmNN = { 0, 2, 3, 1 }
 
const armnn::PermutationVector ArmNNToNHWC = { 0, 3, 1, 2 }
 

Typedef Documentation

◆ LabelCategoryNames

using LabelCategoryNames = std::vector<std::string>

Definition at line 25 of file ModelAccuracyChecker.hpp.

Function Documentation

◆ CalculateReducedOutputTensoInfo()

void CalculateReducedOutputTensoInfo ( const armnn::TensorInfo inputTensorInfo,
const std::set< unsigned int > &  axisSet,
bool  keepDims,
armnn::TensorInfo outputTensorInfo 
)

Creates a tensor info after reducing the dimensions mentioned in axisData.

Definition at line 54 of file ParserHelper.cpp.

References TensorInfo::GetDataType(), TensorInfo::GetNumDimensions(), and TensorInfo::GetShape().

Referenced by BOOST_AUTO_TEST_CASE(), and armnnTfParser::OutputShapeOfSqueeze().

58 {
59  std::vector<unsigned int> outputShapeVector;
60  bool dimensionFound = false;
61  unsigned int size = 1;
62 
63  for (unsigned int i = 0; i < inputTensorInfo.GetNumDimensions(); ++i)
64  {
65  dimensionFound = false;
66  for (unsigned int axis: axisSet)
67  {
68  if (axis == i)
69  {
70  dimensionFound = true;
71  break;
72  }
73  }
74 
75  if (!dimensionFound)
76  {
77  size *= inputTensorInfo.GetShape()[i];
78 
79  if (keepDims)
80  {
81  outputShapeVector.push_back(inputTensorInfo.GetShape()[i]);
82  }
83  }
84  else
85  {
86  if (keepDims)
87  {
88  outputShapeVector.push_back(1);
89  }
90  }
91  }
92 
93  if (keepDims)
94  {
95  armnn::TensorShape outputTensorShape(inputTensorInfo.GetNumDimensions(), &outputShapeVector[0]);
96  outputTensorInfo = armnn::TensorInfo(outputTensorShape, inputTensorInfo.GetDataType());
97  }
98  else
99  {
100  outputTensorInfo = armnn::TensorInfo({size}, inputTensorInfo.GetDataType());
101  }
102 }
const TensorShape & GetShape() const
Definition: Tensor.hpp:88
DataType GetDataType() const
Definition: Tensor.hpp:95
unsigned int GetNumDimensions() const
Definition: Tensor.hpp:92

◆ CalculateStridedSliceOutputTensorInfo()

void CalculateStridedSliceOutputTensorInfo ( const armnn::TensorInfo inputTensorInfo,
const armnn::StridedSliceDescriptor desc,
armnn::TensorInfo outputTensorInfo 
)

Create output tensor info for a StridedSlice operator.

Definition at line 105 of file ParserHelper.cpp.

References TensorInfo::GetDataType(), TensorInfo::GetNumDimensions(), TensorInfo::GetShape(), StridedSliceDescriptor::GetStartForAxis(), StridedSliceDescriptor::GetStopForAxis(), StridedSliceDescriptor::m_ShrinkAxisMask, and StridedSliceDescriptor::m_Stride.

Referenced by armnnTfParser::OutputShapeOfSqueeze().

108 {
109  const armnn::TensorShape& inputShape = inputTensorInfo.GetShape();
110 
111  std::vector<unsigned int> outputShapeVector;
112  for (unsigned int i = 0; i < inputTensorInfo.GetNumDimensions(); i++)
113  {
114  if (desc.m_ShrinkAxisMask & (1 << i))
115  {
116  continue;
117  }
118 
119  int stride = desc.m_Stride[i];
120  int start = desc.GetStartForAxis(inputShape, i);
121  int stop = desc.GetStopForAxis(inputShape, i, start);
122 
123  int newSize = stride > 0 ? ((stop - start) + stride - 1) / stride :
124  ((start - stop) - stride - 1) / -stride;
125 
126  newSize = std::max(0, newSize);
127 
128  outputShapeVector.push_back(static_cast<unsigned int>(newSize));
129  }
130 
131  armnn::TensorShape outputTensorShape(inputTensorInfo.GetNumDimensions(), &outputShapeVector[0]);
132  outputTensorInfo = armnn::TensorInfo(armnn::TensorShape(outputTensorShape), inputTensorInfo.GetDataType());
133 }
const TensorShape & GetShape() const
Definition: Tensor.hpp:88
int32_t m_ShrinkAxisMask
Shrink axis mask value. If set, the nth specification shrinks the dimensionality by 1...
int GetStartForAxis(const TensorShape &inputShape, unsigned int axis) const
DataType GetDataType() const
Definition: Tensor.hpp:95
std::vector< int > m_Stride
Stride values for the input that will be sliced.
int GetStopForAxis(const TensorShape &inputShape, unsigned int axis, int startForAxis) const
unsigned int GetNumDimensions() const
Definition: Tensor.hpp:92

◆ CheckValidSize()

void CheckValidSize ( std::initializer_list< size_t >  validInputCounts,
size_t  actualValue,
const char *  validExpr,
const char *  actualExpr,
const CheckLocation location 
)

Definition at line 15 of file VerificationHelpers.cpp.

References CheckLocation::AsString().

20 {
21  bool isValid = std::any_of(validInputCounts.begin(),
22  validInputCounts.end(),
23  [&actualValue](size_t x) { return x == actualValue; } );
24  if (!isValid)
25  {
26  throw ParseException(
27  boost::str(
28  boost::format("%1% = %2% is not valid, not in {%3%}. %4%") %
29  actualExpr %
30  actualValue %
31  validExpr %
32  location.AsString()));
33  }
34 }
std::string AsString() const
Definition: Exceptions.hpp:29

◆ ConvertInt32ToOctalString()

std::string ConvertInt32ToOctalString ( int  value)

Converts an int value into the Prototxt octal representation.

Definition at line 19 of file PrototxtConversions.cpp.

Referenced by BOOST_AUTO_TEST_CASE().

20 {
21  std::stringstream ss;
22  std::string returnString;
23  for (int i = 0; i < 4; ++i)
24  {
25  ss << "\\";
26  ss << std::setw(3) << std::setfill('0') << std::oct << ((value >> (i * 8)) & 0xFF);
27  }
28 
29  ss >> returnString;
30  return returnString;
31 }

◆ ConvertTensorShapeToString()

std::string ConvertTensorShapeToString ( const armnn::TensorShape shape)

Converts an TensorShape into Prototxt representation.

Definition at line 34 of file PrototxtConversions.cpp.

References TensorShape::GetNumDimensions().

Referenced by BOOST_AUTO_TEST_CASE().

35 {
36  std::stringstream ss;
37  for (unsigned int i = 0 ; i < shape.GetNumDimensions() ; i++)
38  {
39  ss << "dim {\n";
40  ss << "size: " << std::to_string(shape[i]) << "\n";
41  ss << "}\n";
42  }
43  return ss.str();
44 
45 }
unsigned int GetNumDimensions() const
Definition: Tensor.hpp:43

◆ ExpandDims()

TensorShape ExpandDims ( const armnn::TensorShape tensorShape,
int  axis 
)

Definition at line 85 of file TensorUtils.cpp.

References CHECK_LOCATION, TensorShape::GetNumDimensions(), and armnn::numeric_cast().

Referenced by BOOST_AUTO_TEST_CASE().

86 {
87  unsigned int outputDim = tensorShape.GetNumDimensions() + 1;
88 
89  if (axis < -boost::numeric_cast<int>(outputDim) || axis > boost::numeric_cast<int>(tensorShape.GetNumDimensions()))
90  {
92  boost::str(boost::format("Invalid expansion axis %1% for %2%D input tensor. %3%") %
93  axis %
94  tensorShape.GetNumDimensions() %
95  CHECK_LOCATION().AsString()));
96  }
97 
98  if (axis < 0)
99  {
100  axis = boost::numeric_cast<int>(outputDim) + axis;
101  }
102 
103  std::vector<unsigned int> outputShape;
104  for (unsigned int i = 0; i < tensorShape.GetNumDimensions(); ++i)
105  {
106  outputShape.push_back(tensorShape[i]);
107  }
108  outputShape.insert(outputShape.begin() + axis, 1);
109 
110  return TensorShape(outputDim, outputShape.data());
111 }
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
Definition: NumericCast.hpp:33
#define CHECK_LOCATION()
Definition: Exceptions.hpp:192
unsigned int GetNumDimensions() const
Definition: Tensor.hpp:43

◆ FindMinMax()

std::pair< float, float > FindMinMax ( armnn::ITensorHandle tensorHandle)

Definition at line 58 of file TensorUtils.cpp.

References TensorShape::GetNumElements(), ITensorHandle::GetShape(), ITensorHandle::Map(), and ITensorHandle::Unmap().

Referenced by NetworkQuantizer::Refine().

59 {
60  auto tensor_data = static_cast<const float *>(tensorHandle->Map(true));
61  auto tensor_size = tensorHandle->GetShape().GetNumElements();
62 
63  // Set min/max initially to first value in tensor
64  float min = tensor_data[0];
65  float max = tensor_data[0];
66 
67  // Loop over rest of tensor and update min/max if necessary
68  for (unsigned int val = 1; val < tensor_size; val++)
69  {
70  if (tensor_data[val] < min)
71  {
72  min = tensor_data[val];
73  }
74  else if (tensor_data[val] > max)
75  {
76  max = tensor_data[val];
77  }
78  }
79 
80  tensorHandle->Unmap();
81 
82  return std::make_pair(min, max);
83 }
unsigned int GetNumElements() const
Definition: Tensor.cpp:107
virtual TensorShape GetShape() const =0
Get the number of elements for each dimension ordered from slowest iterating dimension to fastest ite...
virtual const void * Map(bool blocking=true) const =0
Map the tensor data for access.
virtual void Unmap() const =0
Unmap the tensor data.

◆ GetNumElementsAfter()

unsigned int GetNumElementsAfter ( const armnn::TensorShape shape,
unsigned int  axis 
)

Definition at line 140 of file TensorUtils.cpp.

References ARMNN_ASSERT, and TensorShape::GetNumDimensions().

Referenced by GetPerAxisParams().

141 {
142  unsigned int numDim = shape.GetNumDimensions();
143  ARMNN_ASSERT(axis <= numDim - 1);
144  unsigned int count = 1;
145  for (unsigned int i = axis; i < numDim; i++)
146  {
147  count *= shape[i];
148  }
149  return count;
150 }
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
unsigned int GetNumDimensions() const
Definition: Tensor.hpp:43

◆ GetNumElementsBetween()

unsigned int GetNumElementsBetween ( const armnn::TensorShape shape,
unsigned int  firstAxisInclusive,
unsigned int  lastAxisExclusive 
)

Definition at line 113 of file TensorUtils.cpp.

References ARMNN_ASSERT, and TensorShape::GetNumDimensions().

Referenced by armnn::ArgMinMax(), armnn::LogSoftmax(), and armnn::Softmax().

116 {
117  ARMNN_ASSERT(firstAxisInclusive <= lastAxisExclusive);
118  ARMNN_ASSERT(lastAxisExclusive <= shape.GetNumDimensions());
119  unsigned int count = 1;
120  for (unsigned int i = firstAxisInclusive; i < lastAxisExclusive; i++)
121  {
122  count *= shape[i];
123  }
124  return count;
125 }
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
unsigned int GetNumDimensions() const
Definition: Tensor.hpp:43

◆ GetPerAxisParams()

std::pair< unsigned int, std::vector< float > > GetPerAxisParams ( const armnn::TensorInfo info)

Definition at line 152 of file TensorUtils.cpp.

References CHECK_LOCATION, TensorInfo::GetDataType(), armnn::GetDataTypeName(), GetNumElementsAfter(), TensorInfo::GetQuantizationDim(), TensorInfo::GetQuantizationScales(), TensorInfo::GetShape(), TensorInfo::HasPerAxisQuantization(), and OptionalReferenceSwitch< IsReference, T >::value().

Referenced by armnn::MakeDecoder(), and armnn::MakeEncoder().

153 {
154  const std::vector<float>& scales = info.GetQuantizationScales();
155  armnn::Optional<unsigned int> quantizationDim = info.GetQuantizationDim();
156  if (!info.HasPerAxisQuantization())
157  {
159  std::string("Per-axis quantization params not set for tensor of type ") +
161  }
162  unsigned int axisFactor = GetNumElementsAfter(info.GetShape(), quantizationDim.value());
163 
164  return { axisFactor, scales };
165 }
const TensorShape & GetShape() const
Definition: Tensor.hpp:88
bool HasPerAxisQuantization() const
Definition: Tensor.cpp:233
Optional< unsigned int > GetQuantizationDim() const
Definition: Tensor.cpp:281
std::vector< float > GetQuantizationScales() const
Definition: Tensor.cpp:238
constexpr const char * GetDataTypeName(DataType dataType)
Definition: TypesUtils.hpp:168
DataType GetDataType() const
Definition: Tensor.hpp:95
#define CHECK_LOCATION()
Definition: Exceptions.hpp:192
unsigned int GetNumElementsAfter(const armnn::TensorShape &shape, unsigned int axis)

◆ GetTensorInfo()

TensorInfo GetTensorInfo ( unsigned int  numberOfBatches,
unsigned int  numberOfChannels,
unsigned int  height,
unsigned int  width,
const armnn::DataLayout  dataLayout,
const armnn::DataType  dataType 
)

Definition at line 38 of file TensorUtils.cpp.

References CHECK_LOCATION, armnn::NCHW, and armnn::NHWC.

Referenced by CaffeParserBase::AddConvLayerWithDepthwiseConv(), CaffeParserBase::AddConvLayerWithSplits(), DepthwiseConvolution2dAsymmetricTestImpl(), DepthwiseConvolution2dDepthMul1TestImpl(), DepthwiseConvolution2dTestImpl(), CaffeParserBase::ParseBatchNormLayer(), CaffeParserBase::ParseConcatLayer(), CaffeParserBase::ParseConvLayer(), CaffeParserBase::ParseEltwiseLayer(), CaffeParserBase::ParseInnerProductLayer(), CaffeParserBase::ParseLRNLayer(), CaffeParserBase::ParsePoolingLayer(), CaffeParserBase::ParseReluLayer(), CaffeParserBase::ParseScaleLayer(), CaffeParserBase::ParseSoftmaxLayer(), and SimpleConvolution2dTestImpl().

44 {
45  switch (dataLayout)
46  {
47  case DataLayout::NCHW:
48  return TensorInfo({numberOfBatches, numberOfChannels, height, width}, dataType);
49  case DataLayout::NHWC:
50  return TensorInfo({numberOfBatches, height, width, numberOfChannels}, dataType);
51  default:
52  throw InvalidArgumentException("Unknown data layout ["
53  + std::to_string(static_cast<int>(dataLayout)) +
54  "]", CHECK_LOCATION());
55  }
56 }
#define CHECK_LOCATION()
Definition: Exceptions.hpp:192

◆ GetTensorShape()

TensorShape GetTensorShape ( unsigned int  numberOfBatches,
unsigned int  numberOfChannels,
unsigned int  height,
unsigned int  width,
const armnn::DataLayout  dataLayout 
)

Definition at line 19 of file TensorUtils.cpp.

References CHECK_LOCATION, armnn::NCHW, and armnn::NHWC.

24 {
25  switch (dataLayout)
26  {
27  case DataLayout::NCHW:
28  return TensorShape({numberOfBatches, numberOfChannels, height, width});
29  case DataLayout::NHWC:
30  return TensorShape({numberOfBatches, height, width, numberOfChannels});
31  default:
32  throw InvalidArgumentException("Unknown data layout ["
33  + std::to_string(static_cast<int>(dataLayout)) +
34  "]", CHECK_LOCATION());
35  }
36 }
#define CHECK_LOCATION()
Definition: Exceptions.hpp:192

◆ GetUnsignedAxis()

unsigned int GetUnsignedAxis ( const unsigned int  inputDimension,
const int  axis 
)

Definition at line 127 of file TensorUtils.cpp.

References ARMNN_ASSERT_MSG, and armnn::numeric_cast().

Referenced by armnn::ArgMinMax(), ClArgMinMaxWorkload::ClArgMinMaxWorkload(), ArgMinMaxLayer::InferOutputShapes(), NeonArgMinMaxWorkload::NeonArgMinMaxWorkload(), and ArgMinMaxQueueDescriptor::Validate().

128 {
129  ARMNN_ASSERT_MSG(axis < boost::numeric_cast<int>(inputDimension),
130  "Required axis index greater than number of dimensions.");
131  ARMNN_ASSERT_MSG(axis >= -boost::numeric_cast<int>(inputDimension),
132  "Required axis index lower than negative of the number of dimensions");
133 
134  unsigned int uAxis = axis < 0 ?
135  inputDimension - boost::numeric_cast<unsigned int>(abs(axis))
136  : boost::numeric_cast<unsigned int>(axis);
137  return uAxis;
138 }
#define ARMNN_ASSERT_MSG(COND, MSG)
Definition: Assert.hpp:15
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
Definition: NumericCast.hpp:33

◆ GraphTopologicalSort()

bool armnnUtils::GraphTopologicalSort ( const TTargetNodes &  targetNodes,
std::function< std::vector< TNodeId >(TNodeId)>  getIncomingEdges,
std::vector< TNodeId > &  outSorted 
)

Definition at line 110 of file GraphTopologicalSort.hpp.

114 {
115  outSorted.clear();
116  std::map<TNodeId, NodeState> nodeStates;
117 
118  for (TNodeId targetNode : targetNodes)
119  {
120  if (!TopologicallySort(targetNode, getIncomingEdges, outSorted, nodeStates))
121  {
122  return false;
123  }
124  }
125 
126  return true;
127 }

◆ MakeInputTensors()

armnn::InputTensors armnnUtils::MakeInputTensors ( const std::vector< armnn::BindingPointInfo > &  inputBindings,
const std::vector< TContainer > &  inputDataContainers 
)
inline

Definition at line 17 of file TensorIOUtils.hpp.

Referenced by InferenceModel< IParser, TDataType >::GetAllQuantizationParams(), and main().

19 {
20  armnn::InputTensors inputTensors;
21 
22  const size_t numInputs = inputBindings.size();
23  if (numInputs != inputDataContainers.size())
24  {
25  throw armnn::Exception(boost::str(boost::format("The number of inputs does not match number of "
26  "tensor data containers: %1% != %2%")
27  % numInputs
28  % inputDataContainers.size()));
29  }
30 
31  for (size_t i = 0; i < numInputs; i++)
32  {
33  const armnn::BindingPointInfo& inputBinding = inputBindings[i];
34  const TContainer& inputData = inputDataContainers[i];
35 
36  boost::apply_visitor([&](auto&& value)
37  {
38  if (value.size() != inputBinding.second.GetNumElements())
39  {
40  throw armnn::Exception(boost::str(boost::format("The input tensor has incorrect size "
41  "(expected %1% got %2%)")
42  % inputBinding.second.GetNumElements()
43  % value.size()));
44  }
45 
46  armnn::ConstTensor inputTensor(inputBinding.second, value.data());
47  inputTensors.push_back(std::make_pair(inputBinding.first, inputTensor));
48  },
49  inputData);
50  }
51 
52  return inputTensors;
53 }
std::vector< std::pair< LayerBindingId, class ConstTensor > > InputTensors
Definition: Tensor.hpp:225
boost::variant< std::vector< float >, std::vector< int >, std::vector< unsigned char > > TContainer
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
Definition: Tensor.hpp:199
std::pair< armnn::LayerBindingId, armnn::TensorInfo > BindingPointInfo
Definition: Tensor.hpp:146
Base class for all ArmNN exceptions so that users can filter to just those.
Definition: Exceptions.hpp:46

◆ MakeOutputTensors()

armnn::OutputTensors armnnUtils::MakeOutputTensors ( const std::vector< armnn::BindingPointInfo > &  outputBindings,
std::vector< TContainer > &  outputDataContainers 
)
inline

Definition at line 56 of file TensorIOUtils.hpp.

Referenced by InferenceModel< IParser, TDataType >::GetAllQuantizationParams(), and main().

58 {
59  armnn::OutputTensors outputTensors;
60 
61  const size_t numOutputs = outputBindings.size();
62  if (numOutputs != outputDataContainers.size())
63  {
64  throw armnn::Exception(boost::str(boost::format("Number of outputs does not match number of "
65  "tensor data containers: %1% != %2%")
66  % numOutputs
67  % outputDataContainers.size()));
68  }
69 
70  for (size_t i = 0; i < numOutputs; i++)
71  {
72  const armnn::BindingPointInfo& outputBinding = outputBindings[i];
73  TContainer& outputData = outputDataContainers[i];
74 
75  boost::apply_visitor([&](auto&& value)
76  {
77  if (value.size() != outputBinding.second.GetNumElements())
78  {
79  throw armnn::Exception("Output tensor has incorrect size");
80  }
81 
82  armnn::Tensor outputTensor(outputBinding.second, value.data());
83  outputTensors.push_back(std::make_pair(outputBinding.first, outputTensor));
84  },
85  outputData);
86  }
87 
88  return outputTensors;
89 }
boost::variant< std::vector< float >, std::vector< int >, std::vector< unsigned char > > TContainer
A tensor defined by a TensorInfo (shape and data type) and a mutable backing store.
Definition: Tensor.hpp:191
std::vector< std::pair< LayerBindingId, class Tensor > > OutputTensors
Definition: Tensor.hpp:226
std::pair< armnn::LayerBindingId, armnn::TensorInfo > BindingPointInfo
Definition: Tensor.hpp:146
Base class for all ArmNN exceptions so that users can filter to just those.
Definition: Exceptions.hpp:46

◆ NonNegative()

uint32_t NonNegative ( const char *  expr,
int32_t  value,
const CheckLocation location 
)

Definition at line 36 of file VerificationHelpers.cpp.

References CheckLocation::AsString().

39 {
40  if (value < 0)
41  {
42  throw ParseException(
43  boost::str(
44  boost::format("'%1%' must be non-negative, received: %2% at %3%") %
45  expr %
46  value %
47  location.AsString() ));
48  }
49  else
50  {
51  return static_cast<uint32_t>(value);
52  }
53 }
std::string AsString() const
Definition: Exceptions.hpp:29

◆ operator==() [1/2]

bool operator== ( const armnn::DataLayout dataLayout,
const DataLayoutIndexed indexed 
)

Equality methods.

Definition at line 34 of file DataLayoutIndexed.cpp.

References DataLayoutIndexed::GetDataLayout().

Referenced by BOOST_AUTO_TEST_CASE(), OutputSlot::Disconnect(), and DataLayoutIndexed::GetIndex().

35 {
36  return dataLayout == indexed.GetDataLayout();
37 }
armnn::DataLayout GetDataLayout() const

◆ operator==() [2/2]

bool operator== ( const DataLayoutIndexed indexed,
const armnn::DataLayout dataLayout 
)

Definition at line 39 of file DataLayoutIndexed.cpp.

References DataLayoutIndexed::GetDataLayout().

40 {
41  return indexed.GetDataLayout() == dataLayout;
42 }
armnn::DataLayout GetDataLayout() const

◆ ParseLine()

CsvRow armnnUtils::ParseLine ( const std::string &  csvLine)

Definition at line 20 of file CsvReader.cpp.

References armnn::stringUtils::StringTrimCopy(), and CsvRow::values.

Referenced by CsvReader::ParseFile(), and CsvReader::ParseVector().

21 {
22  Tokenizer tokenizer(csvLine);
23  CsvRow entry;
24 
25  for (const auto &token : tokenizer)
26  {
27  entry.values.push_back(armnn::stringUtils::StringTrimCopy(token));
28  }
29  return entry;
30 }
std::string StringTrimCopy(const std::string &str, const std::string &chars="\\\")
Trim from both the start and the end of a string, returns a trimmed copy of the string.
Definition: StringUtils.hpp:85
boost::tokenizer< boost::escaped_list_separator< char > > Tokenizer
Definition: CsvReader.cpp:15

◆ Permute()

void Permute ( const armnn::TensorShape dstShape,
const armnn::PermutationVector mappings,
const void *  src,
void *  dst,
size_t  dataTypeSize 
)

◆ Permuted() [1/2]

armnn::TensorShape Permuted ( const armnn::TensorShape srcShape,
const armnn::PermutationVector mappings 
)

Definition at line 98 of file Permute.cpp.

References TensorShape::GetNumDimensions(), PermutationVector::GetSize(), and armnn::MaxNumOfTensorDimensions.

Referenced by armnnTfParser::ConvertTfTensorDataType(), armnn::ConvertWeightTensorInfoFromArmnnToAcl(), PermuteLayer::InferOutputShapes(), Permuted(), PermuteInputsForConcat(), armnn::PermuteTensor(), PermuteTensorData(), PermuteTensorNchwToNhwc(), PermuteTensorNhwcToNchw(), and MovePermuteUpImpl::Run().

99 {
100  assert(srcShape.GetNumDimensions() == mappings.GetSize());
101 
102  const unsigned int numDims = mappings.GetSize();
103  unsigned int outDims[armnn::MaxNumOfTensorDimensions];
104 
105  for (unsigned int i = 0U; i < numDims; ++i)
106  {
107  outDims[mappings[i]] = srcShape[i];
108  }
109 
110  armnn::TensorShape permutedShape(numDims, outDims);
111  return permutedShape;
112 }
SizeType GetSize() const
Definition: Types.hpp:202
unsigned int GetNumDimensions() const
Definition: Tensor.hpp:43
constexpr unsigned int MaxNumOfTensorDimensions
Definition: Types.hpp:18

◆ Permuted() [2/2]

armnn::TensorInfo Permuted ( const armnn::TensorInfo info,
const armnn::PermutationVector mappings 
)

Definition at line 114 of file Permute.cpp.

References TensorInfo::GetShape(), Permuted(), and TensorInfo::SetShape().

115 {
116  armnn::TensorInfo outInfo(info);
117  outInfo.SetShape(Permuted(info.GetShape(), mappings));
118  return outInfo;
119 }
const TensorShape & GetShape() const
Definition: Tensor.hpp:88
armnn::TensorShape Permuted(const armnn::TensorShape &srcShape, const armnn::PermutationVector &mappings)
Definition: Permute.cpp:98

◆ ProcessConcatInputTensorInfo()

void ProcessConcatInputTensorInfo ( armnn::TensorInfo inputTensorInfo,
armnn::OriginsDescriptor concatDescriptor,
const unsigned int &  concatAxis,
unsigned int  inputIndex,
unsigned int &  mergeDimOrigin 
)

Definition at line 19 of file ParserHelper.cpp.

References CHECK_LOCATION, TensorInfo::GetNumDimensions(), OriginsDescriptor::GetNumDimensions(), TensorInfo::GetShape(), and OriginsDescriptor::SetViewOriginCoord().

Referenced by TfLiteParser::OutputShapeOfReshape().

24 {
25  const uint32_t inputRank = concatDescriptor.GetNumDimensions();
26 
27  // double check dimensions of the tensors
28  if (inputTensorInfo.GetNumDimensions() != inputRank)
29  {
31  boost::str(
32  boost::format(
33  "The number of dimensions: %1% for input tensors of the "
34  "concatenation op should be %2% %3%")
35  % inputTensorInfo.GetNumDimensions()
36  % inputRank
37  % CHECK_LOCATION().AsString()));
38  }
39 
40  for (unsigned int j = 0; j < concatAxis; ++j)
41  {
42  concatDescriptor.SetViewOriginCoord(inputIndex, j, 0);
43  }
44 
45  concatDescriptor.SetViewOriginCoord(inputIndex, concatAxis, mergeDimOrigin);
46  mergeDimOrigin += inputTensorInfo.GetShape()[concatAxis];
47 
48  for (unsigned int j = concatAxis + 1; j < inputRank; ++j)
49  {
50  concatDescriptor.SetViewOriginCoord(inputIndex, j, 0);
51  }
52 }
const TensorShape & GetShape() const
Definition: Tensor.hpp:88
#define CHECK_LOCATION()
Definition: Exceptions.hpp:192
uint32_t GetNumDimensions() const
Get the number of dimensions.
unsigned int GetNumDimensions() const
Definition: Tensor.hpp:92
Status SetViewOriginCoord(uint32_t view, uint32_t coord, uint32_t value)
Set the view origin coordinates.

◆ QuantizedVector() [1/3]

std::vector<T> armnnUtils::QuantizedVector ( FloatIt  first,
FloatIt  last,
float  qScale,
int32_t  qOffset 
)

Definition at line 106 of file QuantizeHelper.hpp.

107 {
108  std::vector<T> quantized;
109  quantized.reserve(boost::numeric_cast<size_t>(std::distance(first, last)));
110 
111  for (auto it = first; it != last; ++it)
112  {
113  auto f = *it;
114  T q = SelectiveQuantize<T>(f, qScale, qOffset);
115  quantized.push_back(q);
116  }
117 
118  return quantized;
119 }

◆ QuantizedVector() [2/3]

std::vector<T> armnnUtils::QuantizedVector ( const std::vector< float > &  array,
float  qScale = 1.f,
int32_t  qOffset = 0 
)

Definition at line 122 of file QuantizeHelper.hpp.

123 {
124  return QuantizedVector<T>(array.begin(), array.end(), qScale, qOffset);
125 }

◆ QuantizedVector() [3/3]

std::vector<T> armnnUtils::QuantizedVector ( std::initializer_list< float >  array,
float  qScale = 1.f,
int32_t  qOffset = 0 
)

Definition at line 128 of file QuantizeHelper.hpp.

129 {
130  return QuantizedVector<T>(array.begin(), array.end(), qScale, qOffset);
131 }

◆ SelectiveDequantize()

float armnnUtils::SelectiveDequantize ( value,
float  scale,
int32_t  offset 
)

Definition at line 92 of file QuantizeHelper.hpp.

References SelectiveQuantizer< T, DoQuantize >::Dequantize().

Referenced by ApplyBias().

93 {
94  return SelectiveQuantizer<T, armnn::IsQuantizedType<T>()>::Dequantize(value, scale, offset);
95 };
float Dequantize(QuantizedType value, float scale, int32_t offset)
Dequantize an 8-bit data type into a floating point data type.
Definition: TypesUtils.cpp:47

◆ SelectiveQuantize()

T armnnUtils::SelectiveQuantize ( float  value,
float  scale,
int32_t  offset 
)

Definition at line 86 of file QuantizeHelper.hpp.

References SelectiveQuantizer< T, DoQuantize >::Quantize().

87 {
88  return SelectiveQuantizer<T, armnn::IsQuantizedType<T>()>::Quantize(value, scale, offset);
89 };
QuantizedType Quantize(float value, float scale, int32_t offset)
Quantize a floating point data type into an 8-bit data type.
Definition: TypesUtils.cpp:31

◆ SplitBy()

std::vector< std::string > SplitBy ( const std::string &  originalString,
const std::string &  delimiter = " ",
bool  includeEmptyToken = false 
)

Split a string into tokens by a delimiter.

Parameters
[in]originalStringOriginal string to be split
[in]delimiterDelimiter used to split originalString
[in]includeEmptyToeknIf true, include empty tokens in the result
Returns
A vector of tokens split from originalString by

Definition at line 41 of file ModelAccuracyChecker.cpp.

Referenced by LoadModelOutputLabels(), and main().

42 {
43  std::vector<std::string> tokens;
44  size_t cur = 0;
45  size_t next = 0;
46  while ((next = originalString.find(delimiter, cur)) != std::string::npos)
47  {
48  // Skip empty tokens, unless explicitly stated to include them.
49  if (next - cur > 0 || includeEmptyToken)
50  {
51  tokens.push_back(originalString.substr(cur, next - cur));
52  }
53  cur = next + delimiter.size();
54  }
55  // Get the remaining token
56  // Skip empty tokens, unless explicitly stated to include them.
57  if (originalString.size() - cur > 0 || includeEmptyToken)
58  {
59  tokens.push_back(originalString.substr(cur, originalString.size() - cur));
60  }
61  return tokens;
62 }

◆ Strip()

std::string Strip ( const std::string &  originalString,
const std::string &  characterSet = " " 
)

Remove any preceding and trailing character specified in the characterSet.

Parameters
[in]originalStringOriginal string to be stripped
[in]characterSetSet of characters to be stripped from originalString
Returns
A string stripped of all characters specified in characterSet from originalString

Definition at line 65 of file ModelAccuracyChecker.cpp.

References ARMNN_ASSERT.

Referenced by LoadModelOutputLabels().

66 {
67  ARMNN_ASSERT(!characterSet.empty());
68  const std::size_t firstFound = originalString.find_first_not_of(characterSet);
69  const std::size_t lastFound = originalString.find_last_not_of(characterSet);
70  // Return empty if the originalString is empty or the originalString contains only to-be-striped characters
71  if (firstFound == std::string::npos || lastFound == std::string::npos)
72  {
73  return "";
74  }
75  return originalString.substr(firstFound, lastFound + 1 - firstFound);
76 }
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14

◆ Transpose()

void Transpose ( const armnn::TensorShape dstShape,
const armnn::PermutationVector mappings,
const void *  src,
void *  dst,
size_t  dataTypeSize 
)

Definition at line 120 of file Transpose.cpp.

Referenced by BOOST_AUTO_TEST_CASE(), and TransposeLayer::TransposeLayer().

122 {
123  TransposeLoop(srcShape, mappings).Unroll(src, dst, dataTypeSize);
124 }

◆ TransposeTensorShape() [1/2]

armnn::TensorShape TransposeTensorShape ( const armnn::TensorShape srcShape,
const armnn::PermutationVector mappings 
)

Definition at line 98 of file Transpose.cpp.

References TensorShape::GetNumDimensions(), PermutationVector::GetSize(), and armnn::MaxNumOfTensorDimensions.

Referenced by TransposeLayer::InferOutputShapes(), armnnTfParser::OutputShapeOfExpandDims(), MoveTransposeUpImpl::Run(), and TransposeTensorShape().

99 {
100  assert(srcShape.GetNumDimensions() == mappings.GetSize());
101 
102  const unsigned int numDims = mappings.GetSize();
103  unsigned int outDims[armnn::MaxNumOfTensorDimensions];
104 
105  for (unsigned int i = 0U; i < numDims; ++i)
106  {
107  outDims[i] = srcShape[mappings[i]];
108  }
109  armnn::TensorShape permutedShape(numDims, outDims);
110  return permutedShape;
111 }
SizeType GetSize() const
Definition: Types.hpp:202
unsigned int GetNumDimensions() const
Definition: Tensor.hpp:43
constexpr unsigned int MaxNumOfTensorDimensions
Definition: Types.hpp:18

◆ TransposeTensorShape() [2/2]

armnn::TensorInfo TransposeTensorShape ( const armnn::TensorInfo info,
const armnn::PermutationVector mappings 
)

Definition at line 113 of file Transpose.cpp.

References TensorInfo::GetShape(), TensorInfo::SetShape(), and TransposeTensorShape().

114 {
115  armnn::TensorInfo outInfo(info);
116  outInfo.SetShape(TransposeTensorShape(info.GetShape(), mappings));
117  return outInfo;
118 }
const TensorShape & GetShape() const
Definition: Tensor.hpp:88
armnn::TensorShape TransposeTensorShape(const armnn::TensorShape &srcShape, const armnn::PermutationVector &mappings)
Definition: Transpose.cpp:98

◆ VerifyInt32()

int32_t VerifyInt32 ( const char *  expr,
int64_t  value,
const armnn::CheckLocation location 
)

Definition at line 55 of file VerificationHelpers.cpp.

References CheckLocation::AsString().

58 {
59  if (value < std::numeric_limits<int>::min() || value > std::numeric_limits<int>::max())
60  {
61  throw ParseException(
62  boost::str(
63  boost::format("'%1%' must should fit into a int32 (ArmNN don't support int64), received: %2% at %3%") %
64  expr %
65  value %
66  location.AsString() ));
67  }
68  else
69  {
70  return static_cast<int32_t>(value);
71  }
72 }
std::string AsString() const
Definition: Exceptions.hpp:29

Variable Documentation

◆ ArmNNToNHWC

const armnn::PermutationVector ArmNNToNHWC = { 0, 3, 1, 2 }

Definition at line 17 of file ParserHelper.cpp.

◆ NHWCToArmNN

const armnn::PermutationVector NHWCToArmNN = { 0, 2, 3, 1 }

Definition at line 16 of file ParserHelper.cpp.

Referenced by PrepareImageTensor< float >().