ArmNN  NotReleased
CreateNetworkImpl< IParser > Struct Template Reference

#include <InferenceModel.hpp>

Public Types

using Params = InferenceModelInternal::Params
 

Static Public Member Functions

static armnn::INetworkPtr Create (const Params &params, std::vector< armnn::BindingPointInfo > &inputBindings, std::vector< armnn::BindingPointInfo > &outputBindings)
 

Detailed Description

template<typename IParser>
struct CreateNetworkImpl< IParser >

Definition at line 111 of file InferenceModel.hpp.

Member Typedef Documentation

◆ Params

Definition at line 114 of file InferenceModel.hpp.

Member Function Documentation

◆ Create()

static armnn::INetworkPtr Create ( const Params params,
std::vector< armnn::BindingPointInfo > &  inputBindings,
std::vector< armnn::BindingPointInfo > &  outputBindings 
)
inlinestatic

Definition at line 116 of file InferenceModel.hpp.

References ARMNN_SCOPED_HEAP_PROFILING, CHECK_LOCATION, BindingPointInfo::m_BindingId, Params::m_InputBindings, Params::m_InputShapes, Params::m_IsModelBinary, Params::m_ModelPath, Params::m_OutputBindings, Params::m_ParseUnsupported, Params::m_SubgraphId, BindingPointInfo::m_TensorInfo, and options.

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

119  {
120  const std::string& modelPath = params.m_ModelPath;
121 
122  // Create a network from a file on disk
123  auto parser(IParser::Create());
124 
125  std::map<std::string, armnn::TensorShape> inputShapes;
126  if (!params.m_InputShapes.empty())
127  {
128  const size_t numInputShapes = params.m_InputShapes.size();
129  const size_t numInputBindings = params.m_InputBindings.size();
130  if (numInputShapes < numInputBindings)
131  {
132  throw armnn::Exception(boost::str(boost::format(
133  "Not every input has its tensor shape specified: expected=%1%, got=%2%")
134  % numInputBindings % numInputShapes));
135  }
136 
137  for (size_t i = 0; i < numInputShapes; i++)
138  {
139  inputShapes[params.m_InputBindings[i]] = params.m_InputShapes[i];
140  }
141  }
142 
143  std::vector<std::string> requestedOutputs = params.m_OutputBindings;
144  armnn::INetworkPtr network{nullptr, [](armnn::INetwork *){}};
145 
146  {
147  ARMNN_SCOPED_HEAP_PROFILING("Parsing");
148  // Handle text and binary input differently by calling the corresponding parser function
149  network = (params.m_IsModelBinary ?
150  parser->CreateNetworkFromBinaryFile(modelPath.c_str(), inputShapes, requestedOutputs) :
151  parser->CreateNetworkFromTextFile(modelPath.c_str(), inputShapes, requestedOutputs));
152  }
153 
154  for (const std::string& inputLayerName : params.m_InputBindings)
155  {
156  inputBindings.push_back(parser->GetNetworkInputBindingInfo(inputLayerName));
157  }
158 
159  for (const std::string& outputLayerName : params.m_OutputBindings)
160  {
161  outputBindings.push_back(parser->GetNetworkOutputBindingInfo(outputLayerName));
162  }
163 
164  return network;
165  }
#define ARMNN_SCOPED_HEAP_PROFILING(TAG)
Base class for all ArmNN exceptions so that users can filter to just those.
Definition: Exceptions.hpp:46
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
Definition: INetwork.hpp:85

The documentation for this struct was generated from the following file: