ArmNN
 20.02
Deserializer Class Reference

#include <Deserializer.hpp>

Inheritance diagram for Deserializer:
IDeserializer

Public Types

using ConstTensorRawPtr = const armnnSerializer::ConstTensor *
 
using GraphPtr = const armnnSerializer::SerializedGraph *
 
using TensorRawPtr = const armnnSerializer::TensorInfo *
 
using PoolingDescriptor = const armnnSerializer::Pooling2dDescriptor *
 
using NormalizationDescriptorPtr = const armnnSerializer::NormalizationDescriptor *
 
using LstmDescriptorPtr = const armnnSerializer::LstmDescriptor *
 
using LstmInputParamsPtr = const armnnSerializer::LstmInputParams *
 
using QunatizedLstmInputParamsPtr = const armnnSerializer::QuantizedLstmInputParams *
 
using TensorRawPtrVector = std::vector< TensorRawPtr >
 
using LayerRawPtr = const armnnSerializer::LayerBase *
 
using LayerBaseRawPtr = const armnnSerializer::LayerBase *
 
using LayerBaseRawPtrVector = std::vector< LayerBaseRawPtr >
 

Public Member Functions

armnn::INetworkPtr CreateNetworkFromBinary (const std::vector< uint8_t > &binaryContent) override
 Create an input network from binary file contents. More...
 
armnn::INetworkPtr CreateNetworkFromBinary (std::istream &binaryContent) override
 Create an input network from a binary input stream. More...
 
BindingPointInfo GetNetworkInputBindingInfo (unsigned int layerId, const std::string &name) const override
 Retrieve binding info (layer id and tensor info) for the network input identified by the given layer name. More...
 
BindingPointInfo GetNetworkOutputBindingInfo (unsigned int layerId, const std::string &name) const override
 Retrieve binding info (layer id and tensor info) for the network output identified by the given layer name. More...
 
 Deserializer ()
 
 ~Deserializer ()
 

Static Public Member Functions

static GraphPtr LoadGraphFromBinary (const uint8_t *binaryContent, size_t len)
 
static TensorRawPtrVector GetInputs (const GraphPtr &graph, unsigned int layerIndex)
 
static TensorRawPtrVector GetOutputs (const GraphPtr &graph, unsigned int layerIndex)
 
static LayerBaseRawPtr GetBaseLayer (const GraphPtr &graphPtr, unsigned int layerIndex)
 
static int32_t GetBindingLayerInfo (const GraphPtr &graphPtr, unsigned int layerIndex)
 
static std::string GetLayerName (const GraphPtr &graph, unsigned int index)
 
static armnn::Pooling2dDescriptor GetPoolingDescriptor (PoolingDescriptor pooling2dDescriptor, unsigned int layerIndex)
 
static armnn::NormalizationDescriptor GetNormalizationDescriptor (NormalizationDescriptorPtr normalizationDescriptor, unsigned int layerIndex)
 
static armnn::LstmDescriptor GetLstmDescriptor (LstmDescriptorPtr lstmDescriptor)
 
static armnn::LstmInputParams GetLstmInputParams (LstmDescriptorPtr lstmDescriptor, LstmInputParamsPtr lstmInputParams)
 
static armnn::TensorInfo OutputShapeOfReshape (const armnn::TensorInfo &inputTensorInfo, const std::vector< uint32_t > &targetDimsIn)
 
- Static Public Member Functions inherited from IDeserializer
static IDeserializerCreateRaw ()
 
static IDeserializerPtr Create ()
 
static void Destroy (IDeserializer *parser)
 

Additional Inherited Members

- Protected Member Functions inherited from IDeserializer
virtual ~IDeserializer ()
 

Detailed Description

Definition at line 16 of file Deserializer.hpp.

Member Typedef Documentation

◆ ConstTensorRawPtr

using ConstTensorRawPtr = const armnnSerializer::ConstTensor *

Definition at line 20 of file Deserializer.hpp.

◆ GraphPtr

using GraphPtr = const armnnSerializer::SerializedGraph *

Definition at line 21 of file Deserializer.hpp.

◆ LayerBaseRawPtr

using LayerBaseRawPtr = const armnnSerializer::LayerBase *

Definition at line 30 of file Deserializer.hpp.

◆ LayerBaseRawPtrVector

using LayerBaseRawPtrVector = std::vector<LayerBaseRawPtr>

Definition at line 31 of file Deserializer.hpp.

◆ LayerRawPtr

using LayerRawPtr = const armnnSerializer::LayerBase *

Definition at line 29 of file Deserializer.hpp.

◆ LstmDescriptorPtr

using LstmDescriptorPtr = const armnnSerializer::LstmDescriptor *

Definition at line 25 of file Deserializer.hpp.

◆ LstmInputParamsPtr

using LstmInputParamsPtr = const armnnSerializer::LstmInputParams *

Definition at line 26 of file Deserializer.hpp.

◆ NormalizationDescriptorPtr

using NormalizationDescriptorPtr = const armnnSerializer::NormalizationDescriptor *

Definition at line 24 of file Deserializer.hpp.

◆ PoolingDescriptor

using PoolingDescriptor = const armnnSerializer::Pooling2dDescriptor *

Definition at line 23 of file Deserializer.hpp.

◆ QunatizedLstmInputParamsPtr

using QunatizedLstmInputParamsPtr = const armnnSerializer::QuantizedLstmInputParams *

Definition at line 27 of file Deserializer.hpp.

◆ TensorRawPtr

using TensorRawPtr = const armnnSerializer::TensorInfo *

Definition at line 22 of file Deserializer.hpp.

◆ TensorRawPtrVector

using TensorRawPtrVector = std::vector<TensorRawPtr>

Definition at line 28 of file Deserializer.hpp.

Constructor & Destructor Documentation

◆ Deserializer()

Definition at line 186 of file Deserializer.cpp.

Referenced by IDeserializer::CreateRaw(), and Deserializer::~Deserializer().

187 : m_Network(nullptr, nullptr),
188 //May require LayerType_Max to be included
189 m_ParserFunctions(Layer_MAX+1, &Deserializer::ParseUnsupportedLayer)
190 {
191  // register supported layers
192  m_ParserFunctions[Layer_AbsLayer] = &Deserializer::ParseAbs;
193  m_ParserFunctions[Layer_ActivationLayer] = &Deserializer::ParseActivation;
194  m_ParserFunctions[Layer_AdditionLayer] = &Deserializer::ParseAdd;
195  m_ParserFunctions[Layer_ArgMinMaxLayer] = &Deserializer::ParseArgMinMax;
196  m_ParserFunctions[Layer_BatchToSpaceNdLayer] = &Deserializer::ParseBatchToSpaceNd;
197  m_ParserFunctions[Layer_BatchNormalizationLayer] = &Deserializer::ParseBatchNormalization;
198  m_ParserFunctions[Layer_ComparisonLayer] = &Deserializer::ParseComparison;
199  m_ParserFunctions[Layer_ConcatLayer] = &Deserializer::ParseConcat;
200  m_ParserFunctions[Layer_ConstantLayer] = &Deserializer::ParseConstant;
201  m_ParserFunctions[Layer_Convolution2dLayer] = &Deserializer::ParseConvolution2d;
202  m_ParserFunctions[Layer_DepthToSpaceLayer] = &Deserializer::ParseDepthToSpace;
203  m_ParserFunctions[Layer_DepthwiseConvolution2dLayer] = &Deserializer::ParseDepthwiseConvolution2d;
204  m_ParserFunctions[Layer_DequantizeLayer] = &Deserializer::ParseDequantize;
205  m_ParserFunctions[Layer_DetectionPostProcessLayer] = &Deserializer::ParseDetectionPostProcess;
206  m_ParserFunctions[Layer_DivisionLayer] = &Deserializer::ParseDivision;
207  m_ParserFunctions[Layer_ElementwiseUnaryLayer] = &Deserializer::ParseElementwiseUnary;
208  m_ParserFunctions[Layer_EqualLayer] = &Deserializer::ParseEqual;
209  m_ParserFunctions[Layer_FullyConnectedLayer] = &Deserializer::ParseFullyConnected;
210  m_ParserFunctions[Layer_FloorLayer] = &Deserializer::ParseFloor;
211  m_ParserFunctions[Layer_GatherLayer] = &Deserializer::ParseGather;
212  m_ParserFunctions[Layer_GreaterLayer] = &Deserializer::ParseGreater;
213  m_ParserFunctions[Layer_InstanceNormalizationLayer] = &Deserializer::ParseInstanceNormalization;
214  m_ParserFunctions[Layer_L2NormalizationLayer] = &Deserializer::ParseL2Normalization;
215  m_ParserFunctions[Layer_LogSoftmaxLayer] = &Deserializer::ParseLogSoftmax;
216  m_ParserFunctions[Layer_LstmLayer] = &Deserializer::ParseLstm;
217  m_ParserFunctions[Layer_MaximumLayer] = &Deserializer::ParseMaximum;
218  m_ParserFunctions[Layer_MeanLayer] = &Deserializer::ParseMean;
219  m_ParserFunctions[Layer_MinimumLayer] = &Deserializer::ParseMinimum;
220  m_ParserFunctions[Layer_MergeLayer] = &Deserializer::ParseMerge;
221  m_ParserFunctions[Layer_MergerLayer] = &Deserializer::ParseConcat;
222  m_ParserFunctions[Layer_MultiplicationLayer] = &Deserializer::ParseMultiplication;
223  m_ParserFunctions[Layer_NormalizationLayer] = &Deserializer::ParseNormalization;
224  m_ParserFunctions[Layer_PadLayer] = &Deserializer::ParsePad;
225  m_ParserFunctions[Layer_PermuteLayer] = &Deserializer::ParsePermute;
226  m_ParserFunctions[Layer_Pooling2dLayer] = &Deserializer::ParsePooling2d;
227  m_ParserFunctions[Layer_PreluLayer] = &Deserializer::ParsePrelu;
228  m_ParserFunctions[Layer_QuantizeLayer] = &Deserializer::ParseQuantize;
229  m_ParserFunctions[Layer_QuantizedLstmLayer] = &Deserializer::ParseQuantizedLstm;
230  m_ParserFunctions[Layer_ReshapeLayer] = &Deserializer::ParseReshape;
231  m_ParserFunctions[Layer_ResizeBilinearLayer] = &Deserializer::ParseResizeBilinear;
232  m_ParserFunctions[Layer_ResizeLayer] = &Deserializer::ParseResize;
233  m_ParserFunctions[Layer_RsqrtLayer] = &Deserializer::ParseRsqrt;
234  m_ParserFunctions[Layer_SliceLayer] = &Deserializer::ParseSlice;
235  m_ParserFunctions[Layer_SoftmaxLayer] = &Deserializer::ParseSoftmax;
236  m_ParserFunctions[Layer_SpaceToBatchNdLayer] = &Deserializer::ParseSpaceToBatchNd;
237  m_ParserFunctions[Layer_SpaceToDepthLayer] = &Deserializer::ParseSpaceToDepth;
238  m_ParserFunctions[Layer_SplitterLayer] = &Deserializer::ParseSplitter;
239  m_ParserFunctions[Layer_StackLayer] = &Deserializer::ParseStack;
240  m_ParserFunctions[Layer_StandInLayer] = &Deserializer::ParseStandIn;
241  m_ParserFunctions[Layer_StridedSliceLayer] = &Deserializer::ParseStridedSlice;
242  m_ParserFunctions[Layer_SubtractionLayer] = &Deserializer::ParseSubtraction;
243  m_ParserFunctions[Layer_SwitchLayer] = &Deserializer::ParseSwitch;
244  m_ParserFunctions[Layer_TransposeConvolution2dLayer] = &Deserializer::ParseTransposeConvolution2d;
245  m_ParserFunctions[Layer_TransposeLayer] = &Deserializer::ParseTranspose;
246 }

◆ ~Deserializer()

Member Function Documentation

◆ CreateNetworkFromBinary() [1/2]

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

Create an input network from binary file contents.

Implements IDeserializer.

Definition at line 671 of file Deserializer.cpp.

References Deserializer::LoadGraphFromBinary().

672 {
673  ResetParser();
674  GraphPtr graph = LoadGraphFromBinary(binaryContent.data(), binaryContent.size());
675  return CreateNetworkFromGraph(graph);
676 }
static GraphPtr LoadGraphFromBinary(const uint8_t *binaryContent, size_t len)
const armnnSerializer::SerializedGraph * GraphPtr

◆ CreateNetworkFromBinary() [2/2]

armnn::INetworkPtr CreateNetworkFromBinary ( std::istream &  binaryContent)
overridevirtual

Create an input network from a binary input stream.

Implements IDeserializer.

Definition at line 678 of file Deserializer.cpp.

References Deserializer::LoadGraphFromBinary().

679 {
680  ResetParser();
681  std::vector<uint8_t> content((std::istreambuf_iterator<char>(binaryContent)), std::istreambuf_iterator<char>());
682  GraphPtr graph = LoadGraphFromBinary(content.data(), content.size());
683  return CreateNetworkFromGraph(graph);
684 }
static GraphPtr LoadGraphFromBinary(const uint8_t *binaryContent, size_t len)
const armnnSerializer::SerializedGraph * GraphPtr

◆ GetBaseLayer()

Deserializer::LayerBaseRawPtr GetBaseLayer ( const GraphPtr graphPtr,
unsigned int  layerIndex 
)
static

Definition at line 248 of file Deserializer.cpp.

Referenced by Deserializer::GetInputs(), Deserializer::GetLayerName(), Deserializer::GetNetworkOutputBindingInfo(), Deserializer::GetOutputs(), and Deserializer::~Deserializer().

249 {
250  auto layerType = graphPtr->layers()->Get(layerIndex)->layer_type();
251 
252  switch(layerType)
253  {
254  case Layer::Layer_AbsLayer:
255  return graphPtr->layers()->Get(layerIndex)->layer_as_AbsLayer()->base();
256  case Layer::Layer_ActivationLayer:
257  return graphPtr->layers()->Get(layerIndex)->layer_as_ActivationLayer()->base();
258  case Layer::Layer_AdditionLayer:
259  return graphPtr->layers()->Get(layerIndex)->layer_as_AdditionLayer()->base();
260  case Layer::Layer_ArgMinMaxLayer:
261  return graphPtr->layers()->Get(layerIndex)->layer_as_ArgMinMaxLayer()->base();
262  case Layer::Layer_BatchToSpaceNdLayer:
263  return graphPtr->layers()->Get(layerIndex)->layer_as_BatchToSpaceNdLayer()->base();
264  case Layer::Layer_BatchNormalizationLayer:
265  return graphPtr->layers()->Get(layerIndex)->layer_as_BatchNormalizationLayer()->base();
266  case Layer::Layer_ComparisonLayer:
267  return graphPtr->layers()->Get(layerIndex)->layer_as_ComparisonLayer()->base();
268  case Layer::Layer_ConcatLayer:
269  return graphPtr->layers()->Get(layerIndex)->layer_as_ConcatLayer()->base();
270  case Layer::Layer_ConstantLayer:
271  return graphPtr->layers()->Get(layerIndex)->layer_as_ConstantLayer()->base();
272  case Layer::Layer_Convolution2dLayer:
273  return graphPtr->layers()->Get(layerIndex)->layer_as_Convolution2dLayer()->base();
274  case Layer::Layer_DepthToSpaceLayer:
275  return graphPtr->layers()->Get(layerIndex)->layer_as_DepthToSpaceLayer()->base();
276  case Layer::Layer_DepthwiseConvolution2dLayer:
277  return graphPtr->layers()->Get(layerIndex)->layer_as_DepthwiseConvolution2dLayer()->base();
278  case Layer::Layer_DequantizeLayer:
279  return graphPtr->layers()->Get(layerIndex)->layer_as_DequantizeLayer()->base();
280  case Layer::Layer_DetectionPostProcessLayer:
281  return graphPtr->layers()->Get(layerIndex)->layer_as_DetectionPostProcessLayer()->base();
282  case Layer::Layer_DivisionLayer:
283  return graphPtr->layers()->Get(layerIndex)->layer_as_DivisionLayer()->base();
284  case Layer::Layer_EqualLayer:
285  return graphPtr->layers()->Get(layerIndex)->layer_as_EqualLayer()->base();
286  case Layer::Layer_FullyConnectedLayer:
287  return graphPtr->layers()->Get(layerIndex)->layer_as_FullyConnectedLayer()->base();
288  case Layer::Layer_FloorLayer:
289  return graphPtr->layers()->Get(layerIndex)->layer_as_FloorLayer()->base();
290  case Layer::Layer_GatherLayer:
291  return graphPtr->layers()->Get(layerIndex)->layer_as_GatherLayer()->base();
292  case Layer::Layer_GreaterLayer:
293  return graphPtr->layers()->Get(layerIndex)->layer_as_GreaterLayer()->base();
294  case Layer::Layer_InputLayer:
295  return graphPtr->layers()->Get(layerIndex)->layer_as_InputLayer()->base()->base();
296  case Layer::Layer_InstanceNormalizationLayer:
297  return graphPtr->layers()->Get(layerIndex)->layer_as_InstanceNormalizationLayer()->base();
298  case Layer::Layer_L2NormalizationLayer:
299  return graphPtr->layers()->Get(layerIndex)->layer_as_L2NormalizationLayer()->base();
300  case Layer::Layer_LogSoftmaxLayer:
301  return graphPtr->layers()->Get(layerIndex)->layer_as_LogSoftmaxLayer()->base();
302  case Layer::Layer_LstmLayer:
303  return graphPtr->layers()->Get(layerIndex)->layer_as_LstmLayer()->base();
304  case Layer::Layer_MeanLayer:
305  return graphPtr->layers()->Get(layerIndex)->layer_as_MeanLayer()->base();
306  case Layer::Layer_MinimumLayer:
307  return graphPtr->layers()->Get(layerIndex)->layer_as_MinimumLayer()->base();
308  case Layer::Layer_MaximumLayer:
309  return graphPtr->layers()->Get(layerIndex)->layer_as_MaximumLayer()->base();
310  case Layer::Layer_MergeLayer:
311  return graphPtr->layers()->Get(layerIndex)->layer_as_MergeLayer()->base();
312  case Layer::Layer_MergerLayer:
313  return graphPtr->layers()->Get(layerIndex)->layer_as_MergerLayer()->base();
314  case Layer::Layer_MultiplicationLayer:
315  return graphPtr->layers()->Get(layerIndex)->layer_as_MultiplicationLayer()->base();
316  case Layer::Layer_NormalizationLayer:
317  return graphPtr->layers()->Get(layerIndex)->layer_as_NormalizationLayer()->base();
318  case Layer::Layer_OutputLayer:
319  return graphPtr->layers()->Get(layerIndex)->layer_as_OutputLayer()->base()->base();
320  case Layer::Layer_PadLayer:
321  return graphPtr->layers()->Get(layerIndex)->layer_as_PadLayer()->base();
322  case Layer::Layer_PermuteLayer:
323  return graphPtr->layers()->Get(layerIndex)->layer_as_PermuteLayer()->base();
324  case Layer::Layer_Pooling2dLayer:
325  return graphPtr->layers()->Get(layerIndex)->layer_as_Pooling2dLayer()->base();
326  case Layer::Layer_PreluLayer:
327  return graphPtr->layers()->Get(layerIndex)->layer_as_PreluLayer()->base();
328  case Layer::Layer_QuantizeLayer:
329  return graphPtr->layers()->Get(layerIndex)->layer_as_QuantizeLayer()->base();
330  case Layer::Layer_QuantizedLstmLayer:
331  return graphPtr->layers()->Get(layerIndex)->layer_as_QuantizedLstmLayer()->base();
332  case Layer::Layer_ReshapeLayer:
333  return graphPtr->layers()->Get(layerIndex)->layer_as_ReshapeLayer()->base();
334  case Layer::Layer_ResizeBilinearLayer:
335  return graphPtr->layers()->Get(layerIndex)->layer_as_ResizeBilinearLayer()->base();
336  case Layer::Layer_ResizeLayer:
337  return graphPtr->layers()->Get(layerIndex)->layer_as_ResizeLayer()->base();
338  case Layer::Layer_RsqrtLayer:
339  return graphPtr->layers()->Get(layerIndex)->layer_as_RsqrtLayer()->base();
340  case Layer::Layer_SliceLayer:
341  return graphPtr->layers()->Get(layerIndex)->layer_as_SliceLayer()->base();
342  case Layer::Layer_SoftmaxLayer:
343  return graphPtr->layers()->Get(layerIndex)->layer_as_SoftmaxLayer()->base();
344  case Layer::Layer_SpaceToBatchNdLayer:
345  return graphPtr->layers()->Get(layerIndex)->layer_as_SpaceToBatchNdLayer()->base();
346  case Layer::Layer_SpaceToDepthLayer:
347  return graphPtr->layers()->Get(layerIndex)->layer_as_SpaceToDepthLayer()->base();
348  case Layer::Layer_SplitterLayer:
349  return graphPtr->layers()->Get(layerIndex)->layer_as_SplitterLayer()->base();
350  case Layer::Layer_StackLayer:
351  return graphPtr->layers()->Get(layerIndex)->layer_as_StackLayer()->base();
352  case Layer::Layer_StandInLayer:
353  return graphPtr->layers()->Get(layerIndex)->layer_as_StandInLayer()->base();
354  case Layer::Layer_StridedSliceLayer:
355  return graphPtr->layers()->Get(layerIndex)->layer_as_StridedSliceLayer()->base();
356  case Layer::Layer_SubtractionLayer:
357  return graphPtr->layers()->Get(layerIndex)->layer_as_SubtractionLayer()->base();
358  case Layer::Layer_SwitchLayer:
359  return graphPtr->layers()->Get(layerIndex)->layer_as_SwitchLayer()->base();
360  case Layer::Layer_TransposeConvolution2dLayer:
361  return graphPtr->layers()->Get(layerIndex)->layer_as_TransposeConvolution2dLayer()->base();
362  case Layer::Layer_TransposeLayer:
363  return graphPtr->layers()->Get(layerIndex)->layer_as_TransposeLayer()->base();
364  case Layer::Layer_NONE:
365  default:
366  throw ParseException(boost::str(
367  boost::format("Layer type %1% not recognized") %
368  layerType));
369  }
370 }

◆ GetBindingLayerInfo()

int32_t GetBindingLayerInfo ( const GraphPtr graphPtr,
unsigned int  layerIndex 
)
static

Definition at line 379 of file Deserializer.cpp.

Referenced by Deserializer::GetNetworkOutputBindingInfo(), and Deserializer::~Deserializer().

380 {
381  auto layerType = graphPtr->layers()->Get(layerIndex)->layer_type();
382 
383  if (layerType == Layer::Layer_InputLayer)
384  {
385  return graphPtr->layers()->Get(layerIndex)->layer_as_InputLayer()->base()->layerBindingId();
386  }
387  else if ( layerType == Layer::Layer_OutputLayer )
388  {
389  return graphPtr->layers()->Get(layerIndex)->layer_as_OutputLayer()->base()->layerBindingId();
390  }
391  return 0;
392 }

◆ GetInputs()

Deserializer::TensorRawPtrVector GetInputs ( const GraphPtr graph,
unsigned int  layerIndex 
)
static

Definition at line 601 of file Deserializer.cpp.

References CHECK_LAYERS, CHECKED_NON_NEGATIVE, and Deserializer::GetBaseLayer().

Referenced by Deserializer::GetLstmDescriptor(), Deserializer::GetNetworkOutputBindingInfo(), Deserializer::GetNormalizationDescriptor(), armnnDeserializer::GetOriginsDescriptor(), Deserializer::GetPoolingDescriptor(), Deserializer::OutputShapeOfReshape(), and Deserializer::~Deserializer().

603 {
604  CHECK_LAYERS(graphPtr, 0, layerIndex);
605  auto layer = GetBaseLayer(graphPtr, layerIndex);
606  const auto& numInputs = layer->inputSlots()->size();
607 
608  TensorRawPtrVector result(numInputs);
609 
610  for (unsigned int i=0; i<numInputs; ++i)
611  {
612  auto inputId = CHECKED_NON_NEGATIVE(static_cast<int32_t>
613  (layer->inputSlots()->Get(i)->connection()->sourceLayerIndex()));
614  result[i] = GetBaseLayer(graphPtr, inputId)->outputSlots()->Get(0)->tensorInfo();
615  }
616  return result;
617 }
#define CHECK_LAYERS(GRAPH, LAYERS_INDEX, LAYER_INDEX)
static LayerBaseRawPtr GetBaseLayer(const GraphPtr &graphPtr, unsigned int layerIndex)
#define CHECKED_NON_NEGATIVE(VALUE)
std::vector< TensorRawPtr > TensorRawPtrVector

◆ GetLayerName()

std::string GetLayerName ( const GraphPtr graph,
unsigned int  index 
)
static

Definition at line 372 of file Deserializer.cpp.

References Deserializer::GetBaseLayer().

Referenced by Deserializer::GetLstmDescriptor(), Deserializer::GetNetworkOutputBindingInfo(), Deserializer::GetNormalizationDescriptor(), armnnDeserializer::GetOriginsDescriptor(), Deserializer::GetPoolingDescriptor(), Deserializer::OutputShapeOfReshape(), and Deserializer::~Deserializer().

373 {
374  auto layer = GetBaseLayer(graph, index);
375  assert(layer);
376  return layer->layerName()->str();
377 }
static LayerBaseRawPtr GetBaseLayer(const GraphPtr &graphPtr, unsigned int layerIndex)

◆ GetLstmDescriptor()

armnn::LstmDescriptor GetLstmDescriptor ( Deserializer::LstmDescriptorPtr  lstmDescriptor)
static

Definition at line 2465 of file Deserializer.cpp.

References CHECK_LAYERS, CHECK_LOCATION, CHECK_VALID_SIZE, Deserializer::GetInputs(), Deserializer::GetLayerName(), Deserializer::GetOutputs(), IConnectableLayer::GetOutputSlot(), TensorInfo::GetShape(), LstmDescriptor::m_ActivationFunc, TransposeConvolution2dDescriptor::m_BiasEnabled, QuantizedLstmInputParams::m_CellBias, LstmInputParams::m_CellBias, LstmInputParams::m_CellLayerNormWeights, LstmInputParams::m_CellToForgetWeights, LstmInputParams::m_CellToInputWeights, LstmInputParams::m_CellToOutputWeights, LstmDescriptor::m_CifgEnabled, LstmDescriptor::m_ClippingThresCell, LstmDescriptor::m_ClippingThresProj, TransposeConvolution2dDescriptor::m_DataLayout, QuantizedLstmInputParams::m_ForgetGateBias, LstmInputParams::m_ForgetGateBias, LstmInputParams::m_ForgetLayerNormWeights, QuantizedLstmInputParams::m_InputGateBias, LstmInputParams::m_InputGateBias, LstmInputParams::m_InputLayerNormWeights, QuantizedLstmInputParams::m_InputToCellWeights, LstmInputParams::m_InputToCellWeights, QuantizedLstmInputParams::m_InputToForgetWeights, LstmInputParams::m_InputToForgetWeights, QuantizedLstmInputParams::m_InputToInputWeights, LstmInputParams::m_InputToInputWeights, QuantizedLstmInputParams::m_InputToOutputWeights, LstmInputParams::m_InputToOutputWeights, LstmDescriptor::m_LayerNormEnabled, StandInDescriptor::m_NumInputs, StandInDescriptor::m_NumOutputs, QuantizedLstmInputParams::m_OutputGateBias, LstmInputParams::m_OutputGateBias, LstmInputParams::m_OutputLayerNormWeights, TransposeConvolution2dDescriptor::m_PadBottom, TransposeConvolution2dDescriptor::m_PadLeft, TransposeConvolution2dDescriptor::m_PadRight, TransposeConvolution2dDescriptor::m_PadTop, LstmDescriptor::m_PeepholeEnabled, LstmInputParams::m_ProjectionBias, LstmDescriptor::m_ProjectionEnabled, LstmInputParams::m_ProjectionWeights, QuantizedLstmInputParams::m_RecurrentToCellWeights, LstmInputParams::m_RecurrentToCellWeights, QuantizedLstmInputParams::m_RecurrentToForgetWeights, LstmInputParams::m_RecurrentToForgetWeights, QuantizedLstmInputParams::m_RecurrentToInputWeights, LstmInputParams::m_RecurrentToInputWeights, QuantizedLstmInputParams::m_RecurrentToOutputWeights, LstmInputParams::m_RecurrentToOutputWeights, TransposeConvolution2dDescriptor::m_StrideX, TransposeConvolution2dDescriptor::m_StrideY, IOutputSlot::SetTensorInfo(), armnnDeserializer::ToConstTensor(), armnnDeserializer::ToDataLayout(), and armnnDeserializer::ToTensorInfo().

Referenced by Deserializer::~Deserializer().

2466 {
2467  armnn::LstmDescriptor desc;
2468 
2469  desc.m_ActivationFunc = lstmDescriptor->activationFunc();
2470  desc.m_ClippingThresCell = lstmDescriptor->clippingThresCell();
2471  desc.m_ClippingThresProj = lstmDescriptor->clippingThresProj();
2472  desc.m_CifgEnabled = lstmDescriptor->cifgEnabled();
2473  desc.m_PeepholeEnabled = lstmDescriptor->peepholeEnabled();
2474  desc.m_ProjectionEnabled = lstmDescriptor->projectionEnabled();
2475  desc.m_LayerNormEnabled = lstmDescriptor->layerNormEnabled();
2476 
2477  return desc;
2478 }
bool m_ProjectionEnabled
Enable/disable the projection layer.
float m_ClippingThresProj
Clipping threshold value for the projection.
An LstmDescriptor for the LstmLayer.
bool m_PeepholeEnabled
Enable/disable peephole.
uint32_t m_ActivationFunc
The activation function to use.
float m_ClippingThresCell
Clipping threshold value for the cell state.
bool m_CifgEnabled
Enable/disable cifg (coupled input & forget gate).
bool m_LayerNormEnabled
Enable/disable layer normalization.

◆ GetLstmInputParams()

static armnn::LstmInputParams GetLstmInputParams ( LstmDescriptorPtr  lstmDescriptor,
LstmInputParamsPtr  lstmInputParams 
)
static

◆ GetNetworkInputBindingInfo()

BindingPointInfo GetNetworkInputBindingInfo ( unsigned int  layerId,
const std::string &  name 
) const
overridevirtual

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

Implements IDeserializer.

Definition at line 746 of file Deserializer.cpp.

References CHECK_LOCATION, and armnn::IgnoreUnused().

748 {
749  IgnoreUnused(layerIndex);
750  for (auto inputBinding : m_InputBindings)
751  {
752  if (inputBinding.first == name)
753  {
754  return inputBinding.second;
755  }
756  }
757  throw ParseException(
758  boost::str(
759  boost::format("No input binding found for layer:%1% / %2%") %
760  name %
761  CHECK_LOCATION().AsString()));
762 }
void IgnoreUnused(Ts &&...)
#define CHECK_LOCATION()
Definition: Exceptions.hpp:192

◆ GetNetworkOutputBindingInfo()

BindingPointInfo GetNetworkOutputBindingInfo ( unsigned int  layerId,
const std::string &  name 
) const
overridevirtual

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

Implements IDeserializer.

Definition at line 764 of file Deserializer.cpp.

References armnn::Abs, anchors(), CHECK_GRAPH, CHECK_LAYERS, CHECK_LOCATION, CHECK_VALID_SIZE, armnn::Equal, Deserializer::GetBaseLayer(), Deserializer::GetBindingLayerInfo(), Deserializer::GetInputs(), IConnectableLayer::GetInputSlot(), Deserializer::GetLayerName(), IConnectableLayer::GetNumInputSlots(), IConnectableLayer::GetNumOutputSlots(), Deserializer::GetOutputs(), IConnectableLayer::GetOutputSlot(), armnn::Greater, armnn::IgnoreUnused(), ActivationDescriptor::m_A, ArgMinMaxDescriptor::m_Axis, ActivationDescriptor::m_B, SoftmaxDescriptor::m_Beta, InstanceNormalizationDescriptor::m_Beta, Convolution2dDescriptor::m_BiasEnabled, DepthwiseConvolution2dDescriptor::m_BiasEnabled, BatchToSpaceNdDescriptor::m_BlockShape, SpaceToDepthDescriptor::m_BlockSize, BatchToSpaceNdDescriptor::m_Crops, Convolution2dDescriptor::m_DataLayout, DepthwiseConvolution2dDescriptor::m_DataLayout, L2NormalizationDescriptor::m_DataLayout, BatchNormalizationDescriptor::m_DataLayout, InstanceNormalizationDescriptor::m_DataLayout, BatchToSpaceNdDescriptor::m_DataLayout, SpaceToDepthDescriptor::m_DataLayout, DetectionPostProcessDescriptor::m_DetectionsPerClass, Convolution2dDescriptor::m_DilationX, DepthwiseConvolution2dDescriptor::m_DilationX, Convolution2dDescriptor::m_DilationY, DepthwiseConvolution2dDescriptor::m_DilationY, L2NormalizationDescriptor::m_Eps, BatchNormalizationDescriptor::m_Eps, InstanceNormalizationDescriptor::m_Eps, ActivationDescriptor::m_Function, ArgMinMaxDescriptor::m_Function, InstanceNormalizationDescriptor::m_Gamma, DetectionPostProcessDescriptor::m_MaxClassesPerDetection, DetectionPostProcessDescriptor::m_MaxDetections, DetectionPostProcessDescriptor::m_NmsIouThreshold, DetectionPostProcessDescriptor::m_NmsScoreThreshold, DetectionPostProcessDescriptor::m_NumClasses, Convolution2dDescriptor::m_PadBottom, DepthwiseConvolution2dDescriptor::m_PadBottom, Convolution2dDescriptor::m_PadLeft, DepthwiseConvolution2dDescriptor::m_PadLeft, Convolution2dDescriptor::m_PadRight, DepthwiseConvolution2dDescriptor::m_PadRight, Convolution2dDescriptor::m_PadTop, DepthwiseConvolution2dDescriptor::m_PadTop, DetectionPostProcessDescriptor::m_ScaleH, DetectionPostProcessDescriptor::m_ScaleW, DetectionPostProcessDescriptor::m_ScaleX, DetectionPostProcessDescriptor::m_ScaleY, Convolution2dDescriptor::m_StrideX, DepthwiseConvolution2dDescriptor::m_StrideX, Convolution2dDescriptor::m_StrideY, DepthwiseConvolution2dDescriptor::m_StrideY, DetectionPostProcessDescriptor::m_UseRegularNms, armnn::numeric_cast(), IOutputSlot::SetTensorInfo(), armnnDeserializer::ToActivationFunction(), armnnDeserializer::ToArgMinMaxFunction(), armnnDeserializer::ToConstTensor(), armnnDeserializer::ToDataLayout(), and armnnDeserializer::ToTensorInfo().

766 {
767  IgnoreUnused(layerIndex);
768  for (auto outputBinding : m_OutputBindings)
769  {
770  if (outputBinding.first == name)
771  {
772  return outputBinding.second;
773  }
774  }
775  throw ParseException(
776  boost::str(
777  boost::format("No output binding found for layer:%1% / %2%") %
778  name %
779  CHECK_LOCATION().AsString()));
780 }
void IgnoreUnused(Ts &&...)
#define CHECK_LOCATION()
Definition: Exceptions.hpp:192

◆ GetNormalizationDescriptor()

armnn::NormalizationDescriptor GetNormalizationDescriptor ( Deserializer::NormalizationDescriptorPtr  normalizationDescriptor,
unsigned int  layerIndex 
)
static

Definition at line 2159 of file Deserializer.cpp.

References armnn::Across, CHECK_LAYERS, CHECK_LOCATION, CHECK_VALID_SIZE, Deserializer::GetInputs(), Deserializer::GetLayerName(), Deserializer::GetOutputs(), IConnectableLayer::GetOutputSlot(), armnn::IgnoreUnused(), armnn::LocalBrightness, armnn::LocalContrast, NormalizationDescriptor::m_Alpha, MeanDescriptor::m_Axis, SliceDescriptor::m_Begin, NormalizationDescriptor::m_Beta, NormalizationDescriptor::m_DataLayout, NormalizationDescriptor::m_K, MeanDescriptor::m_KeepDims, NormalizationDescriptor::m_NormChannelType, NormalizationDescriptor::m_NormMethodType, NormalizationDescriptor::m_NormSize, SliceDescriptor::m_Size, armnn::NCHW, armnn::NHWC, armnn::Rsqrt, IOutputSlot::SetTensorInfo(), ViewsDescriptor::SetViewOriginCoord(), ViewsDescriptor::SetViewSize(), armnnDeserializer::ToDataLayout(), armnnDeserializer::ToTensorInfo(), and armnn::Within.

Referenced by Deserializer::~Deserializer().

2162 {
2163  IgnoreUnused(layerIndex);
2165 
2166  switch (normalizationDescriptor->normChannelType())
2167  {
2168  case NormalizationAlgorithmChannel_Across:
2169  {
2171  break;
2172  }
2173  case NormalizationAlgorithmChannel_Within:
2174  {
2176  break;
2177  }
2178  default:
2179  {
2180  BOOST_ASSERT_MSG(false, "Unsupported normalization channel type");
2181  }
2182  }
2183 
2184  switch (normalizationDescriptor->normMethodType())
2185  {
2186  case NormalizationAlgorithmMethod_LocalBrightness:
2187  {
2189  break;
2190  }
2191  case NormalizationAlgorithmMethod_LocalContrast:
2192  {
2194  break;
2195  }
2196  default:
2197  {
2198  BOOST_ASSERT_MSG(false, "Unsupported normalization method type");
2199  }
2200  }
2201 
2202  switch (normalizationDescriptor->dataLayout())
2203  {
2204  case DataLayout_NCHW:
2205  {
2207  break;
2208  }
2209  case DataLayout_NHWC:
2210  {
2212  break;
2213  }
2214  default:
2215  {
2216  BOOST_ASSERT_MSG(false, "Unsupported data layout");
2217  }
2218  }
2219 
2220  desc.m_Alpha = normalizationDescriptor->alpha();
2221  desc.m_Beta = normalizationDescriptor->beta();
2222  desc.m_K = normalizationDescriptor->k();
2223  desc.m_NormSize = normalizationDescriptor->normSize();
2224 
2225  return desc;
2226 }
float m_K
Kappa value used for the across channel normalization equation.
float m_Alpha
Alpha value for the normalization equation.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
void IgnoreUnused(Ts &&...)
NormalizationAlgorithmMethod m_NormMethodType
Normalization method algorithm to use (LocalBrightness, LocalContrast).
NormalizationAlgorithmChannel m_NormChannelType
Normalization channel algorithm to use (Across, Within).
Jarret 2009: Local Contrast Normalization.
Krichevsky 2012: Local Brightness Normalization.
A NormalizationDescriptor for the NormalizationLayer.
float m_Beta
Beta value for the normalization equation.
uint32_t m_NormSize
Depth radius value.

◆ GetOutputs()

Deserializer::TensorRawPtrVector GetOutputs ( const GraphPtr graph,
unsigned int  layerIndex 
)
static

Definition at line 619 of file Deserializer.cpp.

References CHECK_LAYERS, CHECK_LOCATION, and Deserializer::GetBaseLayer().

Referenced by Deserializer::GetLstmDescriptor(), Deserializer::GetNetworkOutputBindingInfo(), Deserializer::GetNormalizationDescriptor(), armnnDeserializer::GetOriginsDescriptor(), Deserializer::GetPoolingDescriptor(), Deserializer::OutputShapeOfReshape(), and Deserializer::~Deserializer().

621 {
622  CHECK_LAYERS(graphPtr, 0, layerIndex);
623  auto layer = GetBaseLayer(graphPtr, layerIndex);
624  const auto& numOutputs = layer->outputSlots()->size();
625 
626  TensorRawPtrVector result(numOutputs);
627 
628  for (unsigned int i=0; i<numOutputs; ++i)
629  {
630  result[i] = layer->outputSlots()->Get(i)->tensorInfo();
631  }
632  return result;
633 }
#define CHECK_LAYERS(GRAPH, LAYERS_INDEX, LAYER_INDEX)
static LayerBaseRawPtr GetBaseLayer(const GraphPtr &graphPtr, unsigned int layerIndex)
std::vector< TensorRawPtr > TensorRawPtrVector

◆ GetPoolingDescriptor()

armnn::Pooling2dDescriptor GetPoolingDescriptor ( Deserializer::PoolingDescriptor  pooling2dDesc,
unsigned int  layerIndex 
)
static

Definition at line 1808 of file Deserializer.cpp.

References armnn::Average, armnn::Ceiling, CHECK_LAYERS, CHECK_VALID_SIZE, armnn::Exclude, armnn::Floor, Deserializer::GetInputs(), Deserializer::GetLayerName(), Deserializer::GetOutputs(), IConnectableLayer::GetOutputSlot(), armnn::IgnoreUnused(), armnn::IgnoreValue, Pooling2dDescriptor::m_DataLayout, Pooling2dDescriptor::m_OutputShapeRounding, Pooling2dDescriptor::m_PadBottom, Pooling2dDescriptor::m_PaddingMethod, Pooling2dDescriptor::m_PadLeft, Pooling2dDescriptor::m_PadRight, Pooling2dDescriptor::m_PadTop, Pooling2dDescriptor::m_PoolHeight, Pooling2dDescriptor::m_PoolType, Pooling2dDescriptor::m_PoolWidth, Pooling2dDescriptor::m_StrideX, Pooling2dDescriptor::m_StrideY, armnn::Max, armnn::NCHW, armnn::NHWC, IOutputSlot::SetTensorInfo(), and armnnDeserializer::ToTensorInfo().

Referenced by Deserializer::~Deserializer().

1810 {
1811  IgnoreUnused(layerIndex);
1813 
1814  switch (pooling2dDesc->poolType())
1815  {
1816  case PoolingAlgorithm_Average:
1817  {
1819  break;
1820  }
1821  case PoolingAlgorithm_Max:
1822  {
1824  break;
1825  }
1826  default:
1827  {
1828  BOOST_ASSERT_MSG(false, "Unsupported pooling algorithm");
1829  }
1830  }
1831 
1832  switch (pooling2dDesc->outputShapeRounding())
1833  {
1834  case OutputShapeRounding_Floor:
1835  {
1837  break;
1838  }
1839  case OutputShapeRounding_Ceiling:
1840  {
1842  break;
1843  }
1844  default:
1845  {
1846  BOOST_ASSERT_MSG(false, "Unsupported output shape rounding");
1847  }
1848  }
1849 
1850  switch (pooling2dDesc->paddingMethod())
1851  {
1852  case PaddingMethod_Exclude:
1853  {
1855  break;
1856  }
1857  case PaddingMethod_IgnoreValue:
1858  {
1860  break;
1861  }
1862  default:
1863  {
1864  BOOST_ASSERT_MSG(false, "Unsupported padding method");
1865  }
1866  }
1867 
1868  switch (pooling2dDesc->dataLayout())
1869  {
1870  case DataLayout_NCHW:
1871  {
1873  break;
1874  }
1875  case DataLayout_NHWC:
1876  {
1878  break;
1879  }
1880  default:
1881  {
1882  BOOST_ASSERT_MSG(false, "Unsupported data layout");
1883  }
1884  }
1885 
1886  desc.m_PadRight = pooling2dDesc->padRight();
1887  desc.m_PadLeft = pooling2dDesc->padLeft();
1888  desc.m_PadBottom = pooling2dDesc->padBottom();
1889  desc.m_PadTop = pooling2dDesc->padTop();
1890  desc.m_StrideX = pooling2dDesc->strideX();
1891  desc.m_StrideY = pooling2dDesc->strideY();
1892  desc.m_PoolWidth = pooling2dDesc->poolWidth();
1893  desc.m_PoolHeight = pooling2dDesc->poolHeight();
1894 
1895  return desc;
1896 }
uint32_t m_PadBottom
Padding bottom value in the height dimension.
uint32_t m_PadLeft
Padding left value in the width dimension.
uint32_t m_PoolWidth
Pooling width value.
The padding fields don&#39;t count and are ignored.
PaddingMethod m_PaddingMethod
The padding method to be used. (Exclude, IgnoreValue).
uint32_t m_PadTop
Padding top value in the height dimension.
void IgnoreUnused(Ts &&...)
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
uint32_t m_PoolHeight
Pooling height value.
uint32_t m_PadRight
Padding right value in the width dimension.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
PoolingAlgorithm m_PoolType
The pooling algorithm to use (Max. Average, L2).
The padding fields count, but are ignored.
OutputShapeRounding m_OutputShapeRounding
The rounding method for the output shape. (Floor, Ceiling).
A Pooling2dDescriptor for the Pooling2dLayer.
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.

◆ LoadGraphFromBinary()

Deserializer::GraphPtr LoadGraphFromBinary ( const uint8_t *  binaryContent,
size_t  len 
)
static

Definition at line 686 of file Deserializer.cpp.

References CHECK_LOCATION, and IOutputSlot::Connect().

Referenced by Deserializer::CreateNetworkFromBinary(), and Deserializer::~Deserializer().

687 {
688  if (binaryContent == nullptr)
689  {
690  throw InvalidArgumentException(boost::str(boost::format("Invalid (null) binary content %1%") %
691  CHECK_LOCATION().AsString()));
692  }
693  flatbuffers::Verifier verifier(binaryContent, len);
694  if (verifier.VerifyBuffer<SerializedGraph>() == false)
695  {
696  throw ParseException(
697  boost::str(boost::format("Buffer doesn't conform to the expected Armnn "
698  "flatbuffers format. size:%1% %2%") %
699  len %
700  CHECK_LOCATION().AsString()));
701  }
702  return GetSerializedGraph(binaryContent);
703 }
#define CHECK_LOCATION()
Definition: Exceptions.hpp:192

◆ OutputShapeOfReshape()

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

Definition at line 1938 of file Deserializer.cpp.

References armnn::Bilinear, CHECK_LAYERS, CHECK_LOCATION, CHECK_VALID_SIZE, armnnDeserializer::CheckShape(), Deserializer::GetInputs(), Deserializer::GetLayerName(), TensorInfo::GetNumElements(), Deserializer::GetOutputs(), IConnectableLayer::GetOutputSlot(), TensorInfo::GetShape(), SoftmaxDescriptor::m_Beta, SpaceToBatchNdDescriptor::m_BlockShape, SpaceToDepthDescriptor::m_BlockSize, ResizeDescriptor::m_DataLayout, SpaceToBatchNdDescriptor::m_DataLayout, SpaceToDepthDescriptor::m_DataLayout, ResizeDescriptor::m_Method, SpaceToBatchNdDescriptor::m_PadList, ResizeDescriptor::m_TargetHeight, ReshapeDescriptor::m_TargetShape, ResizeDescriptor::m_TargetWidth, armnn::numeric_cast(), TensorInfo::SetShape(), IOutputSlot::SetTensorInfo(), armnnDeserializer::ToDataLayout(), armnnDeserializer::ToResizeMethod(), and armnnDeserializer::ToTensorInfo().

Referenced by Deserializer::~Deserializer().

1940 {
1941  std::vector<unsigned int> outputDims(targetDimsIn.begin(), targetDimsIn.end());
1942  const auto stretchDim = std::find(targetDimsIn.begin(), targetDimsIn.end(), -1);
1943 
1944  if (stretchDim != targetDimsIn.end())
1945  {
1946  if (std::find(std::next(stretchDim), targetDimsIn.end(), -1) != targetDimsIn.end())
1947  {
1948  throw ParseException(boost::str(
1949  boost::format("At most one component of shape can be -1 %1%") % CHECK_LOCATION().AsString()));
1950  }
1951 
1952  auto targetNumElements =
1953  boost::numeric_cast<unsigned int>(
1954  std::accumulate(targetDimsIn.begin(), targetDimsIn.end(), -1, std::multiplies<int32_t>()));
1955 
1956  auto stretchIndex = static_cast<size_t>(std::distance(targetDimsIn.begin(), stretchDim));
1957  outputDims[stretchIndex] = inputTensorInfo.GetNumElements() / targetNumElements;
1958  }
1959 
1960  TensorShape outputShape = TensorShape(static_cast<unsigned int>(outputDims.size()), outputDims.data());
1961 
1962  armnn::TensorInfo reshapeInfo = inputTensorInfo;
1963  reshapeInfo.SetShape(outputShape);
1964 
1965  return reshapeInfo;
1966 }
void SetShape(const TensorShape &newShape)
Definition: Tensor.hpp:90
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 GetNumElements() const
Definition: Tensor.hpp:93

The documentation for this class was generated from the following files: