ArmNN
 21.02
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 127 of file InferenceModel.hpp.

Member Typedef Documentation

◆ Params

Definition at line 130 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 132 of file InferenceModel.hpp.

References ARMNN_ASSERT, ARMNN_SCOPED_HEAP_PROFILING, CHECK_LOCATION, BindingPointInfo::m_BindingId, Params::m_InferOutputShape, 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 armnn::numeric_cast().

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

135  {
136  const std::string& modelPath = params.m_ModelPath;
137 
138  // Create a network from a file on disk
139  auto parser(IParser::Create());
140 
141  std::map<std::string, armnn::TensorShape> inputShapes;
142  if (!params.m_InputShapes.empty())
143  {
144  const size_t numInputShapes = params.m_InputShapes.size();
145  const size_t numInputBindings = params.m_InputBindings.size();
146  if (numInputShapes < numInputBindings)
147  {
148  throw armnn::Exception(fmt::format(
149  "Not every input has its tensor shape specified: expected={0}, got={1}",
150  numInputBindings, numInputShapes));
151  }
152 
153  for (size_t i = 0; i < numInputShapes; i++)
154  {
155  inputShapes[params.m_InputBindings[i]] = params.m_InputShapes[i];
156  }
157  }
158 
159  std::vector<std::string> requestedOutputs = params.m_OutputBindings;
160  armnn::INetworkPtr network{nullptr, [](armnn::INetwork *){}};
161 
162  {
163  ARMNN_SCOPED_HEAP_PROFILING("Parsing");
164  // Handle text and binary input differently by calling the corresponding parser function
165  network = (params.m_IsModelBinary ?
166  parser->CreateNetworkFromBinaryFile(modelPath.c_str(), inputShapes, requestedOutputs) :
167  parser->CreateNetworkFromTextFile(modelPath.c_str(), inputShapes, requestedOutputs));
168  }
169 
170  for (const std::string& inputLayerName : params.m_InputBindings)
171  {
172  inputBindings.push_back(parser->GetNetworkInputBindingInfo(inputLayerName));
173  }
174 
175  for (const std::string& outputLayerName : params.m_OutputBindings)
176  {
177  outputBindings.push_back(parser->GetNetworkOutputBindingInfo(outputLayerName));
178  }
179 
180  return network;
181  }
Main network class which provides the interface for building up a neural network. ...
Definition: INetwork.hpp:178
#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:173

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