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),
275 auto layerType = graphPtr->layers()->Get(layerIndex)->layer_type();
280 return graphPtr->layers()->Get(layerIndex)->layer_as_AbsLayer()->base();
282 return graphPtr->layers()->Get(layerIndex)->layer_as_ActivationLayer()->base();
284 return graphPtr->layers()->Get(layerIndex)->layer_as_AdditionLayer()->base();
286 return graphPtr->layers()->Get(layerIndex)->layer_as_ArgMinMaxLayer()->base();
288 return graphPtr->layers()->Get(layerIndex)->layer_as_BatchToSpaceNdLayer()->base();
290 return graphPtr->layers()->Get(layerIndex)->layer_as_BatchNormalizationLayer()->base();
292 return graphPtr->layers()->Get(layerIndex)->layer_as_ComparisonLayer()->base();
294 return graphPtr->layers()->Get(layerIndex)->layer_as_ConcatLayer()->base();
296 return graphPtr->layers()->Get(layerIndex)->layer_as_ConstantLayer()->base();
298 return graphPtr->layers()->Get(layerIndex)->layer_as_Convolution2dLayer()->base();
300 return graphPtr->layers()->Get(layerIndex)->layer_as_DepthToSpaceLayer()->base();
302 return graphPtr->layers()->Get(layerIndex)->layer_as_DepthwiseConvolution2dLayer()->base();
304 return graphPtr->layers()->Get(layerIndex)->layer_as_DequantizeLayer()->base();
306 return graphPtr->layers()->Get(layerIndex)->layer_as_DetectionPostProcessLayer()->base();
308 return graphPtr->layers()->Get(layerIndex)->layer_as_DivisionLayer()->base();
310 return graphPtr->layers()->Get(layerIndex)->layer_as_EqualLayer()->base();
312 return graphPtr->layers()->Get(layerIndex)->layer_as_ElementwiseUnaryLayer()->base();
314 return graphPtr->layers()->Get(layerIndex)->layer_as_FullyConnectedLayer()->base();
316 return graphPtr->layers()->Get(layerIndex)->layer_as_FillLayer()->base();
318 return graphPtr->layers()->Get(layerIndex)->layer_as_FloorLayer()->base();
320 return graphPtr->layers()->Get(layerIndex)->layer_as_GatherLayer()->base();
322 return graphPtr->layers()->Get(layerIndex)->layer_as_GreaterLayer()->base();
324 return graphPtr->layers()->Get(layerIndex)->layer_as_InputLayer()->base()->base();
326 return graphPtr->layers()->Get(layerIndex)->layer_as_InstanceNormalizationLayer()->base();
328 return graphPtr->layers()->Get(layerIndex)->layer_as_L2NormalizationLayer()->base();
330 return graphPtr->layers()->Get(layerIndex)->layer_as_LogicalBinaryLayer()->base();
332 return graphPtr->layers()->Get(layerIndex)->layer_as_LogSoftmaxLayer()->base();
334 return graphPtr->layers()->Get(layerIndex)->layer_as_LstmLayer()->base();
336 return graphPtr->layers()->Get(layerIndex)->layer_as_MeanLayer()->base();
338 return graphPtr->layers()->Get(layerIndex)->layer_as_MinimumLayer()->base();
340 return graphPtr->layers()->Get(layerIndex)->layer_as_MaximumLayer()->base();
342 return graphPtr->layers()->Get(layerIndex)->layer_as_MergeLayer()->base();
344 return graphPtr->layers()->Get(layerIndex)->layer_as_MergerLayer()->base();
346 return graphPtr->layers()->Get(layerIndex)->layer_as_MultiplicationLayer()->base();
348 return graphPtr->layers()->Get(layerIndex)->layer_as_NormalizationLayer()->base();
350 return graphPtr->layers()->Get(layerIndex)->layer_as_OutputLayer()->base()->base();
352 return graphPtr->layers()->Get(layerIndex)->layer_as_PadLayer()->base();
354 return graphPtr->layers()->Get(layerIndex)->layer_as_PermuteLayer()->base();
356 return graphPtr->layers()->Get(layerIndex)->layer_as_Pooling2dLayer()->base();
358 return graphPtr->layers()->Get(layerIndex)->layer_as_PreluLayer()->base();
360 return graphPtr->layers()->Get(layerIndex)->layer_as_QLstmLayer()->base();
362 return graphPtr->layers()->Get(layerIndex)->layer_as_QuantizeLayer()->base();
364 return graphPtr->layers()->Get(layerIndex)->layer_as_QuantizedLstmLayer()->base();
366 return graphPtr->layers()->Get(layerIndex)->layer_as_RankLayer()->base();
368 return graphPtr->layers()->Get(layerIndex)->layer_as_ReduceLayer()->base();
370 return graphPtr->layers()->Get(layerIndex)->layer_as_ReshapeLayer()->base();
372 return graphPtr->layers()->Get(layerIndex)->layer_as_ResizeBilinearLayer()->base();
374 return graphPtr->layers()->Get(layerIndex)->layer_as_ResizeLayer()->base();
376 return graphPtr->layers()->Get(layerIndex)->layer_as_RsqrtLayer()->base();
378 return graphPtr->layers()->Get(layerIndex)->layer_as_SliceLayer()->base();
380 return graphPtr->layers()->Get(layerIndex)->layer_as_SoftmaxLayer()->base();
382 return graphPtr->layers()->Get(layerIndex)->layer_as_SpaceToBatchNdLayer()->base();
384 return graphPtr->layers()->Get(layerIndex)->layer_as_SpaceToDepthLayer()->base();
386 return graphPtr->layers()->Get(layerIndex)->layer_as_SplitterLayer()->base();
388 return graphPtr->layers()->Get(layerIndex)->layer_as_StackLayer()->base();
390 return graphPtr->layers()->Get(layerIndex)->layer_as_StandInLayer()->base();
392 return graphPtr->layers()->Get(layerIndex)->layer_as_StridedSliceLayer()->base();
394 return graphPtr->layers()->Get(layerIndex)->layer_as_SubtractionLayer()->base();
396 return graphPtr->layers()->Get(layerIndex)->layer_as_SwitchLayer()->base();
398 return graphPtr->layers()->Get(layerIndex)->layer_as_TransposeConvolution2dLayer()->base();
400 return graphPtr->layers()->Get(layerIndex)->layer_as_TransposeLayer()->base();
403 throw ParseException(fmt::format(
"Layer type {} not recognized", layerType));
411 return layer->layerName()->str();
416 auto layerType = graphPtr->layers()->Get(layerIndex)->layer_type();
420 return graphPtr->layers()->Get(layerIndex)->layer_as_InputLayer()->base()->layerBindingId();
424 return graphPtr->layers()->Get(layerIndex)->layer_as_OutputLayer()->base()->layerBindingId();
573 switch (tensorPtr->dataType())
604 throw ParseException(fmt::format(
"Unsupported data type {0} = {1}. {2}",
605 tensorPtr->dataType(),
611 float quantizationScale = tensorPtr->quantizationScale();
612 int32_t quantizationOffset = tensorPtr->quantizationOffset();
614 if (tensorPtr->dimensionality() ==
static_cast<unsigned int>(Dimensionality::Scalar))
621 else if (tensorPtr->dimensionality() ==
static_cast<unsigned int>(Dimensionality::NotSpecified))
630 auto dimensions = tensorPtr->dimensions();
631 unsigned int size = dimensions->size();
632 std::vector<unsigned int> outputDims(dimensions->begin(), dimensions->begin() + size);
637 if (tensorPtr->dimensionSpecificity() !=
nullptr)
639 auto dimensionSpecificity = tensorPtr->dimensionSpecificity();
640 size = dimensionSpecificity->size();
641 for (
unsigned int i = 0; i < size; ++i)
643 dimensionsSpecificity[i] = dimensionSpecificity->Get(i);
647 TensorShape shape(size, outputDims.data(), dimensionsSpecificity);
649 auto quantizationScales = tensorPtr->quantizationScales();
650 if (quantizationScales)
652 unsigned int quantizationScalesSize = quantizationScales->size();
653 std::vector<float> scales(quantizationScales->begin(), quantizationScales->begin() + quantizationScalesSize);
654 unsigned int quantizationDim = tensorPtr->quantizationDim();
676 switch (constTensorPtr->data_type())
680 auto byteData = constTensorPtr->data_as_ByteData()->data();
686 auto shortData = constTensorPtr->data_as_ShortData()->data();
692 auto intData = constTensorPtr->data_as_IntData()->data();
698 auto longData = constTensorPtr->data_as_LongData()->data();
705 throw ParseException(fmt::format(
"Unsupported data type {0} = {1}. {2}",
706 constTensorPtr->data_type(),
717 const auto& numInputs = layer->inputSlots()->size();
721 for (
unsigned int i=0; i<numInputs; ++i)
724 (layer->inputSlots()->Get(i)->connection()->sourceLayerIndex()));
725 result[i] =
GetBaseLayer(graphPtr, inputId)->outputSlots()->Get(0)->tensorInfo();
734 const auto& numOutputs = layer->outputSlots()->size();
738 for (
unsigned int i=0; i<numOutputs; ++i)
740 result[i] = layer->outputSlots()->Get(i)->tensorInfo();
745 void IDeserializer::DeserializerImpl::ParseUnsupportedLayer(
GraphPtr graph,
unsigned int layerIndex)
748 const auto layerName =
GetBaseLayer(graph, layerIndex)->layerName()->c_str();
749 throw ParseException(fmt::format(
"Layer not supported. layerIndex: {0} " 750 "layerName: {1} / {2}",
756 void IDeserializer::DeserializerImpl::ResetParser()
759 m_InputBindings.clear();
760 m_OutputBindings.clear();
768 return CreateNetworkFromGraph(graph);
774 std::vector<uint8_t> content((std::istreambuf_iterator<char>(binaryContent)), std::istreambuf_iterator<char>());
776 return CreateNetworkFromGraph(graph);
781 if (binaryContent ==
nullptr)
786 flatbuffers::Verifier verifier(binaryContent, len);
787 if (verifier.VerifyBuffer<SerializedGraph>() ==
false)
789 throw ParseException(fmt::format(
"Buffer doesn't conform to the expected Armnn " 790 "flatbuffers format. size:{0} {1}",
799 m_Network = INetwork::Create();
801 unsigned int layerIndex = 0;
802 for (AnyLayer
const* layer : *graph->layers())
808 auto& parserFunction = m_ParserFunctions[layer->layer_type()];
809 (this->*parserFunction)(graph, layerIndex);
814 SetupInputLayers(graph);
815 SetupOutputLayers(graph);
818 for (
auto&& graphIt : m_GraphConnections)
820 Connections& connections = graphIt.second;
821 for (
auto&& outputIt : connections.outputSlots)
823 const unsigned int outputSlotIndex = outputIt.first;
825 if (connections.inputSlots.find(outputSlotIndex) != connections.inputSlots.end())
827 for (
IInputSlot* inputSlot : connections.inputSlots[outputSlotIndex])
829 outputSlot->
Connect(*inputSlot);
835 return std::move(m_Network);
839 const std::string& name)
const 842 for (
auto inputBinding : m_InputBindings)
844 if (inputBinding.first == name)
846 return inputBinding.second;
849 throw ParseException(fmt::format(
"No input binding found for layer:{0} / {1}",
855 const std::string& name)
const 858 for (
auto outputBinding : m_OutputBindings)
860 if (outputBinding.first == name)
862 return outputBinding.second;
865 throw ParseException(fmt::format(
"No output binding found for layer:{0} / {1}",
870 unsigned int IDeserializer::DeserializerImpl::GetInputLayerInVector(
GraphPtr graph,
int targetId)
872 for (
unsigned int i = 0; i < graph->layers()->size(); i++)
874 auto layer = graph->layers()->Get(i);
877 auto layerBindingId = layer->layer_as_InputLayer()->base()->layerBindingId();
878 if (layerBindingId == targetId)
884 throw ParseException(
"Input layer with given layerBindingId not found");
887 unsigned int IDeserializer::DeserializerImpl::GetOutputLayerInVector(
GraphPtr graph,
int targetId)
889 for (
unsigned int i = 0; i < graph->layers()->size(); i++)
891 auto layer = graph->layers()->Get(i);
894 auto layerBindingId = layer->layer_as_OutputLayer()->base()->layerBindingId();
895 if (layerBindingId == targetId)
901 throw ParseException(
"Output layer with given layerBindingId not found");
904 unsigned int IDeserializer::DeserializerImpl::GetLayerIndexInVector(
GraphPtr graph,
unsigned int targetIndex)
906 for (
unsigned int i = 0; i < graph->layers()->size(); i++)
909 if (layer->index() == targetIndex)
917 IDeserializer::DeserializerImpl::FeatureVersions IDeserializer::DeserializerImpl::GetFeatureVersions(
GraphPtr graph)
919 IDeserializer::DeserializerImpl::FeatureVersions versions;
921 if (graph->featureVersions())
923 versions.m_BindingIdScheme = graph->featureVersions()->bindingIdsScheme();
929 void IDeserializer::DeserializerImpl::SetupInputLayers(
GraphPtr graph)
932 const unsigned int numInputs = graph->inputIds()->size();
933 m_InputBindings.clear();
934 m_InputBindings.reserve(numInputs);
936 for (
unsigned int i = 0; i < numInputs; i++)
938 unsigned int inputLayerIndex = 0xFFFFFFFF;
939 if (GetFeatureVersions(graph).m_BindingIdScheme == 0)
942 inputLayerIndex = GetLayerIndexInVector(graph, inputId);
946 const int inputId = graph->inputIds()->Get(i);
947 inputLayerIndex = GetInputLayerInVector(graph, inputId);
957 m_Network->AddInputLayer(bindingId, baseLayer->layerName()->c_str());
960 inputLayer->GetOutputSlot(0).SetTensorInfo(tensorInfo);
961 RegisterOutputSlots(graph, inputLayerIndex, inputLayer);
964 m_InputBindings.push_back(std::make_pair(baseLayer->layerName()->c_str(), bindingInfo));
968 void IDeserializer::DeserializerImpl::SetupOutputLayers(
GraphPtr graph)
971 const unsigned int numOutputs = graph->outputIds()->size();
972 m_OutputBindings.clear();
973 m_OutputBindings.reserve(numOutputs);
975 for (
unsigned int i = 0; i < numOutputs; i++)
977 unsigned int outputLayerIndex = 0xFFFFFFFF;
978 if (GetFeatureVersions(graph).m_BindingIdScheme == 0)
980 const unsigned int outputId =
armnn::numeric_cast<
unsigned int>(graph->outputIds()->Get(i));
981 outputLayerIndex = GetLayerIndexInVector(graph, outputId);
985 const int outputId = graph->outputIds()->Get(i);
986 outputLayerIndex = GetOutputLayerInVector(graph, outputId);
996 m_Network->AddOutputLayer(bindingId, baseLayer->layerName()->c_str());
998 RegisterInputSlots(graph, outputLayerIndex, outputLayer);
1000 unsigned int sourceLayerIndex =
1001 GetLayerIndexInVector(graph, baseLayer->inputSlots()->Get(0)->connection()->sourceLayerIndex());
1006 m_OutputBindings.push_back(std::make_pair(baseLayer->layerName()->c_str(), bindingInfo));
1010 void IDeserializer::DeserializerImpl::RegisterOutputSlots(
GraphPtr graph,
1011 uint32_t layerIndex,
1019 throw ParseException(fmt::format(
"The number of outputslots ({0}) does not match the number expected ({1})" 1020 " for layer index: {2} {3}",
1021 baseLayer->outputSlots()->size(),
1029 const unsigned int slotIndex = baseLayer->outputSlots()->Get(i)->index();
1032 RegisterOutputSlotOfConnection(baseLayer->index(), slotIndex, outputSlot);
1036 void IDeserializer::DeserializerImpl::RegisterInputSlots(
GraphPtr graph,
1037 uint32_t layerIndex,
1045 throw ParseException(fmt::format(
"The number of inputslots ({0}) does not match the number expected ({1})" 1046 " for layer index:{2} {3}",
1047 baseLayer->inputSlots()->size(),
1055 auto fbInputSlot = baseLayer->inputSlots()->Get(i);
1056 auto fbConnection = fbInputSlot->connection();
1058 RegisterInputSlotOfConnection(fbConnection->sourceLayerIndex(), fbConnection->outputSlotIndex(), inputSlot);
1062 void IDeserializer::DeserializerImpl::RegisterInputSlotOfConnection(uint32_t sourceLayerIndex,
1063 uint32_t outputSlotIndex,
1066 if (m_GraphConnections.find(sourceLayerIndex) == m_GraphConnections.end())
1068 m_GraphConnections[sourceLayerIndex] = Connections();
1071 Connections& connections = m_GraphConnections[sourceLayerIndex];
1072 if (connections.inputSlots.find(outputSlotIndex) == connections.inputSlots.end())
1074 connections.inputSlots[outputSlotIndex] = {inputSlot};
1078 connections.inputSlots[outputSlotIndex].push_back(inputSlot);
1082 void IDeserializer::DeserializerImpl::RegisterOutputSlotOfConnection(uint32_t sourceLayerIndex,
1083 uint32_t outputSlotIndex,
1086 if (m_GraphConnections.find(sourceLayerIndex) == m_GraphConnections.end())
1088 m_GraphConnections[sourceLayerIndex] = Connections();
1091 Connections& connections = m_GraphConnections[sourceLayerIndex];
1092 if (connections.outputSlots.find(outputSlotIndex) != connections.outputSlots.end())
1097 connections.outputSlots[outputSlotIndex] = outputSlot;
1100 void IDeserializer::DeserializerImpl::ParseAbs(
GraphPtr graph,
unsigned int layerIndex)
1103 auto inputs =
GetInputs(graph, layerIndex);
1107 auto outputs =
GetOutputs(graph, layerIndex);
1113 IConnectableLayer* layer = m_Network->AddElementwiseUnaryLayer(descriptor, layerName.c_str());
1117 RegisterInputSlots(graph, layerIndex, layer);
1118 RegisterOutputSlots(graph, layerIndex, layer);
1121 void IDeserializer::DeserializerImpl::ParseActivation(
GraphPtr graph,
unsigned int layerIndex)
1124 auto inputs =
GetInputs(graph, layerIndex);
1128 auto outputs =
GetOutputs(graph, layerIndex);
1131 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_ActivationLayer();
1133 auto serializerDescriptor = serializerLayer->descriptor();
1137 descriptor.
m_A = serializerDescriptor->a();
1138 descriptor.
m_B = serializerDescriptor->b();
1145 RegisterInputSlots(graph, layerIndex, layer);
1146 RegisterOutputSlots(graph, layerIndex, layer);
1149 void IDeserializer::DeserializerImpl::ParseAdd(
GraphPtr graph,
unsigned int layerIndex)
1152 auto inputs =
GetInputs(graph, layerIndex);
1156 auto outputs =
GetOutputs(graph, layerIndex);
1165 RegisterInputSlots(graph, layerIndex, layer);
1166 RegisterOutputSlots(graph, layerIndex, layer);
1169 void IDeserializer::DeserializerImpl::ParseArgMinMax(
GraphPtr graph,
unsigned int layerIndex)
1172 auto inputs =
GetInputs(graph, layerIndex);
1176 auto outputs =
GetOutputs(graph, layerIndex);
1179 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_ArgMinMaxLayer();
1180 auto serializerDescriptor = serializerLayer->descriptor();
1184 descriptor.
m_Axis = serializerDescriptor->axis();
1186 IConnectableLayer* layer = m_Network->AddArgMinMaxLayer(descriptor, layerName.c_str());
1191 RegisterInputSlots(graph, layerIndex, layer);
1192 RegisterOutputSlots(graph, layerIndex, layer);
1195 void IDeserializer::DeserializerImpl::ParseBatchToSpaceNd(
GraphPtr graph,
unsigned int layerIndex)
1205 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_BatchToSpaceNdLayer()->descriptor();
1206 auto flatBufferCrops = flatBufferDescriptor->crops();
1207 auto flatBufferBlockShape = flatBufferDescriptor->blockShape();
1209 if (flatBufferCrops->Length() % 2 != 0)
1214 std::vector<std::pair<unsigned int, unsigned int>> crops;
1215 crops.reserve(flatBufferCrops->Length() / 2);
1216 for (
unsigned int i = 0; i < flatBufferCrops->Length() - 1; i += 2)
1218 crops.emplace_back(flatBufferCrops->Get(i), flatBufferCrops->Get(i+1));
1224 std::vector<unsigned int>(flatBufferBlockShape->begin(), flatBufferBlockShape->end());
1228 IConnectableLayer* layer = m_Network->AddBatchToSpaceNdLayer(descriptor, layerName.c_str());
1233 RegisterInputSlots(graph, layerIndex, layer);
1234 RegisterOutputSlots(graph, layerIndex, layer);
1237 void IDeserializer::DeserializerImpl::ParseBatchNormalization(
GraphPtr graph,
unsigned int layerIndex)
1241 auto inputs =
GetInputs(graph, layerIndex);
1244 auto outputs =
GetOutputs(graph, layerIndex);
1250 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_BatchNormalizationLayer();
1251 auto serializerDescriptor = serializerLayer->descriptor();
1254 descriptor.
m_Eps = serializerDescriptor->eps();
1268 layer->GetOutputSlot(0).SetTensorInfo(outputInfo);
1270 RegisterInputSlots(graph, layerIndex, layer);
1271 RegisterOutputSlots(graph, layerIndex, layer);
1274 void IDeserializer::DeserializerImpl::ParseConstant(
GraphPtr graph,
unsigned int layerIndex)
1279 auto outputs =
GetOutputs(graph, layerIndex);
1284 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_ConstantLayer();
1285 auto serializerInput = serializerLayer->input();
1289 IConnectableLayer* layer = m_Network->AddConstantLayer(input, layerName.c_str());
1294 RegisterOutputSlots(graph, layerIndex, layer);
1297 void IDeserializer::DeserializerImpl::ParseConvolution2d(
GraphPtr graph,
unsigned int layerIndex)
1300 auto inputs =
GetInputs(graph, layerIndex);
1304 auto outputs =
GetOutputs(graph, layerIndex);
1307 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_Convolution2dLayer();
1309 auto serializerDescriptor = serializerLayer->descriptor();
1312 descriptor.
m_PadLeft = serializerDescriptor->padLeft();
1313 descriptor.
m_PadRight = serializerDescriptor->padRight();
1314 descriptor.
m_PadTop = serializerDescriptor->padTop();
1315 descriptor.
m_PadBottom = serializerDescriptor->padBottom();
1316 descriptor.
m_StrideX = serializerDescriptor->strideX();
1317 descriptor.
m_StrideY = serializerDescriptor->strideY();;
1318 descriptor.
m_DilationX = serializerDescriptor->dilationX();
1319 descriptor.
m_DilationY = serializerDescriptor->dilationY();;
1320 descriptor.
m_BiasEnabled = serializerDescriptor->biasEnabled();;
1337 layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo);
1339 RegisterInputSlots(graph, layerIndex, layer);
1340 RegisterOutputSlots(graph, layerIndex, layer);
1343 void IDeserializer::DeserializerImpl::ParseDepthToSpace(
GraphPtr graph,
unsigned int layerIndex)
1347 auto inputs =
GetInputs(graph, layerIndex);
1350 auto outputs =
GetOutputs(graph, layerIndex);
1353 auto fbDescriptor = graph->layers()->Get(layerIndex)->layer_as_DepthToSpaceLayer()->descriptor();
1356 descriptor.
m_BlockSize = fbDescriptor->blockSize();
1360 IConnectableLayer* layer = m_Network->AddDepthToSpaceLayer(descriptor, layerName.c_str());
1365 RegisterInputSlots(graph, layerIndex, layer);
1366 RegisterOutputSlots(graph, layerIndex, layer);
1369 void IDeserializer::DeserializerImpl::ParseDepthwiseConvolution2d(
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_DepthwiseConvolution2dLayer();
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();;
1404 IConnectableLayer* layer = m_Network->AddDepthwiseConvolution2dLayer(descriptor,
1410 layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo);
1412 RegisterInputSlots(graph, layerIndex, layer);
1413 RegisterOutputSlots(graph, layerIndex, layer);
1416 void IDeserializer::DeserializerImpl::ParseDetectionPostProcess(
GraphPtr graph,
unsigned int layerIndex)
1419 auto inputs =
GetInputs(graph, layerIndex);
1423 auto outputs =
GetOutputs(graph, layerIndex);
1426 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_DetectionPostProcessLayer();
1428 auto flatBufferDescriptor = flatBufferLayer->descriptor();
1436 descriptor.
m_NumClasses = flatBufferDescriptor->numClasses();
1438 descriptor.
m_ScaleX = flatBufferDescriptor->scaleX();
1439 descriptor.
m_ScaleY = flatBufferDescriptor->scaleY();
1440 descriptor.
m_ScaleW = flatBufferDescriptor->scaleW();
1441 descriptor.
m_ScaleH = flatBufferDescriptor->scaleH();
1449 for (
unsigned int i = 0; i < 4; i++)
1451 layer->GetOutputSlot(i).SetTensorInfo(
ToTensorInfo(outputs[i]));
1454 RegisterInputSlots(graph, layerIndex, layer);
1455 RegisterOutputSlots(graph, layerIndex, layer);
1458 void IDeserializer::DeserializerImpl::ParseDivision(
GraphPtr graph,
unsigned int layerIndex)
1461 auto inputs =
GetInputs(graph, layerIndex);
1465 auto outputs =
GetOutputs(graph, layerIndex);
1474 RegisterInputSlots(graph, layerIndex, layer);
1475 RegisterOutputSlots(graph, layerIndex, layer);
1478 void IDeserializer::DeserializerImpl::ParseEqual(
GraphPtr graph,
unsigned int layerIndex)
1481 auto inputs =
GetInputs(graph, layerIndex);
1485 auto outputs =
GetOutputs(graph, layerIndex);
1490 IConnectableLayer* layer = m_Network->AddComparisonLayer(descriptor, layerName.c_str());
1495 RegisterInputSlots(graph, layerIndex, layer);
1496 RegisterOutputSlots(graph, layerIndex, layer);
1499 void IDeserializer::DeserializerImpl::ParseFill(
GraphPtr graph,
unsigned int layerIndex)
1502 auto inputs =
GetInputs(graph, layerIndex);
1506 auto outputs =
GetOutputs(graph, layerIndex);
1511 IConnectableLayer* layer = m_Network->AddFillLayer(descriptor, layerName.c_str());
1516 RegisterInputSlots(graph, layerIndex, layer);
1517 RegisterOutputSlots(graph, layerIndex, layer);
1520 void IDeserializer::DeserializerImpl::ParseGreater(
GraphPtr graph,
unsigned int layerIndex)
1523 auto inputs =
GetInputs(graph, layerIndex);
1527 auto outputs =
GetOutputs(graph, layerIndex);
1532 IConnectableLayer* layer = m_Network->AddComparisonLayer(descriptor, layerName.c_str());
1537 RegisterInputSlots(graph, layerIndex, layer);
1538 RegisterOutputSlots(graph, layerIndex, layer);
1541 void IDeserializer::DeserializerImpl::ParseInstanceNormalization(
GraphPtr graph,
unsigned int layerIndex)
1545 auto inputs =
GetInputs(graph, layerIndex);
1548 auto outputs =
GetOutputs(graph, layerIndex);
1551 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_InstanceNormalizationLayer();
1552 auto fbDescriptor = fbLayer->descriptor();
1555 descriptor.
m_Gamma = fbDescriptor->gamma();
1556 descriptor.
m_Beta = fbDescriptor->beta();
1557 descriptor.
m_Eps = fbDescriptor->eps();
1560 const std::string layerName =
GetLayerName(graph, layerIndex);
1563 IConnectableLayer* layer = m_Network->AddInstanceNormalizationLayer(descriptor, layerName.c_str());
1566 RegisterInputSlots(graph, layerIndex, layer);
1567 RegisterOutputSlots(graph, layerIndex, layer);
1570 void IDeserializer::DeserializerImpl::ParseL2Normalization(
GraphPtr graph,
unsigned int layerIndex)
1574 auto inputs =
GetInputs(graph, layerIndex);
1577 auto outputs =
GetOutputs(graph, layerIndex);
1581 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_L2NormalizationLayer();
1582 auto flatBufferDescriptor = flatBufferLayer->descriptor();
1587 descriptor.
m_Eps = flatBufferDescriptor->eps();
1589 IConnectableLayer* layer = m_Network->AddL2NormalizationLayer(descriptor, layerName.c_str());
1592 RegisterInputSlots(graph, layerIndex, layer);
1593 RegisterOutputSlots(graph, layerIndex, layer);
1596 void IDeserializer::DeserializerImpl::ParseLogicalBinary(
GraphPtr graph,
unsigned int layerIndex)
1601 auto inputs =
GetInputs(graph, layerIndex);
1604 auto outputs =
GetOutputs(graph, layerIndex);
1607 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_LogicalBinaryLayer();
1608 auto fbDescriptor = fbLayer->descriptor();
1613 const std::string& layerName =
GetLayerName(graph, layerIndex);
1614 IConnectableLayer* layer = m_Network->AddLogicalBinaryLayer(descriptor, layerName.c_str());
1619 RegisterInputSlots(graph, layerIndex, layer);
1620 RegisterOutputSlots(graph, layerIndex, layer);
1623 void IDeserializer::DeserializerImpl::ParseLogSoftmax(
GraphPtr graph,
unsigned int layerIndex)
1634 descriptor.
m_Beta = graph->layers()->Get(layerIndex)->layer_as_LogSoftmaxLayer()->descriptor()->beta();
1635 descriptor.m_Axis = graph->layers()->Get(layerIndex)->layer_as_LogSoftmaxLayer()->descriptor()->axis();
1638 IConnectableLayer* layer = m_Network->AddLogSoftmaxLayer(descriptor, layerName.c_str());
1643 RegisterInputSlots(graph, layerIndex, layer);
1644 RegisterOutputSlots(graph, layerIndex, layer);
1647 void IDeserializer::DeserializerImpl::ParseMinimum(
GraphPtr graph,
unsigned int layerIndex)
1650 auto inputs =
GetInputs(graph, layerIndex);
1654 auto outputs =
GetOutputs(graph, layerIndex);
1663 RegisterInputSlots(graph, layerIndex, layer);
1664 RegisterOutputSlots(graph, layerIndex, layer);
1667 void IDeserializer::DeserializerImpl::ParseMaximum(
GraphPtr graph,
unsigned int layerIndex)
1670 auto inputs =
GetInputs(graph, layerIndex);
1674 auto outputs =
GetOutputs(graph, layerIndex);
1683 RegisterInputSlots(graph, layerIndex, layer);
1684 RegisterOutputSlots(graph, layerIndex, layer);
1688 unsigned int layerIndex)
1690 auto layerType = graph->layers()->Get(layerIndex)->layer_type();
1695 return graph->layers()->Get(layerIndex)->layer_as_ConcatLayer()->descriptor();
1697 return graph->layers()->Get(layerIndex)->layer_as_MergerLayer()->descriptor();
1703 void IDeserializer::DeserializerImpl::ParseComparison(
GraphPtr graph,
unsigned int layerIndex)
1708 auto inputs =
GetInputs(graph, layerIndex);
1711 auto outputs =
GetOutputs(graph, layerIndex);
1714 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_ComparisonLayer();
1715 auto fbDescriptor = fbLayer->descriptor();
1720 const std::string& layerName =
GetLayerName(graph, layerIndex);
1721 IConnectableLayer* layer = m_Network->AddComparisonLayer(descriptor, layerName.c_str());
1726 RegisterInputSlots(graph, layerIndex, layer);
1727 RegisterOutputSlots(graph, layerIndex, layer);
1730 void IDeserializer::DeserializerImpl::ParseElementwiseUnary(
GraphPtr graph,
unsigned int layerIndex)
1735 auto inputs =
GetInputs(graph, layerIndex);
1738 auto outputs =
GetOutputs(graph, layerIndex);
1741 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_ElementwiseUnaryLayer();
1742 auto fbDescriptor = fbLayer->descriptor();
1747 const std::string& layerName =
GetLayerName(graph, layerIndex);
1748 IConnectableLayer* layer = m_Network->AddElementwiseUnaryLayer(descriptor, layerName.c_str());
1753 RegisterInputSlots(graph, layerIndex, layer);
1754 RegisterOutputSlots(graph, layerIndex, layer);
1757 void IDeserializer::DeserializerImpl::ParseConcat(
GraphPtr graph,
unsigned int layerIndex)
1762 auto outputs =
GetOutputs(graph, layerIndex);
1767 unsigned int numViews = originsDescriptor->numViews();
1768 unsigned int numDimensions = originsDescriptor->numDimensions();
1771 auto inputs =
GetInputs(graph, layerIndex);
1775 auto originsPtr = originsDescriptor->viewOrigins();
1776 for (
unsigned int v = 0; v < numViews; ++v)
1778 auto originPtr = originsPtr->Get(v);
1779 for (
unsigned int d = 0; d < numDimensions; ++d)
1781 uint32_t value = originPtr->data()->Get(d);
1782 descriptor.SetViewOriginCoord(v, d, value);
1785 descriptor.SetConcatAxis(originsDescriptor->concatAxis());
1787 IConnectableLayer* layer = m_Network->AddConcatLayer(descriptor, layerName.c_str());
1791 RegisterInputSlots(graph, layerIndex, layer);
1792 RegisterOutputSlots(graph, layerIndex, layer);
1795 void IDeserializer::DeserializerImpl::ParseMultiplication(
GraphPtr graph,
unsigned int layerIndex)
1798 auto inputs =
GetInputs(graph, layerIndex);
1802 auto outputs =
GetOutputs(graph, layerIndex);
1806 IConnectableLayer* layer = m_Network->AddMultiplicationLayer(layerName.c_str());
1811 RegisterInputSlots(graph, layerIndex, layer);
1812 RegisterOutputSlots(graph, layerIndex, layer);
1815 void IDeserializer::DeserializerImpl::ParseFloor(
GraphPtr graph,
unsigned int layerIndex)
1820 auto inputs =
GetInputs(graph, layerIndex);
1823 auto outputs =
GetOutputs(graph, layerIndex);
1830 layer = m_Network->AddFloorLayer(layerName.c_str());
1835 RegisterInputSlots(graph, layerIndex, layer);
1836 RegisterOutputSlots(graph, layerIndex, layer);
1839 void IDeserializer::DeserializerImpl::ParseFullyConnected(
GraphPtr graph,
unsigned int layerIndex)
1842 auto inputs =
GetInputs(graph, layerIndex);
1846 auto outputs =
GetOutputs(graph, layerIndex);
1849 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_FullyConnectedLayer();
1851 auto flatBufferDescriptor = flatBufferLayer->descriptor();
1854 fullyConnectedDescriptor.
m_BiasEnabled = flatBufferDescriptor->biasEnabled();
1861 if (flatBufferDescriptor->biasEnabled())
1866 layer = m_Network->AddFullyConnectedLayer(fullyConnectedDescriptor,
1872 layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo);
1874 RegisterInputSlots(graph, layerIndex, layer);
1875 RegisterOutputSlots(graph, layerIndex, layer);
1878 void IDeserializer::DeserializerImpl::ParsePad(
GraphPtr graph,
unsigned int layerIndex)
1888 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_PadLayer()->descriptor();
1889 auto flatBufferPadList = flatBufferDescriptor->padList();
1890 float padValue = flatBufferDescriptor->padValue();
1892 if (flatBufferPadList->Length() % 2 != 0)
1894 throw ParseException(fmt::format(
"The size of the pad list must be divisible by 2 {}",
1898 std::vector<std::pair<unsigned int, unsigned int>> padList;
1899 padList.reserve(flatBufferPadList->Length() / 2);
1900 for (
unsigned int i = 0; i < flatBufferPadList->Length() - 1; i += 2)
1902 padList.emplace_back(flatBufferPadList->Get(i), flatBufferPadList->Get(i+1));
1908 IConnectableLayer* layer = m_Network->AddPadLayer(descriptor, layerName.c_str());
1913 RegisterInputSlots(graph, layerIndex, layer);
1914 RegisterOutputSlots(graph, layerIndex, layer);
1917 void IDeserializer::DeserializerImpl::ParsePermute(
GraphPtr graph,
unsigned int layerIndex)
1922 graph->layers()->Get(layerIndex)->layer_as_PermuteLayer()->descriptor()->dimMappings();
1924 auto inputs =
GetInputs(graph, layerIndex);
1927 auto outputs =
GetOutputs(graph, layerIndex);
1934 IConnectableLayer* layer = m_Network->AddPermuteLayer(descriptor, layerName.c_str());
1937 RegisterInputSlots(graph, layerIndex, layer);
1938 RegisterOutputSlots(graph, layerIndex, layer);
1942 unsigned int layerIndex)
1947 switch (pooling2dDesc->poolType())
1965 switch (pooling2dDesc->outputShapeRounding())
1983 switch (pooling2dDesc->paddingMethod())
2001 switch (pooling2dDesc->dataLayout())
2020 desc.
m_PadLeft = pooling2dDesc->padLeft();
2022 desc.
m_PadTop = pooling2dDesc->padTop();
2023 desc.
m_StrideX = pooling2dDesc->strideX();
2024 desc.
m_StrideY = pooling2dDesc->strideY();
2033 void IDeserializer::DeserializerImpl::ParsePooling2d(
GraphPtr graph,
unsigned int layerIndex)
2037 auto pooling2dDes = graph->layers()->Get(layerIndex)->layer_as_Pooling2dLayer()->descriptor();
2038 auto inputs =
GetInputs(graph, layerIndex);
2041 auto outputs =
GetOutputs(graph, layerIndex);
2047 IConnectableLayer* layer = m_Network->AddPooling2dLayer(pooling2dDescriptor, layerName.c_str());
2050 RegisterInputSlots(graph, layerIndex, layer);
2051 RegisterOutputSlots(graph, layerIndex, layer);
2054 void IDeserializer::DeserializerImpl::ParseQuantize(
GraphPtr graph,
unsigned int layerIndex)
2058 auto inputs =
GetInputs(graph, layerIndex);
2061 auto outputs =
GetOutputs(graph, layerIndex);
2069 RegisterInputSlots(graph, layerIndex, layer);
2070 RegisterOutputSlots(graph, layerIndex, layer);
2074 const std::vector<uint32_t>& targetDimsIn)
2076 std::vector<unsigned int> outputDims(targetDimsIn.begin(), targetDimsIn.end());
2077 const auto stretchDim = std::find(targetDimsIn.begin(), targetDimsIn.end(), -1);
2079 if (stretchDim != targetDimsIn.end())
2081 if (std::find(std::next(stretchDim), targetDimsIn.end(), -1) != targetDimsIn.end())
2083 throw ParseException(fmt::format(
"At most one component of shape can be -1 {}",
2087 auto targetNumElements =
2089 std::accumulate(targetDimsIn.begin(), targetDimsIn.end(), -1, std::multiplies<int32_t>()));
2091 auto stretchIndex =
static_cast<size_t>(std::distance(targetDimsIn.begin(), stretchDim));
2092 outputDims[stretchIndex] = inputTensorInfo.
GetNumElements() / targetNumElements;
2103 void IDeserializer::DeserializerImpl::ParseRank(
GraphPtr graph,
unsigned int layerIndex)
2119 RegisterInputSlots(graph, layerIndex, layer);
2120 RegisterOutputSlots(graph, layerIndex, layer);
2123 void IDeserializer::DeserializerImpl::ParseReduce(
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_ReduceLayer();
2135 auto fbDescriptor = fbLayer->descriptor();
2136 auto flatBufferAxis = fbDescriptor->axis();
2139 descriptor.
m_KeepDims = fbDescriptor->keepDims();
2140 descriptor.
m_vAxis = std::vector<unsigned int>(flatBufferAxis->begin(), flatBufferAxis->end());
2143 const std::string& layerName =
GetLayerName(graph, layerIndex);
2144 IConnectableLayer* layer = m_Network->AddReduceLayer(descriptor, layerName.c_str());
2149 RegisterInputSlots(graph, layerIndex, layer);
2150 RegisterOutputSlots(graph, layerIndex, layer);
2153 void IDeserializer::DeserializerImpl::ParseReshape(
GraphPtr graph,
unsigned int layerIndex)
2156 auto inputs =
GetInputs(graph, layerIndex);
2158 auto outputs =
GetOutputs(graph, layerIndex);
2164 const auto targetDims = graph->layers()->Get(layerIndex)->layer_as_ReshapeLayer()->descriptor()->targetShape();
2165 std::vector<uint32_t> outputDims(targetDims->begin(), targetDims->begin() + targetDims->size());
2168 const armnn::TensorShape& reshapeOutputTensorShape = reshapeOutputTensorInfo.GetShape();
2170 const std::vector<uint32_t> expectedDims(outputs[0]->dimensions()->begin(),
2171 outputs[0]->dimensions()->begin() + outputs[0]->dimensions()->size());
2173 if (inputs.size() > 1 && !
CheckShape(reshapeOutputTensorShape, expectedDims))
2175 std::stringstream ss;
2176 ss <<
"New shape defined in reshape parameters " 2177 << reshapeOutputTensorShape
2178 <<
" does not equal output shape " 2179 << actualOutputTensorInfo.
GetShape()
2189 IConnectableLayer* layer = m_Network->AddReshapeLayer(reshapeDesc, layerName.c_str());
2192 RegisterInputSlots(graph, layerIndex, layer);
2193 RegisterOutputSlots(graph, layerIndex, layer);
2196 void IDeserializer::DeserializerImpl::ParseResize(
GraphPtr graph,
unsigned int layerIndex)
2206 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_ResizeLayer()->descriptor();
2209 descriptor.
m_TargetWidth = flatBufferDescriptor->targetWidth();
2210 descriptor.
m_TargetHeight = flatBufferDescriptor->targetHeight();
2213 descriptor.
m_AlignCorners = flatBufferDescriptor->alignCorners();
2217 IConnectableLayer* layer = m_Network->AddResizeLayer(descriptor, layerName.c_str());
2222 RegisterInputSlots(graph, layerIndex, layer);
2223 RegisterOutputSlots(graph, layerIndex, layer);
2226 void IDeserializer::DeserializerImpl::ParseResizeBilinear(
GraphPtr graph,
unsigned int layerIndex)
2236 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_ResizeBilinearLayer()->descriptor();
2239 descriptor.
m_TargetWidth = flatBufferDescriptor->targetWidth();
2240 descriptor.
m_TargetHeight = flatBufferDescriptor->targetHeight();
2243 descriptor.
m_AlignCorners = flatBufferDescriptor->alignCorners();
2247 IConnectableLayer* layer = m_Network->AddResizeLayer(descriptor, layerName.c_str());
2252 RegisterInputSlots(graph, layerIndex, layer);
2253 RegisterOutputSlots(graph, layerIndex, layer);
2256 void IDeserializer::DeserializerImpl::ParseSoftmax(
GraphPtr graph,
unsigned int layerIndex)
2267 descriptor.
m_Beta = graph->layers()->Get(layerIndex)->layer_as_SoftmaxLayer()->descriptor()->beta();
2270 IConnectableLayer* layer = m_Network->AddSoftmaxLayer(descriptor, layerName.c_str());
2275 RegisterInputSlots(graph, layerIndex, layer);
2276 RegisterOutputSlots(graph, layerIndex, layer);
2279 void IDeserializer::DeserializerImpl::ParseSpaceToBatchNd(
GraphPtr graph,
unsigned int layerIndex)
2289 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_SpaceToBatchNdLayer()->descriptor();
2290 auto flatBufferPadList = flatBufferDescriptor->padList();
2291 auto flatBufferBlockShape = flatBufferDescriptor->blockShape();
2293 if (flatBufferPadList->Length() % 2 != 0)
2295 throw ParseException(fmt::format(
"The size of the pad list must be divisible by 2 {}",
2299 std::vector<std::pair<unsigned int, unsigned int>> padList;
2300 padList.reserve(flatBufferPadList->Length() / 2);
2301 for (
unsigned int i = 0; i < flatBufferPadList->Length() - 1; i += 2)
2303 padList.emplace_back(flatBufferPadList->Get(i), flatBufferPadList->Get(i+1));
2309 std::vector<unsigned int>(flatBufferBlockShape->begin(), flatBufferBlockShape->end());
2313 IConnectableLayer* layer = m_Network->AddSpaceToBatchNdLayer(descriptor, layerName.c_str());
2318 RegisterInputSlots(graph, layerIndex, layer);
2319 RegisterOutputSlots(graph, layerIndex, layer);
2322 void IDeserializer::DeserializerImpl::ParseSpaceToDepth(
GraphPtr graph,
unsigned int layerIndex)
2332 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_SpaceToDepthLayer()->descriptor();
2335 descriptor.
m_BlockSize = flatBufferDescriptor->blockSize();
2339 IConnectableLayer* layer = m_Network->AddSpaceToDepthLayer(descriptor, layerName.c_str());
2344 RegisterInputSlots(graph, layerIndex, layer);
2345 RegisterOutputSlots(graph, layerIndex, layer);
2350 unsigned int layerIndex)
2355 switch (normalizationDescriptor->normChannelType())
2373 switch (normalizationDescriptor->normMethodType())
2391 switch (normalizationDescriptor->dataLayout())
2409 desc.
m_Alpha = normalizationDescriptor->alpha();
2410 desc.
m_Beta = normalizationDescriptor->beta();
2411 desc.
m_K = normalizationDescriptor->k();
2412 desc.
m_NormSize = normalizationDescriptor->normSize();
2417 void IDeserializer::DeserializerImpl::ParseNormalization(
GraphPtr graph,
unsigned int layerIndex)
2421 auto normalizationDes = graph->layers()->Get(layerIndex)->layer_as_NormalizationLayer()->descriptor();
2434 IConnectableLayer* layer = m_Network->AddNormalizationLayer(normalizationDescriptor, layerName.c_str());
2437 RegisterInputSlots(graph, layerIndex, layer);
2438 RegisterOutputSlots(graph, layerIndex, layer);
2441 void IDeserializer::DeserializerImpl::ParseRsqrt(
GraphPtr graph,
unsigned int layerIndex)
2444 auto inputs =
GetInputs(graph, layerIndex);
2448 auto outputs =
GetOutputs(graph, layerIndex);
2454 IConnectableLayer* layer = m_Network->AddElementwiseUnaryLayer(descriptor, layerName.c_str());
2458 RegisterInputSlots(graph, layerIndex, layer);
2459 RegisterOutputSlots(graph, layerIndex, layer);
2462 void IDeserializer::DeserializerImpl::ParseSlice(
GraphPtr graph,
unsigned int layerIndex)
2466 auto inputs =
GetInputs(graph, layerIndex);
2469 auto outputs =
GetOutputs(graph, layerIndex);
2472 auto fbDescriptor = graph->layers()->Get(layerIndex)->layer_as_SliceLayer()->descriptor();
2474 auto fbBegin = fbDescriptor->begin();
2475 auto fbSize = fbDescriptor->size();
2477 if (fbBegin->Length() != fbSize->Length())
2479 throw ParseException(fmt::format(
"Begin and size descriptors must have the same length {}",
2484 descriptor.
m_Begin.insert(descriptor.
m_Begin.end(), fbBegin->begin(), fbBegin->end());
2485 descriptor.
m_Size.insert(descriptor.
m_Size.end(), fbSize->begin(), fbSize->end());
2488 IConnectableLayer* layer = m_Network->AddSliceLayer(descriptor, layerName.c_str());
2493 RegisterInputSlots(graph, layerIndex, layer);
2494 RegisterOutputSlots(graph, layerIndex, layer);
2497 void IDeserializer::DeserializerImpl::ParseStridedSlice(
GraphPtr graph,
unsigned int layerIndex)
2507 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_StridedSliceLayer()->descriptor();
2509 auto flatBufferBegin = flatBufferDescriptor->begin();
2510 auto flatBufferEnd = flatBufferDescriptor->end();
2511 auto flatBufferStride = flatBufferDescriptor->stride();
2513 if (!(flatBufferBegin->Length() == flatBufferEnd->Length() &&
2514 flatBufferBegin->Length() == flatBufferStride->Length()))
2516 throw ParseException(fmt::format(
"The size of the begin, end, and stride must be equal {}",
2520 std::vector<int> begin(flatBufferBegin->begin(), flatBufferBegin->end());
2521 std::vector<int> end(flatBufferEnd->begin(), flatBufferEnd->end());
2522 std::vector<int> stride(flatBufferStride->begin(), flatBufferStride->end());
2525 descriptor.m_BeginMask = flatBufferDescriptor->beginMask();
2526 descriptor.m_EndMask = flatBufferDescriptor->endMask();
2527 descriptor.m_ShrinkAxisMask = flatBufferDescriptor->shrinkAxisMask();
2528 descriptor.m_EllipsisMask = flatBufferDescriptor->ellipsisMask();
2529 descriptor.m_NewAxisMask = flatBufferDescriptor->newAxisMask();
2530 descriptor.m_DataLayout =
ToDataLayout(flatBufferDescriptor->dataLayout());
2533 IConnectableLayer* layer = m_Network->AddStridedSliceLayer(descriptor, layerName.c_str());
2538 RegisterInputSlots(graph, layerIndex, layer);
2539 RegisterOutputSlots(graph, layerIndex, layer);
2542 void IDeserializer::DeserializerImpl::ParseSubtraction(
GraphPtr graph,
unsigned int layerIndex)
2545 auto inputs =
GetInputs(graph, layerIndex);
2549 auto outputs =
GetOutputs(graph, layerIndex);
2558 RegisterInputSlots(graph, layerIndex, layer);
2559 RegisterOutputSlots(graph, layerIndex, layer);
2562 void IDeserializer::DeserializerImpl::ParseGather(
GraphPtr graph,
unsigned int layerIndex)
2573 descriptor.
m_Axis = graph->layers()->Get(layerIndex)->layer_as_GatherLayer()->descriptor()->axis();
2576 IConnectableLayer* layer = m_Network->AddGatherLayer(descriptor, layerName.c_str());
2581 RegisterInputSlots(graph, layerIndex, layer);
2582 RegisterOutputSlots(graph, layerIndex, layer);
2585 void IDeserializer::DeserializerImpl::ParseMean(
GraphPtr graph,
unsigned int layerIndex)
2595 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_MeanLayer()->descriptor();
2596 auto flatBufferAxis = flatBufferDescriptor->axis();
2597 auto flatBufferKeepDims = flatBufferDescriptor->keepDims();
2600 descriptor.
m_Axis = std::vector<unsigned int>(flatBufferAxis->begin(), flatBufferAxis->end());
2604 IConnectableLayer* layer = m_Network->AddMeanLayer(descriptor, layerName.c_str());
2609 RegisterInputSlots(graph, layerIndex, layer);
2610 RegisterOutputSlots(graph, layerIndex, layer);
2613 void IDeserializer::DeserializerImpl::ParseSplitter(
GraphPtr graph,
unsigned int layerIndex)
2622 auto flatBufferViewsDescriptor = graph->layers()->Get(layerIndex)->layer_as_SplitterLayer()->descriptor();
2623 auto flatBufferViewSizes = flatBufferViewsDescriptor->viewSizes();
2624 auto flatBufferOriginsDescriptor = flatBufferViewsDescriptor->origins();
2625 auto flatBufferViewOrigins = flatBufferOriginsDescriptor->viewOrigins();
2626 uint32_t numViews = flatBufferOriginsDescriptor->numViews();
2627 uint32_t numDimensions = flatBufferOriginsDescriptor->numDimensions();
2634 for(
unsigned int vIdx = 0; vIdx < numViews; ++vIdx)
2636 for (
unsigned int dIdx = 0; dIdx < numDimensions; ++dIdx)
2638 viewsDescriptor.
SetViewSize(vIdx, dIdx, flatBufferViewSizes->Get(vIdx)->data()->Get(dIdx));
2639 viewsDescriptor.
SetViewOriginCoord(vIdx, dIdx, flatBufferViewOrigins->Get(vIdx)->data()->Get(dIdx));
2644 IConnectableLayer* layer = m_Network->AddSplitterLayer(viewsDescriptor, layerName.c_str());
2647 for(
unsigned int vIdx = 0; vIdx < numViews; ++vIdx)
2653 RegisterInputSlots(graph, layerIndex, layer);
2654 RegisterOutputSlots(graph, layerIndex, layer);
2672 void IDeserializer::DeserializerImpl::ParseLstm(
GraphPtr graph,
unsigned int layerIndex)
2676 auto inputs =
GetInputs(graph, layerIndex);
2679 auto outputs =
GetOutputs(graph, layerIndex);
2682 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_LstmLayer();
2684 auto flatBufferDescriptor = flatBufferLayer->descriptor();
2685 auto flatBufferInputParams = flatBufferLayer->inputParams();
2715 if (!lstmDescriptor.m_CifgEnabled)
2717 inputToInputWeights =
ToConstTensor(flatBufferInputParams->inputToInputWeights());
2718 recurrentToInputWeights =
ToConstTensor(flatBufferInputParams->recurrentToInputWeights());
2719 cellToInputWeights =
ToConstTensor(flatBufferInputParams->cellToInputWeights());
2720 inputGateBias =
ToConstTensor(flatBufferInputParams->inputGateBias());
2730 if (lstmDescriptor.m_ProjectionEnabled)
2732 projectionWeights =
ToConstTensor(flatBufferInputParams->projectionWeights());
2733 projectionBias =
ToConstTensor(flatBufferInputParams->projectionBias());
2741 if (lstmDescriptor.m_PeepholeEnabled)
2743 cellToForgetWeights =
ToConstTensor(flatBufferInputParams->cellToForgetWeights());
2744 cellToOutputWeights =
ToConstTensor(flatBufferInputParams->cellToOutputWeights());
2754 if (lstmDescriptor.m_LayerNormEnabled)
2756 if (!lstmDescriptor.m_CifgEnabled)
2758 inputLayerNormWeights =
ToConstTensor(flatBufferInputParams->inputLayerNormWeights());
2761 forgetLayerNormWeights =
ToConstTensor(flatBufferInputParams->forgetLayerNormWeights());
2762 cellLayerNormWeights =
ToConstTensor(flatBufferInputParams->cellLayerNormWeights());
2763 outputLayerNormWeights =
ToConstTensor(flatBufferInputParams->outputLayerNormWeights());
2770 IConnectableLayer* layer = m_Network->AddLstmLayer(lstmDescriptor, lstmInputParams, layerName.c_str());
2784 RegisterInputSlots(graph, layerIndex, layer);
2785 RegisterOutputSlots(graph, layerIndex, layer);
2797 desc.
m_CellClip = qLstmDescriptor->cellClip();
2811 void IDeserializer::DeserializerImpl::ParseQLstm(
GraphPtr graph,
unsigned int layerIndex)
2815 auto inputs =
GetInputs(graph, layerIndex);
2818 auto outputs =
GetOutputs(graph, layerIndex);
2821 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_QLstmLayer();
2823 auto flatBufferDescriptor = flatBufferLayer->descriptor();
2824 auto flatBufferInputParams = flatBufferLayer->inputParams();
2855 if (!qLstmDescriptor.m_CifgEnabled)
2857 inputToInputWeights =
ToConstTensor(flatBufferInputParams->inputToInputWeights());
2858 recurrentToInputWeights =
ToConstTensor(flatBufferInputParams->recurrentToInputWeights());
2859 inputGateBias =
ToConstTensor(flatBufferInputParams->inputGateBias());
2870 if (qLstmDescriptor.m_ProjectionEnabled)
2872 projectionWeights =
ToConstTensor(flatBufferInputParams->projectionWeights());
2873 projectionBias =
ToConstTensor(flatBufferInputParams->projectionBias());
2884 if (qLstmDescriptor.m_PeepholeEnabled)
2886 if (!qLstmDescriptor.m_CifgEnabled)
2888 cellToInputWeights =
ToConstTensor(flatBufferInputParams->cellToInputWeights());
2892 cellToForgetWeights =
ToConstTensor(flatBufferInputParams->cellToForgetWeights());
2893 cellToOutputWeights =
ToConstTensor(flatBufferInputParams->cellToOutputWeights());
2905 if (qLstmDescriptor.m_LayerNormEnabled)
2907 if (!qLstmDescriptor.m_CifgEnabled)
2909 inputLayerNormWeights =
ToConstTensor(flatBufferInputParams->inputLayerNormWeights());
2913 forgetLayerNormWeights =
ToConstTensor(flatBufferInputParams->forgetLayerNormWeights());
2914 cellLayerNormWeights =
ToConstTensor(flatBufferInputParams->cellLayerNormWeights());
2915 outputLayerNormWeights =
ToConstTensor(flatBufferInputParams->outputLayerNormWeights());
2922 IConnectableLayer* layer = m_Network->AddQLstmLayer(qLstmDescriptor, qLstmInputParams, layerName.c_str());
2933 RegisterInputSlots(graph, layerIndex, layer);
2934 RegisterOutputSlots(graph, layerIndex, layer);
2937 void IDeserializer::DeserializerImpl::ParseQuantizedLstm(
GraphPtr graph,
unsigned int layerIndex)
2941 auto inputs =
GetInputs(graph, layerIndex);
2944 auto outputs =
GetOutputs(graph, layerIndex);
2947 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_QuantizedLstmLayer();
2949 auto flatBufferInputParams = flatBufferLayer->inputParams();
2979 IConnectableLayer* layer = m_Network->AddQuantizedLstmLayer(lstmInputParams, layerName.c_str());
2987 RegisterInputSlots(graph, layerIndex, layer);
2988 RegisterOutputSlots(graph, layerIndex, layer);
2991 void IDeserializer::DeserializerImpl::ParseDequantize(
GraphPtr graph,
unsigned int layerIndex)
3001 const std::string layerName =
GetLayerName(graph, layerIndex);
3007 RegisterInputSlots(graph, layerIndex, layer);
3008 RegisterOutputSlots(graph, layerIndex, layer);
3011 void IDeserializer::DeserializerImpl::ParseMerge(
GraphPtr graph,
unsigned int layerIndex)
3021 const std::string layerName =
GetLayerName(graph, layerIndex);
3027 RegisterInputSlots(graph, layerIndex, layer);
3028 RegisterOutputSlots(graph, layerIndex, layer);
3031 void IDeserializer::DeserializerImpl::ParseSwitch(
GraphPtr graph,
unsigned int layerIndex)
3034 auto inputs =
GetInputs(graph, layerIndex);
3038 auto outputs =
GetOutputs(graph, layerIndex);
3050 RegisterInputSlots(graph, layerIndex, layer);
3051 RegisterOutputSlots(graph, layerIndex, layer);
3054 void IDeserializer::DeserializerImpl::ParsePrelu(
GraphPtr graph,
unsigned int layerIndex)
3057 auto inputs =
GetInputs(graph, layerIndex);
3061 auto outputs =
GetOutputs(graph, layerIndex);
3070 RegisterInputSlots(graph, layerIndex, layer);
3071 RegisterOutputSlots(graph, layerIndex, layer);
3074 void IDeserializer::DeserializerImpl::ParseTranspose(
GraphPtr graph,
unsigned int layerIndex)
3078 auto dimsMapping = graph->layers()->Get(layerIndex)->layer_as_TransposeLayer()->descriptor()->dimMappings();
3080 auto inputs =
GetInputs(graph, layerIndex);
3083 auto outputs =
GetOutputs(graph, layerIndex);
3090 IConnectableLayer* layer = m_Network->AddTransposeLayer(descriptor, layerName.c_str());
3093 RegisterInputSlots(graph, layerIndex, layer);
3094 RegisterOutputSlots(graph, layerIndex, layer);
3097 void IDeserializer::DeserializerImpl::ParseTransposeConvolution2d(
GraphPtr graph,
unsigned int layerIndex)
3101 auto inputs =
GetInputs(graph, layerIndex);
3104 auto outputs =
GetOutputs(graph, layerIndex);
3107 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_TransposeConvolution2dLayer();
3109 auto serializerDescriptor = serializerLayer->descriptor();
3112 descriptor.
m_PadLeft = serializerDescriptor->padLeft();
3113 descriptor.
m_PadRight = serializerDescriptor->padRight();
3114 descriptor.
m_PadTop = serializerDescriptor->padTop();
3115 descriptor.
m_PadBottom = serializerDescriptor->padBottom();
3116 descriptor.
m_StrideX = serializerDescriptor->strideX();
3117 descriptor.
m_StrideY = serializerDescriptor->strideY();;
3118 descriptor.
m_BiasEnabled = serializerDescriptor->biasEnabled();;
3127 optionalBiases = armnn::MakeOptional<armnn::ConstTensor>(biases);
3130 IConnectableLayer* layer = m_Network->AddTransposeConvolution2dLayer(descriptor,
3136 layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo);
3138 RegisterInputSlots(graph, layerIndex, layer);
3139 RegisterOutputSlots(graph, layerIndex, layer);
3142 void IDeserializer::DeserializerImpl::ParseStack(
GraphPtr graph,
unsigned int layerIndex)
3145 auto inputs =
GetInputs(graph, layerIndex);
3147 auto outputs =
GetOutputs(graph, layerIndex);
3150 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_StackLayer()->descriptor();
3151 unsigned int axis = flatBufferDescriptor->axis();
3152 unsigned int numInputs = flatBufferDescriptor->numInputs();
3155 auto flatBufferInputShape = flatBufferDescriptor->inputShape();
3156 std::vector<uint32_t> vectorInputShape(flatBufferInputShape->begin(),
3157 flatBufferInputShape->begin() + flatBufferInputShape->size());
3159 TensorShape inputShape(static_cast<unsigned int>(vectorInputShape.size()), vectorInputShape.data());
3162 for (
unsigned int i=0; i<inputs.size(); ++i)
3165 if (descriptor.m_InputShape != inputShape)
3167 std::stringstream ss;
3168 ss <<
"Shape of input " 3172 <<
" does not equal defined input shape " 3173 << descriptor.m_InputShape
3181 IConnectableLayer* layer = m_Network->AddStackLayer(descriptor, layerName.c_str());
3186 RegisterInputSlots(graph, layerIndex, layer);
3187 RegisterOutputSlots(graph, layerIndex, layer);
3190 void IDeserializer::DeserializerImpl::ParseStandIn(
GraphPtr graph,
unsigned int layerIndex)
3194 auto inputs =
GetInputs(graph, layerIndex);
3195 auto outputs =
GetOutputs(graph, layerIndex);
3197 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_StandInLayer();
3198 auto fbDescriptor = fbLayer->descriptor();
3201 descriptor.
m_NumInputs = fbDescriptor->numInputs();
3207 const std::string layerName =
GetLayerName(graph, layerIndex);
3210 for (
unsigned int i = 0u; i < descriptor.
m_NumOutputs; ++i)
3216 RegisterInputSlots(graph, layerIndex, layer);
3217 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
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)
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
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.
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.
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.
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_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_NumOutputs
Number of output tensors.
NormalizationAlgorithmMethod m_NormMethodType
Normalization method algorithm to use (LocalBrightness, LocalContrast).
void SetShape(const TensorShape &newShape)
A ResizeDescriptor for the ResizeLayer.
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
#define CHECK_CONST_TENSOR_SIZE(CONST_TENSOR_SIZE, TENSOR_SIZE)
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
armnn::INetworkPtr CreateNetworkFromBinary(const std::vector< uint8_t > &binaryContent)
Create an input network from binary file contents.
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
bool m_LayerNormEnabled
Enable/disable layer normalization.
const armnnSerializer::LstmDescriptor * LstmDescriptorPtr
armnn::DataLayout ToDataLayout(armnnSerializer::DataLayout dataLayout)
bool CheckShape(const armnn::TensorShape &actual, const std::vector< uint32_t > &expected)
float m_NmsIouThreshold
Intersection over union threshold.
static armnn::LstmDescriptor GetLstmDescriptor(LstmDescriptorPtr lstmDescriptor)
An LstmDescriptor for the LstmLayer.
uint32_t m_PadRight
Padding right value in the width dimension.
uint32_t m_DilationX
Dilation factor value for width dimension.
uint32_t m_PadTop
Padding top value in the height dimension.
std::string FileLine() const
Status SetViewSize(uint32_t view, uint32_t coord, uint32_t value)
Set the size of the views.
#define ARMNN_ASSERT_MSG(COND, MSG)
std::vector< unsigned int > m_Begin
Beginning indices of the slice in each dimension.
bool m_KeepDims
Enable/disable keep dimensions. If true, then the reduced dimensions that are of length 1 are kept...
std::vector< unsigned int > m_BlockShape
Block shape values.
float m_Eps
Epsilon, small scalar value added to variance to avoid dividing by zero. Defaults to 1e-12f...
An output connection slot for a layer.
A L2NormalizationDescriptor for the L2NormalizationLayer.
static TensorRawPtrVector GetInputs(const GraphPtr &graph, unsigned int layerIndex)
An ArgMinMaxDescriptor for ArgMinMaxLayer.
An OriginsDescriptor for the ConcatLayer.
A ReduceDescriptor for the REDUCE operators.
float m_ProjectionClip
Clipping threshold value for the projection.
A FullyConnectedDescriptor for the FullyConnectedLayer.
BindingPointInfo GetNetworkOutputBindingInfo(unsigned int layerId, const std::string &name) const
Retrieve binding info (layer id and tensor info) for the network output identified by the given layer...
bool m_BiasEnabled
Enable/disable bias.
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
float m_InputIntermediateScale
Input intermediate quantization scale.
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.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
std::vector< unsigned int > m_BlockShape
Block shape value.
An ActivationDescriptor for the ActivationLayer.
min(a, max(b, input)) ReLu1 & ReLu6.
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.
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)
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.
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 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)
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.
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.
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.
float m_CellIntermediateScale
Cell intermediate quantization scale.
float m_B
Beta lower bound value used by the activation functions. (BoundedReLu, Linear, TanH).
A SoftmaxDescriptor for the SoftmaxLayer.
float m_Beta
Beta value for the normalization equation.
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
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
A PermuteDescriptor for the PermuteLayer.
uint32_t m_PadRight
Padding right value in the width dimension.
int32_t m_HiddenStateZeroPoint
Hidden State zero point.
std::vector< float > anchors({ 0.5f, 0.5f, 1.0f, 1.0f, 0.5f, 0.5f, 1.0f, 1.0f, 0.5f, 0.5f, 1.0f, 1.0f, 0.5f, 10.5f, 1.0f, 1.0f, 0.5f, 10.5f, 1.0f, 1.0f, 0.5f, 100.5f, 1.0f, 1.0f })