ArmNN  NotReleased
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 185 of file Deserializer.cpp.

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

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

◆ ~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 660 of file Deserializer.cpp.

References Deserializer::LoadGraphFromBinary().

661 {
662  ResetParser();
663  GraphPtr graph = LoadGraphFromBinary(binaryContent.data(), binaryContent.size());
664  return CreateNetworkFromGraph(graph);
665 }
const armnnSerializer::SerializedGraph * GraphPtr
static GraphPtr LoadGraphFromBinary(const uint8_t *binaryContent, size_t len)

◆ CreateNetworkFromBinary() [2/2]

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

Create an input network from a binary input stream.

Implements IDeserializer.

Definition at line 667 of file Deserializer.cpp.

References Deserializer::LoadGraphFromBinary().

668 {
669  ResetParser();
670  std::vector<uint8_t> content((std::istreambuf_iterator<char>(binaryContent)), std::istreambuf_iterator<char>());
671  GraphPtr graph = LoadGraphFromBinary(content.data(), content.size());
672  return CreateNetworkFromGraph(graph);
673 }
const armnnSerializer::SerializedGraph * GraphPtr
static GraphPtr LoadGraphFromBinary(const uint8_t *binaryContent, size_t len)

◆ GetBaseLayer()

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

Definition at line 246 of file Deserializer.cpp.

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

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

◆ GetBindingLayerInfo()

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

Definition at line 375 of file Deserializer.cpp.

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

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

◆ GetInputs()

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

Definition at line 590 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().

592 {
593  CHECK_LAYERS(graphPtr, 0, layerIndex);
594  auto layer = GetBaseLayer(graphPtr, layerIndex);
595  const auto& numInputs = layer->inputSlots()->size();
596 
597  TensorRawPtrVector result(numInputs);
598 
599  for (unsigned int i=0; i<numInputs; ++i)
600  {
601  auto inputId = CHECKED_NON_NEGATIVE(static_cast<int32_t>
602  (layer->inputSlots()->Get(i)->connection()->sourceLayerIndex()));
603  result[i] = GetBaseLayer(graphPtr, inputId)->outputSlots()->Get(0)->tensorInfo();
604  }
605  return result;
606 }
std::vector< TensorRawPtr > TensorRawPtrVector
#define CHECK_LAYERS(GRAPH, LAYERS_INDEX, LAYER_INDEX)
#define CHECKED_NON_NEGATIVE(VALUE)
static LayerBaseRawPtr GetBaseLayer(const GraphPtr &graphPtr, unsigned int layerIndex)

◆ GetLayerName()

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

Definition at line 368 of file Deserializer.cpp.

References Deserializer::GetBaseLayer().

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

369 {
370  auto layer = GetBaseLayer(graph, index);
371  assert(layer);
372  return layer->layerName()->str();
373 }
static LayerBaseRawPtr GetBaseLayer(const GraphPtr &graphPtr, unsigned int layerIndex)

◆ GetLstmDescriptor()

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

Definition at line 2454 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().

2455 {
2456  armnn::LstmDescriptor desc;
2457 
2458  desc.m_ActivationFunc = lstmDescriptor->activationFunc();
2459  desc.m_ClippingThresCell = lstmDescriptor->clippingThresCell();
2460  desc.m_ClippingThresProj = lstmDescriptor->clippingThresProj();
2461  desc.m_CifgEnabled = lstmDescriptor->cifgEnabled();
2462  desc.m_PeepholeEnabled = lstmDescriptor->peepholeEnabled();
2463  desc.m_ProjectionEnabled = lstmDescriptor->projectionEnabled();
2464  desc.m_LayerNormEnabled = lstmDescriptor->layerNormEnabled();
2465 
2466  return desc;
2467 }
bool m_ProjectionEnabled
Enable/disable the projection layer.
float m_ClippingThresCell
Clipping threshold value for the cell state.
bool m_CifgEnabled
Enable/disable cifg (coupled input & forget gate).
bool m_PeepholeEnabled
Enable/disable peephole.
An LstmDescriptor for the LstmLayer.
uint32_t m_ActivationFunc
The activation function to use. 0: None, 1: Relu, 3: Relu6, 4: Tanh, 6: Sigmoid.
bool m_LayerNormEnabled
Enable/disable layer normalization.
float m_ClippingThresProj
Clipping threshold value for the projection.

◆ 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 735 of file Deserializer.cpp.

References CHECK_LOCATION.

737 {
738  boost::ignore_unused(layerIndex);
739  for (auto inputBinding : m_InputBindings)
740  {
741  if (inputBinding.first == name)
742  {
743  return inputBinding.second;
744  }
745  }
746  throw ParseException(
747  boost::str(
748  boost::format("No input binding found for layer:%1% / %2%") %
749  name %
750  CHECK_LOCATION().AsString()));
751 }
#define CHECK_LOCATION()
Definition: Exceptions.hpp:169

◆ 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 753 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, 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, IOutputSlot::SetTensorInfo(), armnnDeserializer::ToActivationFunction(), armnnDeserializer::ToArgMinMaxFunction(), armnnDeserializer::ToConstTensor(), armnnDeserializer::ToDataLayout(), and armnnDeserializer::ToTensorInfo().

755 {
756  boost::ignore_unused(layerIndex);
757  for (auto outputBinding : m_OutputBindings)
758  {
759  if (outputBinding.first == name)
760  {
761  return outputBinding.second;
762  }
763  }
764  throw ParseException(
765  boost::str(
766  boost::format("No output binding found for layer:%1% / %2%") %
767  name %
768  CHECK_LOCATION().AsString()));
769 }
#define CHECK_LOCATION()
Definition: Exceptions.hpp:169

◆ GetNormalizationDescriptor()

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

Definition at line 2148 of file Deserializer.cpp.

References armnn::Across, CHECK_LAYERS, CHECK_LOCATION, CHECK_VALID_SIZE, Deserializer::GetInputs(), Deserializer::GetLayerName(), Deserializer::GetOutputs(), IConnectableLayer::GetOutputSlot(), 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().

2151 {
2152  boost::ignore_unused(layerIndex);
2154 
2155  switch (normalizationDescriptor->normChannelType())
2156  {
2157  case NormalizationAlgorithmChannel_Across:
2158  {
2160  break;
2161  }
2162  case NormalizationAlgorithmChannel_Within:
2163  {
2165  break;
2166  }
2167  default:
2168  {
2169  BOOST_ASSERT_MSG(false, "Unsupported normalization channel type");
2170  }
2171  }
2172 
2173  switch (normalizationDescriptor->normMethodType())
2174  {
2175  case NormalizationAlgorithmMethod_LocalBrightness:
2176  {
2178  break;
2179  }
2180  case NormalizationAlgorithmMethod_LocalContrast:
2181  {
2183  break;
2184  }
2185  default:
2186  {
2187  BOOST_ASSERT_MSG(false, "Unsupported normalization method type");
2188  }
2189  }
2190 
2191  switch (normalizationDescriptor->dataLayout())
2192  {
2193  case DataLayout_NCHW:
2194  {
2196  break;
2197  }
2198  case DataLayout_NHWC:
2199  {
2201  break;
2202  }
2203  default:
2204  {
2205  BOOST_ASSERT_MSG(false, "Unsupported data layout");
2206  }
2207  }
2208 
2209  desc.m_Alpha = normalizationDescriptor->alpha();
2210  desc.m_Beta = normalizationDescriptor->beta();
2211  desc.m_K = normalizationDescriptor->k();
2212  desc.m_NormSize = normalizationDescriptor->normSize();
2213 
2214  return desc;
2215 }
A NormalizationDescriptor for the NormalizationLayer.
float m_Alpha
Alpha value for the normalization equation.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
Krichevsky 2012: Local Brightness Normalization.
Jarret 2009: Local Contrast Normalization.
uint32_t m_NormSize
Depth radius value.
float m_Beta
Beta value for the normalization equation.
NormalizationAlgorithmMethod m_NormMethodType
Normalization method algorithm to use (LocalBrightness, LocalContrast).
float m_K
Kappa value used for the across channel normalization equation.
NormalizationAlgorithmChannel m_NormChannelType
Normalization channel algorithm to use (Across, Within).

◆ GetOutputs()

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

Definition at line 608 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().

610 {
611  CHECK_LAYERS(graphPtr, 0, layerIndex);
612  auto layer = GetBaseLayer(graphPtr, layerIndex);
613  const auto& numOutputs = layer->outputSlots()->size();
614 
615  TensorRawPtrVector result(numOutputs);
616 
617  for (unsigned int i=0; i<numOutputs; ++i)
618  {
619  result[i] = layer->outputSlots()->Get(i)->tensorInfo();
620  }
621  return result;
622 }
std::vector< TensorRawPtr > TensorRawPtrVector
#define CHECK_LAYERS(GRAPH, LAYERS_INDEX, LAYER_INDEX)
static LayerBaseRawPtr GetBaseLayer(const GraphPtr &graphPtr, unsigned int layerIndex)

◆ GetPoolingDescriptor()

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

Definition at line 1797 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::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().

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

◆ LoadGraphFromBinary()

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

Definition at line 675 of file Deserializer.cpp.

References CHECK_LOCATION, and IOutputSlot::Connect().

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

676 {
677  if (binaryContent == nullptr)
678  {
679  throw InvalidArgumentException(boost::str(boost::format("Invalid (null) binary content %1%") %
680  CHECK_LOCATION().AsString()));
681  }
682  flatbuffers::Verifier verifier(binaryContent, len);
683  if (verifier.VerifyBuffer<SerializedGraph>() == false)
684  {
685  throw ParseException(
686  boost::str(boost::format("Buffer doesn't conform to the expected Armnn "
687  "flatbuffers format. size:%1% %2%") %
688  len %
689  CHECK_LOCATION().AsString()));
690  }
691  return GetSerializedGraph(binaryContent);
692 }
#define CHECK_LOCATION()
Definition: Exceptions.hpp:169

◆ OutputShapeOfReshape()

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

Definition at line 1927 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, TensorInfo::SetShape(), IOutputSlot::SetTensorInfo(), armnnDeserializer::ToDataLayout(), armnnDeserializer::ToResizeMethod(), and armnnDeserializer::ToTensorInfo().

Referenced by Deserializer::~Deserializer().

1929 {
1930  std::vector<unsigned int> outputDims(targetDimsIn.begin(), targetDimsIn.end());
1931  const auto stretchDim = std::find(targetDimsIn.begin(), targetDimsIn.end(), -1);
1932 
1933  if (stretchDim != targetDimsIn.end())
1934  {
1935  if (std::find(std::next(stretchDim), targetDimsIn.end(), -1) != targetDimsIn.end())
1936  {
1937  throw ParseException(boost::str(
1938  boost::format("At most one component of shape can be -1 %1%") % CHECK_LOCATION().AsString()));
1939  }
1940 
1941  auto targetNumElements =
1942  boost::numeric_cast<unsigned int>(
1943  std::accumulate(targetDimsIn.begin(), targetDimsIn.end(), -1, std::multiplies<int32_t>()));
1944 
1945  auto stretchIndex = static_cast<size_t>(std::distance(targetDimsIn.begin(), stretchDim));
1946  outputDims[stretchIndex] = inputTensorInfo.GetNumElements() / targetNumElements;
1947  }
1948 
1949  TensorShape outputShape = TensorShape(static_cast<unsigned int>(outputDims.size()), outputDims.data());
1950 
1951  armnn::TensorInfo reshapeInfo = inputTensorInfo;
1952  reshapeInfo.SetShape(outputShape);
1953 
1954  return reshapeInfo;
1955 }
#define CHECK_LOCATION()
Definition: Exceptions.hpp:169
void SetShape(const TensorShape &newShape)
Definition: Tensor.hpp:90
unsigned int GetNumElements() const
Definition: Tensor.hpp:93

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