24 #include <fmt/format.h>
32 using namespace armnn;
38 IDeserializer::IDeserializer() : pDeserializerImpl(new DeserializerImpl()){}
40 IDeserializer::~IDeserializer() =
default;
57 armnn::INetworkPtr IDeserializer::CreateNetworkFromBinary(
const std::vector<uint8_t> &binaryContent)
64 return pDeserializerImpl->CreateNetworkFromBinary(binaryContent);
67 BindingPointInfo IDeserializer::GetNetworkInputBindingInfo(
unsigned int layerId,
const std::string &name)
const
69 return pDeserializerImpl->GetNetworkInputBindingInfo(layerId, name);
72 BindingPointInfo IDeserializer::GetNetworkOutputBindingInfo(
unsigned int layerId,
const std::string &name)
const
74 return pDeserializerImpl->GetNetworkOutputBindingInfo(layerId, name);
80 const uint32_t VIRTUAL_LAYER_ID = std::numeric_limits<uint32_t>::max();
82 void CheckGraph(
const GraphPtr& graph,
83 unsigned int layersIndex,
86 if (graph->layers() ==
nullptr)
88 throw ParseException(fmt::format(
"{0} was called with invalid (null) graph. "
89 "Possible reason is that the graph is not yet loaded and Unpack(ed). "
95 else if (layersIndex >= graph->layers()->size())
97 throw ParseException(fmt::format(
"{0} was called with an invalid layers index. layers:{1} at {2}",
104 void CheckLayers(
const GraphPtr& graph,
105 unsigned int layersIndex,
106 unsigned int layerIndex,
109 if (graph->layers() ==
nullptr)
111 throw ParseException(fmt::format(
"{0} was called with invalid (null) graph. "
112 "Possible reason is that the graph is not yet loaded and Unpack(ed). "
118 else if (layersIndex >= graph->layers()->size())
120 throw ParseException(fmt::format(
"{0} was called with an invalid layers index. "
126 else if (layerIndex >= graph->layers()[layersIndex].size()
127 && layerIndex != VIRTUAL_LAYER_ID)
129 throw ParseException(fmt::format(
"{0} was called with an invalid layer index. "
130 "layers:{1} layer:{2} at {3}",
141 if (rawPtr ==
nullptr)
143 throw ParseException(fmt::format(
"{0} was called with a null tensor pointer. at {1}",
152 if (rawPtr ==
nullptr)
154 throw ParseException(fmt::format(
"{0} was called with a null const tensor pointer. at {1}",
160 void CheckConstTensorSize(
const unsigned int constTensorSize,
161 const unsigned int tensorSize,
164 if (constTensorSize != tensorSize)
166 throw ParseException(fmt::format(
"{0} wrong number of components supplied to tensor. at:{1}",
172 #define CHECK_TENSOR_PTR(TENSOR_PTR) \
173 CheckTensorPtr(TENSOR_PTR, CHECK_LOCATION())
175 #define CHECK_CONST_TENSOR_SIZE(CONST_TENSOR_SIZE, TENSOR_SIZE) \
176 CheckConstTensorSize(CONST_TENSOR_SIZE, TENSOR_SIZE, CHECK_LOCATION())
178 #define CHECK_CONST_TENSOR_PTR(TENSOR_PTR) \
179 CheckConstTensorPtr(TENSOR_PTR, CHECK_LOCATION())
181 #define CHECK_LAYERS(GRAPH, LAYERS_INDEX, LAYER_INDEX) \
182 CheckLayers(GRAPH, LAYERS_INDEX, LAYER_INDEX, CHECK_LOCATION())
184 #define CHECK_GRAPH(GRAPH, LAYERS_INDEX) \
185 CheckGraph(GRAPH, LAYERS_INDEX, CHECK_LOCATION())
191 if (actualSize != expected.size())
196 for (
unsigned int i = 0u; i < actualSize; i++)
198 if (actual[i] !=
static_cast<unsigned int>(expected[i]))
207 IDeserializer::DeserializerImpl::DeserializerImpl()
208 : m_Network(nullptr, nullptr),
213 m_ParserFunctions[Layer_AbsLayer] = &DeserializerImpl::ParseAbs;
214 m_ParserFunctions[Layer_ActivationLayer] = &DeserializerImpl::ParseActivation;
215 m_ParserFunctions[Layer_AdditionLayer] = &DeserializerImpl::ParseAdd;
216 m_ParserFunctions[Layer_ArgMinMaxLayer] = &DeserializerImpl::ParseArgMinMax;
217 m_ParserFunctions[Layer_BatchMatMulLayer] = &DeserializerImpl::ParseBatchMatMul;
218 m_ParserFunctions[Layer_BatchToSpaceNdLayer] = &DeserializerImpl::ParseBatchToSpaceNd;
219 m_ParserFunctions[Layer_BatchNormalizationLayer] = &DeserializerImpl::ParseBatchNormalization;
220 m_ParserFunctions[Layer_CastLayer] = &DeserializerImpl::ParseCast;
221 m_ParserFunctions[Layer_ChannelShuffleLayer] = &DeserializerImpl::ParseChannelShuffle;
222 m_ParserFunctions[Layer_ComparisonLayer] = &DeserializerImpl::ParseComparison;
223 m_ParserFunctions[Layer_ConcatLayer] = &DeserializerImpl::ParseConcat;
224 m_ParserFunctions[Layer_ConstantLayer] = &DeserializerImpl::ParseConstant;
225 m_ParserFunctions[Layer_Convolution2dLayer] = &DeserializerImpl::ParseConvolution2d;
226 m_ParserFunctions[Layer_Convolution3dLayer] = &DeserializerImpl::ParseConvolution3d;
227 m_ParserFunctions[Layer_DepthToSpaceLayer] = &DeserializerImpl::ParseDepthToSpace;
228 m_ParserFunctions[Layer_DepthwiseConvolution2dLayer] = &DeserializerImpl::ParseDepthwiseConvolution2d;
229 m_ParserFunctions[Layer_DequantizeLayer] = &DeserializerImpl::ParseDequantize;
230 m_ParserFunctions[Layer_DetectionPostProcessLayer] = &DeserializerImpl::ParseDetectionPostProcess;
231 m_ParserFunctions[Layer_DivisionLayer] = &DeserializerImpl::ParseDivision;
232 m_ParserFunctions[Layer_ElementwiseBinaryLayer] = &DeserializerImpl::ParseElementwiseBinary;
233 m_ParserFunctions[Layer_ElementwiseUnaryLayer] = &DeserializerImpl::ParseElementwiseUnary;
234 m_ParserFunctions[Layer_EqualLayer] = &DeserializerImpl::ParseEqual;
235 m_ParserFunctions[Layer_FullyConnectedLayer] = &DeserializerImpl::ParseFullyConnected;
236 m_ParserFunctions[Layer_FillLayer] = &DeserializerImpl::ParseFill;
237 m_ParserFunctions[Layer_FloorLayer] = &DeserializerImpl::ParseFloor;
238 m_ParserFunctions[Layer_GatherLayer] = &DeserializerImpl::ParseGather;
239 m_ParserFunctions[Layer_GatherNdLayer] = &DeserializerImpl::ParseGatherNd;
240 m_ParserFunctions[Layer_GreaterLayer] = &DeserializerImpl::ParseGreater;
241 m_ParserFunctions[Layer_InstanceNormalizationLayer] = &DeserializerImpl::ParseInstanceNormalization;
242 m_ParserFunctions[Layer_L2NormalizationLayer] = &DeserializerImpl::ParseL2Normalization;
243 m_ParserFunctions[Layer_LogicalBinaryLayer] = &DeserializerImpl::ParseLogicalBinary;
244 m_ParserFunctions[Layer_LogSoftmaxLayer] = &DeserializerImpl::ParseLogSoftmax;
245 m_ParserFunctions[Layer_LstmLayer] = &DeserializerImpl::ParseLstm;
246 m_ParserFunctions[Layer_MaximumLayer] = &DeserializerImpl::ParseMaximum;
247 m_ParserFunctions[Layer_MeanLayer] = &DeserializerImpl::ParseMean;
248 m_ParserFunctions[Layer_MinimumLayer] = &DeserializerImpl::ParseMinimum;
249 m_ParserFunctions[Layer_MergeLayer] = &DeserializerImpl::ParseMerge;
250 m_ParserFunctions[Layer_MergerLayer] = &DeserializerImpl::ParseConcat;
251 m_ParserFunctions[Layer_MultiplicationLayer] = &DeserializerImpl::ParseMultiplication;
252 m_ParserFunctions[Layer_NormalizationLayer] = &DeserializerImpl::ParseNormalization;
253 m_ParserFunctions[Layer_PadLayer] = &DeserializerImpl::ParsePad;
254 m_ParserFunctions[Layer_PermuteLayer] = &DeserializerImpl::ParsePermute;
255 m_ParserFunctions[Layer_Pooling2dLayer] = &DeserializerImpl::ParsePooling2d;
256 m_ParserFunctions[Layer_Pooling3dLayer] = &DeserializerImpl::ParsePooling3d;
257 m_ParserFunctions[Layer_PreluLayer] = &DeserializerImpl::ParsePrelu;
258 m_ParserFunctions[Layer_QLstmLayer] = &DeserializerImpl::ParseQLstm;
259 m_ParserFunctions[Layer_QuantizeLayer] = &DeserializerImpl::ParseQuantize;
260 m_ParserFunctions[Layer_QuantizedLstmLayer] = &DeserializerImpl::ParseQuantizedLstm;
261 m_ParserFunctions[Layer_RankLayer] = &DeserializerImpl::ParseRank;
262 m_ParserFunctions[Layer_ReduceLayer] = &DeserializerImpl::ParseReduce;
263 m_ParserFunctions[Layer_ReshapeLayer] = &DeserializerImpl::ParseReshape;
264 m_ParserFunctions[Layer_ResizeBilinearLayer] = &DeserializerImpl::ParseResizeBilinear;
265 m_ParserFunctions[Layer_ResizeLayer] = &DeserializerImpl::ParseResize;
266 m_ParserFunctions[Layer_ReverseV2Layer] = &DeserializerImpl::ParseReverseV2;
267 m_ParserFunctions[Layer_RsqrtLayer] = &DeserializerImpl::ParseRsqrt;
268 m_ParserFunctions[Layer_ScatterNdLayer] = &DeserializerImpl::ParseScatterNd;
269 m_ParserFunctions[Layer_ShapeLayer] = &DeserializerImpl::ParseShape;
270 m_ParserFunctions[Layer_SliceLayer] = &DeserializerImpl::ParseSlice;
271 m_ParserFunctions[Layer_SoftmaxLayer] = &DeserializerImpl::ParseSoftmax;
272 m_ParserFunctions[Layer_SpaceToBatchNdLayer] = &DeserializerImpl::ParseSpaceToBatchNd;
273 m_ParserFunctions[Layer_SpaceToDepthLayer] = &DeserializerImpl::ParseSpaceToDepth;
274 m_ParserFunctions[Layer_SplitterLayer] = &DeserializerImpl::ParseSplitter;
275 m_ParserFunctions[Layer_StackLayer] = &DeserializerImpl::ParseStack;
276 m_ParserFunctions[Layer_StandInLayer] = &DeserializerImpl::ParseStandIn;
277 m_ParserFunctions[Layer_StridedSliceLayer] = &DeserializerImpl::ParseStridedSlice;
278 m_ParserFunctions[Layer_SubtractionLayer] = &DeserializerImpl::ParseSubtraction;
279 m_ParserFunctions[Layer_SwitchLayer] = &DeserializerImpl::ParseSwitch;
280 m_ParserFunctions[Layer_TileLayer] = &DeserializerImpl::ParseTile;
281 m_ParserFunctions[Layer_TransposeConvolution2dLayer] = &DeserializerImpl::ParseTransposeConvolution2d;
282 m_ParserFunctions[Layer_TransposeLayer] = &DeserializerImpl::ParseTranspose;
283 m_ParserFunctions[Layer_UnidirectionalSequenceLstmLayer] = &DeserializerImpl::ParseUnidirectionalSequenceLstm;
288 auto layerType = graphPtr->layers()->Get(layerIndex)->layer_type();
292 case Layer::Layer_AbsLayer:
293 return graphPtr->layers()->Get(layerIndex)->layer_as_AbsLayer()->base();
294 case Layer::Layer_ActivationLayer:
295 return graphPtr->layers()->Get(layerIndex)->layer_as_ActivationLayer()->base();
296 case Layer::Layer_AdditionLayer:
297 return graphPtr->layers()->Get(layerIndex)->layer_as_AdditionLayer()->base();
298 case Layer::Layer_ArgMinMaxLayer:
299 return graphPtr->layers()->Get(layerIndex)->layer_as_ArgMinMaxLayer()->base();
300 case Layer::Layer_BatchMatMulLayer:
301 return graphPtr->layers()->Get(layerIndex)->layer_as_BatchMatMulLayer()->base();
302 case Layer::Layer_BatchToSpaceNdLayer:
303 return graphPtr->layers()->Get(layerIndex)->layer_as_BatchToSpaceNdLayer()->base();
304 case Layer::Layer_BatchNormalizationLayer:
305 return graphPtr->layers()->Get(layerIndex)->layer_as_BatchNormalizationLayer()->base();
306 case Layer::Layer_CastLayer:
307 return graphPtr->layers()->Get(layerIndex)->layer_as_CastLayer()->base();
308 case Layer::Layer_ChannelShuffleLayer:
309 return graphPtr->layers()->Get(layerIndex)->layer_as_ChannelShuffleLayer()->base();
310 case Layer::Layer_ComparisonLayer:
311 return graphPtr->layers()->Get(layerIndex)->layer_as_ComparisonLayer()->base();
312 case Layer::Layer_ConcatLayer:
313 return graphPtr->layers()->Get(layerIndex)->layer_as_ConcatLayer()->base();
314 case Layer::Layer_ConstantLayer:
315 return graphPtr->layers()->Get(layerIndex)->layer_as_ConstantLayer()->base();
316 case Layer::Layer_Convolution2dLayer:
317 return graphPtr->layers()->Get(layerIndex)->layer_as_Convolution2dLayer()->base();
318 case Layer::Layer_Convolution3dLayer:
319 return graphPtr->layers()->Get(layerIndex)->layer_as_Convolution3dLayer()->base();
320 case Layer::Layer_DepthToSpaceLayer:
321 return graphPtr->layers()->Get(layerIndex)->layer_as_DepthToSpaceLayer()->base();
322 case Layer::Layer_DepthwiseConvolution2dLayer:
323 return graphPtr->layers()->Get(layerIndex)->layer_as_DepthwiseConvolution2dLayer()->base();
324 case Layer::Layer_DequantizeLayer:
325 return graphPtr->layers()->Get(layerIndex)->layer_as_DequantizeLayer()->base();
326 case Layer::Layer_DetectionPostProcessLayer:
327 return graphPtr->layers()->Get(layerIndex)->layer_as_DetectionPostProcessLayer()->base();
328 case Layer::Layer_DivisionLayer:
329 return graphPtr->layers()->Get(layerIndex)->layer_as_DivisionLayer()->base();
330 case Layer::Layer_EqualLayer:
331 return graphPtr->layers()->Get(layerIndex)->layer_as_EqualLayer()->base();
332 case Layer::Layer_ElementwiseBinaryLayer:
333 return graphPtr->layers()->Get(layerIndex)->layer_as_ElementwiseBinaryLayer()->base();
334 case Layer::Layer_ElementwiseUnaryLayer:
335 return graphPtr->layers()->Get(layerIndex)->layer_as_ElementwiseUnaryLayer()->base();
336 case Layer::Layer_FullyConnectedLayer:
337 return graphPtr->layers()->Get(layerIndex)->layer_as_FullyConnectedLayer()->base();
338 case Layer::Layer_FillLayer:
339 return graphPtr->layers()->Get(layerIndex)->layer_as_FillLayer()->base();
340 case Layer::Layer_FloorLayer:
341 return graphPtr->layers()->Get(layerIndex)->layer_as_FloorLayer()->base();
342 case Layer::Layer_GatherLayer:
343 return graphPtr->layers()->Get(layerIndex)->layer_as_GatherLayer()->base();
344 case Layer::Layer_GatherNdLayer:
345 return graphPtr->layers()->Get(layerIndex)->layer_as_GatherNdLayer()->base();
346 case Layer::Layer_GreaterLayer:
347 return graphPtr->layers()->Get(layerIndex)->layer_as_GreaterLayer()->base();
348 case Layer::Layer_InputLayer:
349 return graphPtr->layers()->Get(layerIndex)->layer_as_InputLayer()->base()->base();
350 case Layer::Layer_InstanceNormalizationLayer:
351 return graphPtr->layers()->Get(layerIndex)->layer_as_InstanceNormalizationLayer()->base();
352 case Layer::Layer_L2NormalizationLayer:
353 return graphPtr->layers()->Get(layerIndex)->layer_as_L2NormalizationLayer()->base();
354 case Layer::Layer_LogicalBinaryLayer:
355 return graphPtr->layers()->Get(layerIndex)->layer_as_LogicalBinaryLayer()->base();
356 case Layer::Layer_LogSoftmaxLayer:
357 return graphPtr->layers()->Get(layerIndex)->layer_as_LogSoftmaxLayer()->base();
358 case Layer::Layer_LstmLayer:
359 return graphPtr->layers()->Get(layerIndex)->layer_as_LstmLayer()->base();
360 case Layer::Layer_MeanLayer:
361 return graphPtr->layers()->Get(layerIndex)->layer_as_MeanLayer()->base();
362 case Layer::Layer_MinimumLayer:
363 return graphPtr->layers()->Get(layerIndex)->layer_as_MinimumLayer()->base();
364 case Layer::Layer_MaximumLayer:
365 return graphPtr->layers()->Get(layerIndex)->layer_as_MaximumLayer()->base();
366 case Layer::Layer_MergeLayer:
367 return graphPtr->layers()->Get(layerIndex)->layer_as_MergeLayer()->base();
368 case Layer::Layer_MergerLayer:
369 return graphPtr->layers()->Get(layerIndex)->layer_as_MergerLayer()->base();
370 case Layer::Layer_MultiplicationLayer:
371 return graphPtr->layers()->Get(layerIndex)->layer_as_MultiplicationLayer()->base();
372 case Layer::Layer_NormalizationLayer:
373 return graphPtr->layers()->Get(layerIndex)->layer_as_NormalizationLayer()->base();
374 case Layer::Layer_OutputLayer:
375 return graphPtr->layers()->Get(layerIndex)->layer_as_OutputLayer()->base()->base();
376 case Layer::Layer_PadLayer:
377 return graphPtr->layers()->Get(layerIndex)->layer_as_PadLayer()->base();
378 case Layer::Layer_PermuteLayer:
379 return graphPtr->layers()->Get(layerIndex)->layer_as_PermuteLayer()->base();
380 case Layer::Layer_Pooling2dLayer:
381 return graphPtr->layers()->Get(layerIndex)->layer_as_Pooling2dLayer()->base();
382 case Layer::Layer_Pooling3dLayer:
383 return graphPtr->layers()->Get(layerIndex)->layer_as_Pooling3dLayer()->base();
384 case Layer::Layer_PreluLayer:
385 return graphPtr->layers()->Get(layerIndex)->layer_as_PreluLayer()->base();
386 case Layer::Layer_QLstmLayer:
387 return graphPtr->layers()->Get(layerIndex)->layer_as_QLstmLayer()->base();
388 case Layer::Layer_QuantizeLayer:
389 return graphPtr->layers()->Get(layerIndex)->layer_as_QuantizeLayer()->base();
390 case Layer::Layer_QuantizedLstmLayer:
391 return graphPtr->layers()->Get(layerIndex)->layer_as_QuantizedLstmLayer()->base();
392 case Layer::Layer_RankLayer:
393 return graphPtr->layers()->Get(layerIndex)->layer_as_RankLayer()->base();
394 case Layer::Layer_ReduceLayer:
395 return graphPtr->layers()->Get(layerIndex)->layer_as_ReduceLayer()->base();
396 case Layer::Layer_ReshapeLayer:
397 return graphPtr->layers()->Get(layerIndex)->layer_as_ReshapeLayer()->base();
398 case Layer::Layer_ResizeBilinearLayer:
399 return graphPtr->layers()->Get(layerIndex)->layer_as_ResizeBilinearLayer()->base();
400 case Layer::Layer_ResizeLayer:
401 return graphPtr->layers()->Get(layerIndex)->layer_as_ResizeLayer()->base();
402 case Layer::Layer_ReverseV2Layer:
403 return graphPtr->layers()->Get(layerIndex)->layer_as_ReverseV2Layer()->base();
404 case Layer::Layer_RsqrtLayer:
405 return graphPtr->layers()->Get(layerIndex)->layer_as_RsqrtLayer()->base();
406 case Layer::Layer_ScatterNdLayer:
407 return graphPtr->layers()->Get(layerIndex)->layer_as_ScatterNdLayer()->base();
408 case Layer::Layer_ShapeLayer:
409 return graphPtr->layers()->Get(layerIndex)->layer_as_ShapeLayer()->base();
410 case Layer::Layer_SliceLayer:
411 return graphPtr->layers()->Get(layerIndex)->layer_as_SliceLayer()->base();
412 case Layer::Layer_SoftmaxLayer:
413 return graphPtr->layers()->Get(layerIndex)->layer_as_SoftmaxLayer()->base();
414 case Layer::Layer_SpaceToBatchNdLayer:
415 return graphPtr->layers()->Get(layerIndex)->layer_as_SpaceToBatchNdLayer()->base();
416 case Layer::Layer_SpaceToDepthLayer:
417 return graphPtr->layers()->Get(layerIndex)->layer_as_SpaceToDepthLayer()->base();
418 case Layer::Layer_SplitterLayer:
419 return graphPtr->layers()->Get(layerIndex)->layer_as_SplitterLayer()->base();
420 case Layer::Layer_StackLayer:
421 return graphPtr->layers()->Get(layerIndex)->layer_as_StackLayer()->base();
422 case Layer::Layer_StandInLayer:
423 return graphPtr->layers()->Get(layerIndex)->layer_as_StandInLayer()->base();
424 case Layer::Layer_StridedSliceLayer:
425 return graphPtr->layers()->Get(layerIndex)->layer_as_StridedSliceLayer()->base();
426 case Layer::Layer_SubtractionLayer:
427 return graphPtr->layers()->Get(layerIndex)->layer_as_SubtractionLayer()->base();
428 case Layer::Layer_SwitchLayer:
429 return graphPtr->layers()->Get(layerIndex)->layer_as_SwitchLayer()->base();
430 case Layer::Layer_TileLayer:
431 return graphPtr->layers()->Get(layerIndex)->layer_as_TileLayer()->base();
432 case Layer::Layer_TransposeConvolution2dLayer:
433 return graphPtr->layers()->Get(layerIndex)->layer_as_TransposeConvolution2dLayer()->base();
434 case Layer::Layer_TransposeLayer:
435 return graphPtr->layers()->Get(layerIndex)->layer_as_TransposeLayer()->base();
436 case Layer::Layer_UnidirectionalSequenceLstmLayer:
437 return graphPtr->layers()->Get(layerIndex)->layer_as_UnidirectionalSequenceLstmLayer()->base();
438 case Layer::Layer_NONE:
440 throw ParseException(fmt::format(
"Layer type {} not recognized", layerType));
446 auto layer = GetBaseLayer(graph, index);
448 return layer->layerName()->str();
453 auto layerType = graphPtr->layers()->Get(layerIndex)->layer_type();
455 if (layerType == Layer::Layer_InputLayer)
457 return graphPtr->layers()->Get(layerIndex)->layer_as_InputLayer()->base()->layerBindingId();
459 else if ( layerType == Layer::Layer_OutputLayer )
461 return graphPtr->layers()->Get(layerIndex)->layer_as_OutputLayer()->base()->layerBindingId();
470 case armnnSerializer::DataLayout::DataLayout_NHWC:
472 case armnnSerializer::DataLayout::DataLayout_NDHWC:
474 case armnnSerializer::DataLayout::DataLayout_NCDHW:
476 case armnnSerializer::DataLayout::DataLayout_NCHW:
486 case armnnSerializer::ActivationFunction_Sigmoid:
488 case armnnSerializer::ActivationFunction_TanH:
490 case armnnSerializer::ActivationFunction_Linear:
492 case armnnSerializer::ActivationFunction_ReLu:
494 case armnnSerializer::ActivationFunction_BoundedReLu:
496 case armnnSerializer::ActivationFunction_LeakyReLu:
498 case armnnSerializer::ActivationFunction_Abs:
500 case armnnSerializer::ActivationFunction_Sqrt:
502 case armnnSerializer::ActivationFunction_Square:
504 case armnnSerializer::ActivationFunction_Elu:
506 case armnnSerializer::ActivationFunction_HardSwish:
508 case armnnSerializer::ActivationFunction_Gelu:
519 case armnnSerializer::ArgMinMaxFunction::ArgMinMaxFunction_Max:
521 case armnnSerializer::ArgMinMaxFunction::ArgMinMaxFunction_Min:
531 case armnnSerializer::ScatterNdFunction_Update:
533 case armnnSerializer::ScatterNdFunction_Add:
535 case armnnSerializer::ScatterNdFunction_Sub:
537 case armnnSerializer::ScatterNdFunction_Max:
539 case armnnSerializer::ScatterNdFunction_Min:
550 case armnnSerializer::ComparisonOperation::ComparisonOperation_Equal:
552 case armnnSerializer::ComparisonOperation::ComparisonOperation_Greater:
554 case armnnSerializer::ComparisonOperation::ComparisonOperation_GreaterOrEqual:
556 case armnnSerializer::ComparisonOperation::ComparisonOperation_Less:
558 case armnnSerializer::ComparisonOperation::ComparisonOperation_LessOrEqual:
560 case armnnSerializer::ComparisonOperation::ComparisonOperation_NotEqual:
570 case armnnSerializer::ReduceOperation::ReduceOperation_Sum:
572 case armnnSerializer::ReduceOperation::ReduceOperation_Max:
574 case armnnSerializer::ReduceOperation::ReduceOperation_Mean:
576 case armnnSerializer::ReduceOperation::ReduceOperation_Min:
578 case armnnSerializer::ReduceOperation::ReduceOperation_Prod:
589 case armnnSerializer::LogicalBinaryOperation::LogicalBinaryOperation_LogicalAnd:
591 case armnnSerializer::LogicalBinaryOperation::LogicalBinaryOperation_LogicalOr:
602 case armnnSerializer::BinaryOperation::BinaryOperation_Add:
604 case armnnSerializer::BinaryOperation::BinaryOperation_Div:
606 case armnnSerializer::BinaryOperation::BinaryOperation_FloorDiv:
608 case armnnSerializer::BinaryOperation::BinaryOperation_Maximum:
610 case armnnSerializer::BinaryOperation::BinaryOperation_Minimum:
612 case armnnSerializer::BinaryOperation::BinaryOperation_Mul:
614 case armnnSerializer::BinaryOperation::BinaryOperation_Sub:
616 case armnnSerializer::BinaryOperation::BinaryOperation_SqDiff:
618 case armnnSerializer::BinaryOperation::BinaryOperation_Power:
629 case armnnSerializer::UnaryOperation::UnaryOperation_Abs:
631 case armnnSerializer::UnaryOperation::UnaryOperation_Ceil:
633 case armnnSerializer::UnaryOperation::UnaryOperation_Rsqrt:
635 case armnnSerializer::UnaryOperation::UnaryOperation_Sqrt:
637 case armnnSerializer::UnaryOperation::UnaryOperation_Exp:
639 case armnnSerializer::UnaryOperation::UnaryOperation_Neg:
641 case armnnSerializer::UnaryOperation::UnaryOperation_LogicalNot:
643 case armnnSerializer::UnaryOperation::UnaryOperation_Log:
645 case armnnSerializer::UnaryOperation::UnaryOperation_Sin:
656 case armnnSerializer::PaddingMode::PaddingMode_Reflect:
658 case armnnSerializer::PaddingMode::PaddingMode_Symmetric:
669 case armnnSerializer::ResizeMethod_NearestNeighbor:
671 case armnnSerializer::ResizeMethod_Bilinear:
683 switch (tensorPtr->dataType())
685 case DataType_QAsymmS8:
688 case DataType_QSymmS8:
691 case DataType_QuantisedAsymm8:
692 case DataType_QAsymmU8:
695 case DataType_QSymmS16:
696 case DataType_QuantisedSymm16:
699 case DataType_Signed32:
702 case DataType_Signed64:
705 case DataType_Float32:
708 case DataType_Float16:
711 case DataType_Boolean:
717 throw ParseException(fmt::format(
"Unsupported data type {0} = {1}. {2}",
718 tensorPtr->dataType(),
719 EnumNameDataType(tensorPtr->dataType()),
724 float quantizationScale = tensorPtr->quantizationScale();
725 int32_t quantizationOffset = tensorPtr->quantizationOffset();
727 if (tensorPtr->dimensionality() ==
static_cast<unsigned int>(Dimensionality::Scalar))
734 else if (tensorPtr->dimensionality() ==
static_cast<unsigned int>(Dimensionality::NotSpecified))
743 auto dimensions = tensorPtr->dimensions();
744 unsigned int size = dimensions->size();
745 std::vector<unsigned int> outputDims(dimensions->begin(), dimensions->begin() + size);
750 if (tensorPtr->dimensionSpecificity() !=
nullptr)
752 auto dimensionSpecificity = tensorPtr->dimensionSpecificity();
753 size = dimensionSpecificity->size();
754 for (
unsigned int i = 0; i < size; ++i)
756 dimensionsSpecificity[i] = dimensionSpecificity->Get(i);
760 TensorShape shape(size, outputDims.data(), dimensionsSpecificity);
762 auto quantizationScales = tensorPtr->quantizationScales();
763 if (quantizationScales)
765 unsigned int quantizationScalesSize = quantizationScales->size();
766 std::vector<float> scales(quantizationScales->begin(), quantizationScales->begin() + quantizationScalesSize);
767 unsigned int quantizationDim = tensorPtr->quantizationDim();
790 switch (constTensorPtr->data_type())
792 case ConstTensorData_ByteData:
794 auto byteData = constTensorPtr->data_as_ByteData()->data();
798 case ConstTensorData_ShortData:
800 auto shortData = constTensorPtr->data_as_ShortData()->data();
804 case ConstTensorData_IntData:
806 auto intData = constTensorPtr->data_as_IntData()->data();
810 case ConstTensorData_LongData:
812 auto longData = constTensorPtr->data_as_LongData()->data();
819 throw ParseException(fmt::format(
"Unsupported data type {0} = {1}. {2}",
820 constTensorPtr->data_type(),
821 EnumNameConstTensorData(constTensorPtr->data_type()),
830 auto layer = GetBaseLayer(graphPtr, layerIndex);
831 const auto& numInputs = layer->inputSlots()->size();
835 for (
unsigned int i=0; i<numInputs; ++i)
838 (layer->inputSlots()->Get(i)->connection()->sourceLayerIndex()));
839 result[i] = GetBaseLayer(graphPtr, inputId)->outputSlots()->Get(0)->tensorInfo();
847 auto layer = GetBaseLayer(graphPtr, layerIndex);
848 const auto& numOutputs = layer->outputSlots()->size();
852 for (
unsigned int i=0; i<numOutputs; ++i)
854 result[i] = layer->outputSlots()->Get(i)->tensorInfo();
859 void IDeserializer::DeserializerImpl::ParseUnsupportedLayer(
GraphPtr graph,
unsigned int layerIndex)
862 const auto layerName = GetBaseLayer(graph, layerIndex)->layerName()->c_str();
863 throw ParseException(fmt::format(
"Layer not supported. layerIndex: {0} "
864 "layerName: {1} / {2}",
870 void IDeserializer::DeserializerImpl::ResetParser()
873 m_InputBindings.clear();
874 m_OutputBindings.clear();
881 GraphPtr graph = LoadGraphFromBinary(binaryContent.data(), binaryContent.size());
882 return CreateNetworkFromGraph(graph);
888 if (binaryContent.fail()) {
892 binaryContent.seekg(0, std::ios::end);
893 const std::streamoff size = binaryContent.tellg();
894 std::vector<char> content(
static_cast<size_t>(size));
895 binaryContent.seekg(0);
896 binaryContent.read(content.data(),
static_cast<std::streamsize
>(size));
897 GraphPtr graph = LoadGraphFromBinary(
reinterpret_cast<uint8_t*
>(content.data()),
static_cast<size_t>(size));
898 return CreateNetworkFromGraph(graph);
903 if (binaryContent ==
nullptr)
908 flatbuffers::Verifier verifier(binaryContent, len);
909 if (verifier.VerifyBuffer<SerializedGraph>() ==
false)
911 throw ParseException(fmt::format(
"Buffer doesn't conform to the expected Armnn "
912 "flatbuffers format. size:{0} {1}",
916 return GetSerializedGraph(binaryContent);
921 if (graph ==
nullptr)
925 m_Network = INetwork::Create();
926 unsigned int layerIndex = 0;
927 for (AnyLayer
const* layer : *graph->layers())
929 if (layer->layer_type() != Layer_InputLayer &&
930 layer->layer_type() != Layer_OutputLayer)
933 auto& parserFunction = m_ParserFunctions[layer->layer_type()];
934 (this->*parserFunction)(graph, layerIndex);
939 SetupInputLayers(graph);
940 SetupOutputLayers(graph);
943 for (
auto&& graphIt : m_GraphConnections)
945 Connections& connections = graphIt.second;
946 for (
auto&& outputIt : connections.outputSlots)
948 const unsigned int outputSlotIndex = outputIt.first;
950 if (connections.inputSlots.find(outputSlotIndex) != connections.inputSlots.end())
952 for (
IInputSlot* inputSlot : connections.inputSlots[outputSlotIndex])
954 outputSlot->
Connect(*inputSlot);
960 return std::move(m_Network);
964 const std::string& name)
const
967 for (
auto inputBinding : m_InputBindings)
969 if (inputBinding.first == name)
971 return inputBinding.second;
974 throw ParseException(fmt::format(
"No input binding found for layer:{0} / {1}",
980 const std::string& name)
const
983 for (
auto outputBinding : m_OutputBindings)
985 if (outputBinding.first == name)
987 return outputBinding.second;
990 throw ParseException(fmt::format(
"No output binding found for layer:{0} / {1}",
995 unsigned int IDeserializer::DeserializerImpl::GetInputLayerInVector(
GraphPtr graph,
int targetId)
997 for (
unsigned int i = 0; i < graph->layers()->size(); i++)
999 auto layer = graph->layers()->Get(i);
1000 if (layer->layer_type() == Layer::Layer_InputLayer)
1002 auto layerBindingId = layer->layer_as_InputLayer()->base()->layerBindingId();
1003 if (layerBindingId == targetId)
1009 throw ParseException(
"Input layer with given layerBindingId not found");
1012 unsigned int IDeserializer::DeserializerImpl::GetOutputLayerInVector(
GraphPtr graph,
int targetId)
1014 for (
unsigned int i = 0; i < graph->layers()->size(); i++)
1016 auto layer = graph->layers()->Get(i);
1017 if (layer->layer_type() == Layer::Layer_OutputLayer)
1019 auto layerBindingId = layer->layer_as_OutputLayer()->base()->layerBindingId();
1020 if (layerBindingId == targetId)
1026 throw ParseException(
"Output layer with given layerBindingId not found");
1029 unsigned int IDeserializer::DeserializerImpl::GetLayerIndexInVector(
GraphPtr graph,
unsigned int targetIndex)
1031 for (
unsigned int i = 0; i < graph->layers()->size(); i++)
1034 if (layer->index() == targetIndex)
1042 IDeserializer::DeserializerImpl::FeatureVersions IDeserializer::DeserializerImpl::GetFeatureVersions(
GraphPtr graph)
1044 IDeserializer::DeserializerImpl::FeatureVersions versions;
1046 if (graph->featureVersions())
1048 versions.m_BindingIdScheme = graph->featureVersions()->bindingIdsScheme();
1049 versions.m_WeightsLayoutScheme = graph->featureVersions()->weightsLayoutScheme();
1050 versions.m_ConstTensorsAsInputs = graph->featureVersions()->constantTensorsAsInputs();
1056 void IDeserializer::DeserializerImpl::SetupInputLayers(
GraphPtr graph)
1059 const unsigned int numInputs = graph->inputIds()->size();
1060 m_InputBindings.clear();
1061 m_InputBindings.reserve(numInputs);
1063 for (
unsigned int i = 0; i < numInputs; i++)
1065 unsigned int inputLayerIndex = 0xFFFFFFFF;
1066 if (GetFeatureVersions(graph).m_BindingIdScheme == 0)
1068 const unsigned int inputId = armnn::numeric_cast<unsigned int>(graph->inputIds()->Get(i));
1069 inputLayerIndex = GetLayerIndexInVector(graph, inputId);
1073 const int inputId = graph->inputIds()->Get(i);
1074 inputLayerIndex = GetInputLayerInVector(graph, inputId);
1080 LayerBindingId bindingId = GetBindingLayerInfo(graph, inputLayerIndex);
1081 if (baseLayer->layerName()->c_str() ==
nullptr)
1083 throw ParseException(fmt::format(
"Input with layer index [{0}] has no name", inputLayerIndex));
1087 m_Network->AddInputLayer(bindingId, baseLayer->layerName()->c_str());
1091 RegisterOutputSlots(graph, inputLayerIndex, inputLayer);
1094 m_InputBindings.push_back(std::make_pair(baseLayer->layerName()->c_str(), bindingInfo));
1098 void IDeserializer::DeserializerImpl::SetupOutputLayers(
GraphPtr graph)
1101 const unsigned int numOutputs = graph->outputIds()->size();
1102 m_OutputBindings.clear();
1103 m_OutputBindings.reserve(numOutputs);
1105 for (
unsigned int i = 0; i < numOutputs; i++)
1107 unsigned int outputLayerIndex = 0xFFFFFFFF;
1108 if (GetFeatureVersions(graph).m_BindingIdScheme == 0)
1110 const unsigned int outputId = armnn::numeric_cast<unsigned int>(graph->outputIds()->Get(i));
1111 outputLayerIndex = GetLayerIndexInVector(graph, outputId);
1115 const int outputId = graph->outputIds()->Get(i);
1116 outputLayerIndex = GetOutputLayerInVector(graph, outputId);
1122 LayerBindingId bindingId = GetBindingLayerInfo(graph, outputLayerIndex);
1123 if (baseLayer->layerName()->c_str() ==
nullptr)
1125 throw ParseException(fmt::format(
"Output with layer index [{0}] has no name", outputLayerIndex));
1129 m_Network->AddOutputLayer(bindingId, baseLayer->layerName()->c_str());
1131 RegisterInputSlots(graph, outputLayerIndex, outputLayer);
1132 unsigned int sourceLayerIndex =
1133 GetLayerIndexInVector(graph, baseLayer->inputSlots()->Get(0)->connection()->sourceLayerIndex());
1134 unsigned int outputSlotIndex =
1135 GetLayerIndexInVector(graph, baseLayer->inputSlots()->Get(0)->connection()->outputSlotIndex());
1136 LayerBaseRawPtr sourceBaseLayer = GetBaseLayer(graph, sourceLayerIndex);
1138 sourceBaseLayer->outputSlots()->Get(outputSlotIndex)->tensorInfo());
1140 m_OutputBindings.push_back(std::make_pair(baseLayer->layerName()->c_str(), bindingInfo));
1144 void IDeserializer::DeserializerImpl::RegisterOutputSlots(
GraphPtr graph,
1145 uint32_t layerIndex,
1148 if (layer ==
nullptr)
1151 "RegisterOutputSlots: pointer to layer with index [{0}] is null", layerIndex));
1157 throw ParseException(fmt::format(
"The number of outputslots ({0}) does not match the number expected ({1})"
1158 " for layer index: {2} {3}",
1159 baseLayer->outputSlots()->size(),
1167 const unsigned int slotIndex = baseLayer->outputSlots()->Get(i)->index();
1170 RegisterOutputSlotOfConnection(baseLayer->index(), slotIndex, outputSlot);
1174 void IDeserializer::DeserializerImpl::RegisterInputSlots(
GraphPtr graph,
1175 uint32_t layerIndex,
1177 std::vector<unsigned int> ignoreSlots)
1179 if (layer ==
nullptr)
1182 "RegisterInputSlots: pointer to layer with index [{0}] is null", layerIndex));
1187 if (baseLayer->inputSlots()->size() != (layer->
GetNumInputSlots() - ignoreSlots.size()))
1189 throw ParseException(fmt::format(
"The number of inputslots ({0}) does not match the number expected ({1})"
1190 " for layer index:{2} {3}",
1191 baseLayer->inputSlots()->size(),
1200 if (std::find(ignoreSlots.begin(), ignoreSlots.end(), i) == ignoreSlots.end())
1202 auto fbInputSlot = baseLayer->inputSlots()->Get(i);
1203 auto fbConnection = fbInputSlot->connection();
1207 if (fbInputSlot->isOverridden())
1212 RegisterInputSlotOfConnection(fbConnection->sourceLayerIndex(), fbConnection->outputSlotIndex(), inputSlot);
1217 void IDeserializer::DeserializerImpl::RegisterInputSlotOfConnection(uint32_t sourceLayerIndex,
1218 uint32_t outputSlotIndex,
1221 if (m_GraphConnections.find(sourceLayerIndex) == m_GraphConnections.end())
1223 m_GraphConnections[sourceLayerIndex] = Connections();
1226 Connections& connections = m_GraphConnections[sourceLayerIndex];
1227 if (connections.inputSlots.find(outputSlotIndex) == connections.inputSlots.end())
1229 connections.inputSlots[outputSlotIndex] = {inputSlot};
1233 connections.inputSlots[outputSlotIndex].push_back(inputSlot);
1237 void IDeserializer::DeserializerImpl::RegisterOutputSlotOfConnection(uint32_t sourceLayerIndex,
1238 uint32_t outputSlotIndex,
1241 if (m_GraphConnections.find(sourceLayerIndex) == m_GraphConnections.end())
1243 m_GraphConnections[sourceLayerIndex] = Connections();
1246 Connections& connections = m_GraphConnections[sourceLayerIndex];
1247 if (connections.outputSlots.find(outputSlotIndex) != connections.outputSlots.end())
1252 connections.outputSlots[outputSlotIndex] = outputSlot;
1255 void IDeserializer::DeserializerImpl::ParseAbs(
GraphPtr graph,
unsigned int layerIndex)
1258 auto inputs = GetInputs(graph, layerIndex);
1262 auto outputs = GetOutputs(graph, layerIndex);
1265 auto layerName = GetLayerName(graph, layerIndex);
1268 IConnectableLayer* layer = m_Network->AddElementwiseUnaryLayer(descriptor, layerName.c_str());
1272 RegisterInputSlots(graph, layerIndex, layer);
1273 RegisterOutputSlots(graph, layerIndex, layer);
1276 void IDeserializer::DeserializerImpl::ParseActivation(
GraphPtr graph,
unsigned int layerIndex)
1279 auto inputs = GetInputs(graph, layerIndex);
1283 auto outputs = GetOutputs(graph, layerIndex);
1286 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_ActivationLayer();
1287 auto layerName = GetLayerName(graph, layerIndex);
1288 auto serializerDescriptor = serializerLayer->descriptor();
1292 descriptor.
m_A = serializerDescriptor->a();
1293 descriptor.
m_B = serializerDescriptor->b();
1300 RegisterInputSlots(graph, layerIndex, layer);
1301 RegisterOutputSlots(graph, layerIndex, layer);
1304 void IDeserializer::DeserializerImpl::ParseAdd(
GraphPtr graph,
unsigned int layerIndex)
1307 auto inputs = GetInputs(graph, layerIndex);
1311 auto outputs = GetOutputs(graph, layerIndex);
1314 auto layerName = GetLayerName(graph, layerIndex);
1316 IConnectableLayer* layer = m_Network->AddElementwiseBinaryLayer(descriptor, layerName.c_str());
1321 RegisterInputSlots(graph, layerIndex, layer);
1322 RegisterOutputSlots(graph, layerIndex, layer);
1325 void IDeserializer::DeserializerImpl::ParseArgMinMax(
GraphPtr graph,
unsigned int layerIndex)
1328 auto inputs = GetInputs(graph, layerIndex);
1332 auto outputs = GetOutputs(graph, layerIndex);
1335 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_ArgMinMaxLayer();
1336 auto serializerDescriptor = serializerLayer->descriptor();
1340 descriptor.
m_Axis = serializerDescriptor->axis();
1341 auto layerName = GetLayerName(graph, layerIndex);
1342 IConnectableLayer* layer = m_Network->AddArgMinMaxLayer(descriptor, layerName.c_str());
1347 RegisterInputSlots(graph, layerIndex, layer);
1348 RegisterOutputSlots(graph, layerIndex, layer);
1351 void IDeserializer::DeserializerImpl::ParseBatchMatMul(
GraphPtr graph,
unsigned int layerIndex)
1355 auto inputs = GetInputs(graph, layerIndex);
1359 auto outputs = GetOutputs(graph, layerIndex);
1362 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_BatchMatMulLayer();
1363 auto serializerDescriptor = serializerLayer->descriptor();
1366 serializerDescriptor->transposeY(),
1367 serializerDescriptor->adjointX(),
1368 serializerDescriptor->adjointY(),
1372 auto layerName = GetLayerName(graph, layerIndex);
1373 IConnectableLayer* layer = m_Network->AddBatchMatMulLayer(descriptor, layerName.c_str());
1378 RegisterInputSlots(graph, layerIndex, layer);
1379 RegisterOutputSlots(graph, layerIndex, layer);
1382 void IDeserializer::DeserializerImpl::ParseBatchToSpaceNd(
GraphPtr graph,
unsigned int layerIndex)
1392 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_BatchToSpaceNdLayer()->descriptor();
1393 auto flatBufferCrops = flatBufferDescriptor->crops();
1394 auto flatBufferBlockShape = flatBufferDescriptor->blockShape();
1396 if (flatBufferCrops->size() % 2 != 0)
1401 std::vector<std::pair<unsigned int, unsigned int>> crops;
1402 crops.reserve(flatBufferCrops->size() / 2);
1403 for (
unsigned int i = 0; i < flatBufferCrops->size() - 1; i += 2)
1405 crops.emplace_back(flatBufferCrops->Get(i), flatBufferCrops->Get(i+1));
1411 std::vector<unsigned int>(flatBufferBlockShape->begin(), flatBufferBlockShape->end());
1414 auto layerName = GetLayerName(graph, layerIndex);
1415 IConnectableLayer* layer = m_Network->AddBatchToSpaceNdLayer(descriptor, layerName.c_str());
1420 RegisterInputSlots(graph, layerIndex, layer);
1421 RegisterOutputSlots(graph, layerIndex, layer);
1424 void IDeserializer::DeserializerImpl::ParseBatchNormalization(
GraphPtr graph,
unsigned int layerIndex)
1428 auto inputs = GetInputs(graph, layerIndex);
1431 auto outputs = GetOutputs(graph, layerIndex);
1435 auto layerName = GetLayerName(graph, layerIndex);
1437 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_BatchNormalizationLayer();
1438 auto serializerDescriptor = serializerLayer->descriptor();
1441 descriptor.
m_Eps = serializerDescriptor->eps();
1457 RegisterInputSlots(graph, layerIndex, layer);
1458 RegisterOutputSlots(graph, layerIndex, layer);
1461 void IDeserializer::DeserializerImpl::ParseCast(
GraphPtr graph,
unsigned int layerIndex)
1471 auto layerName = GetLayerName(graph, layerIndex);
1478 RegisterInputSlots(graph, layerIndex, layer);
1479 RegisterOutputSlots(graph, layerIndex, layer);
1482 void IDeserializer::DeserializerImpl::ParseConstant(
GraphPtr graph,
unsigned int layerIndex)
1487 auto outputs = GetOutputs(graph, layerIndex);
1490 auto layerName = GetLayerName(graph, layerIndex);
1492 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_ConstantLayer();
1493 auto serializerInput = serializerLayer->input();
1502 if (this->GetFeatureVersions(graph).m_WeightsLayoutScheme <= 0)
1508 std::unique_ptr<unsigned char[]> permuteBuffer(
new unsigned char[weightsInfo.
GetNumBytes()]);
1515 auto weightsShape = weightsInfo.
GetShape();
1519 weightsShape[2]*weightsShape[3]});
1524 layer = m_Network->AddConstantLayer(weightsPermuted, layerName.c_str());
1528 RegisterOutputSlots(graph, layerIndex, layer);
1534 layer = m_Network->AddConstantLayer(input, layerName.c_str());
1541 RegisterOutputSlots(graph, layerIndex, layer);
1544 void IDeserializer::DeserializerImpl::ParseConvolution2d(
GraphPtr graph,
unsigned int layerIndex)
1547 auto inputs = GetInputs(graph, layerIndex);
1550 auto outputs = GetOutputs(graph, layerIndex);
1553 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_Convolution2dLayer();
1555 auto layerName = GetLayerName(graph, layerIndex);
1556 auto flatbufferDescriptor = flatBufferLayer->descriptor();
1559 descriptor.
m_PadLeft = flatbufferDescriptor->padLeft();
1560 descriptor.
m_PadRight = flatbufferDescriptor->padRight();
1561 descriptor.
m_PadTop = flatbufferDescriptor->padTop();
1562 descriptor.
m_PadBottom = flatbufferDescriptor->padBottom();
1563 descriptor.
m_StrideX = flatbufferDescriptor->strideX();
1564 descriptor.
m_StrideY = flatbufferDescriptor->strideY();;
1565 descriptor.
m_DilationX = flatbufferDescriptor->dilationX();
1566 descriptor.
m_DilationY = flatbufferDescriptor->dilationY();;
1567 descriptor.
m_BiasEnabled = flatbufferDescriptor->biasEnabled();;
1571 std::vector<unsigned int> ignoreSlots {};
1576 if (this->GetFeatureVersions(graph).m_ConstTensorsAsInputs <= 0)
1582 layer = m_Network->AddConvolution2dLayer(descriptor,
1586 auto weightsLayer = m_Network->AddConstantLayer(weightsTensor);
1587 weightsLayer->GetOutputSlot(0).Connect(layer->
GetInputSlot(1u));
1588 weightsLayer->GetOutputSlot(0).SetTensorInfo(weightsTensor.
GetInfo());
1589 ignoreSlots.emplace_back(1u);
1594 auto biasLayer = m_Network->AddConstantLayer(biasTensor);
1595 biasLayer->GetOutputSlot(0).Connect(layer->
GetInputSlot(2u));
1596 biasLayer->GetOutputSlot(0).SetTensorInfo(biasTensor.
GetInfo());
1597 ignoreSlots.emplace_back(2u);
1602 layer = m_Network->AddConvolution2dLayer(descriptor,
1611 RegisterInputSlots(graph, layerIndex, layer, ignoreSlots);
1612 RegisterOutputSlots(graph, layerIndex, layer);
1615 void IDeserializer::DeserializerImpl::ParseConvolution3d(
GraphPtr graph,
unsigned int layerIndex)
1618 auto inputs = GetInputs(graph, layerIndex);
1621 auto outputs = GetOutputs(graph, layerIndex);
1624 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_Convolution3dLayer();
1625 auto layerName = GetLayerName(graph, layerIndex);
1626 auto serializerDescriptor = serializerLayer->descriptor();
1629 descriptor.
m_PadLeft = serializerDescriptor->padLeft();
1630 descriptor.
m_PadRight = serializerDescriptor->padRight();
1631 descriptor.
m_PadTop = serializerDescriptor->padTop();
1632 descriptor.
m_PadBottom = serializerDescriptor->padBottom();
1633 descriptor.
m_PadFront = serializerDescriptor->padFront();
1634 descriptor.
m_PadBack = serializerDescriptor->padBack();
1635 descriptor.
m_StrideX = serializerDescriptor->strideX();
1636 descriptor.
m_StrideY = serializerDescriptor->strideY();
1637 descriptor.
m_StrideZ = serializerDescriptor->strideZ();
1638 descriptor.
m_DilationX = serializerDescriptor->dilationX();
1639 descriptor.
m_DilationY = serializerDescriptor->dilationY();
1640 descriptor.
m_DilationZ = serializerDescriptor->dilationZ();
1641 descriptor.
m_BiasEnabled = serializerDescriptor->biasEnabled();
1647 IConnectableLayer* layer = m_Network->AddConvolution3dLayer(descriptor, layerName.c_str());
1652 RegisterInputSlots(graph, layerIndex, layer);
1653 RegisterOutputSlots(graph, layerIndex, layer);
1656 void IDeserializer::DeserializerImpl::ParseDepthToSpace(
GraphPtr graph,
unsigned int layerIndex)
1660 auto inputs = GetInputs(graph, layerIndex);
1663 auto outputs = GetOutputs(graph, layerIndex);
1666 auto fbDescriptor = graph->layers()->Get(layerIndex)->layer_as_DepthToSpaceLayer()->descriptor();
1669 descriptor.
m_BlockSize = fbDescriptor->blockSize();
1672 auto layerName = GetLayerName(graph, layerIndex);
1673 IConnectableLayer* layer = m_Network->AddDepthToSpaceLayer(descriptor, layerName.c_str());
1678 RegisterInputSlots(graph, layerIndex, layer);
1679 RegisterOutputSlots(graph, layerIndex, layer);
1682 void IDeserializer::DeserializerImpl::ParseDepthwiseConvolution2d(
GraphPtr graph,
unsigned int layerIndex)
1685 auto inputs = GetInputs(graph, layerIndex);
1688 auto outputs = GetOutputs(graph, layerIndex);
1691 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_DepthwiseConvolution2dLayer();
1692 auto layerName = GetLayerName(graph, layerIndex);
1693 auto serializerDescriptor = serializerLayer->descriptor();
1696 descriptor.
m_PadLeft = serializerDescriptor->padLeft();
1697 descriptor.
m_PadRight = serializerDescriptor->padRight();
1698 descriptor.
m_PadTop = serializerDescriptor->padTop();
1699 descriptor.
m_PadBottom = serializerDescriptor->padBottom();
1700 descriptor.
m_StrideX = serializerDescriptor->strideX();
1701 descriptor.
m_StrideY = serializerDescriptor->strideY();
1702 descriptor.
m_DilationX = serializerDescriptor->dilationX();
1703 descriptor.
m_DilationY = serializerDescriptor->dilationY();
1704 descriptor.
m_BiasEnabled = serializerDescriptor->biasEnabled();
1708 std::vector<unsigned int> ignoreSlots {};
1712 if (this->GetFeatureVersions(graph).m_ConstTensorsAsInputs <= 0)
1719 ignoreSlots.emplace_back(1u);
1721 layer = m_Network->AddDepthwiseConvolution2dLayer(descriptor,
1728 ignoreSlots.emplace_back(2u);
1730 auto biasLayer = m_Network->AddConstantLayer(biases);
1731 biasLayer->GetOutputSlot(0).Connect(layer->
GetInputSlot(2u));
1732 biasLayer->GetOutputSlot(0).SetTensorInfo(biases.
GetInfo());
1735 if (this->GetFeatureVersions(graph).m_WeightsLayoutScheme <= 0)
1741 std::unique_ptr<unsigned char[]> permuteBuffer(
new unsigned char[weightsInfo.
GetNumBytes()]);
1748 auto weightsShape = weightsInfo.
GetShape();
1752 weightsShape[2]*weightsShape[3]});
1756 auto weightsLayer = m_Network->AddConstantLayer(weightsPermuted);
1757 weightsLayer->GetOutputSlot(0).Connect(layer->
GetInputSlot(1u));
1758 weightsLayer->GetOutputSlot(0).SetTensorInfo(weightsPermuted.GetInfo());
1762 auto weightsLayer = m_Network->AddConstantLayer(weights);
1763 weightsLayer->GetOutputSlot(0).Connect(layer->
GetInputSlot(1u));
1764 weightsLayer->GetOutputSlot(0).SetTensorInfo(weights.
GetInfo());
1769 layer = m_Network->AddDepthwiseConvolution2dLayer(descriptor,
1778 RegisterInputSlots(graph, layerIndex, layer, ignoreSlots);
1779 RegisterOutputSlots(graph, layerIndex, layer);
1782 void IDeserializer::DeserializerImpl::ParseDetectionPostProcess(
GraphPtr graph,
unsigned int layerIndex)
1785 auto inputs = GetInputs(graph, layerIndex);
1789 auto outputs = GetOutputs(graph, layerIndex);
1792 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_DetectionPostProcessLayer();
1793 auto layerName = GetLayerName(graph, layerIndex);
1794 auto flatBufferDescriptor = flatBufferLayer->descriptor();
1802 descriptor.
m_NumClasses = flatBufferDescriptor->numClasses();
1804 descriptor.
m_ScaleX = flatBufferDescriptor->scaleX();
1805 descriptor.
m_ScaleY = flatBufferDescriptor->scaleY();
1806 descriptor.
m_ScaleW = flatBufferDescriptor->scaleW();
1807 descriptor.
m_ScaleH = flatBufferDescriptor->scaleH();
1815 for (
unsigned int i = 0; i < 4; i++)
1820 RegisterInputSlots(graph, layerIndex, layer);
1821 RegisterOutputSlots(graph, layerIndex, layer);
1824 void IDeserializer::DeserializerImpl::ParseDivision(
GraphPtr graph,
unsigned int layerIndex)
1827 auto inputs = GetInputs(graph, layerIndex);
1831 auto outputs = GetOutputs(graph, layerIndex);
1834 auto layerName = GetLayerName(graph, layerIndex);
1836 IConnectableLayer* layer = m_Network->AddElementwiseBinaryLayer(descriptor, layerName.c_str());
1841 RegisterInputSlots(graph, layerIndex, layer);
1842 RegisterOutputSlots(graph, layerIndex, layer);
1845 void IDeserializer::DeserializerImpl::ParseEqual(
GraphPtr graph,
unsigned int layerIndex)
1848 auto inputs = GetInputs(graph, layerIndex);
1852 auto outputs = GetOutputs(graph, layerIndex);
1855 auto layerName = GetLayerName(graph, layerIndex);
1857 IConnectableLayer* layer = m_Network->AddComparisonLayer(descriptor, layerName.c_str());
1862 RegisterInputSlots(graph, layerIndex, layer);
1863 RegisterOutputSlots(graph, layerIndex, layer);
1866 void IDeserializer::DeserializerImpl::ParseFill(
GraphPtr graph,
unsigned int layerIndex)
1869 auto inputs = GetInputs(graph, layerIndex);
1873 auto outputs = GetOutputs(graph, layerIndex);
1876 auto layerName = GetLayerName(graph, layerIndex);
1878 descriptor.
m_Value = graph->layers()->Get(layerIndex)->layer_as_FillLayer()->descriptor()->value();
1879 IConnectableLayer* layer = m_Network->AddFillLayer(descriptor, layerName.c_str());
1884 RegisterInputSlots(graph, layerIndex, layer);
1885 RegisterOutputSlots(graph, layerIndex, layer);
1888 void IDeserializer::DeserializerImpl::ParseGreater(
GraphPtr graph,
unsigned int layerIndex)
1891 auto inputs = GetInputs(graph, layerIndex);
1895 auto outputs = GetOutputs(graph, layerIndex);
1898 auto layerName = GetLayerName(graph, layerIndex);
1900 IConnectableLayer* layer = m_Network->AddComparisonLayer(descriptor, layerName.c_str());
1905 RegisterInputSlots(graph, layerIndex, layer);
1906 RegisterOutputSlots(graph, layerIndex, layer);
1909 void IDeserializer::DeserializerImpl::ParseInstanceNormalization(
GraphPtr graph,
unsigned int layerIndex)
1913 auto inputs = GetInputs(graph, layerIndex);
1916 auto outputs = GetOutputs(graph, layerIndex);
1919 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_InstanceNormalizationLayer();
1920 auto fbDescriptor = fbLayer->descriptor();
1923 descriptor.
m_Gamma = fbDescriptor->gamma();
1924 descriptor.
m_Beta = fbDescriptor->beta();
1925 descriptor.
m_Eps = fbDescriptor->eps();
1928 const std::string layerName = GetLayerName(graph, layerIndex);
1931 IConnectableLayer* layer = m_Network->AddInstanceNormalizationLayer(descriptor, layerName.c_str());
1934 RegisterInputSlots(graph, layerIndex, layer);
1935 RegisterOutputSlots(graph, layerIndex, layer);
1938 void IDeserializer::DeserializerImpl::ParseL2Normalization(
GraphPtr graph,
unsigned int layerIndex)
1942 auto inputs = GetInputs(graph, layerIndex);
1945 auto outputs = GetOutputs(graph, layerIndex);
1949 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_L2NormalizationLayer();
1950 auto flatBufferDescriptor = flatBufferLayer->descriptor();
1952 auto layerName = GetLayerName(graph, layerIndex);
1955 descriptor.
m_Eps = flatBufferDescriptor->eps();
1957 IConnectableLayer* layer = m_Network->AddL2NormalizationLayer(descriptor, layerName.c_str());
1960 RegisterInputSlots(graph, layerIndex, layer);
1961 RegisterOutputSlots(graph, layerIndex, layer);
1964 void IDeserializer::DeserializerImpl::ParseLogicalBinary(
GraphPtr graph,
unsigned int layerIndex)
1969 auto inputs = GetInputs(graph, layerIndex);
1972 auto outputs = GetOutputs(graph, layerIndex);
1975 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_LogicalBinaryLayer();
1976 auto fbDescriptor = fbLayer->descriptor();
1981 const std::string& layerName = GetLayerName(graph, layerIndex);
1982 IConnectableLayer* layer = m_Network->AddLogicalBinaryLayer(descriptor, layerName.c_str());
1987 RegisterInputSlots(graph, layerIndex, layer);
1988 RegisterOutputSlots(graph, layerIndex, layer);
1991 void IDeserializer::DeserializerImpl::ParseLogSoftmax(
GraphPtr graph,
unsigned int layerIndex)
2002 descriptor.
m_Beta = graph->layers()->Get(layerIndex)->layer_as_LogSoftmaxLayer()->descriptor()->beta();
2003 descriptor.
m_Axis = graph->layers()->Get(layerIndex)->layer_as_LogSoftmaxLayer()->descriptor()->axis();
2004 auto layerName = GetLayerName(graph, layerIndex);
2006 IConnectableLayer* layer = m_Network->AddLogSoftmaxLayer(descriptor, layerName.c_str());
2011 RegisterInputSlots(graph, layerIndex, layer);
2012 RegisterOutputSlots(graph, layerIndex, layer);
2015 void IDeserializer::DeserializerImpl::ParseMinimum(
GraphPtr graph,
unsigned int layerIndex)
2018 auto inputs = GetInputs(graph, layerIndex);
2022 auto outputs = GetOutputs(graph, layerIndex);
2025 auto layerName = GetLayerName(graph, layerIndex);
2027 IConnectableLayer* layer = m_Network->AddElementwiseBinaryLayer(descriptor, layerName.c_str());
2032 RegisterInputSlots(graph, layerIndex, layer);
2033 RegisterOutputSlots(graph, layerIndex, layer);
2036 void IDeserializer::DeserializerImpl::ParseMaximum(
GraphPtr graph,
unsigned int layerIndex)
2039 auto inputs = GetInputs(graph, layerIndex);
2043 auto outputs = GetOutputs(graph, layerIndex);
2046 auto layerName = GetLayerName(graph, layerIndex);
2048 IConnectableLayer* layer = m_Network->AddElementwiseBinaryLayer(descriptor, layerName.c_str());
2053 RegisterInputSlots(graph, layerIndex, layer);
2054 RegisterOutputSlots(graph, layerIndex, layer);
2058 unsigned int layerIndex)
2060 auto layerType = graph->layers()->Get(layerIndex)->layer_type();
2064 case Layer::Layer_ConcatLayer:
2065 return graph->layers()->Get(layerIndex)->layer_as_ConcatLayer()->descriptor();
2066 case Layer::Layer_MergerLayer:
2067 return graph->layers()->Get(layerIndex)->layer_as_MergerLayer()->descriptor();
2072 void IDeserializer::DeserializerImpl::ParseChannelShuffle(
GraphPtr graph,
unsigned int layerIndex)
2083 descriptor.
m_Axis = graph->layers()->Get(layerIndex)->layer_as_ChannelShuffleLayer()->descriptor()->axis();
2085 graph->layers()->Get(layerIndex)->layer_as_ChannelShuffleLayer()->descriptor()->numGroups();
2087 auto layerName = GetLayerName(graph, layerIndex);
2088 IConnectableLayer* layer = m_Network->AddChannelShuffleLayer(descriptor, layerName.c_str());
2093 RegisterInputSlots(graph, layerIndex, layer);
2094 RegisterOutputSlots(graph, layerIndex, layer);
2096 void IDeserializer::DeserializerImpl::ParseComparison(
GraphPtr graph,
unsigned int layerIndex)
2101 auto inputs = GetInputs(graph, layerIndex);
2104 auto outputs = GetOutputs(graph, layerIndex);
2107 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_ComparisonLayer();
2108 auto fbDescriptor = fbLayer->descriptor();
2113 const std::string& layerName = GetLayerName(graph, layerIndex);
2114 IConnectableLayer* layer = m_Network->AddComparisonLayer(descriptor, layerName.c_str());
2119 RegisterInputSlots(graph, layerIndex, layer);
2120 RegisterOutputSlots(graph, layerIndex, layer);
2123 void IDeserializer::DeserializerImpl::ParseElementwiseBinary(
GraphPtr graph,
unsigned int layerIndex)
2128 auto inputs = GetInputs(graph, layerIndex);
2131 auto outputs = GetOutputs(graph, layerIndex);
2134 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_ElementwiseBinaryLayer();
2135 auto fbDescriptor = fbLayer->descriptor();
2140 const std::string& layerName = GetLayerName(graph, layerIndex);
2141 IConnectableLayer* layer = m_Network->AddElementwiseBinaryLayer(descriptor, layerName.c_str());
2146 RegisterInputSlots(graph, layerIndex, layer);
2147 RegisterOutputSlots(graph, layerIndex, layer);
2150 void IDeserializer::DeserializerImpl::ParseElementwiseUnary(
GraphPtr graph,
unsigned int layerIndex)
2155 auto inputs = GetInputs(graph, layerIndex);
2158 auto outputs = GetOutputs(graph, layerIndex);
2161 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_ElementwiseUnaryLayer();
2162 auto fbDescriptor = fbLayer->descriptor();
2167 const std::string& layerName = GetLayerName(graph, layerIndex);
2168 IConnectableLayer* layer = m_Network->AddElementwiseUnaryLayer(descriptor, layerName.c_str());
2173 RegisterInputSlots(graph, layerIndex, layer);
2174 RegisterOutputSlots(graph, layerIndex, layer);
2177 void IDeserializer::DeserializerImpl::ParseConcat(
GraphPtr graph,
unsigned int layerIndex)
2182 auto outputs = GetOutputs(graph, layerIndex);
2185 auto layerName = GetLayerName(graph, layerIndex);
2187 unsigned int numViews = originsDescriptor->numViews();
2188 unsigned int numDimensions = originsDescriptor->numDimensions();
2191 auto inputs = GetInputs(graph, layerIndex);
2195 auto originsPtr = originsDescriptor->viewOrigins();
2196 for (
unsigned int v = 0; v < numViews; ++v)
2198 auto originPtr = originsPtr->Get(v);
2199 for (
unsigned int d = 0; d < numDimensions; ++d)
2201 uint32_t value = originPtr->data()->Get(d);
2202 descriptor.SetViewOriginCoord(v, d, value);
2205 descriptor.SetConcatAxis(originsDescriptor->concatAxis());
2207 IConnectableLayer* layer = m_Network->AddConcatLayer(descriptor, layerName.c_str());
2211 RegisterInputSlots(graph, layerIndex, layer);
2212 RegisterOutputSlots(graph, layerIndex, layer);
2215 void IDeserializer::DeserializerImpl::ParseMultiplication(
GraphPtr graph,
unsigned int layerIndex)
2218 auto inputs = GetInputs(graph, layerIndex);
2222 auto outputs = GetOutputs(graph, layerIndex);
2225 auto layerName = GetLayerName(graph, layerIndex);
2227 IConnectableLayer* layer = m_Network->AddElementwiseBinaryLayer(descriptor, layerName.c_str());
2232 RegisterInputSlots(graph, layerIndex, layer);
2233 RegisterOutputSlots(graph, layerIndex, layer);
2236 void IDeserializer::DeserializerImpl::ParseFloor(
GraphPtr graph,
unsigned int layerIndex)
2241 auto inputs = GetInputs(graph, layerIndex);
2244 auto outputs = GetOutputs(graph, layerIndex);
2247 auto layerName = GetLayerName(graph, layerIndex);
2251 layer = m_Network->AddFloorLayer(layerName.c_str());
2256 RegisterInputSlots(graph, layerIndex, layer);
2257 RegisterOutputSlots(graph, layerIndex, layer);
2260 void IDeserializer::DeserializerImpl::ParseFullyConnected(
GraphPtr graph,
unsigned int layerIndex)
2263 auto inputs = GetInputs(graph, layerIndex);
2266 auto outputs = GetOutputs(graph, layerIndex);
2269 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_FullyConnectedLayer();
2270 auto layerName = GetLayerName(graph, layerIndex);
2271 auto flatBufferDescriptor = flatBufferLayer->descriptor();
2274 fullyConnectedDescriptor.
m_BiasEnabled = flatBufferDescriptor->biasEnabled();
2276 fullyConnectedDescriptor.
m_ConstantWeights = flatBufferDescriptor->constantWeights();
2279 std::vector<unsigned int> ignoreSlots {};
2283 if (this->GetFeatureVersions(graph).m_ConstTensorsAsInputs <= 0)
2288 layer = m_Network->AddFullyConnectedLayer(fullyConnectedDescriptor,
2292 auto weightsLayer = m_Network->AddConstantLayer(weightsTensor);
2293 weightsLayer->GetOutputSlot(0).Connect(layer->
GetInputSlot(1u));
2294 weightsLayer->GetOutputSlot(0).SetTensorInfo(weightsTensor.
GetInfo());
2295 ignoreSlots.emplace_back(1u);
2300 auto biasLayer = m_Network->AddConstantLayer(biasTensor);
2301 biasLayer->GetOutputSlot(0).Connect(layer->
GetInputSlot(2u));
2302 biasLayer->GetOutputSlot(0).SetTensorInfo(biasTensor.
GetInfo());
2303 ignoreSlots.emplace_back(2u);
2308 layer = m_Network->AddFullyConnectedLayer(fullyConnectedDescriptor,
2310 uint32_t numInputs = fullyConnectedDescriptor.
GetNumInputs();
2317 RegisterInputSlots(graph, layerIndex, layer, ignoreSlots);
2318 RegisterOutputSlots(graph, layerIndex, layer);
2321 void IDeserializer::DeserializerImpl::ParsePad(
GraphPtr graph,
unsigned int layerIndex)
2331 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_PadLayer()->descriptor();
2332 auto flatBufferPadList = flatBufferDescriptor->padList();
2333 auto paddingMode = flatBufferDescriptor->paddingMode();
2334 float padValue = flatBufferDescriptor->padValue();
2336 if (flatBufferPadList->size() % 2 != 0)
2338 throw ParseException(fmt::format(
"The size of the pad list must be divisible by 2 {}",
2342 std::vector<std::pair<unsigned int, unsigned int>> padList;
2343 padList.reserve(flatBufferPadList->size() / 2);
2344 for (
unsigned int i = 0; i < flatBufferPadList->size() - 1; i += 2)
2346 padList.emplace_back(flatBufferPadList->Get(i), flatBufferPadList->Get(i+1));
2351 auto layerName = GetLayerName(graph, layerIndex);
2352 IConnectableLayer* layer = m_Network->AddPadLayer(descriptor, layerName.c_str());
2357 RegisterInputSlots(graph, layerIndex, layer);
2358 RegisterOutputSlots(graph, layerIndex, layer);
2361 void IDeserializer::DeserializerImpl::ParsePermute(
GraphPtr graph,
unsigned int layerIndex)
2366 graph->layers()->Get(layerIndex)->layer_as_PermuteLayer()->descriptor()->dimMappings();
2368 auto inputs = GetInputs(graph, layerIndex);
2371 auto outputs = GetOutputs(graph, layerIndex);
2375 auto layerName = GetLayerName(graph, layerIndex);
2378 IConnectableLayer* layer = m_Network->AddPermuteLayer(descriptor, layerName.c_str());
2381 RegisterInputSlots(graph, layerIndex, layer);
2382 RegisterOutputSlots(graph, layerIndex, layer);
2386 unsigned int layerIndex)
2391 switch (pooling2dDesc->poolType())
2393 case PoolingAlgorithm_Average:
2398 case PoolingAlgorithm_Max:
2403 case PoolingAlgorithm_L2:
2414 switch (pooling2dDesc->outputShapeRounding())
2416 case OutputShapeRounding_Floor:
2421 case OutputShapeRounding_Ceiling:
2432 switch (pooling2dDesc->paddingMethod())
2434 case PaddingMethod_Exclude:
2439 case PaddingMethod_IgnoreValue:
2450 switch (pooling2dDesc->dataLayout())
2452 case DataLayout_NCHW:
2457 case DataLayout_NHWC:
2469 desc.
m_PadLeft = pooling2dDesc->padLeft();
2471 desc.
m_PadTop = pooling2dDesc->padTop();
2472 desc.
m_StrideX = pooling2dDesc->strideX();
2473 desc.
m_StrideY = pooling2dDesc->strideY();
2481 unsigned int layerIndex)
2486 switch (pooling3dDesc->poolType())
2488 case PoolingAlgorithm_Average:
2493 case PoolingAlgorithm_Max:
2498 case PoolingAlgorithm_L2:
2509 switch (pooling3dDesc->outputShapeRounding())
2511 case OutputShapeRounding_Floor:
2516 case OutputShapeRounding_Ceiling:
2527 switch (pooling3dDesc->paddingMethod())
2529 case PaddingMethod_Exclude:
2534 case PaddingMethod_IgnoreValue:
2545 switch (pooling3dDesc->dataLayout())
2547 case DataLayout_NCDHW:
2552 case DataLayout_NDHWC:
2564 desc.
m_PadLeft = pooling3dDesc->padLeft();
2566 desc.
m_PadTop = pooling3dDesc->padTop();
2568 desc.
m_PadBack = pooling3dDesc->padBack();
2569 desc.
m_StrideX = pooling3dDesc->strideX();
2570 desc.
m_StrideY = pooling3dDesc->strideY();
2571 desc.
m_StrideZ = pooling3dDesc->strideZ();
2579 void IDeserializer::DeserializerImpl::ParsePooling2d(
GraphPtr graph,
unsigned int layerIndex)
2583 auto pooling2dDes = graph->layers()->Get(layerIndex)->layer_as_Pooling2dLayer()->descriptor();
2584 auto inputs = GetInputs(graph, layerIndex);
2587 auto outputs = GetOutputs(graph, layerIndex);
2591 auto pooling2dDescriptor = GetPooling2dDescriptor(pooling2dDes, layerIndex);
2592 auto layerName = GetLayerName(graph, layerIndex);
2593 IConnectableLayer* layer = m_Network->AddPooling2dLayer(pooling2dDescriptor, layerName.c_str());
2596 RegisterInputSlots(graph, layerIndex, layer);
2597 RegisterOutputSlots(graph, layerIndex, layer);
2600 void IDeserializer::DeserializerImpl::ParsePooling3d(
GraphPtr graph,
unsigned int layerIndex)
2604 auto pooling3dDes = graph->layers()->Get(layerIndex)->layer_as_Pooling3dLayer()->descriptor();
2605 auto inputs = GetInputs(graph, layerIndex);
2608 auto outputs = GetOutputs(graph, layerIndex);
2612 auto pooling3dDescriptor = GetPooling3dDescriptor(pooling3dDes, layerIndex);
2613 auto layerName = GetLayerName(graph, layerIndex);
2614 IConnectableLayer* layer = m_Network->AddPooling3dLayer(pooling3dDescriptor, layerName.c_str());
2617 RegisterInputSlots(graph, layerIndex, layer);
2618 RegisterOutputSlots(graph, layerIndex, layer);
2621 void IDeserializer::DeserializerImpl::ParseQuantize(
GraphPtr graph,
unsigned int layerIndex)
2625 auto inputs = GetInputs(graph, layerIndex);
2628 auto outputs = GetOutputs(graph, layerIndex);
2632 auto layerName = GetLayerName(graph, layerIndex);
2636 RegisterInputSlots(graph, layerIndex, layer);
2637 RegisterOutputSlots(graph, layerIndex, layer);
2641 const std::vector<uint32_t>& targetDimsIn)
2643 std::vector<unsigned int> outputDims(targetDimsIn.begin(), targetDimsIn.end());
2644 const auto stretchDim = std::find(targetDimsIn.begin(), targetDimsIn.end(), -1);
2646 if (stretchDim != targetDimsIn.end())
2648 if (std::find(std::next(stretchDim), targetDimsIn.end(), -1) != targetDimsIn.end())
2650 throw ParseException(fmt::format(
"At most one component of shape can be -1 {}",
2654 auto targetNumElements =
2655 armnn::numeric_cast<unsigned int>(
2656 std::accumulate(targetDimsIn.begin(), targetDimsIn.end(), -1, std::multiplies<int32_t>()));
2658 auto stretchIndex =
static_cast<size_t>(std::distance(targetDimsIn.begin(), stretchDim));
2659 if (targetNumElements == 0)
2663 outputDims[stretchIndex] = 0;
2668 fmt::format(
"Input to reshape is a tensor with elements, but the requested shape has 0. {}",
2674 outputDims[stretchIndex] = inputTensorInfo.
GetNumElements() / targetNumElements;
2686 void IDeserializer::DeserializerImpl::ParseRank(
GraphPtr graph,
unsigned int layerIndex)
2696 auto layerName = GetLayerName(graph, layerIndex);
2702 RegisterInputSlots(graph, layerIndex, layer);
2703 RegisterOutputSlots(graph, layerIndex, layer);
2706 void IDeserializer::DeserializerImpl::ParseReduce(
GraphPtr graph,
unsigned int layerIndex)
2711 auto inputs = GetInputs(graph, layerIndex);
2714 auto outputs = GetOutputs(graph, layerIndex);
2717 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_ReduceLayer();
2718 auto fbDescriptor = fbLayer->descriptor();
2719 auto flatBufferAxis = fbDescriptor->axis();
2722 descriptor.
m_KeepDims = fbDescriptor->keepDims();
2723 descriptor.
m_vAxis = std::vector<unsigned int>(flatBufferAxis->begin(), flatBufferAxis->end());
2726 const std::string& layerName = GetLayerName(graph, layerIndex);
2727 IConnectableLayer* layer = m_Network->AddReduceLayer(descriptor, layerName.c_str());
2732 RegisterInputSlots(graph, layerIndex, layer);
2733 RegisterOutputSlots(graph, layerIndex, layer);
2736 void IDeserializer::DeserializerImpl::ParseReshape(
GraphPtr graph,
unsigned int layerIndex)
2739 auto inputs = GetInputs(graph, layerIndex);
2741 auto outputs = GetOutputs(graph, layerIndex);
2747 const auto targetDims = graph->layers()->Get(layerIndex)->layer_as_ReshapeLayer()->descriptor()->targetShape();
2748 std::vector<uint32_t> outputDims(targetDims->begin(), targetDims->begin() + targetDims->size());
2753 const std::vector<uint32_t> expectedDims(outputs[0]->dimensions()->begin(),
2754 outputs[0]->dimensions()->begin() + outputs[0]->dimensions()->size());
2756 if (inputs.size() > 1 && !
CheckShape(reshapeOutputTensorShape, expectedDims))
2758 std::stringstream ss;
2759 ss <<
"New shape defined in reshape parameters "
2760 << reshapeOutputTensorShape
2761 <<
" does not equal output shape "
2762 << actualOutputTensorInfo.
GetShape()
2771 auto layerName = GetLayerName(graph, layerIndex);
2772 IConnectableLayer* layer = m_Network->AddReshapeLayer(reshapeDesc, layerName.c_str());
2775 RegisterInputSlots(graph, layerIndex, layer);
2776 RegisterOutputSlots(graph, layerIndex, layer);
2779 void IDeserializer::DeserializerImpl::ParseResize(
GraphPtr graph,
unsigned int layerIndex)
2789 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_ResizeLayer()->descriptor();
2792 descriptor.
m_TargetWidth = flatBufferDescriptor->targetWidth();
2793 descriptor.
m_TargetHeight = flatBufferDescriptor->targetHeight();
2796 descriptor.
m_AlignCorners = flatBufferDescriptor->alignCorners();
2799 auto layerName = GetLayerName(graph, layerIndex);
2800 IConnectableLayer* layer = m_Network->AddResizeLayer(descriptor, layerName.c_str());
2805 RegisterInputSlots(graph, layerIndex, layer);
2806 RegisterOutputSlots(graph, layerIndex, layer);
2809 void IDeserializer::DeserializerImpl::ParseReverseV2(
GraphPtr graph,
unsigned int layerIndex)
2819 auto layerName = GetLayerName(graph, layerIndex);
2825 RegisterInputSlots(graph, layerIndex, layer);
2826 RegisterOutputSlots(graph, layerIndex, layer);
2831 void IDeserializer::DeserializerImpl::ParseResizeBilinear(
GraphPtr graph,
unsigned int layerIndex)
2841 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_ResizeBilinearLayer()->descriptor();
2844 descriptor.
m_TargetWidth = flatBufferDescriptor->targetWidth();
2845 descriptor.
m_TargetHeight = flatBufferDescriptor->targetHeight();
2848 descriptor.
m_AlignCorners = flatBufferDescriptor->alignCorners();
2851 auto layerName = GetLayerName(graph, layerIndex);
2852 IConnectableLayer* layer = m_Network->AddResizeLayer(descriptor, layerName.c_str());
2857 RegisterInputSlots(graph, layerIndex, layer);
2858 RegisterOutputSlots(graph, layerIndex, layer);
2861 void IDeserializer::DeserializerImpl::ParseShape(
GraphPtr graph,
unsigned int layerIndex)
2871 auto layerName = GetLayerName(graph, layerIndex);
2877 RegisterInputSlots(graph, layerIndex, layer);
2878 RegisterOutputSlots(graph, layerIndex, layer);
2881 void IDeserializer::DeserializerImpl::ParseSoftmax(
GraphPtr graph,
unsigned int layerIndex)
2892 descriptor.
m_Beta = graph->layers()->Get(layerIndex)->layer_as_SoftmaxLayer()->descriptor()->beta();
2893 descriptor.
m_Axis = graph->layers()->Get(layerIndex)->layer_as_SoftmaxLayer()->descriptor()->axis();
2894 auto layerName = GetLayerName(graph, layerIndex);
2896 IConnectableLayer* layer = m_Network->AddSoftmaxLayer(descriptor, layerName.c_str());
2901 RegisterInputSlots(graph, layerIndex, layer);
2902 RegisterOutputSlots(graph, layerIndex, layer);
2905 void IDeserializer::DeserializerImpl::ParseSpaceToBatchNd(
GraphPtr graph,
unsigned int layerIndex)
2915 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_SpaceToBatchNdLayer()->descriptor();
2916 auto flatBufferPadList = flatBufferDescriptor->padList();
2917 auto flatBufferBlockShape = flatBufferDescriptor->blockShape();
2919 if (flatBufferPadList->size() % 2 != 0)
2921 throw ParseException(fmt::format(
"The size of the pad list must be divisible by 2 {}",
2925 std::vector<std::pair<unsigned int, unsigned int>> padList;
2926 padList.reserve(flatBufferPadList->size() / 2);
2927 for (
unsigned int i = 0; i < flatBufferPadList->size() - 1; i += 2)
2929 padList.emplace_back(flatBufferPadList->Get(i), flatBufferPadList->Get(i+1));
2935 std::vector<unsigned int>(flatBufferBlockShape->begin(), flatBufferBlockShape->end());
2938 auto layerName = GetLayerName(graph, layerIndex);
2939 IConnectableLayer* layer = m_Network->AddSpaceToBatchNdLayer(descriptor, layerName.c_str());
2944 RegisterInputSlots(graph, layerIndex, layer);
2945 RegisterOutputSlots(graph, layerIndex, layer);
2948 void IDeserializer::DeserializerImpl::ParseSpaceToDepth(
GraphPtr graph,
unsigned int layerIndex)
2958 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_SpaceToDepthLayer()->descriptor();
2961 descriptor.
m_BlockSize = flatBufferDescriptor->blockSize();
2964 auto layerName = GetLayerName(graph, layerIndex);
2965 IConnectableLayer* layer = m_Network->AddSpaceToDepthLayer(descriptor, layerName.c_str());
2970 RegisterInputSlots(graph, layerIndex, layer);
2971 RegisterOutputSlots(graph, layerIndex, layer);
2976 unsigned int layerIndex)
2981 switch (normalizationDescriptor->normChannelType())
2983 case NormalizationAlgorithmChannel_Across:
2988 case NormalizationAlgorithmChannel_Within:
2999 switch (normalizationDescriptor->normMethodType())
3001 case NormalizationAlgorithmMethod_LocalBrightness:
3006 case NormalizationAlgorithmMethod_LocalContrast:
3017 switch (normalizationDescriptor->dataLayout())
3019 case DataLayout_NCHW:
3024 case DataLayout_NHWC:
3035 desc.
m_Alpha = normalizationDescriptor->alpha();
3036 desc.
m_Beta = normalizationDescriptor->beta();
3037 desc.
m_K = normalizationDescriptor->k();
3038 desc.
m_NormSize = normalizationDescriptor->normSize();
3043 void IDeserializer::DeserializerImpl::ParseNormalization(
GraphPtr graph,
unsigned int layerIndex)
3047 auto normalizationDes = graph->layers()->Get(layerIndex)->layer_as_NormalizationLayer()->descriptor();
3057 auto normalizationDescriptor = GetNormalizationDescriptor(normalizationDes, layerIndex);
3058 auto layerName = GetLayerName(graph, layerIndex);
3060 IConnectableLayer* layer = m_Network->AddNormalizationLayer(normalizationDescriptor, layerName.c_str());
3063 RegisterInputSlots(graph, layerIndex, layer);
3064 RegisterOutputSlots(graph, layerIndex, layer);
3067 void IDeserializer::DeserializerImpl::ParseRsqrt(
GraphPtr graph,
unsigned int layerIndex)
3070 auto inputs = GetInputs(graph, layerIndex);
3074 auto outputs = GetOutputs(graph, layerIndex);
3077 auto layerName = GetLayerName(graph, layerIndex);
3080 IConnectableLayer* layer = m_Network->AddElementwiseUnaryLayer(descriptor, layerName.c_str());
3084 RegisterInputSlots(graph, layerIndex, layer);
3085 RegisterOutputSlots(graph, layerIndex, layer);
3088 void IDeserializer::DeserializerImpl::ParseSlice(
GraphPtr graph,
unsigned int layerIndex)
3092 auto inputs = GetInputs(graph, layerIndex);
3095 auto outputs = GetOutputs(graph, layerIndex);
3098 auto fbDescriptor = graph->layers()->Get(layerIndex)->layer_as_SliceLayer()->descriptor();
3100 auto fbBegin = fbDescriptor->begin();
3101 auto fbSize = fbDescriptor->size();
3103 if (fbBegin->size() != fbSize->size())
3105 throw ParseException(fmt::format(
"Begin and size descriptors must have the same length {}",
3110 descriptor.
m_Begin.insert(descriptor.
m_Begin.end(), fbBegin->begin(), fbBegin->end());
3111 descriptor.
m_Size.insert(descriptor.
m_Size.end(), fbSize->begin(), fbSize->end());
3113 auto layerName = GetLayerName(graph, layerIndex);
3114 IConnectableLayer* layer = m_Network->AddSliceLayer(descriptor, layerName.c_str());
3119 RegisterInputSlots(graph, layerIndex, layer);
3120 RegisterOutputSlots(graph, layerIndex, layer);
3123 void IDeserializer::DeserializerImpl::ParseStridedSlice(
GraphPtr graph,
unsigned int layerIndex)
3133 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_StridedSliceLayer()->descriptor();
3135 auto flatBufferBegin = flatBufferDescriptor->begin();
3136 auto flatBufferEnd = flatBufferDescriptor->end();
3137 auto flatBufferStride = flatBufferDescriptor->stride();
3139 if (!(flatBufferBegin->size() == flatBufferEnd->size() &&
3140 flatBufferBegin->size() == flatBufferStride->size()))
3142 throw ParseException(fmt::format(
"The size of the begin, end, and stride must be equal {}",
3146 std::vector<int> begin(flatBufferBegin->begin(), flatBufferBegin->end());
3147 std::vector<int> end(flatBufferEnd->begin(), flatBufferEnd->end());
3148 std::vector<int> stride(flatBufferStride->begin(), flatBufferStride->end());
3151 descriptor.m_BeginMask = flatBufferDescriptor->beginMask();
3152 descriptor.m_EndMask = flatBufferDescriptor->endMask();
3153 descriptor.m_ShrinkAxisMask = flatBufferDescriptor->shrinkAxisMask();
3154 descriptor.m_EllipsisMask = flatBufferDescriptor->ellipsisMask();
3155 descriptor.m_NewAxisMask = flatBufferDescriptor->newAxisMask();
3156 descriptor.m_DataLayout =
ToDataLayout(flatBufferDescriptor->dataLayout());
3158 auto layerName = GetLayerName(graph, layerIndex);
3159 IConnectableLayer* layer = m_Network->AddStridedSliceLayer(descriptor, layerName.c_str());
3164 RegisterInputSlots(graph, layerIndex, layer);
3165 RegisterOutputSlots(graph, layerIndex, layer);
3168 void IDeserializer::DeserializerImpl::ParseSubtraction(
GraphPtr graph,
unsigned int layerIndex)
3171 auto inputs = GetInputs(graph, layerIndex);
3175 auto outputs = GetOutputs(graph, layerIndex);
3178 auto layerName = GetLayerName(graph, layerIndex);
3180 IConnectableLayer* layer = m_Network->AddElementwiseBinaryLayer(descriptor, layerName.c_str());
3185 RegisterInputSlots(graph, layerIndex, layer);
3186 RegisterOutputSlots(graph, layerIndex, layer);
3189 void IDeserializer::DeserializerImpl::ParseGather(
GraphPtr graph,
unsigned int layerIndex)
3200 descriptor.
m_Axis = graph->layers()->Get(layerIndex)->layer_as_GatherLayer()->descriptor()->axis();
3202 auto layerName = GetLayerName(graph, layerIndex);
3203 IConnectableLayer* layer = m_Network->AddGatherLayer(descriptor, layerName.c_str());
3208 RegisterInputSlots(graph, layerIndex, layer);
3209 RegisterOutputSlots(graph, layerIndex, layer);
3212 void IDeserializer::DeserializerImpl::ParseGatherNd(
GraphPtr graph,
unsigned int layerIndex)
3222 auto layerName = GetLayerName(graph, layerIndex);
3228 RegisterInputSlots(graph, layerIndex, layer);
3229 RegisterOutputSlots(graph, layerIndex, layer);
3232 void IDeserializer::DeserializerImpl::ParseMean(
GraphPtr graph,
unsigned int layerIndex)
3242 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_MeanLayer()->descriptor();
3243 auto flatBufferAxis = flatBufferDescriptor->axis();
3244 auto flatBufferKeepDims = flatBufferDescriptor->keepDims();
3247 descriptor.
m_Axis = std::vector<unsigned int>(flatBufferAxis->begin(), flatBufferAxis->end());
3250 auto layerName = GetLayerName(graph, layerIndex);
3251 IConnectableLayer* layer = m_Network->AddMeanLayer(descriptor, layerName.c_str());
3256 RegisterInputSlots(graph, layerIndex, layer);
3257 RegisterOutputSlots(graph, layerIndex, layer);
3260 void IDeserializer::DeserializerImpl::ParseSplitter(
GraphPtr graph,
unsigned int layerIndex)
3269 auto flatBufferViewsDescriptor = graph->layers()->Get(layerIndex)->layer_as_SplitterLayer()->descriptor();
3270 auto flatBufferViewSizes = flatBufferViewsDescriptor->viewSizes();
3271 auto flatBufferOriginsDescriptor = flatBufferViewsDescriptor->origins();
3272 auto flatBufferViewOrigins = flatBufferOriginsDescriptor->viewOrigins();
3273 uint32_t numViews = flatBufferOriginsDescriptor->numViews();
3274 uint32_t numDimensions = flatBufferOriginsDescriptor->numDimensions();
3281 for(
unsigned int vIdx = 0; vIdx < numViews; ++vIdx)
3283 for (
unsigned int dIdx = 0; dIdx < numDimensions; ++dIdx)
3285 viewsDescriptor.SetViewSize(vIdx, dIdx, flatBufferViewSizes->Get(vIdx)->data()->Get(dIdx));
3286 viewsDescriptor.SetViewOriginCoord(vIdx, dIdx, flatBufferViewOrigins->Get(vIdx)->data()->Get(dIdx));
3290 if (flatBufferViewsDescriptor->hasAxis())
3292 viewsDescriptor.SetAxis(flatBufferViewsDescriptor->axis());
3295 auto layerName = GetLayerName(graph, layerIndex);
3296 IConnectableLayer* layer = m_Network->AddSplitterLayer(viewsDescriptor, layerName.c_str());
3299 for(
unsigned int vIdx = 0; vIdx < numViews; ++vIdx)
3305 RegisterInputSlots(graph, layerIndex, layer);
3306 RegisterOutputSlots(graph, layerIndex, layer);
3324 void IDeserializer::DeserializerImpl::ParseLstm(
GraphPtr graph,
unsigned int layerIndex)
3328 auto inputs = GetInputs(graph, layerIndex);
3331 auto outputs = GetOutputs(graph, layerIndex);
3334 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_LstmLayer();
3335 auto layerName = GetLayerName(graph, layerIndex);
3336 auto flatBufferDescriptor = flatBufferLayer->descriptor();
3337 auto flatBufferInputParams = flatBufferLayer->inputParams();
3339 auto lstmDescriptor = GetLstmDescriptor(flatBufferDescriptor);
3367 if (!lstmDescriptor.m_CifgEnabled)
3369 inputToInputWeights =
ToConstTensor(flatBufferInputParams->inputToInputWeights());
3370 recurrentToInputWeights =
ToConstTensor(flatBufferInputParams->recurrentToInputWeights());
3371 cellToInputWeights =
ToConstTensor(flatBufferInputParams->cellToInputWeights());
3372 inputGateBias =
ToConstTensor(flatBufferInputParams->inputGateBias());
3382 if (lstmDescriptor.m_ProjectionEnabled)
3384 projectionWeights =
ToConstTensor(flatBufferInputParams->projectionWeights());
3385 projectionBias =
ToConstTensor(flatBufferInputParams->projectionBias());
3393 if (lstmDescriptor.m_PeepholeEnabled)
3395 cellToForgetWeights =
ToConstTensor(flatBufferInputParams->cellToForgetWeights());
3396 cellToOutputWeights =
ToConstTensor(flatBufferInputParams->cellToOutputWeights());
3406 if (lstmDescriptor.m_LayerNormEnabled)
3408 if (!lstmDescriptor.m_CifgEnabled)
3410 inputLayerNormWeights =
ToConstTensor(flatBufferInputParams->inputLayerNormWeights());
3413 forgetLayerNormWeights =
ToConstTensor(flatBufferInputParams->forgetLayerNormWeights());
3414 cellLayerNormWeights =
ToConstTensor(flatBufferInputParams->cellLayerNormWeights());
3415 outputLayerNormWeights =
ToConstTensor(flatBufferInputParams->outputLayerNormWeights());
3422 IConnectableLayer* layer = m_Network->AddLstmLayer(lstmDescriptor, lstmInputParams, layerName.c_str());
3436 RegisterInputSlots(graph, layerIndex, layer);
3437 RegisterOutputSlots(graph, layerIndex, layer);
3449 desc.
m_CellClip = qLstmDescriptor->cellClip();
3463 void IDeserializer::DeserializerImpl::ParseQLstm(
GraphPtr graph,
unsigned int layerIndex)
3467 auto inputs = GetInputs(graph, layerIndex);
3470 auto outputs = GetOutputs(graph, layerIndex);
3473 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_QLstmLayer();
3474 auto layerName = GetLayerName(graph, layerIndex);
3475 auto flatBufferDescriptor = flatBufferLayer->descriptor();
3476 auto flatBufferInputParams = flatBufferLayer->inputParams();
3478 auto qLstmDescriptor = GetQLstmDescriptor(flatBufferDescriptor);
3507 if (!qLstmDescriptor.m_CifgEnabled)
3509 inputToInputWeights =
ToConstTensor(flatBufferInputParams->inputToInputWeights());
3510 recurrentToInputWeights =
ToConstTensor(flatBufferInputParams->recurrentToInputWeights());
3511 inputGateBias =
ToConstTensor(flatBufferInputParams->inputGateBias());
3522 if (qLstmDescriptor.m_ProjectionEnabled)
3524 projectionWeights =
ToConstTensor(flatBufferInputParams->projectionWeights());
3525 projectionBias =
ToConstTensor(flatBufferInputParams->projectionBias());
3536 if (qLstmDescriptor.m_PeepholeEnabled)
3538 if (!qLstmDescriptor.m_CifgEnabled)
3540 cellToInputWeights =
ToConstTensor(flatBufferInputParams->cellToInputWeights());
3544 cellToForgetWeights =
ToConstTensor(flatBufferInputParams->cellToForgetWeights());
3545 cellToOutputWeights =
ToConstTensor(flatBufferInputParams->cellToOutputWeights());
3557 if (qLstmDescriptor.m_LayerNormEnabled)
3559 if (!qLstmDescriptor.m_CifgEnabled)
3561 inputLayerNormWeights =
ToConstTensor(flatBufferInputParams->inputLayerNormWeights());
3565 forgetLayerNormWeights =
ToConstTensor(flatBufferInputParams->forgetLayerNormWeights());
3566 cellLayerNormWeights =
ToConstTensor(flatBufferInputParams->cellLayerNormWeights());
3567 outputLayerNormWeights =
ToConstTensor(flatBufferInputParams->outputLayerNormWeights());
3574 IConnectableLayer* layer = m_Network->AddQLstmLayer(qLstmDescriptor, qLstmInputParams, layerName.c_str());
3585 RegisterInputSlots(graph, layerIndex, layer);
3586 RegisterOutputSlots(graph, layerIndex, layer);
3589 void IDeserializer::DeserializerImpl::ParseQuantizedLstm(
GraphPtr graph,
unsigned int layerIndex)
3593 auto inputs = GetInputs(graph, layerIndex);
3596 auto outputs = GetOutputs(graph, layerIndex);
3599 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_QuantizedLstmLayer();
3600 auto layerName = GetLayerName(graph, layerIndex);
3601 auto flatBufferInputParams = flatBufferLayer->inputParams();
3631 IConnectableLayer* layer = m_Network->AddQuantizedLstmLayer(lstmInputParams, layerName.c_str());
3639 RegisterInputSlots(graph, layerIndex, layer);
3640 RegisterOutputSlots(graph, layerIndex, layer);
3643 void IDeserializer::DeserializerImpl::ParseDequantize(
GraphPtr graph,
unsigned int layerIndex)
3653 const std::string layerName = GetLayerName(graph, layerIndex);
3659 RegisterInputSlots(graph, layerIndex, layer);
3660 RegisterOutputSlots(graph, layerIndex, layer);
3663 void IDeserializer::DeserializerImpl::ParseMerge(
GraphPtr graph,
unsigned int layerIndex)
3673 const std::string layerName = GetLayerName(graph, layerIndex);
3679 RegisterInputSlots(graph, layerIndex, layer);
3680 RegisterOutputSlots(graph, layerIndex, layer);
3683 void IDeserializer::DeserializerImpl::ParseSwitch(
GraphPtr graph,
unsigned int layerIndex)
3686 auto inputs = GetInputs(graph, layerIndex);
3690 auto outputs = GetOutputs(graph, layerIndex);
3693 auto layerName = GetLayerName(graph, layerIndex);
3702 RegisterInputSlots(graph, layerIndex, layer);
3703 RegisterOutputSlots(graph, layerIndex, layer);
3706 void IDeserializer::DeserializerImpl::ParseTile(
GraphPtr graph,
unsigned int layerIndex)
3709 auto inputs = GetInputs(graph, layerIndex);
3713 auto outputs = GetOutputs(graph, layerIndex);
3716 auto TileLayer = graph->layers()->Get(layerIndex)->layer_as_TileLayer();
3717 auto layerName = GetLayerName(graph, layerIndex);
3718 auto flatBufferDescriptor =
TileLayer->descriptor();
3719 auto flatBufferMultiples = flatBufferDescriptor->m_Multiples();
3722 tileDescriptor.
m_Multiples = std::vector<unsigned int>(flatBufferMultiples->begin(), flatBufferMultiples->end());
3724 IConnectableLayer* layer = m_Network->AddTileLayer(tileDescriptor, layerName.c_str());
3729 RegisterInputSlots(graph, layerIndex, layer);
3730 RegisterOutputSlots(graph, layerIndex, layer);
3733 void IDeserializer::DeserializerImpl::ParsePrelu(
GraphPtr graph,
unsigned int layerIndex)
3736 auto inputs = GetInputs(graph, layerIndex);
3740 auto outputs = GetOutputs(graph, layerIndex);
3743 auto layerName = GetLayerName(graph, layerIndex);
3749 RegisterInputSlots(graph, layerIndex, layer);
3750 RegisterOutputSlots(graph, layerIndex, layer);
3753 void IDeserializer::DeserializerImpl::ParseTranspose(
GraphPtr graph,
unsigned int layerIndex)
3757 auto dimsMapping = graph->layers()->Get(layerIndex)->layer_as_TransposeLayer()->descriptor()->dimMappings();
3759 auto inputs = GetInputs(graph, layerIndex);
3762 auto outputs = GetOutputs(graph, layerIndex);
3766 auto layerName = GetLayerName(graph, layerIndex);
3769 IConnectableLayer* layer = m_Network->AddTransposeLayer(descriptor, layerName.c_str());
3772 RegisterInputSlots(graph, layerIndex, layer);
3773 RegisterOutputSlots(graph, layerIndex, layer);
3776 void IDeserializer::DeserializerImpl::ParseTransposeConvolution2d(
GraphPtr graph,
unsigned int layerIndex)
3780 auto inputs = GetInputs(graph, layerIndex);
3783 auto outputs = GetOutputs(graph, layerIndex);
3786 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_TransposeConvolution2dLayer();
3787 auto layerName = GetLayerName(graph, layerIndex);
3788 auto serializerDescriptor = serializerLayer->descriptor();
3791 descriptor.
m_PadLeft = serializerDescriptor->padLeft();
3792 descriptor.
m_PadRight = serializerDescriptor->padRight();
3793 descriptor.
m_PadTop = serializerDescriptor->padTop();
3794 descriptor.
m_PadBottom = serializerDescriptor->padBottom();
3795 descriptor.
m_StrideX = serializerDescriptor->strideX();
3796 descriptor.
m_StrideY = serializerDescriptor->strideY();;
3797 descriptor.
m_BiasEnabled = serializerDescriptor->biasEnabled();;
3806 optionalBiases = armnn::MakeOptional<armnn::ConstTensor>(biases);
3809 IConnectableLayer* layer = m_Network->AddTransposeConvolution2dLayer(descriptor,
3817 RegisterInputSlots(graph, layerIndex, layer);
3818 RegisterOutputSlots(graph, layerIndex, layer);
3821 void IDeserializer::DeserializerImpl::ParseStack(
GraphPtr graph,
unsigned int layerIndex)
3824 auto inputs = GetInputs(graph, layerIndex);
3826 auto outputs = GetOutputs(graph, layerIndex);
3829 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_StackLayer()->descriptor();
3830 unsigned int axis = flatBufferDescriptor->axis();
3831 unsigned int numInputs = flatBufferDescriptor->numInputs();
3834 auto flatBufferInputShape = flatBufferDescriptor->inputShape();
3835 std::vector<uint32_t> vectorInputShape(flatBufferInputShape->begin(),
3836 flatBufferInputShape->begin() + flatBufferInputShape->size());
3838 TensorShape inputShape(
static_cast<unsigned int>(vectorInputShape.size()), vectorInputShape.data());
3841 for (
unsigned int i=0; i<inputs.size(); ++i)
3844 if (descriptor.m_InputShape != inputShape)
3846 std::stringstream ss;
3847 ss <<
"Shape of input "
3851 <<
" does not equal defined input shape "
3852 << descriptor.m_InputShape
3859 auto layerName = GetLayerName(graph, layerIndex);
3860 IConnectableLayer* layer = m_Network->AddStackLayer(descriptor, layerName.c_str());
3865 RegisterInputSlots(graph, layerIndex, layer);
3866 RegisterOutputSlots(graph, layerIndex, layer);
3869 void IDeserializer::DeserializerImpl::ParseStandIn(
GraphPtr graph,
unsigned int layerIndex)
3873 auto inputs = GetInputs(graph, layerIndex);
3874 auto outputs = GetOutputs(graph, layerIndex);
3876 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_StandInLayer();
3877 auto fbDescriptor = fbLayer->descriptor();
3880 descriptor.
m_NumInputs = fbDescriptor->numInputs();
3886 const std::string layerName = GetLayerName(graph, layerIndex);
3889 for (
unsigned int i = 0u; i < descriptor.
m_NumOutputs; ++i)
3895 RegisterInputSlots(graph, layerIndex, layer);
3896 RegisterOutputSlots(graph, layerIndex, layer);
3916 void IDeserializer::DeserializerImpl::ParseUnidirectionalSequenceLstm(
GraphPtr graph,
unsigned int layerIndex)
3920 auto inputs = GetInputs(graph, layerIndex);
3923 auto outputs = GetOutputs(graph, layerIndex);
3926 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_UnidirectionalSequenceLstmLayer();
3927 auto layerName = GetLayerName(graph, layerIndex);
3928 auto flatBufferDescriptor = flatBufferLayer->descriptor();
3929 auto flatBufferInputParams = flatBufferLayer->inputParams();
3931 auto descriptor = GetUnidirectionalSequenceLstmDescriptor(flatBufferDescriptor);
3959 if (!descriptor.m_CifgEnabled)
3961 inputToInputWeights =
ToConstTensor(flatBufferInputParams->inputToInputWeights());
3962 recurrentToInputWeights =
ToConstTensor(flatBufferInputParams->recurrentToInputWeights());
3963 inputGateBias =
ToConstTensor(flatBufferInputParams->inputGateBias());
3969 if (descriptor.m_PeepholeEnabled)
3971 cellToInputWeights =
ToConstTensor(flatBufferInputParams->cellToInputWeights());
3978 if (descriptor.m_ProjectionEnabled)
3980 projectionWeights =
ToConstTensor(flatBufferInputParams->projectionWeights());
3981 projectionBias =
ToConstTensor(flatBufferInputParams->projectionBias());
3989 if (descriptor.m_PeepholeEnabled)
3991 cellToForgetWeights =
ToConstTensor(flatBufferInputParams->cellToForgetWeights());
3992 cellToOutputWeights =
ToConstTensor(flatBufferInputParams->cellToOutputWeights());
4002 if (descriptor.m_LayerNormEnabled)
4004 if (!descriptor.m_CifgEnabled)
4006 inputLayerNormWeights =
ToConstTensor(flatBufferInputParams->inputLayerNormWeights());
4009 forgetLayerNormWeights =
ToConstTensor(flatBufferInputParams->forgetLayerNormWeights());
4010 cellLayerNormWeights =
ToConstTensor(flatBufferInputParams->cellLayerNormWeights());
4011 outputLayerNormWeights =
ToConstTensor(flatBufferInputParams->outputLayerNormWeights());
4018 IConnectableLayer* layer = m_Network->AddUnidirectionalSequenceLstmLayer(descriptor,
4031 RegisterInputSlots(graph, layerIndex, layer);
4032 RegisterOutputSlots(graph, layerIndex, layer);
4035 void IDeserializer::DeserializerImpl::ParseScatterNd(
GraphPtr graph,
unsigned int layerIndex)
4038 auto inputs = GetInputs(graph, layerIndex);
4042 auto outputs = GetOutputs(graph, layerIndex);
4045 auto ScatterNdLayer = graph->layers()->Get(layerIndex)->layer_as_ScatterNdLayer();
4046 auto layerName = GetLayerName(graph, layerIndex);
4051 scatterNdDescriptor.
m_InputEnabled = flatBufferDescriptor->m_InputEnabled();
4052 scatterNdDescriptor.
m_Axis = flatBufferDescriptor->m_Axis();
4053 scatterNdDescriptor.
m_AxisEnabled = flatBufferDescriptor->m_AxisEnabled();
4055 IConnectableLayer* layer = m_Network->AddScatterNdLayer(scatterNdDescriptor, layerName.c_str());
4060 RegisterInputSlots(graph, layerIndex, layer);
4061 RegisterOutputSlots(graph, layerIndex, layer);
#define CHECK_CONST_TENSOR_PTR(TENSOR_PTR)
#define CHECK_LAYERS(GRAPH, LAYERS_INDEX, LAYER_INDEX)
#define CHECK_CONST_TENSOR_SIZE(CONST_TENSOR_SIZE, TENSOR_SIZE)
#define CHECK_GRAPH(GRAPH, LAYERS_INDEX)
#define CHECK_TENSOR_PTR(TENSOR_PTR)
#define ARMNN_LOG(severity)
#define CHECK_VALID_SIZE(ACTUAL,...)
#define CHECKED_NON_NEGATIVE(VALUE)
const TensorInfo & GetInfo() const
MemoryType GetMemoryArea() const
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
Base class for all ArmNN exceptions so that users can filter to just those.
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
virtual const IInputSlot & GetInputSlot(unsigned int index) const =0
Get a const input slot handle by slot index.
virtual const IOutputSlot & GetOutputSlot(unsigned int index) const =0
Get the const output slot handle by slot index.
virtual unsigned int GetNumInputSlots() const =0
Returns the number of connectable input slots.
virtual unsigned int GetNumOutputSlots() const =0
Returns the number of connectable output slots.
An output connection slot for a layer.
virtual void SetTensorInfo(const TensorInfo &tensorInfo)=0
virtual int Connect(IInputSlot &destination)=0
This layer represents a ScatterNd operator.
unsigned int GetNumElements() const
const TensorShape & GetShape() const
void SetConstant(const bool IsConstant=true)
Marks the data corresponding to this tensor info as constant.
unsigned int GetNumBytes() const
void SetShape(const TensorShape &newShape)
DataType GetDataType() const
unsigned int GetNumDimensions() const
Function that returns the tensor rank.
static GraphPtr LoadGraphFromBinary(const uint8_t *binaryContent, size_t len)
static armnn::Pooling3dDescriptor GetPooling3dDescriptor(Pooling3dDescriptor pooling3dDescriptor, unsigned int layerIndex)
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...
armnn::INetworkPtr CreateNetworkFromBinary(const std::vector< uint8_t > &binaryContent)
Create an input network from binary file contents.
static armnn::QLstmDescriptor GetQLstmDescriptor(QLstmDescriptorPtr qLstmDescriptorPtr)
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 ...
static armnn::TensorInfo OutputShapeOfReshape(const armnn::TensorInfo &inputTensorInfo, const std::vector< uint32_t > &targetDimsIn)
static TensorRawPtrVector GetOutputs(const GraphPtr &graph, unsigned int layerIndex)
static armnn::NormalizationDescriptor GetNormalizationDescriptor(NormalizationDescriptorPtr normalizationDescriptor, unsigned int layerIndex)
static LayerBaseRawPtr GetBaseLayer(const GraphPtr &graphPtr, unsigned int layerIndex)
static armnn::Pooling2dDescriptor GetPooling2dDescriptor(Pooling2dDescriptor pooling2dDescriptor, unsigned int layerIndex)
static TensorRawPtrVector GetInputs(const GraphPtr &graph, unsigned int layerIndex)
static armnn::UnidirectionalSequenceLstmDescriptor GetUnidirectionalSequenceLstmDescriptor(UnidirectionalSequenceLstmDescriptorPtr descriptor)
static std::string GetLayerName(const GraphPtr &graph, unsigned int index)
static armnn::LstmDescriptor GetLstmDescriptor(LstmDescriptorPtr lstmDescriptor)
static int32_t GetBindingLayerInfo(const GraphPtr &graphPtr, unsigned int layerIndex)
armnn::INetworkPtr CreateNetworkFromBinary(const std::vector< uint8_t > &binaryContent)
Create an input network from binary file contents.
const armnnSerializer::LstmDescriptor * LstmDescriptorPtr
armnn::ComparisonOperation ToComparisonOperation(armnnSerializer::ComparisonOperation operation)
const armnnSerializer::NormalizationDescriptor * NormalizationDescriptorPtr
armnn::LogicalBinaryOperation ToLogicalBinaryOperation(armnnSerializer::LogicalBinaryOperation operation)
armnn::ActivationFunction ToActivationFunction(armnnSerializer::ActivationFunction function)
const armnnSerializer::SerializedGraph * GraphPtr
armnn::BinaryOperation ToElementwiseBinaryOperation(armnnSerializer::BinaryOperation operation)
const armnnSerializer::QLstmDescriptor * QLstmDescriptorPtr
const armnnSerializer::OriginsDescriptor * GetOriginsDescriptor(const armnnSerializer::SerializedGraph *graph, unsigned int layerIndex)
const armnnSerializer::Pooling3dDescriptor * Pooling3dDescriptor
const armnnSerializer::ConstTensor * ConstTensorRawPtr
const armnnSerializer::Pooling2dDescriptor * Pooling2dDescriptor
const armnnSerializer::TensorInfo * TensorRawPtr
armnn::ResizeMethod ToResizeMethod(armnnSerializer::ResizeMethod method)
armnn::ArgMinMaxFunction ToArgMinMaxFunction(armnnSerializer::ArgMinMaxFunction function)
const armnnSerializer::LayerBase * LayerBaseRawPtr
armnn::TensorInfo ToTensorInfo(TensorRawPtr tensorPtr)
bool CheckShape(const armnn::TensorShape &actual, const std::vector< uint32_t > &expected)
armnn::UnaryOperation ToElementwiseUnaryOperation(armnnSerializer::UnaryOperation operation)
const armnnSerializer::UnidirectionalSequenceLstmDescriptor * UnidirectionalSequenceLstmDescriptorPtr
armnn::ConstTensor ToConstTensor(ConstTensorRawPtr constTensorPtr)
std::vector< TensorRawPtr > TensorRawPtrVector
armnn::PaddingMode ToPaddingMode(armnnSerializer::PaddingMode paddingMode)
std::unique_ptr< IDeserializer, void(*)(IDeserializer *parser)> IDeserializerPtr
armnn::ScatterNdFunction ToScatterNdFunction(armnnSerializer::ScatterNdFunction function)
armnn::DataLayout ToDataLayout(armnnSerializer::DataLayout dataLayout)
armnn::ReduceOperation ToReduceOperation(armnnSerializer::ReduceOperation operation)
Copyright (c) 2021 ARM Limited and Contributors.
PaddingMode
The padding mode controls whether the padding should be filled with constant values (Constant),...
std::pair< armnn::LayerBindingId, armnn::TensorInfo > BindingPointInfo
@ Exclude
The padding fields don't count and are ignored.
@ IgnoreValue
The padding fields count, but are ignored.
void IgnoreUnused(Ts &&...)
@ BoundedReLu
min(a, max(b, input)) ReLu1 & ReLu6.
constexpr unsigned int GetDataTypeSize(DataType dataType)
int LayerBindingId
Type of identifiers for bindable layers (inputs, outputs).
constexpr unsigned int MaxNumOfTensorDimensions
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
@ LocalContrast
Jarret 2009: Local Contrast Normalization.
@ LocalBrightness
Krichevsky 2012: Local Brightness Normalization.
armnn::TensorShape Permuted(const armnn::TensorShape &srcShape, const armnn::PermutationVector &mappings)
void Permute(const armnn::TensorShape &dstShape, const armnn::PermutationVector &mappings, const void *src, void *dst, size_t dataTypeSize)
An ActivationDescriptor for the ActivationLayer.
float m_A
Alpha upper bound value used by the activation functions. (BoundedReLu, Linear, TanH,...
float m_B
Beta lower bound value used by the activation functions. (BoundedReLu, Linear, TanH).
ActivationFunction m_Function
The activation function to use (Sigmoid, TanH, Linear, ReLu, BoundedReLu, SoftReLu,...
An ArgMinMaxDescriptor for ArgMinMaxLayer.
int m_Axis
Axis to reduce across the input tensor.
ArgMinMaxFunction m_Function
Specify if the function is to find Min or Max.
A BatchMatMulDescriptor for the BatchMatMul operator.
A BatchNormalizationDescriptor for the BatchNormalizationLayer.
float m_Eps
Value to add to the variance. Used to avoid dividing by zero.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
A BatchToSpaceNdDescriptor for the BatchToSpaceNdLayer.
std::vector< unsigned int > m_BlockShape
Block shape values.
std::vector< std::pair< unsigned int, unsigned int > > m_Crops
The values to crop from the input dimension.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
A ChannelShuffleDescriptor for the ChannelShuffle operator.
uint32_t m_NumGroups
Number of groups for the channel shuffle operation.
uint32_t m_Axis
Axis to apply channel shuffle operation on.
std::string AsString() const
std::string FileLine() const
A ComparisonDescriptor for the ComparisonLayer.
ComparisonOperation m_Operation
Specifies the comparison operation to execute.
A Convolution2dDescriptor for the Convolution2dLayer.
uint32_t m_PadRight
Padding right value in the width dimension.
uint32_t m_DilationY
Dilation along y axis.
uint32_t m_PadTop
Padding top value in the height dimension.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
uint32_t GetNumInputs() const
uint32_t m_DilationX
Dilation along x axis.
uint32_t m_PadBottom
Padding bottom value in the height dimension.
uint32_t m_PadLeft
Padding left value in the width dimension.
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
bool m_BiasEnabled
Enable/disable bias.
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
A Convolution3dDescriptor for the Convolution3dLayer.
uint32_t m_PadRight
Padding right value in the width dimension.
uint32_t m_PadBack
Padding back value in the depth dimension.
uint32_t m_DilationZ
Dilation along z axis.
uint32_t m_DilationY
Dilation along y axis.
uint32_t m_StrideZ
Stride value when proceeding through input for the depth dimension.
uint32_t m_PadTop
Padding top value in the height dimension.
DataLayout m_DataLayout
The data layout to be used (NDHWC, NCDHW).
uint32_t GetNumInputs() const
Get the number of views/inputs.
uint32_t m_PadFront
Padding front value in the depth dimension.
uint32_t m_DilationX
Dilation along x axis.
uint32_t m_PadBottom
Padding bottom value in the height dimension.
uint32_t m_PadLeft
Padding left value in the width dimension.
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
bool m_BiasEnabled
Enable/disable bias.
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
A DepthwiseConvolution2dDescriptor for the DepthwiseConvolution2dLayer.
uint32_t m_PadRight
Padding right value in the width dimension.
uint32_t m_DilationY
Dilation factor value for height dimension.
uint32_t m_PadTop
Padding top value in the height dimension.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
uint32_t GetNumInputs() const
Get the number of views/inputs.
uint32_t m_DilationX
Dilation factor value for width dimension.
uint32_t m_PadBottom
Padding bottom value in the height dimension.
uint32_t m_PadLeft
Padding left value in the width dimension.
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
bool m_BiasEnabled
Enable/disable bias.
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
uint32_t m_NumClasses
Number of classes.
float m_NmsScoreThreshold
NMS score threshold.
float m_NmsIouThreshold
Intersection over union threshold.
float m_ScaleY
Center size encoding scale y.
uint32_t m_DetectionsPerClass
Detections per classes, used in Regular NMS.
bool m_UseRegularNms
Use Regular NMS.
uint32_t m_MaxClassesPerDetection
Maximum numbers of classes per detection, used in Fast NMS.
float m_ScaleH
Center size encoding scale height.
float m_ScaleW
Center size encoding scale weight.
float m_ScaleX
Center size encoding scale x.
uint32_t m_MaxDetections
Maximum numbers of detections.
A ElementwiseBinaryDescriptor for the ElementwiseBinaryLayer.
BinaryOperation m_Operation
Specifies the elementwiseBinary operation to execute.
A ElementwiseUnaryDescriptor for the ElementwiseUnaryLayer.
UnaryOperation m_Operation
Specifies the elementwiseUnary operation to execute.
EmptyOptional is used to initialize the Optional class in case we want to have default value for an O...
A FillDescriptor for the FillLayer.
A FullyConnectedDescriptor for the FullyConnectedLayer.
bool m_TransposeWeightMatrix
Enable/disable transpose weight matrix.
bool m_ConstantWeights
Enable/disable constant weights and biases.
uint32_t GetNumInputs() const
Get the number of inputs.
bool m_BiasEnabled
Enable/disable bias.
A GatherDescriptor for the GatherLayer.
int32_t m_Axis
The axis in params to gather indices from.
An InstanceNormalizationDescriptor for InstanceNormalizationLayer.
float m_Eps
Epsilon, small scalar value added to variance to avoid dividing by zero. Defaults to 1e-12f.
float m_Gamma
Gamma, the scale scalar value applied for the normalized tensor. Defaults to 1.0.
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.
A L2NormalizationDescriptor for the L2NormalizationLayer.
float m_Eps
Used to avoid dividing by zero.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
A LogicalBinaryDescriptor for the LogicalBinaryLayer.
LogicalBinaryOperation m_Operation
Specifies the logical operation to execute.
An LstmDescriptor for the LstmLayer.
bool m_PeepholeEnabled
Enable/disable peephole.
bool m_TimeMajor
Enable/disable time major.
bool m_LayerNormEnabled
Enable/disable layer normalization.
float m_ClippingThresCell
Clipping threshold value for the cell state.
bool m_ProjectionEnabled
Enable/disable the projection layer.
float m_ClippingThresProj
Clipping threshold value for the projection.
bool m_CifgEnabled
Enable/disable cifg (coupled input & forget gate).
uint32_t m_ActivationFunc
The activation function to use.
A MeanDescriptor for the MeanLayer.
std::vector< unsigned int > m_Axis
Values for the dimensions to reduce.
bool m_KeepDims
Enable/disable keep dimensions. If true, then the reduced dimensions that are of length 1 are kept.
A NormalizationDescriptor for the NormalizationLayer.
NormalizationAlgorithmMethod m_NormMethodType
Normalization method algorithm to use (LocalBrightness, LocalContrast).
float m_Alpha
Alpha value for the normalization equation.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
float m_Beta
Beta value for the normalization equation.
float m_K
Kappa value used for the across channel normalization equation.
uint32_t m_NormSize
Depth radius value.
NormalizationAlgorithmChannel m_NormChannelType
Normalization channel algorithm to use (Across, Within).
An OriginsDescriptor for the ConcatLayer.
A PadDescriptor for the PadLayer.
A PermuteDescriptor for the PermuteLayer.
A Pooling2dDescriptor for the Pooling2dLayer.
uint32_t m_PadRight
Padding right value in the width dimension.
PoolingAlgorithm m_PoolType
The pooling algorithm to use (Max. Average, L2).
uint32_t m_PoolHeight
Pooling height value.
uint32_t m_PadTop
Padding top value in the height dimension.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
uint32_t m_PoolWidth
Pooling width value.
PaddingMethod m_PaddingMethod
The padding method to be used. (Exclude, IgnoreValue).
uint32_t m_PadBottom
Padding bottom value in the height dimension.
uint32_t m_PadLeft
Padding left value in the width dimension.
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
OutputShapeRounding m_OutputShapeRounding
The rounding method for the output shape. (Floor, Ceiling).
A Pooling3dDescriptor for the Pooling3dLayer.
uint32_t m_PadRight
Padding right value in the width dimension.
PoolingAlgorithm m_PoolType
The pooling algorithm to use (Max. Average, L2).
uint32_t m_PadBack
Padding back value in the depth dimension.
uint32_t m_StrideZ
Stride value when proceeding through input for the depth dimension.
uint32_t m_PoolHeight
Pooling height value.
uint32_t m_PadTop
Padding top value in the height dimension.
DataLayout m_DataLayout
The data layout to be used (NCDHW, NDHWC).
uint32_t m_PoolWidth
Pooling width value.
uint32_t m_PadFront
Padding front value in the depth dimension.
PaddingMethod m_PaddingMethod
The padding method to be used. (Exclude, IgnoreValue).
uint32_t m_PadBottom
Padding bottom value in the height dimension.
uint32_t m_PadLeft
Padding left value in the width dimension.
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
uint32_t m_PoolDepth
Pooling depth value.
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
OutputShapeRounding m_OutputShapeRounding
The rounding method for the output shape. (Floor, Ceiling).
A QLstmDescriptor for the QLstmLayer.
float m_CellIntermediateScale
Cell intermediate quantization scale.
float m_InputIntermediateScale
Input intermediate quantization scale.
bool m_PeepholeEnabled
Enable/disable peephole.
int32_t m_HiddenStateZeroPoint
Hidden State zero point.
bool m_LayerNormEnabled
Enable/disable layer normalization.
bool m_ProjectionEnabled
Enable/disable the projection layer.
float m_OutputIntermediateScale
Output intermediate quantization scale.
float m_ProjectionClip
Clipping threshold value for the projection.
float m_CellClip
Clipping threshold value for the cell state.
bool m_CifgEnabled
Enable/disable CIFG (coupled input & forget gate).
float m_HiddenStateScale
Hidden State quantization scale.
float m_ForgetIntermediateScale
Forget intermediate quantization scale.
A ReduceDescriptor for the REDUCE operators.
bool m_KeepDims
if true then output shape has no change.
std::vector< uint32_t > m_vAxis
The indices of the dimensions to reduce.
ReduceOperation m_ReduceOperation
Specifies the reduction operation to execute.
A ReshapeDescriptor for the ReshapeLayer.
TensorShape m_TargetShape
Target shape value.
A ResizeDescriptor for the ResizeLayer.
bool m_HalfPixelCenters
Half Pixel Centers.
uint32_t m_TargetHeight
Target height value.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
ResizeMethod m_Method
The Interpolation method to use (Bilinear, NearestNeighbor).
uint32_t m_TargetWidth
Target width value.
bool m_AlignCorners
Aligned corners.
A ScatterNdDescriptor for the ScatterNdLayer.
bool m_InputEnabled
Flag to show if input tensor is accepted.
ScatterNdFunction m_Function
Specify if the function is update, add, sub, max or min.
int32_t m_Axis
Extra attribute for ScatterElement, will be set to 0 by default, we do not support axis !...
bool m_AxisEnabled
Flag for ScatterElement, will be set to false by default, we do not support m_AxisEnable = true for n...
A SliceDescriptor for the SliceLayer.
std::vector< unsigned int > m_Begin
Beginning indices of the slice in each dimension.
std::vector< unsigned int > m_Size
Size of the slice in each dimension.
A SoftmaxDescriptor for the SoftmaxLayer.
int m_Axis
Scalar, defaulted to the last index (-1), specifying the dimension the activation will be performed o...
float m_Beta
Exponentiation value.
A SpaceToBatchNdDescriptor for the SpaceToBatchNdLayer.
std::vector< unsigned int > m_BlockShape
Block shape value.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
std::vector< std::pair< unsigned int, unsigned int > > m_PadList
Specifies the padding values for the input dimension: heightPad{top, bottom} widthPad{left,...
A SpaceToDepthDescriptor for the SpaceToDepthLayer.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
unsigned int m_BlockSize
Scalar specifying the input block size. It must be >= 1.
A StackDescriptor for the StackLayer.
A StandInDescriptor for the StandIn layer.
uint32_t m_NumOutputs
Number of output tensors.
uint32_t m_NumInputs
Number of input tensors.
A StridedSliceDescriptor for the StridedSliceLayer.
std::vector< uint32_t > m_Multiples
The vector to multiply the input shape by.
A TransposeConvolution2dDescriptor for the TransposeConvolution2dLayer.
uint32_t m_PadRight
Padding right value in the width dimension.
uint32_t m_PadTop
Padding top value in the height dimension.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
uint32_t m_PadBottom
Padding bottom value in the height dimension.
uint32_t m_PadLeft
Padding left value in the width dimension.
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
bool m_BiasEnabled
Enable/disable bias.
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
A TransposeDescriptor for the TransposeLayer.
A ViewsDescriptor for the SplitterLayer.