10 #include <boost/assert.hpp> 11 #include <boost/format.hpp> 12 #include <boost/numeric/conversion/cast.hpp> 14 using namespace armnn;
20 unsigned int numberOfChannels,
28 return TensorShape({numberOfBatches, numberOfChannels, height, width});
30 return TensorShape({numberOfBatches, height, width, numberOfChannels});
33 + std::to_string(static_cast<int>(dataLayout)) +
39 unsigned int numberOfChannels,
48 return TensorInfo({numberOfBatches, numberOfChannels, height, width}, dataType);
50 return TensorInfo({numberOfBatches, height, width, numberOfChannels}, dataType);
53 + std::to_string(static_cast<int>(dataLayout)) +
60 auto tensor_data =
static_cast<const float *
>(tensorHandle->
Map(
true));
64 float min = tensor_data[0];
65 float max = tensor_data[0];
68 for (
unsigned int val = 1; val < tensor_size; val++)
70 if (tensor_data[val] < min)
72 min = tensor_data[val];
74 else if (tensor_data[val] > max)
76 max = tensor_data[val];
80 tensorHandle->
Unmap();
82 return std::make_pair(min, max);
89 if (axis < -boost::numeric_cast<int>(outputDim) || axis > boost::numeric_cast<int>(tensorShape.
GetNumDimensions()))
92 boost::str(boost::format(
"Invalid expansion axis %1% for %2%D input tensor. %3%") %
100 axis = boost::numeric_cast<
int>(outputDim) + axis;
103 std::vector<unsigned int> outputShape;
106 outputShape.push_back(tensorShape[i]);
108 outputShape.insert(outputShape.begin() + axis, 1);
114 const unsigned int firstAxisInclusive,
115 const unsigned int lastAxisExclusive)
117 BOOST_ASSERT(firstAxisInclusive <= lastAxisExclusive);
119 unsigned int count = 1;
120 for (
unsigned int i = firstAxisInclusive; i < lastAxisExclusive; i++)
129 BOOST_ASSERT_MSG(axis < boost::numeric_cast<int>(inputDimension),
130 "Required axis index greater than number of dimensions.");
131 BOOST_ASSERT_MSG(axis >= -boost::numeric_cast<int>(inputDimension),
132 "Required axis index lower than negative of the number of dimensions");
134 unsigned int uAxis = axis < 0 ?
135 inputDimension - boost::numeric_cast<
unsigned int>(
abs(axis))
136 : boost::numeric_cast<unsigned int>(axis);
143 BOOST_ASSERT(axis <= numDim - 1);
144 unsigned int count = 1;
145 for (
unsigned int i = axis; i < numDim; i++)
159 std::string(
"Per-axis quantization params not set for tensor of type ") +
164 return { axisFactor, scales };
armnn::TensorShape GetTensorShape(unsigned int numberOfBatches, unsigned int numberOfChannels, unsigned int height, unsigned int width, const armnn::DataLayout dataLayout)
bool HasPerAxisQuantization() const
unsigned int GetNumDimensions() const
std::pair< float, float > FindMinMax(armnn::ITensorHandle *tensorHandle)
unsigned int GetUnsignedAxis(const unsigned int inputDimension, const int axis)
virtual const void * Map(bool blocking=true) const =0
virtual TensorShape GetShape() const =0
Optional< unsigned int > GetQuantizationDim() const
std::pair< unsigned int, std::vector< float > > GetPerAxisParams(const armnn::TensorInfo &info)
armnn::TensorShape ExpandDims(const armnn::TensorShape &tensorShape, int axis)
unsigned int GetNumElements() const
std::vector< float > GetQuantizationScales() const
virtual void Unmap() const =0
Unmap the tensor data.
DataType GetDataType() const
unsigned int GetNumElementsBetween(const armnn::TensorShape &shape, unsigned int firstAxisInclusive, unsigned int lastAxisExclusive)
const TensorShape & GetShape() const
constexpr const char * GetDataTypeName(DataType dataType)
const TensorInfo & GetTensorInfo(const ITensorHandle *tensorHandle)
float32 helpers
unsigned int GetNumElementsAfter(const armnn::TensorShape &shape, unsigned int axis)