24 #include <fmt/format.h>
32 using namespace armnn;
38 IDeserializer::IDeserializer() : pDeserializerImpl(new DeserializerImpl()){}
40 IDeserializer::~IDeserializer() =
default;
57 armnn::INetworkPtr IDeserializer::CreateNetworkFromBinary(
const std::vector<uint8_t> &binaryContent)
64 return pDeserializerImpl->CreateNetworkFromBinary(binaryContent);
67 BindingPointInfo IDeserializer::GetNetworkInputBindingInfo(
unsigned int layerId,
const std::string &name)
const
69 return pDeserializerImpl->GetNetworkInputBindingInfo(layerId, name);
72 BindingPointInfo IDeserializer::GetNetworkOutputBindingInfo(
unsigned int layerId,
const std::string &name)
const
74 return pDeserializerImpl->GetNetworkOutputBindingInfo(layerId, name);
80 const uint32_t VIRTUAL_LAYER_ID = std::numeric_limits<uint32_t>::max();
82 void CheckGraph(
const GraphPtr& graph,
83 unsigned int layersIndex,
86 if (graph->layers() ==
nullptr)
88 throw ParseException(fmt::format(
"{0} was called with invalid (null) graph. "
89 "Possible reason is that the graph is not yet loaded and Unpack(ed). "
95 else if (layersIndex >= graph->layers()->size())
97 throw ParseException(fmt::format(
"{0} was called with an invalid layers index. layers:{1} at {2}",
104 void CheckLayers(
const GraphPtr& graph,
105 unsigned int layersIndex,
106 unsigned int layerIndex,
109 if (graph->layers() ==
nullptr)
111 throw ParseException(fmt::format(
"{0} was called with invalid (null) graph. "
112 "Possible reason is that the graph is not yet loaded and Unpack(ed). "
118 else if (layersIndex >= graph->layers()->size())
120 throw ParseException(fmt::format(
"{0} was called with an invalid layers index. "
126 else if (layerIndex >= graph->layers()[layersIndex].size()
127 && layerIndex != VIRTUAL_LAYER_ID)
129 throw ParseException(fmt::format(
"{0} was called with an invalid layer index. "
130 "layers:{1} layer:{2} at {3}",
141 if (rawPtr ==
nullptr)
143 throw ParseException(fmt::format(
"{0} was called with a null tensor pointer. at {1}",
152 if (rawPtr ==
nullptr)
154 throw ParseException(fmt::format(
"{0} was called with a null const tensor pointer. at {1}",
160 void CheckConstTensorSize(
const unsigned int constTensorSize,
161 const unsigned int tensorSize,
164 if (constTensorSize != tensorSize)
166 throw ParseException(fmt::format(
"{0} wrong number of components supplied to tensor. at:{1}",
172 #define CHECK_TENSOR_PTR(TENSOR_PTR) \
173 CheckTensorPtr(TENSOR_PTR, CHECK_LOCATION())
175 #define CHECK_CONST_TENSOR_SIZE(CONST_TENSOR_SIZE, TENSOR_SIZE) \
176 CheckConstTensorSize(CONST_TENSOR_SIZE, TENSOR_SIZE, CHECK_LOCATION())
178 #define CHECK_CONST_TENSOR_PTR(TENSOR_PTR) \
179 CheckConstTensorPtr(TENSOR_PTR, CHECK_LOCATION())
181 #define CHECK_LAYERS(GRAPH, LAYERS_INDEX, LAYER_INDEX) \
182 CheckLayers(GRAPH, LAYERS_INDEX, LAYER_INDEX, CHECK_LOCATION())
184 #define CHECK_GRAPH(GRAPH, LAYERS_INDEX) \
185 CheckGraph(GRAPH, LAYERS_INDEX, CHECK_LOCATION())
191 if (actualSize != expected.size())
196 for (
unsigned int i = 0u; i < actualSize; i++)
198 if (actual[i] !=
static_cast<unsigned int>(expected[i]))
207 IDeserializer::DeserializerImpl::DeserializerImpl()
208 : m_Network(nullptr, nullptr),
213 m_ParserFunctions[Layer_AbsLayer] = &DeserializerImpl::ParseAbs;
214 m_ParserFunctions[Layer_ActivationLayer] = &DeserializerImpl::ParseActivation;
215 m_ParserFunctions[Layer_AdditionLayer] = &DeserializerImpl::ParseAdd;
216 m_ParserFunctions[Layer_ArgMinMaxLayer] = &DeserializerImpl::ParseArgMinMax;
217 m_ParserFunctions[Layer_BatchMatMulLayer] = &DeserializerImpl::ParseBatchMatMul;
218 m_ParserFunctions[Layer_BatchToSpaceNdLayer] = &DeserializerImpl::ParseBatchToSpaceNd;
219 m_ParserFunctions[Layer_BatchNormalizationLayer] = &DeserializerImpl::ParseBatchNormalization;
220 m_ParserFunctions[Layer_CastLayer] = &DeserializerImpl::ParseCast;
221 m_ParserFunctions[Layer_ChannelShuffleLayer] = &DeserializerImpl::ParseChannelShuffle;
222 m_ParserFunctions[Layer_ComparisonLayer] = &DeserializerImpl::ParseComparison;
223 m_ParserFunctions[Layer_ConcatLayer] = &DeserializerImpl::ParseConcat;
224 m_ParserFunctions[Layer_ConstantLayer] = &DeserializerImpl::ParseConstant;
225 m_ParserFunctions[Layer_Convolution2dLayer] = &DeserializerImpl::ParseConvolution2d;
226 m_ParserFunctions[Layer_Convolution3dLayer] = &DeserializerImpl::ParseConvolution3d;
227 m_ParserFunctions[Layer_DepthToSpaceLayer] = &DeserializerImpl::ParseDepthToSpace;
228 m_ParserFunctions[Layer_DepthwiseConvolution2dLayer] = &DeserializerImpl::ParseDepthwiseConvolution2d;
229 m_ParserFunctions[Layer_DequantizeLayer] = &DeserializerImpl::ParseDequantize;
230 m_ParserFunctions[Layer_DetectionPostProcessLayer] = &DeserializerImpl::ParseDetectionPostProcess;
231 m_ParserFunctions[Layer_DivisionLayer] = &DeserializerImpl::ParseDivision;
232 m_ParserFunctions[Layer_ElementwiseBinaryLayer] = &DeserializerImpl::ParseElementwiseBinary;
233 m_ParserFunctions[Layer_ElementwiseUnaryLayer] = &DeserializerImpl::ParseElementwiseUnary;
234 m_ParserFunctions[Layer_EqualLayer] = &DeserializerImpl::ParseEqual;
235 m_ParserFunctions[Layer_FullyConnectedLayer] = &DeserializerImpl::ParseFullyConnected;
236 m_ParserFunctions[Layer_FillLayer] = &DeserializerImpl::ParseFill;
237 m_ParserFunctions[Layer_FloorLayer] = &DeserializerImpl::ParseFloor;
238 m_ParserFunctions[Layer_GatherLayer] = &DeserializerImpl::ParseGather;
239 m_ParserFunctions[Layer_GatherNdLayer] = &DeserializerImpl::ParseGatherNd;
240 m_ParserFunctions[Layer_GreaterLayer] = &DeserializerImpl::ParseGreater;
241 m_ParserFunctions[Layer_InstanceNormalizationLayer] = &DeserializerImpl::ParseInstanceNormalization;
242 m_ParserFunctions[Layer_L2NormalizationLayer] = &DeserializerImpl::ParseL2Normalization;
243 m_ParserFunctions[Layer_LogicalBinaryLayer] = &DeserializerImpl::ParseLogicalBinary;
244 m_ParserFunctions[Layer_LogSoftmaxLayer] = &DeserializerImpl::ParseLogSoftmax;
245 m_ParserFunctions[Layer_LstmLayer] = &DeserializerImpl::ParseLstm;
246 m_ParserFunctions[Layer_MaximumLayer] = &DeserializerImpl::ParseMaximum;
247 m_ParserFunctions[Layer_MeanLayer] = &DeserializerImpl::ParseMean;
248 m_ParserFunctions[Layer_MinimumLayer] = &DeserializerImpl::ParseMinimum;
249 m_ParserFunctions[Layer_MergeLayer] = &DeserializerImpl::ParseMerge;
250 m_ParserFunctions[Layer_MergerLayer] = &DeserializerImpl::ParseConcat;
251 m_ParserFunctions[Layer_MultiplicationLayer] = &DeserializerImpl::ParseMultiplication;
252 m_ParserFunctions[Layer_NormalizationLayer] = &DeserializerImpl::ParseNormalization;
253 m_ParserFunctions[Layer_PadLayer] = &DeserializerImpl::ParsePad;
254 m_ParserFunctions[Layer_PermuteLayer] = &DeserializerImpl::ParsePermute;
255 m_ParserFunctions[Layer_Pooling2dLayer] = &DeserializerImpl::ParsePooling2d;
256 m_ParserFunctions[Layer_Pooling3dLayer] = &DeserializerImpl::ParsePooling3d;
257 m_ParserFunctions[Layer_PreluLayer] = &DeserializerImpl::ParsePrelu;
258 m_ParserFunctions[Layer_QLstmLayer] = &DeserializerImpl::ParseQLstm;
259 m_ParserFunctions[Layer_QuantizeLayer] = &DeserializerImpl::ParseQuantize;
260 m_ParserFunctions[Layer_QuantizedLstmLayer] = &DeserializerImpl::ParseQuantizedLstm;
261 m_ParserFunctions[Layer_RankLayer] = &DeserializerImpl::ParseRank;
262 m_ParserFunctions[Layer_ReduceLayer] = &DeserializerImpl::ParseReduce;
263 m_ParserFunctions[Layer_ReshapeLayer] = &DeserializerImpl::ParseReshape;
264 m_ParserFunctions[Layer_ResizeBilinearLayer] = &DeserializerImpl::ParseResizeBilinear;
265 m_ParserFunctions[Layer_ResizeLayer] = &DeserializerImpl::ParseResize;
266 m_ParserFunctions[Layer_RsqrtLayer] = &DeserializerImpl::ParseRsqrt;
267 m_ParserFunctions[Layer_ShapeLayer] = &DeserializerImpl::ParseShape;
268 m_ParserFunctions[Layer_SliceLayer] = &DeserializerImpl::ParseSlice;
269 m_ParserFunctions[Layer_SoftmaxLayer] = &DeserializerImpl::ParseSoftmax;
270 m_ParserFunctions[Layer_SpaceToBatchNdLayer] = &DeserializerImpl::ParseSpaceToBatchNd;
271 m_ParserFunctions[Layer_SpaceToDepthLayer] = &DeserializerImpl::ParseSpaceToDepth;
272 m_ParserFunctions[Layer_SplitterLayer] = &DeserializerImpl::ParseSplitter;
273 m_ParserFunctions[Layer_StackLayer] = &DeserializerImpl::ParseStack;
274 m_ParserFunctions[Layer_StandInLayer] = &DeserializerImpl::ParseStandIn;
275 m_ParserFunctions[Layer_StridedSliceLayer] = &DeserializerImpl::ParseStridedSlice;
276 m_ParserFunctions[Layer_SubtractionLayer] = &DeserializerImpl::ParseSubtraction;
277 m_ParserFunctions[Layer_SwitchLayer] = &DeserializerImpl::ParseSwitch;
278 m_ParserFunctions[Layer_TransposeConvolution2dLayer] = &DeserializerImpl::ParseTransposeConvolution2d;
279 m_ParserFunctions[Layer_TransposeLayer] = &DeserializerImpl::ParseTranspose;
280 m_ParserFunctions[Layer_UnidirectionalSequenceLstmLayer] = &DeserializerImpl::ParseUnidirectionalSequenceLstm;
285 auto layerType = graphPtr->layers()->Get(layerIndex)->layer_type();
289 case Layer::Layer_AbsLayer:
290 return graphPtr->layers()->Get(layerIndex)->layer_as_AbsLayer()->base();
291 case Layer::Layer_ActivationLayer:
292 return graphPtr->layers()->Get(layerIndex)->layer_as_ActivationLayer()->base();
293 case Layer::Layer_AdditionLayer:
294 return graphPtr->layers()->Get(layerIndex)->layer_as_AdditionLayer()->base();
295 case Layer::Layer_ArgMinMaxLayer:
296 return graphPtr->layers()->Get(layerIndex)->layer_as_ArgMinMaxLayer()->base();
297 case Layer::Layer_BatchMatMulLayer:
298 return graphPtr->layers()->Get(layerIndex)->layer_as_BatchMatMulLayer()->base();
299 case Layer::Layer_BatchToSpaceNdLayer:
300 return graphPtr->layers()->Get(layerIndex)->layer_as_BatchToSpaceNdLayer()->base();
301 case Layer::Layer_BatchNormalizationLayer:
302 return graphPtr->layers()->Get(layerIndex)->layer_as_BatchNormalizationLayer()->base();
303 case Layer::Layer_CastLayer:
304 return graphPtr->layers()->Get(layerIndex)->layer_as_CastLayer()->base();
305 case Layer::Layer_ChannelShuffleLayer:
306 return graphPtr->layers()->Get(layerIndex)->layer_as_ChannelShuffleLayer()->base();
307 case Layer::Layer_ComparisonLayer:
308 return graphPtr->layers()->Get(layerIndex)->layer_as_ComparisonLayer()->base();
309 case Layer::Layer_ConcatLayer:
310 return graphPtr->layers()->Get(layerIndex)->layer_as_ConcatLayer()->base();
311 case Layer::Layer_ConstantLayer:
312 return graphPtr->layers()->Get(layerIndex)->layer_as_ConstantLayer()->base();
313 case Layer::Layer_Convolution2dLayer:
314 return graphPtr->layers()->Get(layerIndex)->layer_as_Convolution2dLayer()->base();
315 case Layer::Layer_Convolution3dLayer:
316 return graphPtr->layers()->Get(layerIndex)->layer_as_Convolution3dLayer()->base();
317 case Layer::Layer_DepthToSpaceLayer:
318 return graphPtr->layers()->Get(layerIndex)->layer_as_DepthToSpaceLayer()->base();
319 case Layer::Layer_DepthwiseConvolution2dLayer:
320 return graphPtr->layers()->Get(layerIndex)->layer_as_DepthwiseConvolution2dLayer()->base();
321 case Layer::Layer_DequantizeLayer:
322 return graphPtr->layers()->Get(layerIndex)->layer_as_DequantizeLayer()->base();
323 case Layer::Layer_DetectionPostProcessLayer:
324 return graphPtr->layers()->Get(layerIndex)->layer_as_DetectionPostProcessLayer()->base();
325 case Layer::Layer_DivisionLayer:
326 return graphPtr->layers()->Get(layerIndex)->layer_as_DivisionLayer()->base();
327 case Layer::Layer_EqualLayer:
328 return graphPtr->layers()->Get(layerIndex)->layer_as_EqualLayer()->base();
329 case Layer::Layer_ElementwiseBinaryLayer:
330 return graphPtr->layers()->Get(layerIndex)->layer_as_ElementwiseBinaryLayer()->base();
331 case Layer::Layer_ElementwiseUnaryLayer:
332 return graphPtr->layers()->Get(layerIndex)->layer_as_ElementwiseUnaryLayer()->base();
333 case Layer::Layer_FullyConnectedLayer:
334 return graphPtr->layers()->Get(layerIndex)->layer_as_FullyConnectedLayer()->base();
335 case Layer::Layer_FillLayer:
336 return graphPtr->layers()->Get(layerIndex)->layer_as_FillLayer()->base();
337 case Layer::Layer_FloorLayer:
338 return graphPtr->layers()->Get(layerIndex)->layer_as_FloorLayer()->base();
339 case Layer::Layer_GatherLayer:
340 return graphPtr->layers()->Get(layerIndex)->layer_as_GatherLayer()->base();
341 case Layer::Layer_GatherNdLayer:
342 return graphPtr->layers()->Get(layerIndex)->layer_as_GatherNdLayer()->base();
343 case Layer::Layer_GreaterLayer:
344 return graphPtr->layers()->Get(layerIndex)->layer_as_GreaterLayer()->base();
345 case Layer::Layer_InputLayer:
346 return graphPtr->layers()->Get(layerIndex)->layer_as_InputLayer()->base()->base();
347 case Layer::Layer_InstanceNormalizationLayer:
348 return graphPtr->layers()->Get(layerIndex)->layer_as_InstanceNormalizationLayer()->base();
349 case Layer::Layer_L2NormalizationLayer:
350 return graphPtr->layers()->Get(layerIndex)->layer_as_L2NormalizationLayer()->base();
351 case Layer::Layer_LogicalBinaryLayer:
352 return graphPtr->layers()->Get(layerIndex)->layer_as_LogicalBinaryLayer()->base();
353 case Layer::Layer_LogSoftmaxLayer:
354 return graphPtr->layers()->Get(layerIndex)->layer_as_LogSoftmaxLayer()->base();
355 case Layer::Layer_LstmLayer:
356 return graphPtr->layers()->Get(layerIndex)->layer_as_LstmLayer()->base();
357 case Layer::Layer_MeanLayer:
358 return graphPtr->layers()->Get(layerIndex)->layer_as_MeanLayer()->base();
359 case Layer::Layer_MinimumLayer:
360 return graphPtr->layers()->Get(layerIndex)->layer_as_MinimumLayer()->base();
361 case Layer::Layer_MaximumLayer:
362 return graphPtr->layers()->Get(layerIndex)->layer_as_MaximumLayer()->base();
363 case Layer::Layer_MergeLayer:
364 return graphPtr->layers()->Get(layerIndex)->layer_as_MergeLayer()->base();
365 case Layer::Layer_MergerLayer:
366 return graphPtr->layers()->Get(layerIndex)->layer_as_MergerLayer()->base();
367 case Layer::Layer_MultiplicationLayer:
368 return graphPtr->layers()->Get(layerIndex)->layer_as_MultiplicationLayer()->base();
369 case Layer::Layer_NormalizationLayer:
370 return graphPtr->layers()->Get(layerIndex)->layer_as_NormalizationLayer()->base();
371 case Layer::Layer_OutputLayer:
372 return graphPtr->layers()->Get(layerIndex)->layer_as_OutputLayer()->base()->base();
373 case Layer::Layer_PadLayer:
374 return graphPtr->layers()->Get(layerIndex)->layer_as_PadLayer()->base();
375 case Layer::Layer_PermuteLayer:
376 return graphPtr->layers()->Get(layerIndex)->layer_as_PermuteLayer()->base();
377 case Layer::Layer_Pooling2dLayer:
378 return graphPtr->layers()->Get(layerIndex)->layer_as_Pooling2dLayer()->base();
379 case Layer::Layer_Pooling3dLayer:
380 return graphPtr->layers()->Get(layerIndex)->layer_as_Pooling3dLayer()->base();
381 case Layer::Layer_PreluLayer:
382 return graphPtr->layers()->Get(layerIndex)->layer_as_PreluLayer()->base();
383 case Layer::Layer_QLstmLayer:
384 return graphPtr->layers()->Get(layerIndex)->layer_as_QLstmLayer()->base();
385 case Layer::Layer_QuantizeLayer:
386 return graphPtr->layers()->Get(layerIndex)->layer_as_QuantizeLayer()->base();
387 case Layer::Layer_QuantizedLstmLayer:
388 return graphPtr->layers()->Get(layerIndex)->layer_as_QuantizedLstmLayer()->base();
389 case Layer::Layer_RankLayer:
390 return graphPtr->layers()->Get(layerIndex)->layer_as_RankLayer()->base();
391 case Layer::Layer_ReduceLayer:
392 return graphPtr->layers()->Get(layerIndex)->layer_as_ReduceLayer()->base();
393 case Layer::Layer_ReshapeLayer:
394 return graphPtr->layers()->Get(layerIndex)->layer_as_ReshapeLayer()->base();
395 case Layer::Layer_ResizeBilinearLayer:
396 return graphPtr->layers()->Get(layerIndex)->layer_as_ResizeBilinearLayer()->base();
397 case Layer::Layer_ResizeLayer:
398 return graphPtr->layers()->Get(layerIndex)->layer_as_ResizeLayer()->base();
399 case Layer::Layer_RsqrtLayer:
400 return graphPtr->layers()->Get(layerIndex)->layer_as_RsqrtLayer()->base();
401 case Layer::Layer_ShapeLayer:
402 return graphPtr->layers()->Get(layerIndex)->layer_as_ShapeLayer()->base();
403 case Layer::Layer_SliceLayer:
404 return graphPtr->layers()->Get(layerIndex)->layer_as_SliceLayer()->base();
405 case Layer::Layer_SoftmaxLayer:
406 return graphPtr->layers()->Get(layerIndex)->layer_as_SoftmaxLayer()->base();
407 case Layer::Layer_SpaceToBatchNdLayer:
408 return graphPtr->layers()->Get(layerIndex)->layer_as_SpaceToBatchNdLayer()->base();
409 case Layer::Layer_SpaceToDepthLayer:
410 return graphPtr->layers()->Get(layerIndex)->layer_as_SpaceToDepthLayer()->base();
411 case Layer::Layer_SplitterLayer:
412 return graphPtr->layers()->Get(layerIndex)->layer_as_SplitterLayer()->base();
413 case Layer::Layer_StackLayer:
414 return graphPtr->layers()->Get(layerIndex)->layer_as_StackLayer()->base();
415 case Layer::Layer_StandInLayer:
416 return graphPtr->layers()->Get(layerIndex)->layer_as_StandInLayer()->base();
417 case Layer::Layer_StridedSliceLayer:
418 return graphPtr->layers()->Get(layerIndex)->layer_as_StridedSliceLayer()->base();
419 case Layer::Layer_SubtractionLayer:
420 return graphPtr->layers()->Get(layerIndex)->layer_as_SubtractionLayer()->base();
421 case Layer::Layer_SwitchLayer:
422 return graphPtr->layers()->Get(layerIndex)->layer_as_SwitchLayer()->base();
423 case Layer::Layer_TransposeConvolution2dLayer:
424 return graphPtr->layers()->Get(layerIndex)->layer_as_TransposeConvolution2dLayer()->base();
425 case Layer::Layer_TransposeLayer:
426 return graphPtr->layers()->Get(layerIndex)->layer_as_TransposeLayer()->base();
427 case Layer::Layer_UnidirectionalSequenceLstmLayer:
428 return graphPtr->layers()->Get(layerIndex)->layer_as_UnidirectionalSequenceLstmLayer()->base();
429 case Layer::Layer_NONE:
431 throw ParseException(fmt::format(
"Layer type {} not recognized", layerType));
437 auto layer = GetBaseLayer(graph, index);
439 return layer->layerName()->str();
444 auto layerType = graphPtr->layers()->Get(layerIndex)->layer_type();
446 if (layerType == Layer::Layer_InputLayer)
448 return graphPtr->layers()->Get(layerIndex)->layer_as_InputLayer()->base()->layerBindingId();
450 else if ( layerType == Layer::Layer_OutputLayer )
452 return graphPtr->layers()->Get(layerIndex)->layer_as_OutputLayer()->base()->layerBindingId();
461 case armnnSerializer::DataLayout::DataLayout_NHWC:
463 case armnnSerializer::DataLayout::DataLayout_NDHWC:
465 case armnnSerializer::DataLayout::DataLayout_NCDHW:
467 case armnnSerializer::DataLayout::DataLayout_NCHW:
477 case armnnSerializer::ActivationFunction_Sigmoid:
479 case armnnSerializer::ActivationFunction_TanH:
481 case armnnSerializer::ActivationFunction_Linear:
483 case armnnSerializer::ActivationFunction_ReLu:
485 case armnnSerializer::ActivationFunction_BoundedReLu:
487 case armnnSerializer::ActivationFunction_LeakyReLu:
489 case armnnSerializer::ActivationFunction_Abs:
491 case armnnSerializer::ActivationFunction_Sqrt:
493 case armnnSerializer::ActivationFunction_Square:
495 case armnnSerializer::ActivationFunction_Elu:
497 case armnnSerializer::ActivationFunction_HardSwish:
508 case armnnSerializer::ArgMinMaxFunction::ArgMinMaxFunction_Max:
510 case armnnSerializer::ArgMinMaxFunction::ArgMinMaxFunction_Min:
520 case armnnSerializer::ComparisonOperation::ComparisonOperation_Equal:
522 case armnnSerializer::ComparisonOperation::ComparisonOperation_Greater:
524 case armnnSerializer::ComparisonOperation::ComparisonOperation_GreaterOrEqual:
526 case armnnSerializer::ComparisonOperation::ComparisonOperation_Less:
528 case armnnSerializer::ComparisonOperation::ComparisonOperation_LessOrEqual:
530 case armnnSerializer::ComparisonOperation::ComparisonOperation_NotEqual:
540 case armnnSerializer::ReduceOperation::ReduceOperation_Sum:
542 case armnnSerializer::ReduceOperation::ReduceOperation_Max:
544 case armnnSerializer::ReduceOperation::ReduceOperation_Mean:
546 case armnnSerializer::ReduceOperation::ReduceOperation_Min:
548 case armnnSerializer::ReduceOperation::ReduceOperation_Prod:
559 case armnnSerializer::LogicalBinaryOperation::LogicalBinaryOperation_LogicalAnd:
561 case armnnSerializer::LogicalBinaryOperation::LogicalBinaryOperation_LogicalOr:
572 case armnnSerializer::BinaryOperation::BinaryOperation_Add:
574 case armnnSerializer::BinaryOperation::BinaryOperation_Div:
576 case armnnSerializer::BinaryOperation::BinaryOperation_Maximum:
578 case armnnSerializer::BinaryOperation::BinaryOperation_Minimum:
580 case armnnSerializer::BinaryOperation::BinaryOperation_Mul:
582 case armnnSerializer::BinaryOperation::BinaryOperation_Sub:
593 case armnnSerializer::UnaryOperation::UnaryOperation_Abs:
595 case armnnSerializer::UnaryOperation::UnaryOperation_Ceil:
597 case armnnSerializer::UnaryOperation::UnaryOperation_Rsqrt:
599 case armnnSerializer::UnaryOperation::UnaryOperation_Sqrt:
601 case armnnSerializer::UnaryOperation::UnaryOperation_Exp:
603 case armnnSerializer::UnaryOperation::UnaryOperation_Neg:
605 case armnnSerializer::UnaryOperation::UnaryOperation_LogicalNot:
607 case armnnSerializer::UnaryOperation::UnaryOperation_Log:
609 case armnnSerializer::UnaryOperation::UnaryOperation_Sin:
620 case armnnSerializer::PaddingMode::PaddingMode_Reflect:
622 case armnnSerializer::PaddingMode::PaddingMode_Symmetric:
633 case armnnSerializer::ResizeMethod_NearestNeighbor:
635 case armnnSerializer::ResizeMethod_Bilinear:
647 switch (tensorPtr->dataType())
649 case DataType_QAsymmS8:
652 case DataType_QSymmS8:
655 case DataType_QuantisedAsymm8:
656 case DataType_QAsymmU8:
659 case DataType_QSymmS16:
660 case DataType_QuantisedSymm16:
663 case DataType_Signed32:
666 case DataType_Signed64:
669 case DataType_Float32:
672 case DataType_Float16:
675 case DataType_Boolean:
681 throw ParseException(fmt::format(
"Unsupported data type {0} = {1}. {2}",
682 tensorPtr->dataType(),
683 EnumNameDataType(tensorPtr->dataType()),
688 float quantizationScale = tensorPtr->quantizationScale();
689 int32_t quantizationOffset = tensorPtr->quantizationOffset();
691 if (tensorPtr->dimensionality() ==
static_cast<unsigned int>(Dimensionality::Scalar))
698 else if (tensorPtr->dimensionality() ==
static_cast<unsigned int>(Dimensionality::NotSpecified))
707 auto dimensions = tensorPtr->dimensions();
708 unsigned int size = dimensions->size();
709 std::vector<unsigned int> outputDims(dimensions->begin(), dimensions->begin() + size);
714 if (tensorPtr->dimensionSpecificity() !=
nullptr)
716 auto dimensionSpecificity = tensorPtr->dimensionSpecificity();
717 size = dimensionSpecificity->size();
718 for (
unsigned int i = 0; i < size; ++i)
720 dimensionsSpecificity[i] = dimensionSpecificity->Get(i);
724 TensorShape shape(size, outputDims.data(), dimensionsSpecificity);
726 auto quantizationScales = tensorPtr->quantizationScales();
727 if (quantizationScales)
729 unsigned int quantizationScalesSize = quantizationScales->size();
730 std::vector<float> scales(quantizationScales->begin(), quantizationScales->begin() + quantizationScalesSize);
731 unsigned int quantizationDim = tensorPtr->quantizationDim();
754 switch (constTensorPtr->data_type())
756 case ConstTensorData_ByteData:
758 auto byteData = constTensorPtr->data_as_ByteData()->data();
762 case ConstTensorData_ShortData:
764 auto shortData = constTensorPtr->data_as_ShortData()->data();
768 case ConstTensorData_IntData:
770 auto intData = constTensorPtr->data_as_IntData()->data();
774 case ConstTensorData_LongData:
776 auto longData = constTensorPtr->data_as_LongData()->data();
783 throw ParseException(fmt::format(
"Unsupported data type {0} = {1}. {2}",
784 constTensorPtr->data_type(),
785 EnumNameConstTensorData(constTensorPtr->data_type()),
794 auto layer = GetBaseLayer(graphPtr, layerIndex);
795 const auto& numInputs = layer->inputSlots()->size();
799 for (
unsigned int i=0; i<numInputs; ++i)
802 (layer->inputSlots()->Get(i)->connection()->sourceLayerIndex()));
803 result[i] = GetBaseLayer(graphPtr, inputId)->outputSlots()->Get(0)->tensorInfo();
811 auto layer = GetBaseLayer(graphPtr, layerIndex);
812 const auto& numOutputs = layer->outputSlots()->size();
816 for (
unsigned int i=0; i<numOutputs; ++i)
818 result[i] = layer->outputSlots()->Get(i)->tensorInfo();
823 void IDeserializer::DeserializerImpl::ParseUnsupportedLayer(
GraphPtr graph,
unsigned int layerIndex)
826 const auto layerName = GetBaseLayer(graph, layerIndex)->layerName()->c_str();
827 throw ParseException(fmt::format(
"Layer not supported. layerIndex: {0} "
828 "layerName: {1} / {2}",
834 void IDeserializer::DeserializerImpl::ResetParser()
837 m_InputBindings.clear();
838 m_OutputBindings.clear();
845 GraphPtr graph = LoadGraphFromBinary(binaryContent.data(), binaryContent.size());
846 return CreateNetworkFromGraph(graph);
852 if (binaryContent.fail()) {
856 binaryContent.seekg(0, std::ios::end);
857 const std::streamoff size = binaryContent.tellg();
858 std::vector<char> content(
static_cast<size_t>(size));
859 binaryContent.seekg(0);
860 binaryContent.read(content.data(),
static_cast<std::streamsize
>(size));
861 GraphPtr graph = LoadGraphFromBinary(
reinterpret_cast<uint8_t*
>(content.data()),
static_cast<size_t>(size));
862 return CreateNetworkFromGraph(graph);
867 if (binaryContent ==
nullptr)
872 flatbuffers::Verifier verifier(binaryContent, len);
873 if (verifier.VerifyBuffer<SerializedGraph>() ==
false)
875 throw ParseException(fmt::format(
"Buffer doesn't conform to the expected Armnn "
876 "flatbuffers format. size:{0} {1}",
880 return GetSerializedGraph(binaryContent);
885 m_Network = INetwork::Create();
887 unsigned int layerIndex = 0;
888 for (AnyLayer
const* layer : *graph->layers())
890 if (layer->layer_type() != Layer_InputLayer &&
891 layer->layer_type() != Layer_OutputLayer)
894 auto& parserFunction = m_ParserFunctions[layer->layer_type()];
895 (this->*parserFunction)(graph, layerIndex);
900 SetupInputLayers(graph);
901 SetupOutputLayers(graph);
904 for (
auto&& graphIt : m_GraphConnections)
906 Connections& connections = graphIt.second;
907 for (
auto&& outputIt : connections.outputSlots)
909 const unsigned int outputSlotIndex = outputIt.first;
911 if (connections.inputSlots.find(outputSlotIndex) != connections.inputSlots.end())
913 for (
IInputSlot* inputSlot : connections.inputSlots[outputSlotIndex])
915 outputSlot->
Connect(*inputSlot);
921 return std::move(m_Network);
925 const std::string& name)
const
928 for (
auto inputBinding : m_InputBindings)
930 if (inputBinding.first == name)
932 return inputBinding.second;
935 throw ParseException(fmt::format(
"No input binding found for layer:{0} / {1}",
941 const std::string& name)
const
944 for (
auto outputBinding : m_OutputBindings)
946 if (outputBinding.first == name)
948 return outputBinding.second;
951 throw ParseException(fmt::format(
"No output binding found for layer:{0} / {1}",
956 unsigned int IDeserializer::DeserializerImpl::GetInputLayerInVector(
GraphPtr graph,
int targetId)
958 for (
unsigned int i = 0; i < graph->layers()->size(); i++)
960 auto layer = graph->layers()->Get(i);
961 if (layer->layer_type() == Layer::Layer_InputLayer)
963 auto layerBindingId = layer->layer_as_InputLayer()->base()->layerBindingId();
964 if (layerBindingId == targetId)
970 throw ParseException(
"Input layer with given layerBindingId not found");
973 unsigned int IDeserializer::DeserializerImpl::GetOutputLayerInVector(
GraphPtr graph,
int targetId)
975 for (
unsigned int i = 0; i < graph->layers()->size(); i++)
977 auto layer = graph->layers()->Get(i);
978 if (layer->layer_type() == Layer::Layer_OutputLayer)
980 auto layerBindingId = layer->layer_as_OutputLayer()->base()->layerBindingId();
981 if (layerBindingId == targetId)
987 throw ParseException(
"Output layer with given layerBindingId not found");
990 unsigned int IDeserializer::DeserializerImpl::GetLayerIndexInVector(
GraphPtr graph,
unsigned int targetIndex)
992 for (
unsigned int i = 0; i < graph->layers()->size(); i++)
995 if (layer->index() == targetIndex)
1003 IDeserializer::DeserializerImpl::FeatureVersions IDeserializer::DeserializerImpl::GetFeatureVersions(
GraphPtr graph)
1005 IDeserializer::DeserializerImpl::FeatureVersions versions;
1007 if (graph->featureVersions())
1009 versions.m_BindingIdScheme = graph->featureVersions()->bindingIdsScheme();
1010 versions.m_WeightsLayoutScheme = graph->featureVersions()->weightsLayoutScheme();
1011 versions.m_ConstTensorsAsInputs = graph->featureVersions()->constantTensorsAsInputs();
1017 void IDeserializer::DeserializerImpl::SetupInputLayers(
GraphPtr graph)
1020 const unsigned int numInputs = graph->inputIds()->size();
1021 m_InputBindings.clear();
1022 m_InputBindings.reserve(numInputs);
1024 for (
unsigned int i = 0; i < numInputs; i++)
1026 unsigned int inputLayerIndex = 0xFFFFFFFF;
1027 if (GetFeatureVersions(graph).m_BindingIdScheme == 0)
1029 const unsigned int inputId = armnn::numeric_cast<unsigned int>(graph->inputIds()->Get(i));
1030 inputLayerIndex = GetLayerIndexInVector(graph, inputId);
1034 const int inputId = graph->inputIds()->Get(i);
1035 inputLayerIndex = GetInputLayerInVector(graph, inputId);
1041 LayerBindingId bindingId = GetBindingLayerInfo(graph, inputLayerIndex);
1045 m_Network->AddInputLayer(bindingId, baseLayer->layerName()->c_str());
1049 RegisterOutputSlots(graph, inputLayerIndex, inputLayer);
1052 m_InputBindings.push_back(std::make_pair(baseLayer->layerName()->c_str(), bindingInfo));
1056 void IDeserializer::DeserializerImpl::SetupOutputLayers(
GraphPtr graph)
1059 const unsigned int numOutputs = graph->outputIds()->size();
1060 m_OutputBindings.clear();
1061 m_OutputBindings.reserve(numOutputs);
1063 for (
unsigned int i = 0; i < numOutputs; i++)
1065 unsigned int outputLayerIndex = 0xFFFFFFFF;
1066 if (GetFeatureVersions(graph).m_BindingIdScheme == 0)
1068 const unsigned int outputId = armnn::numeric_cast<unsigned int>(graph->outputIds()->Get(i));
1069 outputLayerIndex = GetLayerIndexInVector(graph, outputId);
1073 const int outputId = graph->outputIds()->Get(i);
1074 outputLayerIndex = GetOutputLayerInVector(graph, outputId);
1080 LayerBindingId bindingId = GetBindingLayerInfo(graph, outputLayerIndex);
1084 m_Network->AddOutputLayer(bindingId, baseLayer->layerName()->c_str());
1086 RegisterInputSlots(graph, outputLayerIndex, outputLayer);
1087 unsigned int sourceLayerIndex =
1088 GetLayerIndexInVector(graph, baseLayer->inputSlots()->Get(0)->connection()->sourceLayerIndex());
1089 unsigned int outputSlotIndex =
1090 GetLayerIndexInVector(graph, baseLayer->inputSlots()->Get(0)->connection()->outputSlotIndex());
1091 LayerBaseRawPtr sourceBaseLayer = GetBaseLayer(graph, sourceLayerIndex);
1093 sourceBaseLayer->outputSlots()->Get(outputSlotIndex)->tensorInfo());
1095 m_OutputBindings.push_back(std::make_pair(baseLayer->layerName()->c_str(), bindingInfo));
1099 void IDeserializer::DeserializerImpl::RegisterOutputSlots(
GraphPtr graph,
1100 uint32_t layerIndex,
1108 throw ParseException(fmt::format(
"The number of outputslots ({0}) does not match the number expected ({1})"
1109 " for layer index: {2} {3}",
1110 baseLayer->outputSlots()->size(),
1118 const unsigned int slotIndex = baseLayer->outputSlots()->Get(i)->index();
1121 RegisterOutputSlotOfConnection(baseLayer->index(), slotIndex, outputSlot);
1125 void IDeserializer::DeserializerImpl::RegisterInputSlots(
GraphPtr graph,
1126 uint32_t layerIndex,
1128 std::vector<unsigned int> ignoreSlots)
1134 if (baseLayer->inputSlots()->size() != (layer->
GetNumInputSlots() - ignoreSlots.size()))
1136 throw ParseException(fmt::format(
"The number of inputslots ({0}) does not match the number expected ({1})"
1137 " for layer index:{2} {3}",
1138 baseLayer->inputSlots()->size(),
1147 if (std::find(ignoreSlots.begin(), ignoreSlots.end(), i) == ignoreSlots.end())
1149 auto fbInputSlot = baseLayer->inputSlots()->Get(i);
1150 auto fbConnection = fbInputSlot->connection();
1152 RegisterInputSlotOfConnection(fbConnection->sourceLayerIndex(), fbConnection->outputSlotIndex(), inputSlot);
1157 void IDeserializer::DeserializerImpl::RegisterInputSlotOfConnection(uint32_t sourceLayerIndex,
1158 uint32_t outputSlotIndex,
1161 if (m_GraphConnections.find(sourceLayerIndex) == m_GraphConnections.end())
1163 m_GraphConnections[sourceLayerIndex] = Connections();
1166 Connections& connections = m_GraphConnections[sourceLayerIndex];
1167 if (connections.inputSlots.find(outputSlotIndex) == connections.inputSlots.end())
1169 connections.inputSlots[outputSlotIndex] = {inputSlot};
1173 connections.inputSlots[outputSlotIndex].push_back(inputSlot);
1177 void IDeserializer::DeserializerImpl::RegisterOutputSlotOfConnection(uint32_t sourceLayerIndex,
1178 uint32_t outputSlotIndex,
1181 if (m_GraphConnections.find(sourceLayerIndex) == m_GraphConnections.end())
1183 m_GraphConnections[sourceLayerIndex] = Connections();
1186 Connections& connections = m_GraphConnections[sourceLayerIndex];
1187 if (connections.outputSlots.find(outputSlotIndex) != connections.outputSlots.end())
1192 connections.outputSlots[outputSlotIndex] = outputSlot;
1195 void IDeserializer::DeserializerImpl::ParseAbs(
GraphPtr graph,
unsigned int layerIndex)
1198 auto inputs = GetInputs(graph, layerIndex);
1202 auto outputs = GetOutputs(graph, layerIndex);
1205 auto layerName = GetLayerName(graph, layerIndex);
1208 IConnectableLayer* layer = m_Network->AddElementwiseUnaryLayer(descriptor, layerName.c_str());
1212 RegisterInputSlots(graph, layerIndex, layer);
1213 RegisterOutputSlots(graph, layerIndex, layer);
1216 void IDeserializer::DeserializerImpl::ParseActivation(
GraphPtr graph,
unsigned int layerIndex)
1219 auto inputs = GetInputs(graph, layerIndex);
1223 auto outputs = GetOutputs(graph, layerIndex);
1226 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_ActivationLayer();
1227 auto layerName = GetLayerName(graph, layerIndex);
1228 auto serializerDescriptor = serializerLayer->descriptor();
1232 descriptor.
m_A = serializerDescriptor->a();
1233 descriptor.
m_B = serializerDescriptor->b();
1240 RegisterInputSlots(graph, layerIndex, layer);
1241 RegisterOutputSlots(graph, layerIndex, layer);
1244 void IDeserializer::DeserializerImpl::ParseAdd(
GraphPtr graph,
unsigned int layerIndex)
1247 auto inputs = GetInputs(graph, layerIndex);
1251 auto outputs = GetOutputs(graph, layerIndex);
1254 auto layerName = GetLayerName(graph, layerIndex);
1256 IConnectableLayer* layer = m_Network->AddElementwiseBinaryLayer(descriptor, layerName.c_str());
1261 RegisterInputSlots(graph, layerIndex, layer);
1262 RegisterOutputSlots(graph, layerIndex, layer);
1265 void IDeserializer::DeserializerImpl::ParseArgMinMax(
GraphPtr graph,
unsigned int layerIndex)
1268 auto inputs = GetInputs(graph, layerIndex);
1272 auto outputs = GetOutputs(graph, layerIndex);
1275 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_ArgMinMaxLayer();
1276 auto serializerDescriptor = serializerLayer->descriptor();
1280 descriptor.
m_Axis = serializerDescriptor->axis();
1281 auto layerName = GetLayerName(graph, layerIndex);
1282 IConnectableLayer* layer = m_Network->AddArgMinMaxLayer(descriptor, layerName.c_str());
1287 RegisterInputSlots(graph, layerIndex, layer);
1288 RegisterOutputSlots(graph, layerIndex, layer);
1291 void IDeserializer::DeserializerImpl::ParseBatchMatMul(
GraphPtr graph,
unsigned int layerIndex)
1295 auto inputs = GetInputs(graph, layerIndex);
1299 auto outputs = GetOutputs(graph, layerIndex);
1302 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_BatchMatMulLayer();
1303 auto serializerDescriptor = serializerLayer->descriptor();
1306 serializerDescriptor->transposeY(),
1307 serializerDescriptor->adjointX(),
1308 serializerDescriptor->adjointY(),
1312 auto layerName = GetLayerName(graph, layerIndex);
1313 IConnectableLayer* layer = m_Network->AddBatchMatMulLayer(descriptor, layerName.c_str());
1318 RegisterInputSlots(graph, layerIndex, layer);
1319 RegisterOutputSlots(graph, layerIndex, layer);
1322 void IDeserializer::DeserializerImpl::ParseBatchToSpaceNd(
GraphPtr graph,
unsigned int layerIndex)
1332 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_BatchToSpaceNdLayer()->descriptor();
1333 auto flatBufferCrops = flatBufferDescriptor->crops();
1334 auto flatBufferBlockShape = flatBufferDescriptor->blockShape();
1336 if (flatBufferCrops->size() % 2 != 0)
1341 std::vector<std::pair<unsigned int, unsigned int>> crops;
1342 crops.reserve(flatBufferCrops->size() / 2);
1343 for (
unsigned int i = 0; i < flatBufferCrops->size() - 1; i += 2)
1345 crops.emplace_back(flatBufferCrops->Get(i), flatBufferCrops->Get(i+1));
1351 std::vector<unsigned int>(flatBufferBlockShape->begin(), flatBufferBlockShape->end());
1354 auto layerName = GetLayerName(graph, layerIndex);
1355 IConnectableLayer* layer = m_Network->AddBatchToSpaceNdLayer(descriptor, layerName.c_str());
1360 RegisterInputSlots(graph, layerIndex, layer);
1361 RegisterOutputSlots(graph, layerIndex, layer);
1364 void IDeserializer::DeserializerImpl::ParseBatchNormalization(
GraphPtr graph,
unsigned int layerIndex)
1368 auto inputs = GetInputs(graph, layerIndex);
1371 auto outputs = GetOutputs(graph, layerIndex);
1375 auto layerName = GetLayerName(graph, layerIndex);
1377 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_BatchNormalizationLayer();
1378 auto serializerDescriptor = serializerLayer->descriptor();
1381 descriptor.
m_Eps = serializerDescriptor->eps();
1397 RegisterInputSlots(graph, layerIndex, layer);
1398 RegisterOutputSlots(graph, layerIndex, layer);
1401 void IDeserializer::DeserializerImpl::ParseCast(
GraphPtr graph,
unsigned int layerIndex)
1411 auto layerName = GetLayerName(graph, layerIndex);
1418 RegisterInputSlots(graph, layerIndex, layer);
1419 RegisterOutputSlots(graph, layerIndex, layer);
1422 void IDeserializer::DeserializerImpl::ParseConstant(
GraphPtr graph,
unsigned int layerIndex)
1427 auto outputs = GetOutputs(graph, layerIndex);
1430 auto layerName = GetLayerName(graph, layerIndex);
1432 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_ConstantLayer();
1433 auto serializerInput = serializerLayer->input();
1442 if (this->GetFeatureVersions(graph).m_WeightsLayoutScheme <= 0)
1448 std::unique_ptr<unsigned char[]> permuteBuffer(
new unsigned char[weightsInfo.
GetNumBytes()]);
1455 auto weightsShape = weightsInfo.
GetShape();
1459 weightsShape[2]*weightsShape[3]});
1464 layer = m_Network->AddConstantLayer(weightsPermuted, layerName.c_str());
1468 RegisterOutputSlots(graph, layerIndex, layer);
1474 layer = m_Network->AddConstantLayer(input, layerName.c_str());
1481 RegisterOutputSlots(graph, layerIndex, layer);
1484 void IDeserializer::DeserializerImpl::ParseConvolution2d(
GraphPtr graph,
unsigned int layerIndex)
1487 auto inputs = GetInputs(graph, layerIndex);
1490 auto outputs = GetOutputs(graph, layerIndex);
1493 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_Convolution2dLayer();
1495 auto layerName = GetLayerName(graph, layerIndex);
1496 auto flatbufferDescriptor = flatBufferLayer->descriptor();
1499 descriptor.
m_PadLeft = flatbufferDescriptor->padLeft();
1500 descriptor.
m_PadRight = flatbufferDescriptor->padRight();
1501 descriptor.
m_PadTop = flatbufferDescriptor->padTop();
1502 descriptor.
m_PadBottom = flatbufferDescriptor->padBottom();
1503 descriptor.
m_StrideX = flatbufferDescriptor->strideX();
1504 descriptor.
m_StrideY = flatbufferDescriptor->strideY();;
1505 descriptor.
m_DilationX = flatbufferDescriptor->dilationX();
1506 descriptor.
m_DilationY = flatbufferDescriptor->dilationY();;
1507 descriptor.
m_BiasEnabled = flatbufferDescriptor->biasEnabled();;
1511 std::vector<unsigned int> ignoreSlots {};
1516 if (this->GetFeatureVersions(graph).m_ConstTensorsAsInputs <= 0)
1522 layer = m_Network->AddConvolution2dLayer(descriptor,
1526 auto weightsLayer = m_Network->AddConstantLayer(weightsTensor);
1527 weightsLayer->GetOutputSlot(0).Connect(layer->
GetInputSlot(1u));
1528 weightsLayer->GetOutputSlot(0).SetTensorInfo(weightsTensor.
GetInfo());
1529 ignoreSlots.emplace_back(1u);
1534 auto biasLayer = m_Network->AddConstantLayer(biasTensor);
1535 biasLayer->GetOutputSlot(0).Connect(layer->
GetInputSlot(2u));
1536 biasLayer->GetOutputSlot(0).SetTensorInfo(biasTensor.
GetInfo());
1537 ignoreSlots.emplace_back(2u);
1542 layer = m_Network->AddConvolution2dLayer(descriptor,
1551 RegisterInputSlots(graph, layerIndex, layer, ignoreSlots);
1552 RegisterOutputSlots(graph, layerIndex, layer);
1555 void IDeserializer::DeserializerImpl::ParseConvolution3d(
GraphPtr graph,
unsigned int layerIndex)
1558 auto inputs = GetInputs(graph, layerIndex);
1561 auto outputs = GetOutputs(graph, layerIndex);
1564 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_Convolution3dLayer();
1565 auto layerName = GetLayerName(graph, layerIndex);
1566 auto serializerDescriptor = serializerLayer->descriptor();
1569 descriptor.
m_PadLeft = serializerDescriptor->padLeft();
1570 descriptor.
m_PadRight = serializerDescriptor->padRight();
1571 descriptor.
m_PadTop = serializerDescriptor->padTop();
1572 descriptor.
m_PadBottom = serializerDescriptor->padBottom();
1573 descriptor.
m_PadFront = serializerDescriptor->padFront();
1574 descriptor.
m_PadBack = serializerDescriptor->padBack();
1575 descriptor.
m_StrideX = serializerDescriptor->strideX();
1576 descriptor.
m_StrideY = serializerDescriptor->strideY();
1577 descriptor.
m_StrideZ = serializerDescriptor->strideZ();
1578 descriptor.
m_DilationX = serializerDescriptor->dilationX();
1579 descriptor.
m_DilationY = serializerDescriptor->dilationY();
1580 descriptor.
m_DilationZ = serializerDescriptor->dilationZ();
1581 descriptor.
m_BiasEnabled = serializerDescriptor->biasEnabled();
1587 IConnectableLayer* layer = m_Network->AddConvolution3dLayer(descriptor, layerName.c_str());
1592 RegisterInputSlots(graph, layerIndex, layer);
1593 RegisterOutputSlots(graph, layerIndex, layer);
1596 void IDeserializer::DeserializerImpl::ParseDepthToSpace(
GraphPtr graph,
unsigned int layerIndex)
1600 auto inputs = GetInputs(graph, layerIndex);
1603 auto outputs = GetOutputs(graph, layerIndex);
1606 auto fbDescriptor = graph->layers()->Get(layerIndex)->layer_as_DepthToSpaceLayer()->descriptor();
1609 descriptor.
m_BlockSize = fbDescriptor->blockSize();
1612 auto layerName = GetLayerName(graph, layerIndex);
1613 IConnectableLayer* layer = m_Network->AddDepthToSpaceLayer(descriptor, layerName.c_str());
1618 RegisterInputSlots(graph, layerIndex, layer);
1619 RegisterOutputSlots(graph, layerIndex, layer);
1622 void IDeserializer::DeserializerImpl::ParseDepthwiseConvolution2d(
GraphPtr graph,
unsigned int layerIndex)
1625 auto inputs = GetInputs(graph, layerIndex);
1628 auto outputs = GetOutputs(graph, layerIndex);
1631 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_DepthwiseConvolution2dLayer();
1632 auto layerName = GetLayerName(graph, layerIndex);
1633 auto serializerDescriptor = serializerLayer->descriptor();
1636 descriptor.
m_PadLeft = serializerDescriptor->padLeft();
1637 descriptor.
m_PadRight = serializerDescriptor->padRight();
1638 descriptor.
m_PadTop = serializerDescriptor->padTop();
1639 descriptor.
m_PadBottom = serializerDescriptor->padBottom();
1640 descriptor.
m_StrideX = serializerDescriptor->strideX();
1641 descriptor.
m_StrideY = serializerDescriptor->strideY();
1642 descriptor.
m_DilationX = serializerDescriptor->dilationX();
1643 descriptor.
m_DilationY = serializerDescriptor->dilationY();
1644 descriptor.
m_BiasEnabled = serializerDescriptor->biasEnabled();
1648 std::vector<unsigned int> ignoreSlots {};
1652 if (this->GetFeatureVersions(graph).m_ConstTensorsAsInputs <= 0)
1659 ignoreSlots.emplace_back(1u);
1661 layer = m_Network->AddDepthwiseConvolution2dLayer(descriptor,
1668 ignoreSlots.emplace_back(2u);
1670 auto biasLayer = m_Network->AddConstantLayer(biases);
1671 biasLayer->GetOutputSlot(0).Connect(layer->
GetInputSlot(2u));
1672 biasLayer->GetOutputSlot(0).SetTensorInfo(biases.
GetInfo());
1675 if (this->GetFeatureVersions(graph).m_WeightsLayoutScheme <= 0)
1681 std::unique_ptr<unsigned char[]> permuteBuffer(
new unsigned char[weightsInfo.
GetNumBytes()]);
1688 auto weightsShape = weightsInfo.
GetShape();
1692 weightsShape[2]*weightsShape[3]});
1696 auto weightsLayer = m_Network->AddConstantLayer(weightsPermuted);
1697 weightsLayer->GetOutputSlot(0).Connect(layer->
GetInputSlot(1u));
1698 weightsLayer->GetOutputSlot(0).SetTensorInfo(weightsPermuted.GetInfo());
1702 auto weightsLayer = m_Network->AddConstantLayer(weights);
1703 weightsLayer->GetOutputSlot(0).Connect(layer->
GetInputSlot(1u));
1704 weightsLayer->GetOutputSlot(0).SetTensorInfo(weights.
GetInfo());
1709 layer = m_Network->AddDepthwiseConvolution2dLayer(descriptor,
1718 RegisterInputSlots(graph, layerIndex, layer, ignoreSlots);
1719 RegisterOutputSlots(graph, layerIndex, layer);
1722 void IDeserializer::DeserializerImpl::ParseDetectionPostProcess(
GraphPtr graph,
unsigned int layerIndex)
1725 auto inputs = GetInputs(graph, layerIndex);
1729 auto outputs = GetOutputs(graph, layerIndex);
1732 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_DetectionPostProcessLayer();
1733 auto layerName = GetLayerName(graph, layerIndex);
1734 auto flatBufferDescriptor = flatBufferLayer->descriptor();
1742 descriptor.
m_NumClasses = flatBufferDescriptor->numClasses();
1744 descriptor.
m_ScaleX = flatBufferDescriptor->scaleX();
1745 descriptor.
m_ScaleY = flatBufferDescriptor->scaleY();
1746 descriptor.
m_ScaleW = flatBufferDescriptor->scaleW();
1747 descriptor.
m_ScaleH = flatBufferDescriptor->scaleH();
1755 for (
unsigned int i = 0; i < 4; i++)
1760 RegisterInputSlots(graph, layerIndex, layer);
1761 RegisterOutputSlots(graph, layerIndex, layer);
1764 void IDeserializer::DeserializerImpl::ParseDivision(
GraphPtr graph,
unsigned int layerIndex)
1767 auto inputs = GetInputs(graph, layerIndex);
1771 auto outputs = GetOutputs(graph, layerIndex);
1774 auto layerName = GetLayerName(graph, layerIndex);
1776 IConnectableLayer* layer = m_Network->AddElementwiseBinaryLayer(descriptor, layerName.c_str());
1781 RegisterInputSlots(graph, layerIndex, layer);
1782 RegisterOutputSlots(graph, layerIndex, layer);
1785 void IDeserializer::DeserializerImpl::ParseEqual(
GraphPtr graph,
unsigned int layerIndex)
1788 auto inputs = GetInputs(graph, layerIndex);
1792 auto outputs = GetOutputs(graph, layerIndex);
1795 auto layerName = GetLayerName(graph, layerIndex);
1797 IConnectableLayer* layer = m_Network->AddComparisonLayer(descriptor, layerName.c_str());
1802 RegisterInputSlots(graph, layerIndex, layer);
1803 RegisterOutputSlots(graph, layerIndex, layer);
1806 void IDeserializer::DeserializerImpl::ParseFill(
GraphPtr graph,
unsigned int layerIndex)
1809 auto inputs = GetInputs(graph, layerIndex);
1813 auto outputs = GetOutputs(graph, layerIndex);
1816 auto layerName = GetLayerName(graph, layerIndex);
1818 descriptor.
m_Value = graph->layers()->Get(layerIndex)->layer_as_FillLayer()->descriptor()->value();
1819 IConnectableLayer* layer = m_Network->AddFillLayer(descriptor, layerName.c_str());
1824 RegisterInputSlots(graph, layerIndex, layer);
1825 RegisterOutputSlots(graph, layerIndex, layer);
1828 void IDeserializer::DeserializerImpl::ParseGreater(
GraphPtr graph,
unsigned int layerIndex)
1831 auto inputs = GetInputs(graph, layerIndex);
1835 auto outputs = GetOutputs(graph, layerIndex);
1838 auto layerName = GetLayerName(graph, layerIndex);
1840 IConnectableLayer* layer = m_Network->AddComparisonLayer(descriptor, layerName.c_str());
1845 RegisterInputSlots(graph, layerIndex, layer);
1846 RegisterOutputSlots(graph, layerIndex, layer);
1849 void IDeserializer::DeserializerImpl::ParseInstanceNormalization(
GraphPtr graph,
unsigned int layerIndex)
1853 auto inputs = GetInputs(graph, layerIndex);
1856 auto outputs = GetOutputs(graph, layerIndex);
1859 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_InstanceNormalizationLayer();
1860 auto fbDescriptor = fbLayer->descriptor();
1863 descriptor.
m_Gamma = fbDescriptor->gamma();
1864 descriptor.
m_Beta = fbDescriptor->beta();
1865 descriptor.
m_Eps = fbDescriptor->eps();
1868 const std::string layerName = GetLayerName(graph, layerIndex);
1871 IConnectableLayer* layer = m_Network->AddInstanceNormalizationLayer(descriptor, layerName.c_str());
1874 RegisterInputSlots(graph, layerIndex, layer);
1875 RegisterOutputSlots(graph, layerIndex, layer);
1878 void IDeserializer::DeserializerImpl::ParseL2Normalization(
GraphPtr graph,
unsigned int layerIndex)
1882 auto inputs = GetInputs(graph, layerIndex);
1885 auto outputs = GetOutputs(graph, layerIndex);
1889 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_L2NormalizationLayer();
1890 auto flatBufferDescriptor = flatBufferLayer->descriptor();
1892 auto layerName = GetLayerName(graph, layerIndex);
1895 descriptor.
m_Eps = flatBufferDescriptor->eps();
1897 IConnectableLayer* layer = m_Network->AddL2NormalizationLayer(descriptor, layerName.c_str());
1900 RegisterInputSlots(graph, layerIndex, layer);
1901 RegisterOutputSlots(graph, layerIndex, layer);
1904 void IDeserializer::DeserializerImpl::ParseLogicalBinary(
GraphPtr graph,
unsigned int layerIndex)
1909 auto inputs = GetInputs(graph, layerIndex);
1912 auto outputs = GetOutputs(graph, layerIndex);
1915 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_LogicalBinaryLayer();
1916 auto fbDescriptor = fbLayer->descriptor();
1921 const std::string& layerName = GetLayerName(graph, layerIndex);
1922 IConnectableLayer* layer = m_Network->AddLogicalBinaryLayer(descriptor, layerName.c_str());
1927 RegisterInputSlots(graph, layerIndex, layer);
1928 RegisterOutputSlots(graph, layerIndex, layer);
1931 void IDeserializer::DeserializerImpl::ParseLogSoftmax(
GraphPtr graph,
unsigned int layerIndex)
1942 descriptor.
m_Beta = graph->layers()->Get(layerIndex)->layer_as_LogSoftmaxLayer()->descriptor()->beta();
1943 descriptor.
m_Axis = graph->layers()->Get(layerIndex)->layer_as_LogSoftmaxLayer()->descriptor()->axis();
1944 auto layerName = GetLayerName(graph, layerIndex);
1946 IConnectableLayer* layer = m_Network->AddLogSoftmaxLayer(descriptor, layerName.c_str());
1951 RegisterInputSlots(graph, layerIndex, layer);
1952 RegisterOutputSlots(graph, layerIndex, layer);
1955 void IDeserializer::DeserializerImpl::ParseMinimum(
GraphPtr graph,
unsigned int layerIndex)
1958 auto inputs = GetInputs(graph, layerIndex);
1962 auto outputs = GetOutputs(graph, layerIndex);
1965 auto layerName = GetLayerName(graph, layerIndex);
1967 IConnectableLayer* layer = m_Network->AddElementwiseBinaryLayer(descriptor, layerName.c_str());
1972 RegisterInputSlots(graph, layerIndex, layer);
1973 RegisterOutputSlots(graph, layerIndex, layer);
1976 void IDeserializer::DeserializerImpl::ParseMaximum(
GraphPtr graph,
unsigned int layerIndex)
1979 auto inputs = GetInputs(graph, layerIndex);
1983 auto outputs = GetOutputs(graph, layerIndex);
1986 auto layerName = GetLayerName(graph, layerIndex);
1988 IConnectableLayer* layer = m_Network->AddElementwiseBinaryLayer(descriptor, layerName.c_str());
1993 RegisterInputSlots(graph, layerIndex, layer);
1994 RegisterOutputSlots(graph, layerIndex, layer);
1998 unsigned int layerIndex)
2000 auto layerType = graph->layers()->Get(layerIndex)->layer_type();
2004 case Layer::Layer_ConcatLayer:
2005 return graph->layers()->Get(layerIndex)->layer_as_ConcatLayer()->descriptor();
2006 case Layer::Layer_MergerLayer:
2007 return graph->layers()->Get(layerIndex)->layer_as_MergerLayer()->descriptor();
2012 void IDeserializer::DeserializerImpl::ParseChannelShuffle(
GraphPtr graph,
unsigned int layerIndex)
2023 descriptor.
m_Axis = graph->layers()->Get(layerIndex)->layer_as_ChannelShuffleLayer()->descriptor()->axis();
2025 graph->layers()->Get(layerIndex)->layer_as_ChannelShuffleLayer()->descriptor()->numGroups();
2027 auto layerName = GetLayerName(graph, layerIndex);
2028 IConnectableLayer* layer = m_Network->AddChannelShuffleLayer(descriptor, layerName.c_str());
2033 RegisterInputSlots(graph, layerIndex, layer);
2034 RegisterOutputSlots(graph, layerIndex, layer);
2036 void IDeserializer::DeserializerImpl::ParseComparison(
GraphPtr graph,
unsigned int layerIndex)
2041 auto inputs = GetInputs(graph, layerIndex);
2044 auto outputs = GetOutputs(graph, layerIndex);
2047 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_ComparisonLayer();
2048 auto fbDescriptor = fbLayer->descriptor();
2053 const std::string& layerName = GetLayerName(graph, layerIndex);
2054 IConnectableLayer* layer = m_Network->AddComparisonLayer(descriptor, layerName.c_str());
2059 RegisterInputSlots(graph, layerIndex, layer);
2060 RegisterOutputSlots(graph, layerIndex, layer);
2063 void IDeserializer::DeserializerImpl::ParseElementwiseBinary(
GraphPtr graph,
unsigned int layerIndex)
2068 auto inputs = GetInputs(graph, layerIndex);
2071 auto outputs = GetOutputs(graph, layerIndex);
2074 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_ElementwiseBinaryLayer();
2075 auto fbDescriptor = fbLayer->descriptor();
2080 const std::string& layerName = GetLayerName(graph, layerIndex);
2081 IConnectableLayer* layer = m_Network->AddElementwiseBinaryLayer(descriptor, layerName.c_str());
2086 RegisterInputSlots(graph, layerIndex, layer);
2087 RegisterOutputSlots(graph, layerIndex, layer);
2090 void IDeserializer::DeserializerImpl::ParseElementwiseUnary(
GraphPtr graph,
unsigned int layerIndex)
2095 auto inputs = GetInputs(graph, layerIndex);
2098 auto outputs = GetOutputs(graph, layerIndex);
2101 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_ElementwiseUnaryLayer();
2102 auto fbDescriptor = fbLayer->descriptor();
2107 const std::string& layerName = GetLayerName(graph, layerIndex);
2108 IConnectableLayer* layer = m_Network->AddElementwiseUnaryLayer(descriptor, layerName.c_str());
2113 RegisterInputSlots(graph, layerIndex, layer);
2114 RegisterOutputSlots(graph, layerIndex, layer);
2117 void IDeserializer::DeserializerImpl::ParseConcat(
GraphPtr graph,
unsigned int layerIndex)
2122 auto outputs = GetOutputs(graph, layerIndex);
2125 auto layerName = GetLayerName(graph, layerIndex);
2127 unsigned int numViews = originsDescriptor->numViews();
2128 unsigned int numDimensions = originsDescriptor->numDimensions();
2131 auto inputs = GetInputs(graph, layerIndex);
2135 auto originsPtr = originsDescriptor->viewOrigins();
2136 for (
unsigned int v = 0; v < numViews; ++v)
2138 auto originPtr = originsPtr->Get(v);
2139 for (
unsigned int d = 0; d < numDimensions; ++d)
2141 uint32_t value = originPtr->data()->Get(d);
2142 descriptor.SetViewOriginCoord(v, d, value);
2145 descriptor.SetConcatAxis(originsDescriptor->concatAxis());
2147 IConnectableLayer* layer = m_Network->AddConcatLayer(descriptor, layerName.c_str());
2151 RegisterInputSlots(graph, layerIndex, layer);
2152 RegisterOutputSlots(graph, layerIndex, layer);
2155 void IDeserializer::DeserializerImpl::ParseMultiplication(
GraphPtr graph,
unsigned int layerIndex)
2158 auto inputs = GetInputs(graph, layerIndex);
2162 auto outputs = GetOutputs(graph, layerIndex);
2165 auto layerName = GetLayerName(graph, layerIndex);
2167 IConnectableLayer* layer = m_Network->AddElementwiseBinaryLayer(descriptor, layerName.c_str());
2172 RegisterInputSlots(graph, layerIndex, layer);
2173 RegisterOutputSlots(graph, layerIndex, layer);
2176 void IDeserializer::DeserializerImpl::ParseFloor(
GraphPtr graph,
unsigned int layerIndex)
2181 auto inputs = GetInputs(graph, layerIndex);
2184 auto outputs = GetOutputs(graph, layerIndex);
2187 auto layerName = GetLayerName(graph, layerIndex);
2191 layer = m_Network->AddFloorLayer(layerName.c_str());
2196 RegisterInputSlots(graph, layerIndex, layer);
2197 RegisterOutputSlots(graph, layerIndex, layer);
2200 void IDeserializer::DeserializerImpl::ParseFullyConnected(
GraphPtr graph,
unsigned int layerIndex)
2203 auto inputs = GetInputs(graph, layerIndex);
2206 auto outputs = GetOutputs(graph, layerIndex);
2209 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_FullyConnectedLayer();
2210 auto layerName = GetLayerName(graph, layerIndex);
2211 auto flatBufferDescriptor = flatBufferLayer->descriptor();
2214 fullyConnectedDescriptor.
m_BiasEnabled = flatBufferDescriptor->biasEnabled();
2216 fullyConnectedDescriptor.
m_ConstantWeights = flatBufferDescriptor->constantWeights();
2219 std::vector<unsigned int> ignoreSlots {};
2223 if (this->GetFeatureVersions(graph).m_ConstTensorsAsInputs <= 0)
2228 layer = m_Network->AddFullyConnectedLayer(fullyConnectedDescriptor,
2232 auto weightsLayer = m_Network->AddConstantLayer(weightsTensor);
2233 weightsLayer->GetOutputSlot(0).Connect(layer->
GetInputSlot(1u));
2234 weightsLayer->GetOutputSlot(0).SetTensorInfo(weightsTensor.
GetInfo());
2235 ignoreSlots.emplace_back(1u);
2240 auto biasLayer = m_Network->AddConstantLayer(biasTensor);
2241 biasLayer->GetOutputSlot(0).Connect(layer->
GetInputSlot(2u));
2242 biasLayer->GetOutputSlot(0).SetTensorInfo(biasTensor.
GetInfo());
2243 ignoreSlots.emplace_back(2u);
2248 layer = m_Network->AddFullyConnectedLayer(fullyConnectedDescriptor,
2250 uint32_t numInputs = fullyConnectedDescriptor.
GetNumInputs();
2257 RegisterInputSlots(graph, layerIndex, layer, ignoreSlots);
2258 RegisterOutputSlots(graph, layerIndex, layer);
2261 void IDeserializer::DeserializerImpl::ParsePad(
GraphPtr graph,
unsigned int layerIndex)
2271 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_PadLayer()->descriptor();
2272 auto flatBufferPadList = flatBufferDescriptor->padList();
2273 auto paddingMode = flatBufferDescriptor->paddingMode();
2274 float padValue = flatBufferDescriptor->padValue();
2276 if (flatBufferPadList->size() % 2 != 0)
2278 throw ParseException(fmt::format(
"The size of the pad list must be divisible by 2 {}",
2282 std::vector<std::pair<unsigned int, unsigned int>> padList;
2283 padList.reserve(flatBufferPadList->size() / 2);
2284 for (
unsigned int i = 0; i < flatBufferPadList->size() - 1; i += 2)
2286 padList.emplace_back(flatBufferPadList->Get(i), flatBufferPadList->Get(i+1));
2291 auto layerName = GetLayerName(graph, layerIndex);
2292 IConnectableLayer* layer = m_Network->AddPadLayer(descriptor, layerName.c_str());
2297 RegisterInputSlots(graph, layerIndex, layer);
2298 RegisterOutputSlots(graph, layerIndex, layer);
2301 void IDeserializer::DeserializerImpl::ParsePermute(
GraphPtr graph,
unsigned int layerIndex)
2306 graph->layers()->Get(layerIndex)->layer_as_PermuteLayer()->descriptor()->dimMappings();
2308 auto inputs = GetInputs(graph, layerIndex);
2311 auto outputs = GetOutputs(graph, layerIndex);
2315 auto layerName = GetLayerName(graph, layerIndex);
2318 IConnectableLayer* layer = m_Network->AddPermuteLayer(descriptor, layerName.c_str());
2321 RegisterInputSlots(graph, layerIndex, layer);
2322 RegisterOutputSlots(graph, layerIndex, layer);
2326 unsigned int layerIndex)
2331 switch (pooling2dDesc->poolType())
2333 case PoolingAlgorithm_Average:
2338 case PoolingAlgorithm_Max:
2343 case PoolingAlgorithm_L2:
2354 switch (pooling2dDesc->outputShapeRounding())
2356 case OutputShapeRounding_Floor:
2361 case OutputShapeRounding_Ceiling:
2372 switch (pooling2dDesc->paddingMethod())
2374 case PaddingMethod_Exclude:
2379 case PaddingMethod_IgnoreValue:
2390 switch (pooling2dDesc->dataLayout())
2392 case DataLayout_NCHW:
2397 case DataLayout_NHWC:
2409 desc.
m_PadLeft = pooling2dDesc->padLeft();
2411 desc.
m_PadTop = pooling2dDesc->padTop();
2412 desc.
m_StrideX = pooling2dDesc->strideX();
2413 desc.
m_StrideY = pooling2dDesc->strideY();
2421 unsigned int layerIndex)
2426 switch (pooling3dDesc->poolType())
2428 case PoolingAlgorithm_Average:
2433 case PoolingAlgorithm_Max:
2438 case PoolingAlgorithm_L2:
2449 switch (pooling3dDesc->outputShapeRounding())
2451 case OutputShapeRounding_Floor:
2456 case OutputShapeRounding_Ceiling:
2467 switch (pooling3dDesc->paddingMethod())
2469 case PaddingMethod_Exclude:
2474 case PaddingMethod_IgnoreValue:
2485 switch (pooling3dDesc->dataLayout())
2487 case DataLayout_NCDHW:
2492 case DataLayout_NDHWC:
2504 desc.
m_PadLeft = pooling3dDesc->padLeft();
2506 desc.
m_PadTop = pooling3dDesc->padTop();
2508 desc.
m_PadBack = pooling3dDesc->padBack();
2509 desc.
m_StrideX = pooling3dDesc->strideX();
2510 desc.
m_StrideY = pooling3dDesc->strideY();
2511 desc.
m_StrideZ = pooling3dDesc->strideZ();
2519 void IDeserializer::DeserializerImpl::ParsePooling2d(
GraphPtr graph,
unsigned int layerIndex)
2523 auto pooling2dDes = graph->layers()->Get(layerIndex)->layer_as_Pooling2dLayer()->descriptor();
2524 auto inputs = GetInputs(graph, layerIndex);
2527 auto outputs = GetOutputs(graph, layerIndex);
2531 auto pooling2dDescriptor = GetPooling2dDescriptor(pooling2dDes, layerIndex);
2532 auto layerName = GetLayerName(graph, layerIndex);
2533 IConnectableLayer* layer = m_Network->AddPooling2dLayer(pooling2dDescriptor, layerName.c_str());
2536 RegisterInputSlots(graph, layerIndex, layer);
2537 RegisterOutputSlots(graph, layerIndex, layer);
2540 void IDeserializer::DeserializerImpl::ParsePooling3d(
GraphPtr graph,
unsigned int layerIndex)
2544 auto pooling3dDes = graph->layers()->Get(layerIndex)->layer_as_Pooling3dLayer()->descriptor();
2545 auto inputs = GetInputs(graph, layerIndex);
2548 auto outputs = GetOutputs(graph, layerIndex);
2552 auto pooling3dDescriptor = GetPooling3dDescriptor(pooling3dDes, layerIndex);
2553 auto layerName = GetLayerName(graph, layerIndex);
2554 IConnectableLayer* layer = m_Network->AddPooling3dLayer(pooling3dDescriptor, layerName.c_str());
2557 RegisterInputSlots(graph, layerIndex, layer);
2558 RegisterOutputSlots(graph, layerIndex, layer);
2561 void IDeserializer::DeserializerImpl::ParseQuantize(
GraphPtr graph,
unsigned int layerIndex)
2565 auto inputs = GetInputs(graph, layerIndex);
2568 auto outputs = GetOutputs(graph, layerIndex);
2572 auto layerName = GetLayerName(graph, layerIndex);
2576 RegisterInputSlots(graph, layerIndex, layer);
2577 RegisterOutputSlots(graph, layerIndex, layer);
2581 const std::vector<uint32_t>& targetDimsIn)
2583 std::vector<unsigned int> outputDims(targetDimsIn.begin(), targetDimsIn.end());
2584 const auto stretchDim = std::find(targetDimsIn.begin(), targetDimsIn.end(), -1);
2586 if (stretchDim != targetDimsIn.end())
2588 if (std::find(std::next(stretchDim), targetDimsIn.end(), -1) != targetDimsIn.end())
2590 throw ParseException(fmt::format(
"At most one component of shape can be -1 {}",
2594 auto targetNumElements =
2595 armnn::numeric_cast<unsigned int>(
2596 std::accumulate(targetDimsIn.begin(), targetDimsIn.end(), -1, std::multiplies<int32_t>()));
2598 auto stretchIndex =
static_cast<size_t>(std::distance(targetDimsIn.begin(), stretchDim));
2599 outputDims[stretchIndex] = inputTensorInfo.
GetNumElements() / targetNumElements;
2610 void IDeserializer::DeserializerImpl::ParseRank(
GraphPtr graph,
unsigned int layerIndex)
2620 auto layerName = GetLayerName(graph, layerIndex);
2626 RegisterInputSlots(graph, layerIndex, layer);
2627 RegisterOutputSlots(graph, layerIndex, layer);
2630 void IDeserializer::DeserializerImpl::ParseReduce(
GraphPtr graph,
unsigned int layerIndex)
2635 auto inputs = GetInputs(graph, layerIndex);
2638 auto outputs = GetOutputs(graph, layerIndex);
2641 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_ReduceLayer();
2642 auto fbDescriptor = fbLayer->descriptor();
2643 auto flatBufferAxis = fbDescriptor->axis();
2646 descriptor.
m_KeepDims = fbDescriptor->keepDims();
2647 descriptor.
m_vAxis = std::vector<unsigned int>(flatBufferAxis->begin(), flatBufferAxis->end());
2650 const std::string& layerName = GetLayerName(graph, layerIndex);
2651 IConnectableLayer* layer = m_Network->AddReduceLayer(descriptor, layerName.c_str());
2656 RegisterInputSlots(graph, layerIndex, layer);
2657 RegisterOutputSlots(graph, layerIndex, layer);
2660 void IDeserializer::DeserializerImpl::ParseReshape(
GraphPtr graph,
unsigned int layerIndex)
2663 auto inputs = GetInputs(graph, layerIndex);
2665 auto outputs = GetOutputs(graph, layerIndex);
2671 const auto targetDims = graph->layers()->Get(layerIndex)->layer_as_ReshapeLayer()->descriptor()->targetShape();
2672 std::vector<uint32_t> outputDims(targetDims->begin(), targetDims->begin() + targetDims->size());
2677 const std::vector<uint32_t> expectedDims(outputs[0]->dimensions()->begin(),
2678 outputs[0]->dimensions()->begin() + outputs[0]->dimensions()->size());
2680 if (inputs.size() > 1 && !
CheckShape(reshapeOutputTensorShape, expectedDims))
2682 std::stringstream ss;
2683 ss <<
"New shape defined in reshape parameters "
2684 << reshapeOutputTensorShape
2685 <<
" does not equal output shape "
2686 << actualOutputTensorInfo.
GetShape()
2695 auto layerName = GetLayerName(graph, layerIndex);
2696 IConnectableLayer* layer = m_Network->AddReshapeLayer(reshapeDesc, layerName.c_str());
2699 RegisterInputSlots(graph, layerIndex, layer);
2700 RegisterOutputSlots(graph, layerIndex, layer);
2703 void IDeserializer::DeserializerImpl::ParseResize(
GraphPtr graph,
unsigned int layerIndex)
2713 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_ResizeLayer()->descriptor();
2716 descriptor.
m_TargetWidth = flatBufferDescriptor->targetWidth();
2717 descriptor.
m_TargetHeight = flatBufferDescriptor->targetHeight();
2720 descriptor.
m_AlignCorners = flatBufferDescriptor->alignCorners();
2723 auto layerName = GetLayerName(graph, layerIndex);
2724 IConnectableLayer* layer = m_Network->AddResizeLayer(descriptor, layerName.c_str());
2729 RegisterInputSlots(graph, layerIndex, layer);
2730 RegisterOutputSlots(graph, layerIndex, layer);
2736 void IDeserializer::DeserializerImpl::ParseResizeBilinear(
GraphPtr graph,
unsigned int layerIndex)
2746 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_ResizeBilinearLayer()->descriptor();
2749 descriptor.
m_TargetWidth = flatBufferDescriptor->targetWidth();
2750 descriptor.
m_TargetHeight = flatBufferDescriptor->targetHeight();
2753 descriptor.
m_AlignCorners = flatBufferDescriptor->alignCorners();
2756 auto layerName = GetLayerName(graph, layerIndex);
2757 IConnectableLayer* layer = m_Network->AddResizeLayer(descriptor, layerName.c_str());
2762 RegisterInputSlots(graph, layerIndex, layer);
2763 RegisterOutputSlots(graph, layerIndex, layer);
2766 void IDeserializer::DeserializerImpl::ParseShape(
GraphPtr graph,
unsigned int layerIndex)
2776 auto layerName = GetLayerName(graph, layerIndex);
2782 RegisterInputSlots(graph, layerIndex, layer);
2783 RegisterOutputSlots(graph, layerIndex, layer);
2786 void IDeserializer::DeserializerImpl::ParseSoftmax(
GraphPtr graph,
unsigned int layerIndex)
2797 descriptor.
m_Beta = graph->layers()->Get(layerIndex)->layer_as_SoftmaxLayer()->descriptor()->beta();
2798 descriptor.
m_Axis = graph->layers()->Get(layerIndex)->layer_as_SoftmaxLayer()->descriptor()->axis();
2799 auto layerName = GetLayerName(graph, layerIndex);
2801 IConnectableLayer* layer = m_Network->AddSoftmaxLayer(descriptor, layerName.c_str());
2806 RegisterInputSlots(graph, layerIndex, layer);
2807 RegisterOutputSlots(graph, layerIndex, layer);
2810 void IDeserializer::DeserializerImpl::ParseSpaceToBatchNd(
GraphPtr graph,
unsigned int layerIndex)
2820 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_SpaceToBatchNdLayer()->descriptor();
2821 auto flatBufferPadList = flatBufferDescriptor->padList();
2822 auto flatBufferBlockShape = flatBufferDescriptor->blockShape();
2824 if (flatBufferPadList->size() % 2 != 0)
2826 throw ParseException(fmt::format(
"The size of the pad list must be divisible by 2 {}",
2830 std::vector<std::pair<unsigned int, unsigned int>> padList;
2831 padList.reserve(flatBufferPadList->size() / 2);
2832 for (
unsigned int i = 0; i < flatBufferPadList->size() - 1; i += 2)
2834 padList.emplace_back(flatBufferPadList->Get(i), flatBufferPadList->Get(i+1));
2840 std::vector<unsigned int>(flatBufferBlockShape->begin(), flatBufferBlockShape->end());
2843 auto layerName = GetLayerName(graph, layerIndex);
2844 IConnectableLayer* layer = m_Network->AddSpaceToBatchNdLayer(descriptor, layerName.c_str());
2849 RegisterInputSlots(graph, layerIndex, layer);
2850 RegisterOutputSlots(graph, layerIndex, layer);
2853 void IDeserializer::DeserializerImpl::ParseSpaceToDepth(
GraphPtr graph,
unsigned int layerIndex)
2863 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_SpaceToDepthLayer()->descriptor();
2866 descriptor.
m_BlockSize = flatBufferDescriptor->blockSize();
2869 auto layerName = GetLayerName(graph, layerIndex);
2870 IConnectableLayer* layer = m_Network->AddSpaceToDepthLayer(descriptor, layerName.c_str());
2875 RegisterInputSlots(graph, layerIndex, layer);
2876 RegisterOutputSlots(graph, layerIndex, layer);
2881 unsigned int layerIndex)
2886 switch (normalizationDescriptor->normChannelType())
2888 case NormalizationAlgorithmChannel_Across:
2893 case NormalizationAlgorithmChannel_Within:
2904 switch (normalizationDescriptor->normMethodType())
2906 case NormalizationAlgorithmMethod_LocalBrightness:
2911 case NormalizationAlgorithmMethod_LocalContrast:
2922 switch (normalizationDescriptor->dataLayout())
2924 case DataLayout_NCHW:
2929 case DataLayout_NHWC:
2940 desc.
m_Alpha = normalizationDescriptor->alpha();
2941 desc.
m_Beta = normalizationDescriptor->beta();
2942 desc.
m_K = normalizationDescriptor->k();
2943 desc.
m_NormSize = normalizationDescriptor->normSize();
2948 void IDeserializer::DeserializerImpl::ParseNormalization(
GraphPtr graph,
unsigned int layerIndex)
2952 auto normalizationDes = graph->layers()->Get(layerIndex)->layer_as_NormalizationLayer()->descriptor();
2962 auto normalizationDescriptor = GetNormalizationDescriptor(normalizationDes, layerIndex);
2963 auto layerName = GetLayerName(graph, layerIndex);
2965 IConnectableLayer* layer = m_Network->AddNormalizationLayer(normalizationDescriptor, layerName.c_str());
2968 RegisterInputSlots(graph, layerIndex, layer);
2969 RegisterOutputSlots(graph, layerIndex, layer);
2972 void IDeserializer::DeserializerImpl::ParseRsqrt(
GraphPtr graph,
unsigned int layerIndex)
2975 auto inputs = GetInputs(graph, layerIndex);
2979 auto outputs = GetOutputs(graph, layerIndex);
2982 auto layerName = GetLayerName(graph, layerIndex);
2985 IConnectableLayer* layer = m_Network->AddElementwiseUnaryLayer(descriptor, layerName.c_str());
2989 RegisterInputSlots(graph, layerIndex, layer);
2990 RegisterOutputSlots(graph, layerIndex, layer);
2993 void IDeserializer::DeserializerImpl::ParseSlice(
GraphPtr graph,
unsigned int layerIndex)
2997 auto inputs = GetInputs(graph, layerIndex);
3000 auto outputs = GetOutputs(graph, layerIndex);
3003 auto fbDescriptor = graph->layers()->Get(layerIndex)->layer_as_SliceLayer()->descriptor();
3005 auto fbBegin = fbDescriptor->begin();
3006 auto fbSize = fbDescriptor->size();
3008 if (fbBegin->size() != fbSize->size())
3010 throw ParseException(fmt::format(
"Begin and size descriptors must have the same length {}",
3015 descriptor.
m_Begin.insert(descriptor.
m_Begin.end(), fbBegin->begin(), fbBegin->end());
3016 descriptor.
m_Size.insert(descriptor.
m_Size.end(), fbSize->begin(), fbSize->end());
3018 auto layerName = GetLayerName(graph, layerIndex);
3019 IConnectableLayer* layer = m_Network->AddSliceLayer(descriptor, layerName.c_str());
3024 RegisterInputSlots(graph, layerIndex, layer);
3025 RegisterOutputSlots(graph, layerIndex, layer);
3028 void IDeserializer::DeserializerImpl::ParseStridedSlice(
GraphPtr graph,
unsigned int layerIndex)
3038 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_StridedSliceLayer()->descriptor();
3040 auto flatBufferBegin = flatBufferDescriptor->begin();
3041 auto flatBufferEnd = flatBufferDescriptor->end();
3042 auto flatBufferStride = flatBufferDescriptor->stride();
3044 if (!(flatBufferBegin->size() == flatBufferEnd->size() &&
3045 flatBufferBegin->size() == flatBufferStride->size()))
3047 throw ParseException(fmt::format(
"The size of the begin, end, and stride must be equal {}",
3051 std::vector<int> begin(flatBufferBegin->begin(), flatBufferBegin->end());
3052 std::vector<int> end(flatBufferEnd->begin(), flatBufferEnd->end());
3053 std::vector<int> stride(flatBufferStride->begin(), flatBufferStride->end());
3056 descriptor.m_BeginMask = flatBufferDescriptor->beginMask();
3057 descriptor.m_EndMask = flatBufferDescriptor->endMask();
3058 descriptor.m_ShrinkAxisMask = flatBufferDescriptor->shrinkAxisMask();
3059 descriptor.m_EllipsisMask = flatBufferDescriptor->ellipsisMask();
3060 descriptor.m_NewAxisMask = flatBufferDescriptor->newAxisMask();
3061 descriptor.m_DataLayout =
ToDataLayout(flatBufferDescriptor->dataLayout());
3063 auto layerName = GetLayerName(graph, layerIndex);
3064 IConnectableLayer* layer = m_Network->AddStridedSliceLayer(descriptor, layerName.c_str());
3069 RegisterInputSlots(graph, layerIndex, layer);
3070 RegisterOutputSlots(graph, layerIndex, layer);
3073 void IDeserializer::DeserializerImpl::ParseSubtraction(
GraphPtr graph,
unsigned int layerIndex)
3076 auto inputs = GetInputs(graph, layerIndex);
3080 auto outputs = GetOutputs(graph, layerIndex);
3083 auto layerName = GetLayerName(graph, layerIndex);
3085 IConnectableLayer* layer = m_Network->AddElementwiseBinaryLayer(descriptor, layerName.c_str());
3090 RegisterInputSlots(graph, layerIndex, layer);
3091 RegisterOutputSlots(graph, layerIndex, layer);
3094 void IDeserializer::DeserializerImpl::ParseGather(
GraphPtr graph,
unsigned int layerIndex)
3105 descriptor.
m_Axis = graph->layers()->Get(layerIndex)->layer_as_GatherLayer()->descriptor()->axis();
3107 auto layerName = GetLayerName(graph, layerIndex);
3108 IConnectableLayer* layer = m_Network->AddGatherLayer(descriptor, layerName.c_str());
3113 RegisterInputSlots(graph, layerIndex, layer);
3114 RegisterOutputSlots(graph, layerIndex, layer);
3117 void IDeserializer::DeserializerImpl::ParseGatherNd(
GraphPtr graph,
unsigned int layerIndex)
3127 auto layerName = GetLayerName(graph, layerIndex);
3133 RegisterInputSlots(graph, layerIndex, layer);
3134 RegisterOutputSlots(graph, layerIndex, layer);
3137 void IDeserializer::DeserializerImpl::ParseMean(
GraphPtr graph,
unsigned int layerIndex)
3147 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_MeanLayer()->descriptor();
3148 auto flatBufferAxis = flatBufferDescriptor->axis();
3149 auto flatBufferKeepDims = flatBufferDescriptor->keepDims();
3152 descriptor.
m_Axis = std::vector<unsigned int>(flatBufferAxis->begin(), flatBufferAxis->end());
3155 auto layerName = GetLayerName(graph, layerIndex);
3156 IConnectableLayer* layer = m_Network->AddMeanLayer(descriptor, layerName.c_str());
3161 RegisterInputSlots(graph, layerIndex, layer);
3162 RegisterOutputSlots(graph, layerIndex, layer);
3165 void IDeserializer::DeserializerImpl::ParseSplitter(
GraphPtr graph,
unsigned int layerIndex)
3174 auto flatBufferViewsDescriptor = graph->layers()->Get(layerIndex)->layer_as_SplitterLayer()->descriptor();
3175 auto flatBufferViewSizes = flatBufferViewsDescriptor->viewSizes();
3176 auto flatBufferOriginsDescriptor = flatBufferViewsDescriptor->origins();
3177 auto flatBufferViewOrigins = flatBufferOriginsDescriptor->viewOrigins();
3178 uint32_t numViews = flatBufferOriginsDescriptor->numViews();
3179 uint32_t numDimensions = flatBufferOriginsDescriptor->numDimensions();
3186 for(
unsigned int vIdx = 0; vIdx < numViews; ++vIdx)
3188 for (
unsigned int dIdx = 0; dIdx < numDimensions; ++dIdx)
3190 viewsDescriptor.SetViewSize(vIdx, dIdx, flatBufferViewSizes->Get(vIdx)->data()->Get(dIdx));
3191 viewsDescriptor.SetViewOriginCoord(vIdx, dIdx, flatBufferViewOrigins->Get(vIdx)->data()->Get(dIdx));
3195 auto layerName = GetLayerName(graph, layerIndex);
3196 IConnectableLayer* layer = m_Network->AddSplitterLayer(viewsDescriptor, layerName.c_str());
3199 for(
unsigned int vIdx = 0; vIdx < numViews; ++vIdx)
3205 RegisterInputSlots(graph, layerIndex, layer);
3206 RegisterOutputSlots(graph, layerIndex, layer);
3224 void IDeserializer::DeserializerImpl::ParseLstm(
GraphPtr graph,
unsigned int layerIndex)
3228 auto inputs = GetInputs(graph, layerIndex);
3231 auto outputs = GetOutputs(graph, layerIndex);
3234 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_LstmLayer();
3235 auto layerName = GetLayerName(graph, layerIndex);
3236 auto flatBufferDescriptor = flatBufferLayer->descriptor();
3237 auto flatBufferInputParams = flatBufferLayer->inputParams();
3239 auto lstmDescriptor = GetLstmDescriptor(flatBufferDescriptor);
3267 if (!lstmDescriptor.m_CifgEnabled)
3269 inputToInputWeights =
ToConstTensor(flatBufferInputParams->inputToInputWeights());
3270 recurrentToInputWeights =
ToConstTensor(flatBufferInputParams->recurrentToInputWeights());
3271 cellToInputWeights =
ToConstTensor(flatBufferInputParams->cellToInputWeights());
3272 inputGateBias =
ToConstTensor(flatBufferInputParams->inputGateBias());
3282 if (lstmDescriptor.m_ProjectionEnabled)
3284 projectionWeights =
ToConstTensor(flatBufferInputParams->projectionWeights());
3285 projectionBias =
ToConstTensor(flatBufferInputParams->projectionBias());
3293 if (lstmDescriptor.m_PeepholeEnabled)
3295 cellToForgetWeights =
ToConstTensor(flatBufferInputParams->cellToForgetWeights());
3296 cellToOutputWeights =
ToConstTensor(flatBufferInputParams->cellToOutputWeights());
3306 if (lstmDescriptor.m_LayerNormEnabled)
3308 if (!lstmDescriptor.m_CifgEnabled)
3310 inputLayerNormWeights =
ToConstTensor(flatBufferInputParams->inputLayerNormWeights());
3313 forgetLayerNormWeights =
ToConstTensor(flatBufferInputParams->forgetLayerNormWeights());
3314 cellLayerNormWeights =
ToConstTensor(flatBufferInputParams->cellLayerNormWeights());
3315 outputLayerNormWeights =
ToConstTensor(flatBufferInputParams->outputLayerNormWeights());
3322 IConnectableLayer* layer = m_Network->AddLstmLayer(lstmDescriptor, lstmInputParams, layerName.c_str());
3336 RegisterInputSlots(graph, layerIndex, layer);
3337 RegisterOutputSlots(graph, layerIndex, layer);
3349 desc.
m_CellClip = qLstmDescriptor->cellClip();
3363 void IDeserializer::DeserializerImpl::ParseQLstm(
GraphPtr graph,
unsigned int layerIndex)
3367 auto inputs = GetInputs(graph, layerIndex);
3370 auto outputs = GetOutputs(graph, layerIndex);
3373 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_QLstmLayer();
3374 auto layerName = GetLayerName(graph, layerIndex);
3375 auto flatBufferDescriptor = flatBufferLayer->descriptor();
3376 auto flatBufferInputParams = flatBufferLayer->inputParams();
3378 auto qLstmDescriptor = GetQLstmDescriptor(flatBufferDescriptor);
3407 if (!qLstmDescriptor.m_CifgEnabled)
3409 inputToInputWeights =
ToConstTensor(flatBufferInputParams->inputToInputWeights());
3410 recurrentToInputWeights =
ToConstTensor(flatBufferInputParams->recurrentToInputWeights());
3411 inputGateBias =
ToConstTensor(flatBufferInputParams->inputGateBias());
3422 if (qLstmDescriptor.m_ProjectionEnabled)
3424 projectionWeights =
ToConstTensor(flatBufferInputParams->projectionWeights());
3425 projectionBias =
ToConstTensor(flatBufferInputParams->projectionBias());
3436 if (qLstmDescriptor.m_PeepholeEnabled)
3438 if (!qLstmDescriptor.m_CifgEnabled)
3440 cellToInputWeights =
ToConstTensor(flatBufferInputParams->cellToInputWeights());
3444 cellToForgetWeights =
ToConstTensor(flatBufferInputParams->cellToForgetWeights());
3445 cellToOutputWeights =
ToConstTensor(flatBufferInputParams->cellToOutputWeights());
3457 if (qLstmDescriptor.m_LayerNormEnabled)
3459 if (!qLstmDescriptor.m_CifgEnabled)
3461 inputLayerNormWeights =
ToConstTensor(flatBufferInputParams->inputLayerNormWeights());
3465 forgetLayerNormWeights =
ToConstTensor(flatBufferInputParams->forgetLayerNormWeights());
3466 cellLayerNormWeights =
ToConstTensor(flatBufferInputParams->cellLayerNormWeights());
3467 outputLayerNormWeights =
ToConstTensor(flatBufferInputParams->outputLayerNormWeights());
3474 IConnectableLayer* layer = m_Network->AddQLstmLayer(qLstmDescriptor, qLstmInputParams, layerName.c_str());
3485 RegisterInputSlots(graph, layerIndex, layer);
3486 RegisterOutputSlots(graph, layerIndex, layer);
3489 void IDeserializer::DeserializerImpl::ParseQuantizedLstm(
GraphPtr graph,
unsigned int layerIndex)
3493 auto inputs = GetInputs(graph, layerIndex);
3496 auto outputs = GetOutputs(graph, layerIndex);
3499 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_QuantizedLstmLayer();
3500 auto layerName = GetLayerName(graph, layerIndex);
3501 auto flatBufferInputParams = flatBufferLayer->inputParams();
3531 IConnectableLayer* layer = m_Network->AddQuantizedLstmLayer(lstmInputParams, layerName.c_str());
3539 RegisterInputSlots(graph, layerIndex, layer);
3540 RegisterOutputSlots(graph, layerIndex, layer);
3543 void IDeserializer::DeserializerImpl::ParseDequantize(
GraphPtr graph,
unsigned int layerIndex)
3553 const std::string layerName = GetLayerName(graph, layerIndex);
3559 RegisterInputSlots(graph, layerIndex, layer);
3560 RegisterOutputSlots(graph, layerIndex, layer);
3563 void IDeserializer::DeserializerImpl::ParseMerge(
GraphPtr graph,
unsigned int layerIndex)
3573 const std::string layerName = GetLayerName(graph, layerIndex);
3579 RegisterInputSlots(graph, layerIndex, layer);
3580 RegisterOutputSlots(graph, layerIndex, layer);
3583 void IDeserializer::DeserializerImpl::ParseSwitch(
GraphPtr graph,
unsigned int layerIndex)
3586 auto inputs = GetInputs(graph, layerIndex);
3590 auto outputs = GetOutputs(graph, layerIndex);
3593 auto layerName = GetLayerName(graph, layerIndex);
3602 RegisterInputSlots(graph, layerIndex, layer);
3603 RegisterOutputSlots(graph, layerIndex, layer);
3606 void IDeserializer::DeserializerImpl::ParsePrelu(
GraphPtr graph,
unsigned int layerIndex)
3609 auto inputs = GetInputs(graph, layerIndex);
3613 auto outputs = GetOutputs(graph, layerIndex);
3616 auto layerName = GetLayerName(graph, layerIndex);
3622 RegisterInputSlots(graph, layerIndex, layer);
3623 RegisterOutputSlots(graph, layerIndex, layer);
3626 void IDeserializer::DeserializerImpl::ParseTranspose(
GraphPtr graph,
unsigned int layerIndex)
3630 auto dimsMapping = graph->layers()->Get(layerIndex)->layer_as_TransposeLayer()->descriptor()->dimMappings();
3632 auto inputs = GetInputs(graph, layerIndex);
3635 auto outputs = GetOutputs(graph, layerIndex);
3639 auto layerName = GetLayerName(graph, layerIndex);
3642 IConnectableLayer* layer = m_Network->AddTransposeLayer(descriptor, layerName.c_str());
3645 RegisterInputSlots(graph, layerIndex, layer);
3646 RegisterOutputSlots(graph, layerIndex, layer);
3649 void IDeserializer::DeserializerImpl::ParseTransposeConvolution2d(
GraphPtr graph,
unsigned int layerIndex)
3653 auto inputs = GetInputs(graph, layerIndex);
3656 auto outputs = GetOutputs(graph, layerIndex);
3659 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_TransposeConvolution2dLayer();
3660 auto layerName = GetLayerName(graph, layerIndex);
3661 auto serializerDescriptor = serializerLayer->descriptor();
3664 descriptor.
m_PadLeft = serializerDescriptor->padLeft();
3665 descriptor.
m_PadRight = serializerDescriptor->padRight();
3666 descriptor.
m_PadTop = serializerDescriptor->padTop();
3667 descriptor.
m_PadBottom = serializerDescriptor->padBottom();
3668 descriptor.
m_StrideX = serializerDescriptor->strideX();
3669 descriptor.
m_StrideY = serializerDescriptor->strideY();;
3670 descriptor.
m_BiasEnabled = serializerDescriptor->biasEnabled();;
3679 optionalBiases = armnn::MakeOptional<armnn::ConstTensor>(biases);
3682 IConnectableLayer* layer = m_Network->AddTransposeConvolution2dLayer(descriptor,
3690 RegisterInputSlots(graph, layerIndex, layer);
3691 RegisterOutputSlots(graph, layerIndex, layer);
3694 void IDeserializer::DeserializerImpl::ParseStack(
GraphPtr graph,
unsigned int layerIndex)
3697 auto inputs = GetInputs(graph, layerIndex);
3699 auto outputs = GetOutputs(graph, layerIndex);
3702 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_StackLayer()->descriptor();
3703 unsigned int axis = flatBufferDescriptor->axis();
3704 unsigned int numInputs = flatBufferDescriptor->numInputs();
3707 auto flatBufferInputShape = flatBufferDescriptor->inputShape();
3708 std::vector<uint32_t> vectorInputShape(flatBufferInputShape->begin(),
3709 flatBufferInputShape->begin() + flatBufferInputShape->size());
3711 TensorShape inputShape(
static_cast<unsigned int>(vectorInputShape.size()), vectorInputShape.data());
3714 for (
unsigned int i=0; i<inputs.size(); ++i)
3717 if (descriptor.m_InputShape != inputShape)
3719 std::stringstream ss;
3720 ss <<
"Shape of input "
3724 <<
" does not equal defined input shape "
3725 << descriptor.m_InputShape
3732 auto layerName = GetLayerName(graph, layerIndex);
3733 IConnectableLayer* layer = m_Network->AddStackLayer(descriptor, layerName.c_str());
3738 RegisterInputSlots(graph, layerIndex, layer);
3739 RegisterOutputSlots(graph, layerIndex, layer);
3742 void IDeserializer::DeserializerImpl::ParseStandIn(
GraphPtr graph,
unsigned int layerIndex)
3746 auto inputs = GetInputs(graph, layerIndex);
3747 auto outputs = GetOutputs(graph, layerIndex);
3749 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_StandInLayer();
3750 auto fbDescriptor = fbLayer->descriptor();
3753 descriptor.
m_NumInputs = fbDescriptor->numInputs();
3759 const std::string layerName = GetLayerName(graph, layerIndex);
3762 for (
unsigned int i = 0u; i < descriptor.
m_NumOutputs; ++i)
3768 RegisterInputSlots(graph, layerIndex, layer);
3769 RegisterOutputSlots(graph, layerIndex, layer);
3789 void IDeserializer::DeserializerImpl::ParseUnidirectionalSequenceLstm(
GraphPtr graph,
unsigned int layerIndex)
3793 auto inputs = GetInputs(graph, layerIndex);
3796 auto outputs = GetOutputs(graph, layerIndex);
3799 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_UnidirectionalSequenceLstmLayer();
3800 auto layerName = GetLayerName(graph, layerIndex);
3801 auto flatBufferDescriptor = flatBufferLayer->descriptor();
3802 auto flatBufferInputParams = flatBufferLayer->inputParams();
3804 auto descriptor = GetUnidirectionalSequenceLstmDescriptor(flatBufferDescriptor);
3832 if (!descriptor.m_CifgEnabled)
3834 inputToInputWeights =
ToConstTensor(flatBufferInputParams->inputToInputWeights());
3835 recurrentToInputWeights =
ToConstTensor(flatBufferInputParams->recurrentToInputWeights());
3836 inputGateBias =
ToConstTensor(flatBufferInputParams->inputGateBias());
3842 if (descriptor.m_PeepholeEnabled)
3844 cellToInputWeights =
ToConstTensor(flatBufferInputParams->cellToInputWeights());
3851 if (descriptor.m_ProjectionEnabled)
3853 projectionWeights =
ToConstTensor(flatBufferInputParams->projectionWeights());
3854 projectionBias =
ToConstTensor(flatBufferInputParams->projectionBias());
3862 if (descriptor.m_PeepholeEnabled)
3864 cellToForgetWeights =
ToConstTensor(flatBufferInputParams->cellToForgetWeights());
3865 cellToOutputWeights =
ToConstTensor(flatBufferInputParams->cellToOutputWeights());
3875 if (descriptor.m_LayerNormEnabled)
3877 if (!descriptor.m_CifgEnabled)
3879 inputLayerNormWeights =
ToConstTensor(flatBufferInputParams->inputLayerNormWeights());
3882 forgetLayerNormWeights =
ToConstTensor(flatBufferInputParams->forgetLayerNormWeights());
3883 cellLayerNormWeights =
ToConstTensor(flatBufferInputParams->cellLayerNormWeights());
3884 outputLayerNormWeights =
ToConstTensor(flatBufferInputParams->outputLayerNormWeights());
3891 IConnectableLayer* layer = m_Network->AddUnidirectionalSequenceLstmLayer(descriptor,
3904 RegisterInputSlots(graph, layerIndex, layer);
3905 RegisterOutputSlots(graph, layerIndex, layer);