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}",
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_BatchToSpaceNdLayer] = &DeserializerImpl::ParseBatchToSpaceNd;
218 m_ParserFunctions[Layer_BatchNormalizationLayer] = &DeserializerImpl::ParseBatchNormalization;
219 m_ParserFunctions[Layer_CastLayer] = &DeserializerImpl::ParseCast;
220 m_ParserFunctions[Layer_ChannelShuffleLayer] = &DeserializerImpl::ParseChannelShuffle;
221 m_ParserFunctions[Layer_ComparisonLayer] = &DeserializerImpl::ParseComparison;
222 m_ParserFunctions[Layer_ConcatLayer] = &DeserializerImpl::ParseConcat;
223 m_ParserFunctions[Layer_ConstantLayer] = &DeserializerImpl::ParseConstant;
224 m_ParserFunctions[Layer_Convolution2dLayer] = &DeserializerImpl::ParseConvolution2d;
225 m_ParserFunctions[Layer_Convolution3dLayer] = &DeserializerImpl::ParseConvolution3d;
226 m_ParserFunctions[Layer_DepthToSpaceLayer] = &DeserializerImpl::ParseDepthToSpace;
227 m_ParserFunctions[Layer_DepthwiseConvolution2dLayer] = &DeserializerImpl::ParseDepthwiseConvolution2d;
228 m_ParserFunctions[Layer_DequantizeLayer] = &DeserializerImpl::ParseDequantize;
229 m_ParserFunctions[Layer_DetectionPostProcessLayer] = &DeserializerImpl::ParseDetectionPostProcess;
230 m_ParserFunctions[Layer_DivisionLayer] = &DeserializerImpl::ParseDivision;
231 m_ParserFunctions[Layer_ElementwiseUnaryLayer] = &DeserializerImpl::ParseElementwiseUnary;
232 m_ParserFunctions[Layer_EqualLayer] = &DeserializerImpl::ParseEqual;
233 m_ParserFunctions[Layer_FullyConnectedLayer] = &DeserializerImpl::ParseFullyConnected;
234 m_ParserFunctions[Layer_FillLayer] = &DeserializerImpl::ParseFill;
235 m_ParserFunctions[Layer_FloorLayer] = &DeserializerImpl::ParseFloor;
236 m_ParserFunctions[Layer_GatherLayer] = &DeserializerImpl::ParseGather;
237 m_ParserFunctions[Layer_GatherNdLayer] = &DeserializerImpl::ParseGatherNd;
238 m_ParserFunctions[Layer_GreaterLayer] = &DeserializerImpl::ParseGreater;
239 m_ParserFunctions[Layer_InstanceNormalizationLayer] = &DeserializerImpl::ParseInstanceNormalization;
240 m_ParserFunctions[Layer_L2NormalizationLayer] = &DeserializerImpl::ParseL2Normalization;
241 m_ParserFunctions[Layer_LogicalBinaryLayer] = &DeserializerImpl::ParseLogicalBinary;
242 m_ParserFunctions[Layer_LogSoftmaxLayer] = &DeserializerImpl::ParseLogSoftmax;
243 m_ParserFunctions[Layer_LstmLayer] = &DeserializerImpl::ParseLstm;
244 m_ParserFunctions[Layer_MaximumLayer] = &DeserializerImpl::ParseMaximum;
245 m_ParserFunctions[Layer_MeanLayer] = &DeserializerImpl::ParseMean;
246 m_ParserFunctions[Layer_MinimumLayer] = &DeserializerImpl::ParseMinimum;
247 m_ParserFunctions[Layer_MergeLayer] = &DeserializerImpl::ParseMerge;
248 m_ParserFunctions[Layer_MergerLayer] = &DeserializerImpl::ParseConcat;
249 m_ParserFunctions[Layer_MultiplicationLayer] = &DeserializerImpl::ParseMultiplication;
250 m_ParserFunctions[Layer_NormalizationLayer] = &DeserializerImpl::ParseNormalization;
251 m_ParserFunctions[Layer_PadLayer] = &DeserializerImpl::ParsePad;
252 m_ParserFunctions[Layer_PermuteLayer] = &DeserializerImpl::ParsePermute;
253 m_ParserFunctions[Layer_Pooling2dLayer] = &DeserializerImpl::ParsePooling2d;
254 m_ParserFunctions[Layer_Pooling3dLayer] = &DeserializerImpl::ParsePooling3d;
255 m_ParserFunctions[Layer_PreluLayer] = &DeserializerImpl::ParsePrelu;
256 m_ParserFunctions[Layer_QLstmLayer] = &DeserializerImpl::ParseQLstm;
257 m_ParserFunctions[Layer_QuantizeLayer] = &DeserializerImpl::ParseQuantize;
258 m_ParserFunctions[Layer_QuantizedLstmLayer] = &DeserializerImpl::ParseQuantizedLstm;
259 m_ParserFunctions[Layer_RankLayer] = &DeserializerImpl::ParseRank;
260 m_ParserFunctions[Layer_ReduceLayer] = &DeserializerImpl::ParseReduce;
261 m_ParserFunctions[Layer_ReshapeLayer] = &DeserializerImpl::ParseReshape;
262 m_ParserFunctions[Layer_ResizeBilinearLayer] = &DeserializerImpl::ParseResizeBilinear;
263 m_ParserFunctions[Layer_ResizeLayer] = &DeserializerImpl::ParseResize;
264 m_ParserFunctions[Layer_RsqrtLayer] = &DeserializerImpl::ParseRsqrt;
265 m_ParserFunctions[Layer_ShapeLayer] = &DeserializerImpl::ParseShape;
266 m_ParserFunctions[Layer_SliceLayer] = &DeserializerImpl::ParseSlice;
267 m_ParserFunctions[Layer_SoftmaxLayer] = &DeserializerImpl::ParseSoftmax;
268 m_ParserFunctions[Layer_SpaceToBatchNdLayer] = &DeserializerImpl::ParseSpaceToBatchNd;
269 m_ParserFunctions[Layer_SpaceToDepthLayer] = &DeserializerImpl::ParseSpaceToDepth;
270 m_ParserFunctions[Layer_SplitterLayer] = &DeserializerImpl::ParseSplitter;
271 m_ParserFunctions[Layer_StackLayer] = &DeserializerImpl::ParseStack;
272 m_ParserFunctions[Layer_StandInLayer] = &DeserializerImpl::ParseStandIn;
273 m_ParserFunctions[Layer_StridedSliceLayer] = &DeserializerImpl::ParseStridedSlice;
274 m_ParserFunctions[Layer_SubtractionLayer] = &DeserializerImpl::ParseSubtraction;
275 m_ParserFunctions[Layer_SwitchLayer] = &DeserializerImpl::ParseSwitch;
276 m_ParserFunctions[Layer_TransposeConvolution2dLayer] = &DeserializerImpl::ParseTransposeConvolution2d;
277 m_ParserFunctions[Layer_TransposeLayer] = &DeserializerImpl::ParseTranspose;
278 m_ParserFunctions[Layer_UnidirectionalSequenceLstmLayer] = &DeserializerImpl::ParseUnidirectionalSequenceLstm;
283 auto layerType = graphPtr->layers()->Get(layerIndex)->layer_type();
287 case Layer::Layer_AbsLayer:
288 return graphPtr->layers()->Get(layerIndex)->layer_as_AbsLayer()->base();
289 case Layer::Layer_ActivationLayer:
290 return graphPtr->layers()->Get(layerIndex)->layer_as_ActivationLayer()->base();
291 case Layer::Layer_AdditionLayer:
292 return graphPtr->layers()->Get(layerIndex)->layer_as_AdditionLayer()->base();
293 case Layer::Layer_ArgMinMaxLayer:
294 return graphPtr->layers()->Get(layerIndex)->layer_as_ArgMinMaxLayer()->base();
295 case Layer::Layer_BatchToSpaceNdLayer:
296 return graphPtr->layers()->Get(layerIndex)->layer_as_BatchToSpaceNdLayer()->base();
297 case Layer::Layer_BatchNormalizationLayer:
298 return graphPtr->layers()->Get(layerIndex)->layer_as_BatchNormalizationLayer()->base();
299 case Layer::Layer_CastLayer:
300 return graphPtr->layers()->Get(layerIndex)->layer_as_CastLayer()->base();
301 case Layer::Layer_ChannelShuffleLayer:
302 return graphPtr->layers()->Get(layerIndex)->layer_as_ChannelShuffleLayer()->base();
303 case Layer::Layer_ComparisonLayer:
304 return graphPtr->layers()->Get(layerIndex)->layer_as_ComparisonLayer()->base();
305 case Layer::Layer_ConcatLayer:
306 return graphPtr->layers()->Get(layerIndex)->layer_as_ConcatLayer()->base();
307 case Layer::Layer_ConstantLayer:
308 return graphPtr->layers()->Get(layerIndex)->layer_as_ConstantLayer()->base();
309 case Layer::Layer_Convolution2dLayer:
310 return graphPtr->layers()->Get(layerIndex)->layer_as_Convolution2dLayer()->base();
311 case Layer::Layer_Convolution3dLayer:
312 return graphPtr->layers()->Get(layerIndex)->layer_as_Convolution3dLayer()->base();
313 case Layer::Layer_DepthToSpaceLayer:
314 return graphPtr->layers()->Get(layerIndex)->layer_as_DepthToSpaceLayer()->base();
315 case Layer::Layer_DepthwiseConvolution2dLayer:
316 return graphPtr->layers()->Get(layerIndex)->layer_as_DepthwiseConvolution2dLayer()->base();
317 case Layer::Layer_DequantizeLayer:
318 return graphPtr->layers()->Get(layerIndex)->layer_as_DequantizeLayer()->base();
319 case Layer::Layer_DetectionPostProcessLayer:
320 return graphPtr->layers()->Get(layerIndex)->layer_as_DetectionPostProcessLayer()->base();
321 case Layer::Layer_DivisionLayer:
322 return graphPtr->layers()->Get(layerIndex)->layer_as_DivisionLayer()->base();
323 case Layer::Layer_EqualLayer:
324 return graphPtr->layers()->Get(layerIndex)->layer_as_EqualLayer()->base();
325 case Layer::Layer_ElementwiseUnaryLayer:
326 return graphPtr->layers()->Get(layerIndex)->layer_as_ElementwiseUnaryLayer()->base();
327 case Layer::Layer_FullyConnectedLayer:
328 return graphPtr->layers()->Get(layerIndex)->layer_as_FullyConnectedLayer()->base();
329 case Layer::Layer_FillLayer:
330 return graphPtr->layers()->Get(layerIndex)->layer_as_FillLayer()->base();
331 case Layer::Layer_FloorLayer:
332 return graphPtr->layers()->Get(layerIndex)->layer_as_FloorLayer()->base();
333 case Layer::Layer_GatherLayer:
334 return graphPtr->layers()->Get(layerIndex)->layer_as_GatherLayer()->base();
335 case Layer::Layer_GatherNdLayer:
336 return graphPtr->layers()->Get(layerIndex)->layer_as_GatherNdLayer()->base();
337 case Layer::Layer_GreaterLayer:
338 return graphPtr->layers()->Get(layerIndex)->layer_as_GreaterLayer()->base();
339 case Layer::Layer_InputLayer:
340 return graphPtr->layers()->Get(layerIndex)->layer_as_InputLayer()->base()->base();
341 case Layer::Layer_InstanceNormalizationLayer:
342 return graphPtr->layers()->Get(layerIndex)->layer_as_InstanceNormalizationLayer()->base();
343 case Layer::Layer_L2NormalizationLayer:
344 return graphPtr->layers()->Get(layerIndex)->layer_as_L2NormalizationLayer()->base();
345 case Layer::Layer_LogicalBinaryLayer:
346 return graphPtr->layers()->Get(layerIndex)->layer_as_LogicalBinaryLayer()->base();
347 case Layer::Layer_LogSoftmaxLayer:
348 return graphPtr->layers()->Get(layerIndex)->layer_as_LogSoftmaxLayer()->base();
349 case Layer::Layer_LstmLayer:
350 return graphPtr->layers()->Get(layerIndex)->layer_as_LstmLayer()->base();
351 case Layer::Layer_MeanLayer:
352 return graphPtr->layers()->Get(layerIndex)->layer_as_MeanLayer()->base();
353 case Layer::Layer_MinimumLayer:
354 return graphPtr->layers()->Get(layerIndex)->layer_as_MinimumLayer()->base();
355 case Layer::Layer_MaximumLayer:
356 return graphPtr->layers()->Get(layerIndex)->layer_as_MaximumLayer()->base();
357 case Layer::Layer_MergeLayer:
358 return graphPtr->layers()->Get(layerIndex)->layer_as_MergeLayer()->base();
359 case Layer::Layer_MergerLayer:
360 return graphPtr->layers()->Get(layerIndex)->layer_as_MergerLayer()->base();
361 case Layer::Layer_MultiplicationLayer:
362 return graphPtr->layers()->Get(layerIndex)->layer_as_MultiplicationLayer()->base();
363 case Layer::Layer_NormalizationLayer:
364 return graphPtr->layers()->Get(layerIndex)->layer_as_NormalizationLayer()->base();
365 case Layer::Layer_OutputLayer:
366 return graphPtr->layers()->Get(layerIndex)->layer_as_OutputLayer()->base()->base();
367 case Layer::Layer_PadLayer:
368 return graphPtr->layers()->Get(layerIndex)->layer_as_PadLayer()->base();
369 case Layer::Layer_PermuteLayer:
370 return graphPtr->layers()->Get(layerIndex)->layer_as_PermuteLayer()->base();
371 case Layer::Layer_Pooling2dLayer:
372 return graphPtr->layers()->Get(layerIndex)->layer_as_Pooling2dLayer()->base();
373 case Layer::Layer_Pooling3dLayer:
374 return graphPtr->layers()->Get(layerIndex)->layer_as_Pooling3dLayer()->base();
375 case Layer::Layer_PreluLayer:
376 return graphPtr->layers()->Get(layerIndex)->layer_as_PreluLayer()->base();
377 case Layer::Layer_QLstmLayer:
378 return graphPtr->layers()->Get(layerIndex)->layer_as_QLstmLayer()->base();
379 case Layer::Layer_QuantizeLayer:
380 return graphPtr->layers()->Get(layerIndex)->layer_as_QuantizeLayer()->base();
381 case Layer::Layer_QuantizedLstmLayer:
382 return graphPtr->layers()->Get(layerIndex)->layer_as_QuantizedLstmLayer()->base();
383 case Layer::Layer_RankLayer:
384 return graphPtr->layers()->Get(layerIndex)->layer_as_RankLayer()->base();
385 case Layer::Layer_ReduceLayer:
386 return graphPtr->layers()->Get(layerIndex)->layer_as_ReduceLayer()->base();
387 case Layer::Layer_ReshapeLayer:
388 return graphPtr->layers()->Get(layerIndex)->layer_as_ReshapeLayer()->base();
389 case Layer::Layer_ResizeBilinearLayer:
390 return graphPtr->layers()->Get(layerIndex)->layer_as_ResizeBilinearLayer()->base();
391 case Layer::Layer_ResizeLayer:
392 return graphPtr->layers()->Get(layerIndex)->layer_as_ResizeLayer()->base();
393 case Layer::Layer_RsqrtLayer:
394 return graphPtr->layers()->Get(layerIndex)->layer_as_RsqrtLayer()->base();
395 case Layer::Layer_ShapeLayer:
396 return graphPtr->layers()->Get(layerIndex)->layer_as_ShapeLayer()->base();
397 case Layer::Layer_SliceLayer:
398 return graphPtr->layers()->Get(layerIndex)->layer_as_SliceLayer()->base();
399 case Layer::Layer_SoftmaxLayer:
400 return graphPtr->layers()->Get(layerIndex)->layer_as_SoftmaxLayer()->base();
401 case Layer::Layer_SpaceToBatchNdLayer:
402 return graphPtr->layers()->Get(layerIndex)->layer_as_SpaceToBatchNdLayer()->base();
403 case Layer::Layer_SpaceToDepthLayer:
404 return graphPtr->layers()->Get(layerIndex)->layer_as_SpaceToDepthLayer()->base();
405 case Layer::Layer_SplitterLayer:
406 return graphPtr->layers()->Get(layerIndex)->layer_as_SplitterLayer()->base();
407 case Layer::Layer_StackLayer:
408 return graphPtr->layers()->Get(layerIndex)->layer_as_StackLayer()->base();
409 case Layer::Layer_StandInLayer:
410 return graphPtr->layers()->Get(layerIndex)->layer_as_StandInLayer()->base();
411 case Layer::Layer_StridedSliceLayer:
412 return graphPtr->layers()->Get(layerIndex)->layer_as_StridedSliceLayer()->base();
413 case Layer::Layer_SubtractionLayer:
414 return graphPtr->layers()->Get(layerIndex)->layer_as_SubtractionLayer()->base();
415 case Layer::Layer_SwitchLayer:
416 return graphPtr->layers()->Get(layerIndex)->layer_as_SwitchLayer()->base();
417 case Layer::Layer_TransposeConvolution2dLayer:
418 return graphPtr->layers()->Get(layerIndex)->layer_as_TransposeConvolution2dLayer()->base();
419 case Layer::Layer_TransposeLayer:
420 return graphPtr->layers()->Get(layerIndex)->layer_as_TransposeLayer()->base();
421 case Layer::Layer_UnidirectionalSequenceLstmLayer:
422 return graphPtr->layers()->Get(layerIndex)->layer_as_UnidirectionalSequenceLstmLayer()->base();
423 case Layer::Layer_NONE:
425 throw ParseException(fmt::format(
"Layer type {} not recognized", layerType));
433 return layer->layerName()->str();
438 auto layerType = graphPtr->layers()->Get(layerIndex)->layer_type();
440 if (layerType == Layer::Layer_InputLayer)
442 return graphPtr->layers()->Get(layerIndex)->layer_as_InputLayer()->base()->layerBindingId();
444 else if ( layerType == Layer::Layer_OutputLayer )
446 return graphPtr->layers()->Get(layerIndex)->layer_as_OutputLayer()->base()->layerBindingId();
455 case armnnSerializer::DataLayout::DataLayout_NHWC:
457 case armnnSerializer::DataLayout::DataLayout_NDHWC:
459 case armnnSerializer::DataLayout::DataLayout_NCDHW:
461 case armnnSerializer::DataLayout::DataLayout_NCHW:
471 case armnnSerializer::ActivationFunction_Sigmoid:
473 case armnnSerializer::ActivationFunction_TanH:
475 case armnnSerializer::ActivationFunction_Linear:
477 case armnnSerializer::ActivationFunction_ReLu:
479 case armnnSerializer::ActivationFunction_BoundedReLu:
481 case armnnSerializer::ActivationFunction_LeakyReLu:
483 case armnnSerializer::ActivationFunction_Abs:
485 case armnnSerializer::ActivationFunction_Sqrt:
487 case armnnSerializer::ActivationFunction_Square:
489 case armnnSerializer::ActivationFunction_Elu:
491 case armnnSerializer::ActivationFunction_HardSwish:
502 case armnnSerializer::ArgMinMaxFunction::ArgMinMaxFunction_Max:
504 case armnnSerializer::ArgMinMaxFunction::ArgMinMaxFunction_Min:
514 case armnnSerializer::ComparisonOperation::ComparisonOperation_Equal:
516 case armnnSerializer::ComparisonOperation::ComparisonOperation_Greater:
518 case armnnSerializer::ComparisonOperation::ComparisonOperation_GreaterOrEqual:
520 case armnnSerializer::ComparisonOperation::ComparisonOperation_Less:
522 case armnnSerializer::ComparisonOperation::ComparisonOperation_LessOrEqual:
524 case armnnSerializer::ComparisonOperation::ComparisonOperation_NotEqual:
534 case armnnSerializer::ReduceOperation::ReduceOperation_Sum:
536 case armnnSerializer::ReduceOperation::ReduceOperation_Max:
538 case armnnSerializer::ReduceOperation::ReduceOperation_Mean:
540 case armnnSerializer::ReduceOperation::ReduceOperation_Min:
542 case armnnSerializer::ReduceOperation::ReduceOperation_Prod:
553 case armnnSerializer::LogicalBinaryOperation::LogicalBinaryOperation_LogicalAnd:
555 case armnnSerializer::LogicalBinaryOperation::LogicalBinaryOperation_LogicalOr:
566 case armnnSerializer::UnaryOperation::UnaryOperation_Abs:
568 case armnnSerializer::UnaryOperation::UnaryOperation_Rsqrt:
570 case armnnSerializer::UnaryOperation::UnaryOperation_Sqrt:
572 case armnnSerializer::UnaryOperation::UnaryOperation_Exp:
574 case armnnSerializer::UnaryOperation::UnaryOperation_Neg:
576 case armnnSerializer::UnaryOperation::UnaryOperation_LogicalNot:
578 case armnnSerializer::UnaryOperation::UnaryOperation_Log:
580 case armnnSerializer::UnaryOperation::UnaryOperation_Sin:
591 case armnnSerializer::PaddingMode::PaddingMode_Reflect:
593 case armnnSerializer::PaddingMode::PaddingMode_Symmetric:
604 case armnnSerializer::ResizeMethod_NearestNeighbor:
606 case armnnSerializer::ResizeMethod_Bilinear:
618 switch (tensorPtr->dataType())
620 case DataType_QAsymmS8:
623 case DataType_QSymmS8:
626 case DataType_QuantisedAsymm8:
627 case DataType_QAsymmU8:
630 case DataType_QSymmS16:
631 case DataType_QuantisedSymm16:
634 case DataType_Signed32:
637 case DataType_Signed64:
640 case DataType_Float32:
643 case DataType_Float16:
646 case DataType_Boolean:
652 throw ParseException(fmt::format(
"Unsupported data type {0} = {1}. {2}",
653 tensorPtr->dataType(),
654 EnumNameDataType(tensorPtr->dataType()),
659 float quantizationScale = tensorPtr->quantizationScale();
660 int32_t quantizationOffset = tensorPtr->quantizationOffset();
662 if (tensorPtr->dimensionality() ==
static_cast<unsigned int>(Dimensionality::Scalar))
669 else if (tensorPtr->dimensionality() ==
static_cast<unsigned int>(Dimensionality::NotSpecified))
678 auto dimensions = tensorPtr->dimensions();
679 unsigned int size = dimensions->size();
680 std::vector<unsigned int> outputDims(dimensions->begin(), dimensions->begin() + size);
685 if (tensorPtr->dimensionSpecificity() !=
nullptr)
687 auto dimensionSpecificity = tensorPtr->dimensionSpecificity();
688 size = dimensionSpecificity->size();
689 for (
unsigned int i = 0; i < size; ++i)
691 dimensionsSpecificity[i] = dimensionSpecificity->Get(i);
695 TensorShape shape(size, outputDims.data(), dimensionsSpecificity);
697 auto quantizationScales = tensorPtr->quantizationScales();
698 if (quantizationScales)
700 unsigned int quantizationScalesSize = quantizationScales->size();
701 std::vector<float> scales(quantizationScales->begin(), quantizationScales->begin() + quantizationScalesSize);
702 unsigned int quantizationDim = tensorPtr->quantizationDim();
725 switch (constTensorPtr->data_type())
727 case ConstTensorData_ByteData:
729 auto byteData = constTensorPtr->data_as_ByteData()->data();
733 case ConstTensorData_ShortData:
735 auto shortData = constTensorPtr->data_as_ShortData()->data();
739 case ConstTensorData_IntData:
741 auto intData = constTensorPtr->data_as_IntData()->data();
745 case ConstTensorData_LongData:
747 auto longData = constTensorPtr->data_as_LongData()->data();
754 throw ParseException(fmt::format(
"Unsupported data type {0} = {1}. {2}",
755 constTensorPtr->data_type(),
756 EnumNameConstTensorData(constTensorPtr->data_type()),
766 const auto& numInputs = layer->inputSlots()->size();
770 for (
unsigned int i=0; i<numInputs; ++i)
773 (layer->inputSlots()->Get(i)->connection()->sourceLayerIndex()));
774 result[i] =
GetBaseLayer(graphPtr, inputId)->outputSlots()->Get(0)->tensorInfo();
783 const auto& numOutputs = layer->outputSlots()->size();
787 for (
unsigned int i=0; i<numOutputs; ++i)
789 result[i] = layer->outputSlots()->Get(i)->tensorInfo();
794 void IDeserializer::DeserializerImpl::ParseUnsupportedLayer(
GraphPtr graph,
unsigned int layerIndex)
797 const auto layerName =
GetBaseLayer(graph, layerIndex)->layerName()->c_str();
798 throw ParseException(fmt::format(
"Layer not supported. layerIndex: {0} " 799 "layerName: {1} / {2}",
805 void IDeserializer::DeserializerImpl::ResetParser()
808 m_InputBindings.clear();
809 m_OutputBindings.clear();
817 return CreateNetworkFromGraph(graph);
823 if (binaryContent.fail()) {
827 binaryContent.seekg(0, std::ios::end);
828 const std::streamoff size = binaryContent.tellg();
829 std::vector<char> content(static_cast<size_t>(size));
830 binaryContent.seekg(0);
831 binaryContent.read(content.data(),
static_cast<std::streamsize
>(size));
833 return CreateNetworkFromGraph(graph);
838 if (binaryContent ==
nullptr)
843 flatbuffers::Verifier verifier(binaryContent, len);
844 if (verifier.VerifyBuffer<SerializedGraph>() ==
false)
846 throw ParseException(fmt::format(
"Buffer doesn't conform to the expected Armnn " 847 "flatbuffers format. size:{0} {1}",
851 return GetSerializedGraph(binaryContent);
856 m_Network = INetwork::Create();
858 unsigned int layerIndex = 0;
859 for (AnyLayer
const* layer : *graph->layers())
861 if (layer->layer_type() != Layer_InputLayer &&
862 layer->layer_type() != Layer_OutputLayer)
865 auto& parserFunction = m_ParserFunctions[layer->layer_type()];
866 (this->*parserFunction)(graph, layerIndex);
871 SetupInputLayers(graph);
872 SetupOutputLayers(graph);
875 for (
auto&& graphIt : m_GraphConnections)
877 Connections& connections = graphIt.second;
878 for (
auto&& outputIt : connections.outputSlots)
880 const unsigned int outputSlotIndex = outputIt.first;
882 if (connections.inputSlots.find(outputSlotIndex) != connections.inputSlots.end())
884 for (
IInputSlot* inputSlot : connections.inputSlots[outputSlotIndex])
886 outputSlot->
Connect(*inputSlot);
892 return std::move(m_Network);
896 const std::string& name)
const 899 for (
auto inputBinding : m_InputBindings)
901 if (inputBinding.first == name)
903 return inputBinding.second;
906 throw ParseException(fmt::format(
"No input binding found for layer:{0} / {1}",
912 const std::string& name)
const 915 for (
auto outputBinding : m_OutputBindings)
917 if (outputBinding.first == name)
919 return outputBinding.second;
922 throw ParseException(fmt::format(
"No output binding found for layer:{0} / {1}",
927 unsigned int IDeserializer::DeserializerImpl::GetInputLayerInVector(
GraphPtr graph,
int targetId)
929 for (
unsigned int i = 0; i < graph->layers()->size(); i++)
931 auto layer = graph->layers()->Get(i);
932 if (layer->layer_type() == Layer::Layer_InputLayer)
934 auto layerBindingId = layer->layer_as_InputLayer()->base()->layerBindingId();
935 if (layerBindingId == targetId)
941 throw ParseException(
"Input layer with given layerBindingId not found");
944 unsigned int IDeserializer::DeserializerImpl::GetOutputLayerInVector(
GraphPtr graph,
int targetId)
946 for (
unsigned int i = 0; i < graph->layers()->size(); i++)
948 auto layer = graph->layers()->Get(i);
949 if (layer->layer_type() == Layer::Layer_OutputLayer)
951 auto layerBindingId = layer->layer_as_OutputLayer()->base()->layerBindingId();
952 if (layerBindingId == targetId)
958 throw ParseException(
"Output layer with given layerBindingId not found");
961 unsigned int IDeserializer::DeserializerImpl::GetLayerIndexInVector(
GraphPtr graph,
unsigned int targetIndex)
963 for (
unsigned int i = 0; i < graph->layers()->size(); i++)
966 if (layer->index() == targetIndex)
974 IDeserializer::DeserializerImpl::FeatureVersions IDeserializer::DeserializerImpl::GetFeatureVersions(
GraphPtr graph)
976 IDeserializer::DeserializerImpl::FeatureVersions versions;
978 if (graph->featureVersions())
980 versions.m_BindingIdScheme = graph->featureVersions()->bindingIdsScheme();
981 versions.m_WeightsLayoutScheme = graph->featureVersions()->weightsLayoutScheme();
982 versions.m_ConstTensorsAsInputs = graph->featureVersions()->constantTensorsAsInputs();
988 void IDeserializer::DeserializerImpl::SetupInputLayers(
GraphPtr graph)
991 const unsigned int numInputs = graph->inputIds()->size();
992 m_InputBindings.clear();
993 m_InputBindings.reserve(numInputs);
995 for (
unsigned int i = 0; i < numInputs; i++)
997 unsigned int inputLayerIndex = 0xFFFFFFFF;
998 if (GetFeatureVersions(graph).m_BindingIdScheme == 0)
1000 const unsigned int inputId =
armnn::numeric_cast<
unsigned int>(graph->inputIds()->Get(i));
1001 inputLayerIndex = GetLayerIndexInVector(graph, inputId);
1005 const int inputId = graph->inputIds()->Get(i);
1006 inputLayerIndex = GetInputLayerInVector(graph, inputId);
1016 m_Network->AddInputLayer(bindingId, baseLayer->layerName()->c_str());
1019 inputLayer->GetOutputSlot(0).SetTensorInfo(tensorInfo);
1020 RegisterOutputSlots(graph, inputLayerIndex, inputLayer);
1023 m_InputBindings.push_back(std::make_pair(baseLayer->layerName()->c_str(), bindingInfo));
1027 void IDeserializer::DeserializerImpl::SetupOutputLayers(
GraphPtr graph)
1030 const unsigned int numOutputs = graph->outputIds()->size();
1031 m_OutputBindings.clear();
1032 m_OutputBindings.reserve(numOutputs);
1034 for (
unsigned int i = 0; i < numOutputs; i++)
1036 unsigned int outputLayerIndex = 0xFFFFFFFF;
1037 if (GetFeatureVersions(graph).m_BindingIdScheme == 0)
1039 const unsigned int outputId =
armnn::numeric_cast<
unsigned int>(graph->outputIds()->Get(i));
1040 outputLayerIndex = GetLayerIndexInVector(graph, outputId);
1044 const int outputId = graph->outputIds()->Get(i);
1045 outputLayerIndex = GetOutputLayerInVector(graph, outputId);
1055 m_Network->AddOutputLayer(bindingId, baseLayer->layerName()->c_str());
1057 RegisterInputSlots(graph, outputLayerIndex, outputLayer);
1058 unsigned int sourceLayerIndex =
1059 GetLayerIndexInVector(graph, baseLayer->inputSlots()->Get(0)->connection()->sourceLayerIndex());
1060 unsigned int outputSlotIndex =
1061 GetLayerIndexInVector(graph, baseLayer->inputSlots()->Get(0)->connection()->outputSlotIndex());
1064 sourceBaseLayer->outputSlots()->Get(outputSlotIndex)->tensorInfo());
1066 m_OutputBindings.push_back(std::make_pair(baseLayer->layerName()->c_str(), bindingInfo));
1070 void IDeserializer::DeserializerImpl::RegisterOutputSlots(
GraphPtr graph,
1071 uint32_t layerIndex,
1079 throw ParseException(fmt::format(
"The number of outputslots ({0}) does not match the number expected ({1})" 1080 " for layer index: {2} {3}",
1081 baseLayer->outputSlots()->size(),
1089 const unsigned int slotIndex = baseLayer->outputSlots()->Get(i)->index();
1092 RegisterOutputSlotOfConnection(baseLayer->index(), slotIndex, outputSlot);
1096 void IDeserializer::DeserializerImpl::RegisterInputSlots(
GraphPtr graph,
1097 uint32_t layerIndex,
1099 std::vector<unsigned int> ignoreSlots)
1105 if (baseLayer->inputSlots()->size() != (layer->
GetNumInputSlots() - ignoreSlots.size()))
1107 throw ParseException(fmt::format(
"The number of inputslots ({0}) does not match the number expected ({1})" 1108 " for layer index:{2} {3}",
1109 baseLayer->inputSlots()->size(),
1118 if (std::find(ignoreSlots.begin(), ignoreSlots.end(), i) == ignoreSlots.end())
1120 auto fbInputSlot = baseLayer->inputSlots()->Get(i);
1121 auto fbConnection = fbInputSlot->connection();
1123 RegisterInputSlotOfConnection(fbConnection->sourceLayerIndex(), fbConnection->outputSlotIndex(), inputSlot);
1128 void IDeserializer::DeserializerImpl::RegisterInputSlotOfConnection(uint32_t sourceLayerIndex,
1129 uint32_t outputSlotIndex,
1132 if (m_GraphConnections.find(sourceLayerIndex) == m_GraphConnections.end())
1134 m_GraphConnections[sourceLayerIndex] = Connections();
1137 Connections& connections = m_GraphConnections[sourceLayerIndex];
1138 if (connections.inputSlots.find(outputSlotIndex) == connections.inputSlots.end())
1140 connections.inputSlots[outputSlotIndex] = {inputSlot};
1144 connections.inputSlots[outputSlotIndex].push_back(inputSlot);
1148 void IDeserializer::DeserializerImpl::RegisterOutputSlotOfConnection(uint32_t sourceLayerIndex,
1149 uint32_t outputSlotIndex,
1152 if (m_GraphConnections.find(sourceLayerIndex) == m_GraphConnections.end())
1154 m_GraphConnections[sourceLayerIndex] = Connections();
1157 Connections& connections = m_GraphConnections[sourceLayerIndex];
1158 if (connections.outputSlots.find(outputSlotIndex) != connections.outputSlots.end())
1163 connections.outputSlots[outputSlotIndex] = outputSlot;
1166 void IDeserializer::DeserializerImpl::ParseAbs(
GraphPtr graph,
unsigned int layerIndex)
1169 auto inputs =
GetInputs(graph, layerIndex);
1173 auto outputs =
GetOutputs(graph, layerIndex);
1179 IConnectableLayer* layer = m_Network->AddElementwiseUnaryLayer(descriptor, layerName.c_str());
1183 RegisterInputSlots(graph, layerIndex, layer);
1184 RegisterOutputSlots(graph, layerIndex, layer);
1187 void IDeserializer::DeserializerImpl::ParseActivation(
GraphPtr graph,
unsigned int layerIndex)
1190 auto inputs =
GetInputs(graph, layerIndex);
1194 auto outputs =
GetOutputs(graph, layerIndex);
1197 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_ActivationLayer();
1199 auto serializerDescriptor = serializerLayer->descriptor();
1203 descriptor.
m_A = serializerDescriptor->a();
1204 descriptor.
m_B = serializerDescriptor->b();
1211 RegisterInputSlots(graph, layerIndex, layer);
1212 RegisterOutputSlots(graph, layerIndex, layer);
1215 void IDeserializer::DeserializerImpl::ParseAdd(
GraphPtr graph,
unsigned int layerIndex)
1218 auto inputs =
GetInputs(graph, layerIndex);
1222 auto outputs =
GetOutputs(graph, layerIndex);
1231 RegisterInputSlots(graph, layerIndex, layer);
1232 RegisterOutputSlots(graph, layerIndex, layer);
1235 void IDeserializer::DeserializerImpl::ParseArgMinMax(
GraphPtr graph,
unsigned int layerIndex)
1238 auto inputs =
GetInputs(graph, layerIndex);
1242 auto outputs =
GetOutputs(graph, layerIndex);
1245 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_ArgMinMaxLayer();
1246 auto serializerDescriptor = serializerLayer->descriptor();
1250 descriptor.
m_Axis = serializerDescriptor->axis();
1252 IConnectableLayer* layer = m_Network->AddArgMinMaxLayer(descriptor, layerName.c_str());
1257 RegisterInputSlots(graph, layerIndex, layer);
1258 RegisterOutputSlots(graph, layerIndex, layer);
1261 void IDeserializer::DeserializerImpl::ParseBatchToSpaceNd(
GraphPtr graph,
unsigned int layerIndex)
1271 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_BatchToSpaceNdLayer()->descriptor();
1272 auto flatBufferCrops = flatBufferDescriptor->crops();
1273 auto flatBufferBlockShape = flatBufferDescriptor->blockShape();
1275 if (flatBufferCrops->size() % 2 != 0)
1280 std::vector<std::pair<unsigned int, unsigned int>> crops;
1281 crops.reserve(flatBufferCrops->size() / 2);
1282 for (
unsigned int i = 0; i < flatBufferCrops->size() - 1; i += 2)
1284 crops.emplace_back(flatBufferCrops->Get(i), flatBufferCrops->Get(i+1));
1290 std::vector<unsigned int>(flatBufferBlockShape->begin(), flatBufferBlockShape->end());
1294 IConnectableLayer* layer = m_Network->AddBatchToSpaceNdLayer(descriptor, layerName.c_str());
1299 RegisterInputSlots(graph, layerIndex, layer);
1300 RegisterOutputSlots(graph, layerIndex, layer);
1303 void IDeserializer::DeserializerImpl::ParseBatchNormalization(
GraphPtr graph,
unsigned int layerIndex)
1307 auto inputs =
GetInputs(graph, layerIndex);
1310 auto outputs =
GetOutputs(graph, layerIndex);
1316 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_BatchNormalizationLayer();
1317 auto serializerDescriptor = serializerLayer->descriptor();
1320 descriptor.
m_Eps = serializerDescriptor->eps();
1334 layer->GetOutputSlot(0).SetTensorInfo(outputInfo);
1336 RegisterInputSlots(graph, layerIndex, layer);
1337 RegisterOutputSlots(graph, layerIndex, layer);
1340 void IDeserializer::DeserializerImpl::ParseCast(
GraphPtr graph,
unsigned int layerIndex)
1357 RegisterInputSlots(graph, layerIndex, layer);
1358 RegisterOutputSlots(graph, layerIndex, layer);
1361 void IDeserializer::DeserializerImpl::ParseConstant(
GraphPtr graph,
unsigned int layerIndex)
1366 auto outputs =
GetOutputs(graph, layerIndex);
1371 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_ConstantLayer();
1372 auto serializerInput = serializerLayer->input();
1381 if (this->GetFeatureVersions(graph).m_WeightsLayoutScheme <= 0)
1387 std::unique_ptr<unsigned char[]> permuteBuffer(
new unsigned char[weightsInfo.
GetNumBytes()]);
1394 auto weightsShape = weightsInfo.GetShape();
1395 weightsInfo.SetShape({1,
1398 weightsShape[2]*weightsShape[3]});
1399 weightsInfo.SetConstant(
true);
1403 layer = m_Network->AddConstantLayer(weightsPermuted, layerName.c_str());
1405 layer->GetOutputSlot(0).SetTensorInfo(weightsPermuted.GetInfo());
1407 RegisterOutputSlots(graph, layerIndex, layer);
1413 layer = m_Network->AddConstantLayer(input, layerName.c_str());
1420 RegisterOutputSlots(graph, layerIndex, layer);
1423 void IDeserializer::DeserializerImpl::ParseConvolution2d(
GraphPtr graph,
unsigned int layerIndex)
1426 auto inputs =
GetInputs(graph, layerIndex);
1429 auto outputs =
GetOutputs(graph, layerIndex);
1432 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_Convolution2dLayer();
1435 auto flatbufferDescriptor = flatBufferLayer->descriptor();
1438 descriptor.
m_PadLeft = flatbufferDescriptor->padLeft();
1439 descriptor.
m_PadRight = flatbufferDescriptor->padRight();
1440 descriptor.
m_PadTop = flatbufferDescriptor->padTop();
1441 descriptor.
m_PadBottom = flatbufferDescriptor->padBottom();
1442 descriptor.
m_StrideX = flatbufferDescriptor->strideX();
1443 descriptor.
m_StrideY = flatbufferDescriptor->strideY();;
1444 descriptor.
m_DilationX = flatbufferDescriptor->dilationX();
1445 descriptor.
m_DilationY = flatbufferDescriptor->dilationY();;
1446 descriptor.
m_BiasEnabled = flatbufferDescriptor->biasEnabled();;
1450 std::vector<unsigned int> ignoreSlots {};
1455 if (this->GetFeatureVersions(graph).m_ConstTensorsAsInputs <= 0)
1461 layer = m_Network->AddConvolution2dLayer(descriptor,
1465 auto weightsLayer = m_Network->AddConstantLayer(weightsTensor);
1466 weightsLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(1u));
1467 weightsLayer->GetOutputSlot(0).SetTensorInfo(weightsTensor.
GetInfo());
1468 ignoreSlots.emplace_back(1u);
1473 auto biasLayer = m_Network->AddConstantLayer(biasTensor);
1474 biasLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(2u));
1475 biasLayer->GetOutputSlot(0).SetTensorInfo(biasTensor.
GetInfo());
1476 ignoreSlots.emplace_back(2u);
1481 layer = m_Network->AddConvolution2dLayer(descriptor,
1488 layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo);
1490 RegisterInputSlots(graph, layerIndex, layer, ignoreSlots);
1491 RegisterOutputSlots(graph, layerIndex, layer);
1494 void IDeserializer::DeserializerImpl::ParseConvolution3d(
GraphPtr graph,
unsigned int layerIndex)
1497 auto inputs =
GetInputs(graph, layerIndex);
1500 auto outputs =
GetOutputs(graph, layerIndex);
1503 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_Convolution3dLayer();
1505 auto serializerDescriptor = serializerLayer->descriptor();
1508 descriptor.
m_PadLeft = serializerDescriptor->padLeft();
1509 descriptor.
m_PadRight = serializerDescriptor->padRight();
1510 descriptor.
m_PadTop = serializerDescriptor->padTop();
1511 descriptor.
m_PadBottom = serializerDescriptor->padBottom();
1512 descriptor.
m_PadFront = serializerDescriptor->padFront();
1513 descriptor.
m_PadBack = serializerDescriptor->padBack();
1514 descriptor.
m_StrideX = serializerDescriptor->strideX();
1515 descriptor.
m_StrideY = serializerDescriptor->strideY();
1516 descriptor.
m_StrideZ = serializerDescriptor->strideZ();
1517 descriptor.
m_DilationX = serializerDescriptor->dilationX();
1518 descriptor.
m_DilationY = serializerDescriptor->dilationY();
1519 descriptor.
m_DilationZ = serializerDescriptor->dilationZ();
1520 descriptor.
m_BiasEnabled = serializerDescriptor->biasEnabled();
1526 IConnectableLayer* layer = m_Network->AddConvolution3dLayer(descriptor, layerName.c_str());
1529 layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo);
1531 RegisterInputSlots(graph, layerIndex, layer);
1532 RegisterOutputSlots(graph, layerIndex, layer);
1535 void IDeserializer::DeserializerImpl::ParseDepthToSpace(
GraphPtr graph,
unsigned int layerIndex)
1539 auto inputs =
GetInputs(graph, layerIndex);
1542 auto outputs =
GetOutputs(graph, layerIndex);
1545 auto fbDescriptor = graph->layers()->Get(layerIndex)->layer_as_DepthToSpaceLayer()->descriptor();
1548 descriptor.
m_BlockSize = fbDescriptor->blockSize();
1552 IConnectableLayer* layer = m_Network->AddDepthToSpaceLayer(descriptor, layerName.c_str());
1557 RegisterInputSlots(graph, layerIndex, layer);
1558 RegisterOutputSlots(graph, layerIndex, layer);
1561 void IDeserializer::DeserializerImpl::ParseDepthwiseConvolution2d(
GraphPtr graph,
unsigned int layerIndex)
1564 auto inputs =
GetInputs(graph, layerIndex);
1567 auto outputs =
GetOutputs(graph, layerIndex);
1570 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_DepthwiseConvolution2dLayer();
1572 auto serializerDescriptor = serializerLayer->descriptor();
1575 descriptor.
m_PadLeft = serializerDescriptor->padLeft();
1576 descriptor.
m_PadRight = serializerDescriptor->padRight();
1577 descriptor.
m_PadTop = serializerDescriptor->padTop();
1578 descriptor.
m_PadBottom = serializerDescriptor->padBottom();
1579 descriptor.
m_StrideX = serializerDescriptor->strideX();
1580 descriptor.
m_StrideY = serializerDescriptor->strideY();
1581 descriptor.
m_DilationX = serializerDescriptor->dilationX();
1582 descriptor.
m_DilationY = serializerDescriptor->dilationY();
1583 descriptor.
m_BiasEnabled = serializerDescriptor->biasEnabled();
1587 std::vector<unsigned int> ignoreSlots {};
1591 if (this->GetFeatureVersions(graph).m_ConstTensorsAsInputs <= 0)
1598 ignoreSlots.emplace_back(1u);
1600 layer = m_Network->AddDepthwiseConvolution2dLayer(descriptor,
1607 ignoreSlots.emplace_back(2u);
1609 auto biasLayer = m_Network->AddConstantLayer(biases);
1610 biasLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(2u));
1611 biasLayer->GetOutputSlot(0).SetTensorInfo(biases.
GetInfo());
1614 if (this->GetFeatureVersions(graph).m_WeightsLayoutScheme <= 0)
1620 std::unique_ptr<unsigned char[]> permuteBuffer(
new unsigned char[weightsInfo.
GetNumBytes()]);
1623 weights.GetMemoryArea(), permuteBuffer.get(),
1627 auto weightsShape = weightsInfo.GetShape();
1628 weightsInfo.SetShape({1,
1631 weightsShape[2]*weightsShape[3]});
1635 auto weightsLayer = m_Network->AddConstantLayer(weightsPermuted);
1636 weightsLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(1u));
1637 weightsLayer->GetOutputSlot(0).SetTensorInfo(weightsPermuted.GetInfo());
1641 auto weightsLayer = m_Network->AddConstantLayer(weights);
1642 weightsLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(1u));
1643 weightsLayer->GetOutputSlot(0).SetTensorInfo(weights.GetInfo());
1648 layer = m_Network->AddDepthwiseConvolution2dLayer(descriptor,
1655 layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo);
1657 RegisterInputSlots(graph, layerIndex, layer, ignoreSlots);
1658 RegisterOutputSlots(graph, layerIndex, layer);
1661 void IDeserializer::DeserializerImpl::ParseDetectionPostProcess(
GraphPtr graph,
unsigned int layerIndex)
1664 auto inputs =
GetInputs(graph, layerIndex);
1668 auto outputs =
GetOutputs(graph, layerIndex);
1671 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_DetectionPostProcessLayer();
1673 auto flatBufferDescriptor = flatBufferLayer->descriptor();
1681 descriptor.
m_NumClasses = flatBufferDescriptor->numClasses();
1683 descriptor.
m_ScaleX = flatBufferDescriptor->scaleX();
1684 descriptor.
m_ScaleY = flatBufferDescriptor->scaleY();
1685 descriptor.
m_ScaleW = flatBufferDescriptor->scaleW();
1686 descriptor.
m_ScaleH = flatBufferDescriptor->scaleH();
1694 for (
unsigned int i = 0; i < 4; i++)
1696 layer->GetOutputSlot(i).SetTensorInfo(
ToTensorInfo(outputs[i]));
1699 RegisterInputSlots(graph, layerIndex, layer);
1700 RegisterOutputSlots(graph, layerIndex, layer);
1703 void IDeserializer::DeserializerImpl::ParseDivision(
GraphPtr graph,
unsigned int layerIndex)
1706 auto inputs =
GetInputs(graph, layerIndex);
1710 auto outputs =
GetOutputs(graph, layerIndex);
1719 RegisterInputSlots(graph, layerIndex, layer);
1720 RegisterOutputSlots(graph, layerIndex, layer);
1723 void IDeserializer::DeserializerImpl::ParseEqual(
GraphPtr graph,
unsigned int layerIndex)
1726 auto inputs =
GetInputs(graph, layerIndex);
1730 auto outputs =
GetOutputs(graph, layerIndex);
1735 IConnectableLayer* layer = m_Network->AddComparisonLayer(descriptor, layerName.c_str());
1740 RegisterInputSlots(graph, layerIndex, layer);
1741 RegisterOutputSlots(graph, layerIndex, layer);
1744 void IDeserializer::DeserializerImpl::ParseFill(
GraphPtr graph,
unsigned int layerIndex)
1747 auto inputs =
GetInputs(graph, layerIndex);
1751 auto outputs =
GetOutputs(graph, layerIndex);
1756 descriptor.
m_Value = graph->layers()->Get(layerIndex)->layer_as_FillLayer()->descriptor()->value();
1757 IConnectableLayer* layer = m_Network->AddFillLayer(descriptor, layerName.c_str());
1762 RegisterInputSlots(graph, layerIndex, layer);
1763 RegisterOutputSlots(graph, layerIndex, layer);
1766 void IDeserializer::DeserializerImpl::ParseGreater(
GraphPtr graph,
unsigned int layerIndex)
1769 auto inputs =
GetInputs(graph, layerIndex);
1773 auto outputs =
GetOutputs(graph, layerIndex);
1778 IConnectableLayer* layer = m_Network->AddComparisonLayer(descriptor, layerName.c_str());
1783 RegisterInputSlots(graph, layerIndex, layer);
1784 RegisterOutputSlots(graph, layerIndex, layer);
1787 void IDeserializer::DeserializerImpl::ParseInstanceNormalization(
GraphPtr graph,
unsigned int layerIndex)
1791 auto inputs =
GetInputs(graph, layerIndex);
1794 auto outputs =
GetOutputs(graph, layerIndex);
1797 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_InstanceNormalizationLayer();
1798 auto fbDescriptor = fbLayer->descriptor();
1801 descriptor.
m_Gamma = fbDescriptor->gamma();
1802 descriptor.
m_Beta = fbDescriptor->beta();
1803 descriptor.
m_Eps = fbDescriptor->eps();
1806 const std::string layerName =
GetLayerName(graph, layerIndex);
1809 IConnectableLayer* layer = m_Network->AddInstanceNormalizationLayer(descriptor, layerName.c_str());
1812 RegisterInputSlots(graph, layerIndex, layer);
1813 RegisterOutputSlots(graph, layerIndex, layer);
1816 void IDeserializer::DeserializerImpl::ParseL2Normalization(
GraphPtr graph,
unsigned int layerIndex)
1820 auto inputs =
GetInputs(graph, layerIndex);
1823 auto outputs =
GetOutputs(graph, layerIndex);
1827 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_L2NormalizationLayer();
1828 auto flatBufferDescriptor = flatBufferLayer->descriptor();
1833 descriptor.
m_Eps = flatBufferDescriptor->eps();
1835 IConnectableLayer* layer = m_Network->AddL2NormalizationLayer(descriptor, layerName.c_str());
1838 RegisterInputSlots(graph, layerIndex, layer);
1839 RegisterOutputSlots(graph, layerIndex, layer);
1842 void IDeserializer::DeserializerImpl::ParseLogicalBinary(
GraphPtr graph,
unsigned int layerIndex)
1847 auto inputs =
GetInputs(graph, layerIndex);
1850 auto outputs =
GetOutputs(graph, layerIndex);
1853 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_LogicalBinaryLayer();
1854 auto fbDescriptor = fbLayer->descriptor();
1859 const std::string& layerName =
GetLayerName(graph, layerIndex);
1860 IConnectableLayer* layer = m_Network->AddLogicalBinaryLayer(descriptor, layerName.c_str());
1865 RegisterInputSlots(graph, layerIndex, layer);
1866 RegisterOutputSlots(graph, layerIndex, layer);
1869 void IDeserializer::DeserializerImpl::ParseLogSoftmax(
GraphPtr graph,
unsigned int layerIndex)
1880 descriptor.
m_Beta = graph->layers()->Get(layerIndex)->layer_as_LogSoftmaxLayer()->descriptor()->beta();
1881 descriptor.m_Axis = graph->layers()->Get(layerIndex)->layer_as_LogSoftmaxLayer()->descriptor()->axis();
1884 IConnectableLayer* layer = m_Network->AddLogSoftmaxLayer(descriptor, layerName.c_str());
1889 RegisterInputSlots(graph, layerIndex, layer);
1890 RegisterOutputSlots(graph, layerIndex, layer);
1893 void IDeserializer::DeserializerImpl::ParseMinimum(
GraphPtr graph,
unsigned int layerIndex)
1896 auto inputs =
GetInputs(graph, layerIndex);
1900 auto outputs =
GetOutputs(graph, layerIndex);
1909 RegisterInputSlots(graph, layerIndex, layer);
1910 RegisterOutputSlots(graph, layerIndex, layer);
1913 void IDeserializer::DeserializerImpl::ParseMaximum(
GraphPtr graph,
unsigned int layerIndex)
1916 auto inputs =
GetInputs(graph, layerIndex);
1920 auto outputs =
GetOutputs(graph, layerIndex);
1929 RegisterInputSlots(graph, layerIndex, layer);
1930 RegisterOutputSlots(graph, layerIndex, layer);
1934 unsigned int layerIndex)
1936 auto layerType = graph->layers()->Get(layerIndex)->layer_type();
1940 case Layer::Layer_ConcatLayer:
1941 return graph->layers()->Get(layerIndex)->layer_as_ConcatLayer()->descriptor();
1942 case Layer::Layer_MergerLayer:
1943 return graph->layers()->Get(layerIndex)->layer_as_MergerLayer()->descriptor();
1948 void IDeserializer::DeserializerImpl::ParseChannelShuffle(
GraphPtr graph,
unsigned int layerIndex)
1959 descriptor.
m_Axis = graph->layers()->Get(layerIndex)->layer_as_ChannelShuffleLayer()->descriptor()->axis();
1960 descriptor.m_NumGroups =
1961 graph->layers()->Get(layerIndex)->layer_as_ChannelShuffleLayer()->descriptor()->numGroups();
1964 IConnectableLayer* layer = m_Network->AddChannelShuffleLayer(descriptor, layerName.c_str());
1969 RegisterInputSlots(graph, layerIndex, layer);
1970 RegisterOutputSlots(graph, layerIndex, layer);
1972 void IDeserializer::DeserializerImpl::ParseComparison(
GraphPtr graph,
unsigned int layerIndex)
1977 auto inputs =
GetInputs(graph, layerIndex);
1980 auto outputs =
GetOutputs(graph, layerIndex);
1983 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_ComparisonLayer();
1984 auto fbDescriptor = fbLayer->descriptor();
1989 const std::string& layerName =
GetLayerName(graph, layerIndex);
1990 IConnectableLayer* layer = m_Network->AddComparisonLayer(descriptor, layerName.c_str());
1995 RegisterInputSlots(graph, layerIndex, layer);
1996 RegisterOutputSlots(graph, layerIndex, layer);
1999 void IDeserializer::DeserializerImpl::ParseElementwiseUnary(
GraphPtr graph,
unsigned int layerIndex)
2004 auto inputs =
GetInputs(graph, layerIndex);
2007 auto outputs =
GetOutputs(graph, layerIndex);
2010 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_ElementwiseUnaryLayer();
2011 auto fbDescriptor = fbLayer->descriptor();
2016 const std::string& layerName =
GetLayerName(graph, layerIndex);
2017 IConnectableLayer* layer = m_Network->AddElementwiseUnaryLayer(descriptor, layerName.c_str());
2022 RegisterInputSlots(graph, layerIndex, layer);
2023 RegisterOutputSlots(graph, layerIndex, layer);
2026 void IDeserializer::DeserializerImpl::ParseConcat(
GraphPtr graph,
unsigned int layerIndex)
2031 auto outputs =
GetOutputs(graph, layerIndex);
2036 unsigned int numViews = originsDescriptor->numViews();
2037 unsigned int numDimensions = originsDescriptor->numDimensions();
2040 auto inputs =
GetInputs(graph, layerIndex);
2044 auto originsPtr = originsDescriptor->viewOrigins();
2045 for (
unsigned int v = 0; v < numViews; ++v)
2047 auto originPtr = originsPtr->Get(v);
2048 for (
unsigned int d = 0; d < numDimensions; ++d)
2050 uint32_t value = originPtr->data()->Get(d);
2051 descriptor.SetViewOriginCoord(v, d, value);
2054 descriptor.SetConcatAxis(originsDescriptor->concatAxis());
2056 IConnectableLayer* layer = m_Network->AddConcatLayer(descriptor, layerName.c_str());
2060 RegisterInputSlots(graph, layerIndex, layer);
2061 RegisterOutputSlots(graph, layerIndex, layer);
2064 void IDeserializer::DeserializerImpl::ParseMultiplication(
GraphPtr graph,
unsigned int layerIndex)
2067 auto inputs =
GetInputs(graph, layerIndex);
2071 auto outputs =
GetOutputs(graph, layerIndex);
2075 IConnectableLayer* layer = m_Network->AddMultiplicationLayer(layerName.c_str());
2080 RegisterInputSlots(graph, layerIndex, layer);
2081 RegisterOutputSlots(graph, layerIndex, layer);
2084 void IDeserializer::DeserializerImpl::ParseFloor(
GraphPtr graph,
unsigned int layerIndex)
2089 auto inputs =
GetInputs(graph, layerIndex);
2092 auto outputs =
GetOutputs(graph, layerIndex);
2099 layer = m_Network->AddFloorLayer(layerName.c_str());
2104 RegisterInputSlots(graph, layerIndex, layer);
2105 RegisterOutputSlots(graph, layerIndex, layer);
2108 void IDeserializer::DeserializerImpl::ParseFullyConnected(
GraphPtr graph,
unsigned int layerIndex)
2111 auto inputs =
GetInputs(graph, layerIndex);
2114 auto outputs =
GetOutputs(graph, layerIndex);
2117 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_FullyConnectedLayer();
2119 auto flatBufferDescriptor = flatBufferLayer->descriptor();
2122 fullyConnectedDescriptor.
m_BiasEnabled = flatBufferDescriptor->biasEnabled();
2124 fullyConnectedDescriptor.
m_ConstantWeights = flatBufferDescriptor->constantWeights();
2127 std::vector<unsigned int> ignoreSlots {};
2131 if (this->GetFeatureVersions(graph).m_ConstTensorsAsInputs <= 0)
2136 layer = m_Network->AddFullyConnectedLayer(fullyConnectedDescriptor,
2140 auto weightsLayer = m_Network->AddConstantLayer(weightsTensor);
2141 weightsLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(1u));
2142 weightsLayer->GetOutputSlot(0).SetTensorInfo(weightsTensor.
GetInfo());
2143 ignoreSlots.emplace_back(1u);
2148 auto biasLayer = m_Network->AddConstantLayer(biasTensor);
2149 biasLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(2u));
2150 biasLayer->GetOutputSlot(0).SetTensorInfo(biasTensor.
GetInfo());
2151 ignoreSlots.emplace_back(2u);
2156 layer = m_Network->AddFullyConnectedLayer(fullyConnectedDescriptor,
2158 uint32_t numInputs = fullyConnectedDescriptor.
GetNumInputs();
2165 RegisterInputSlots(graph, layerIndex, layer, ignoreSlots);
2166 RegisterOutputSlots(graph, layerIndex, layer);
2169 void IDeserializer::DeserializerImpl::ParsePad(
GraphPtr graph,
unsigned int layerIndex)
2179 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_PadLayer()->descriptor();
2180 auto flatBufferPadList = flatBufferDescriptor->padList();
2181 auto paddingMode = flatBufferDescriptor->paddingMode();
2182 float padValue = flatBufferDescriptor->padValue();
2184 if (flatBufferPadList->size() % 2 != 0)
2186 throw ParseException(fmt::format(
"The size of the pad list must be divisible by 2 {}",
2190 std::vector<std::pair<unsigned int, unsigned int>> padList;
2191 padList.reserve(flatBufferPadList->size() / 2);
2192 for (
unsigned int i = 0; i < flatBufferPadList->size() - 1; i += 2)
2194 padList.emplace_back(flatBufferPadList->Get(i), flatBufferPadList->Get(i+1));
2200 IConnectableLayer* layer = m_Network->AddPadLayer(descriptor, layerName.c_str());
2205 RegisterInputSlots(graph, layerIndex, layer);
2206 RegisterOutputSlots(graph, layerIndex, layer);
2209 void IDeserializer::DeserializerImpl::ParsePermute(
GraphPtr graph,
unsigned int layerIndex)
2214 graph->layers()->Get(layerIndex)->layer_as_PermuteLayer()->descriptor()->dimMappings();
2216 auto inputs =
GetInputs(graph, layerIndex);
2219 auto outputs =
GetOutputs(graph, layerIndex);
2226 IConnectableLayer* layer = m_Network->AddPermuteLayer(descriptor, layerName.c_str());
2229 RegisterInputSlots(graph, layerIndex, layer);
2230 RegisterOutputSlots(graph, layerIndex, layer);
2234 unsigned int layerIndex)
2239 switch (pooling2dDesc->poolType())
2241 case PoolingAlgorithm_Average:
2246 case PoolingAlgorithm_Max:
2251 case PoolingAlgorithm_L2:
2262 switch (pooling2dDesc->outputShapeRounding())
2264 case OutputShapeRounding_Floor:
2269 case OutputShapeRounding_Ceiling:
2280 switch (pooling2dDesc->paddingMethod())
2282 case PaddingMethod_Exclude:
2287 case PaddingMethod_IgnoreValue:
2298 switch (pooling2dDesc->dataLayout())
2300 case DataLayout_NCHW:
2305 case DataLayout_NHWC:
2317 desc.
m_PadLeft = pooling2dDesc->padLeft();
2319 desc.
m_PadTop = pooling2dDesc->padTop();
2320 desc.
m_StrideX = pooling2dDesc->strideX();
2321 desc.
m_StrideY = pooling2dDesc->strideY();
2329 unsigned int layerIndex)
2334 switch (pooling3dDesc->poolType())
2336 case PoolingAlgorithm_Average:
2341 case PoolingAlgorithm_Max:
2346 case PoolingAlgorithm_L2:
2357 switch (pooling3dDesc->outputShapeRounding())
2359 case OutputShapeRounding_Floor:
2364 case OutputShapeRounding_Ceiling:
2375 switch (pooling3dDesc->paddingMethod())
2377 case PaddingMethod_Exclude:
2382 case PaddingMethod_IgnoreValue:
2393 switch (pooling3dDesc->dataLayout())
2395 case DataLayout_NCDHW:
2400 case DataLayout_NDHWC:
2412 desc.
m_PadLeft = pooling3dDesc->padLeft();
2414 desc.
m_PadTop = pooling3dDesc->padTop();
2416 desc.
m_PadBack = pooling3dDesc->padBack();
2417 desc.
m_StrideX = pooling3dDesc->strideX();
2418 desc.
m_StrideY = pooling3dDesc->strideY();
2419 desc.
m_StrideZ = pooling3dDesc->strideZ();
2427 void IDeserializer::DeserializerImpl::ParsePooling2d(
GraphPtr graph,
unsigned int layerIndex)
2431 auto pooling2dDes = graph->layers()->Get(layerIndex)->layer_as_Pooling2dLayer()->descriptor();
2432 auto inputs =
GetInputs(graph, layerIndex);
2435 auto outputs =
GetOutputs(graph, layerIndex);
2441 IConnectableLayer* layer = m_Network->AddPooling2dLayer(pooling2dDescriptor, layerName.c_str());
2444 RegisterInputSlots(graph, layerIndex, layer);
2445 RegisterOutputSlots(graph, layerIndex, layer);
2448 void IDeserializer::DeserializerImpl::ParsePooling3d(
GraphPtr graph,
unsigned int layerIndex)
2452 auto pooling3dDes = graph->layers()->Get(layerIndex)->layer_as_Pooling3dLayer()->descriptor();
2453 auto inputs =
GetInputs(graph, layerIndex);
2456 auto outputs =
GetOutputs(graph, layerIndex);
2462 IConnectableLayer* layer = m_Network->AddPooling3dLayer(pooling3dDescriptor, layerName.c_str());
2465 RegisterInputSlots(graph, layerIndex, layer);
2466 RegisterOutputSlots(graph, layerIndex, layer);
2469 void IDeserializer::DeserializerImpl::ParseQuantize(
GraphPtr graph,
unsigned int layerIndex)
2473 auto inputs =
GetInputs(graph, layerIndex);
2476 auto outputs =
GetOutputs(graph, layerIndex);
2484 RegisterInputSlots(graph, layerIndex, layer);
2485 RegisterOutputSlots(graph, layerIndex, layer);
2489 const std::vector<uint32_t>& targetDimsIn)
2491 std::vector<unsigned int> outputDims(targetDimsIn.begin(), targetDimsIn.end());
2492 const auto stretchDim = std::find(targetDimsIn.begin(), targetDimsIn.end(), -1);
2494 if (stretchDim != targetDimsIn.end())
2496 if (std::find(std::next(stretchDim), targetDimsIn.end(), -1) != targetDimsIn.end())
2498 throw ParseException(fmt::format(
"At most one component of shape can be -1 {}",
2502 auto targetNumElements =
2504 std::accumulate(targetDimsIn.begin(), targetDimsIn.end(), -1, std::multiplies<int32_t>()));
2506 auto stretchIndex =
static_cast<size_t>(std::distance(targetDimsIn.begin(), stretchDim));
2507 outputDims[stretchIndex] = inputTensorInfo.
GetNumElements() / targetNumElements;
2518 void IDeserializer::DeserializerImpl::ParseRank(
GraphPtr graph,
unsigned int layerIndex)
2534 RegisterInputSlots(graph, layerIndex, layer);
2535 RegisterOutputSlots(graph, layerIndex, layer);
2538 void IDeserializer::DeserializerImpl::ParseReduce(
GraphPtr graph,
unsigned int layerIndex)
2543 auto inputs =
GetInputs(graph, layerIndex);
2546 auto outputs =
GetOutputs(graph, layerIndex);
2549 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_ReduceLayer();
2550 auto fbDescriptor = fbLayer->descriptor();
2551 auto flatBufferAxis = fbDescriptor->axis();
2554 descriptor.
m_KeepDims = fbDescriptor->keepDims();
2555 descriptor.
m_vAxis = std::vector<unsigned int>(flatBufferAxis->begin(), flatBufferAxis->end());
2558 const std::string& layerName =
GetLayerName(graph, layerIndex);
2559 IConnectableLayer* layer = m_Network->AddReduceLayer(descriptor, layerName.c_str());
2564 RegisterInputSlots(graph, layerIndex, layer);
2565 RegisterOutputSlots(graph, layerIndex, layer);
2568 void IDeserializer::DeserializerImpl::ParseReshape(
GraphPtr graph,
unsigned int layerIndex)
2571 auto inputs =
GetInputs(graph, layerIndex);
2573 auto outputs =
GetOutputs(graph, layerIndex);
2579 const auto targetDims = graph->layers()->Get(layerIndex)->layer_as_ReshapeLayer()->descriptor()->targetShape();
2580 std::vector<uint32_t> outputDims(targetDims->begin(), targetDims->begin() + targetDims->size());
2583 const armnn::TensorShape& reshapeOutputTensorShape = reshapeOutputTensorInfo.GetShape();
2585 const std::vector<uint32_t> expectedDims(outputs[0]->dimensions()->begin(),
2586 outputs[0]->dimensions()->begin() + outputs[0]->dimensions()->size());
2588 if (inputs.size() > 1 && !
CheckShape(reshapeOutputTensorShape, expectedDims))
2590 std::stringstream ss;
2591 ss <<
"New shape defined in reshape parameters " 2592 << reshapeOutputTensorShape
2593 <<
" does not equal output shape " 2594 << actualOutputTensorInfo.
GetShape()
2604 IConnectableLayer* layer = m_Network->AddReshapeLayer(reshapeDesc, layerName.c_str());
2607 RegisterInputSlots(graph, layerIndex, layer);
2608 RegisterOutputSlots(graph, layerIndex, layer);
2611 void IDeserializer::DeserializerImpl::ParseResize(
GraphPtr graph,
unsigned int layerIndex)
2621 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_ResizeLayer()->descriptor();
2624 descriptor.
m_TargetWidth = flatBufferDescriptor->targetWidth();
2625 descriptor.
m_TargetHeight = flatBufferDescriptor->targetHeight();
2628 descriptor.
m_AlignCorners = flatBufferDescriptor->alignCorners();
2632 IConnectableLayer* layer = m_Network->AddResizeLayer(descriptor, layerName.c_str());
2637 RegisterInputSlots(graph, layerIndex, layer);
2638 RegisterOutputSlots(graph, layerIndex, layer);
2644 void IDeserializer::DeserializerImpl::ParseResizeBilinear(
GraphPtr graph,
unsigned int layerIndex)
2654 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_ResizeBilinearLayer()->descriptor();
2657 descriptor.
m_TargetWidth = flatBufferDescriptor->targetWidth();
2658 descriptor.
m_TargetHeight = flatBufferDescriptor->targetHeight();
2661 descriptor.
m_AlignCorners = flatBufferDescriptor->alignCorners();
2665 IConnectableLayer* layer = m_Network->AddResizeLayer(descriptor, layerName.c_str());
2670 RegisterInputSlots(graph, layerIndex, layer);
2671 RegisterOutputSlots(graph, layerIndex, layer);
2674 void IDeserializer::DeserializerImpl::ParseShape(
GraphPtr graph,
unsigned int layerIndex)
2690 RegisterInputSlots(graph, layerIndex, layer);
2691 RegisterOutputSlots(graph, layerIndex, layer);
2694 void IDeserializer::DeserializerImpl::ParseSoftmax(
GraphPtr graph,
unsigned int layerIndex)
2705 descriptor.
m_Beta = graph->layers()->Get(layerIndex)->layer_as_SoftmaxLayer()->descriptor()->beta();
2706 descriptor.m_Axis = graph->layers()->Get(layerIndex)->layer_as_SoftmaxLayer()->descriptor()->axis();
2709 IConnectableLayer* layer = m_Network->AddSoftmaxLayer(descriptor, layerName.c_str());
2714 RegisterInputSlots(graph, layerIndex, layer);
2715 RegisterOutputSlots(graph, layerIndex, layer);
2718 void IDeserializer::DeserializerImpl::ParseSpaceToBatchNd(
GraphPtr graph,
unsigned int layerIndex)
2728 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_SpaceToBatchNdLayer()->descriptor();
2729 auto flatBufferPadList = flatBufferDescriptor->padList();
2730 auto flatBufferBlockShape = flatBufferDescriptor->blockShape();
2732 if (flatBufferPadList->size() % 2 != 0)
2734 throw ParseException(fmt::format(
"The size of the pad list must be divisible by 2 {}",
2738 std::vector<std::pair<unsigned int, unsigned int>> padList;
2739 padList.reserve(flatBufferPadList->size() / 2);
2740 for (
unsigned int i = 0; i < flatBufferPadList->size() - 1; i += 2)
2742 padList.emplace_back(flatBufferPadList->Get(i), flatBufferPadList->Get(i+1));
2748 std::vector<unsigned int>(flatBufferBlockShape->begin(), flatBufferBlockShape->end());
2752 IConnectableLayer* layer = m_Network->AddSpaceToBatchNdLayer(descriptor, layerName.c_str());
2757 RegisterInputSlots(graph, layerIndex, layer);
2758 RegisterOutputSlots(graph, layerIndex, layer);
2761 void IDeserializer::DeserializerImpl::ParseSpaceToDepth(
GraphPtr graph,
unsigned int layerIndex)
2771 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_SpaceToDepthLayer()->descriptor();
2774 descriptor.
m_BlockSize = flatBufferDescriptor->blockSize();
2778 IConnectableLayer* layer = m_Network->AddSpaceToDepthLayer(descriptor, layerName.c_str());
2783 RegisterInputSlots(graph, layerIndex, layer);
2784 RegisterOutputSlots(graph, layerIndex, layer);
2789 unsigned int layerIndex)
2794 switch (normalizationDescriptor->normChannelType())
2796 case NormalizationAlgorithmChannel_Across:
2801 case NormalizationAlgorithmChannel_Within:
2812 switch (normalizationDescriptor->normMethodType())
2814 case NormalizationAlgorithmMethod_LocalBrightness:
2819 case NormalizationAlgorithmMethod_LocalContrast:
2830 switch (normalizationDescriptor->dataLayout())
2832 case DataLayout_NCHW:
2837 case DataLayout_NHWC:
2848 desc.
m_Alpha = normalizationDescriptor->alpha();
2849 desc.
m_Beta = normalizationDescriptor->beta();
2850 desc.
m_K = normalizationDescriptor->k();
2851 desc.
m_NormSize = normalizationDescriptor->normSize();
2856 void IDeserializer::DeserializerImpl::ParseNormalization(
GraphPtr graph,
unsigned int layerIndex)
2860 auto normalizationDes = graph->layers()->Get(layerIndex)->layer_as_NormalizationLayer()->descriptor();
2873 IConnectableLayer* layer = m_Network->AddNormalizationLayer(normalizationDescriptor, layerName.c_str());
2876 RegisterInputSlots(graph, layerIndex, layer);
2877 RegisterOutputSlots(graph, layerIndex, layer);
2880 void IDeserializer::DeserializerImpl::ParseRsqrt(
GraphPtr graph,
unsigned int layerIndex)
2883 auto inputs =
GetInputs(graph, layerIndex);
2887 auto outputs =
GetOutputs(graph, layerIndex);
2893 IConnectableLayer* layer = m_Network->AddElementwiseUnaryLayer(descriptor, layerName.c_str());
2897 RegisterInputSlots(graph, layerIndex, layer);
2898 RegisterOutputSlots(graph, layerIndex, layer);
2901 void IDeserializer::DeserializerImpl::ParseSlice(
GraphPtr graph,
unsigned int layerIndex)
2905 auto inputs =
GetInputs(graph, layerIndex);
2908 auto outputs =
GetOutputs(graph, layerIndex);
2911 auto fbDescriptor = graph->layers()->Get(layerIndex)->layer_as_SliceLayer()->descriptor();
2913 auto fbBegin = fbDescriptor->begin();
2914 auto fbSize = fbDescriptor->size();
2916 if (fbBegin->size() != fbSize->size())
2918 throw ParseException(fmt::format(
"Begin and size descriptors must have the same length {}",
2923 descriptor.
m_Begin.insert(descriptor.
m_Begin.end(), fbBegin->begin(), fbBegin->end());
2924 descriptor.
m_Size.insert(descriptor.
m_Size.end(), fbSize->begin(), fbSize->end());
2927 IConnectableLayer* layer = m_Network->AddSliceLayer(descriptor, layerName.c_str());
2932 RegisterInputSlots(graph, layerIndex, layer);
2933 RegisterOutputSlots(graph, layerIndex, layer);
2936 void IDeserializer::DeserializerImpl::ParseStridedSlice(
GraphPtr graph,
unsigned int layerIndex)
2946 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_StridedSliceLayer()->descriptor();
2948 auto flatBufferBegin = flatBufferDescriptor->begin();
2949 auto flatBufferEnd = flatBufferDescriptor->end();
2950 auto flatBufferStride = flatBufferDescriptor->stride();
2952 if (!(flatBufferBegin->size() == flatBufferEnd->size() &&
2953 flatBufferBegin->size() == flatBufferStride->size()))
2955 throw ParseException(fmt::format(
"The size of the begin, end, and stride must be equal {}",
2959 std::vector<int> begin(flatBufferBegin->begin(), flatBufferBegin->end());
2960 std::vector<int> end(flatBufferEnd->begin(), flatBufferEnd->end());
2961 std::vector<int> stride(flatBufferStride->begin(), flatBufferStride->end());
2964 descriptor.m_BeginMask = flatBufferDescriptor->beginMask();
2965 descriptor.m_EndMask = flatBufferDescriptor->endMask();
2966 descriptor.m_ShrinkAxisMask = flatBufferDescriptor->shrinkAxisMask();
2967 descriptor.m_EllipsisMask = flatBufferDescriptor->ellipsisMask();
2968 descriptor.m_NewAxisMask = flatBufferDescriptor->newAxisMask();
2969 descriptor.m_DataLayout =
ToDataLayout(flatBufferDescriptor->dataLayout());
2972 IConnectableLayer* layer = m_Network->AddStridedSliceLayer(descriptor, layerName.c_str());
2977 RegisterInputSlots(graph, layerIndex, layer);
2978 RegisterOutputSlots(graph, layerIndex, layer);
2981 void IDeserializer::DeserializerImpl::ParseSubtraction(
GraphPtr graph,
unsigned int layerIndex)
2984 auto inputs =
GetInputs(graph, layerIndex);
2988 auto outputs =
GetOutputs(graph, layerIndex);
2997 RegisterInputSlots(graph, layerIndex, layer);
2998 RegisterOutputSlots(graph, layerIndex, layer);
3001 void IDeserializer::DeserializerImpl::ParseGather(
GraphPtr graph,
unsigned int layerIndex)
3012 descriptor.
m_Axis = graph->layers()->Get(layerIndex)->layer_as_GatherLayer()->descriptor()->axis();
3015 IConnectableLayer* layer = m_Network->AddGatherLayer(descriptor, layerName.c_str());
3020 RegisterInputSlots(graph, layerIndex, layer);
3021 RegisterOutputSlots(graph, layerIndex, layer);
3024 void IDeserializer::DeserializerImpl::ParseGatherNd(
GraphPtr graph,
unsigned int layerIndex)
3040 RegisterInputSlots(graph, layerIndex, layer);
3041 RegisterOutputSlots(graph, layerIndex, layer);
3044 void IDeserializer::DeserializerImpl::ParseMean(
GraphPtr graph,
unsigned int layerIndex)
3054 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_MeanLayer()->descriptor();
3055 auto flatBufferAxis = flatBufferDescriptor->axis();
3056 auto flatBufferKeepDims = flatBufferDescriptor->keepDims();
3059 descriptor.
m_Axis = std::vector<unsigned int>(flatBufferAxis->begin(), flatBufferAxis->end());
3063 IConnectableLayer* layer = m_Network->AddMeanLayer(descriptor, layerName.c_str());
3068 RegisterInputSlots(graph, layerIndex, layer);
3069 RegisterOutputSlots(graph, layerIndex, layer);
3072 void IDeserializer::DeserializerImpl::ParseSplitter(
GraphPtr graph,
unsigned int layerIndex)
3081 auto flatBufferViewsDescriptor = graph->layers()->Get(layerIndex)->layer_as_SplitterLayer()->descriptor();
3082 auto flatBufferViewSizes = flatBufferViewsDescriptor->viewSizes();
3083 auto flatBufferOriginsDescriptor = flatBufferViewsDescriptor->origins();
3084 auto flatBufferViewOrigins = flatBufferOriginsDescriptor->viewOrigins();
3085 uint32_t numViews = flatBufferOriginsDescriptor->numViews();
3086 uint32_t numDimensions = flatBufferOriginsDescriptor->numDimensions();
3093 for(
unsigned int vIdx = 0; vIdx < numViews; ++vIdx)
3095 for (
unsigned int dIdx = 0; dIdx < numDimensions; ++dIdx)
3097 viewsDescriptor.
SetViewSize(vIdx, dIdx, flatBufferViewSizes->Get(vIdx)->data()->Get(dIdx));
3098 viewsDescriptor.
SetViewOriginCoord(vIdx, dIdx, flatBufferViewOrigins->Get(vIdx)->data()->Get(dIdx));
3103 IConnectableLayer* layer = m_Network->AddSplitterLayer(viewsDescriptor, layerName.c_str());
3106 for(
unsigned int vIdx = 0; vIdx < numViews; ++vIdx)
3112 RegisterInputSlots(graph, layerIndex, layer);
3113 RegisterOutputSlots(graph, layerIndex, layer);
3131 void IDeserializer::DeserializerImpl::ParseLstm(
GraphPtr graph,
unsigned int layerIndex)
3135 auto inputs =
GetInputs(graph, layerIndex);
3138 auto outputs =
GetOutputs(graph, layerIndex);
3141 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_LstmLayer();
3143 auto flatBufferDescriptor = flatBufferLayer->descriptor();
3144 auto flatBufferInputParams = flatBufferLayer->inputParams();
3174 if (!lstmDescriptor.m_CifgEnabled)
3176 inputToInputWeights =
ToConstTensor(flatBufferInputParams->inputToInputWeights());
3177 recurrentToInputWeights =
ToConstTensor(flatBufferInputParams->recurrentToInputWeights());
3178 cellToInputWeights =
ToConstTensor(flatBufferInputParams->cellToInputWeights());
3179 inputGateBias =
ToConstTensor(flatBufferInputParams->inputGateBias());
3189 if (lstmDescriptor.m_ProjectionEnabled)
3191 projectionWeights =
ToConstTensor(flatBufferInputParams->projectionWeights());
3192 projectionBias =
ToConstTensor(flatBufferInputParams->projectionBias());
3200 if (lstmDescriptor.m_PeepholeEnabled)
3202 cellToForgetWeights =
ToConstTensor(flatBufferInputParams->cellToForgetWeights());
3203 cellToOutputWeights =
ToConstTensor(flatBufferInputParams->cellToOutputWeights());
3213 if (lstmDescriptor.m_LayerNormEnabled)
3215 if (!lstmDescriptor.m_CifgEnabled)
3217 inputLayerNormWeights =
ToConstTensor(flatBufferInputParams->inputLayerNormWeights());
3220 forgetLayerNormWeights =
ToConstTensor(flatBufferInputParams->forgetLayerNormWeights());
3221 cellLayerNormWeights =
ToConstTensor(flatBufferInputParams->cellLayerNormWeights());
3222 outputLayerNormWeights =
ToConstTensor(flatBufferInputParams->outputLayerNormWeights());
3229 IConnectableLayer* layer = m_Network->AddLstmLayer(lstmDescriptor, lstmInputParams, layerName.c_str());
3243 RegisterInputSlots(graph, layerIndex, layer);
3244 RegisterOutputSlots(graph, layerIndex, layer);
3256 desc.
m_CellClip = qLstmDescriptor->cellClip();
3270 void IDeserializer::DeserializerImpl::ParseQLstm(
GraphPtr graph,
unsigned int layerIndex)
3274 auto inputs =
GetInputs(graph, layerIndex);
3277 auto outputs =
GetOutputs(graph, layerIndex);
3280 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_QLstmLayer();
3282 auto flatBufferDescriptor = flatBufferLayer->descriptor();
3283 auto flatBufferInputParams = flatBufferLayer->inputParams();
3314 if (!qLstmDescriptor.m_CifgEnabled)
3316 inputToInputWeights =
ToConstTensor(flatBufferInputParams->inputToInputWeights());
3317 recurrentToInputWeights =
ToConstTensor(flatBufferInputParams->recurrentToInputWeights());
3318 inputGateBias =
ToConstTensor(flatBufferInputParams->inputGateBias());
3329 if (qLstmDescriptor.m_ProjectionEnabled)
3331 projectionWeights =
ToConstTensor(flatBufferInputParams->projectionWeights());
3332 projectionBias =
ToConstTensor(flatBufferInputParams->projectionBias());
3343 if (qLstmDescriptor.m_PeepholeEnabled)
3345 if (!qLstmDescriptor.m_CifgEnabled)
3347 cellToInputWeights =
ToConstTensor(flatBufferInputParams->cellToInputWeights());
3351 cellToForgetWeights =
ToConstTensor(flatBufferInputParams->cellToForgetWeights());
3352 cellToOutputWeights =
ToConstTensor(flatBufferInputParams->cellToOutputWeights());
3364 if (qLstmDescriptor.m_LayerNormEnabled)
3366 if (!qLstmDescriptor.m_CifgEnabled)
3368 inputLayerNormWeights =
ToConstTensor(flatBufferInputParams->inputLayerNormWeights());
3372 forgetLayerNormWeights =
ToConstTensor(flatBufferInputParams->forgetLayerNormWeights());
3373 cellLayerNormWeights =
ToConstTensor(flatBufferInputParams->cellLayerNormWeights());
3374 outputLayerNormWeights =
ToConstTensor(flatBufferInputParams->outputLayerNormWeights());
3381 IConnectableLayer* layer = m_Network->AddQLstmLayer(qLstmDescriptor, qLstmInputParams, layerName.c_str());
3392 RegisterInputSlots(graph, layerIndex, layer);
3393 RegisterOutputSlots(graph, layerIndex, layer);
3396 void IDeserializer::DeserializerImpl::ParseQuantizedLstm(
GraphPtr graph,
unsigned int layerIndex)
3400 auto inputs =
GetInputs(graph, layerIndex);
3403 auto outputs =
GetOutputs(graph, layerIndex);
3406 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_QuantizedLstmLayer();
3408 auto flatBufferInputParams = flatBufferLayer->inputParams();
3438 IConnectableLayer* layer = m_Network->AddQuantizedLstmLayer(lstmInputParams, layerName.c_str());
3446 RegisterInputSlots(graph, layerIndex, layer);
3447 RegisterOutputSlots(graph, layerIndex, layer);
3450 void IDeserializer::DeserializerImpl::ParseDequantize(
GraphPtr graph,
unsigned int layerIndex)
3460 const std::string layerName =
GetLayerName(graph, layerIndex);
3466 RegisterInputSlots(graph, layerIndex, layer);
3467 RegisterOutputSlots(graph, layerIndex, layer);
3470 void IDeserializer::DeserializerImpl::ParseMerge(
GraphPtr graph,
unsigned int layerIndex)
3480 const std::string layerName =
GetLayerName(graph, layerIndex);
3486 RegisterInputSlots(graph, layerIndex, layer);
3487 RegisterOutputSlots(graph, layerIndex, layer);
3490 void IDeserializer::DeserializerImpl::ParseSwitch(
GraphPtr graph,
unsigned int layerIndex)
3493 auto inputs =
GetInputs(graph, layerIndex);
3497 auto outputs =
GetOutputs(graph, layerIndex);
3509 RegisterInputSlots(graph, layerIndex, layer);
3510 RegisterOutputSlots(graph, layerIndex, layer);
3513 void IDeserializer::DeserializerImpl::ParsePrelu(
GraphPtr graph,
unsigned int layerIndex)
3516 auto inputs =
GetInputs(graph, layerIndex);
3520 auto outputs =
GetOutputs(graph, layerIndex);
3529 RegisterInputSlots(graph, layerIndex, layer);
3530 RegisterOutputSlots(graph, layerIndex, layer);
3533 void IDeserializer::DeserializerImpl::ParseTranspose(
GraphPtr graph,
unsigned int layerIndex)
3537 auto dimsMapping = graph->layers()->Get(layerIndex)->layer_as_TransposeLayer()->descriptor()->dimMappings();
3539 auto inputs =
GetInputs(graph, layerIndex);
3542 auto outputs =
GetOutputs(graph, layerIndex);
3549 IConnectableLayer* layer = m_Network->AddTransposeLayer(descriptor, layerName.c_str());
3552 RegisterInputSlots(graph, layerIndex, layer);
3553 RegisterOutputSlots(graph, layerIndex, layer);
3556 void IDeserializer::DeserializerImpl::ParseTransposeConvolution2d(
GraphPtr graph,
unsigned int layerIndex)
3560 auto inputs =
GetInputs(graph, layerIndex);
3563 auto outputs =
GetOutputs(graph, layerIndex);
3566 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_TransposeConvolution2dLayer();
3568 auto serializerDescriptor = serializerLayer->descriptor();
3571 descriptor.
m_PadLeft = serializerDescriptor->padLeft();
3572 descriptor.
m_PadRight = serializerDescriptor->padRight();
3573 descriptor.
m_PadTop = serializerDescriptor->padTop();
3574 descriptor.
m_PadBottom = serializerDescriptor->padBottom();
3575 descriptor.
m_StrideX = serializerDescriptor->strideX();
3576 descriptor.
m_StrideY = serializerDescriptor->strideY();;
3577 descriptor.
m_BiasEnabled = serializerDescriptor->biasEnabled();;
3586 optionalBiases = armnn::MakeOptional<armnn::ConstTensor>(biases);
3589 IConnectableLayer* layer = m_Network->AddTransposeConvolution2dLayer(descriptor,
3595 layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo);
3597 RegisterInputSlots(graph, layerIndex, layer);
3598 RegisterOutputSlots(graph, layerIndex, layer);
3601 void IDeserializer::DeserializerImpl::ParseStack(
GraphPtr graph,
unsigned int layerIndex)
3604 auto inputs =
GetInputs(graph, layerIndex);
3606 auto outputs =
GetOutputs(graph, layerIndex);
3609 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_StackLayer()->descriptor();
3610 unsigned int axis = flatBufferDescriptor->axis();
3611 unsigned int numInputs = flatBufferDescriptor->numInputs();
3614 auto flatBufferInputShape = flatBufferDescriptor->inputShape();
3615 std::vector<uint32_t> vectorInputShape(flatBufferInputShape->begin(),
3616 flatBufferInputShape->begin() + flatBufferInputShape->size());
3618 TensorShape inputShape(static_cast<unsigned int>(vectorInputShape.size()), vectorInputShape.data());
3621 for (
unsigned int i=0; i<inputs.size(); ++i)
3624 if (descriptor.m_InputShape != inputShape)
3626 std::stringstream ss;
3627 ss <<
"Shape of input " 3631 <<
" does not equal defined input shape " 3632 << descriptor.m_InputShape
3640 IConnectableLayer* layer = m_Network->AddStackLayer(descriptor, layerName.c_str());
3645 RegisterInputSlots(graph, layerIndex, layer);
3646 RegisterOutputSlots(graph, layerIndex, layer);
3649 void IDeserializer::DeserializerImpl::ParseStandIn(
GraphPtr graph,
unsigned int layerIndex)
3653 auto inputs =
GetInputs(graph, layerIndex);
3654 auto outputs =
GetOutputs(graph, layerIndex);
3656 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_StandInLayer();
3657 auto fbDescriptor = fbLayer->descriptor();
3660 descriptor.
m_NumInputs = fbDescriptor->numInputs();
3666 const std::string layerName =
GetLayerName(graph, layerIndex);
3669 for (
unsigned int i = 0u; i < descriptor.
m_NumOutputs; ++i)
3675 RegisterInputSlots(graph, layerIndex, layer);
3676 RegisterOutputSlots(graph, layerIndex, layer);
3696 void IDeserializer::DeserializerImpl::ParseUnidirectionalSequenceLstm(
GraphPtr graph,
unsigned int layerIndex)
3700 auto inputs =
GetInputs(graph, layerIndex);
3703 auto outputs =
GetOutputs(graph, layerIndex);
3706 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_UnidirectionalSequenceLstmLayer();
3708 auto flatBufferDescriptor = flatBufferLayer->descriptor();
3709 auto flatBufferInputParams = flatBufferLayer->inputParams();
3739 if (!descriptor.m_CifgEnabled)
3741 inputToInputWeights =
ToConstTensor(flatBufferInputParams->inputToInputWeights());
3742 recurrentToInputWeights =
ToConstTensor(flatBufferInputParams->recurrentToInputWeights());
3743 inputGateBias =
ToConstTensor(flatBufferInputParams->inputGateBias());
3749 if (descriptor.m_PeepholeEnabled)
3751 cellToInputWeights =
ToConstTensor(flatBufferInputParams->cellToInputWeights());
3758 if (descriptor.m_ProjectionEnabled)
3760 projectionWeights =
ToConstTensor(flatBufferInputParams->projectionWeights());
3761 projectionBias =
ToConstTensor(flatBufferInputParams->projectionBias());
3769 if (descriptor.m_PeepholeEnabled)
3771 cellToForgetWeights =
ToConstTensor(flatBufferInputParams->cellToForgetWeights());
3772 cellToOutputWeights =
ToConstTensor(flatBufferInputParams->cellToOutputWeights());
3782 if (descriptor.m_LayerNormEnabled)
3784 if (!descriptor.m_CifgEnabled)
3786 inputLayerNormWeights =
ToConstTensor(flatBufferInputParams->inputLayerNormWeights());
3789 forgetLayerNormWeights =
ToConstTensor(flatBufferInputParams->forgetLayerNormWeights());
3790 cellLayerNormWeights =
ToConstTensor(flatBufferInputParams->cellLayerNormWeights());
3791 outputLayerNormWeights =
ToConstTensor(flatBufferInputParams->outputLayerNormWeights());
3798 IConnectableLayer* layer = m_Network->AddUnidirectionalSequenceLstmLayer(descriptor,
3811 RegisterInputSlots(graph, layerIndex, layer);
3812 RegisterOutputSlots(graph, layerIndex, layer);
static armnn::NormalizationDescriptor GetNormalizationDescriptor(NormalizationDescriptorPtr normalizationDescriptor, unsigned int layerIndex)
uint32_t m_PadBottom
Padding bottom value in the height dimension.
bool m_BiasEnabled
Enable/disable bias.
PoolingAlgorithm m_PoolType
The pooling algorithm to use (Max. Average, L2).
float m_Eps
Used to avoid dividing by zero.
virtual unsigned int GetNumOutputSlots() const =0
Returns the number of connectable output slots.
armnn::LogicalBinaryOperation ToLogicalBinaryOperation(armnnSerializer::LogicalBinaryOperation operation)
bool m_ProjectionEnabled
Enable/disable the projection layer.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
UnaryOperation m_Operation
Specifies the elementwiseUnary operation to execute.
static TensorRawPtrVector GetOutputs(const GraphPtr &graph, unsigned int layerIndex)
A ViewsDescriptor for the SplitterLayer.
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
float m_ScaleW
Center size encoding scale weight.
#define CHECK_LAYERS(GRAPH, LAYERS_INDEX, LAYER_INDEX)
uint32_t m_PadBottom
Padding bottom value in the height dimension.
bool m_BiasEnabled
Enable/disable bias.
armnn::ReduceOperation ToReduceOperation(armnnSerializer::ReduceOperation operation)
virtual unsigned int GetNumInputSlots() const =0
Returns the number of connectable input slots.
float m_K
Kappa value used for the across channel normalization equation.
uint32_t GetNumInputs() const
A TransposeConvolution2dDescriptor for the TransposeConvolution2dLayer.
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
const TensorShape & GetShape() const
uint32_t m_PoolWidth
Pooling width value.
uint32_t m_PadBottom
Padding bottom value in the height dimension.
uint32_t m_PadLeft
Padding left value in the width dimension.
float m_ClippingThresProj
Clipping threshold value for the projection.
uint32_t m_PoolDepth
Pooling depth value.
std::string AsString() const
static LayerBaseRawPtr GetBaseLayer(const GraphPtr &graphPtr, unsigned int layerIndex)
A ReshapeDescriptor for the ReshapeLayer.
const armnnSerializer::ConstTensor * ConstTensorRawPtr
uint32_t m_PadBack
Padding back value in the depth dimension.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
const armnnSerializer::NormalizationDescriptor * NormalizationDescriptorPtr
A ComparisonDescriptor for the ComparisonLayer.
static GraphPtr LoadGraphFromBinary(const uint8_t *binaryContent, size_t len)
float m_ScaleX
Center size encoding scale x.
bool m_TransposeWeightMatrix
Enable/disable transpose weight matrix.
uint32_t m_PoolWidth
Pooling width value.
bool m_PeepholeEnabled
Enable/disable peephole.
uint32_t GetNumInputs() const
Get the number of views/inputs.
#define CHECK_TENSOR_PTR(TENSOR_PTR)
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
A Convolution2dDescriptor for the Convolution2dLayer.
float m_Alpha
Alpha value for the normalization equation.
uint32_t m_PadLeft
Padding left value in the width dimension.
const armnnSerializer::QLstmDescriptor * QLstmDescriptorPtr
static armnn::UnidirectionalSequenceLstmDescriptor GetUnidirectionalSequenceLstmDescriptor(UnidirectionalSequenceLstmDescriptorPtr descriptor)
bool m_KeepDims
if true then output shape has no change.
float m_HiddenStateScale
Hidden State quantization scale.
bool m_BiasEnabled
Enable/disable bias.
unsigned int GetNumBytes() const
float m_OutputIntermediateScale
Output intermediate quantization scale.
ResizeMethod m_Method
The Interpolation method to use (Bilinear, NearestNeighbor).
float m_Gamma
Gamma, the scale scalar value applied for the normalized tensor. Defaults to 1.0. ...
float m_Beta
Exponentiation value.
BindingPointInfo GetNetworkInputBindingInfo(unsigned int layerId, const std::string &name) const
Retrieve binding info (layer id and tensor info) for the network input identified by the given layer ...
std::vector< unsigned int > m_Size
Size of the slice in each dimension.
armnn::INetworkPtr CreateNetworkFromBinary(const std::vector< uint8_t > &binaryContent)
Create an input network from binary file contents.
The padding fields don't count and are ignored.
float m_Eps
Value to add to the variance. Used to avoid dividing by zero.
PaddingMethod m_PaddingMethod
The padding method to be used. (Exclude, IgnoreValue).
ArgMinMaxFunction m_Function
Specify if the function is to find Min or Max.
uint32_t m_DetectionsPerClass
Detections per classes, used in Regular NMS.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
void CheckLayers(Graph &graph)
#define ARMNN_LOG(severity)
uint32_t m_PadRight
Padding right value in the width dimension.
uint32_t m_PadTop
Padding top value in the height dimension.
uint32_t m_PadBottom
Padding bottom value in the height dimension.
bool m_BiasEnabled
Enable/disable bias.
A LogicalBinaryDescriptor for the LogicalBinaryLayer.
uint32_t m_PadRight
Padding right value in the width dimension.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
MemoryType GetMemoryArea() const
ReduceOperation m_ReduceOperation
Specifies the reduction operation to execute.
bool m_TimeMajor
Enable/disable time major.
Copyright (c) 2021 ARM Limited and Contributors.
DataLayout m_DataLayout
The data layout to be used (NCDHW, NDHWC).
void IgnoreUnused(Ts &&...)
uint32_t m_PadBottom
Padding bottom value in the height dimension.
uint32_t m_PadFront
Padding front value in the depth dimension.
#define CHECK_GRAPH(GRAPH, LAYERS_INDEX)
uint32_t m_DilationY
Dilation along y axis.
A SpaceToDepthDescriptor for the SpaceToDepthLayer.
const armnnSerializer::SerializedGraph * GraphPtr
std::vector< std::pair< unsigned int, unsigned int > > m_PadList
Specifies the padding values for the input dimension: heightPad{top, bottom} widthPad{left, right}.
uint32_t m_PoolHeight
Pooling height value.
uint32_t m_DilationX
Dilation along x axis.
uint32_t m_DilationY
Dilation factor value for height dimension.
const armnnSerializer::Pooling2dDescriptor * Pooling2dDescriptor
LogicalBinaryOperation m_Operation
Specifies the logical operation to execute.
A BatchToSpaceNdDescriptor for the BatchToSpaceNdLayer.
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
int LayerBindingId
Type of identifiers for bindable layers (inputs, outputs).
armnn::ComparisonOperation ToComparisonOperation(armnnSerializer::ComparisonOperation operation)
virtual void SetTensorInfo(const TensorInfo &tensorInfo)=0
static int32_t GetBindingLayerInfo(const GraphPtr &graphPtr, unsigned int layerIndex)
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
uint32_t m_NumOutputs
Number of output tensors.
NormalizationAlgorithmMethod m_NormMethodType
Normalization method algorithm to use (LocalBrightness, LocalContrast).
void SetShape(const TensorShape &newShape)
A ResizeBilinearDescriptor for the ResizeBilinearLayer.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
uint32_t m_MaxClassesPerDetection
Maximum numbers of classes per detection, used in Fast NMS.
const armnnSerializer::LayerBase * LayerBaseRawPtr
std::vector< unsigned int > m_Axis
Values for the dimensions to reduce.
A StackDescriptor for the StackLayer.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
TensorShape m_TargetShape
Target shape value.
uint32_t m_PoolHeight
Pooling height value.
uint32_t m_PadTop
Padding top value in the height dimension.
uint32_t m_MaxDetections
Maximum numbers of detections.
A PadDescriptor for the PadLayer.
std::vector< TensorRawPtr > TensorRawPtrVector
void Permute(const armnn::TensorShape &dstShape, const armnn::PermutationVector &mappings, const void *src, void *dst, size_t dataTypeSize)
#define CHECK_CONST_TENSOR_SIZE(CONST_TENSOR_SIZE, TENSOR_SIZE)
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
const armnnSerializer::UnidirectionalSequenceLstmDescriptor * UnidirectionalSequenceLstmDescriptorPtr
uint32_t m_PadBack
Padding back value in the depth dimension.
armnn::INetworkPtr CreateNetworkFromBinary(const std::vector< uint8_t > &binaryContent)
Create an input network from binary file contents.
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
bool m_LayerNormEnabled
Enable/disable layer normalization.
const armnnSerializer::LstmDescriptor * LstmDescriptorPtr
armnn::DataLayout ToDataLayout(armnnSerializer::DataLayout dataLayout)
bool CheckShape(const armnn::TensorShape &actual, const std::vector< uint32_t > &expected)
float m_NmsIouThreshold
Intersection over union threshold.
static armnn::LstmDescriptor GetLstmDescriptor(LstmDescriptorPtr lstmDescriptor)
An LstmDescriptor for the LstmLayer.
uint32_t m_PadRight
Padding right value in the width dimension.
uint32_t m_DilationX
Dilation factor value for width dimension.
uint32_t m_PadTop
Padding top value in the height dimension.
std::string FileLine() const
Status SetViewSize(uint32_t view, uint32_t coord, uint32_t value)
Set the size of the views.
#define ARMNN_ASSERT_MSG(COND, MSG)
std::vector< unsigned int > m_Begin
Beginning indices of the slice in each dimension.
bool m_KeepDims
Enable/disable keep dimensions. If true, then the reduced dimensions that are of length 1 are kept...
std::vector< unsigned int > m_BlockShape
Block shape values.
float m_Eps
Epsilon, small scalar value added to variance to avoid dividing by zero. Defaults to 1e-12f...
An output connection slot for a layer.
A L2NormalizationDescriptor for the L2NormalizationLayer.
static TensorRawPtrVector GetInputs(const GraphPtr &graph, unsigned int layerIndex)
An ArgMinMaxDescriptor for ArgMinMaxLayer.
An OriginsDescriptor for the ConcatLayer.
A ReduceDescriptor for the REDUCE operators.
float m_ProjectionClip
Clipping threshold value for the projection.
A FullyConnectedDescriptor for the FullyConnectedLayer.
BindingPointInfo GetNetworkOutputBindingInfo(unsigned int layerId, const std::string &name) const
Retrieve binding info (layer id and tensor info) for the network output identified by the given layer...
bool m_BiasEnabled
Enable/disable bias.
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
float m_InputIntermediateScale
Input intermediate quantization scale.
OutputShapeRounding m_OutputShapeRounding
The rounding method for the output shape. (Floor, Ceiling).
uint32_t m_TargetWidth
Target width value.
A GatherDescriptor for the GatherLayer.
uint32_t m_PadBottom
Padding bottom value in the height dimension.
#define CHECK_VALID_SIZE(ACTUAL,...)
bool m_PeepholeEnabled
Enable/disable peephole.
uint32_t m_NumClasses
Number of classes.
#define CHECKED_NON_NEGATIVE(VALUE)
bool m_HalfPixelCenters
Half Pixel Centers.
std::unique_ptr< IDeserializer, void(*)(IDeserializer *parser)> IDeserializerPtr
armnn::ConstTensor ToConstTensor(ConstTensorRawPtr constTensorPtr)
armnn::ActivationFunction ToActivationFunction(armnnSerializer::ActivationFunction function)
uint32_t m_PadTop
Padding top value in the height dimension.
armnn::UnaryOperation ToUnaryOperation(armnnSerializer::UnaryOperation operation)
#define ARMNN_ASSERT(COND)
A StandInDescriptor for the StandIn layer.
A QLstmDescriptor for the QLstmLayer.
#define CHECK_CONST_TENSOR_PTR(TENSOR_PTR)
bool m_UseRegularNms
Use Regular NMS.
uint32_t m_PadFront
Padding front value in the depth dimension.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
std::vector< unsigned int > m_BlockShape
Block shape value.
PaddingMode
The padding mode controls whether the padding should be filled with constant values (Constant)...
An ActivationDescriptor for the ActivationLayer.
const TensorInfo & GetInfo() const
min(a, max(b, input)) ReLu1 & ReLu6.
uint32_t m_PadLeft
Padding left value in the width dimension.
uint32_t m_TargetHeight
Target height value.
uint32_t m_ActivationFunc
The activation function to use.
A SliceDescriptor for the SliceLayer.
static armnn::Pooling3dDescriptor GetPooling3dDescriptor(Pooling3dDescriptor pooling3dDescriptor, unsigned int layerIndex)
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
A Convolution3dDescriptor for the Convolution3dLayer.
uint32_t m_PadRight
Padding right value in the width dimension.
float m_ClippingThresCell
Clipping threshold value for the cell state.
unsigned int m_BlockSize
Scalar specifying the input block size. It must be >= 1.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
float m_ForgetIntermediateScale
Forget intermediate quantization scale.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
float m_Beta
Beta, the offset scalar value applied for the normalized tensor. Defaults to 1.0. ...
armnn::ResizeMethod ToResizeMethod(armnnSerializer::ResizeMethod method)
armnn::PaddingMode ToPaddingMode(armnnSerializer::PaddingMode paddingMode)
A Pooling3dDescriptor for the Pooling3dLayer.
uint32_t m_StrideZ
Stride value when proceeding through input for the depth dimension.
std::vector< uint32_t > m_vAxis
The indices of the dimensions to reduce.
float m_ScaleH
Center size encoding scale height.
static armnn::Pooling2dDescriptor GetPooling2dDescriptor(Pooling2dDescriptor pooling2dDescriptor, unsigned int layerIndex)
ComparisonOperation m_Operation
Specifies the comparison operation to execute.
A SpaceToBatchNdDescriptor for the SpaceToBatchNdLayer.
DataLayout m_DataLayout
The data layout to be used (NDHWC, NCDHW).
NormalizationAlgorithmChannel m_NormChannelType
Normalization channel algorithm to use (Across, Within).
float m_CellClip
Clipping threshold value for the cell state.
float m_A
Alpha upper bound value used by the activation functions. (BoundedReLu, Linear, TanH, Elu).
uint32_t m_DilationX
Dilation along x axis.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
const armnnSerializer::TensorInfo * TensorRawPtr
bool m_CifgEnabled
Enable/disable cifg (coupled input & forget gate).
armnn::ArgMinMaxFunction ToArgMinMaxFunction(armnnSerializer::ArgMinMaxFunction function)
uint32_t GetNumInputs() const
Get the number of inputs.
uint32_t m_PadLeft
Padding left value in the width dimension.
EmptyOptional is used to initialize the Optional class in case we want to have default value for an O...
bool m_AlignCorners
Aligned corners.
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
int32_t m_Axis
The axis in params to gather indices from.
A ElementwiseUnaryDescriptor for the ElementwiseUnaryLayer.
PoolingAlgorithm m_PoolType
The pooling algorithm to use (Max. Average, L2).
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
uint32_t m_PadLeft
Padding left value in the width dimension.
The padding fields count, but are ignored.
std::vector< std::pair< unsigned int, unsigned int > > m_Crops
The values to crop from the input dimension.
Base class for all ArmNN exceptions so that users can filter to just those.
static std::string GetLayerName(const GraphPtr &graph, unsigned int index)
uint32_t m_PadTop
Padding top value in the height dimension.
unsigned int GetNumDimensions() const
Function that returns the tensor rank.
uint32_t m_PadTop
Padding top value in the height dimension.
bool m_ProjectionEnabled
Enable/disable the projection layer.
Jarret 2009: Local Contrast Normalization.
OutputShapeRounding m_OutputShapeRounding
The rounding method for the output shape. (Floor, Ceiling).
uint32_t m_NumInputs
Number of input tensors.
virtual const IInputSlot & GetInputSlot(unsigned int index) const =0
Get a const input slot handle by slot index.
A MeanDescriptor for the MeanLayer.
void SetConstant(const bool IsConstant=true)
Marks the data corresponding to this tensor info as constant.
static armnn::QLstmDescriptor GetQLstmDescriptor(QLstmDescriptorPtr qLstmDescriptorPtr)
static armnn::TensorInfo OutputShapeOfReshape(const armnn::TensorInfo &inputTensorInfo, const std::vector< uint32_t > &targetDimsIn)
bool m_LayerNormEnabled
Enable/disable layer normalization.
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
armnn::TensorInfo ToTensorInfo(TensorRawPtr tensorPtr)
uint32_t m_PadRight
Padding right value in the width dimension.
A TransposeDescriptor for the TransposeLayer.
A StridedSliceDescriptor for the StridedSliceLayer.
uint32_t m_Axis
Axis to apply channel shuffle operation on.
uint32_t GetNumInputs() const
Get the number of views/inputs.
virtual const IOutputSlot & GetOutputSlot(unsigned int index) const =0
Get the const output slot handle by slot index.
int m_Axis
Axis to reduce across the input tensor.
float m_ScaleY
Center size encoding scale y.
float m_NmsScoreThreshold
NMS score threshold.
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
virtual int Connect(IInputSlot &destination)=0
Krichevsky 2012: Local Brightness Normalization.
A Pooling2dDescriptor for the Pooling2dLayer.
A NormalizationDescriptor for the NormalizationLayer.
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
An InstanceNormalizationDescriptor for InstanceNormalizationLayer.
PaddingMethod m_PaddingMethod
The padding method to be used. (Exclude, IgnoreValue).
A ChannelShuffleDescriptor for the ChannelShuffle operator.
float m_CellIntermediateScale
Cell intermediate quantization scale.
uint32_t m_DilationZ
Dilation along z axis.
float m_B
Beta lower bound value used by the activation functions. (BoundedReLu, Linear, TanH).
armnn::TensorShape Permuted(const armnn::TensorShape &srcShape, const armnn::PermutationVector &mappings)
A SoftmaxDescriptor for the SoftmaxLayer.
float m_Beta
Beta value for the normalization equation.
uint32_t m_StrideZ
Stride value when proceeding through input for the depth dimension.
const armnnSerializer::OriginsDescriptor * GetOriginsDescriptor(const armnnSerializer::SerializedGraph *graph, unsigned int layerIndex)
bool m_CifgEnabled
Enable/disable CIFG (coupled input & forget gate).
uint32_t m_NormSize
Depth radius value.
Status SetViewOriginCoord(uint32_t view, uint32_t coord, uint32_t value)
Set the view origin coordinates.
ActivationFunction m_Function
The activation function to use (Sigmoid, TanH, Linear, ReLu, BoundedReLu, SoftReLu, LeakyReLu, Abs, Sqrt, Square, Elu).
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
A DepthwiseConvolution2dDescriptor for the DepthwiseConvolution2dLayer.
constexpr unsigned int MaxNumOfTensorDimensions
uint32_t m_DilationY
Dilation along y axis.
A FillDescriptor for the FillLayer.
A BatchNormalizationDescriptor for the BatchNormalizationLayer.
uint32_t m_PadLeft
Padding left value in the width dimension.
unsigned int GetNumElements() const
constexpr unsigned int GetDataTypeSize(DataType dataType)
A PermuteDescriptor for the PermuteLayer.
const armnnSerializer::Pooling3dDescriptor * Pooling3dDescriptor
uint32_t m_PadRight
Padding right value in the width dimension.
int32_t m_HiddenStateZeroPoint
Hidden State zero point.
bool m_ConstantWeights
Enable/disable constant weights and biases.