ArmNN
 23.05
TfLiteParserImpl Class Reference

#include <TfLiteParser.hpp>

Public Types

using ModelPtr = std::unique_ptr< tflite::ModelT >
 
using SubgraphPtr = std::unique_ptr< tflite::SubGraphT >
 
using OperatorPtr = std::unique_ptr< tflite::OperatorT >
 
using OperatorCodePtr = std::unique_ptr< tflite::OperatorCodeT >
 
using TensorPtr = std::unique_ptr< tflite::TensorT >
 
using TensorRawPtr = const tflite::TensorT *
 
using TensorRawPtrVector = std::vector< TensorRawPtr >
 
using TensorIdRawPtr = std::pair< size_t, TensorRawPtr >
 
using TensorIdRawPtrVector = std::vector< TensorIdRawPtr >
 
using BufferPtr = std::unique_ptr< tflite::BufferT >
 
using BufferRawPtr = const tflite::BufferT *
 

Public Member Functions

armnn::INetworkPtr CreateNetworkFromBinaryFile (const char *graphFile)
 Create the network from a flatbuffers binary file on disk. More...
 
armnn::INetworkPtr CreateNetworkFromBinary (const std::vector< uint8_t > &binaryContent)
 Create the network from a flatbuffers binary. More...
 
BindingPointInfo GetNetworkInputBindingInfo (size_t subgraphId, const std::string &name) const
 Retrieve binding info (layer id and tensor info) for the network input identified by the given layer name and subgraph id. More...
 
BindingPointInfo GetNetworkOutputBindingInfo (size_t subgraphId, const std::string &name) const
 Retrieve binding info (layer id and tensor info) for the network output identified by the given layer name and subgraph id. More...
 
size_t GetSubgraphCount () const
 Return the number of subgraphs in the parsed model. More...
 
std::vector< std::string > GetSubgraphInputTensorNames (size_t subgraphId) const
 Return the input tensor names for a given subgraph. More...
 
std::vector< std::string > GetSubgraphOutputTensorNames (size_t subgraphId) const
 Return the output tensor names for a given subgraph. More...
 
 TfLiteParserImpl (const armnn::Optional< ITfLiteParser::TfLiteParserOptions > &options=armnn::EmptyOptional())
 
 ~TfLiteParserImpl ()=default
 
armnn::INetworkPtr CreateNetworkFromBinaryAsDynamic (const std::vector< uint8_t > &binaryContent)
 
armnn::INetworkPtr LoadModel (std::unique_ptr< tflite::ModelT > model)
 

Static Public Member Functions

static ModelPtr LoadModelFromFile (const char *fileName)
 
static ModelPtr LoadModelFromBinary (const uint8_t *binaryContent, size_t len)
 
static TensorRawPtrVector GetInputs (const ModelPtr &model, size_t subgraphIndex, size_t operatorIndex)
 
static TensorRawPtrVector GetOutputs (const ModelPtr &model, size_t subgraphIndex, size_t operatorIndex)
 
static TensorIdRawPtrVector GetSubgraphInputs (const ModelPtr &model, size_t subgraphIndex)
 
static TensorIdRawPtrVector GetSubgraphOutputs (const ModelPtr &model, size_t subgraphIndex)
 
static std::vector< int32_t > & GetInputTensorIds (const ModelPtr &model, size_t subgraphIndex, size_t operatorIndex)
 
static std::vector< int32_t > & GetOutputTensorIds (const ModelPtr &model, size_t subgraphIndex, size_t operatorIndex)
 
static BufferRawPtr GetBuffer (const ModelPtr &model, size_t bufferIndex)
 
static armnn::TensorInfo OutputShapeOfSqueeze (std::vector< uint32_t > squeezeDims, const armnn::TensorInfo &inputTensorInfo)
 
static armnn::TensorInfo OutputShapeOfReshape (const armnn::TensorInfo &inputTensorInfo, const std::vector< int32_t > &targetDimsIn)
 
static const std::string GetVersion ()
 Retrieve version in X.Y.Z form. More...
 

Detailed Description

Definition at line 26 of file TfLiteParser.hpp.

Member Typedef Documentation

◆ BufferPtr

using BufferPtr = std::unique_ptr<tflite::BufferT>

Definition at line 39 of file TfLiteParser.hpp.

◆ BufferRawPtr

using BufferRawPtr = const tflite::BufferT *

Definition at line 40 of file TfLiteParser.hpp.

◆ ModelPtr

using ModelPtr = std::unique_ptr<tflite::ModelT>

Definition at line 30 of file TfLiteParser.hpp.

◆ OperatorCodePtr

using OperatorCodePtr = std::unique_ptr<tflite::OperatorCodeT>

Definition at line 33 of file TfLiteParser.hpp.

◆ OperatorPtr

using OperatorPtr = std::unique_ptr<tflite::OperatorT>

Definition at line 32 of file TfLiteParser.hpp.

◆ SubgraphPtr

using SubgraphPtr = std::unique_ptr<tflite::SubGraphT>

Definition at line 31 of file TfLiteParser.hpp.

◆ TensorIdRawPtr

using TensorIdRawPtr = std::pair<size_t, TensorRawPtr>

Definition at line 37 of file TfLiteParser.hpp.

◆ TensorIdRawPtrVector

using TensorIdRawPtrVector = std::vector<TensorIdRawPtr>

Definition at line 38 of file TfLiteParser.hpp.

◆ TensorPtr

using TensorPtr = std::unique_ptr<tflite::TensorT>

Definition at line 34 of file TfLiteParser.hpp.

◆ TensorRawPtr

using TensorRawPtr = const tflite::TensorT *

Definition at line 35 of file TfLiteParser.hpp.

◆ TensorRawPtrVector

using TensorRawPtrVector = std::vector<TensorRawPtr>

Definition at line 36 of file TfLiteParser.hpp.

Constructor & Destructor Documentation

◆ TfLiteParserImpl()

Definition at line 742 of file TfLiteParser.cpp.

743 : m_Options(options)
744 , m_Network(nullptr, nullptr)
745 , m_ParserFunctions(tflite::BuiltinOperator_MAX+1, &TfLiteParserImpl::ParseUnsupportedOperator)
746 {
747  // register supported operators
748  m_ParserFunctions[tflite::BuiltinOperator_ABS] = &TfLiteParserImpl::ParseAbs;
749  m_ParserFunctions[tflite::BuiltinOperator_ADD] = &TfLiteParserImpl::ParseAdd;
750  m_ParserFunctions[tflite::BuiltinOperator_ARG_MIN] = &TfLiteParserImpl::ParseArgMin;
751  m_ParserFunctions[tflite::BuiltinOperator_ARG_MAX] = &TfLiteParserImpl::ParseArgMax;
752  m_ParserFunctions[tflite::BuiltinOperator_AVERAGE_POOL_2D] = &TfLiteParserImpl::ParseAveragePool2D;
753  m_ParserFunctions[tflite::BuiltinOperator_BATCH_TO_SPACE_ND] = &TfLiteParserImpl::ParseBatchToSpaceND;
754  m_ParserFunctions[tflite::BuiltinOperator_BATCH_MATMUL] = &TfLiteParserImpl::ParseBatchMatMul;
755  m_ParserFunctions[tflite::BuiltinOperator_CEIL] = &TfLiteParserImpl::ParseCeil;
756  m_ParserFunctions[tflite::BuiltinOperator_CAST] = &TfLiteParserImpl::ParseCast;
757  m_ParserFunctions[tflite::BuiltinOperator_CONCATENATION] = &TfLiteParserImpl::ParseConcatenation;
758  m_ParserFunctions[tflite::BuiltinOperator_CONV_2D] = &TfLiteParserImpl::ParseConv2D;
759  // Conv3D support was added in TF 2.5, so for backwards compatibility a hash define is needed.
760  #if defined(ARMNN_POST_TFLITE_2_4)
761  m_ParserFunctions[tflite::BuiltinOperator_CONV_3D] = &TfLiteParserImpl::ParseConv3D;
762  #endif
763  m_ParserFunctions[tflite::BuiltinOperator_CUSTOM] = &TfLiteParserImpl::ParseCustomOperator;
764  m_ParserFunctions[tflite::BuiltinOperator_DEPTH_TO_SPACE] = &TfLiteParserImpl::ParseDepthToSpace;
765  m_ParserFunctions[tflite::BuiltinOperator_DEPTHWISE_CONV_2D] = &TfLiteParserImpl::ParseDepthwiseConv2D;
766  m_ParserFunctions[tflite::BuiltinOperator_DEQUANTIZE] = &TfLiteParserImpl::ParseDequantize;
767  m_ParserFunctions[tflite::BuiltinOperator_DIV] = &TfLiteParserImpl::ParseDiv;
768  m_ParserFunctions[tflite::BuiltinOperator_ELU] = &TfLiteParserImpl::ParseElu;
769  m_ParserFunctions[tflite::BuiltinOperator_EQUAL] = &TfLiteParserImpl::ParseEqual;
770  m_ParserFunctions[tflite::BuiltinOperator_EXP] = &TfLiteParserImpl::ParseExp;
771  m_ParserFunctions[tflite::BuiltinOperator_EXPAND_DIMS] = &TfLiteParserImpl::ParseExpandDims;
772  m_ParserFunctions[tflite::BuiltinOperator_FLOOR_DIV] = &TfLiteParserImpl::ParseFloorDiv;
773  m_ParserFunctions[tflite::BuiltinOperator_FULLY_CONNECTED] = &TfLiteParserImpl::ParseFullyConnected;
774  m_ParserFunctions[tflite::BuiltinOperator_GATHER] = &TfLiteParserImpl::ParseGather;
775  m_ParserFunctions[tflite::BuiltinOperator_GATHER_ND] = &TfLiteParserImpl::ParseGatherNd;
776  m_ParserFunctions[tflite::BuiltinOperator_GREATER] = &TfLiteParserImpl::ParseGreater;
777  m_ParserFunctions[tflite::BuiltinOperator_GREATER_EQUAL] = &TfLiteParserImpl::ParseGreaterOrEqual;
778  m_ParserFunctions[tflite::BuiltinOperator_HARD_SWISH] = &TfLiteParserImpl::ParseHardSwish;
779  m_ParserFunctions[tflite::BuiltinOperator_LEAKY_RELU] = &TfLiteParserImpl::ParseLeakyRelu;
780  m_ParserFunctions[tflite::BuiltinOperator_LESS] = &TfLiteParserImpl::ParseLess;
781  m_ParserFunctions[tflite::BuiltinOperator_LESS_EQUAL] = &TfLiteParserImpl::ParseLessOrEqual;
782  m_ParserFunctions[tflite::BuiltinOperator_LOCAL_RESPONSE_NORMALIZATION]
783  = &TfLiteParserImpl::ParseLocalResponseNormalization;
784  m_ParserFunctions[tflite::BuiltinOperator_LOG] = &TfLiteParserImpl::ParseLog;
785  m_ParserFunctions[tflite::BuiltinOperator_LOGICAL_NOT] = &TfLiteParserImpl::ParseLogicalNot;
786  m_ParserFunctions[tflite::BuiltinOperator_LOGISTIC] = &TfLiteParserImpl::ParseLogistic;
787  m_ParserFunctions[tflite::BuiltinOperator_LOG_SOFTMAX] = &TfLiteParserImpl::ParseLogSoftmax;
788  m_ParserFunctions[tflite::BuiltinOperator_L2_NORMALIZATION] = &TfLiteParserImpl::ParseL2Normalization;
789  m_ParserFunctions[tflite::BuiltinOperator_MAX_POOL_2D] = &TfLiteParserImpl::ParseMaxPool2D;
790  m_ParserFunctions[tflite::BuiltinOperator_MAXIMUM] = &TfLiteParserImpl::ParseMaximum;
791  m_ParserFunctions[tflite::BuiltinOperator_MEAN] = &TfLiteParserImpl::ParseMean;
792  m_ParserFunctions[tflite::BuiltinOperator_MINIMUM] = &TfLiteParserImpl::ParseMinimum;
793  m_ParserFunctions[tflite::BuiltinOperator_MIRROR_PAD] = &TfLiteParserImpl::ParseMirrorPad;
794  m_ParserFunctions[tflite::BuiltinOperator_MUL] = &TfLiteParserImpl::ParseMul;
795  m_ParserFunctions[tflite::BuiltinOperator_NEG] = &TfLiteParserImpl::ParseNeg;
796  m_ParserFunctions[tflite::BuiltinOperator_NOT_EQUAL] = &TfLiteParserImpl::ParseNotEqual;
797  m_ParserFunctions[tflite::BuiltinOperator_PACK] = &TfLiteParserImpl::ParsePack;
798  m_ParserFunctions[tflite::BuiltinOperator_PAD] = &TfLiteParserImpl::ParsePad;
799  m_ParserFunctions[tflite::BuiltinOperator_PADV2] = &TfLiteParserImpl::ParsePad;
800  m_ParserFunctions[tflite::BuiltinOperator_PRELU] = &TfLiteParserImpl::ParsePrelu;
801  m_ParserFunctions[tflite::BuiltinOperator_QUANTIZE] = &TfLiteParserImpl::ParseQuantize;
802  m_ParserFunctions[tflite::BuiltinOperator_RELU] = &TfLiteParserImpl::ParseRelu;
803  m_ParserFunctions[tflite::BuiltinOperator_RELU6] = &TfLiteParserImpl::ParseRelu6;
804  m_ParserFunctions[tflite::BuiltinOperator_REDUCE_MAX] = &TfLiteParserImpl::ParseReduceMax;
805  m_ParserFunctions[tflite::BuiltinOperator_REDUCE_MIN] = &TfLiteParserImpl::ParseReduceMin;
806  m_ParserFunctions[tflite::BuiltinOperator_REDUCE_PROD] = &TfLiteParserImpl::ParseReduceProd;
807  m_ParserFunctions[tflite::BuiltinOperator_RESHAPE] = &TfLiteParserImpl::ParseReshape;
808  m_ParserFunctions[tflite::BuiltinOperator_RESIZE_BILINEAR] = &TfLiteParserImpl::ParseResizeBilinear;
809  m_ParserFunctions[tflite::BuiltinOperator_RESIZE_NEAREST_NEIGHBOR] = &TfLiteParserImpl::ParseResizeNearestNeighbor;
810  m_ParserFunctions[tflite::BuiltinOperator_RSQRT] = &TfLiteParserImpl::ParseRsqrt;
811  m_ParserFunctions[tflite::BuiltinOperator_SQRT] = &TfLiteParserImpl::ParseSqrt;
812  m_ParserFunctions[tflite::BuiltinOperator_SHAPE] = &TfLiteParserImpl::ParseShape;
813  m_ParserFunctions[tflite::BuiltinOperator_SIN] = &TfLiteParserImpl::ParseSin;
814  m_ParserFunctions[tflite::BuiltinOperator_SLICE] = &TfLiteParserImpl::ParseSlice;
815  m_ParserFunctions[tflite::BuiltinOperator_SOFTMAX] = &TfLiteParserImpl::ParseSoftmax;
816  m_ParserFunctions[tflite::BuiltinOperator_SPACE_TO_BATCH_ND] = &TfLiteParserImpl::ParseSpaceToBatchND;
817  m_ParserFunctions[tflite::BuiltinOperator_SPACE_TO_DEPTH] = &TfLiteParserImpl::ParseSpaceToDepth;
818  m_ParserFunctions[tflite::BuiltinOperator_SPLIT] = &TfLiteParserImpl::ParseSplit;
819  m_ParserFunctions[tflite::BuiltinOperator_SPLIT_V] = &TfLiteParserImpl::ParseSplitV;
820  m_ParserFunctions[tflite::BuiltinOperator_SQUEEZE] = &TfLiteParserImpl::ParseSqueeze;
821  m_ParserFunctions[tflite::BuiltinOperator_STRIDED_SLICE] = &TfLiteParserImpl::ParseStridedSlice;
822  m_ParserFunctions[tflite::BuiltinOperator_SUB] = &TfLiteParserImpl::ParseSub;
823  m_ParserFunctions[tflite::BuiltinOperator_SUM] = &TfLiteParserImpl::ParseSum;
824  m_ParserFunctions[tflite::BuiltinOperator_TANH] = &TfLiteParserImpl::ParseTanH;
825  m_ParserFunctions[tflite::BuiltinOperator_TRANSPOSE] = &TfLiteParserImpl::ParseTranspose;
826  m_ParserFunctions[tflite::BuiltinOperator_TRANSPOSE_CONV] = &TfLiteParserImpl::ParseTransposeConv;
827  m_ParserFunctions[tflite::BuiltinOperator_UNIDIRECTIONAL_SEQUENCE_LSTM]
828  = &TfLiteParserImpl::ParseUnidirectionalSequenceLSTM;
829  m_ParserFunctions[tflite::BuiltinOperator_UNPACK] = &TfLiteParserImpl::ParseUnpack;
830 
831  // register supported custom operators
832  m_CustomParserFunctions["TFLite_Detection_PostProcess"] = &TfLiteParserImpl::ParseDetectionPostProcess;
833 }

◆ ~TfLiteParserImpl()

~TfLiteParserImpl ( )
default

Member Function Documentation

◆ CreateNetworkFromBinary()

INetworkPtr CreateNetworkFromBinary ( const std::vector< uint8_t > &  binaryContent)

Create the network from a flatbuffers binary.

Definition at line 955 of file TfLiteParser.cpp.

956 {
957  ResetParser();
958  m_Model = LoadModelFromBinary(binaryContent.data(), binaryContent.size());
959  return CreateNetworkFromModel();
960 }

References TfLiteParserImpl::LoadModelFromBinary().

◆ CreateNetworkFromBinaryAsDynamic()

armnn::INetworkPtr CreateNetworkFromBinaryAsDynamic ( const std::vector< uint8_t > &  binaryContent)

◆ CreateNetworkFromBinaryFile()

INetworkPtr CreateNetworkFromBinaryFile ( const char *  graphFile)

Create the network from a flatbuffers binary file on disk.

Definition at line 948 of file TfLiteParser.cpp.

949 {
950  ResetParser();
951  m_Model = LoadModelFromFile(graphFile);
952  return CreateNetworkFromModel();
953 }

References TfLiteParserImpl::LoadModelFromFile().

◆ GetBuffer()

TfLiteParserImpl::BufferRawPtr GetBuffer ( const ModelPtr model,
size_t  bufferIndex 
)
static

Definition at line 5136 of file TfLiteParser.cpp.

5137 {
5138  CHECK_BUFFER(model, bufferIndex);
5139  return model->buffers[bufferIndex].get();
5140 }

References CHECK_BUFFER.

◆ GetInputs()

TfLiteParserImpl::TensorRawPtrVector GetInputs ( const ModelPtr model,
size_t  subgraphIndex,
size_t  operatorIndex 
)
static

Definition at line 4835 of file TfLiteParser.cpp.

4838 {
4839  CHECK_MODEL(model, subgraphIndex, operatorIndex);
4840 
4841  const auto& subgraphPtr = model->subgraphs[subgraphIndex];
4842  const auto& operatorPtr = subgraphPtr->operators[operatorIndex];
4843 
4844  size_t inputCount = operatorPtr->inputs.size();
4845  TensorRawPtrVector result;
4846  for (size_t i = 0; i < inputCount; ++i)
4847  {
4848  // If the input location is -1 then assume input is turned off.
4849  if (operatorPtr->inputs[i] == -1)
4850  {
4851  continue;
4852  }
4853  else
4854  {
4855  uint32_t inputId = CHECKED_NON_NEGATIVE(operatorPtr->inputs[i]);
4856  result.push_back(subgraphPtr->tensors[inputId].get());
4857  }
4858  }
4859  return result;
4860 }

References CHECK_MODEL, and CHECKED_NON_NEGATIVE.

◆ GetInputTensorIds()

std::vector< int32_t > & GetInputTensorIds ( const ModelPtr model,
size_t  subgraphIndex,
size_t  operatorIndex 
)
static

Definition at line 4915 of file TfLiteParser.cpp.

4918 {
4919  CHECK_MODEL(model, subgraphIndex, operatorIndex);
4920  const auto& subgraphPtr = model->subgraphs[subgraphIndex];
4921  const auto& operatorPtr = subgraphPtr->operators[operatorIndex];
4922  return operatorPtr->inputs;
4923 }

References CHECK_MODEL.

◆ GetNetworkInputBindingInfo()

BindingPointInfo GetNetworkInputBindingInfo ( size_t  subgraphId,
const std::string &  name 
) const

Retrieve binding info (layer id and tensor info) for the network input identified by the given layer name and subgraph id.

Definition at line 5314 of file TfLiteParser.cpp.

5316 {
5317  CHECK_SUBGRAPH(m_Model, subgraphId);
5318  auto inputs = GetSubgraphInputs(m_Model, subgraphId);
5319  for (auto const& input : inputs)
5320  {
5321  if (input.second->name == name)
5322  {
5323  auto bindingId = GenerateLayerBindingId(subgraphId, input.first);
5324  auto inputTensorInfo = ToTensorInfo(input.second);
5325  // Input tensors are always treated as constant tensors during network execution.
5326  inputTensorInfo.SetConstant(true);
5327  return std::make_pair(bindingId, inputTensorInfo);
5328  }
5329  }
5330 
5331  std::stringstream bindings;
5332  for (auto const& input : inputs)
5333  {
5334  bindings << "'" << input.second->name << "' ";
5335  }
5336 
5337  throw ParseException(
5338  fmt::format("No input binding found for subgraph:{} and name:{}. "
5339  "Possible inputs are: [{}] {}",
5340  subgraphId,
5341  name,
5342  bindings.str(),
5343  CHECK_LOCATION().AsString()));
5344 }

References CHECK_LOCATION, CHECK_SUBGRAPH, TfLiteParserImpl::GetSubgraphInputs(), TensorInfo::SetConstant(), and armnnDeserializer::ToTensorInfo().

◆ GetNetworkOutputBindingInfo()

BindingPointInfo GetNetworkOutputBindingInfo ( size_t  subgraphId,
const std::string &  name 
) const

Retrieve binding info (layer id and tensor info) for the network output identified by the given layer name and subgraph id.

Definition at line 5346 of file TfLiteParser.cpp.

5348 {
5349  CHECK_SUBGRAPH(m_Model, subgraphId);
5350  auto outputs = GetSubgraphOutputs(m_Model, subgraphId);
5351  for (unsigned int i = 0; i < outputs.size(); ++i)
5352  {
5353  auto const output = outputs[i];
5354  if (output.second->name == name)
5355  {
5356  auto bindingId = GenerateLayerBindingId(subgraphId, output.first);
5357  std::vector<unsigned int> shape = m_OverriddenOutputShapes.size() > 0 ?
5358  m_OverriddenOutputShapes[i] : AsUnsignedVector(output.second->shape);
5359  return std::make_pair(bindingId, ToTensorInfo(output.second, shape));
5360  }
5361  }
5362 
5363  std::stringstream bindings;
5364  for (auto const& output : outputs)
5365  {
5366  bindings << "'" << output.second->name << "' ";
5367  }
5368 
5369  throw ParseException(
5370  fmt::format("No output binding found for subgraph:{} and name:{}. "
5371  "Possible outputs are: [{}] {}",
5372  subgraphId,
5373  name,
5374  bindings.str(),
5375  CHECK_LOCATION().AsString()));
5376 }

References CHECK_LOCATION, CHECK_SUBGRAPH, TfLiteParserImpl::GetSubgraphOutputs(), and armnnDeserializer::ToTensorInfo().

◆ GetOutputs()

TfLiteParserImpl::TensorRawPtrVector GetOutputs ( const ModelPtr model,
size_t  subgraphIndex,
size_t  operatorIndex 
)
static

Definition at line 4862 of file TfLiteParser.cpp.

4865 {
4866  CHECK_MODEL(model, subgraphIndex, operatorIndex);
4867 
4868  const auto& subgraphPtr = model->subgraphs[subgraphIndex];
4869  const auto& operatorPtr = subgraphPtr->operators[operatorIndex];
4870 
4871  size_t outputCount = operatorPtr->outputs.size();
4872  TensorRawPtrVector result(outputCount);
4873  for (size_t i = 0; i < outputCount; ++i)
4874  {
4875  uint32_t outputId = CHECKED_NON_NEGATIVE(operatorPtr->outputs[i]);
4876  CHECK_TENSOR(model, subgraphIndex, outputId);
4877  result[i] = subgraphPtr->tensors[outputId].get();
4878  }
4879  return result;
4880 }

References CHECK_MODEL, CHECK_TENSOR, and CHECKED_NON_NEGATIVE.

◆ GetOutputTensorIds()

std::vector< int32_t > & GetOutputTensorIds ( const ModelPtr model,
size_t  subgraphIndex,
size_t  operatorIndex 
)
static

Definition at line 4925 of file TfLiteParser.cpp.

4928 {
4929  CHECK_MODEL(model, subgraphIndex, operatorIndex);
4930  const auto& subgraphPtr = model->subgraphs[subgraphIndex];
4931  const auto& operatorPtr = subgraphPtr->operators[operatorIndex];
4932  return operatorPtr->outputs;
4933 }

References CHECK_MODEL.

◆ GetSubgraphCount()

size_t GetSubgraphCount ( ) const

Return the number of subgraphs in the parsed model.

Definition at line 5378 of file TfLiteParser.cpp.

5379 {
5380  return m_Model->subgraphs.size();
5381 }

◆ GetSubgraphInputs()

TfLiteParserImpl::TensorIdRawPtrVector GetSubgraphInputs ( const ModelPtr model,
size_t  subgraphIndex 
)
static

Definition at line 4882 of file TfLiteParser.cpp.

4884 {
4885  CHECK_SUBGRAPH(model, subgraphIndex);
4886  const auto& subgraphPtr = model->subgraphs[subgraphIndex];
4887 
4888  size_t inputCount = subgraphPtr->inputs.size();
4889  TensorIdRawPtrVector result(inputCount);
4890  for (size_t i = 0; i < inputCount; ++i)
4891  {
4892  uint32_t inputId = CHECKED_NON_NEGATIVE(subgraphPtr->inputs[i]);
4893  CHECK_TENSOR(model, subgraphIndex, inputId);
4894  result[i] = std::make_pair(inputId, subgraphPtr->tensors[inputId].get());
4895  }
4896  return result;
4897 }

References CHECK_SUBGRAPH, CHECK_TENSOR, and CHECKED_NON_NEGATIVE.

Referenced by TfLiteParserImpl::GetNetworkInputBindingInfo(), and TfLiteParserImpl::GetSubgraphInputTensorNames().

◆ GetSubgraphInputTensorNames()

std::vector< std::string > GetSubgraphInputTensorNames ( size_t  subgraphId) const

Return the input tensor names for a given subgraph.

Definition at line 5383 of file TfLiteParser.cpp.

5384 {
5385  CHECK_SUBGRAPH(m_Model, subgraphId);
5386  auto inputs = GetSubgraphInputs(m_Model, subgraphId);
5387  std::vector<std::string> result;
5388  result.reserve(inputs.size());
5389  for (auto const& input : inputs)
5390  {
5391  result.push_back(input.second->name);
5392  }
5393  return result;
5394 }

References CHECK_SUBGRAPH, and TfLiteParserImpl::GetSubgraphInputs().

◆ GetSubgraphOutputs()

TfLiteParserImpl::TensorIdRawPtrVector GetSubgraphOutputs ( const ModelPtr model,
size_t  subgraphIndex 
)
static

Definition at line 4899 of file TfLiteParser.cpp.

4901 {
4902  CHECK_SUBGRAPH(model, subgraphIndex);
4903  const auto& subgraphPtr = model->subgraphs[subgraphIndex];
4904 
4905  size_t outputCount = subgraphPtr->outputs.size();
4906  TensorIdRawPtrVector result(outputCount);
4907  for (size_t i = 0; i < outputCount; ++i)
4908  {
4909  uint32_t outputId = CHECKED_NON_NEGATIVE(subgraphPtr->outputs[i]);
4910  result[i] = std::make_pair(outputId, subgraphPtr->tensors[outputId].get());
4911  }
4912  return result;
4913 }

References CHECK_SUBGRAPH, and CHECKED_NON_NEGATIVE.

Referenced by TfLiteParserImpl::GetNetworkOutputBindingInfo(), and TfLiteParserImpl::GetSubgraphOutputTensorNames().

◆ GetSubgraphOutputTensorNames()

std::vector< std::string > GetSubgraphOutputTensorNames ( size_t  subgraphId) const

Return the output tensor names for a given subgraph.

Definition at line 5396 of file TfLiteParser.cpp.

5397 {
5398  CHECK_SUBGRAPH(m_Model, subgraphId);
5399  auto outputs = GetSubgraphOutputs(m_Model, subgraphId);
5400  std::vector<std::string> result;
5401  result.reserve(outputs.size());
5402  for (auto const& output : outputs)
5403  {
5404  result.push_back(output.second->name);
5405  }
5406  return result;
5407 }

References CHECK_SUBGRAPH, and TfLiteParserImpl::GetSubgraphOutputs().

◆ GetVersion()

const std::string GetVersion ( )
static

Retrieve version in X.Y.Z form.

Definition at line 5409 of file TfLiteParser.cpp.

5410 {
5411  return TFLITE_PARSER_VERSION;
5412 }

References TFLITE_PARSER_VERSION.

◆ LoadModel()

armnn::INetworkPtr LoadModel ( std::unique_ptr< tflite::ModelT >  model)

Definition at line 963 of file TfLiteParser.cpp.

964 {
965  ResetParser();
966  m_Model = std::move(model);
967 
968  return CreateNetworkFromModel();
969 }

◆ LoadModelFromBinary()

TfLiteParserImpl::ModelPtr LoadModelFromBinary ( const uint8_t *  binaryContent,
size_t  len 
)
static

Definition at line 4816 of file TfLiteParser.cpp.

4817 {
4818  if (binaryContent == nullptr)
4819  {
4820  throw InvalidArgumentException(fmt::format("Invalid (null) binary content {}",
4821  CHECK_LOCATION().AsString()));
4822  }
4823  flatbuffers::Verifier verifier(binaryContent, len);
4824  if (verifier.VerifyBuffer<tflite::Model>() == false)
4825  {
4826  throw ParseException(
4827  fmt::format("Buffer doesn't conform to the expected Tensorflow Lite "
4828  "flatbuffers format. size:{} {}",
4829  len,
4830  CHECK_LOCATION().AsString()));
4831  }
4832  return tflite::UnPackModel(binaryContent);
4833 }

References CHECK_LOCATION.

Referenced by TfLiteParserImpl::CreateNetworkFromBinary(), and TfLiteParserImpl::LoadModelFromFile().

◆ LoadModelFromFile()

TfLiteParserImpl::ModelPtr LoadModelFromFile ( const char *  fileName)
static

Definition at line 4792 of file TfLiteParser.cpp.

4793 {
4794  if (fileName == nullptr)
4795  {
4796  throw InvalidArgumentException(fmt::format("Invalid (null) file name {}",
4797  CHECK_LOCATION().AsString()));
4798  }
4799  std::error_code errorCode;
4800  fs::path pathToFile(fileName);
4801  if (!fs::exists(pathToFile, errorCode))
4802  {
4803  //fmt::format() could not be used here (format error)
4804  std::stringstream msg;
4805  msg << "Cannot find the file (" << fileName << ") errorCode: " << errorCode
4806  << " " << CHECK_LOCATION().AsString();
4807 
4808  throw FileNotFoundException(msg.str());
4809  }
4810  std::ifstream file(fileName, std::ios::binary);
4811  std::string fileContent((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
4812  return LoadModelFromBinary(reinterpret_cast<const uint8_t *>(fileContent.c_str()),
4813  fileContent.size());
4814 }

References CHECK_LOCATION, and TfLiteParserImpl::LoadModelFromBinary().

Referenced by TfLiteParserImpl::CreateNetworkFromBinaryFile().

◆ OutputShapeOfReshape()

armnn::TensorInfo OutputShapeOfReshape ( const armnn::TensorInfo inputTensorInfo,
const std::vector< int32_t > &  targetDimsIn 
)
static

Definition at line 2994 of file TfLiteParser.cpp.

2996 {
2997  std::vector<unsigned int> outputDims(targetDimsIn.begin(), targetDimsIn.end());
2998  const auto stretchDim = std::find(targetDimsIn.begin(), targetDimsIn.end(), -1);
2999 
3000  if (stretchDim != targetDimsIn.end())
3001  {
3002  if (std::find(std::next(stretchDim), targetDimsIn.end(), -1) != targetDimsIn.end())
3003  {
3004  throw ParseException(
3005  fmt::format("At most one component of shape can be -1 {}", CHECK_LOCATION().AsString()));
3006  }
3007 
3008  auto targetNumElements =
3009  armnn::numeric_cast<unsigned int>(
3010  std::accumulate(targetDimsIn.begin(), targetDimsIn.end(), -1, std::multiplies<int32_t>()));
3011 
3012  auto stretchIndex = static_cast<size_t>(std::distance(targetDimsIn.begin(), stretchDim));
3013  outputDims[stretchIndex] = inputTensorInfo.GetNumElements() / targetNumElements;
3014  }
3015 
3016  TensorShape outputShape = TensorShape(static_cast<unsigned int>(outputDims.size()), outputDims.data());
3017 
3018  TensorInfo reshapeInfo = inputTensorInfo;
3019  reshapeInfo.SetShape(outputShape);
3020 
3021  return reshapeInfo;
3022 }

References CHECK_LOCATION, TensorInfo::GetNumElements(), and TensorInfo::SetShape().

◆ OutputShapeOfSqueeze()

armnn::TensorInfo OutputShapeOfSqueeze ( std::vector< uint32_t >  squeezeDims,
const armnn::TensorInfo inputTensorInfo 
)
static

Definition at line 2228 of file TfLiteParser.cpp.

2230 {
2231  CHECK_VALID_SIZE(squeezeDims.size(), 0, 1, 2, 3, 4);
2232  static const uint32_t dimensionSequence[] = { 0, 1, 2, 3 };
2233 
2234  if (inputTensorInfo.GetNumDimensions() > 4)
2235  {
2236  std::stringstream ss;
2237  ss << "Input tensor has unexpected number of dimensions:" << inputTensorInfo.GetNumDimensions()
2238  << " shape:" << inputTensorInfo.GetShape() << " "
2239  << CHECK_LOCATION().AsString();
2240  throw ParseException(ss.str());
2241  }
2242 
2243  if (squeezeDims.empty())
2244  {
2245  squeezeDims.assign(dimensionSequence,
2246  dimensionSequence+inputTensorInfo.GetNumDimensions());
2247  }
2248 
2249  std::vector<uint32_t> outputDims;
2250  for(unsigned int i = 0; i < inputTensorInfo.GetNumDimensions(); i++)
2251  {
2252  bool skipSqueeze = (std::find(squeezeDims.begin(), squeezeDims.end(), i) == squeezeDims.end());
2253  auto currentDimension = inputTensorInfo.GetShape()[i];
2254  if (skipSqueeze || currentDimension != 1)
2255  {
2256  outputDims.push_back(currentDimension);
2257  }
2258  }
2259 
2260  if (outputDims.size() > 4)
2261  {
2262  std::stringstream ss;
2263  ss << "Output tensor has unexpected number of dimensions:" << inputTensorInfo.GetNumDimensions()
2264  << " shape:" << inputTensorInfo.GetShape() << " "
2265  << CHECK_LOCATION().AsString();
2266  throw ParseException(ss.str());
2267  }
2268 
2269  TensorShape outShape = TensorShape(static_cast<unsigned int>(outputDims.size()),
2270  outputDims.data());
2271 
2272  // we need to preserve the tensor type and the quantization data as well
2273  TensorInfo outTensorInfo = inputTensorInfo;
2274  outTensorInfo.SetShape(outShape);
2275 
2276  return outTensorInfo;
2277 }

References CHECK_LOCATION, CHECK_VALID_SIZE, TensorInfo::GetNumDimensions(), TensorInfo::GetShape(), and TensorInfo::SetShape().


The documentation for this class was generated from the following files:
armnnTfLiteParser::TfLiteParserImpl::GetSubgraphOutputs
static TensorIdRawPtrVector GetSubgraphOutputs(const ModelPtr &model, size_t subgraphIndex)
Definition: TfLiteParser.cpp:4899
armnnTfLiteParser::TfLiteParserImpl::LoadModelFromFile
static ModelPtr LoadModelFromFile(const char *fileName)
Definition: TfLiteParser.cpp:4792
CHECK_BUFFER
#define CHECK_BUFFER(MODEL, BUFFER_INDEX)
Definition: TfLiteParser.cpp:260
CHECK_LOCATION
#define CHECK_LOCATION()
Definition: Exceptions.hpp:203
armnn::ParseException
Definition: Exceptions.hpp:92
armnn_driver::Model
::android::nn::Model Model
Helper classes.
Definition: ConversionUtils.hpp:43
CHECK_TENSOR
#define CHECK_TENSOR(MODEL, SUBGRAPH_INDEX, TENSOR_INDEX)
Definition: TfLiteParser.cpp:212
armnn::TensorShape
Definition: Tensor.hpp:20
armnnTfLiteParser::TfLiteParserImpl::LoadModelFromBinary
static ModelPtr LoadModelFromBinary(const uint8_t *binaryContent, size_t len)
Definition: TfLiteParser.cpp:4816
armnn::TensorInfo::GetNumDimensions
unsigned int GetNumDimensions() const
Definition: Tensor.hpp:195
CHECK_SUBGRAPH
#define CHECK_SUBGRAPH(MODEL, SUBGRAPH_INDEX)
Definition: TfLiteParser.cpp:141
armnn::TensorInfo::GetNumElements
unsigned int GetNumElements() const
Definition: Tensor.hpp:196
armnn::TensorInfo
Definition: Tensor.hpp:152
CHECKED_NON_NEGATIVE
#define CHECKED_NON_NEGATIVE(VALUE)
Definition: VerificationHelpers.hpp:35
TFLITE_PARSER_VERSION
#define TFLITE_PARSER_VERSION
TFLITE_PARSER_VERSION: "X.Y.Z" where: X = Major version number Y = Minor version number Z = Patch ver...
Definition: Version.hpp:25
armnn::TensorInfo::GetShape
const TensorShape & GetShape() const
Definition: Tensor.hpp:191
armnnTfLiteParser::TfLiteParserImpl::TensorRawPtrVector
std::vector< TensorRawPtr > TensorRawPtrVector
Definition: TfLiteParser.hpp:36
CHECK_VALID_SIZE
#define CHECK_VALID_SIZE(ACTUAL,...)
Definition: VerificationHelpers.hpp:32
armnn::FileNotFoundException
Definition: Exceptions.hpp:86
armnnTfLiteParser::TfLiteParserImpl::TensorIdRawPtrVector
std::vector< TensorIdRawPtr > TensorIdRawPtrVector
Definition: TfLiteParser.hpp:38
armnnDeserializer::ToTensorInfo
armnn::TensorInfo ToTensorInfo(TensorRawPtr tensorPtr)
Definition: Deserializer.cpp:642
armnnTfLiteParser::TfLiteParserImpl::GetSubgraphInputs
static TensorIdRawPtrVector GetSubgraphInputs(const ModelPtr &model, size_t subgraphIndex)
Definition: TfLiteParser.cpp:4882
armnn::TensorInfo::SetShape
void SetShape(const TensorShape &newShape)
Definition: Tensor.hpp:193
CHECK_MODEL
#define CHECK_MODEL(MODEL, SUBGRAPH_INDEX, OPERATOR_INDEX)
Definition: TfLiteParser.cpp:183
armnn::InvalidArgumentException
Definition: Exceptions.hpp:80