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_ReverseV2Layer] = &DeserializerImpl::ParseReverseV2;
267 m_ParserFunctions[Layer_RsqrtLayer] = &DeserializerImpl::ParseRsqrt;
268 m_ParserFunctions[Layer_ScatterNdLayer] = &DeserializerImpl::ParseScatterNd;
269 m_ParserFunctions[Layer_ShapeLayer] = &DeserializerImpl::ParseShape;
270 m_ParserFunctions[Layer_SliceLayer] = &DeserializerImpl::ParseSlice;
271 m_ParserFunctions[Layer_SoftmaxLayer] = &DeserializerImpl::ParseSoftmax;
272 m_ParserFunctions[Layer_SpaceToBatchNdLayer] = &DeserializerImpl::ParseSpaceToBatchNd;
273 m_ParserFunctions[Layer_SpaceToDepthLayer] = &DeserializerImpl::ParseSpaceToDepth;
274 m_ParserFunctions[Layer_SplitterLayer] = &DeserializerImpl::ParseSplitter;
275 m_ParserFunctions[Layer_StackLayer] = &DeserializerImpl::ParseStack;
276 m_ParserFunctions[Layer_StandInLayer] = &DeserializerImpl::ParseStandIn;
277 m_ParserFunctions[Layer_StridedSliceLayer] = &DeserializerImpl::ParseStridedSlice;
278 m_ParserFunctions[Layer_SubtractionLayer] = &DeserializerImpl::ParseSubtraction;
279 m_ParserFunctions[Layer_SwitchLayer] = &DeserializerImpl::ParseSwitch;
280 m_ParserFunctions[Layer_TileLayer] = &DeserializerImpl::ParseTile;
281 m_ParserFunctions[Layer_TransposeConvolution2dLayer] = &DeserializerImpl::ParseTransposeConvolution2d;
282 m_ParserFunctions[Layer_TransposeLayer] = &DeserializerImpl::ParseTranspose;
283 m_ParserFunctions[Layer_UnidirectionalSequenceLstmLayer] = &DeserializerImpl::ParseUnidirectionalSequenceLstm;
288 auto layerType = graphPtr->layers()->Get(layerIndex)->layer_type();
292 case Layer::Layer_AbsLayer:
293 return graphPtr->layers()->Get(layerIndex)->layer_as_AbsLayer()->base();
294 case Layer::Layer_ActivationLayer:
295 return graphPtr->layers()->Get(layerIndex)->layer_as_ActivationLayer()->base();
296 case Layer::Layer_AdditionLayer:
297 return graphPtr->layers()->Get(layerIndex)->layer_as_AdditionLayer()->base();
298 case Layer::Layer_ArgMinMaxLayer:
299 return graphPtr->layers()->Get(layerIndex)->layer_as_ArgMinMaxLayer()->base();
300 case Layer::Layer_BatchMatMulLayer:
301 return graphPtr->layers()->Get(layerIndex)->layer_as_BatchMatMulLayer()->base();
302 case Layer::Layer_BatchToSpaceNdLayer:
303 return graphPtr->layers()->Get(layerIndex)->layer_as_BatchToSpaceNdLayer()->base();
304 case Layer::Layer_BatchNormalizationLayer:
305 return graphPtr->layers()->Get(layerIndex)->layer_as_BatchNormalizationLayer()->base();
306 case Layer::Layer_CastLayer:
307 return graphPtr->layers()->Get(layerIndex)->layer_as_CastLayer()->base();
308 case Layer::Layer_ChannelShuffleLayer:
309 return graphPtr->layers()->Get(layerIndex)->layer_as_ChannelShuffleLayer()->base();
310 case Layer::Layer_ComparisonLayer:
311 return graphPtr->layers()->Get(layerIndex)->layer_as_ComparisonLayer()->base();
312 case Layer::Layer_ConcatLayer:
313 return graphPtr->layers()->Get(layerIndex)->layer_as_ConcatLayer()->base();
314 case Layer::Layer_ConstantLayer:
315 return graphPtr->layers()->Get(layerIndex)->layer_as_ConstantLayer()->base();
316 case Layer::Layer_Convolution2dLayer:
317 return graphPtr->layers()->Get(layerIndex)->layer_as_Convolution2dLayer()->base();
318 case Layer::Layer_Convolution3dLayer:
319 return graphPtr->layers()->Get(layerIndex)->layer_as_Convolution3dLayer()->base();
320 case Layer::Layer_DepthToSpaceLayer:
321 return graphPtr->layers()->Get(layerIndex)->layer_as_DepthToSpaceLayer()->base();
322 case Layer::Layer_DepthwiseConvolution2dLayer:
323 return graphPtr->layers()->Get(layerIndex)->layer_as_DepthwiseConvolution2dLayer()->base();
324 case Layer::Layer_DequantizeLayer:
325 return graphPtr->layers()->Get(layerIndex)->layer_as_DequantizeLayer()->base();
326 case Layer::Layer_DetectionPostProcessLayer:
327 return graphPtr->layers()->Get(layerIndex)->layer_as_DetectionPostProcessLayer()->base();
328 case Layer::Layer_DivisionLayer:
329 return graphPtr->layers()->Get(layerIndex)->layer_as_DivisionLayer()->base();
330 case Layer::Layer_EqualLayer:
331 return graphPtr->layers()->Get(layerIndex)->layer_as_EqualLayer()->base();
332 case Layer::Layer_ElementwiseBinaryLayer:
333 return graphPtr->layers()->Get(layerIndex)->layer_as_ElementwiseBinaryLayer()->base();
334 case Layer::Layer_ElementwiseUnaryLayer:
335 return graphPtr->layers()->Get(layerIndex)->layer_as_ElementwiseUnaryLayer()->base();
336 case Layer::Layer_FullyConnectedLayer:
337 return graphPtr->layers()->Get(layerIndex)->layer_as_FullyConnectedLayer()->base();
338 case Layer::Layer_FillLayer:
339 return graphPtr->layers()->Get(layerIndex)->layer_as_FillLayer()->base();
340 case Layer::Layer_FloorLayer:
341 return graphPtr->layers()->Get(layerIndex)->layer_as_FloorLayer()->base();
342 case Layer::Layer_GatherLayer:
343 return graphPtr->layers()->Get(layerIndex)->layer_as_GatherLayer()->base();
344 case Layer::Layer_GatherNdLayer:
345 return graphPtr->layers()->Get(layerIndex)->layer_as_GatherNdLayer()->base();
346 case Layer::Layer_GreaterLayer:
347 return graphPtr->layers()->Get(layerIndex)->layer_as_GreaterLayer()->base();
348 case Layer::Layer_InputLayer:
349 return graphPtr->layers()->Get(layerIndex)->layer_as_InputLayer()->base()->base();
350 case Layer::Layer_InstanceNormalizationLayer:
351 return graphPtr->layers()->Get(layerIndex)->layer_as_InstanceNormalizationLayer()->base();
352 case Layer::Layer_L2NormalizationLayer:
353 return graphPtr->layers()->Get(layerIndex)->layer_as_L2NormalizationLayer()->base();
354 case Layer::Layer_LogicalBinaryLayer:
355 return graphPtr->layers()->Get(layerIndex)->layer_as_LogicalBinaryLayer()->base();
356 case Layer::Layer_LogSoftmaxLayer:
357 return graphPtr->layers()->Get(layerIndex)->layer_as_LogSoftmaxLayer()->base();
358 case Layer::Layer_LstmLayer:
359 return graphPtr->layers()->Get(layerIndex)->layer_as_LstmLayer()->base();
360 case Layer::Layer_MeanLayer:
361 return graphPtr->layers()->Get(layerIndex)->layer_as_MeanLayer()->base();
362 case Layer::Layer_MinimumLayer:
363 return graphPtr->layers()->Get(layerIndex)->layer_as_MinimumLayer()->base();
364 case Layer::Layer_MaximumLayer:
365 return graphPtr->layers()->Get(layerIndex)->layer_as_MaximumLayer()->base();
366 case Layer::Layer_MergeLayer:
367 return graphPtr->layers()->Get(layerIndex)->layer_as_MergeLayer()->base();
368 case Layer::Layer_MergerLayer:
369 return graphPtr->layers()->Get(layerIndex)->layer_as_MergerLayer()->base();
370 case Layer::Layer_MultiplicationLayer:
371 return graphPtr->layers()->Get(layerIndex)->layer_as_MultiplicationLayer()->base();
372 case Layer::Layer_NormalizationLayer:
373 return graphPtr->layers()->Get(layerIndex)->layer_as_NormalizationLayer()->base();
374 case Layer::Layer_OutputLayer:
375 return graphPtr->layers()->Get(layerIndex)->layer_as_OutputLayer()->base()->base();
376 case Layer::Layer_PadLayer:
377 return graphPtr->layers()->Get(layerIndex)->layer_as_PadLayer()->base();
378 case Layer::Layer_PermuteLayer:
379 return graphPtr->layers()->Get(layerIndex)->layer_as_PermuteLayer()->base();
380 case Layer::Layer_Pooling2dLayer:
381 return graphPtr->layers()->Get(layerIndex)->layer_as_Pooling2dLayer()->base();
382 case Layer::Layer_Pooling3dLayer:
383 return graphPtr->layers()->Get(layerIndex)->layer_as_Pooling3dLayer()->base();
384 case Layer::Layer_PreluLayer:
385 return graphPtr->layers()->Get(layerIndex)->layer_as_PreluLayer()->base();
386 case Layer::Layer_QLstmLayer:
387 return graphPtr->layers()->Get(layerIndex)->layer_as_QLstmLayer()->base();
388 case Layer::Layer_QuantizeLayer:
389 return graphPtr->layers()->Get(layerIndex)->layer_as_QuantizeLayer()->base();
390 case Layer::Layer_QuantizedLstmLayer:
391 return graphPtr->layers()->Get(layerIndex)->layer_as_QuantizedLstmLayer()->base();
392 case Layer::Layer_RankLayer:
393 return graphPtr->layers()->Get(layerIndex)->layer_as_RankLayer()->base();
394 case Layer::Layer_ReduceLayer:
395 return graphPtr->layers()->Get(layerIndex)->layer_as_ReduceLayer()->base();
396 case Layer::Layer_ReshapeLayer:
397 return graphPtr->layers()->Get(layerIndex)->layer_as_ReshapeLayer()->base();
398 case Layer::Layer_ResizeBilinearLayer:
399 return graphPtr->layers()->Get(layerIndex)->layer_as_ResizeBilinearLayer()->base();
400 case Layer::Layer_ResizeLayer:
401 return graphPtr->layers()->Get(layerIndex)->layer_as_ResizeLayer()->base();
402 case Layer::Layer_ReverseV2Layer:
403 return graphPtr->layers()->Get(layerIndex)->layer_as_ReverseV2Layer()->base();
404 case Layer::Layer_RsqrtLayer:
405 return graphPtr->layers()->Get(layerIndex)->layer_as_RsqrtLayer()->base();
406 case Layer::Layer_ScatterNdLayer:
407 return graphPtr->layers()->Get(layerIndex)->layer_as_ScatterNdLayer()->base();
408 case Layer::Layer_ShapeLayer:
409 return graphPtr->layers()->Get(layerIndex)->layer_as_ShapeLayer()->base();
410 case Layer::Layer_SliceLayer:
411 return graphPtr->layers()->Get(layerIndex)->layer_as_SliceLayer()->base();
412 case Layer::Layer_SoftmaxLayer:
413 return graphPtr->layers()->Get(layerIndex)->layer_as_SoftmaxLayer()->base();
414 case Layer::Layer_SpaceToBatchNdLayer:
415 return graphPtr->layers()->Get(layerIndex)->layer_as_SpaceToBatchNdLayer()->base();
416 case Layer::Layer_SpaceToDepthLayer:
417 return graphPtr->layers()->Get(layerIndex)->layer_as_SpaceToDepthLayer()->base();
418 case Layer::Layer_SplitterLayer:
419 return graphPtr->layers()->Get(layerIndex)->layer_as_SplitterLayer()->base();
420 case Layer::Layer_StackLayer:
421 return graphPtr->layers()->Get(layerIndex)->layer_as_StackLayer()->base();
422 case Layer::Layer_StandInLayer:
423 return graphPtr->layers()->Get(layerIndex)->layer_as_StandInLayer()->base();
424 case Layer::Layer_StridedSliceLayer:
425 return graphPtr->layers()->Get(layerIndex)->layer_as_StridedSliceLayer()->base();
426 case Layer::Layer_SubtractionLayer:
427 return graphPtr->layers()->Get(layerIndex)->layer_as_SubtractionLayer()->base();
428 case Layer::Layer_SwitchLayer:
429 return graphPtr->layers()->Get(layerIndex)->layer_as_SwitchLayer()->base();
430 case Layer::Layer_TileLayer:
431 return graphPtr->layers()->Get(layerIndex)->layer_as_TileLayer()->base();
432 case Layer::Layer_TransposeConvolution2dLayer:
433 return graphPtr->layers()->Get(layerIndex)->layer_as_TransposeConvolution2dLayer()->base();
434 case Layer::Layer_TransposeLayer:
435 return graphPtr->layers()->Get(layerIndex)->layer_as_TransposeLayer()->base();
436 case Layer::Layer_UnidirectionalSequenceLstmLayer:
437 return graphPtr->layers()->Get(layerIndex)->layer_as_UnidirectionalSequenceLstmLayer()->base();
438 case Layer::Layer_NONE:
440 throw ParseException(fmt::format(
"Layer type {} not recognized", layerType));
446 auto layer = GetBaseLayer(graph, index);
448 return layer->layerName()->str();
453 auto layerType = graphPtr->layers()->Get(layerIndex)->layer_type();
455 if (layerType == Layer::Layer_InputLayer)
457 return graphPtr->layers()->Get(layerIndex)->layer_as_InputLayer()->base()->layerBindingId();
459 else if ( layerType == Layer::Layer_OutputLayer )
461 return graphPtr->layers()->Get(layerIndex)->layer_as_OutputLayer()->base()->layerBindingId();
470 case armnnSerializer::DataLayout::DataLayout_NHWC:
472 case armnnSerializer::DataLayout::DataLayout_NDHWC:
474 case armnnSerializer::DataLayout::DataLayout_NCDHW:
476 case armnnSerializer::DataLayout::DataLayout_NCHW:
486 case armnnSerializer::ActivationFunction_Sigmoid:
488 case armnnSerializer::ActivationFunction_TanH:
490 case armnnSerializer::ActivationFunction_Linear:
492 case armnnSerializer::ActivationFunction_ReLu:
494 case armnnSerializer::ActivationFunction_BoundedReLu:
496 case armnnSerializer::ActivationFunction_LeakyReLu:
498 case armnnSerializer::ActivationFunction_Abs:
500 case armnnSerializer::ActivationFunction_Sqrt:
502 case armnnSerializer::ActivationFunction_Square:
504 case armnnSerializer::ActivationFunction_Elu:
506 case armnnSerializer::ActivationFunction_HardSwish:
508 case armnnSerializer::ActivationFunction_Gelu:
519 case armnnSerializer::ArgMinMaxFunction::ArgMinMaxFunction_Max:
521 case armnnSerializer::ArgMinMaxFunction::ArgMinMaxFunction_Min:
531 case armnnSerializer::ScatterNdFunction_Update:
533 case armnnSerializer::ScatterNdFunction_Add:
535 case armnnSerializer::ScatterNdFunction_Sub:
537 case armnnSerializer::ScatterNdFunction_Max:
539 case armnnSerializer::ScatterNdFunction_Min:
550 case armnnSerializer::ComparisonOperation::ComparisonOperation_Equal:
552 case armnnSerializer::ComparisonOperation::ComparisonOperation_Greater:
554 case armnnSerializer::ComparisonOperation::ComparisonOperation_GreaterOrEqual:
556 case armnnSerializer::ComparisonOperation::ComparisonOperation_Less:
558 case armnnSerializer::ComparisonOperation::ComparisonOperation_LessOrEqual:
560 case armnnSerializer::ComparisonOperation::ComparisonOperation_NotEqual:
570 case armnnSerializer::ReduceOperation::ReduceOperation_Sum:
572 case armnnSerializer::ReduceOperation::ReduceOperation_Max:
574 case armnnSerializer::ReduceOperation::ReduceOperation_Mean:
576 case armnnSerializer::ReduceOperation::ReduceOperation_Min:
578 case armnnSerializer::ReduceOperation::ReduceOperation_Prod:
589 case armnnSerializer::LogicalBinaryOperation::LogicalBinaryOperation_LogicalAnd:
591 case armnnSerializer::LogicalBinaryOperation::LogicalBinaryOperation_LogicalOr:
602 case armnnSerializer::BinaryOperation::BinaryOperation_Add:
604 case armnnSerializer::BinaryOperation::BinaryOperation_Div:
606 case armnnSerializer::BinaryOperation::BinaryOperation_Maximum:
608 case armnnSerializer::BinaryOperation::BinaryOperation_Minimum:
610 case armnnSerializer::BinaryOperation::BinaryOperation_Mul:
612 case armnnSerializer::BinaryOperation::BinaryOperation_Sub:
614 case armnnSerializer::BinaryOperation::BinaryOperation_SqDiff:
616 case armnnSerializer::BinaryOperation::BinaryOperation_Power:
627 case armnnSerializer::UnaryOperation::UnaryOperation_Abs:
629 case armnnSerializer::UnaryOperation::UnaryOperation_Ceil:
631 case armnnSerializer::UnaryOperation::UnaryOperation_Rsqrt:
633 case armnnSerializer::UnaryOperation::UnaryOperation_Sqrt:
635 case armnnSerializer::UnaryOperation::UnaryOperation_Exp:
637 case armnnSerializer::UnaryOperation::UnaryOperation_Neg:
639 case armnnSerializer::UnaryOperation::UnaryOperation_LogicalNot:
641 case armnnSerializer::UnaryOperation::UnaryOperation_Log:
643 case armnnSerializer::UnaryOperation::UnaryOperation_Sin:
654 case armnnSerializer::PaddingMode::PaddingMode_Reflect:
656 case armnnSerializer::PaddingMode::PaddingMode_Symmetric:
667 case armnnSerializer::ResizeMethod_NearestNeighbor:
669 case armnnSerializer::ResizeMethod_Bilinear:
681 switch (tensorPtr->dataType())
683 case DataType_QAsymmS8:
686 case DataType_QSymmS8:
689 case DataType_QuantisedAsymm8:
690 case DataType_QAsymmU8:
693 case DataType_QSymmS16:
694 case DataType_QuantisedSymm16:
697 case DataType_Signed32:
700 case DataType_Signed64:
703 case DataType_Float32:
706 case DataType_Float16:
709 case DataType_Boolean:
715 throw ParseException(fmt::format(
"Unsupported data type {0} = {1}. {2}",
716 tensorPtr->dataType(),
717 EnumNameDataType(tensorPtr->dataType()),
722 float quantizationScale = tensorPtr->quantizationScale();
723 int32_t quantizationOffset = tensorPtr->quantizationOffset();
725 if (tensorPtr->dimensionality() ==
static_cast<unsigned int>(Dimensionality::Scalar))
732 else if (tensorPtr->dimensionality() ==
static_cast<unsigned int>(Dimensionality::NotSpecified))
741 auto dimensions = tensorPtr->dimensions();
742 unsigned int size = dimensions->size();
743 std::vector<unsigned int> outputDims(dimensions->begin(), dimensions->begin() + size);
748 if (tensorPtr->dimensionSpecificity() !=
nullptr)
750 auto dimensionSpecificity = tensorPtr->dimensionSpecificity();
751 size = dimensionSpecificity->size();
752 for (
unsigned int i = 0; i < size; ++i)
754 dimensionsSpecificity[i] = dimensionSpecificity->Get(i);
758 TensorShape shape(size, outputDims.data(), dimensionsSpecificity);
760 auto quantizationScales = tensorPtr->quantizationScales();
761 if (quantizationScales)
763 unsigned int quantizationScalesSize = quantizationScales->size();
764 std::vector<float> scales(quantizationScales->begin(), quantizationScales->begin() + quantizationScalesSize);
765 unsigned int quantizationDim = tensorPtr->quantizationDim();
788 switch (constTensorPtr->data_type())
790 case ConstTensorData_ByteData:
792 auto byteData = constTensorPtr->data_as_ByteData()->data();
796 case ConstTensorData_ShortData:
798 auto shortData = constTensorPtr->data_as_ShortData()->data();
802 case ConstTensorData_IntData:
804 auto intData = constTensorPtr->data_as_IntData()->data();
808 case ConstTensorData_LongData:
810 auto longData = constTensorPtr->data_as_LongData()->data();
817 throw ParseException(fmt::format(
"Unsupported data type {0} = {1}. {2}",
818 constTensorPtr->data_type(),
819 EnumNameConstTensorData(constTensorPtr->data_type()),
828 auto layer = GetBaseLayer(graphPtr, layerIndex);
829 const auto& numInputs = layer->inputSlots()->size();
833 for (
unsigned int i=0; i<numInputs; ++i)
836 (layer->inputSlots()->Get(i)->connection()->sourceLayerIndex()));
837 result[i] = GetBaseLayer(graphPtr, inputId)->outputSlots()->Get(0)->tensorInfo();
845 auto layer = GetBaseLayer(graphPtr, layerIndex);
846 const auto& numOutputs = layer->outputSlots()->size();
850 for (
unsigned int i=0; i<numOutputs; ++i)
852 result[i] = layer->outputSlots()->Get(i)->tensorInfo();
857 void IDeserializer::DeserializerImpl::ParseUnsupportedLayer(
GraphPtr graph,
unsigned int layerIndex)
860 const auto layerName = GetBaseLayer(graph, layerIndex)->layerName()->c_str();
861 throw ParseException(fmt::format(
"Layer not supported. layerIndex: {0} "
862 "layerName: {1} / {2}",
868 void IDeserializer::DeserializerImpl::ResetParser()
871 m_InputBindings.clear();
872 m_OutputBindings.clear();
879 GraphPtr graph = LoadGraphFromBinary(binaryContent.data(), binaryContent.size());
880 return CreateNetworkFromGraph(graph);
886 if (binaryContent.fail()) {
890 binaryContent.seekg(0, std::ios::end);
891 const std::streamoff size = binaryContent.tellg();
892 std::vector<char> content(
static_cast<size_t>(size));
893 binaryContent.seekg(0);
894 binaryContent.read(content.data(),
static_cast<std::streamsize
>(size));
895 GraphPtr graph = LoadGraphFromBinary(
reinterpret_cast<uint8_t*
>(content.data()),
static_cast<size_t>(size));
896 return CreateNetworkFromGraph(graph);
901 if (binaryContent ==
nullptr)
906 flatbuffers::Verifier verifier(binaryContent, len);
907 if (verifier.VerifyBuffer<SerializedGraph>() ==
false)
909 throw ParseException(fmt::format(
"Buffer doesn't conform to the expected Armnn "
910 "flatbuffers format. size:{0} {1}",
914 return GetSerializedGraph(binaryContent);
919 if (graph ==
nullptr)
923 m_Network = INetwork::Create();
924 unsigned int layerIndex = 0;
925 for (AnyLayer
const* layer : *graph->layers())
927 if (layer->layer_type() != Layer_InputLayer &&
928 layer->layer_type() != Layer_OutputLayer)
931 auto& parserFunction = m_ParserFunctions[layer->layer_type()];
932 (this->*parserFunction)(graph, layerIndex);
937 SetupInputLayers(graph);
938 SetupOutputLayers(graph);
941 for (
auto&& graphIt : m_GraphConnections)
943 Connections& connections = graphIt.second;
944 for (
auto&& outputIt : connections.outputSlots)
946 const unsigned int outputSlotIndex = outputIt.first;
948 if (connections.inputSlots.find(outputSlotIndex) != connections.inputSlots.end())
950 for (
IInputSlot* inputSlot : connections.inputSlots[outputSlotIndex])
952 outputSlot->
Connect(*inputSlot);
958 return std::move(m_Network);
962 const std::string& name)
const
965 for (
auto inputBinding : m_InputBindings)
967 if (inputBinding.first == name)
969 return inputBinding.second;
972 throw ParseException(fmt::format(
"No input binding found for layer:{0} / {1}",
978 const std::string& name)
const
981 for (
auto outputBinding : m_OutputBindings)
983 if (outputBinding.first == name)
985 return outputBinding.second;
988 throw ParseException(fmt::format(
"No output binding found for layer:{0} / {1}",
993 unsigned int IDeserializer::DeserializerImpl::GetInputLayerInVector(
GraphPtr graph,
int targetId)
995 for (
unsigned int i = 0; i < graph->layers()->size(); i++)
997 auto layer = graph->layers()->Get(i);
998 if (layer->layer_type() == Layer::Layer_InputLayer)
1000 auto layerBindingId = layer->layer_as_InputLayer()->base()->layerBindingId();
1001 if (layerBindingId == targetId)
1007 throw ParseException(
"Input layer with given layerBindingId not found");
1010 unsigned int IDeserializer::DeserializerImpl::GetOutputLayerInVector(
GraphPtr graph,
int targetId)
1012 for (
unsigned int i = 0; i < graph->layers()->size(); i++)
1014 auto layer = graph->layers()->Get(i);
1015 if (layer->layer_type() == Layer::Layer_OutputLayer)
1017 auto layerBindingId = layer->layer_as_OutputLayer()->base()->layerBindingId();
1018 if (layerBindingId == targetId)
1024 throw ParseException(
"Output layer with given layerBindingId not found");
1027 unsigned int IDeserializer::DeserializerImpl::GetLayerIndexInVector(
GraphPtr graph,
unsigned int targetIndex)
1029 for (
unsigned int i = 0; i < graph->layers()->size(); i++)
1032 if (layer->index() == targetIndex)
1040 IDeserializer::DeserializerImpl::FeatureVersions IDeserializer::DeserializerImpl::GetFeatureVersions(
GraphPtr graph)
1042 IDeserializer::DeserializerImpl::FeatureVersions versions;
1044 if (graph->featureVersions())
1046 versions.m_BindingIdScheme = graph->featureVersions()->bindingIdsScheme();
1047 versions.m_WeightsLayoutScheme = graph->featureVersions()->weightsLayoutScheme();
1048 versions.m_ConstTensorsAsInputs = graph->featureVersions()->constantTensorsAsInputs();
1054 void IDeserializer::DeserializerImpl::SetupInputLayers(
GraphPtr graph)
1057 const unsigned int numInputs = graph->inputIds()->size();
1058 m_InputBindings.clear();
1059 m_InputBindings.reserve(numInputs);
1061 for (
unsigned int i = 0; i < numInputs; i++)
1063 unsigned int inputLayerIndex = 0xFFFFFFFF;
1064 if (GetFeatureVersions(graph).m_BindingIdScheme == 0)
1066 const unsigned int inputId = armnn::numeric_cast<unsigned int>(graph->inputIds()->Get(i));
1067 inputLayerIndex = GetLayerIndexInVector(graph, inputId);
1071 const int inputId = graph->inputIds()->Get(i);
1072 inputLayerIndex = GetInputLayerInVector(graph, inputId);
1078 LayerBindingId bindingId = GetBindingLayerInfo(graph, inputLayerIndex);
1079 if (baseLayer->layerName()->c_str() ==
nullptr)
1081 throw ParseException(fmt::format(
"Input with layer index [{0}] has no name", inputLayerIndex));
1085 m_Network->AddInputLayer(bindingId, baseLayer->layerName()->c_str());
1089 RegisterOutputSlots(graph, inputLayerIndex, inputLayer);
1092 m_InputBindings.push_back(std::make_pair(baseLayer->layerName()->c_str(), bindingInfo));
1096 void IDeserializer::DeserializerImpl::SetupOutputLayers(
GraphPtr graph)
1099 const unsigned int numOutputs = graph->outputIds()->size();
1100 m_OutputBindings.clear();
1101 m_OutputBindings.reserve(numOutputs);
1103 for (
unsigned int i = 0; i < numOutputs; i++)
1105 unsigned int outputLayerIndex = 0xFFFFFFFF;
1106 if (GetFeatureVersions(graph).m_BindingIdScheme == 0)
1108 const unsigned int outputId = armnn::numeric_cast<unsigned int>(graph->outputIds()->Get(i));
1109 outputLayerIndex = GetLayerIndexInVector(graph, outputId);
1113 const int outputId = graph->outputIds()->Get(i);
1114 outputLayerIndex = GetOutputLayerInVector(graph, outputId);
1120 LayerBindingId bindingId = GetBindingLayerInfo(graph, outputLayerIndex);
1121 if (baseLayer->layerName()->c_str() ==
nullptr)
1123 throw ParseException(fmt::format(
"Output with layer index [{0}] has no name", outputLayerIndex));
1127 m_Network->AddOutputLayer(bindingId, baseLayer->layerName()->c_str());
1129 RegisterInputSlots(graph, outputLayerIndex, outputLayer);
1130 unsigned int sourceLayerIndex =
1131 GetLayerIndexInVector(graph, baseLayer->inputSlots()->Get(0)->connection()->sourceLayerIndex());
1132 unsigned int outputSlotIndex =
1133 GetLayerIndexInVector(graph, baseLayer->inputSlots()->Get(0)->connection()->outputSlotIndex());
1134 LayerBaseRawPtr sourceBaseLayer = GetBaseLayer(graph, sourceLayerIndex);
1136 sourceBaseLayer->outputSlots()->Get(outputSlotIndex)->tensorInfo());
1138 m_OutputBindings.push_back(std::make_pair(baseLayer->layerName()->c_str(), bindingInfo));
1142 void IDeserializer::DeserializerImpl::RegisterOutputSlots(
GraphPtr graph,
1143 uint32_t layerIndex,
1146 if (layer ==
nullptr)
1149 "RegisterOutputSlots: pointer to layer with index [{0}] is null", layerIndex));
1155 throw ParseException(fmt::format(
"The number of outputslots ({0}) does not match the number expected ({1})"
1156 " for layer index: {2} {3}",
1157 baseLayer->outputSlots()->size(),
1165 const unsigned int slotIndex = baseLayer->outputSlots()->Get(i)->index();
1168 RegisterOutputSlotOfConnection(baseLayer->index(), slotIndex, outputSlot);
1172 void IDeserializer::DeserializerImpl::RegisterInputSlots(
GraphPtr graph,
1173 uint32_t layerIndex,
1175 std::vector<unsigned int> ignoreSlots)
1177 if (layer ==
nullptr)
1180 "RegisterInputSlots: pointer to layer with index [{0}] is null", layerIndex));
1185 if (baseLayer->inputSlots()->size() != (layer->
GetNumInputSlots() - ignoreSlots.size()))
1187 throw ParseException(fmt::format(
"The number of inputslots ({0}) does not match the number expected ({1})"
1188 " for layer index:{2} {3}",
1189 baseLayer->inputSlots()->size(),
1198 if (std::find(ignoreSlots.begin(), ignoreSlots.end(), i) == ignoreSlots.end())
1200 auto fbInputSlot = baseLayer->inputSlots()->Get(i);
1201 auto fbConnection = fbInputSlot->connection();
1205 if (fbInputSlot->isOverridden())
1210 RegisterInputSlotOfConnection(fbConnection->sourceLayerIndex(), fbConnection->outputSlotIndex(), inputSlot);
1215 void IDeserializer::DeserializerImpl::RegisterInputSlotOfConnection(uint32_t sourceLayerIndex,
1216 uint32_t outputSlotIndex,
1219 if (m_GraphConnections.find(sourceLayerIndex) == m_GraphConnections.end())
1221 m_GraphConnections[sourceLayerIndex] = Connections();
1224 Connections& connections = m_GraphConnections[sourceLayerIndex];
1225 if (connections.inputSlots.find(outputSlotIndex) == connections.inputSlots.end())
1227 connections.inputSlots[outputSlotIndex] = {inputSlot};
1231 connections.inputSlots[outputSlotIndex].push_back(inputSlot);
1235 void IDeserializer::DeserializerImpl::RegisterOutputSlotOfConnection(uint32_t sourceLayerIndex,
1236 uint32_t outputSlotIndex,
1239 if (m_GraphConnections.find(sourceLayerIndex) == m_GraphConnections.end())
1241 m_GraphConnections[sourceLayerIndex] = Connections();
1244 Connections& connections = m_GraphConnections[sourceLayerIndex];
1245 if (connections.outputSlots.find(outputSlotIndex) != connections.outputSlots.end())
1250 connections.outputSlots[outputSlotIndex] = outputSlot;
1253 void IDeserializer::DeserializerImpl::ParseAbs(
GraphPtr graph,
unsigned int layerIndex)
1256 auto inputs = GetInputs(graph, layerIndex);
1260 auto outputs = GetOutputs(graph, layerIndex);
1263 auto layerName = GetLayerName(graph, layerIndex);
1266 IConnectableLayer* layer = m_Network->AddElementwiseUnaryLayer(descriptor, layerName.c_str());
1270 RegisterInputSlots(graph, layerIndex, layer);
1271 RegisterOutputSlots(graph, layerIndex, layer);
1274 void IDeserializer::DeserializerImpl::ParseActivation(
GraphPtr graph,
unsigned int layerIndex)
1277 auto inputs = GetInputs(graph, layerIndex);
1281 auto outputs = GetOutputs(graph, layerIndex);
1284 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_ActivationLayer();
1285 auto layerName = GetLayerName(graph, layerIndex);
1286 auto serializerDescriptor = serializerLayer->descriptor();
1290 descriptor.
m_A = serializerDescriptor->a();
1291 descriptor.
m_B = serializerDescriptor->b();
1298 RegisterInputSlots(graph, layerIndex, layer);
1299 RegisterOutputSlots(graph, layerIndex, layer);
1302 void IDeserializer::DeserializerImpl::ParseAdd(
GraphPtr graph,
unsigned int layerIndex)
1305 auto inputs = GetInputs(graph, layerIndex);
1309 auto outputs = GetOutputs(graph, layerIndex);
1312 auto layerName = GetLayerName(graph, layerIndex);
1314 IConnectableLayer* layer = m_Network->AddElementwiseBinaryLayer(descriptor, layerName.c_str());
1319 RegisterInputSlots(graph, layerIndex, layer);
1320 RegisterOutputSlots(graph, layerIndex, layer);
1323 void IDeserializer::DeserializerImpl::ParseArgMinMax(
GraphPtr graph,
unsigned int layerIndex)
1326 auto inputs = GetInputs(graph, layerIndex);
1330 auto outputs = GetOutputs(graph, layerIndex);
1333 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_ArgMinMaxLayer();
1334 auto serializerDescriptor = serializerLayer->descriptor();
1338 descriptor.
m_Axis = serializerDescriptor->axis();
1339 auto layerName = GetLayerName(graph, layerIndex);
1340 IConnectableLayer* layer = m_Network->AddArgMinMaxLayer(descriptor, layerName.c_str());
1345 RegisterInputSlots(graph, layerIndex, layer);
1346 RegisterOutputSlots(graph, layerIndex, layer);
1349 void IDeserializer::DeserializerImpl::ParseBatchMatMul(
GraphPtr graph,
unsigned int layerIndex)
1353 auto inputs = GetInputs(graph, layerIndex);
1357 auto outputs = GetOutputs(graph, layerIndex);
1360 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_BatchMatMulLayer();
1361 auto serializerDescriptor = serializerLayer->descriptor();
1364 serializerDescriptor->transposeY(),
1365 serializerDescriptor->adjointX(),
1366 serializerDescriptor->adjointY(),
1370 auto layerName = GetLayerName(graph, layerIndex);
1371 IConnectableLayer* layer = m_Network->AddBatchMatMulLayer(descriptor, layerName.c_str());
1376 RegisterInputSlots(graph, layerIndex, layer);
1377 RegisterOutputSlots(graph, layerIndex, layer);
1380 void IDeserializer::DeserializerImpl::ParseBatchToSpaceNd(
GraphPtr graph,
unsigned int layerIndex)
1390 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_BatchToSpaceNdLayer()->descriptor();
1391 auto flatBufferCrops = flatBufferDescriptor->crops();
1392 auto flatBufferBlockShape = flatBufferDescriptor->blockShape();
1394 if (flatBufferCrops->size() % 2 != 0)
1399 std::vector<std::pair<unsigned int, unsigned int>> crops;
1400 crops.reserve(flatBufferCrops->size() / 2);
1401 for (
unsigned int i = 0; i < flatBufferCrops->size() - 1; i += 2)
1403 crops.emplace_back(flatBufferCrops->Get(i), flatBufferCrops->Get(i+1));
1409 std::vector<unsigned int>(flatBufferBlockShape->begin(), flatBufferBlockShape->end());
1412 auto layerName = GetLayerName(graph, layerIndex);
1413 IConnectableLayer* layer = m_Network->AddBatchToSpaceNdLayer(descriptor, layerName.c_str());
1418 RegisterInputSlots(graph, layerIndex, layer);
1419 RegisterOutputSlots(graph, layerIndex, layer);
1422 void IDeserializer::DeserializerImpl::ParseBatchNormalization(
GraphPtr graph,
unsigned int layerIndex)
1426 auto inputs = GetInputs(graph, layerIndex);
1429 auto outputs = GetOutputs(graph, layerIndex);
1433 auto layerName = GetLayerName(graph, layerIndex);
1435 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_BatchNormalizationLayer();
1436 auto serializerDescriptor = serializerLayer->descriptor();
1439 descriptor.
m_Eps = serializerDescriptor->eps();
1455 RegisterInputSlots(graph, layerIndex, layer);
1456 RegisterOutputSlots(graph, layerIndex, layer);
1459 void IDeserializer::DeserializerImpl::ParseCast(
GraphPtr graph,
unsigned int layerIndex)
1469 auto layerName = GetLayerName(graph, layerIndex);
1476 RegisterInputSlots(graph, layerIndex, layer);
1477 RegisterOutputSlots(graph, layerIndex, layer);
1480 void IDeserializer::DeserializerImpl::ParseConstant(
GraphPtr graph,
unsigned int layerIndex)
1485 auto outputs = GetOutputs(graph, layerIndex);
1488 auto layerName = GetLayerName(graph, layerIndex);
1490 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_ConstantLayer();
1491 auto serializerInput = serializerLayer->input();
1500 if (this->GetFeatureVersions(graph).m_WeightsLayoutScheme <= 0)
1506 std::unique_ptr<unsigned char[]> permuteBuffer(
new unsigned char[weightsInfo.
GetNumBytes()]);
1513 auto weightsShape = weightsInfo.
GetShape();
1517 weightsShape[2]*weightsShape[3]});
1522 layer = m_Network->AddConstantLayer(weightsPermuted, layerName.c_str());
1526 RegisterOutputSlots(graph, layerIndex, layer);
1532 layer = m_Network->AddConstantLayer(input, layerName.c_str());
1539 RegisterOutputSlots(graph, layerIndex, layer);
1542 void IDeserializer::DeserializerImpl::ParseConvolution2d(
GraphPtr graph,
unsigned int layerIndex)
1545 auto inputs = GetInputs(graph, layerIndex);
1548 auto outputs = GetOutputs(graph, layerIndex);
1551 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_Convolution2dLayer();
1553 auto layerName = GetLayerName(graph, layerIndex);
1554 auto flatbufferDescriptor = flatBufferLayer->descriptor();
1557 descriptor.
m_PadLeft = flatbufferDescriptor->padLeft();
1558 descriptor.
m_PadRight = flatbufferDescriptor->padRight();
1559 descriptor.
m_PadTop = flatbufferDescriptor->padTop();
1560 descriptor.
m_PadBottom = flatbufferDescriptor->padBottom();
1561 descriptor.
m_StrideX = flatbufferDescriptor->strideX();
1562 descriptor.
m_StrideY = flatbufferDescriptor->strideY();;
1563 descriptor.
m_DilationX = flatbufferDescriptor->dilationX();
1564 descriptor.
m_DilationY = flatbufferDescriptor->dilationY();;
1565 descriptor.
m_BiasEnabled = flatbufferDescriptor->biasEnabled();;
1569 std::vector<unsigned int> ignoreSlots {};
1574 if (this->GetFeatureVersions(graph).m_ConstTensorsAsInputs <= 0)
1580 layer = m_Network->AddConvolution2dLayer(descriptor,
1584 auto weightsLayer = m_Network->AddConstantLayer(weightsTensor);
1585 weightsLayer->GetOutputSlot(0).Connect(layer->
GetInputSlot(1u));
1586 weightsLayer->GetOutputSlot(0).SetTensorInfo(weightsTensor.
GetInfo());
1587 ignoreSlots.emplace_back(1u);
1592 auto biasLayer = m_Network->AddConstantLayer(biasTensor);
1593 biasLayer->GetOutputSlot(0).Connect(layer->
GetInputSlot(2u));
1594 biasLayer->GetOutputSlot(0).SetTensorInfo(biasTensor.
GetInfo());
1595 ignoreSlots.emplace_back(2u);
1600 layer = m_Network->AddConvolution2dLayer(descriptor,
1609 RegisterInputSlots(graph, layerIndex, layer, ignoreSlots);
1610 RegisterOutputSlots(graph, layerIndex, layer);
1613 void IDeserializer::DeserializerImpl::ParseConvolution3d(
GraphPtr graph,
unsigned int layerIndex)
1616 auto inputs = GetInputs(graph, layerIndex);
1619 auto outputs = GetOutputs(graph, layerIndex);
1622 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_Convolution3dLayer();
1623 auto layerName = GetLayerName(graph, layerIndex);
1624 auto serializerDescriptor = serializerLayer->descriptor();
1627 descriptor.
m_PadLeft = serializerDescriptor->padLeft();
1628 descriptor.
m_PadRight = serializerDescriptor->padRight();
1629 descriptor.
m_PadTop = serializerDescriptor->padTop();
1630 descriptor.
m_PadBottom = serializerDescriptor->padBottom();
1631 descriptor.
m_PadFront = serializerDescriptor->padFront();
1632 descriptor.
m_PadBack = serializerDescriptor->padBack();
1633 descriptor.
m_StrideX = serializerDescriptor->strideX();
1634 descriptor.
m_StrideY = serializerDescriptor->strideY();
1635 descriptor.
m_StrideZ = serializerDescriptor->strideZ();
1636 descriptor.
m_DilationX = serializerDescriptor->dilationX();
1637 descriptor.
m_DilationY = serializerDescriptor->dilationY();
1638 descriptor.
m_DilationZ = serializerDescriptor->dilationZ();
1639 descriptor.
m_BiasEnabled = serializerDescriptor->biasEnabled();
1645 IConnectableLayer* layer = m_Network->AddConvolution3dLayer(descriptor, layerName.c_str());
1650 RegisterInputSlots(graph, layerIndex, layer);
1651 RegisterOutputSlots(graph, layerIndex, layer);
1654 void IDeserializer::DeserializerImpl::ParseDepthToSpace(
GraphPtr graph,
unsigned int layerIndex)
1658 auto inputs = GetInputs(graph, layerIndex);
1661 auto outputs = GetOutputs(graph, layerIndex);
1664 auto fbDescriptor = graph->layers()->Get(layerIndex)->layer_as_DepthToSpaceLayer()->descriptor();
1667 descriptor.
m_BlockSize = fbDescriptor->blockSize();
1670 auto layerName = GetLayerName(graph, layerIndex);
1671 IConnectableLayer* layer = m_Network->AddDepthToSpaceLayer(descriptor, layerName.c_str());
1676 RegisterInputSlots(graph, layerIndex, layer);
1677 RegisterOutputSlots(graph, layerIndex, layer);
1680 void IDeserializer::DeserializerImpl::ParseDepthwiseConvolution2d(
GraphPtr graph,
unsigned int layerIndex)
1683 auto inputs = GetInputs(graph, layerIndex);
1686 auto outputs = GetOutputs(graph, layerIndex);
1689 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_DepthwiseConvolution2dLayer();
1690 auto layerName = GetLayerName(graph, layerIndex);
1691 auto serializerDescriptor = serializerLayer->descriptor();
1694 descriptor.
m_PadLeft = serializerDescriptor->padLeft();
1695 descriptor.
m_PadRight = serializerDescriptor->padRight();
1696 descriptor.
m_PadTop = serializerDescriptor->padTop();
1697 descriptor.
m_PadBottom = serializerDescriptor->padBottom();
1698 descriptor.
m_StrideX = serializerDescriptor->strideX();
1699 descriptor.
m_StrideY = serializerDescriptor->strideY();
1700 descriptor.
m_DilationX = serializerDescriptor->dilationX();
1701 descriptor.
m_DilationY = serializerDescriptor->dilationY();
1702 descriptor.
m_BiasEnabled = serializerDescriptor->biasEnabled();
1706 std::vector<unsigned int> ignoreSlots {};
1710 if (this->GetFeatureVersions(graph).m_ConstTensorsAsInputs <= 0)
1717 ignoreSlots.emplace_back(1u);
1719 layer = m_Network->AddDepthwiseConvolution2dLayer(descriptor,
1726 ignoreSlots.emplace_back(2u);
1728 auto biasLayer = m_Network->AddConstantLayer(biases);
1729 biasLayer->GetOutputSlot(0).Connect(layer->
GetInputSlot(2u));
1730 biasLayer->GetOutputSlot(0).SetTensorInfo(biases.
GetInfo());
1733 if (this->GetFeatureVersions(graph).m_WeightsLayoutScheme <= 0)
1739 std::unique_ptr<unsigned char[]> permuteBuffer(
new unsigned char[weightsInfo.
GetNumBytes()]);
1746 auto weightsShape = weightsInfo.
GetShape();
1750 weightsShape[2]*weightsShape[3]});
1754 auto weightsLayer = m_Network->AddConstantLayer(weightsPermuted);
1755 weightsLayer->GetOutputSlot(0).Connect(layer->
GetInputSlot(1u));
1756 weightsLayer->GetOutputSlot(0).SetTensorInfo(weightsPermuted.GetInfo());
1760 auto weightsLayer = m_Network->AddConstantLayer(weights);
1761 weightsLayer->GetOutputSlot(0).Connect(layer->
GetInputSlot(1u));
1762 weightsLayer->GetOutputSlot(0).SetTensorInfo(weights.
GetInfo());
1767 layer = m_Network->AddDepthwiseConvolution2dLayer(descriptor,
1776 RegisterInputSlots(graph, layerIndex, layer, ignoreSlots);
1777 RegisterOutputSlots(graph, layerIndex, layer);
1780 void IDeserializer::DeserializerImpl::ParseDetectionPostProcess(
GraphPtr graph,
unsigned int layerIndex)
1783 auto inputs = GetInputs(graph, layerIndex);
1787 auto outputs = GetOutputs(graph, layerIndex);
1790 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_DetectionPostProcessLayer();
1791 auto layerName = GetLayerName(graph, layerIndex);
1792 auto flatBufferDescriptor = flatBufferLayer->descriptor();
1800 descriptor.
m_NumClasses = flatBufferDescriptor->numClasses();
1802 descriptor.
m_ScaleX = flatBufferDescriptor->scaleX();
1803 descriptor.
m_ScaleY = flatBufferDescriptor->scaleY();
1804 descriptor.
m_ScaleW = flatBufferDescriptor->scaleW();
1805 descriptor.
m_ScaleH = flatBufferDescriptor->scaleH();
1813 for (
unsigned int i = 0; i < 4; i++)
1818 RegisterInputSlots(graph, layerIndex, layer);
1819 RegisterOutputSlots(graph, layerIndex, layer);
1822 void IDeserializer::DeserializerImpl::ParseDivision(
GraphPtr graph,
unsigned int layerIndex)
1825 auto inputs = GetInputs(graph, layerIndex);
1829 auto outputs = GetOutputs(graph, layerIndex);
1832 auto layerName = GetLayerName(graph, layerIndex);
1834 IConnectableLayer* layer = m_Network->AddElementwiseBinaryLayer(descriptor, layerName.c_str());
1839 RegisterInputSlots(graph, layerIndex, layer);
1840 RegisterOutputSlots(graph, layerIndex, layer);
1843 void IDeserializer::DeserializerImpl::ParseEqual(
GraphPtr graph,
unsigned int layerIndex)
1846 auto inputs = GetInputs(graph, layerIndex);
1850 auto outputs = GetOutputs(graph, layerIndex);
1853 auto layerName = GetLayerName(graph, layerIndex);
1855 IConnectableLayer* layer = m_Network->AddComparisonLayer(descriptor, layerName.c_str());
1860 RegisterInputSlots(graph, layerIndex, layer);
1861 RegisterOutputSlots(graph, layerIndex, layer);
1864 void IDeserializer::DeserializerImpl::ParseFill(
GraphPtr graph,
unsigned int layerIndex)
1867 auto inputs = GetInputs(graph, layerIndex);
1871 auto outputs = GetOutputs(graph, layerIndex);
1874 auto layerName = GetLayerName(graph, layerIndex);
1876 descriptor.
m_Value = graph->layers()->Get(layerIndex)->layer_as_FillLayer()->descriptor()->value();
1877 IConnectableLayer* layer = m_Network->AddFillLayer(descriptor, layerName.c_str());
1882 RegisterInputSlots(graph, layerIndex, layer);
1883 RegisterOutputSlots(graph, layerIndex, layer);
1886 void IDeserializer::DeserializerImpl::ParseGreater(
GraphPtr graph,
unsigned int layerIndex)
1889 auto inputs = GetInputs(graph, layerIndex);
1893 auto outputs = GetOutputs(graph, layerIndex);
1896 auto layerName = GetLayerName(graph, layerIndex);
1898 IConnectableLayer* layer = m_Network->AddComparisonLayer(descriptor, layerName.c_str());
1903 RegisterInputSlots(graph, layerIndex, layer);
1904 RegisterOutputSlots(graph, layerIndex, layer);
1907 void IDeserializer::DeserializerImpl::ParseInstanceNormalization(
GraphPtr graph,
unsigned int layerIndex)
1911 auto inputs = GetInputs(graph, layerIndex);
1914 auto outputs = GetOutputs(graph, layerIndex);
1917 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_InstanceNormalizationLayer();
1918 auto fbDescriptor = fbLayer->descriptor();
1921 descriptor.
m_Gamma = fbDescriptor->gamma();
1922 descriptor.
m_Beta = fbDescriptor->beta();
1923 descriptor.
m_Eps = fbDescriptor->eps();
1926 const std::string layerName = GetLayerName(graph, layerIndex);
1929 IConnectableLayer* layer = m_Network->AddInstanceNormalizationLayer(descriptor, layerName.c_str());
1932 RegisterInputSlots(graph, layerIndex, layer);
1933 RegisterOutputSlots(graph, layerIndex, layer);
1936 void IDeserializer::DeserializerImpl::ParseL2Normalization(
GraphPtr graph,
unsigned int layerIndex)
1940 auto inputs = GetInputs(graph, layerIndex);
1943 auto outputs = GetOutputs(graph, layerIndex);
1947 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_L2NormalizationLayer();
1948 auto flatBufferDescriptor = flatBufferLayer->descriptor();
1950 auto layerName = GetLayerName(graph, layerIndex);
1953 descriptor.
m_Eps = flatBufferDescriptor->eps();
1955 IConnectableLayer* layer = m_Network->AddL2NormalizationLayer(descriptor, layerName.c_str());
1958 RegisterInputSlots(graph, layerIndex, layer);
1959 RegisterOutputSlots(graph, layerIndex, layer);
1962 void IDeserializer::DeserializerImpl::ParseLogicalBinary(
GraphPtr graph,
unsigned int layerIndex)
1967 auto inputs = GetInputs(graph, layerIndex);
1970 auto outputs = GetOutputs(graph, layerIndex);
1973 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_LogicalBinaryLayer();
1974 auto fbDescriptor = fbLayer->descriptor();
1979 const std::string& layerName = GetLayerName(graph, layerIndex);
1980 IConnectableLayer* layer = m_Network->AddLogicalBinaryLayer(descriptor, layerName.c_str());
1985 RegisterInputSlots(graph, layerIndex, layer);
1986 RegisterOutputSlots(graph, layerIndex, layer);
1989 void IDeserializer::DeserializerImpl::ParseLogSoftmax(
GraphPtr graph,
unsigned int layerIndex)
2000 descriptor.
m_Beta = graph->layers()->Get(layerIndex)->layer_as_LogSoftmaxLayer()->descriptor()->beta();
2001 descriptor.
m_Axis = graph->layers()->Get(layerIndex)->layer_as_LogSoftmaxLayer()->descriptor()->axis();
2002 auto layerName = GetLayerName(graph, layerIndex);
2004 IConnectableLayer* layer = m_Network->AddLogSoftmaxLayer(descriptor, layerName.c_str());
2009 RegisterInputSlots(graph, layerIndex, layer);
2010 RegisterOutputSlots(graph, layerIndex, layer);
2013 void IDeserializer::DeserializerImpl::ParseMinimum(
GraphPtr graph,
unsigned int layerIndex)
2016 auto inputs = GetInputs(graph, layerIndex);
2020 auto outputs = GetOutputs(graph, layerIndex);
2023 auto layerName = GetLayerName(graph, layerIndex);
2025 IConnectableLayer* layer = m_Network->AddElementwiseBinaryLayer(descriptor, layerName.c_str());
2030 RegisterInputSlots(graph, layerIndex, layer);
2031 RegisterOutputSlots(graph, layerIndex, layer);
2034 void IDeserializer::DeserializerImpl::ParseMaximum(
GraphPtr graph,
unsigned int layerIndex)
2037 auto inputs = GetInputs(graph, layerIndex);
2041 auto outputs = GetOutputs(graph, layerIndex);
2044 auto layerName = GetLayerName(graph, layerIndex);
2046 IConnectableLayer* layer = m_Network->AddElementwiseBinaryLayer(descriptor, layerName.c_str());
2051 RegisterInputSlots(graph, layerIndex, layer);
2052 RegisterOutputSlots(graph, layerIndex, layer);
2056 unsigned int layerIndex)
2058 auto layerType = graph->layers()->Get(layerIndex)->layer_type();
2062 case Layer::Layer_ConcatLayer:
2063 return graph->layers()->Get(layerIndex)->layer_as_ConcatLayer()->descriptor();
2064 case Layer::Layer_MergerLayer:
2065 return graph->layers()->Get(layerIndex)->layer_as_MergerLayer()->descriptor();
2070 void IDeserializer::DeserializerImpl::ParseChannelShuffle(
GraphPtr graph,
unsigned int layerIndex)
2081 descriptor.
m_Axis = graph->layers()->Get(layerIndex)->layer_as_ChannelShuffleLayer()->descriptor()->axis();
2083 graph->layers()->Get(layerIndex)->layer_as_ChannelShuffleLayer()->descriptor()->numGroups();
2085 auto layerName = GetLayerName(graph, layerIndex);
2086 IConnectableLayer* layer = m_Network->AddChannelShuffleLayer(descriptor, layerName.c_str());
2091 RegisterInputSlots(graph, layerIndex, layer);
2092 RegisterOutputSlots(graph, layerIndex, layer);
2094 void IDeserializer::DeserializerImpl::ParseComparison(
GraphPtr graph,
unsigned int layerIndex)
2099 auto inputs = GetInputs(graph, layerIndex);
2102 auto outputs = GetOutputs(graph, layerIndex);
2105 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_ComparisonLayer();
2106 auto fbDescriptor = fbLayer->descriptor();
2111 const std::string& layerName = GetLayerName(graph, layerIndex);
2112 IConnectableLayer* layer = m_Network->AddComparisonLayer(descriptor, layerName.c_str());
2117 RegisterInputSlots(graph, layerIndex, layer);
2118 RegisterOutputSlots(graph, layerIndex, layer);
2121 void IDeserializer::DeserializerImpl::ParseElementwiseBinary(
GraphPtr graph,
unsigned int layerIndex)
2126 auto inputs = GetInputs(graph, layerIndex);
2129 auto outputs = GetOutputs(graph, layerIndex);
2132 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_ElementwiseBinaryLayer();
2133 auto fbDescriptor = fbLayer->descriptor();
2138 const std::string& layerName = GetLayerName(graph, layerIndex);
2139 IConnectableLayer* layer = m_Network->AddElementwiseBinaryLayer(descriptor, layerName.c_str());
2144 RegisterInputSlots(graph, layerIndex, layer);
2145 RegisterOutputSlots(graph, layerIndex, layer);
2148 void IDeserializer::DeserializerImpl::ParseElementwiseUnary(
GraphPtr graph,
unsigned int layerIndex)
2153 auto inputs = GetInputs(graph, layerIndex);
2156 auto outputs = GetOutputs(graph, layerIndex);
2159 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_ElementwiseUnaryLayer();
2160 auto fbDescriptor = fbLayer->descriptor();
2165 const std::string& layerName = GetLayerName(graph, layerIndex);
2166 IConnectableLayer* layer = m_Network->AddElementwiseUnaryLayer(descriptor, layerName.c_str());
2171 RegisterInputSlots(graph, layerIndex, layer);
2172 RegisterOutputSlots(graph, layerIndex, layer);
2175 void IDeserializer::DeserializerImpl::ParseConcat(
GraphPtr graph,
unsigned int layerIndex)
2180 auto outputs = GetOutputs(graph, layerIndex);
2183 auto layerName = GetLayerName(graph, layerIndex);
2185 unsigned int numViews = originsDescriptor->numViews();
2186 unsigned int numDimensions = originsDescriptor->numDimensions();
2189 auto inputs = GetInputs(graph, layerIndex);
2193 auto originsPtr = originsDescriptor->viewOrigins();
2194 for (
unsigned int v = 0; v < numViews; ++v)
2196 auto originPtr = originsPtr->Get(v);
2197 for (
unsigned int d = 0; d < numDimensions; ++d)
2199 uint32_t value = originPtr->data()->Get(d);
2200 descriptor.SetViewOriginCoord(v, d, value);
2203 descriptor.SetConcatAxis(originsDescriptor->concatAxis());
2205 IConnectableLayer* layer = m_Network->AddConcatLayer(descriptor, layerName.c_str());
2209 RegisterInputSlots(graph, layerIndex, layer);
2210 RegisterOutputSlots(graph, layerIndex, layer);
2213 void IDeserializer::DeserializerImpl::ParseMultiplication(
GraphPtr graph,
unsigned int layerIndex)
2216 auto inputs = GetInputs(graph, layerIndex);
2220 auto outputs = GetOutputs(graph, layerIndex);
2223 auto layerName = GetLayerName(graph, layerIndex);
2225 IConnectableLayer* layer = m_Network->AddElementwiseBinaryLayer(descriptor, layerName.c_str());
2230 RegisterInputSlots(graph, layerIndex, layer);
2231 RegisterOutputSlots(graph, layerIndex, layer);
2234 void IDeserializer::DeserializerImpl::ParseFloor(
GraphPtr graph,
unsigned int layerIndex)
2239 auto inputs = GetInputs(graph, layerIndex);
2242 auto outputs = GetOutputs(graph, layerIndex);
2245 auto layerName = GetLayerName(graph, layerIndex);
2249 layer = m_Network->AddFloorLayer(layerName.c_str());
2254 RegisterInputSlots(graph, layerIndex, layer);
2255 RegisterOutputSlots(graph, layerIndex, layer);
2258 void IDeserializer::DeserializerImpl::ParseFullyConnected(
GraphPtr graph,
unsigned int layerIndex)
2261 auto inputs = GetInputs(graph, layerIndex);
2264 auto outputs = GetOutputs(graph, layerIndex);
2267 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_FullyConnectedLayer();
2268 auto layerName = GetLayerName(graph, layerIndex);
2269 auto flatBufferDescriptor = flatBufferLayer->descriptor();
2272 fullyConnectedDescriptor.
m_BiasEnabled = flatBufferDescriptor->biasEnabled();
2274 fullyConnectedDescriptor.
m_ConstantWeights = flatBufferDescriptor->constantWeights();
2277 std::vector<unsigned int> ignoreSlots {};
2281 if (this->GetFeatureVersions(graph).m_ConstTensorsAsInputs <= 0)
2286 layer = m_Network->AddFullyConnectedLayer(fullyConnectedDescriptor,
2290 auto weightsLayer = m_Network->AddConstantLayer(weightsTensor);
2291 weightsLayer->GetOutputSlot(0).Connect(layer->
GetInputSlot(1u));
2292 weightsLayer->GetOutputSlot(0).SetTensorInfo(weightsTensor.
GetInfo());
2293 ignoreSlots.emplace_back(1u);
2298 auto biasLayer = m_Network->AddConstantLayer(biasTensor);
2299 biasLayer->GetOutputSlot(0).Connect(layer->
GetInputSlot(2u));
2300 biasLayer->GetOutputSlot(0).SetTensorInfo(biasTensor.
GetInfo());
2301 ignoreSlots.emplace_back(2u);
2306 layer = m_Network->AddFullyConnectedLayer(fullyConnectedDescriptor,
2308 uint32_t numInputs = fullyConnectedDescriptor.
GetNumInputs();
2315 RegisterInputSlots(graph, layerIndex, layer, ignoreSlots);
2316 RegisterOutputSlots(graph, layerIndex, layer);
2319 void IDeserializer::DeserializerImpl::ParsePad(
GraphPtr graph,
unsigned int layerIndex)
2329 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_PadLayer()->descriptor();
2330 auto flatBufferPadList = flatBufferDescriptor->padList();
2331 auto paddingMode = flatBufferDescriptor->paddingMode();
2332 float padValue = flatBufferDescriptor->padValue();
2334 if (flatBufferPadList->size() % 2 != 0)
2336 throw ParseException(fmt::format(
"The size of the pad list must be divisible by 2 {}",
2340 std::vector<std::pair<unsigned int, unsigned int>> padList;
2341 padList.reserve(flatBufferPadList->size() / 2);
2342 for (
unsigned int i = 0; i < flatBufferPadList->size() - 1; i += 2)
2344 padList.emplace_back(flatBufferPadList->Get(i), flatBufferPadList->Get(i+1));
2349 auto layerName = GetLayerName(graph, layerIndex);
2350 IConnectableLayer* layer = m_Network->AddPadLayer(descriptor, layerName.c_str());
2355 RegisterInputSlots(graph, layerIndex, layer);
2356 RegisterOutputSlots(graph, layerIndex, layer);
2359 void IDeserializer::DeserializerImpl::ParsePermute(
GraphPtr graph,
unsigned int layerIndex)
2364 graph->layers()->Get(layerIndex)->layer_as_PermuteLayer()->descriptor()->dimMappings();
2366 auto inputs = GetInputs(graph, layerIndex);
2369 auto outputs = GetOutputs(graph, layerIndex);
2373 auto layerName = GetLayerName(graph, layerIndex);
2376 IConnectableLayer* layer = m_Network->AddPermuteLayer(descriptor, layerName.c_str());
2379 RegisterInputSlots(graph, layerIndex, layer);
2380 RegisterOutputSlots(graph, layerIndex, layer);
2384 unsigned int layerIndex)
2389 switch (pooling2dDesc->poolType())
2391 case PoolingAlgorithm_Average:
2396 case PoolingAlgorithm_Max:
2401 case PoolingAlgorithm_L2:
2412 switch (pooling2dDesc->outputShapeRounding())
2414 case OutputShapeRounding_Floor:
2419 case OutputShapeRounding_Ceiling:
2430 switch (pooling2dDesc->paddingMethod())
2432 case PaddingMethod_Exclude:
2437 case PaddingMethod_IgnoreValue:
2448 switch (pooling2dDesc->dataLayout())
2450 case DataLayout_NCHW:
2455 case DataLayout_NHWC:
2467 desc.
m_PadLeft = pooling2dDesc->padLeft();
2469 desc.
m_PadTop = pooling2dDesc->padTop();
2470 desc.
m_StrideX = pooling2dDesc->strideX();
2471 desc.
m_StrideY = pooling2dDesc->strideY();
2479 unsigned int layerIndex)
2484 switch (pooling3dDesc->poolType())
2486 case PoolingAlgorithm_Average:
2491 case PoolingAlgorithm_Max:
2496 case PoolingAlgorithm_L2:
2507 switch (pooling3dDesc->outputShapeRounding())
2509 case OutputShapeRounding_Floor:
2514 case OutputShapeRounding_Ceiling:
2525 switch (pooling3dDesc->paddingMethod())
2527 case PaddingMethod_Exclude:
2532 case PaddingMethod_IgnoreValue:
2543 switch (pooling3dDesc->dataLayout())
2545 case DataLayout_NCDHW:
2550 case DataLayout_NDHWC:
2562 desc.
m_PadLeft = pooling3dDesc->padLeft();
2564 desc.
m_PadTop = pooling3dDesc->padTop();
2566 desc.
m_PadBack = pooling3dDesc->padBack();
2567 desc.
m_StrideX = pooling3dDesc->strideX();
2568 desc.
m_StrideY = pooling3dDesc->strideY();
2569 desc.
m_StrideZ = pooling3dDesc->strideZ();
2577 void IDeserializer::DeserializerImpl::ParsePooling2d(
GraphPtr graph,
unsigned int layerIndex)
2581 auto pooling2dDes = graph->layers()->Get(layerIndex)->layer_as_Pooling2dLayer()->descriptor();
2582 auto inputs = GetInputs(graph, layerIndex);
2585 auto outputs = GetOutputs(graph, layerIndex);
2589 auto pooling2dDescriptor = GetPooling2dDescriptor(pooling2dDes, layerIndex);
2590 auto layerName = GetLayerName(graph, layerIndex);
2591 IConnectableLayer* layer = m_Network->AddPooling2dLayer(pooling2dDescriptor, layerName.c_str());
2594 RegisterInputSlots(graph, layerIndex, layer);
2595 RegisterOutputSlots(graph, layerIndex, layer);
2598 void IDeserializer::DeserializerImpl::ParsePooling3d(
GraphPtr graph,
unsigned int layerIndex)
2602 auto pooling3dDes = graph->layers()->Get(layerIndex)->layer_as_Pooling3dLayer()->descriptor();
2603 auto inputs = GetInputs(graph, layerIndex);
2606 auto outputs = GetOutputs(graph, layerIndex);
2610 auto pooling3dDescriptor = GetPooling3dDescriptor(pooling3dDes, layerIndex);
2611 auto layerName = GetLayerName(graph, layerIndex);
2612 IConnectableLayer* layer = m_Network->AddPooling3dLayer(pooling3dDescriptor, layerName.c_str());
2615 RegisterInputSlots(graph, layerIndex, layer);
2616 RegisterOutputSlots(graph, layerIndex, layer);
2619 void IDeserializer::DeserializerImpl::ParseQuantize(
GraphPtr graph,
unsigned int layerIndex)
2623 auto inputs = GetInputs(graph, layerIndex);
2626 auto outputs = GetOutputs(graph, layerIndex);
2630 auto layerName = GetLayerName(graph, layerIndex);
2634 RegisterInputSlots(graph, layerIndex, layer);
2635 RegisterOutputSlots(graph, layerIndex, layer);
2639 const std::vector<uint32_t>& targetDimsIn)
2641 std::vector<unsigned int> outputDims(targetDimsIn.begin(), targetDimsIn.end());
2642 const auto stretchDim = std::find(targetDimsIn.begin(), targetDimsIn.end(), -1);
2644 if (stretchDim != targetDimsIn.end())
2646 if (std::find(std::next(stretchDim), targetDimsIn.end(), -1) != targetDimsIn.end())
2648 throw ParseException(fmt::format(
"At most one component of shape can be -1 {}",
2652 auto targetNumElements =
2653 armnn::numeric_cast<unsigned int>(
2654 std::accumulate(targetDimsIn.begin(), targetDimsIn.end(), -1, std::multiplies<int32_t>()));
2656 auto stretchIndex =
static_cast<size_t>(std::distance(targetDimsIn.begin(), stretchDim));
2657 if (targetNumElements == 0)
2661 outputDims[stretchIndex] = 0;
2666 fmt::format(
"Input to reshape is a tensor with elements, but the requested shape has 0. {}",
2672 outputDims[stretchIndex] = inputTensorInfo.
GetNumElements() / targetNumElements;
2684 void IDeserializer::DeserializerImpl::ParseRank(
GraphPtr graph,
unsigned int layerIndex)
2694 auto layerName = GetLayerName(graph, layerIndex);
2700 RegisterInputSlots(graph, layerIndex, layer);
2701 RegisterOutputSlots(graph, layerIndex, layer);
2704 void IDeserializer::DeserializerImpl::ParseReduce(
GraphPtr graph,
unsigned int layerIndex)
2709 auto inputs = GetInputs(graph, layerIndex);
2712 auto outputs = GetOutputs(graph, layerIndex);
2715 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_ReduceLayer();
2716 auto fbDescriptor = fbLayer->descriptor();
2717 auto flatBufferAxis = fbDescriptor->axis();
2720 descriptor.
m_KeepDims = fbDescriptor->keepDims();
2721 descriptor.
m_vAxis = std::vector<unsigned int>(flatBufferAxis->begin(), flatBufferAxis->end());
2724 const std::string& layerName = GetLayerName(graph, layerIndex);
2725 IConnectableLayer* layer = m_Network->AddReduceLayer(descriptor, layerName.c_str());
2730 RegisterInputSlots(graph, layerIndex, layer);
2731 RegisterOutputSlots(graph, layerIndex, layer);
2734 void IDeserializer::DeserializerImpl::ParseReshape(
GraphPtr graph,
unsigned int layerIndex)
2737 auto inputs = GetInputs(graph, layerIndex);
2739 auto outputs = GetOutputs(graph, layerIndex);
2745 const auto targetDims = graph->layers()->Get(layerIndex)->layer_as_ReshapeLayer()->descriptor()->targetShape();
2746 std::vector<uint32_t> outputDims(targetDims->begin(), targetDims->begin() + targetDims->size());
2751 const std::vector<uint32_t> expectedDims(outputs[0]->dimensions()->begin(),
2752 outputs[0]->dimensions()->begin() + outputs[0]->dimensions()->size());
2754 if (inputs.size() > 1 && !
CheckShape(reshapeOutputTensorShape, expectedDims))
2756 std::stringstream ss;
2757 ss <<
"New shape defined in reshape parameters "
2758 << reshapeOutputTensorShape
2759 <<
" does not equal output shape "
2760 << actualOutputTensorInfo.
GetShape()
2769 auto layerName = GetLayerName(graph, layerIndex);
2770 IConnectableLayer* layer = m_Network->AddReshapeLayer(reshapeDesc, layerName.c_str());
2773 RegisterInputSlots(graph, layerIndex, layer);
2774 RegisterOutputSlots(graph, layerIndex, layer);
2777 void IDeserializer::DeserializerImpl::ParseResize(
GraphPtr graph,
unsigned int layerIndex)
2787 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_ResizeLayer()->descriptor();
2790 descriptor.
m_TargetWidth = flatBufferDescriptor->targetWidth();
2791 descriptor.
m_TargetHeight = flatBufferDescriptor->targetHeight();
2794 descriptor.
m_AlignCorners = flatBufferDescriptor->alignCorners();
2797 auto layerName = GetLayerName(graph, layerIndex);
2798 IConnectableLayer* layer = m_Network->AddResizeLayer(descriptor, layerName.c_str());
2803 RegisterInputSlots(graph, layerIndex, layer);
2804 RegisterOutputSlots(graph, layerIndex, layer);
2807 void IDeserializer::DeserializerImpl::ParseReverseV2(
GraphPtr graph,
unsigned int layerIndex)
2817 auto layerName = GetLayerName(graph, layerIndex);
2823 RegisterInputSlots(graph, layerIndex, layer);
2824 RegisterOutputSlots(graph, layerIndex, layer);
2829 void IDeserializer::DeserializerImpl::ParseResizeBilinear(
GraphPtr graph,
unsigned int layerIndex)
2839 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_ResizeBilinearLayer()->descriptor();
2842 descriptor.
m_TargetWidth = flatBufferDescriptor->targetWidth();
2843 descriptor.
m_TargetHeight = flatBufferDescriptor->targetHeight();
2846 descriptor.
m_AlignCorners = flatBufferDescriptor->alignCorners();
2849 auto layerName = GetLayerName(graph, layerIndex);
2850 IConnectableLayer* layer = m_Network->AddResizeLayer(descriptor, layerName.c_str());
2855 RegisterInputSlots(graph, layerIndex, layer);
2856 RegisterOutputSlots(graph, layerIndex, layer);
2859 void IDeserializer::DeserializerImpl::ParseShape(
GraphPtr graph,
unsigned int layerIndex)
2869 auto layerName = GetLayerName(graph, layerIndex);
2875 RegisterInputSlots(graph, layerIndex, layer);
2876 RegisterOutputSlots(graph, layerIndex, layer);
2879 void IDeserializer::DeserializerImpl::ParseSoftmax(
GraphPtr graph,
unsigned int layerIndex)
2890 descriptor.
m_Beta = graph->layers()->Get(layerIndex)->layer_as_SoftmaxLayer()->descriptor()->beta();
2891 descriptor.
m_Axis = graph->layers()->Get(layerIndex)->layer_as_SoftmaxLayer()->descriptor()->axis();
2892 auto layerName = GetLayerName(graph, layerIndex);
2894 IConnectableLayer* layer = m_Network->AddSoftmaxLayer(descriptor, layerName.c_str());
2899 RegisterInputSlots(graph, layerIndex, layer);
2900 RegisterOutputSlots(graph, layerIndex, layer);
2903 void IDeserializer::DeserializerImpl::ParseSpaceToBatchNd(
GraphPtr graph,
unsigned int layerIndex)
2913 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_SpaceToBatchNdLayer()->descriptor();
2914 auto flatBufferPadList = flatBufferDescriptor->padList();
2915 auto flatBufferBlockShape = flatBufferDescriptor->blockShape();
2917 if (flatBufferPadList->size() % 2 != 0)
2919 throw ParseException(fmt::format(
"The size of the pad list must be divisible by 2 {}",
2923 std::vector<std::pair<unsigned int, unsigned int>> padList;
2924 padList.reserve(flatBufferPadList->size() / 2);
2925 for (
unsigned int i = 0; i < flatBufferPadList->size() - 1; i += 2)
2927 padList.emplace_back(flatBufferPadList->Get(i), flatBufferPadList->Get(i+1));
2933 std::vector<unsigned int>(flatBufferBlockShape->begin(), flatBufferBlockShape->end());
2936 auto layerName = GetLayerName(graph, layerIndex);
2937 IConnectableLayer* layer = m_Network->AddSpaceToBatchNdLayer(descriptor, layerName.c_str());
2942 RegisterInputSlots(graph, layerIndex, layer);
2943 RegisterOutputSlots(graph, layerIndex, layer);
2946 void IDeserializer::DeserializerImpl::ParseSpaceToDepth(
GraphPtr graph,
unsigned int layerIndex)
2956 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_SpaceToDepthLayer()->descriptor();
2959 descriptor.
m_BlockSize = flatBufferDescriptor->blockSize();
2962 auto layerName = GetLayerName(graph, layerIndex);
2963 IConnectableLayer* layer = m_Network->AddSpaceToDepthLayer(descriptor, layerName.c_str());
2968 RegisterInputSlots(graph, layerIndex, layer);
2969 RegisterOutputSlots(graph, layerIndex, layer);
2974 unsigned int layerIndex)
2979 switch (normalizationDescriptor->normChannelType())
2981 case NormalizationAlgorithmChannel_Across:
2986 case NormalizationAlgorithmChannel_Within:
2997 switch (normalizationDescriptor->normMethodType())
2999 case NormalizationAlgorithmMethod_LocalBrightness:
3004 case NormalizationAlgorithmMethod_LocalContrast:
3015 switch (normalizationDescriptor->dataLayout())
3017 case DataLayout_NCHW:
3022 case DataLayout_NHWC:
3033 desc.
m_Alpha = normalizationDescriptor->alpha();
3034 desc.
m_Beta = normalizationDescriptor->beta();
3035 desc.
m_K = normalizationDescriptor->k();
3036 desc.
m_NormSize = normalizationDescriptor->normSize();
3041 void IDeserializer::DeserializerImpl::ParseNormalization(
GraphPtr graph,
unsigned int layerIndex)
3045 auto normalizationDes = graph->layers()->Get(layerIndex)->layer_as_NormalizationLayer()->descriptor();
3055 auto normalizationDescriptor = GetNormalizationDescriptor(normalizationDes, layerIndex);
3056 auto layerName = GetLayerName(graph, layerIndex);
3058 IConnectableLayer* layer = m_Network->AddNormalizationLayer(normalizationDescriptor, layerName.c_str());
3061 RegisterInputSlots(graph, layerIndex, layer);
3062 RegisterOutputSlots(graph, layerIndex, layer);
3065 void IDeserializer::DeserializerImpl::ParseRsqrt(
GraphPtr graph,
unsigned int layerIndex)
3068 auto inputs = GetInputs(graph, layerIndex);
3072 auto outputs = GetOutputs(graph, layerIndex);
3075 auto layerName = GetLayerName(graph, layerIndex);
3078 IConnectableLayer* layer = m_Network->AddElementwiseUnaryLayer(descriptor, layerName.c_str());
3082 RegisterInputSlots(graph, layerIndex, layer);
3083 RegisterOutputSlots(graph, layerIndex, layer);
3086 void IDeserializer::DeserializerImpl::ParseSlice(
GraphPtr graph,
unsigned int layerIndex)
3090 auto inputs = GetInputs(graph, layerIndex);
3093 auto outputs = GetOutputs(graph, layerIndex);
3096 auto fbDescriptor = graph->layers()->Get(layerIndex)->layer_as_SliceLayer()->descriptor();
3098 auto fbBegin = fbDescriptor->begin();
3099 auto fbSize = fbDescriptor->size();
3101 if (fbBegin->size() != fbSize->size())
3103 throw ParseException(fmt::format(
"Begin and size descriptors must have the same length {}",
3108 descriptor.
m_Begin.insert(descriptor.
m_Begin.end(), fbBegin->begin(), fbBegin->end());
3109 descriptor.
m_Size.insert(descriptor.
m_Size.end(), fbSize->begin(), fbSize->end());
3111 auto layerName = GetLayerName(graph, layerIndex);
3112 IConnectableLayer* layer = m_Network->AddSliceLayer(descriptor, layerName.c_str());
3117 RegisterInputSlots(graph, layerIndex, layer);
3118 RegisterOutputSlots(graph, layerIndex, layer);
3121 void IDeserializer::DeserializerImpl::ParseStridedSlice(
GraphPtr graph,
unsigned int layerIndex)
3131 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_StridedSliceLayer()->descriptor();
3133 auto flatBufferBegin = flatBufferDescriptor->begin();
3134 auto flatBufferEnd = flatBufferDescriptor->end();
3135 auto flatBufferStride = flatBufferDescriptor->stride();
3137 if (!(flatBufferBegin->size() == flatBufferEnd->size() &&
3138 flatBufferBegin->size() == flatBufferStride->size()))
3140 throw ParseException(fmt::format(
"The size of the begin, end, and stride must be equal {}",
3144 std::vector<int> begin(flatBufferBegin->begin(), flatBufferBegin->end());
3145 std::vector<int> end(flatBufferEnd->begin(), flatBufferEnd->end());
3146 std::vector<int> stride(flatBufferStride->begin(), flatBufferStride->end());
3149 descriptor.m_BeginMask = flatBufferDescriptor->beginMask();
3150 descriptor.m_EndMask = flatBufferDescriptor->endMask();
3151 descriptor.m_ShrinkAxisMask = flatBufferDescriptor->shrinkAxisMask();
3152 descriptor.m_EllipsisMask = flatBufferDescriptor->ellipsisMask();
3153 descriptor.m_NewAxisMask = flatBufferDescriptor->newAxisMask();
3154 descriptor.m_DataLayout =
ToDataLayout(flatBufferDescriptor->dataLayout());
3156 auto layerName = GetLayerName(graph, layerIndex);
3157 IConnectableLayer* layer = m_Network->AddStridedSliceLayer(descriptor, layerName.c_str());
3162 RegisterInputSlots(graph, layerIndex, layer);
3163 RegisterOutputSlots(graph, layerIndex, layer);
3166 void IDeserializer::DeserializerImpl::ParseSubtraction(
GraphPtr graph,
unsigned int layerIndex)
3169 auto inputs = GetInputs(graph, layerIndex);
3173 auto outputs = GetOutputs(graph, layerIndex);
3176 auto layerName = GetLayerName(graph, layerIndex);
3178 IConnectableLayer* layer = m_Network->AddElementwiseBinaryLayer(descriptor, layerName.c_str());
3183 RegisterInputSlots(graph, layerIndex, layer);
3184 RegisterOutputSlots(graph, layerIndex, layer);
3187 void IDeserializer::DeserializerImpl::ParseGather(
GraphPtr graph,
unsigned int layerIndex)
3198 descriptor.
m_Axis = graph->layers()->Get(layerIndex)->layer_as_GatherLayer()->descriptor()->axis();
3200 auto layerName = GetLayerName(graph, layerIndex);
3201 IConnectableLayer* layer = m_Network->AddGatherLayer(descriptor, layerName.c_str());
3206 RegisterInputSlots(graph, layerIndex, layer);
3207 RegisterOutputSlots(graph, layerIndex, layer);
3210 void IDeserializer::DeserializerImpl::ParseGatherNd(
GraphPtr graph,
unsigned int layerIndex)
3220 auto layerName = GetLayerName(graph, layerIndex);
3226 RegisterInputSlots(graph, layerIndex, layer);
3227 RegisterOutputSlots(graph, layerIndex, layer);
3230 void IDeserializer::DeserializerImpl::ParseMean(
GraphPtr graph,
unsigned int layerIndex)
3240 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_MeanLayer()->descriptor();
3241 auto flatBufferAxis = flatBufferDescriptor->axis();
3242 auto flatBufferKeepDims = flatBufferDescriptor->keepDims();
3245 descriptor.
m_Axis = std::vector<unsigned int>(flatBufferAxis->begin(), flatBufferAxis->end());
3248 auto layerName = GetLayerName(graph, layerIndex);
3249 IConnectableLayer* layer = m_Network->AddMeanLayer(descriptor, layerName.c_str());
3254 RegisterInputSlots(graph, layerIndex, layer);
3255 RegisterOutputSlots(graph, layerIndex, layer);
3258 void IDeserializer::DeserializerImpl::ParseSplitter(
GraphPtr graph,
unsigned int layerIndex)
3267 auto flatBufferViewsDescriptor = graph->layers()->Get(layerIndex)->layer_as_SplitterLayer()->descriptor();
3268 auto flatBufferViewSizes = flatBufferViewsDescriptor->viewSizes();
3269 auto flatBufferOriginsDescriptor = flatBufferViewsDescriptor->origins();
3270 auto flatBufferViewOrigins = flatBufferOriginsDescriptor->viewOrigins();
3271 uint32_t numViews = flatBufferOriginsDescriptor->numViews();
3272 uint32_t numDimensions = flatBufferOriginsDescriptor->numDimensions();
3279 for(
unsigned int vIdx = 0; vIdx < numViews; ++vIdx)
3281 for (
unsigned int dIdx = 0; dIdx < numDimensions; ++dIdx)
3283 viewsDescriptor.SetViewSize(vIdx, dIdx, flatBufferViewSizes->Get(vIdx)->data()->Get(dIdx));
3284 viewsDescriptor.SetViewOriginCoord(vIdx, dIdx, flatBufferViewOrigins->Get(vIdx)->data()->Get(dIdx));
3288 if (flatBufferViewsDescriptor->hasAxis())
3290 viewsDescriptor.SetAxis(flatBufferViewsDescriptor->axis());
3293 auto layerName = GetLayerName(graph, layerIndex);
3294 IConnectableLayer* layer = m_Network->AddSplitterLayer(viewsDescriptor, layerName.c_str());
3297 for(
unsigned int vIdx = 0; vIdx < numViews; ++vIdx)
3303 RegisterInputSlots(graph, layerIndex, layer);
3304 RegisterOutputSlots(graph, layerIndex, layer);
3322 void IDeserializer::DeserializerImpl::ParseLstm(
GraphPtr graph,
unsigned int layerIndex)
3326 auto inputs = GetInputs(graph, layerIndex);
3329 auto outputs = GetOutputs(graph, layerIndex);
3332 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_LstmLayer();
3333 auto layerName = GetLayerName(graph, layerIndex);
3334 auto flatBufferDescriptor = flatBufferLayer->descriptor();
3335 auto flatBufferInputParams = flatBufferLayer->inputParams();
3337 auto lstmDescriptor = GetLstmDescriptor(flatBufferDescriptor);
3365 if (!lstmDescriptor.m_CifgEnabled)
3367 inputToInputWeights =
ToConstTensor(flatBufferInputParams->inputToInputWeights());
3368 recurrentToInputWeights =
ToConstTensor(flatBufferInputParams->recurrentToInputWeights());
3369 cellToInputWeights =
ToConstTensor(flatBufferInputParams->cellToInputWeights());
3370 inputGateBias =
ToConstTensor(flatBufferInputParams->inputGateBias());
3380 if (lstmDescriptor.m_ProjectionEnabled)
3382 projectionWeights =
ToConstTensor(flatBufferInputParams->projectionWeights());
3383 projectionBias =
ToConstTensor(flatBufferInputParams->projectionBias());
3391 if (lstmDescriptor.m_PeepholeEnabled)
3393 cellToForgetWeights =
ToConstTensor(flatBufferInputParams->cellToForgetWeights());
3394 cellToOutputWeights =
ToConstTensor(flatBufferInputParams->cellToOutputWeights());
3404 if (lstmDescriptor.m_LayerNormEnabled)
3406 if (!lstmDescriptor.m_CifgEnabled)
3408 inputLayerNormWeights =
ToConstTensor(flatBufferInputParams->inputLayerNormWeights());
3411 forgetLayerNormWeights =
ToConstTensor(flatBufferInputParams->forgetLayerNormWeights());
3412 cellLayerNormWeights =
ToConstTensor(flatBufferInputParams->cellLayerNormWeights());
3413 outputLayerNormWeights =
ToConstTensor(flatBufferInputParams->outputLayerNormWeights());
3420 IConnectableLayer* layer = m_Network->AddLstmLayer(lstmDescriptor, lstmInputParams, layerName.c_str());
3434 RegisterInputSlots(graph, layerIndex, layer);
3435 RegisterOutputSlots(graph, layerIndex, layer);
3447 desc.
m_CellClip = qLstmDescriptor->cellClip();
3461 void IDeserializer::DeserializerImpl::ParseQLstm(
GraphPtr graph,
unsigned int layerIndex)
3465 auto inputs = GetInputs(graph, layerIndex);
3468 auto outputs = GetOutputs(graph, layerIndex);
3471 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_QLstmLayer();
3472 auto layerName = GetLayerName(graph, layerIndex);
3473 auto flatBufferDescriptor = flatBufferLayer->descriptor();
3474 auto flatBufferInputParams = flatBufferLayer->inputParams();
3476 auto qLstmDescriptor = GetQLstmDescriptor(flatBufferDescriptor);
3505 if (!qLstmDescriptor.m_CifgEnabled)
3507 inputToInputWeights =
ToConstTensor(flatBufferInputParams->inputToInputWeights());
3508 recurrentToInputWeights =
ToConstTensor(flatBufferInputParams->recurrentToInputWeights());
3509 inputGateBias =
ToConstTensor(flatBufferInputParams->inputGateBias());
3520 if (qLstmDescriptor.m_ProjectionEnabled)
3522 projectionWeights =
ToConstTensor(flatBufferInputParams->projectionWeights());
3523 projectionBias =
ToConstTensor(flatBufferInputParams->projectionBias());
3534 if (qLstmDescriptor.m_PeepholeEnabled)
3536 if (!qLstmDescriptor.m_CifgEnabled)
3538 cellToInputWeights =
ToConstTensor(flatBufferInputParams->cellToInputWeights());
3542 cellToForgetWeights =
ToConstTensor(flatBufferInputParams->cellToForgetWeights());
3543 cellToOutputWeights =
ToConstTensor(flatBufferInputParams->cellToOutputWeights());
3555 if (qLstmDescriptor.m_LayerNormEnabled)
3557 if (!qLstmDescriptor.m_CifgEnabled)
3559 inputLayerNormWeights =
ToConstTensor(flatBufferInputParams->inputLayerNormWeights());
3563 forgetLayerNormWeights =
ToConstTensor(flatBufferInputParams->forgetLayerNormWeights());
3564 cellLayerNormWeights =
ToConstTensor(flatBufferInputParams->cellLayerNormWeights());
3565 outputLayerNormWeights =
ToConstTensor(flatBufferInputParams->outputLayerNormWeights());
3572 IConnectableLayer* layer = m_Network->AddQLstmLayer(qLstmDescriptor, qLstmInputParams, layerName.c_str());
3583 RegisterInputSlots(graph, layerIndex, layer);
3584 RegisterOutputSlots(graph, layerIndex, layer);
3587 void IDeserializer::DeserializerImpl::ParseQuantizedLstm(
GraphPtr graph,
unsigned int layerIndex)
3591 auto inputs = GetInputs(graph, layerIndex);
3594 auto outputs = GetOutputs(graph, layerIndex);
3597 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_QuantizedLstmLayer();
3598 auto layerName = GetLayerName(graph, layerIndex);
3599 auto flatBufferInputParams = flatBufferLayer->inputParams();
3629 IConnectableLayer* layer = m_Network->AddQuantizedLstmLayer(lstmInputParams, layerName.c_str());
3637 RegisterInputSlots(graph, layerIndex, layer);
3638 RegisterOutputSlots(graph, layerIndex, layer);
3641 void IDeserializer::DeserializerImpl::ParseDequantize(
GraphPtr graph,
unsigned int layerIndex)
3651 const std::string layerName = GetLayerName(graph, layerIndex);
3657 RegisterInputSlots(graph, layerIndex, layer);
3658 RegisterOutputSlots(graph, layerIndex, layer);
3661 void IDeserializer::DeserializerImpl::ParseMerge(
GraphPtr graph,
unsigned int layerIndex)
3671 const std::string layerName = GetLayerName(graph, layerIndex);
3677 RegisterInputSlots(graph, layerIndex, layer);
3678 RegisterOutputSlots(graph, layerIndex, layer);
3681 void IDeserializer::DeserializerImpl::ParseSwitch(
GraphPtr graph,
unsigned int layerIndex)
3684 auto inputs = GetInputs(graph, layerIndex);
3688 auto outputs = GetOutputs(graph, layerIndex);
3691 auto layerName = GetLayerName(graph, layerIndex);
3700 RegisterInputSlots(graph, layerIndex, layer);
3701 RegisterOutputSlots(graph, layerIndex, layer);
3704 void IDeserializer::DeserializerImpl::ParseTile(
GraphPtr graph,
unsigned int layerIndex)
3707 auto inputs = GetInputs(graph, layerIndex);
3711 auto outputs = GetOutputs(graph, layerIndex);
3714 auto TileLayer = graph->layers()->Get(layerIndex)->layer_as_TileLayer();
3715 auto layerName = GetLayerName(graph, layerIndex);
3716 auto flatBufferDescriptor =
TileLayer->descriptor();
3717 auto flatBufferMultiples = flatBufferDescriptor->m_Multiples();
3720 tileDescriptor.
m_Multiples = std::vector<unsigned int>(flatBufferMultiples->begin(), flatBufferMultiples->end());
3722 IConnectableLayer* layer = m_Network->AddTileLayer(tileDescriptor, layerName.c_str());
3727 RegisterInputSlots(graph, layerIndex, layer);
3728 RegisterOutputSlots(graph, layerIndex, layer);
3731 void IDeserializer::DeserializerImpl::ParsePrelu(
GraphPtr graph,
unsigned int layerIndex)
3734 auto inputs = GetInputs(graph, layerIndex);
3738 auto outputs = GetOutputs(graph, layerIndex);
3741 auto layerName = GetLayerName(graph, layerIndex);
3747 RegisterInputSlots(graph, layerIndex, layer);
3748 RegisterOutputSlots(graph, layerIndex, layer);
3751 void IDeserializer::DeserializerImpl::ParseTranspose(
GraphPtr graph,
unsigned int layerIndex)
3755 auto dimsMapping = graph->layers()->Get(layerIndex)->layer_as_TransposeLayer()->descriptor()->dimMappings();
3757 auto inputs = GetInputs(graph, layerIndex);
3760 auto outputs = GetOutputs(graph, layerIndex);
3764 auto layerName = GetLayerName(graph, layerIndex);
3767 IConnectableLayer* layer = m_Network->AddTransposeLayer(descriptor, layerName.c_str());
3770 RegisterInputSlots(graph, layerIndex, layer);
3771 RegisterOutputSlots(graph, layerIndex, layer);
3774 void IDeserializer::DeserializerImpl::ParseTransposeConvolution2d(
GraphPtr graph,
unsigned int layerIndex)
3778 auto inputs = GetInputs(graph, layerIndex);
3781 auto outputs = GetOutputs(graph, layerIndex);
3784 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_TransposeConvolution2dLayer();
3785 auto layerName = GetLayerName(graph, layerIndex);
3786 auto serializerDescriptor = serializerLayer->descriptor();
3789 descriptor.
m_PadLeft = serializerDescriptor->padLeft();
3790 descriptor.
m_PadRight = serializerDescriptor->padRight();
3791 descriptor.
m_PadTop = serializerDescriptor->padTop();
3792 descriptor.
m_PadBottom = serializerDescriptor->padBottom();
3793 descriptor.
m_StrideX = serializerDescriptor->strideX();
3794 descriptor.
m_StrideY = serializerDescriptor->strideY();;
3795 descriptor.
m_BiasEnabled = serializerDescriptor->biasEnabled();;
3804 optionalBiases = armnn::MakeOptional<armnn::ConstTensor>(biases);
3807 IConnectableLayer* layer = m_Network->AddTransposeConvolution2dLayer(descriptor,
3815 RegisterInputSlots(graph, layerIndex, layer);
3816 RegisterOutputSlots(graph, layerIndex, layer);
3819 void IDeserializer::DeserializerImpl::ParseStack(
GraphPtr graph,
unsigned int layerIndex)
3822 auto inputs = GetInputs(graph, layerIndex);
3824 auto outputs = GetOutputs(graph, layerIndex);
3827 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_StackLayer()->descriptor();
3828 unsigned int axis = flatBufferDescriptor->axis();
3829 unsigned int numInputs = flatBufferDescriptor->numInputs();
3832 auto flatBufferInputShape = flatBufferDescriptor->inputShape();
3833 std::vector<uint32_t> vectorInputShape(flatBufferInputShape->begin(),
3834 flatBufferInputShape->begin() + flatBufferInputShape->size());
3836 TensorShape inputShape(
static_cast<unsigned int>(vectorInputShape.size()), vectorInputShape.data());
3839 for (
unsigned int i=0; i<inputs.size(); ++i)
3842 if (descriptor.m_InputShape != inputShape)
3844 std::stringstream ss;
3845 ss <<
"Shape of input "
3849 <<
" does not equal defined input shape "
3850 << descriptor.m_InputShape
3857 auto layerName = GetLayerName(graph, layerIndex);
3858 IConnectableLayer* layer = m_Network->AddStackLayer(descriptor, layerName.c_str());
3863 RegisterInputSlots(graph, layerIndex, layer);
3864 RegisterOutputSlots(graph, layerIndex, layer);
3867 void IDeserializer::DeserializerImpl::ParseStandIn(
GraphPtr graph,
unsigned int layerIndex)
3871 auto inputs = GetInputs(graph, layerIndex);
3872 auto outputs = GetOutputs(graph, layerIndex);
3874 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_StandInLayer();
3875 auto fbDescriptor = fbLayer->descriptor();
3878 descriptor.
m_NumInputs = fbDescriptor->numInputs();
3884 const std::string layerName = GetLayerName(graph, layerIndex);
3887 for (
unsigned int i = 0u; i < descriptor.
m_NumOutputs; ++i)
3893 RegisterInputSlots(graph, layerIndex, layer);
3894 RegisterOutputSlots(graph, layerIndex, layer);
3914 void IDeserializer::DeserializerImpl::ParseUnidirectionalSequenceLstm(
GraphPtr graph,
unsigned int layerIndex)
3918 auto inputs = GetInputs(graph, layerIndex);
3921 auto outputs = GetOutputs(graph, layerIndex);
3924 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_UnidirectionalSequenceLstmLayer();
3925 auto layerName = GetLayerName(graph, layerIndex);
3926 auto flatBufferDescriptor = flatBufferLayer->descriptor();
3927 auto flatBufferInputParams = flatBufferLayer->inputParams();
3929 auto descriptor = GetUnidirectionalSequenceLstmDescriptor(flatBufferDescriptor);
3957 if (!descriptor.m_CifgEnabled)
3959 inputToInputWeights =
ToConstTensor(flatBufferInputParams->inputToInputWeights());
3960 recurrentToInputWeights =
ToConstTensor(flatBufferInputParams->recurrentToInputWeights());
3961 inputGateBias =
ToConstTensor(flatBufferInputParams->inputGateBias());
3967 if (descriptor.m_PeepholeEnabled)
3969 cellToInputWeights =
ToConstTensor(flatBufferInputParams->cellToInputWeights());
3976 if (descriptor.m_ProjectionEnabled)
3978 projectionWeights =
ToConstTensor(flatBufferInputParams->projectionWeights());
3979 projectionBias =
ToConstTensor(flatBufferInputParams->projectionBias());
3987 if (descriptor.m_PeepholeEnabled)
3989 cellToForgetWeights =
ToConstTensor(flatBufferInputParams->cellToForgetWeights());
3990 cellToOutputWeights =
ToConstTensor(flatBufferInputParams->cellToOutputWeights());
4000 if (descriptor.m_LayerNormEnabled)
4002 if (!descriptor.m_CifgEnabled)
4004 inputLayerNormWeights =
ToConstTensor(flatBufferInputParams->inputLayerNormWeights());
4007 forgetLayerNormWeights =
ToConstTensor(flatBufferInputParams->forgetLayerNormWeights());
4008 cellLayerNormWeights =
ToConstTensor(flatBufferInputParams->cellLayerNormWeights());
4009 outputLayerNormWeights =
ToConstTensor(flatBufferInputParams->outputLayerNormWeights());
4016 IConnectableLayer* layer = m_Network->AddUnidirectionalSequenceLstmLayer(descriptor,
4029 RegisterInputSlots(graph, layerIndex, layer);
4030 RegisterOutputSlots(graph, layerIndex, layer);
4033 void IDeserializer::DeserializerImpl::ParseScatterNd(
GraphPtr graph,
unsigned int layerIndex)
4036 auto inputs = GetInputs(graph, layerIndex);
4040 auto outputs = GetOutputs(graph, layerIndex);
4043 auto ScatterNdLayer = graph->layers()->Get(layerIndex)->layer_as_ScatterNdLayer();
4044 auto layerName = GetLayerName(graph, layerIndex);
4049 scatterNdDescriptor.
m_InputEnabled = flatBufferDescriptor->m_InputEnabled();
4050 scatterNdDescriptor.
m_Axis = flatBufferDescriptor->m_Axis();
4051 scatterNdDescriptor.
m_AxisEnabled = flatBufferDescriptor->m_AxisEnabled();
4053 IConnectableLayer* layer = m_Network->AddScatterNdLayer(scatterNdDescriptor, layerName.c_str());
4058 RegisterInputSlots(graph, layerIndex, layer);
4059 RegisterOutputSlots(graph, layerIndex, layer);