23 #include <fmt/format.h> 31 using namespace armnn;
37 IDeserializer::IDeserializer() : pDeserializerImpl(new DeserializerImpl()){}
39 IDeserializer::~IDeserializer() =
default;
56 armnn::INetworkPtr IDeserializer::CreateNetworkFromBinary(
const std::vector<uint8_t> &binaryContent)
63 return pDeserializerImpl->CreateNetworkFromBinary(binaryContent);
66 BindingPointInfo IDeserializer::GetNetworkInputBindingInfo(
unsigned int layerId,
const std::string &name)
const 68 return pDeserializerImpl->GetNetworkInputBindingInfo(layerId, name);
71 BindingPointInfo IDeserializer::GetNetworkOutputBindingInfo(
unsigned int layerId,
const std::string &name)
const 73 return pDeserializerImpl->GetNetworkOutputBindingInfo(layerId, name);
79 const uint32_t VIRTUAL_LAYER_ID = std::numeric_limits<uint32_t>::max();
81 void CheckGraph(
const GraphPtr& graph,
82 unsigned int layersIndex,
85 if (graph->layers() ==
nullptr)
87 throw ParseException(fmt::format(
"{0} was called with invalid (null) graph. " 88 "Possible reason is that the graph is not yet loaded and Unpack(ed). " 94 else if (layersIndex >= graph->layers()->size())
96 throw ParseException(fmt::format(
"{0} was called with an invalid layers index. layers:{1} at {2}",
104 unsigned int layersIndex,
105 unsigned int layerIndex,
108 if (graph->layers() ==
nullptr)
110 throw ParseException(fmt::format(
"{0} was called with invalid (null) graph. " 111 "Possible reason is that the graph is not yet loaded and Unpack(ed). " 117 else if (layersIndex >= graph->layers()->size())
119 throw ParseException(fmt::format(
"{0} was called with an invalid layers index. " 125 else if (layerIndex >= graph->layers()[layersIndex].size()
126 && layerIndex != VIRTUAL_LAYER_ID)
128 throw ParseException(fmt::format(
"{0} was called with an invalid layer index. " 129 "layers:{1} layer:{2} at {3}",
140 if (rawPtr ==
nullptr)
142 throw ParseException(fmt::format(
"{0} was called with a null tensor pointer. at {1}",
151 if (rawPtr ==
nullptr)
153 throw ParseException(fmt::format(
"{0} was called with a null const tensor pointer. at {1}",
159 void CheckConstTensorSize(
const unsigned int constTensorSize,
160 const unsigned int tensorSize,
163 if (constTensorSize != tensorSize)
165 throw ParseException(fmt::format(
"{0} wrong number of components supplied to tensor. at:{1}",
171 #define CHECK_TENSOR_PTR(TENSOR_PTR) \ 172 CheckTensorPtr(TENSOR_PTR, CHECK_LOCATION()) 174 #define CHECK_CONST_TENSOR_SIZE(CONST_TENSOR_SIZE, TENSOR_SIZE) \ 175 CheckConstTensorSize(CONST_TENSOR_SIZE, TENSOR_SIZE, CHECK_LOCATION()) 177 #define CHECK_CONST_TENSOR_PTR(TENSOR_PTR) \ 178 CheckConstTensorPtr(TENSOR_PTR, CHECK_LOCATION()) 180 #define CHECK_LAYERS(GRAPH, LAYERS_INDEX, LAYER_INDEX) \ 181 CheckLayers(GRAPH, LAYERS_INDEX, LAYER_INDEX, CHECK_LOCATION()) 183 #define CHECK_GRAPH(GRAPH, LAYERS_INDEX) \ 184 CheckGraph(GRAPH, LAYERS_INDEX, CHECK_LOCATION()) 190 if (actualSize != expected.size())
195 for (
unsigned int i = 0u; i < actualSize; i++)
197 if (actual[i] != static_cast<unsigned int>(expected[i]))
206 IDeserializer::DeserializerImpl::DeserializerImpl()
207 : m_Network(nullptr, nullptr),
280 auto layerType = graphPtr->layers()->Get(layerIndex)->layer_type();
285 return graphPtr->layers()->Get(layerIndex)->layer_as_AbsLayer()->base();
287 return graphPtr->layers()->Get(layerIndex)->layer_as_ActivationLayer()->base();
289 return graphPtr->layers()->Get(layerIndex)->layer_as_AdditionLayer()->base();
291 return graphPtr->layers()->Get(layerIndex)->layer_as_ArgMinMaxLayer()->base();
293 return graphPtr->layers()->Get(layerIndex)->layer_as_BatchToSpaceNdLayer()->base();
295 return graphPtr->layers()->Get(layerIndex)->layer_as_BatchNormalizationLayer()->base();
297 return graphPtr->layers()->Get(layerIndex)->layer_as_CastLayer()->base();
299 return graphPtr->layers()->Get(layerIndex)->layer_as_ChannelShuffleLayer()->base();
301 return graphPtr->layers()->Get(layerIndex)->layer_as_ComparisonLayer()->base();
303 return graphPtr->layers()->Get(layerIndex)->layer_as_ConcatLayer()->base();
305 return graphPtr->layers()->Get(layerIndex)->layer_as_ConstantLayer()->base();
307 return graphPtr->layers()->Get(layerIndex)->layer_as_Convolution2dLayer()->base();
309 return graphPtr->layers()->Get(layerIndex)->layer_as_Convolution3dLayer()->base();
311 return graphPtr->layers()->Get(layerIndex)->layer_as_DepthToSpaceLayer()->base();
313 return graphPtr->layers()->Get(layerIndex)->layer_as_DepthwiseConvolution2dLayer()->base();
315 return graphPtr->layers()->Get(layerIndex)->layer_as_DequantizeLayer()->base();
317 return graphPtr->layers()->Get(layerIndex)->layer_as_DetectionPostProcessLayer()->base();
319 return graphPtr->layers()->Get(layerIndex)->layer_as_DivisionLayer()->base();
321 return graphPtr->layers()->Get(layerIndex)->layer_as_EqualLayer()->base();
323 return graphPtr->layers()->Get(layerIndex)->layer_as_ElementwiseUnaryLayer()->base();
325 return graphPtr->layers()->Get(layerIndex)->layer_as_FullyConnectedLayer()->base();
327 return graphPtr->layers()->Get(layerIndex)->layer_as_FillLayer()->base();
329 return graphPtr->layers()->Get(layerIndex)->layer_as_FloorLayer()->base();
331 return graphPtr->layers()->Get(layerIndex)->layer_as_GatherLayer()->base();
333 return graphPtr->layers()->Get(layerIndex)->layer_as_GreaterLayer()->base();
335 return graphPtr->layers()->Get(layerIndex)->layer_as_InputLayer()->base()->base();
337 return graphPtr->layers()->Get(layerIndex)->layer_as_InstanceNormalizationLayer()->base();
339 return graphPtr->layers()->Get(layerIndex)->layer_as_L2NormalizationLayer()->base();
341 return graphPtr->layers()->Get(layerIndex)->layer_as_LogicalBinaryLayer()->base();
343 return graphPtr->layers()->Get(layerIndex)->layer_as_LogSoftmaxLayer()->base();
345 return graphPtr->layers()->Get(layerIndex)->layer_as_LstmLayer()->base();
347 return graphPtr->layers()->Get(layerIndex)->layer_as_MeanLayer()->base();
349 return graphPtr->layers()->Get(layerIndex)->layer_as_MinimumLayer()->base();
351 return graphPtr->layers()->Get(layerIndex)->layer_as_MaximumLayer()->base();
353 return graphPtr->layers()->Get(layerIndex)->layer_as_MergeLayer()->base();
355 return graphPtr->layers()->Get(layerIndex)->layer_as_MergerLayer()->base();
357 return graphPtr->layers()->Get(layerIndex)->layer_as_MultiplicationLayer()->base();
359 return graphPtr->layers()->Get(layerIndex)->layer_as_NormalizationLayer()->base();
361 return graphPtr->layers()->Get(layerIndex)->layer_as_OutputLayer()->base()->base();
363 return graphPtr->layers()->Get(layerIndex)->layer_as_PadLayer()->base();
365 return graphPtr->layers()->Get(layerIndex)->layer_as_PermuteLayer()->base();
367 return graphPtr->layers()->Get(layerIndex)->layer_as_Pooling2dLayer()->base();
369 return graphPtr->layers()->Get(layerIndex)->layer_as_PreluLayer()->base();
371 return graphPtr->layers()->Get(layerIndex)->layer_as_QLstmLayer()->base();
373 return graphPtr->layers()->Get(layerIndex)->layer_as_QuantizeLayer()->base();
375 return graphPtr->layers()->Get(layerIndex)->layer_as_QuantizedLstmLayer()->base();
377 return graphPtr->layers()->Get(layerIndex)->layer_as_RankLayer()->base();
379 return graphPtr->layers()->Get(layerIndex)->layer_as_ReduceLayer()->base();
381 return graphPtr->layers()->Get(layerIndex)->layer_as_ReshapeLayer()->base();
383 return graphPtr->layers()->Get(layerIndex)->layer_as_ResizeBilinearLayer()->base();
385 return graphPtr->layers()->Get(layerIndex)->layer_as_ResizeLayer()->base();
387 return graphPtr->layers()->Get(layerIndex)->layer_as_RsqrtLayer()->base();
389 return graphPtr->layers()->Get(layerIndex)->layer_as_ShapeLayer()->base();
391 return graphPtr->layers()->Get(layerIndex)->layer_as_SliceLayer()->base();
393 return graphPtr->layers()->Get(layerIndex)->layer_as_SoftmaxLayer()->base();
395 return graphPtr->layers()->Get(layerIndex)->layer_as_SpaceToBatchNdLayer()->base();
397 return graphPtr->layers()->Get(layerIndex)->layer_as_SpaceToDepthLayer()->base();
399 return graphPtr->layers()->Get(layerIndex)->layer_as_SplitterLayer()->base();
401 return graphPtr->layers()->Get(layerIndex)->layer_as_StackLayer()->base();
403 return graphPtr->layers()->Get(layerIndex)->layer_as_StandInLayer()->base();
405 return graphPtr->layers()->Get(layerIndex)->layer_as_StridedSliceLayer()->base();
407 return graphPtr->layers()->Get(layerIndex)->layer_as_SubtractionLayer()->base();
409 return graphPtr->layers()->Get(layerIndex)->layer_as_SwitchLayer()->base();
411 return graphPtr->layers()->Get(layerIndex)->layer_as_TransposeConvolution2dLayer()->base();
413 return graphPtr->layers()->Get(layerIndex)->layer_as_TransposeLayer()->base();
415 return graphPtr->layers()->Get(layerIndex)->layer_as_UnidirectionalSequenceLstmLayer()->base();
418 throw ParseException(fmt::format(
"Layer type {} not recognized", layerType));
426 return layer->layerName()->str();
431 auto layerType = graphPtr->layers()->Get(layerIndex)->layer_type();
435 return graphPtr->layers()->Get(layerIndex)->layer_as_InputLayer()->base()->layerBindingId();
439 return graphPtr->layers()->Get(layerIndex)->layer_as_OutputLayer()->base()->layerBindingId();
611 switch (tensorPtr->dataType())
645 throw ParseException(fmt::format(
"Unsupported data type {0} = {1}. {2}",
646 tensorPtr->dataType(),
652 float quantizationScale = tensorPtr->quantizationScale();
653 int32_t quantizationOffset = tensorPtr->quantizationOffset();
655 if (tensorPtr->dimensionality() ==
static_cast<unsigned int>(Dimensionality::Scalar))
662 else if (tensorPtr->dimensionality() ==
static_cast<unsigned int>(Dimensionality::NotSpecified))
671 auto dimensions = tensorPtr->dimensions();
672 unsigned int size = dimensions->size();
673 std::vector<unsigned int> outputDims(dimensions->begin(), dimensions->begin() + size);
678 if (tensorPtr->dimensionSpecificity() !=
nullptr)
680 auto dimensionSpecificity = tensorPtr->dimensionSpecificity();
681 size = dimensionSpecificity->size();
682 for (
unsigned int i = 0; i < size; ++i)
684 dimensionsSpecificity[i] = dimensionSpecificity->Get(i);
688 TensorShape shape(size, outputDims.data(), dimensionsSpecificity);
690 auto quantizationScales = tensorPtr->quantizationScales();
691 if (quantizationScales)
693 unsigned int quantizationScalesSize = quantizationScales->size();
694 std::vector<float> scales(quantizationScales->begin(), quantizationScales->begin() + quantizationScalesSize);
695 unsigned int quantizationDim = tensorPtr->quantizationDim();
718 switch (constTensorPtr->data_type())
722 auto byteData = constTensorPtr->data_as_ByteData()->data();
728 auto shortData = constTensorPtr->data_as_ShortData()->data();
734 auto intData = constTensorPtr->data_as_IntData()->data();
740 auto longData = constTensorPtr->data_as_LongData()->data();
747 throw ParseException(fmt::format(
"Unsupported data type {0} = {1}. {2}",
748 constTensorPtr->data_type(),
759 const auto& numInputs = layer->inputSlots()->size();
763 for (
unsigned int i=0; i<numInputs; ++i)
766 (layer->inputSlots()->Get(i)->connection()->sourceLayerIndex()));
767 result[i] =
GetBaseLayer(graphPtr, inputId)->outputSlots()->Get(0)->tensorInfo();
776 const auto& numOutputs = layer->outputSlots()->size();
780 for (
unsigned int i=0; i<numOutputs; ++i)
782 result[i] = layer->outputSlots()->Get(i)->tensorInfo();
787 void IDeserializer::DeserializerImpl::ParseUnsupportedLayer(
GraphPtr graph,
unsigned int layerIndex)
790 const auto layerName =
GetBaseLayer(graph, layerIndex)->layerName()->c_str();
791 throw ParseException(fmt::format(
"Layer not supported. layerIndex: {0} " 792 "layerName: {1} / {2}",
798 void IDeserializer::DeserializerImpl::ResetParser()
801 m_InputBindings.clear();
802 m_OutputBindings.clear();
810 return CreateNetworkFromGraph(graph);
816 std::vector<uint8_t> content((std::istreambuf_iterator<char>(binaryContent)), std::istreambuf_iterator<char>());
818 return CreateNetworkFromGraph(graph);
823 if (binaryContent ==
nullptr)
828 flatbuffers::Verifier verifier(binaryContent, len);
829 if (verifier.VerifyBuffer<SerializedGraph>() ==
false)
831 throw ParseException(fmt::format(
"Buffer doesn't conform to the expected Armnn " 832 "flatbuffers format. size:{0} {1}",
841 m_Network = INetwork::Create();
843 unsigned int layerIndex = 0;
844 for (AnyLayer
const* layer : *graph->layers())
850 auto& parserFunction = m_ParserFunctions[layer->layer_type()];
851 (this->*parserFunction)(graph, layerIndex);
856 SetupInputLayers(graph);
857 SetupOutputLayers(graph);
860 for (
auto&& graphIt : m_GraphConnections)
862 Connections& connections = graphIt.second;
863 for (
auto&& outputIt : connections.outputSlots)
865 const unsigned int outputSlotIndex = outputIt.first;
867 if (connections.inputSlots.find(outputSlotIndex) != connections.inputSlots.end())
869 for (
IInputSlot* inputSlot : connections.inputSlots[outputSlotIndex])
871 outputSlot->
Connect(*inputSlot);
877 return std::move(m_Network);
881 const std::string& name)
const 884 for (
auto inputBinding : m_InputBindings)
886 if (inputBinding.first == name)
888 return inputBinding.second;
891 throw ParseException(fmt::format(
"No input binding found for layer:{0} / {1}",
897 const std::string& name)
const 900 for (
auto outputBinding : m_OutputBindings)
902 if (outputBinding.first == name)
904 return outputBinding.second;
907 throw ParseException(fmt::format(
"No output binding found for layer:{0} / {1}",
912 unsigned int IDeserializer::DeserializerImpl::GetInputLayerInVector(
GraphPtr graph,
int targetId)
914 for (
unsigned int i = 0; i < graph->layers()->size(); i++)
916 auto layer = graph->layers()->Get(i);
919 auto layerBindingId = layer->layer_as_InputLayer()->base()->layerBindingId();
920 if (layerBindingId == targetId)
926 throw ParseException(
"Input layer with given layerBindingId not found");
929 unsigned int IDeserializer::DeserializerImpl::GetOutputLayerInVector(
GraphPtr graph,
int targetId)
931 for (
unsigned int i = 0; i < graph->layers()->size(); i++)
933 auto layer = graph->layers()->Get(i);
936 auto layerBindingId = layer->layer_as_OutputLayer()->base()->layerBindingId();
937 if (layerBindingId == targetId)
943 throw ParseException(
"Output layer with given layerBindingId not found");
946 unsigned int IDeserializer::DeserializerImpl::GetLayerIndexInVector(
GraphPtr graph,
unsigned int targetIndex)
948 for (
unsigned int i = 0; i < graph->layers()->size(); i++)
951 if (layer->index() == targetIndex)
959 IDeserializer::DeserializerImpl::FeatureVersions IDeserializer::DeserializerImpl::GetFeatureVersions(
GraphPtr graph)
961 IDeserializer::DeserializerImpl::FeatureVersions versions;
963 if (graph->featureVersions())
965 versions.m_BindingIdScheme = graph->featureVersions()->bindingIdsScheme();
966 versions.m_WeightsLayoutScheme = graph->featureVersions()->weightsLayoutScheme();
967 versions.m_ConstTensorsAsInputs = graph->featureVersions()->constantTensorsAsInputs();
973 void IDeserializer::DeserializerImpl::SetupInputLayers(
GraphPtr graph)
976 const unsigned int numInputs = graph->inputIds()->size();
977 m_InputBindings.clear();
978 m_InputBindings.reserve(numInputs);
980 for (
unsigned int i = 0; i < numInputs; i++)
982 unsigned int inputLayerIndex = 0xFFFFFFFF;
983 if (GetFeatureVersions(graph).m_BindingIdScheme == 0)
986 inputLayerIndex = GetLayerIndexInVector(graph, inputId);
990 const int inputId = graph->inputIds()->Get(i);
991 inputLayerIndex = GetInputLayerInVector(graph, inputId);
1001 m_Network->AddInputLayer(bindingId, baseLayer->layerName()->c_str());
1004 inputLayer->GetOutputSlot(0).SetTensorInfo(tensorInfo);
1005 RegisterOutputSlots(graph, inputLayerIndex, inputLayer);
1008 m_InputBindings.push_back(std::make_pair(baseLayer->layerName()->c_str(), bindingInfo));
1012 void IDeserializer::DeserializerImpl::SetupOutputLayers(
GraphPtr graph)
1015 const unsigned int numOutputs = graph->outputIds()->size();
1016 m_OutputBindings.clear();
1017 m_OutputBindings.reserve(numOutputs);
1019 for (
unsigned int i = 0; i < numOutputs; i++)
1021 unsigned int outputLayerIndex = 0xFFFFFFFF;
1022 if (GetFeatureVersions(graph).m_BindingIdScheme == 0)
1024 const unsigned int outputId =
armnn::numeric_cast<
unsigned int>(graph->outputIds()->Get(i));
1025 outputLayerIndex = GetLayerIndexInVector(graph, outputId);
1029 const int outputId = graph->outputIds()->Get(i);
1030 outputLayerIndex = GetOutputLayerInVector(graph, outputId);
1040 m_Network->AddOutputLayer(bindingId, baseLayer->layerName()->c_str());
1042 RegisterInputSlots(graph, outputLayerIndex, outputLayer);
1043 unsigned int sourceLayerIndex =
1044 GetLayerIndexInVector(graph, baseLayer->inputSlots()->Get(0)->connection()->sourceLayerIndex());
1045 unsigned int outputSlotIndex =
1046 GetLayerIndexInVector(graph, baseLayer->inputSlots()->Get(0)->connection()->outputSlotIndex());
1049 sourceBaseLayer->outputSlots()->Get(outputSlotIndex)->tensorInfo());
1051 m_OutputBindings.push_back(std::make_pair(baseLayer->layerName()->c_str(), bindingInfo));
1055 void IDeserializer::DeserializerImpl::RegisterOutputSlots(
GraphPtr graph,
1056 uint32_t layerIndex,
1064 throw ParseException(fmt::format(
"The number of outputslots ({0}) does not match the number expected ({1})" 1065 " for layer index: {2} {3}",
1066 baseLayer->outputSlots()->size(),
1074 const unsigned int slotIndex = baseLayer->outputSlots()->Get(i)->index();
1077 RegisterOutputSlotOfConnection(baseLayer->index(), slotIndex, outputSlot);
1081 void IDeserializer::DeserializerImpl::RegisterInputSlots(
GraphPtr graph,
1082 uint32_t layerIndex,
1084 std::vector<unsigned int> ignoreSlots)
1090 if (baseLayer->inputSlots()->size() != (layer->
GetNumInputSlots() - ignoreSlots.size()))
1092 throw ParseException(fmt::format(
"The number of inputslots ({0}) does not match the number expected ({1})" 1093 " for layer index:{2} {3}",
1094 baseLayer->inputSlots()->size(),
1103 if (std::find(ignoreSlots.begin(), ignoreSlots.end(), i) == ignoreSlots.end())
1105 auto fbInputSlot = baseLayer->inputSlots()->Get(i);
1106 auto fbConnection = fbInputSlot->connection();
1108 RegisterInputSlotOfConnection(fbConnection->sourceLayerIndex(), fbConnection->outputSlotIndex(), inputSlot);
1113 void IDeserializer::DeserializerImpl::RegisterInputSlotOfConnection(uint32_t sourceLayerIndex,
1114 uint32_t outputSlotIndex,
1117 if (m_GraphConnections.find(sourceLayerIndex) == m_GraphConnections.end())
1119 m_GraphConnections[sourceLayerIndex] = Connections();
1122 Connections& connections = m_GraphConnections[sourceLayerIndex];
1123 if (connections.inputSlots.find(outputSlotIndex) == connections.inputSlots.end())
1125 connections.inputSlots[outputSlotIndex] = {inputSlot};
1129 connections.inputSlots[outputSlotIndex].push_back(inputSlot);
1133 void IDeserializer::DeserializerImpl::RegisterOutputSlotOfConnection(uint32_t sourceLayerIndex,
1134 uint32_t outputSlotIndex,
1137 if (m_GraphConnections.find(sourceLayerIndex) == m_GraphConnections.end())
1139 m_GraphConnections[sourceLayerIndex] = Connections();
1142 Connections& connections = m_GraphConnections[sourceLayerIndex];
1143 if (connections.outputSlots.find(outputSlotIndex) != connections.outputSlots.end())
1148 connections.outputSlots[outputSlotIndex] = outputSlot;
1151 void IDeserializer::DeserializerImpl::ParseAbs(
GraphPtr graph,
unsigned int layerIndex)
1154 auto inputs =
GetInputs(graph, layerIndex);
1158 auto outputs =
GetOutputs(graph, layerIndex);
1164 IConnectableLayer* layer = m_Network->AddElementwiseUnaryLayer(descriptor, layerName.c_str());
1168 RegisterInputSlots(graph, layerIndex, layer);
1169 RegisterOutputSlots(graph, layerIndex, layer);
1172 void IDeserializer::DeserializerImpl::ParseActivation(
GraphPtr graph,
unsigned int layerIndex)
1175 auto inputs =
GetInputs(graph, layerIndex);
1179 auto outputs =
GetOutputs(graph, layerIndex);
1182 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_ActivationLayer();
1184 auto serializerDescriptor = serializerLayer->descriptor();
1188 descriptor.
m_A = serializerDescriptor->a();
1189 descriptor.
m_B = serializerDescriptor->b();
1196 RegisterInputSlots(graph, layerIndex, layer);
1197 RegisterOutputSlots(graph, layerIndex, layer);
1200 void IDeserializer::DeserializerImpl::ParseAdd(
GraphPtr graph,
unsigned int layerIndex)
1203 auto inputs =
GetInputs(graph, layerIndex);
1207 auto outputs =
GetOutputs(graph, layerIndex);
1216 RegisterInputSlots(graph, layerIndex, layer);
1217 RegisterOutputSlots(graph, layerIndex, layer);
1220 void IDeserializer::DeserializerImpl::ParseArgMinMax(
GraphPtr graph,
unsigned int layerIndex)
1223 auto inputs =
GetInputs(graph, layerIndex);
1227 auto outputs =
GetOutputs(graph, layerIndex);
1230 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_ArgMinMaxLayer();
1231 auto serializerDescriptor = serializerLayer->descriptor();
1235 descriptor.
m_Axis = serializerDescriptor->axis();
1237 IConnectableLayer* layer = m_Network->AddArgMinMaxLayer(descriptor, layerName.c_str());
1242 RegisterInputSlots(graph, layerIndex, layer);
1243 RegisterOutputSlots(graph, layerIndex, layer);
1246 void IDeserializer::DeserializerImpl::ParseBatchToSpaceNd(
GraphPtr graph,
unsigned int layerIndex)
1256 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_BatchToSpaceNdLayer()->descriptor();
1257 auto flatBufferCrops = flatBufferDescriptor->crops();
1258 auto flatBufferBlockShape = flatBufferDescriptor->blockShape();
1260 if (flatBufferCrops->Length() % 2 != 0)
1265 std::vector<std::pair<unsigned int, unsigned int>> crops;
1266 crops.reserve(flatBufferCrops->Length() / 2);
1267 for (
unsigned int i = 0; i < flatBufferCrops->Length() - 1; i += 2)
1269 crops.emplace_back(flatBufferCrops->Get(i), flatBufferCrops->Get(i+1));
1275 std::vector<unsigned int>(flatBufferBlockShape->begin(), flatBufferBlockShape->end());
1279 IConnectableLayer* layer = m_Network->AddBatchToSpaceNdLayer(descriptor, layerName.c_str());
1284 RegisterInputSlots(graph, layerIndex, layer);
1285 RegisterOutputSlots(graph, layerIndex, layer);
1288 void IDeserializer::DeserializerImpl::ParseBatchNormalization(
GraphPtr graph,
unsigned int layerIndex)
1292 auto inputs =
GetInputs(graph, layerIndex);
1295 auto outputs =
GetOutputs(graph, layerIndex);
1301 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_BatchNormalizationLayer();
1302 auto serializerDescriptor = serializerLayer->descriptor();
1305 descriptor.
m_Eps = serializerDescriptor->eps();
1319 layer->GetOutputSlot(0).SetTensorInfo(outputInfo);
1321 RegisterInputSlots(graph, layerIndex, layer);
1322 RegisterOutputSlots(graph, layerIndex, layer);
1325 void IDeserializer::DeserializerImpl::ParseCast(
GraphPtr graph,
unsigned int layerIndex)
1342 RegisterInputSlots(graph, layerIndex, layer);
1343 RegisterOutputSlots(graph, layerIndex, layer);
1346 void IDeserializer::DeserializerImpl::ParseConstant(
GraphPtr graph,
unsigned int layerIndex)
1351 auto outputs =
GetOutputs(graph, layerIndex);
1356 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_ConstantLayer();
1357 auto serializerInput = serializerLayer->input();
1361 IConnectableLayer* layer = m_Network->AddConstantLayer(input, layerName.c_str());
1366 RegisterOutputSlots(graph, layerIndex, layer);
1369 void IDeserializer::DeserializerImpl::ParseConvolution2d(
GraphPtr graph,
unsigned int layerIndex)
1372 auto inputs =
GetInputs(graph, layerIndex);
1376 auto outputs =
GetOutputs(graph, layerIndex);
1379 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_Convolution2dLayer();
1381 auto serializerDescriptor = serializerLayer->descriptor();
1384 descriptor.
m_PadLeft = serializerDescriptor->padLeft();
1385 descriptor.
m_PadRight = serializerDescriptor->padRight();
1386 descriptor.
m_PadTop = serializerDescriptor->padTop();
1387 descriptor.
m_PadBottom = serializerDescriptor->padBottom();
1388 descriptor.
m_StrideX = serializerDescriptor->strideX();
1389 descriptor.
m_StrideY = serializerDescriptor->strideY();;
1390 descriptor.
m_DilationX = serializerDescriptor->dilationX();
1391 descriptor.
m_DilationY = serializerDescriptor->dilationY();;
1392 descriptor.
m_BiasEnabled = serializerDescriptor->biasEnabled();;
1409 layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo);
1411 RegisterInputSlots(graph, layerIndex, layer);
1412 RegisterOutputSlots(graph, layerIndex, layer);
1415 void IDeserializer::DeserializerImpl::ParseConvolution3d(
GraphPtr graph,
unsigned int layerIndex)
1418 auto inputs =
GetInputs(graph, layerIndex);
1421 auto outputs =
GetOutputs(graph, layerIndex);
1424 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_Convolution3dLayer();
1426 auto serializerDescriptor = serializerLayer->descriptor();
1429 descriptor.
m_PadLeft = serializerDescriptor->padLeft();
1430 descriptor.
m_PadRight = serializerDescriptor->padRight();
1431 descriptor.
m_PadTop = serializerDescriptor->padTop();
1432 descriptor.
m_PadBottom = serializerDescriptor->padBottom();
1433 descriptor.
m_PadFront = serializerDescriptor->padFront();
1434 descriptor.
m_PadBack = serializerDescriptor->padBack();
1435 descriptor.
m_StrideX = serializerDescriptor->strideX();
1436 descriptor.
m_StrideY = serializerDescriptor->strideY();
1437 descriptor.
m_StrideZ = serializerDescriptor->strideZ();
1438 descriptor.
m_DilationX = serializerDescriptor->dilationX();
1439 descriptor.
m_DilationY = serializerDescriptor->dilationY();
1440 descriptor.
m_DilationZ = serializerDescriptor->dilationZ();
1441 descriptor.
m_BiasEnabled = serializerDescriptor->biasEnabled();
1447 IConnectableLayer* layer = m_Network->AddConvolution3dLayer(descriptor, layerName.c_str());
1450 layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo);
1452 RegisterInputSlots(graph, layerIndex, layer);
1453 RegisterOutputSlots(graph, layerIndex, layer);
1456 void IDeserializer::DeserializerImpl::ParseDepthToSpace(
GraphPtr graph,
unsigned int layerIndex)
1460 auto inputs =
GetInputs(graph, layerIndex);
1463 auto outputs =
GetOutputs(graph, layerIndex);
1466 auto fbDescriptor = graph->layers()->Get(layerIndex)->layer_as_DepthToSpaceLayer()->descriptor();
1469 descriptor.
m_BlockSize = fbDescriptor->blockSize();
1473 IConnectableLayer* layer = m_Network->AddDepthToSpaceLayer(descriptor, layerName.c_str());
1478 RegisterInputSlots(graph, layerIndex, layer);
1479 RegisterOutputSlots(graph, layerIndex, layer);
1482 void IDeserializer::DeserializerImpl::ParseDepthwiseConvolution2d(
GraphPtr graph,
unsigned int layerIndex)
1485 auto inputs =
GetInputs(graph, layerIndex);
1489 auto outputs =
GetOutputs(graph, layerIndex);
1492 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_DepthwiseConvolution2dLayer();
1494 auto serializerDescriptor = serializerLayer->descriptor();
1497 descriptor.
m_PadLeft = serializerDescriptor->padLeft();
1498 descriptor.
m_PadRight = serializerDescriptor->padRight();
1499 descriptor.
m_PadTop = serializerDescriptor->padTop();
1500 descriptor.
m_PadBottom = serializerDescriptor->padBottom();
1501 descriptor.
m_StrideX = serializerDescriptor->strideX();
1502 descriptor.
m_StrideY = serializerDescriptor->strideY();
1503 descriptor.
m_DilationX = serializerDescriptor->dilationX();
1504 descriptor.
m_DilationY = serializerDescriptor->dilationY();
1505 descriptor.
m_BiasEnabled = serializerDescriptor->biasEnabled();;
1520 if (this->GetFeatureVersions(graph).m_WeightsLayoutScheme <= 0)
1526 std::unique_ptr<unsigned char[]> permuteBuffer(
new unsigned char[weightsInfo.
GetNumBytes()]);
1529 weights.GetMemoryArea(), permuteBuffer.get(),
1533 auto weightsShape = weightsInfo.GetShape();
1534 weightsInfo.SetShape({1,
1537 weightsShape[2]*weightsShape[3]});
1541 layer = m_Network->AddDepthwiseConvolution2dLayer(descriptor,
1548 layer = m_Network->AddDepthwiseConvolution2dLayer(descriptor,
1555 layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo);
1557 RegisterInputSlots(graph, layerIndex, layer);
1558 RegisterOutputSlots(graph, layerIndex, layer);
1561 void IDeserializer::DeserializerImpl::ParseDetectionPostProcess(
GraphPtr graph,
unsigned int layerIndex)
1564 auto inputs =
GetInputs(graph, layerIndex);
1568 auto outputs =
GetOutputs(graph, layerIndex);
1571 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_DetectionPostProcessLayer();
1573 auto flatBufferDescriptor = flatBufferLayer->descriptor();
1581 descriptor.
m_NumClasses = flatBufferDescriptor->numClasses();
1583 descriptor.
m_ScaleX = flatBufferDescriptor->scaleX();
1584 descriptor.
m_ScaleY = flatBufferDescriptor->scaleY();
1585 descriptor.
m_ScaleW = flatBufferDescriptor->scaleW();
1586 descriptor.
m_ScaleH = flatBufferDescriptor->scaleH();
1594 for (
unsigned int i = 0; i < 4; i++)
1596 layer->GetOutputSlot(i).SetTensorInfo(
ToTensorInfo(outputs[i]));
1599 RegisterInputSlots(graph, layerIndex, layer);
1600 RegisterOutputSlots(graph, layerIndex, layer);
1603 void IDeserializer::DeserializerImpl::ParseDivision(
GraphPtr graph,
unsigned int layerIndex)
1606 auto inputs =
GetInputs(graph, layerIndex);
1610 auto outputs =
GetOutputs(graph, layerIndex);
1619 RegisterInputSlots(graph, layerIndex, layer);
1620 RegisterOutputSlots(graph, layerIndex, layer);
1623 void IDeserializer::DeserializerImpl::ParseEqual(
GraphPtr graph,
unsigned int layerIndex)
1626 auto inputs =
GetInputs(graph, layerIndex);
1630 auto outputs =
GetOutputs(graph, layerIndex);
1635 IConnectableLayer* layer = m_Network->AddComparisonLayer(descriptor, layerName.c_str());
1640 RegisterInputSlots(graph, layerIndex, layer);
1641 RegisterOutputSlots(graph, layerIndex, layer);
1644 void IDeserializer::DeserializerImpl::ParseFill(
GraphPtr graph,
unsigned int layerIndex)
1647 auto inputs =
GetInputs(graph, layerIndex);
1651 auto outputs =
GetOutputs(graph, layerIndex);
1656 descriptor.
m_Value = graph->layers()->Get(layerIndex)->layer_as_FillLayer()->descriptor()->value();
1657 IConnectableLayer* layer = m_Network->AddFillLayer(descriptor, layerName.c_str());
1662 RegisterInputSlots(graph, layerIndex, layer);
1663 RegisterOutputSlots(graph, layerIndex, layer);
1666 void IDeserializer::DeserializerImpl::ParseGreater(
GraphPtr graph,
unsigned int layerIndex)
1669 auto inputs =
GetInputs(graph, layerIndex);
1673 auto outputs =
GetOutputs(graph, layerIndex);
1678 IConnectableLayer* layer = m_Network->AddComparisonLayer(descriptor, layerName.c_str());
1683 RegisterInputSlots(graph, layerIndex, layer);
1684 RegisterOutputSlots(graph, layerIndex, layer);
1687 void IDeserializer::DeserializerImpl::ParseInstanceNormalization(
GraphPtr graph,
unsigned int layerIndex)
1691 auto inputs =
GetInputs(graph, layerIndex);
1694 auto outputs =
GetOutputs(graph, layerIndex);
1697 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_InstanceNormalizationLayer();
1698 auto fbDescriptor = fbLayer->descriptor();
1701 descriptor.
m_Gamma = fbDescriptor->gamma();
1702 descriptor.
m_Beta = fbDescriptor->beta();
1703 descriptor.
m_Eps = fbDescriptor->eps();
1706 const std::string layerName =
GetLayerName(graph, layerIndex);
1709 IConnectableLayer* layer = m_Network->AddInstanceNormalizationLayer(descriptor, layerName.c_str());
1712 RegisterInputSlots(graph, layerIndex, layer);
1713 RegisterOutputSlots(graph, layerIndex, layer);
1716 void IDeserializer::DeserializerImpl::ParseL2Normalization(
GraphPtr graph,
unsigned int layerIndex)
1720 auto inputs =
GetInputs(graph, layerIndex);
1723 auto outputs =
GetOutputs(graph, layerIndex);
1727 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_L2NormalizationLayer();
1728 auto flatBufferDescriptor = flatBufferLayer->descriptor();
1733 descriptor.
m_Eps = flatBufferDescriptor->eps();
1735 IConnectableLayer* layer = m_Network->AddL2NormalizationLayer(descriptor, layerName.c_str());
1738 RegisterInputSlots(graph, layerIndex, layer);
1739 RegisterOutputSlots(graph, layerIndex, layer);
1742 void IDeserializer::DeserializerImpl::ParseLogicalBinary(
GraphPtr graph,
unsigned int layerIndex)
1747 auto inputs =
GetInputs(graph, layerIndex);
1750 auto outputs =
GetOutputs(graph, layerIndex);
1753 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_LogicalBinaryLayer();
1754 auto fbDescriptor = fbLayer->descriptor();
1759 const std::string& layerName =
GetLayerName(graph, layerIndex);
1760 IConnectableLayer* layer = m_Network->AddLogicalBinaryLayer(descriptor, layerName.c_str());
1765 RegisterInputSlots(graph, layerIndex, layer);
1766 RegisterOutputSlots(graph, layerIndex, layer);
1769 void IDeserializer::DeserializerImpl::ParseLogSoftmax(
GraphPtr graph,
unsigned int layerIndex)
1780 descriptor.
m_Beta = graph->layers()->Get(layerIndex)->layer_as_LogSoftmaxLayer()->descriptor()->beta();
1781 descriptor.m_Axis = graph->layers()->Get(layerIndex)->layer_as_LogSoftmaxLayer()->descriptor()->axis();
1784 IConnectableLayer* layer = m_Network->AddLogSoftmaxLayer(descriptor, layerName.c_str());
1789 RegisterInputSlots(graph, layerIndex, layer);
1790 RegisterOutputSlots(graph, layerIndex, layer);
1793 void IDeserializer::DeserializerImpl::ParseMinimum(
GraphPtr graph,
unsigned int layerIndex)
1796 auto inputs =
GetInputs(graph, layerIndex);
1800 auto outputs =
GetOutputs(graph, layerIndex);
1809 RegisterInputSlots(graph, layerIndex, layer);
1810 RegisterOutputSlots(graph, layerIndex, layer);
1813 void IDeserializer::DeserializerImpl::ParseMaximum(
GraphPtr graph,
unsigned int layerIndex)
1816 auto inputs =
GetInputs(graph, layerIndex);
1820 auto outputs =
GetOutputs(graph, layerIndex);
1829 RegisterInputSlots(graph, layerIndex, layer);
1830 RegisterOutputSlots(graph, layerIndex, layer);
1834 unsigned int layerIndex)
1836 auto layerType = graph->layers()->Get(layerIndex)->layer_type();
1841 return graph->layers()->Get(layerIndex)->layer_as_ConcatLayer()->descriptor();
1843 return graph->layers()->Get(layerIndex)->layer_as_MergerLayer()->descriptor();
1848 void IDeserializer::DeserializerImpl::ParseChannelShuffle(
GraphPtr graph,
unsigned int layerIndex)
1859 descriptor.
m_Axis = graph->layers()->Get(layerIndex)->layer_as_ChannelShuffleLayer()->descriptor()->axis();
1860 descriptor.m_NumGroups =
1861 graph->layers()->Get(layerIndex)->layer_as_ChannelShuffleLayer()->descriptor()->numGroups();
1864 IConnectableLayer* layer = m_Network->AddChannelShuffleLayer(descriptor, layerName.c_str());
1869 RegisterInputSlots(graph, layerIndex, layer);
1870 RegisterOutputSlots(graph, layerIndex, layer);
1872 void IDeserializer::DeserializerImpl::ParseComparison(
GraphPtr graph,
unsigned int layerIndex)
1877 auto inputs =
GetInputs(graph, layerIndex);
1880 auto outputs =
GetOutputs(graph, layerIndex);
1883 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_ComparisonLayer();
1884 auto fbDescriptor = fbLayer->descriptor();
1889 const std::string& layerName =
GetLayerName(graph, layerIndex);
1890 IConnectableLayer* layer = m_Network->AddComparisonLayer(descriptor, layerName.c_str());
1895 RegisterInputSlots(graph, layerIndex, layer);
1896 RegisterOutputSlots(graph, layerIndex, layer);
1899 void IDeserializer::DeserializerImpl::ParseElementwiseUnary(
GraphPtr graph,
unsigned int layerIndex)
1904 auto inputs =
GetInputs(graph, layerIndex);
1907 auto outputs =
GetOutputs(graph, layerIndex);
1910 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_ElementwiseUnaryLayer();
1911 auto fbDescriptor = fbLayer->descriptor();
1916 const std::string& layerName =
GetLayerName(graph, layerIndex);
1917 IConnectableLayer* layer = m_Network->AddElementwiseUnaryLayer(descriptor, layerName.c_str());
1922 RegisterInputSlots(graph, layerIndex, layer);
1923 RegisterOutputSlots(graph, layerIndex, layer);
1926 void IDeserializer::DeserializerImpl::ParseConcat(
GraphPtr graph,
unsigned int layerIndex)
1931 auto outputs =
GetOutputs(graph, layerIndex);
1936 unsigned int numViews = originsDescriptor->numViews();
1937 unsigned int numDimensions = originsDescriptor->numDimensions();
1940 auto inputs =
GetInputs(graph, layerIndex);
1944 auto originsPtr = originsDescriptor->viewOrigins();
1945 for (
unsigned int v = 0; v < numViews; ++v)
1947 auto originPtr = originsPtr->Get(v);
1948 for (
unsigned int d = 0; d < numDimensions; ++d)
1950 uint32_t value = originPtr->data()->Get(d);
1951 descriptor.SetViewOriginCoord(v, d, value);
1954 descriptor.SetConcatAxis(originsDescriptor->concatAxis());
1956 IConnectableLayer* layer = m_Network->AddConcatLayer(descriptor, layerName.c_str());
1960 RegisterInputSlots(graph, layerIndex, layer);
1961 RegisterOutputSlots(graph, layerIndex, layer);
1964 void IDeserializer::DeserializerImpl::ParseMultiplication(
GraphPtr graph,
unsigned int layerIndex)
1967 auto inputs =
GetInputs(graph, layerIndex);
1971 auto outputs =
GetOutputs(graph, layerIndex);
1975 IConnectableLayer* layer = m_Network->AddMultiplicationLayer(layerName.c_str());
1980 RegisterInputSlots(graph, layerIndex, layer);
1981 RegisterOutputSlots(graph, layerIndex, layer);
1984 void IDeserializer::DeserializerImpl::ParseFloor(
GraphPtr graph,
unsigned int layerIndex)
1989 auto inputs =
GetInputs(graph, layerIndex);
1992 auto outputs =
GetOutputs(graph, layerIndex);
1999 layer = m_Network->AddFloorLayer(layerName.c_str());
2004 RegisterInputSlots(graph, layerIndex, layer);
2005 RegisterOutputSlots(graph, layerIndex, layer);
2008 void IDeserializer::DeserializerImpl::ParseFullyConnected(
GraphPtr graph,
unsigned int layerIndex)
2011 auto inputs =
GetInputs(graph, layerIndex);
2014 auto outputs =
GetOutputs(graph, layerIndex);
2017 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_FullyConnectedLayer();
2019 auto flatBufferDescriptor = flatBufferLayer->descriptor();
2022 fullyConnectedDescriptor.
m_BiasEnabled = flatBufferDescriptor->biasEnabled();
2024 fullyConnectedDescriptor.
m_ConstantWeights = flatBufferDescriptor->constantWeights();
2027 std::vector<unsigned int> ignoreSlots {};
2031 if (this->GetFeatureVersions(graph).m_ConstTensorsAsInputs <= 0)
2036 layer = m_Network->AddFullyConnectedLayer(fullyConnectedDescriptor,
2040 auto weightsLayer = m_Network->AddConstantLayer(weightsTensor);
2041 weightsLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(1u));
2042 weightsLayer->GetOutputSlot(0).SetTensorInfo(weightsTensor.
GetInfo());
2043 ignoreSlots.emplace_back(1u);
2048 auto biasLayer = m_Network->AddConstantLayer(biasTensor);
2049 biasLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(2u));
2050 biasLayer->GetOutputSlot(0).SetTensorInfo(biasTensor.
GetInfo());
2051 ignoreSlots.emplace_back(2u);
2056 layer = m_Network->AddFullyConnectedLayer(fullyConnectedDescriptor,
2058 uint32_t numInputs = fullyConnectedDescriptor.
GetNumInputs();
2065 RegisterInputSlots(graph, layerIndex, layer, ignoreSlots);
2066 RegisterOutputSlots(graph, layerIndex, layer);
2069 void IDeserializer::DeserializerImpl::ParsePad(
GraphPtr graph,
unsigned int layerIndex)
2079 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_PadLayer()->descriptor();
2080 auto flatBufferPadList = flatBufferDescriptor->padList();
2081 auto paddingMode = flatBufferDescriptor->paddingMode();
2082 float padValue = flatBufferDescriptor->padValue();
2084 if (flatBufferPadList->Length() % 2 != 0)
2086 throw ParseException(fmt::format(
"The size of the pad list must be divisible by 2 {}",
2090 std::vector<std::pair<unsigned int, unsigned int>> padList;
2091 padList.reserve(flatBufferPadList->Length() / 2);
2092 for (
unsigned int i = 0; i < flatBufferPadList->Length() - 1; i += 2)
2094 padList.emplace_back(flatBufferPadList->Get(i), flatBufferPadList->Get(i+1));
2100 IConnectableLayer* layer = m_Network->AddPadLayer(descriptor, layerName.c_str());
2105 RegisterInputSlots(graph, layerIndex, layer);
2106 RegisterOutputSlots(graph, layerIndex, layer);
2109 void IDeserializer::DeserializerImpl::ParsePermute(
GraphPtr graph,
unsigned int layerIndex)
2114 graph->layers()->Get(layerIndex)->layer_as_PermuteLayer()->descriptor()->dimMappings();
2116 auto inputs =
GetInputs(graph, layerIndex);
2119 auto outputs =
GetOutputs(graph, layerIndex);
2126 IConnectableLayer* layer = m_Network->AddPermuteLayer(descriptor, layerName.c_str());
2129 RegisterInputSlots(graph, layerIndex, layer);
2130 RegisterOutputSlots(graph, layerIndex, layer);
2134 unsigned int layerIndex)
2139 switch (pooling2dDesc->poolType())
2162 switch (pooling2dDesc->outputShapeRounding())
2180 switch (pooling2dDesc->paddingMethod())
2198 switch (pooling2dDesc->dataLayout())
2217 desc.
m_PadLeft = pooling2dDesc->padLeft();
2219 desc.
m_PadTop = pooling2dDesc->padTop();
2220 desc.
m_StrideX = pooling2dDesc->strideX();
2221 desc.
m_StrideY = pooling2dDesc->strideY();
2230 void IDeserializer::DeserializerImpl::ParsePooling2d(
GraphPtr graph,
unsigned int layerIndex)
2234 auto pooling2dDes = graph->layers()->Get(layerIndex)->layer_as_Pooling2dLayer()->descriptor();
2235 auto inputs =
GetInputs(graph, layerIndex);
2238 auto outputs =
GetOutputs(graph, layerIndex);
2244 IConnectableLayer* layer = m_Network->AddPooling2dLayer(pooling2dDescriptor, layerName.c_str());
2247 RegisterInputSlots(graph, layerIndex, layer);
2248 RegisterOutputSlots(graph, layerIndex, layer);
2251 void IDeserializer::DeserializerImpl::ParseQuantize(
GraphPtr graph,
unsigned int layerIndex)
2255 auto inputs =
GetInputs(graph, layerIndex);
2258 auto outputs =
GetOutputs(graph, layerIndex);
2266 RegisterInputSlots(graph, layerIndex, layer);
2267 RegisterOutputSlots(graph, layerIndex, layer);
2271 const std::vector<uint32_t>& targetDimsIn)
2273 std::vector<unsigned int> outputDims(targetDimsIn.begin(), targetDimsIn.end());
2274 const auto stretchDim = std::find(targetDimsIn.begin(), targetDimsIn.end(), -1);
2276 if (stretchDim != targetDimsIn.end())
2278 if (std::find(std::next(stretchDim), targetDimsIn.end(), -1) != targetDimsIn.end())
2280 throw ParseException(fmt::format(
"At most one component of shape can be -1 {}",
2284 auto targetNumElements =
2286 std::accumulate(targetDimsIn.begin(), targetDimsIn.end(), -1, std::multiplies<int32_t>()));
2288 auto stretchIndex =
static_cast<size_t>(std::distance(targetDimsIn.begin(), stretchDim));
2289 outputDims[stretchIndex] = inputTensorInfo.
GetNumElements() / targetNumElements;
2300 void IDeserializer::DeserializerImpl::ParseRank(
GraphPtr graph,
unsigned int layerIndex)
2316 RegisterInputSlots(graph, layerIndex, layer);
2317 RegisterOutputSlots(graph, layerIndex, layer);
2320 void IDeserializer::DeserializerImpl::ParseReduce(
GraphPtr graph,
unsigned int layerIndex)
2325 auto inputs =
GetInputs(graph, layerIndex);
2328 auto outputs =
GetOutputs(graph, layerIndex);
2331 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_ReduceLayer();
2332 auto fbDescriptor = fbLayer->descriptor();
2333 auto flatBufferAxis = fbDescriptor->axis();
2336 descriptor.
m_KeepDims = fbDescriptor->keepDims();
2337 descriptor.
m_vAxis = std::vector<unsigned int>(flatBufferAxis->begin(), flatBufferAxis->end());
2340 const std::string& layerName =
GetLayerName(graph, layerIndex);
2341 IConnectableLayer* layer = m_Network->AddReduceLayer(descriptor, layerName.c_str());
2346 RegisterInputSlots(graph, layerIndex, layer);
2347 RegisterOutputSlots(graph, layerIndex, layer);
2350 void IDeserializer::DeserializerImpl::ParseReshape(
GraphPtr graph,
unsigned int layerIndex)
2353 auto inputs =
GetInputs(graph, layerIndex);
2355 auto outputs =
GetOutputs(graph, layerIndex);
2361 const auto targetDims = graph->layers()->Get(layerIndex)->layer_as_ReshapeLayer()->descriptor()->targetShape();
2362 std::vector<uint32_t> outputDims(targetDims->begin(), targetDims->begin() + targetDims->size());
2365 const armnn::TensorShape& reshapeOutputTensorShape = reshapeOutputTensorInfo.GetShape();
2367 const std::vector<uint32_t> expectedDims(outputs[0]->dimensions()->begin(),
2368 outputs[0]->dimensions()->begin() + outputs[0]->dimensions()->size());
2370 if (inputs.size() > 1 && !
CheckShape(reshapeOutputTensorShape, expectedDims))
2372 std::stringstream ss;
2373 ss <<
"New shape defined in reshape parameters " 2374 << reshapeOutputTensorShape
2375 <<
" does not equal output shape " 2376 << actualOutputTensorInfo.
GetShape()
2386 IConnectableLayer* layer = m_Network->AddReshapeLayer(reshapeDesc, layerName.c_str());
2389 RegisterInputSlots(graph, layerIndex, layer);
2390 RegisterOutputSlots(graph, layerIndex, layer);
2393 void IDeserializer::DeserializerImpl::ParseResize(
GraphPtr graph,
unsigned int layerIndex)
2403 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_ResizeLayer()->descriptor();
2406 descriptor.
m_TargetWidth = flatBufferDescriptor->targetWidth();
2407 descriptor.
m_TargetHeight = flatBufferDescriptor->targetHeight();
2410 descriptor.
m_AlignCorners = flatBufferDescriptor->alignCorners();
2414 IConnectableLayer* layer = m_Network->AddResizeLayer(descriptor, layerName.c_str());
2419 RegisterInputSlots(graph, layerIndex, layer);
2420 RegisterOutputSlots(graph, layerIndex, layer);
2426 void IDeserializer::DeserializerImpl::ParseResizeBilinear(
GraphPtr graph,
unsigned int layerIndex)
2436 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_ResizeBilinearLayer()->descriptor();
2439 descriptor.
m_TargetWidth = flatBufferDescriptor->targetWidth();
2440 descriptor.
m_TargetHeight = flatBufferDescriptor->targetHeight();
2443 descriptor.
m_AlignCorners = flatBufferDescriptor->alignCorners();
2447 IConnectableLayer* layer = m_Network->AddResizeLayer(descriptor, layerName.c_str());
2452 RegisterInputSlots(graph, layerIndex, layer);
2453 RegisterOutputSlots(graph, layerIndex, layer);
2456 void IDeserializer::DeserializerImpl::ParseShape(
GraphPtr graph,
unsigned int layerIndex)
2472 RegisterInputSlots(graph, layerIndex, layer);
2473 RegisterOutputSlots(graph, layerIndex, layer);
2476 void IDeserializer::DeserializerImpl::ParseSoftmax(
GraphPtr graph,
unsigned int layerIndex)
2487 descriptor.
m_Beta = graph->layers()->Get(layerIndex)->layer_as_SoftmaxLayer()->descriptor()->beta();
2488 descriptor.m_Axis = graph->layers()->Get(layerIndex)->layer_as_SoftmaxLayer()->descriptor()->axis();
2491 IConnectableLayer* layer = m_Network->AddSoftmaxLayer(descriptor, layerName.c_str());
2496 RegisterInputSlots(graph, layerIndex, layer);
2497 RegisterOutputSlots(graph, layerIndex, layer);
2500 void IDeserializer::DeserializerImpl::ParseSpaceToBatchNd(
GraphPtr graph,
unsigned int layerIndex)
2510 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_SpaceToBatchNdLayer()->descriptor();
2511 auto flatBufferPadList = flatBufferDescriptor->padList();
2512 auto flatBufferBlockShape = flatBufferDescriptor->blockShape();
2514 if (flatBufferPadList->Length() % 2 != 0)
2516 throw ParseException(fmt::format(
"The size of the pad list must be divisible by 2 {}",
2520 std::vector<std::pair<unsigned int, unsigned int>> padList;
2521 padList.reserve(flatBufferPadList->Length() / 2);
2522 for (
unsigned int i = 0; i < flatBufferPadList->Length() - 1; i += 2)
2524 padList.emplace_back(flatBufferPadList->Get(i), flatBufferPadList->Get(i+1));
2530 std::vector<unsigned int>(flatBufferBlockShape->begin(), flatBufferBlockShape->end());
2534 IConnectableLayer* layer = m_Network->AddSpaceToBatchNdLayer(descriptor, layerName.c_str());
2539 RegisterInputSlots(graph, layerIndex, layer);
2540 RegisterOutputSlots(graph, layerIndex, layer);
2543 void IDeserializer::DeserializerImpl::ParseSpaceToDepth(
GraphPtr graph,
unsigned int layerIndex)
2553 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_SpaceToDepthLayer()->descriptor();
2556 descriptor.
m_BlockSize = flatBufferDescriptor->blockSize();
2560 IConnectableLayer* layer = m_Network->AddSpaceToDepthLayer(descriptor, layerName.c_str());
2565 RegisterInputSlots(graph, layerIndex, layer);
2566 RegisterOutputSlots(graph, layerIndex, layer);
2571 unsigned int layerIndex)
2576 switch (normalizationDescriptor->normChannelType())
2594 switch (normalizationDescriptor->normMethodType())
2612 switch (normalizationDescriptor->dataLayout())
2630 desc.
m_Alpha = normalizationDescriptor->alpha();
2631 desc.
m_Beta = normalizationDescriptor->beta();
2632 desc.
m_K = normalizationDescriptor->k();
2633 desc.
m_NormSize = normalizationDescriptor->normSize();
2638 void IDeserializer::DeserializerImpl::ParseNormalization(
GraphPtr graph,
unsigned int layerIndex)
2642 auto normalizationDes = graph->layers()->Get(layerIndex)->layer_as_NormalizationLayer()->descriptor();
2655 IConnectableLayer* layer = m_Network->AddNormalizationLayer(normalizationDescriptor, layerName.c_str());
2658 RegisterInputSlots(graph, layerIndex, layer);
2659 RegisterOutputSlots(graph, layerIndex, layer);
2662 void IDeserializer::DeserializerImpl::ParseRsqrt(
GraphPtr graph,
unsigned int layerIndex)
2665 auto inputs =
GetInputs(graph, layerIndex);
2669 auto outputs =
GetOutputs(graph, layerIndex);
2675 IConnectableLayer* layer = m_Network->AddElementwiseUnaryLayer(descriptor, layerName.c_str());
2679 RegisterInputSlots(graph, layerIndex, layer);
2680 RegisterOutputSlots(graph, layerIndex, layer);
2683 void IDeserializer::DeserializerImpl::ParseSlice(
GraphPtr graph,
unsigned int layerIndex)
2687 auto inputs =
GetInputs(graph, layerIndex);
2690 auto outputs =
GetOutputs(graph, layerIndex);
2693 auto fbDescriptor = graph->layers()->Get(layerIndex)->layer_as_SliceLayer()->descriptor();
2695 auto fbBegin = fbDescriptor->begin();
2696 auto fbSize = fbDescriptor->size();
2698 if (fbBegin->Length() != fbSize->Length())
2700 throw ParseException(fmt::format(
"Begin and size descriptors must have the same length {}",
2705 descriptor.
m_Begin.insert(descriptor.
m_Begin.end(), fbBegin->begin(), fbBegin->end());
2706 descriptor.
m_Size.insert(descriptor.
m_Size.end(), fbSize->begin(), fbSize->end());
2709 IConnectableLayer* layer = m_Network->AddSliceLayer(descriptor, layerName.c_str());
2714 RegisterInputSlots(graph, layerIndex, layer);
2715 RegisterOutputSlots(graph, layerIndex, layer);
2718 void IDeserializer::DeserializerImpl::ParseStridedSlice(
GraphPtr graph,
unsigned int layerIndex)
2728 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_StridedSliceLayer()->descriptor();
2730 auto flatBufferBegin = flatBufferDescriptor->begin();
2731 auto flatBufferEnd = flatBufferDescriptor->end();
2732 auto flatBufferStride = flatBufferDescriptor->stride();
2734 if (!(flatBufferBegin->Length() == flatBufferEnd->Length() &&
2735 flatBufferBegin->Length() == flatBufferStride->Length()))
2737 throw ParseException(fmt::format(
"The size of the begin, end, and stride must be equal {}",
2741 std::vector<int> begin(flatBufferBegin->begin(), flatBufferBegin->end());
2742 std::vector<int> end(flatBufferEnd->begin(), flatBufferEnd->end());
2743 std::vector<int> stride(flatBufferStride->begin(), flatBufferStride->end());
2746 descriptor.m_BeginMask = flatBufferDescriptor->beginMask();
2747 descriptor.m_EndMask = flatBufferDescriptor->endMask();
2748 descriptor.m_ShrinkAxisMask = flatBufferDescriptor->shrinkAxisMask();
2749 descriptor.m_EllipsisMask = flatBufferDescriptor->ellipsisMask();
2750 descriptor.m_NewAxisMask = flatBufferDescriptor->newAxisMask();
2751 descriptor.m_DataLayout =
ToDataLayout(flatBufferDescriptor->dataLayout());
2754 IConnectableLayer* layer = m_Network->AddStridedSliceLayer(descriptor, layerName.c_str());
2759 RegisterInputSlots(graph, layerIndex, layer);
2760 RegisterOutputSlots(graph, layerIndex, layer);
2763 void IDeserializer::DeserializerImpl::ParseSubtraction(
GraphPtr graph,
unsigned int layerIndex)
2766 auto inputs =
GetInputs(graph, layerIndex);
2770 auto outputs =
GetOutputs(graph, layerIndex);
2779 RegisterInputSlots(graph, layerIndex, layer);
2780 RegisterOutputSlots(graph, layerIndex, layer);
2783 void IDeserializer::DeserializerImpl::ParseGather(
GraphPtr graph,
unsigned int layerIndex)
2794 descriptor.
m_Axis = graph->layers()->Get(layerIndex)->layer_as_GatherLayer()->descriptor()->axis();
2797 IConnectableLayer* layer = m_Network->AddGatherLayer(descriptor, layerName.c_str());
2802 RegisterInputSlots(graph, layerIndex, layer);
2803 RegisterOutputSlots(graph, layerIndex, layer);
2806 void IDeserializer::DeserializerImpl::ParseMean(
GraphPtr graph,
unsigned int layerIndex)
2816 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_MeanLayer()->descriptor();
2817 auto flatBufferAxis = flatBufferDescriptor->axis();
2818 auto flatBufferKeepDims = flatBufferDescriptor->keepDims();
2821 descriptor.
m_Axis = std::vector<unsigned int>(flatBufferAxis->begin(), flatBufferAxis->end());
2825 IConnectableLayer* layer = m_Network->AddMeanLayer(descriptor, layerName.c_str());
2830 RegisterInputSlots(graph, layerIndex, layer);
2831 RegisterOutputSlots(graph, layerIndex, layer);
2834 void IDeserializer::DeserializerImpl::ParseSplitter(
GraphPtr graph,
unsigned int layerIndex)
2843 auto flatBufferViewsDescriptor = graph->layers()->Get(layerIndex)->layer_as_SplitterLayer()->descriptor();
2844 auto flatBufferViewSizes = flatBufferViewsDescriptor->viewSizes();
2845 auto flatBufferOriginsDescriptor = flatBufferViewsDescriptor->origins();
2846 auto flatBufferViewOrigins = flatBufferOriginsDescriptor->viewOrigins();
2847 uint32_t numViews = flatBufferOriginsDescriptor->numViews();
2848 uint32_t numDimensions = flatBufferOriginsDescriptor->numDimensions();
2855 for(
unsigned int vIdx = 0; vIdx < numViews; ++vIdx)
2857 for (
unsigned int dIdx = 0; dIdx < numDimensions; ++dIdx)
2859 viewsDescriptor.
SetViewSize(vIdx, dIdx, flatBufferViewSizes->Get(vIdx)->data()->Get(dIdx));
2860 viewsDescriptor.
SetViewOriginCoord(vIdx, dIdx, flatBufferViewOrigins->Get(vIdx)->data()->Get(dIdx));
2865 IConnectableLayer* layer = m_Network->AddSplitterLayer(viewsDescriptor, layerName.c_str());
2868 for(
unsigned int vIdx = 0; vIdx < numViews; ++vIdx)
2874 RegisterInputSlots(graph, layerIndex, layer);
2875 RegisterOutputSlots(graph, layerIndex, layer);
2893 void IDeserializer::DeserializerImpl::ParseLstm(
GraphPtr graph,
unsigned int layerIndex)
2897 auto inputs =
GetInputs(graph, layerIndex);
2900 auto outputs =
GetOutputs(graph, layerIndex);
2903 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_LstmLayer();
2905 auto flatBufferDescriptor = flatBufferLayer->descriptor();
2906 auto flatBufferInputParams = flatBufferLayer->inputParams();
2936 if (!lstmDescriptor.m_CifgEnabled)
2938 inputToInputWeights =
ToConstTensor(flatBufferInputParams->inputToInputWeights());
2939 recurrentToInputWeights =
ToConstTensor(flatBufferInputParams->recurrentToInputWeights());
2940 cellToInputWeights =
ToConstTensor(flatBufferInputParams->cellToInputWeights());
2941 inputGateBias =
ToConstTensor(flatBufferInputParams->inputGateBias());
2951 if (lstmDescriptor.m_ProjectionEnabled)
2953 projectionWeights =
ToConstTensor(flatBufferInputParams->projectionWeights());
2954 projectionBias =
ToConstTensor(flatBufferInputParams->projectionBias());
2962 if (lstmDescriptor.m_PeepholeEnabled)
2964 cellToForgetWeights =
ToConstTensor(flatBufferInputParams->cellToForgetWeights());
2965 cellToOutputWeights =
ToConstTensor(flatBufferInputParams->cellToOutputWeights());
2975 if (lstmDescriptor.m_LayerNormEnabled)
2977 if (!lstmDescriptor.m_CifgEnabled)
2979 inputLayerNormWeights =
ToConstTensor(flatBufferInputParams->inputLayerNormWeights());
2982 forgetLayerNormWeights =
ToConstTensor(flatBufferInputParams->forgetLayerNormWeights());
2983 cellLayerNormWeights =
ToConstTensor(flatBufferInputParams->cellLayerNormWeights());
2984 outputLayerNormWeights =
ToConstTensor(flatBufferInputParams->outputLayerNormWeights());
2991 IConnectableLayer* layer = m_Network->AddLstmLayer(lstmDescriptor, lstmInputParams, layerName.c_str());
3005 RegisterInputSlots(graph, layerIndex, layer);
3006 RegisterOutputSlots(graph, layerIndex, layer);
3018 desc.
m_CellClip = qLstmDescriptor->cellClip();
3032 void IDeserializer::DeserializerImpl::ParseQLstm(
GraphPtr graph,
unsigned int layerIndex)
3036 auto inputs =
GetInputs(graph, layerIndex);
3039 auto outputs =
GetOutputs(graph, layerIndex);
3042 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_QLstmLayer();
3044 auto flatBufferDescriptor = flatBufferLayer->descriptor();
3045 auto flatBufferInputParams = flatBufferLayer->inputParams();
3076 if (!qLstmDescriptor.m_CifgEnabled)
3078 inputToInputWeights =
ToConstTensor(flatBufferInputParams->inputToInputWeights());
3079 recurrentToInputWeights =
ToConstTensor(flatBufferInputParams->recurrentToInputWeights());
3080 inputGateBias =
ToConstTensor(flatBufferInputParams->inputGateBias());
3091 if (qLstmDescriptor.m_ProjectionEnabled)
3093 projectionWeights =
ToConstTensor(flatBufferInputParams->projectionWeights());
3094 projectionBias =
ToConstTensor(flatBufferInputParams->projectionBias());
3105 if (qLstmDescriptor.m_PeepholeEnabled)
3107 if (!qLstmDescriptor.m_CifgEnabled)
3109 cellToInputWeights =
ToConstTensor(flatBufferInputParams->cellToInputWeights());
3113 cellToForgetWeights =
ToConstTensor(flatBufferInputParams->cellToForgetWeights());
3114 cellToOutputWeights =
ToConstTensor(flatBufferInputParams->cellToOutputWeights());
3126 if (qLstmDescriptor.m_LayerNormEnabled)
3128 if (!qLstmDescriptor.m_CifgEnabled)
3130 inputLayerNormWeights =
ToConstTensor(flatBufferInputParams->inputLayerNormWeights());
3134 forgetLayerNormWeights =
ToConstTensor(flatBufferInputParams->forgetLayerNormWeights());
3135 cellLayerNormWeights =
ToConstTensor(flatBufferInputParams->cellLayerNormWeights());
3136 outputLayerNormWeights =
ToConstTensor(flatBufferInputParams->outputLayerNormWeights());
3143 IConnectableLayer* layer = m_Network->AddQLstmLayer(qLstmDescriptor, qLstmInputParams, layerName.c_str());
3154 RegisterInputSlots(graph, layerIndex, layer);
3155 RegisterOutputSlots(graph, layerIndex, layer);
3158 void IDeserializer::DeserializerImpl::ParseQuantizedLstm(
GraphPtr graph,
unsigned int layerIndex)
3162 auto inputs =
GetInputs(graph, layerIndex);
3165 auto outputs =
GetOutputs(graph, layerIndex);
3168 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_QuantizedLstmLayer();
3170 auto flatBufferInputParams = flatBufferLayer->inputParams();
3200 IConnectableLayer* layer = m_Network->AddQuantizedLstmLayer(lstmInputParams, layerName.c_str());
3208 RegisterInputSlots(graph, layerIndex, layer);
3209 RegisterOutputSlots(graph, layerIndex, layer);
3212 void IDeserializer::DeserializerImpl::ParseDequantize(
GraphPtr graph,
unsigned int layerIndex)
3222 const std::string layerName =
GetLayerName(graph, layerIndex);
3228 RegisterInputSlots(graph, layerIndex, layer);
3229 RegisterOutputSlots(graph, layerIndex, layer);
3232 void IDeserializer::DeserializerImpl::ParseMerge(
GraphPtr graph,
unsigned int layerIndex)
3242 const std::string layerName =
GetLayerName(graph, layerIndex);
3248 RegisterInputSlots(graph, layerIndex, layer);
3249 RegisterOutputSlots(graph, layerIndex, layer);
3252 void IDeserializer::DeserializerImpl::ParseSwitch(
GraphPtr graph,
unsigned int layerIndex)
3255 auto inputs =
GetInputs(graph, layerIndex);
3259 auto outputs =
GetOutputs(graph, layerIndex);
3271 RegisterInputSlots(graph, layerIndex, layer);
3272 RegisterOutputSlots(graph, layerIndex, layer);
3275 void IDeserializer::DeserializerImpl::ParsePrelu(
GraphPtr graph,
unsigned int layerIndex)
3278 auto inputs =
GetInputs(graph, layerIndex);
3282 auto outputs =
GetOutputs(graph, layerIndex);
3291 RegisterInputSlots(graph, layerIndex, layer);
3292 RegisterOutputSlots(graph, layerIndex, layer);
3295 void IDeserializer::DeserializerImpl::ParseTranspose(
GraphPtr graph,
unsigned int layerIndex)
3299 auto dimsMapping = graph->layers()->Get(layerIndex)->layer_as_TransposeLayer()->descriptor()->dimMappings();
3301 auto inputs =
GetInputs(graph, layerIndex);
3304 auto outputs =
GetOutputs(graph, layerIndex);
3311 IConnectableLayer* layer = m_Network->AddTransposeLayer(descriptor, layerName.c_str());
3314 RegisterInputSlots(graph, layerIndex, layer);
3315 RegisterOutputSlots(graph, layerIndex, layer);
3318 void IDeserializer::DeserializerImpl::ParseTransposeConvolution2d(
GraphPtr graph,
unsigned int layerIndex)
3322 auto inputs =
GetInputs(graph, layerIndex);
3325 auto outputs =
GetOutputs(graph, layerIndex);
3328 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_TransposeConvolution2dLayer();
3330 auto serializerDescriptor = serializerLayer->descriptor();
3333 descriptor.
m_PadLeft = serializerDescriptor->padLeft();
3334 descriptor.
m_PadRight = serializerDescriptor->padRight();
3335 descriptor.
m_PadTop = serializerDescriptor->padTop();
3336 descriptor.
m_PadBottom = serializerDescriptor->padBottom();
3337 descriptor.
m_StrideX = serializerDescriptor->strideX();
3338 descriptor.
m_StrideY = serializerDescriptor->strideY();;
3339 descriptor.
m_BiasEnabled = serializerDescriptor->biasEnabled();;
3348 optionalBiases = armnn::MakeOptional<armnn::ConstTensor>(biases);
3351 IConnectableLayer* layer = m_Network->AddTransposeConvolution2dLayer(descriptor,
3357 layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo);
3359 RegisterInputSlots(graph, layerIndex, layer);
3360 RegisterOutputSlots(graph, layerIndex, layer);
3363 void IDeserializer::DeserializerImpl::ParseStack(
GraphPtr graph,
unsigned int layerIndex)
3366 auto inputs =
GetInputs(graph, layerIndex);
3368 auto outputs =
GetOutputs(graph, layerIndex);
3371 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_StackLayer()->descriptor();
3372 unsigned int axis = flatBufferDescriptor->axis();
3373 unsigned int numInputs = flatBufferDescriptor->numInputs();
3376 auto flatBufferInputShape = flatBufferDescriptor->inputShape();
3377 std::vector<uint32_t> vectorInputShape(flatBufferInputShape->begin(),
3378 flatBufferInputShape->begin() + flatBufferInputShape->size());
3380 TensorShape inputShape(static_cast<unsigned int>(vectorInputShape.size()), vectorInputShape.data());
3383 for (
unsigned int i=0; i<inputs.size(); ++i)
3386 if (descriptor.m_InputShape != inputShape)
3388 std::stringstream ss;
3389 ss <<
"Shape of input " 3393 <<
" does not equal defined input shape " 3394 << descriptor.m_InputShape
3402 IConnectableLayer* layer = m_Network->AddStackLayer(descriptor, layerName.c_str());
3407 RegisterInputSlots(graph, layerIndex, layer);
3408 RegisterOutputSlots(graph, layerIndex, layer);
3411 void IDeserializer::DeserializerImpl::ParseStandIn(
GraphPtr graph,
unsigned int layerIndex)
3415 auto inputs =
GetInputs(graph, layerIndex);
3416 auto outputs =
GetOutputs(graph, layerIndex);
3418 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_StandInLayer();
3419 auto fbDescriptor = fbLayer->descriptor();
3422 descriptor.
m_NumInputs = fbDescriptor->numInputs();
3428 const std::string layerName =
GetLayerName(graph, layerIndex);
3431 for (
unsigned int i = 0u; i < descriptor.
m_NumOutputs; ++i)
3437 RegisterInputSlots(graph, layerIndex, layer);
3438 RegisterOutputSlots(graph, layerIndex, layer);
3458 void IDeserializer::DeserializerImpl::ParseUnidirectionalSequenceLstm(
GraphPtr graph,
unsigned int layerIndex)
3462 auto inputs =
GetInputs(graph, layerIndex);
3465 auto outputs =
GetOutputs(graph, layerIndex);
3468 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_UnidirectionalSequenceLstmLayer();
3470 auto flatBufferDescriptor = flatBufferLayer->descriptor();
3471 auto flatBufferInputParams = flatBufferLayer->inputParams();
3501 if (!descriptor.m_CifgEnabled)
3503 inputToInputWeights =
ToConstTensor(flatBufferInputParams->inputToInputWeights());
3504 recurrentToInputWeights =
ToConstTensor(flatBufferInputParams->recurrentToInputWeights());
3505 inputGateBias =
ToConstTensor(flatBufferInputParams->inputGateBias());
3511 if (descriptor.m_PeepholeEnabled)
3513 cellToInputWeights =
ToConstTensor(flatBufferInputParams->cellToInputWeights());
3520 if (descriptor.m_ProjectionEnabled)
3522 projectionWeights =
ToConstTensor(flatBufferInputParams->projectionWeights());
3523 projectionBias =
ToConstTensor(flatBufferInputParams->projectionBias());
3531 if (descriptor.m_PeepholeEnabled)
3533 cellToForgetWeights =
ToConstTensor(flatBufferInputParams->cellToForgetWeights());
3534 cellToOutputWeights =
ToConstTensor(flatBufferInputParams->cellToOutputWeights());
3544 if (descriptor.m_LayerNormEnabled)
3546 if (!descriptor.m_CifgEnabled)
3548 inputLayerNormWeights =
ToConstTensor(flatBufferInputParams->inputLayerNormWeights());
3551 forgetLayerNormWeights =
ToConstTensor(flatBufferInputParams->forgetLayerNormWeights());
3552 cellLayerNormWeights =
ToConstTensor(flatBufferInputParams->cellLayerNormWeights());
3553 outputLayerNormWeights =
ToConstTensor(flatBufferInputParams->outputLayerNormWeights());
3560 IConnectableLayer* layer = m_Network->AddUnidirectionalSequenceLstmLayer(descriptor,
3567 RegisterInputSlots(graph, layerIndex, layer);
3568 RegisterOutputSlots(graph, layerIndex, layer);
static armnn::NormalizationDescriptor GetNormalizationDescriptor(NormalizationDescriptorPtr normalizationDescriptor, unsigned int layerIndex)
uint32_t m_PadBottom
Padding bottom value in the height dimension.
bool m_BiasEnabled
Enable/disable bias.
float m_Eps
Used to avoid dividing by zero.
virtual unsigned int GetNumOutputSlots() const =0
Returns the number of connectable output slots.
armnn::LogicalBinaryOperation ToLogicalBinaryOperation(armnnSerializer::LogicalBinaryOperation operation)
bool m_ProjectionEnabled
Enable/disable the projection layer.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
UnaryOperation m_Operation
Specifies the elementwiseUnary operation to execute.
static TensorRawPtrVector GetOutputs(const GraphPtr &graph, unsigned int layerIndex)
A ViewsDescriptor for the SplitterLayer.
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
float m_ScaleW
Center size encoding scale weight.
#define CHECK_LAYERS(GRAPH, LAYERS_INDEX, LAYER_INDEX)
uint32_t m_PadBottom
Padding bottom value in the height dimension.
bool m_BiasEnabled
Enable/disable bias.
armnn::ReduceOperation ToReduceOperation(armnnSerializer::ReduceOperation operation)
virtual unsigned int GetNumInputSlots() const =0
Returns the number of connectable input slots.
float m_K
Kappa value used for the across channel normalization equation.
A TransposeConvolution2dDescriptor for the TransposeConvolution2dLayer.
const TensorShape & GetShape() const
uint32_t m_PadBottom
Padding bottom value in the height dimension.
uint32_t m_PadLeft
Padding left value in the width dimension.
float m_ClippingThresProj
Clipping threshold value for the projection.
std::string AsString() const
static LayerBaseRawPtr GetBaseLayer(const GraphPtr &graphPtr, unsigned int layerIndex)
A ReshapeDescriptor for the ReshapeLayer.
const armnnSerializer::ConstTensor * ConstTensorRawPtr
uint32_t m_PadBack
Padding back value in the depth dimension.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
const armnnSerializer::NormalizationDescriptor * NormalizationDescriptorPtr
A ComparisonDescriptor for the ComparisonLayer.
static GraphPtr LoadGraphFromBinary(const uint8_t *binaryContent, size_t len)
float m_ScaleX
Center size encoding scale x.
bool m_TransposeWeightMatrix
Enable/disable transpose weight matrix.
uint32_t m_PoolWidth
Pooling width value.
bool m_PeepholeEnabled
Enable/disable peephole.
#define CHECK_TENSOR_PTR(TENSOR_PTR)
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
A Convolution2dDescriptor for the Convolution2dLayer.
float m_Alpha
Alpha value for the normalization equation.
uint32_t m_PadLeft
Padding left value in the width dimension.
const armnnSerializer::QLstmDescriptor * QLstmDescriptorPtr
static armnn::UnidirectionalSequenceLstmDescriptor GetUnidirectionalSequenceLstmDescriptor(UnidirectionalSequenceLstmDescriptorPtr descriptor)
bool m_KeepDims
if true then output shape has no change.
float m_HiddenStateScale
Hidden State quantization scale.
const char * EnumNameConstTensorData(ConstTensorData e)
bool m_BiasEnabled
Enable/disable bias.
unsigned int GetNumBytes() const
float m_OutputIntermediateScale
Output intermediate quantization scale.
ResizeMethod m_Method
The Interpolation method to use (Bilinear, NearestNeighbor).
float m_Gamma
Gamma, the scale scalar value applied for the normalized tensor. Defaults to 1.0. ...
float m_Beta
Exponentiation value.
BindingPointInfo GetNetworkInputBindingInfo(unsigned int layerId, const std::string &name) const
Retrieve binding info (layer id and tensor info) for the network input identified by the given layer ...
std::vector< unsigned int > m_Size
Size of the slice in each dimension.
armnn::INetworkPtr CreateNetworkFromBinary(const std::vector< uint8_t > &binaryContent)
Create an input network from binary file contents.
The padding fields don't count and are ignored.
float m_Eps
Value to add to the variance. Used to avoid dividing by zero.
PaddingMethod m_PaddingMethod
The padding method to be used. (Exclude, IgnoreValue).
ArgMinMaxFunction m_Function
Specify if the function is to find Min or Max.
uint32_t m_DetectionsPerClass
Detections per classes, used in Regular NMS.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
void CheckLayers(Graph &graph)
const armnnSerializer::SerializedGraph * GetSerializedGraph(const void *buf)
uint32_t m_PadTop
Padding top value in the height dimension.
uint32_t m_PadBottom
Padding bottom value in the height dimension.
bool m_BiasEnabled
Enable/disable bias.
A LogicalBinaryDescriptor for the LogicalBinaryLayer.
uint32_t m_PadRight
Padding right value in the width dimension.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
ReduceOperation m_ReduceOperation
Specifies the reduction operation to execute.
bool m_TimeMajor
Enable/disable time major.
Copyright (c) 2021 ARM Limited and Contributors.
void IgnoreUnused(Ts &&...)
uint32_t m_PadBottom
Padding bottom value in the height dimension.
#define CHECK_GRAPH(GRAPH, LAYERS_INDEX)
uint32_t m_DilationY
Dilation along y axis.
A SpaceToDepthDescriptor for the SpaceToDepthLayer.
const armnnSerializer::SerializedGraph * GraphPtr
std::vector< std::pair< unsigned int, unsigned int > > m_PadList
Specifies the padding values for the input dimension: heightPad{top, bottom} widthPad{left, right}.
uint32_t m_DilationX
Dilation along x axis.
uint32_t m_DilationY
Dilation factor value for height dimension.
LogicalBinaryOperation m_Operation
Specifies the logical operation to execute.
A BatchToSpaceNdDescriptor for the BatchToSpaceNdLayer.
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
int LayerBindingId
Type of identifiers for bindable layers (inputs, outputs).
armnn::ComparisonOperation ToComparisonOperation(armnnSerializer::ComparisonOperation operation)
virtual void SetTensorInfo(const TensorInfo &tensorInfo)=0
static int32_t GetBindingLayerInfo(const GraphPtr &graphPtr, unsigned int layerIndex)
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
uint32_t m_NumOutputs
Number of output tensors.
NormalizationAlgorithmMethod m_NormMethodType
Normalization method algorithm to use (LocalBrightness, LocalContrast).
void SetShape(const TensorShape &newShape)
A ResizeBilinearDescriptor for the ResizeBilinearLayer.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
uint32_t m_MaxClassesPerDetection
Maximum numbers of classes per detection, used in Fast NMS.
const armnnSerializer::LayerBase * LayerBaseRawPtr
std::vector< unsigned int > m_Axis
Values for the dimensions to reduce.
A StackDescriptor for the StackLayer.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
TensorShape m_TargetShape
Target shape value.
uint32_t m_PoolHeight
Pooling height value.
uint32_t m_PadTop
Padding top value in the height dimension.
uint32_t m_MaxDetections
Maximum numbers of detections.
A PadDescriptor for the PadLayer.
std::vector< TensorRawPtr > TensorRawPtrVector
void Permute(const armnn::TensorShape &dstShape, const armnn::PermutationVector &mappings, const void *src, void *dst, size_t dataTypeSize)
#define CHECK_CONST_TENSOR_SIZE(CONST_TENSOR_SIZE, TENSOR_SIZE)
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
const armnnSerializer::UnidirectionalSequenceLstmDescriptor * UnidirectionalSequenceLstmDescriptorPtr
armnn::INetworkPtr CreateNetworkFromBinary(const std::vector< uint8_t > &binaryContent)
Create an input network from binary file contents.
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
bool m_LayerNormEnabled
Enable/disable layer normalization.
const armnnSerializer::LstmDescriptor * LstmDescriptorPtr
armnn::DataLayout ToDataLayout(armnnSerializer::DataLayout dataLayout)
bool CheckShape(const armnn::TensorShape &actual, const std::vector< uint32_t > &expected)
float m_NmsIouThreshold
Intersection over union threshold.
static armnn::LstmDescriptor GetLstmDescriptor(LstmDescriptorPtr lstmDescriptor)
An LstmDescriptor for the LstmLayer.
uint32_t m_PadRight
Padding right value in the width dimension.
uint32_t m_DilationX
Dilation factor value for width dimension.
uint32_t m_PadTop
Padding top value in the height dimension.
std::string FileLine() const
Status SetViewSize(uint32_t view, uint32_t coord, uint32_t value)
Set the size of the views.
#define ARMNN_ASSERT_MSG(COND, MSG)
std::vector< unsigned int > m_Begin
Beginning indices of the slice in each dimension.
bool m_KeepDims
Enable/disable keep dimensions. If true, then the reduced dimensions that are of length 1 are kept...
std::vector< unsigned int > m_BlockShape
Block shape values.
float m_Eps
Epsilon, small scalar value added to variance to avoid dividing by zero. Defaults to 1e-12f...
An output connection slot for a layer.
A L2NormalizationDescriptor for the L2NormalizationLayer.
static TensorRawPtrVector GetInputs(const GraphPtr &graph, unsigned int layerIndex)
An ArgMinMaxDescriptor for ArgMinMaxLayer.
An OriginsDescriptor for the ConcatLayer.
A ReduceDescriptor for the REDUCE operators.
float m_ProjectionClip
Clipping threshold value for the projection.
A FullyConnectedDescriptor for the FullyConnectedLayer.
BindingPointInfo GetNetworkOutputBindingInfo(unsigned int layerId, const std::string &name) const
Retrieve binding info (layer id and tensor info) for the network output identified by the given layer...
bool m_BiasEnabled
Enable/disable bias.
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
float m_InputIntermediateScale
Input intermediate quantization scale.
static armnn::Pooling2dDescriptor GetPoolingDescriptor(PoolingDescriptor pooling2dDescriptor, unsigned int layerIndex)
uint32_t m_TargetWidth
Target width value.
A GatherDescriptor for the GatherLayer.
#define CHECK_VALID_SIZE(ACTUAL,...)
bool m_PeepholeEnabled
Enable/disable peephole.
uint32_t m_NumClasses
Number of classes.
#define CHECKED_NON_NEGATIVE(VALUE)
bool m_HalfPixelCenters
Half Pixel Centers.
std::unique_ptr< IDeserializer, void(*)(IDeserializer *parser)> IDeserializerPtr
armnn::ConstTensor ToConstTensor(ConstTensorRawPtr constTensorPtr)
armnn::ActivationFunction ToActivationFunction(armnnSerializer::ActivationFunction function)
uint32_t m_PadTop
Padding top value in the height dimension.
armnn::UnaryOperation ToUnaryOperation(armnnSerializer::UnaryOperation operation)
#define ARMNN_ASSERT(COND)
A StandInDescriptor for the StandIn layer.
A QLstmDescriptor for the QLstmLayer.
#define CHECK_CONST_TENSOR_PTR(TENSOR_PTR)
bool m_UseRegularNms
Use Regular NMS.
uint32_t m_PadFront
Padding front value in the depth dimension.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
std::vector< unsigned int > m_BlockShape
Block shape value.
PaddingMode
The padding mode controls whether the padding should be filled with constant values (Constant)...
An ActivationDescriptor for the ActivationLayer.
const TensorInfo & GetInfo() const
min(a, max(b, input)) ReLu1 & ReLu6.
uint32_t m_PadLeft
Padding left value in the width dimension.
uint32_t m_TargetHeight
Target height value.
uint32_t m_ActivationFunc
The activation function to use.
A SliceDescriptor for the SliceLayer.
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
A Convolution3dDescriptor for the Convolution3dLayer.
uint32_t m_PadRight
Padding right value in the width dimension.
float m_ClippingThresCell
Clipping threshold value for the cell state.
unsigned int m_BlockSize
Scalar specifying the input block size. It must be >= 1.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
float m_ForgetIntermediateScale
Forget intermediate quantization scale.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
float m_Beta
Beta, the offset scalar value applied for the normalized tensor. Defaults to 1.0. ...
armnn::ResizeMethod ToResizeMethod(armnnSerializer::ResizeMethod method)
armnn::PaddingMode ToPaddingMode(armnnSerializer::PaddingMode paddingMode)
std::vector< uint32_t > m_vAxis
The indices of the dimensions to reduce.
float m_ScaleH
Center size encoding scale height.
ComparisonOperation m_Operation
Specifies the comparison operation to execute.
A SpaceToBatchNdDescriptor for the SpaceToBatchNdLayer.
DataLayout m_DataLayout
The data layout to be used (NDHWC, NCDHW).
NormalizationAlgorithmChannel m_NormChannelType
Normalization channel algorithm to use (Across, Within).
float m_CellClip
Clipping threshold value for the cell state.
float m_A
Alpha upper bound value used by the activation functions. (BoundedReLu, Linear, TanH, Elu).
uint32_t m_DilationX
Dilation along x axis.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
const armnnSerializer::TensorInfo * TensorRawPtr
bool m_CifgEnabled
Enable/disable cifg (coupled input & forget gate).
armnn::ArgMinMaxFunction ToArgMinMaxFunction(armnnSerializer::ArgMinMaxFunction function)
uint32_t GetNumInputs() const
Get the number of views/inputs.
uint32_t m_PadLeft
Padding left value in the width dimension.
EmptyOptional is used to initialize the Optional class in case we want to have default value for an O...
bool m_AlignCorners
Aligned corners.
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
int32_t m_Axis
The axis in params to gather indices from.
A ElementwiseUnaryDescriptor for the ElementwiseUnaryLayer.
PoolingAlgorithm m_PoolType
The pooling algorithm to use (Max. Average, L2).
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
The padding fields count, but are ignored.
std::vector< std::pair< unsigned int, unsigned int > > m_Crops
The values to crop from the input dimension.
Base class for all ArmNN exceptions so that users can filter to just those.
static std::string GetLayerName(const GraphPtr &graph, unsigned int index)
uint32_t m_PadTop
Padding top value in the height dimension.
unsigned int GetNumDimensions() const
Function that returns the tensor rank.
bool m_ProjectionEnabled
Enable/disable the projection layer.
Jarret 2009: Local Contrast Normalization.
OutputShapeRounding m_OutputShapeRounding
The rounding method for the output shape. (Floor, Ceiling).
uint32_t m_NumInputs
Number of input tensors.
virtual const IInputSlot & GetInputSlot(unsigned int index) const =0
Get a const input slot handle by slot index.
A MeanDescriptor for the MeanLayer.
void SetConstant(const bool IsConstant=true)
Marks the data corresponding to this tensor info as constant.
static armnn::QLstmDescriptor GetQLstmDescriptor(QLstmDescriptorPtr qLstmDescriptorPtr)
static armnn::TensorInfo OutputShapeOfReshape(const armnn::TensorInfo &inputTensorInfo, const std::vector< uint32_t > &targetDimsIn)
bool m_LayerNormEnabled
Enable/disable layer normalization.
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
armnn::TensorInfo ToTensorInfo(TensorRawPtr tensorPtr)
uint32_t m_PadRight
Padding right value in the width dimension.
A TransposeDescriptor for the TransposeLayer.
A StridedSliceDescriptor for the StridedSliceLayer.
uint32_t m_Axis
Axis to apply channel shuffle operation on.
uint32_t GetNumInputs() const
Get the number of views/inputs.
virtual const IOutputSlot & GetOutputSlot(unsigned int index) const =0
Get the const output slot handle by slot index.
int m_Axis
Axis to reduce across the input tensor.
float m_ScaleY
Center size encoding scale y.
float m_NmsScoreThreshold
NMS score threshold.
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
virtual int Connect(IInputSlot &destination)=0
Krichevsky 2012: Local Brightness Normalization.
const char * EnumNameDataType(DataType e)
A Pooling2dDescriptor for the Pooling2dLayer.
A NormalizationDescriptor for the NormalizationLayer.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
An InstanceNormalizationDescriptor for InstanceNormalizationLayer.
A ChannelShuffleDescriptor for the ChannelShuffle operator.
float m_CellIntermediateScale
Cell intermediate quantization scale.
uint32_t m_DilationZ
Dilation along z axis.
float m_B
Beta lower bound value used by the activation functions. (BoundedReLu, Linear, TanH).
armnn::TensorShape Permuted(const armnn::TensorShape &srcShape, const armnn::PermutationVector &mappings)
A SoftmaxDescriptor for the SoftmaxLayer.
float m_Beta
Beta value for the normalization equation.
uint32_t m_StrideZ
Stride value when proceeding through input for the depth dimension.
const armnnSerializer::OriginsDescriptor * GetOriginsDescriptor(const armnnSerializer::SerializedGraph *graph, unsigned int layerIndex)
bool m_CifgEnabled
Enable/disable CIFG (coupled input & forget gate).
uint32_t m_NormSize
Depth radius value.
Status SetViewOriginCoord(uint32_t view, uint32_t coord, uint32_t value)
Set the view origin coordinates.
ActivationFunction m_Function
The activation function to use (Sigmoid, TanH, Linear, ReLu, BoundedReLu, SoftReLu, LeakyReLu, Abs, Sqrt, Square, Elu).
const armnnSerializer::Pooling2dDescriptor * PoolingDescriptor
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
A DepthwiseConvolution2dDescriptor for the DepthwiseConvolution2dLayer.
constexpr unsigned int MaxNumOfTensorDimensions
uint32_t m_DilationY
Dilation along y axis.
A FillDescriptor for the FillLayer.
A BatchNormalizationDescriptor for the BatchNormalizationLayer.
uint32_t m_PadLeft
Padding left value in the width dimension.
unsigned int GetNumElements() const
constexpr unsigned int GetDataTypeSize(DataType dataType)
A PermuteDescriptor for the PermuteLayer.
uint32_t m_PadRight
Padding right value in the width dimension.
int32_t m_HiddenStateZeroPoint
Hidden State zero point.
bool m_ConstantWeights
Enable/disable constant weights and biases.