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),
276 auto layerType = graphPtr->layers()->Get(layerIndex)->layer_type();
281 return graphPtr->layers()->Get(layerIndex)->layer_as_AbsLayer()->base();
283 return graphPtr->layers()->Get(layerIndex)->layer_as_ActivationLayer()->base();
285 return graphPtr->layers()->Get(layerIndex)->layer_as_AdditionLayer()->base();
287 return graphPtr->layers()->Get(layerIndex)->layer_as_ArgMinMaxLayer()->base();
289 return graphPtr->layers()->Get(layerIndex)->layer_as_BatchToSpaceNdLayer()->base();
291 return graphPtr->layers()->Get(layerIndex)->layer_as_BatchNormalizationLayer()->base();
293 return graphPtr->layers()->Get(layerIndex)->layer_as_CastLayer()->base();
295 return graphPtr->layers()->Get(layerIndex)->layer_as_ComparisonLayer()->base();
297 return graphPtr->layers()->Get(layerIndex)->layer_as_ConcatLayer()->base();
299 return graphPtr->layers()->Get(layerIndex)->layer_as_ConstantLayer()->base();
301 return graphPtr->layers()->Get(layerIndex)->layer_as_Convolution2dLayer()->base();
303 return graphPtr->layers()->Get(layerIndex)->layer_as_DepthToSpaceLayer()->base();
305 return graphPtr->layers()->Get(layerIndex)->layer_as_DepthwiseConvolution2dLayer()->base();
307 return graphPtr->layers()->Get(layerIndex)->layer_as_DequantizeLayer()->base();
309 return graphPtr->layers()->Get(layerIndex)->layer_as_DetectionPostProcessLayer()->base();
311 return graphPtr->layers()->Get(layerIndex)->layer_as_DivisionLayer()->base();
313 return graphPtr->layers()->Get(layerIndex)->layer_as_EqualLayer()->base();
315 return graphPtr->layers()->Get(layerIndex)->layer_as_ElementwiseUnaryLayer()->base();
317 return graphPtr->layers()->Get(layerIndex)->layer_as_FullyConnectedLayer()->base();
319 return graphPtr->layers()->Get(layerIndex)->layer_as_FillLayer()->base();
321 return graphPtr->layers()->Get(layerIndex)->layer_as_FloorLayer()->base();
323 return graphPtr->layers()->Get(layerIndex)->layer_as_GatherLayer()->base();
325 return graphPtr->layers()->Get(layerIndex)->layer_as_GreaterLayer()->base();
327 return graphPtr->layers()->Get(layerIndex)->layer_as_InputLayer()->base()->base();
329 return graphPtr->layers()->Get(layerIndex)->layer_as_InstanceNormalizationLayer()->base();
331 return graphPtr->layers()->Get(layerIndex)->layer_as_L2NormalizationLayer()->base();
333 return graphPtr->layers()->Get(layerIndex)->layer_as_LogicalBinaryLayer()->base();
335 return graphPtr->layers()->Get(layerIndex)->layer_as_LogSoftmaxLayer()->base();
337 return graphPtr->layers()->Get(layerIndex)->layer_as_LstmLayer()->base();
339 return graphPtr->layers()->Get(layerIndex)->layer_as_MeanLayer()->base();
341 return graphPtr->layers()->Get(layerIndex)->layer_as_MinimumLayer()->base();
343 return graphPtr->layers()->Get(layerIndex)->layer_as_MaximumLayer()->base();
345 return graphPtr->layers()->Get(layerIndex)->layer_as_MergeLayer()->base();
347 return graphPtr->layers()->Get(layerIndex)->layer_as_MergerLayer()->base();
349 return graphPtr->layers()->Get(layerIndex)->layer_as_MultiplicationLayer()->base();
351 return graphPtr->layers()->Get(layerIndex)->layer_as_NormalizationLayer()->base();
353 return graphPtr->layers()->Get(layerIndex)->layer_as_OutputLayer()->base()->base();
355 return graphPtr->layers()->Get(layerIndex)->layer_as_PadLayer()->base();
357 return graphPtr->layers()->Get(layerIndex)->layer_as_PermuteLayer()->base();
359 return graphPtr->layers()->Get(layerIndex)->layer_as_Pooling2dLayer()->base();
361 return graphPtr->layers()->Get(layerIndex)->layer_as_PreluLayer()->base();
363 return graphPtr->layers()->Get(layerIndex)->layer_as_QLstmLayer()->base();
365 return graphPtr->layers()->Get(layerIndex)->layer_as_QuantizeLayer()->base();
367 return graphPtr->layers()->Get(layerIndex)->layer_as_QuantizedLstmLayer()->base();
369 return graphPtr->layers()->Get(layerIndex)->layer_as_RankLayer()->base();
371 return graphPtr->layers()->Get(layerIndex)->layer_as_ReduceLayer()->base();
373 return graphPtr->layers()->Get(layerIndex)->layer_as_ReshapeLayer()->base();
375 return graphPtr->layers()->Get(layerIndex)->layer_as_ResizeBilinearLayer()->base();
377 return graphPtr->layers()->Get(layerIndex)->layer_as_ResizeLayer()->base();
379 return graphPtr->layers()->Get(layerIndex)->layer_as_RsqrtLayer()->base();
381 return graphPtr->layers()->Get(layerIndex)->layer_as_SliceLayer()->base();
383 return graphPtr->layers()->Get(layerIndex)->layer_as_SoftmaxLayer()->base();
385 return graphPtr->layers()->Get(layerIndex)->layer_as_SpaceToBatchNdLayer()->base();
387 return graphPtr->layers()->Get(layerIndex)->layer_as_SpaceToDepthLayer()->base();
389 return graphPtr->layers()->Get(layerIndex)->layer_as_SplitterLayer()->base();
391 return graphPtr->layers()->Get(layerIndex)->layer_as_StackLayer()->base();
393 return graphPtr->layers()->Get(layerIndex)->layer_as_StandInLayer()->base();
395 return graphPtr->layers()->Get(layerIndex)->layer_as_StridedSliceLayer()->base();
397 return graphPtr->layers()->Get(layerIndex)->layer_as_SubtractionLayer()->base();
399 return graphPtr->layers()->Get(layerIndex)->layer_as_SwitchLayer()->base();
401 return graphPtr->layers()->Get(layerIndex)->layer_as_TransposeConvolution2dLayer()->base();
403 return graphPtr->layers()->Get(layerIndex)->layer_as_TransposeLayer()->base();
406 throw ParseException(fmt::format(
"Layer type {} not recognized", layerType));
414 return layer->layerName()->str();
419 auto layerType = graphPtr->layers()->Get(layerIndex)->layer_type();
423 return graphPtr->layers()->Get(layerIndex)->layer_as_InputLayer()->base()->layerBindingId();
427 return graphPtr->layers()->Get(layerIndex)->layer_as_OutputLayer()->base()->layerBindingId();
576 switch (tensorPtr->dataType())
610 throw ParseException(fmt::format(
"Unsupported data type {0} = {1}. {2}",
611 tensorPtr->dataType(),
617 float quantizationScale = tensorPtr->quantizationScale();
618 int32_t quantizationOffset = tensorPtr->quantizationOffset();
620 if (tensorPtr->dimensionality() ==
static_cast<unsigned int>(Dimensionality::Scalar))
627 else if (tensorPtr->dimensionality() ==
static_cast<unsigned int>(Dimensionality::NotSpecified))
636 auto dimensions = tensorPtr->dimensions();
637 unsigned int size = dimensions->size();
638 std::vector<unsigned int> outputDims(dimensions->begin(), dimensions->begin() + size);
643 if (tensorPtr->dimensionSpecificity() !=
nullptr)
645 auto dimensionSpecificity = tensorPtr->dimensionSpecificity();
646 size = dimensionSpecificity->size();
647 for (
unsigned int i = 0; i < size; ++i)
649 dimensionsSpecificity[i] = dimensionSpecificity->Get(i);
653 TensorShape shape(size, outputDims.data(), dimensionsSpecificity);
655 auto quantizationScales = tensorPtr->quantizationScales();
656 if (quantizationScales)
658 unsigned int quantizationScalesSize = quantizationScales->size();
659 std::vector<float> scales(quantizationScales->begin(), quantizationScales->begin() + quantizationScalesSize);
660 unsigned int quantizationDim = tensorPtr->quantizationDim();
682 switch (constTensorPtr->data_type())
686 auto byteData = constTensorPtr->data_as_ByteData()->data();
692 auto shortData = constTensorPtr->data_as_ShortData()->data();
698 auto intData = constTensorPtr->data_as_IntData()->data();
704 auto longData = constTensorPtr->data_as_LongData()->data();
711 throw ParseException(fmt::format(
"Unsupported data type {0} = {1}. {2}",
712 constTensorPtr->data_type(),
723 const auto& numInputs = layer->inputSlots()->size();
727 for (
unsigned int i=0; i<numInputs; ++i)
730 (layer->inputSlots()->Get(i)->connection()->sourceLayerIndex()));
731 result[i] =
GetBaseLayer(graphPtr, inputId)->outputSlots()->Get(0)->tensorInfo();
740 const auto& numOutputs = layer->outputSlots()->size();
744 for (
unsigned int i=0; i<numOutputs; ++i)
746 result[i] = layer->outputSlots()->Get(i)->tensorInfo();
751 void IDeserializer::DeserializerImpl::ParseUnsupportedLayer(
GraphPtr graph,
unsigned int layerIndex)
754 const auto layerName =
GetBaseLayer(graph, layerIndex)->layerName()->c_str();
755 throw ParseException(fmt::format(
"Layer not supported. layerIndex: {0} " 756 "layerName: {1} / {2}",
762 void IDeserializer::DeserializerImpl::ResetParser()
765 m_InputBindings.clear();
766 m_OutputBindings.clear();
774 return CreateNetworkFromGraph(graph);
780 std::vector<uint8_t> content((std::istreambuf_iterator<char>(binaryContent)), std::istreambuf_iterator<char>());
782 return CreateNetworkFromGraph(graph);
787 if (binaryContent ==
nullptr)
792 flatbuffers::Verifier verifier(binaryContent, len);
793 if (verifier.VerifyBuffer<SerializedGraph>() ==
false)
795 throw ParseException(fmt::format(
"Buffer doesn't conform to the expected Armnn " 796 "flatbuffers format. size:{0} {1}",
805 m_Network = INetwork::Create();
807 unsigned int layerIndex = 0;
808 for (AnyLayer
const* layer : *graph->layers())
814 auto& parserFunction = m_ParserFunctions[layer->layer_type()];
815 (this->*parserFunction)(graph, layerIndex);
820 SetupInputLayers(graph);
821 SetupOutputLayers(graph);
824 for (
auto&& graphIt : m_GraphConnections)
826 Connections& connections = graphIt.second;
827 for (
auto&& outputIt : connections.outputSlots)
829 const unsigned int outputSlotIndex = outputIt.first;
831 if (connections.inputSlots.find(outputSlotIndex) != connections.inputSlots.end())
833 for (
IInputSlot* inputSlot : connections.inputSlots[outputSlotIndex])
835 outputSlot->
Connect(*inputSlot);
841 return std::move(m_Network);
845 const std::string& name)
const 848 for (
auto inputBinding : m_InputBindings)
850 if (inputBinding.first == name)
852 return inputBinding.second;
855 throw ParseException(fmt::format(
"No input binding found for layer:{0} / {1}",
861 const std::string& name)
const 864 for (
auto outputBinding : m_OutputBindings)
866 if (outputBinding.first == name)
868 return outputBinding.second;
871 throw ParseException(fmt::format(
"No output binding found for layer:{0} / {1}",
876 unsigned int IDeserializer::DeserializerImpl::GetInputLayerInVector(
GraphPtr graph,
int targetId)
878 for (
unsigned int i = 0; i < graph->layers()->size(); i++)
880 auto layer = graph->layers()->Get(i);
883 auto layerBindingId = layer->layer_as_InputLayer()->base()->layerBindingId();
884 if (layerBindingId == targetId)
890 throw ParseException(
"Input layer with given layerBindingId not found");
893 unsigned int IDeserializer::DeserializerImpl::GetOutputLayerInVector(
GraphPtr graph,
int targetId)
895 for (
unsigned int i = 0; i < graph->layers()->size(); i++)
897 auto layer = graph->layers()->Get(i);
900 auto layerBindingId = layer->layer_as_OutputLayer()->base()->layerBindingId();
901 if (layerBindingId == targetId)
907 throw ParseException(
"Output layer with given layerBindingId not found");
910 unsigned int IDeserializer::DeserializerImpl::GetLayerIndexInVector(
GraphPtr graph,
unsigned int targetIndex)
912 for (
unsigned int i = 0; i < graph->layers()->size(); i++)
915 if (layer->index() == targetIndex)
923 IDeserializer::DeserializerImpl::FeatureVersions IDeserializer::DeserializerImpl::GetFeatureVersions(
GraphPtr graph)
925 IDeserializer::DeserializerImpl::FeatureVersions versions;
927 if (graph->featureVersions())
929 versions.m_BindingIdScheme = graph->featureVersions()->bindingIdsScheme();
935 void IDeserializer::DeserializerImpl::SetupInputLayers(
GraphPtr graph)
938 const unsigned int numInputs = graph->inputIds()->size();
939 m_InputBindings.clear();
940 m_InputBindings.reserve(numInputs);
942 for (
unsigned int i = 0; i < numInputs; i++)
944 unsigned int inputLayerIndex = 0xFFFFFFFF;
945 if (GetFeatureVersions(graph).m_BindingIdScheme == 0)
948 inputLayerIndex = GetLayerIndexInVector(graph, inputId);
952 const int inputId = graph->inputIds()->Get(i);
953 inputLayerIndex = GetInputLayerInVector(graph, inputId);
963 m_Network->AddInputLayer(bindingId, baseLayer->layerName()->c_str());
966 inputLayer->GetOutputSlot(0).SetTensorInfo(tensorInfo);
967 RegisterOutputSlots(graph, inputLayerIndex, inputLayer);
970 m_InputBindings.push_back(std::make_pair(baseLayer->layerName()->c_str(), bindingInfo));
974 void IDeserializer::DeserializerImpl::SetupOutputLayers(
GraphPtr graph)
977 const unsigned int numOutputs = graph->outputIds()->size();
978 m_OutputBindings.clear();
979 m_OutputBindings.reserve(numOutputs);
981 for (
unsigned int i = 0; i < numOutputs; i++)
983 unsigned int outputLayerIndex = 0xFFFFFFFF;
984 if (GetFeatureVersions(graph).m_BindingIdScheme == 0)
986 const unsigned int outputId =
armnn::numeric_cast<
unsigned int>(graph->outputIds()->Get(i));
987 outputLayerIndex = GetLayerIndexInVector(graph, outputId);
991 const int outputId = graph->outputIds()->Get(i);
992 outputLayerIndex = GetOutputLayerInVector(graph, outputId);
1002 m_Network->AddOutputLayer(bindingId, baseLayer->layerName()->c_str());
1004 RegisterInputSlots(graph, outputLayerIndex, outputLayer);
1005 unsigned int sourceLayerIndex =
1006 GetLayerIndexInVector(graph, baseLayer->inputSlots()->Get(0)->connection()->sourceLayerIndex());
1007 unsigned int outputSlotIndex =
1008 GetLayerIndexInVector(graph, baseLayer->inputSlots()->Get(0)->connection()->outputSlotIndex());
1011 sourceBaseLayer->outputSlots()->Get(outputSlotIndex)->tensorInfo());
1013 m_OutputBindings.push_back(std::make_pair(baseLayer->layerName()->c_str(), bindingInfo));
1017 void IDeserializer::DeserializerImpl::RegisterOutputSlots(
GraphPtr graph,
1018 uint32_t layerIndex,
1026 throw ParseException(fmt::format(
"The number of outputslots ({0}) does not match the number expected ({1})" 1027 " for layer index: {2} {3}",
1028 baseLayer->outputSlots()->size(),
1036 const unsigned int slotIndex = baseLayer->outputSlots()->Get(i)->index();
1039 RegisterOutputSlotOfConnection(baseLayer->index(), slotIndex, outputSlot);
1043 void IDeserializer::DeserializerImpl::RegisterInputSlots(
GraphPtr graph,
1044 uint32_t layerIndex,
1052 throw ParseException(fmt::format(
"The number of inputslots ({0}) does not match the number expected ({1})" 1053 " for layer index:{2} {3}",
1054 baseLayer->inputSlots()->size(),
1062 auto fbInputSlot = baseLayer->inputSlots()->Get(i);
1063 auto fbConnection = fbInputSlot->connection();
1065 RegisterInputSlotOfConnection(fbConnection->sourceLayerIndex(), fbConnection->outputSlotIndex(), inputSlot);
1069 void IDeserializer::DeserializerImpl::RegisterInputSlotOfConnection(uint32_t sourceLayerIndex,
1070 uint32_t outputSlotIndex,
1073 if (m_GraphConnections.find(sourceLayerIndex) == m_GraphConnections.end())
1075 m_GraphConnections[sourceLayerIndex] = Connections();
1078 Connections& connections = m_GraphConnections[sourceLayerIndex];
1079 if (connections.inputSlots.find(outputSlotIndex) == connections.inputSlots.end())
1081 connections.inputSlots[outputSlotIndex] = {inputSlot};
1085 connections.inputSlots[outputSlotIndex].push_back(inputSlot);
1089 void IDeserializer::DeserializerImpl::RegisterOutputSlotOfConnection(uint32_t sourceLayerIndex,
1090 uint32_t outputSlotIndex,
1093 if (m_GraphConnections.find(sourceLayerIndex) == m_GraphConnections.end())
1095 m_GraphConnections[sourceLayerIndex] = Connections();
1098 Connections& connections = m_GraphConnections[sourceLayerIndex];
1099 if (connections.outputSlots.find(outputSlotIndex) != connections.outputSlots.end())
1104 connections.outputSlots[outputSlotIndex] = outputSlot;
1107 void IDeserializer::DeserializerImpl::ParseAbs(
GraphPtr graph,
unsigned int layerIndex)
1110 auto inputs =
GetInputs(graph, layerIndex);
1114 auto outputs =
GetOutputs(graph, layerIndex);
1120 IConnectableLayer* layer = m_Network->AddElementwiseUnaryLayer(descriptor, layerName.c_str());
1124 RegisterInputSlots(graph, layerIndex, layer);
1125 RegisterOutputSlots(graph, layerIndex, layer);
1128 void IDeserializer::DeserializerImpl::ParseActivation(
GraphPtr graph,
unsigned int layerIndex)
1131 auto inputs =
GetInputs(graph, layerIndex);
1135 auto outputs =
GetOutputs(graph, layerIndex);
1138 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_ActivationLayer();
1140 auto serializerDescriptor = serializerLayer->descriptor();
1144 descriptor.
m_A = serializerDescriptor->a();
1145 descriptor.
m_B = serializerDescriptor->b();
1152 RegisterInputSlots(graph, layerIndex, layer);
1153 RegisterOutputSlots(graph, layerIndex, layer);
1156 void IDeserializer::DeserializerImpl::ParseAdd(
GraphPtr graph,
unsigned int layerIndex)
1159 auto inputs =
GetInputs(graph, layerIndex);
1163 auto outputs =
GetOutputs(graph, layerIndex);
1172 RegisterInputSlots(graph, layerIndex, layer);
1173 RegisterOutputSlots(graph, layerIndex, layer);
1176 void IDeserializer::DeserializerImpl::ParseArgMinMax(
GraphPtr graph,
unsigned int layerIndex)
1179 auto inputs =
GetInputs(graph, layerIndex);
1183 auto outputs =
GetOutputs(graph, layerIndex);
1186 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_ArgMinMaxLayer();
1187 auto serializerDescriptor = serializerLayer->descriptor();
1191 descriptor.
m_Axis = serializerDescriptor->axis();
1193 IConnectableLayer* layer = m_Network->AddArgMinMaxLayer(descriptor, layerName.c_str());
1198 RegisterInputSlots(graph, layerIndex, layer);
1199 RegisterOutputSlots(graph, layerIndex, layer);
1202 void IDeserializer::DeserializerImpl::ParseBatchToSpaceNd(
GraphPtr graph,
unsigned int layerIndex)
1212 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_BatchToSpaceNdLayer()->descriptor();
1213 auto flatBufferCrops = flatBufferDescriptor->crops();
1214 auto flatBufferBlockShape = flatBufferDescriptor->blockShape();
1216 if (flatBufferCrops->Length() % 2 != 0)
1221 std::vector<std::pair<unsigned int, unsigned int>> crops;
1222 crops.reserve(flatBufferCrops->Length() / 2);
1223 for (
unsigned int i = 0; i < flatBufferCrops->Length() - 1; i += 2)
1225 crops.emplace_back(flatBufferCrops->Get(i), flatBufferCrops->Get(i+1));
1231 std::vector<unsigned int>(flatBufferBlockShape->begin(), flatBufferBlockShape->end());
1235 IConnectableLayer* layer = m_Network->AddBatchToSpaceNdLayer(descriptor, layerName.c_str());
1240 RegisterInputSlots(graph, layerIndex, layer);
1241 RegisterOutputSlots(graph, layerIndex, layer);
1244 void IDeserializer::DeserializerImpl::ParseBatchNormalization(
GraphPtr graph,
unsigned int layerIndex)
1248 auto inputs =
GetInputs(graph, layerIndex);
1251 auto outputs =
GetOutputs(graph, layerIndex);
1257 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_BatchNormalizationLayer();
1258 auto serializerDescriptor = serializerLayer->descriptor();
1261 descriptor.
m_Eps = serializerDescriptor->eps();
1275 layer->GetOutputSlot(0).SetTensorInfo(outputInfo);
1277 RegisterInputSlots(graph, layerIndex, layer);
1278 RegisterOutputSlots(graph, layerIndex, layer);
1281 void IDeserializer::DeserializerImpl::ParseCast(
GraphPtr graph,
unsigned int layerIndex)
1298 RegisterInputSlots(graph, layerIndex, layer);
1299 RegisterOutputSlots(graph, layerIndex, layer);
1302 void IDeserializer::DeserializerImpl::ParseConstant(
GraphPtr graph,
unsigned int layerIndex)
1307 auto outputs =
GetOutputs(graph, layerIndex);
1312 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_ConstantLayer();
1313 auto serializerInput = serializerLayer->input();
1317 IConnectableLayer* layer = m_Network->AddConstantLayer(input, layerName.c_str());
1322 RegisterOutputSlots(graph, layerIndex, layer);
1325 void IDeserializer::DeserializerImpl::ParseConvolution2d(
GraphPtr graph,
unsigned int layerIndex)
1328 auto inputs =
GetInputs(graph, layerIndex);
1332 auto outputs =
GetOutputs(graph, layerIndex);
1335 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_Convolution2dLayer();
1337 auto serializerDescriptor = serializerLayer->descriptor();
1340 descriptor.
m_PadLeft = serializerDescriptor->padLeft();
1341 descriptor.
m_PadRight = serializerDescriptor->padRight();
1342 descriptor.
m_PadTop = serializerDescriptor->padTop();
1343 descriptor.
m_PadBottom = serializerDescriptor->padBottom();
1344 descriptor.
m_StrideX = serializerDescriptor->strideX();
1345 descriptor.
m_StrideY = serializerDescriptor->strideY();;
1346 descriptor.
m_DilationX = serializerDescriptor->dilationX();
1347 descriptor.
m_DilationY = serializerDescriptor->dilationY();;
1348 descriptor.
m_BiasEnabled = serializerDescriptor->biasEnabled();;
1365 layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo);
1367 RegisterInputSlots(graph, layerIndex, layer);
1368 RegisterOutputSlots(graph, layerIndex, layer);
1371 void IDeserializer::DeserializerImpl::ParseDepthToSpace(
GraphPtr graph,
unsigned int layerIndex)
1375 auto inputs =
GetInputs(graph, layerIndex);
1378 auto outputs =
GetOutputs(graph, layerIndex);
1381 auto fbDescriptor = graph->layers()->Get(layerIndex)->layer_as_DepthToSpaceLayer()->descriptor();
1384 descriptor.
m_BlockSize = fbDescriptor->blockSize();
1388 IConnectableLayer* layer = m_Network->AddDepthToSpaceLayer(descriptor, layerName.c_str());
1393 RegisterInputSlots(graph, layerIndex, layer);
1394 RegisterOutputSlots(graph, layerIndex, layer);
1397 void IDeserializer::DeserializerImpl::ParseDepthwiseConvolution2d(
GraphPtr graph,
unsigned int layerIndex)
1400 auto inputs =
GetInputs(graph, layerIndex);
1404 auto outputs =
GetOutputs(graph, layerIndex);
1407 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_DepthwiseConvolution2dLayer();
1409 auto serializerDescriptor = serializerLayer->descriptor();
1412 descriptor.
m_PadLeft = serializerDescriptor->padLeft();
1413 descriptor.
m_PadRight = serializerDescriptor->padRight();
1414 descriptor.
m_PadTop = serializerDescriptor->padTop();
1415 descriptor.
m_PadBottom = serializerDescriptor->padBottom();
1416 descriptor.
m_StrideX = serializerDescriptor->strideX();
1417 descriptor.
m_StrideY = serializerDescriptor->strideY();
1418 descriptor.
m_DilationX = serializerDescriptor->dilationX();
1419 descriptor.
m_DilationY = serializerDescriptor->dilationY();
1420 descriptor.
m_BiasEnabled = serializerDescriptor->biasEnabled();;
1432 IConnectableLayer* layer = m_Network->AddDepthwiseConvolution2dLayer(descriptor,
1438 layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo);
1440 RegisterInputSlots(graph, layerIndex, layer);
1441 RegisterOutputSlots(graph, layerIndex, layer);
1444 void IDeserializer::DeserializerImpl::ParseDetectionPostProcess(
GraphPtr graph,
unsigned int layerIndex)
1447 auto inputs =
GetInputs(graph, layerIndex);
1451 auto outputs =
GetOutputs(graph, layerIndex);
1454 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_DetectionPostProcessLayer();
1456 auto flatBufferDescriptor = flatBufferLayer->descriptor();
1464 descriptor.
m_NumClasses = flatBufferDescriptor->numClasses();
1466 descriptor.
m_ScaleX = flatBufferDescriptor->scaleX();
1467 descriptor.
m_ScaleY = flatBufferDescriptor->scaleY();
1468 descriptor.
m_ScaleW = flatBufferDescriptor->scaleW();
1469 descriptor.
m_ScaleH = flatBufferDescriptor->scaleH();
1477 for (
unsigned int i = 0; i < 4; i++)
1479 layer->GetOutputSlot(i).SetTensorInfo(
ToTensorInfo(outputs[i]));
1482 RegisterInputSlots(graph, layerIndex, layer);
1483 RegisterOutputSlots(graph, layerIndex, layer);
1486 void IDeserializer::DeserializerImpl::ParseDivision(
GraphPtr graph,
unsigned int layerIndex)
1489 auto inputs =
GetInputs(graph, layerIndex);
1493 auto outputs =
GetOutputs(graph, layerIndex);
1502 RegisterInputSlots(graph, layerIndex, layer);
1503 RegisterOutputSlots(graph, layerIndex, layer);
1506 void IDeserializer::DeserializerImpl::ParseEqual(
GraphPtr graph,
unsigned int layerIndex)
1509 auto inputs =
GetInputs(graph, layerIndex);
1513 auto outputs =
GetOutputs(graph, layerIndex);
1518 IConnectableLayer* layer = m_Network->AddComparisonLayer(descriptor, layerName.c_str());
1523 RegisterInputSlots(graph, layerIndex, layer);
1524 RegisterOutputSlots(graph, layerIndex, layer);
1527 void IDeserializer::DeserializerImpl::ParseFill(
GraphPtr graph,
unsigned int layerIndex)
1530 auto inputs =
GetInputs(graph, layerIndex);
1534 auto outputs =
GetOutputs(graph, layerIndex);
1539 IConnectableLayer* layer = m_Network->AddFillLayer(descriptor, layerName.c_str());
1544 RegisterInputSlots(graph, layerIndex, layer);
1545 RegisterOutputSlots(graph, layerIndex, layer);
1548 void IDeserializer::DeserializerImpl::ParseGreater(
GraphPtr graph,
unsigned int layerIndex)
1551 auto inputs =
GetInputs(graph, layerIndex);
1555 auto outputs =
GetOutputs(graph, layerIndex);
1560 IConnectableLayer* layer = m_Network->AddComparisonLayer(descriptor, layerName.c_str());
1565 RegisterInputSlots(graph, layerIndex, layer);
1566 RegisterOutputSlots(graph, layerIndex, layer);
1569 void IDeserializer::DeserializerImpl::ParseInstanceNormalization(
GraphPtr graph,
unsigned int layerIndex)
1573 auto inputs =
GetInputs(graph, layerIndex);
1576 auto outputs =
GetOutputs(graph, layerIndex);
1579 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_InstanceNormalizationLayer();
1580 auto fbDescriptor = fbLayer->descriptor();
1583 descriptor.
m_Gamma = fbDescriptor->gamma();
1584 descriptor.
m_Beta = fbDescriptor->beta();
1585 descriptor.
m_Eps = fbDescriptor->eps();
1588 const std::string layerName =
GetLayerName(graph, layerIndex);
1591 IConnectableLayer* layer = m_Network->AddInstanceNormalizationLayer(descriptor, layerName.c_str());
1594 RegisterInputSlots(graph, layerIndex, layer);
1595 RegisterOutputSlots(graph, layerIndex, layer);
1598 void IDeserializer::DeserializerImpl::ParseL2Normalization(
GraphPtr graph,
unsigned int layerIndex)
1602 auto inputs =
GetInputs(graph, layerIndex);
1605 auto outputs =
GetOutputs(graph, layerIndex);
1609 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_L2NormalizationLayer();
1610 auto flatBufferDescriptor = flatBufferLayer->descriptor();
1615 descriptor.
m_Eps = flatBufferDescriptor->eps();
1617 IConnectableLayer* layer = m_Network->AddL2NormalizationLayer(descriptor, layerName.c_str());
1620 RegisterInputSlots(graph, layerIndex, layer);
1621 RegisterOutputSlots(graph, layerIndex, layer);
1624 void IDeserializer::DeserializerImpl::ParseLogicalBinary(
GraphPtr graph,
unsigned int layerIndex)
1629 auto inputs =
GetInputs(graph, layerIndex);
1632 auto outputs =
GetOutputs(graph, layerIndex);
1635 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_LogicalBinaryLayer();
1636 auto fbDescriptor = fbLayer->descriptor();
1641 const std::string& layerName =
GetLayerName(graph, layerIndex);
1642 IConnectableLayer* layer = m_Network->AddLogicalBinaryLayer(descriptor, layerName.c_str());
1647 RegisterInputSlots(graph, layerIndex, layer);
1648 RegisterOutputSlots(graph, layerIndex, layer);
1651 void IDeserializer::DeserializerImpl::ParseLogSoftmax(
GraphPtr graph,
unsigned int layerIndex)
1662 descriptor.
m_Beta = graph->layers()->Get(layerIndex)->layer_as_LogSoftmaxLayer()->descriptor()->beta();
1663 descriptor.m_Axis = graph->layers()->Get(layerIndex)->layer_as_LogSoftmaxLayer()->descriptor()->axis();
1666 IConnectableLayer* layer = m_Network->AddLogSoftmaxLayer(descriptor, layerName.c_str());
1671 RegisterInputSlots(graph, layerIndex, layer);
1672 RegisterOutputSlots(graph, layerIndex, layer);
1675 void IDeserializer::DeserializerImpl::ParseMinimum(
GraphPtr graph,
unsigned int layerIndex)
1678 auto inputs =
GetInputs(graph, layerIndex);
1682 auto outputs =
GetOutputs(graph, layerIndex);
1691 RegisterInputSlots(graph, layerIndex, layer);
1692 RegisterOutputSlots(graph, layerIndex, layer);
1695 void IDeserializer::DeserializerImpl::ParseMaximum(
GraphPtr graph,
unsigned int layerIndex)
1698 auto inputs =
GetInputs(graph, layerIndex);
1702 auto outputs =
GetOutputs(graph, layerIndex);
1711 RegisterInputSlots(graph, layerIndex, layer);
1712 RegisterOutputSlots(graph, layerIndex, layer);
1716 unsigned int layerIndex)
1718 auto layerType = graph->layers()->Get(layerIndex)->layer_type();
1723 return graph->layers()->Get(layerIndex)->layer_as_ConcatLayer()->descriptor();
1725 return graph->layers()->Get(layerIndex)->layer_as_MergerLayer()->descriptor();
1731 void IDeserializer::DeserializerImpl::ParseComparison(
GraphPtr graph,
unsigned int layerIndex)
1736 auto inputs =
GetInputs(graph, layerIndex);
1739 auto outputs =
GetOutputs(graph, layerIndex);
1742 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_ComparisonLayer();
1743 auto fbDescriptor = fbLayer->descriptor();
1748 const std::string& layerName =
GetLayerName(graph, layerIndex);
1749 IConnectableLayer* layer = m_Network->AddComparisonLayer(descriptor, layerName.c_str());
1754 RegisterInputSlots(graph, layerIndex, layer);
1755 RegisterOutputSlots(graph, layerIndex, layer);
1758 void IDeserializer::DeserializerImpl::ParseElementwiseUnary(
GraphPtr graph,
unsigned int layerIndex)
1763 auto inputs =
GetInputs(graph, layerIndex);
1766 auto outputs =
GetOutputs(graph, layerIndex);
1769 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_ElementwiseUnaryLayer();
1770 auto fbDescriptor = fbLayer->descriptor();
1775 const std::string& layerName =
GetLayerName(graph, layerIndex);
1776 IConnectableLayer* layer = m_Network->AddElementwiseUnaryLayer(descriptor, layerName.c_str());
1781 RegisterInputSlots(graph, layerIndex, layer);
1782 RegisterOutputSlots(graph, layerIndex, layer);
1785 void IDeserializer::DeserializerImpl::ParseConcat(
GraphPtr graph,
unsigned int layerIndex)
1790 auto outputs =
GetOutputs(graph, layerIndex);
1795 unsigned int numViews = originsDescriptor->numViews();
1796 unsigned int numDimensions = originsDescriptor->numDimensions();
1799 auto inputs =
GetInputs(graph, layerIndex);
1803 auto originsPtr = originsDescriptor->viewOrigins();
1804 for (
unsigned int v = 0; v < numViews; ++v)
1806 auto originPtr = originsPtr->Get(v);
1807 for (
unsigned int d = 0; d < numDimensions; ++d)
1809 uint32_t value = originPtr->data()->Get(d);
1810 descriptor.SetViewOriginCoord(v, d, value);
1813 descriptor.SetConcatAxis(originsDescriptor->concatAxis());
1815 IConnectableLayer* layer = m_Network->AddConcatLayer(descriptor, layerName.c_str());
1819 RegisterInputSlots(graph, layerIndex, layer);
1820 RegisterOutputSlots(graph, layerIndex, layer);
1823 void IDeserializer::DeserializerImpl::ParseMultiplication(
GraphPtr graph,
unsigned int layerIndex)
1826 auto inputs =
GetInputs(graph, layerIndex);
1830 auto outputs =
GetOutputs(graph, layerIndex);
1834 IConnectableLayer* layer = m_Network->AddMultiplicationLayer(layerName.c_str());
1839 RegisterInputSlots(graph, layerIndex, layer);
1840 RegisterOutputSlots(graph, layerIndex, layer);
1843 void IDeserializer::DeserializerImpl::ParseFloor(
GraphPtr graph,
unsigned int layerIndex)
1848 auto inputs =
GetInputs(graph, layerIndex);
1851 auto outputs =
GetOutputs(graph, layerIndex);
1858 layer = m_Network->AddFloorLayer(layerName.c_str());
1863 RegisterInputSlots(graph, layerIndex, layer);
1864 RegisterOutputSlots(graph, layerIndex, layer);
1867 void IDeserializer::DeserializerImpl::ParseFullyConnected(
GraphPtr graph,
unsigned int layerIndex)
1870 auto inputs =
GetInputs(graph, layerIndex);
1873 auto outputs =
GetOutputs(graph, layerIndex);
1876 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_FullyConnectedLayer();
1878 auto flatBufferDescriptor = flatBufferLayer->descriptor();
1881 fullyConnectedDescriptor.
m_BiasEnabled = flatBufferDescriptor->biasEnabled();
1883 fullyConnectedDescriptor.
m_ConstantWeights = flatBufferDescriptor->constantWeights();
1884 uint32_t numInputs = 1;
1902 if (flatBufferDescriptor->biasEnabled())
1915 layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo);
1917 RegisterInputSlots(graph, layerIndex, layer);
1918 RegisterOutputSlots(graph, layerIndex, layer);
1921 void IDeserializer::DeserializerImpl::ParsePad(
GraphPtr graph,
unsigned int layerIndex)
1931 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_PadLayer()->descriptor();
1932 auto flatBufferPadList = flatBufferDescriptor->padList();
1933 float padValue = flatBufferDescriptor->padValue();
1935 if (flatBufferPadList->Length() % 2 != 0)
1937 throw ParseException(fmt::format(
"The size of the pad list must be divisible by 2 {}",
1941 std::vector<std::pair<unsigned int, unsigned int>> padList;
1942 padList.reserve(flatBufferPadList->Length() / 2);
1943 for (
unsigned int i = 0; i < flatBufferPadList->Length() - 1; i += 2)
1945 padList.emplace_back(flatBufferPadList->Get(i), flatBufferPadList->Get(i+1));
1951 IConnectableLayer* layer = m_Network->AddPadLayer(descriptor, layerName.c_str());
1956 RegisterInputSlots(graph, layerIndex, layer);
1957 RegisterOutputSlots(graph, layerIndex, layer);
1960 void IDeserializer::DeserializerImpl::ParsePermute(
GraphPtr graph,
unsigned int layerIndex)
1965 graph->layers()->Get(layerIndex)->layer_as_PermuteLayer()->descriptor()->dimMappings();
1967 auto inputs =
GetInputs(graph, layerIndex);
1970 auto outputs =
GetOutputs(graph, layerIndex);
1977 IConnectableLayer* layer = m_Network->AddPermuteLayer(descriptor, layerName.c_str());
1980 RegisterInputSlots(graph, layerIndex, layer);
1981 RegisterOutputSlots(graph, layerIndex, layer);
1985 unsigned int layerIndex)
1990 switch (pooling2dDesc->poolType())
2013 switch (pooling2dDesc->outputShapeRounding())
2031 switch (pooling2dDesc->paddingMethod())
2049 switch (pooling2dDesc->dataLayout())
2068 desc.
m_PadLeft = pooling2dDesc->padLeft();
2070 desc.
m_PadTop = pooling2dDesc->padTop();
2071 desc.
m_StrideX = pooling2dDesc->strideX();
2072 desc.
m_StrideY = pooling2dDesc->strideY();
2081 void IDeserializer::DeserializerImpl::ParsePooling2d(
GraphPtr graph,
unsigned int layerIndex)
2085 auto pooling2dDes = graph->layers()->Get(layerIndex)->layer_as_Pooling2dLayer()->descriptor();
2086 auto inputs =
GetInputs(graph, layerIndex);
2089 auto outputs =
GetOutputs(graph, layerIndex);
2095 IConnectableLayer* layer = m_Network->AddPooling2dLayer(pooling2dDescriptor, layerName.c_str());
2098 RegisterInputSlots(graph, layerIndex, layer);
2099 RegisterOutputSlots(graph, layerIndex, layer);
2102 void IDeserializer::DeserializerImpl::ParseQuantize(
GraphPtr graph,
unsigned int layerIndex)
2106 auto inputs =
GetInputs(graph, layerIndex);
2109 auto outputs =
GetOutputs(graph, layerIndex);
2117 RegisterInputSlots(graph, layerIndex, layer);
2118 RegisterOutputSlots(graph, layerIndex, layer);
2122 const std::vector<uint32_t>& targetDimsIn)
2124 std::vector<unsigned int> outputDims(targetDimsIn.begin(), targetDimsIn.end());
2125 const auto stretchDim = std::find(targetDimsIn.begin(), targetDimsIn.end(), -1);
2127 if (stretchDim != targetDimsIn.end())
2129 if (std::find(std::next(stretchDim), targetDimsIn.end(), -1) != targetDimsIn.end())
2131 throw ParseException(fmt::format(
"At most one component of shape can be -1 {}",
2135 auto targetNumElements =
2137 std::accumulate(targetDimsIn.begin(), targetDimsIn.end(), -1, std::multiplies<int32_t>()));
2139 auto stretchIndex =
static_cast<size_t>(std::distance(targetDimsIn.begin(), stretchDim));
2140 outputDims[stretchIndex] = inputTensorInfo.
GetNumElements() / targetNumElements;
2151 void IDeserializer::DeserializerImpl::ParseRank(
GraphPtr graph,
unsigned int layerIndex)
2167 RegisterInputSlots(graph, layerIndex, layer);
2168 RegisterOutputSlots(graph, layerIndex, layer);
2171 void IDeserializer::DeserializerImpl::ParseReduce(
GraphPtr graph,
unsigned int layerIndex)
2176 auto inputs =
GetInputs(graph, layerIndex);
2179 auto outputs =
GetOutputs(graph, layerIndex);
2182 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_ReduceLayer();
2183 auto fbDescriptor = fbLayer->descriptor();
2184 auto flatBufferAxis = fbDescriptor->axis();
2187 descriptor.
m_KeepDims = fbDescriptor->keepDims();
2188 descriptor.
m_vAxis = std::vector<unsigned int>(flatBufferAxis->begin(), flatBufferAxis->end());
2191 const std::string& layerName =
GetLayerName(graph, layerIndex);
2192 IConnectableLayer* layer = m_Network->AddReduceLayer(descriptor, layerName.c_str());
2197 RegisterInputSlots(graph, layerIndex, layer);
2198 RegisterOutputSlots(graph, layerIndex, layer);
2201 void IDeserializer::DeserializerImpl::ParseReshape(
GraphPtr graph,
unsigned int layerIndex)
2204 auto inputs =
GetInputs(graph, layerIndex);
2206 auto outputs =
GetOutputs(graph, layerIndex);
2212 const auto targetDims = graph->layers()->Get(layerIndex)->layer_as_ReshapeLayer()->descriptor()->targetShape();
2213 std::vector<uint32_t> outputDims(targetDims->begin(), targetDims->begin() + targetDims->size());
2216 const armnn::TensorShape& reshapeOutputTensorShape = reshapeOutputTensorInfo.GetShape();
2218 const std::vector<uint32_t> expectedDims(outputs[0]->dimensions()->begin(),
2219 outputs[0]->dimensions()->begin() + outputs[0]->dimensions()->size());
2221 if (inputs.size() > 1 && !
CheckShape(reshapeOutputTensorShape, expectedDims))
2223 std::stringstream ss;
2224 ss <<
"New shape defined in reshape parameters " 2225 << reshapeOutputTensorShape
2226 <<
" does not equal output shape " 2227 << actualOutputTensorInfo.
GetShape()
2237 IConnectableLayer* layer = m_Network->AddReshapeLayer(reshapeDesc, layerName.c_str());
2240 RegisterInputSlots(graph, layerIndex, layer);
2241 RegisterOutputSlots(graph, layerIndex, layer);
2244 void IDeserializer::DeserializerImpl::ParseResize(
GraphPtr graph,
unsigned int layerIndex)
2254 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_ResizeLayer()->descriptor();
2257 descriptor.
m_TargetWidth = flatBufferDescriptor->targetWidth();
2258 descriptor.
m_TargetHeight = flatBufferDescriptor->targetHeight();
2261 descriptor.
m_AlignCorners = flatBufferDescriptor->alignCorners();
2265 IConnectableLayer* layer = m_Network->AddResizeLayer(descriptor, layerName.c_str());
2270 RegisterInputSlots(graph, layerIndex, layer);
2271 RegisterOutputSlots(graph, layerIndex, layer);
2274 void IDeserializer::DeserializerImpl::ParseResizeBilinear(
GraphPtr graph,
unsigned int layerIndex)
2284 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_ResizeBilinearLayer()->descriptor();
2287 descriptor.
m_TargetWidth = flatBufferDescriptor->targetWidth();
2288 descriptor.
m_TargetHeight = flatBufferDescriptor->targetHeight();
2291 descriptor.
m_AlignCorners = flatBufferDescriptor->alignCorners();
2295 IConnectableLayer* layer = m_Network->AddResizeLayer(descriptor, layerName.c_str());
2300 RegisterInputSlots(graph, layerIndex, layer);
2301 RegisterOutputSlots(graph, layerIndex, layer);
2304 void IDeserializer::DeserializerImpl::ParseSoftmax(
GraphPtr graph,
unsigned int layerIndex)
2315 descriptor.
m_Beta = graph->layers()->Get(layerIndex)->layer_as_SoftmaxLayer()->descriptor()->beta();
2318 IConnectableLayer* layer = m_Network->AddSoftmaxLayer(descriptor, layerName.c_str());
2323 RegisterInputSlots(graph, layerIndex, layer);
2324 RegisterOutputSlots(graph, layerIndex, layer);
2327 void IDeserializer::DeserializerImpl::ParseSpaceToBatchNd(
GraphPtr graph,
unsigned int layerIndex)
2337 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_SpaceToBatchNdLayer()->descriptor();
2338 auto flatBufferPadList = flatBufferDescriptor->padList();
2339 auto flatBufferBlockShape = flatBufferDescriptor->blockShape();
2341 if (flatBufferPadList->Length() % 2 != 0)
2343 throw ParseException(fmt::format(
"The size of the pad list must be divisible by 2 {}",
2347 std::vector<std::pair<unsigned int, unsigned int>> padList;
2348 padList.reserve(flatBufferPadList->Length() / 2);
2349 for (
unsigned int i = 0; i < flatBufferPadList->Length() - 1; i += 2)
2351 padList.emplace_back(flatBufferPadList->Get(i), flatBufferPadList->Get(i+1));
2357 std::vector<unsigned int>(flatBufferBlockShape->begin(), flatBufferBlockShape->end());
2361 IConnectableLayer* layer = m_Network->AddSpaceToBatchNdLayer(descriptor, layerName.c_str());
2366 RegisterInputSlots(graph, layerIndex, layer);
2367 RegisterOutputSlots(graph, layerIndex, layer);
2370 void IDeserializer::DeserializerImpl::ParseSpaceToDepth(
GraphPtr graph,
unsigned int layerIndex)
2380 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_SpaceToDepthLayer()->descriptor();
2383 descriptor.
m_BlockSize = flatBufferDescriptor->blockSize();
2387 IConnectableLayer* layer = m_Network->AddSpaceToDepthLayer(descriptor, layerName.c_str());
2392 RegisterInputSlots(graph, layerIndex, layer);
2393 RegisterOutputSlots(graph, layerIndex, layer);
2398 unsigned int layerIndex)
2403 switch (normalizationDescriptor->normChannelType())
2421 switch (normalizationDescriptor->normMethodType())
2439 switch (normalizationDescriptor->dataLayout())
2457 desc.
m_Alpha = normalizationDescriptor->alpha();
2458 desc.
m_Beta = normalizationDescriptor->beta();
2459 desc.
m_K = normalizationDescriptor->k();
2460 desc.
m_NormSize = normalizationDescriptor->normSize();
2465 void IDeserializer::DeserializerImpl::ParseNormalization(
GraphPtr graph,
unsigned int layerIndex)
2469 auto normalizationDes = graph->layers()->Get(layerIndex)->layer_as_NormalizationLayer()->descriptor();
2482 IConnectableLayer* layer = m_Network->AddNormalizationLayer(normalizationDescriptor, layerName.c_str());
2485 RegisterInputSlots(graph, layerIndex, layer);
2486 RegisterOutputSlots(graph, layerIndex, layer);
2489 void IDeserializer::DeserializerImpl::ParseRsqrt(
GraphPtr graph,
unsigned int layerIndex)
2492 auto inputs =
GetInputs(graph, layerIndex);
2496 auto outputs =
GetOutputs(graph, layerIndex);
2502 IConnectableLayer* layer = m_Network->AddElementwiseUnaryLayer(descriptor, layerName.c_str());
2506 RegisterInputSlots(graph, layerIndex, layer);
2507 RegisterOutputSlots(graph, layerIndex, layer);
2510 void IDeserializer::DeserializerImpl::ParseSlice(
GraphPtr graph,
unsigned int layerIndex)
2514 auto inputs =
GetInputs(graph, layerIndex);
2517 auto outputs =
GetOutputs(graph, layerIndex);
2520 auto fbDescriptor = graph->layers()->Get(layerIndex)->layer_as_SliceLayer()->descriptor();
2522 auto fbBegin = fbDescriptor->begin();
2523 auto fbSize = fbDescriptor->size();
2525 if (fbBegin->Length() != fbSize->Length())
2527 throw ParseException(fmt::format(
"Begin and size descriptors must have the same length {}",
2532 descriptor.
m_Begin.insert(descriptor.
m_Begin.end(), fbBegin->begin(), fbBegin->end());
2533 descriptor.
m_Size.insert(descriptor.
m_Size.end(), fbSize->begin(), fbSize->end());
2536 IConnectableLayer* layer = m_Network->AddSliceLayer(descriptor, layerName.c_str());
2541 RegisterInputSlots(graph, layerIndex, layer);
2542 RegisterOutputSlots(graph, layerIndex, layer);
2545 void IDeserializer::DeserializerImpl::ParseStridedSlice(
GraphPtr graph,
unsigned int layerIndex)
2555 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_StridedSliceLayer()->descriptor();
2557 auto flatBufferBegin = flatBufferDescriptor->begin();
2558 auto flatBufferEnd = flatBufferDescriptor->end();
2559 auto flatBufferStride = flatBufferDescriptor->stride();
2561 if (!(flatBufferBegin->Length() == flatBufferEnd->Length() &&
2562 flatBufferBegin->Length() == flatBufferStride->Length()))
2564 throw ParseException(fmt::format(
"The size of the begin, end, and stride must be equal {}",
2568 std::vector<int> begin(flatBufferBegin->begin(), flatBufferBegin->end());
2569 std::vector<int> end(flatBufferEnd->begin(), flatBufferEnd->end());
2570 std::vector<int> stride(flatBufferStride->begin(), flatBufferStride->end());
2573 descriptor.m_BeginMask = flatBufferDescriptor->beginMask();
2574 descriptor.m_EndMask = flatBufferDescriptor->endMask();
2575 descriptor.m_ShrinkAxisMask = flatBufferDescriptor->shrinkAxisMask();
2576 descriptor.m_EllipsisMask = flatBufferDescriptor->ellipsisMask();
2577 descriptor.m_NewAxisMask = flatBufferDescriptor->newAxisMask();
2578 descriptor.m_DataLayout =
ToDataLayout(flatBufferDescriptor->dataLayout());
2581 IConnectableLayer* layer = m_Network->AddStridedSliceLayer(descriptor, layerName.c_str());
2586 RegisterInputSlots(graph, layerIndex, layer);
2587 RegisterOutputSlots(graph, layerIndex, layer);
2590 void IDeserializer::DeserializerImpl::ParseSubtraction(
GraphPtr graph,
unsigned int layerIndex)
2593 auto inputs =
GetInputs(graph, layerIndex);
2597 auto outputs =
GetOutputs(graph, layerIndex);
2606 RegisterInputSlots(graph, layerIndex, layer);
2607 RegisterOutputSlots(graph, layerIndex, layer);
2610 void IDeserializer::DeserializerImpl::ParseGather(
GraphPtr graph,
unsigned int layerIndex)
2621 descriptor.
m_Axis = graph->layers()->Get(layerIndex)->layer_as_GatherLayer()->descriptor()->axis();
2624 IConnectableLayer* layer = m_Network->AddGatherLayer(descriptor, layerName.c_str());
2629 RegisterInputSlots(graph, layerIndex, layer);
2630 RegisterOutputSlots(graph, layerIndex, layer);
2633 void IDeserializer::DeserializerImpl::ParseMean(
GraphPtr graph,
unsigned int layerIndex)
2643 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_MeanLayer()->descriptor();
2644 auto flatBufferAxis = flatBufferDescriptor->axis();
2645 auto flatBufferKeepDims = flatBufferDescriptor->keepDims();
2648 descriptor.
m_Axis = std::vector<unsigned int>(flatBufferAxis->begin(), flatBufferAxis->end());
2652 IConnectableLayer* layer = m_Network->AddMeanLayer(descriptor, layerName.c_str());
2657 RegisterInputSlots(graph, layerIndex, layer);
2658 RegisterOutputSlots(graph, layerIndex, layer);
2661 void IDeserializer::DeserializerImpl::ParseSplitter(
GraphPtr graph,
unsigned int layerIndex)
2670 auto flatBufferViewsDescriptor = graph->layers()->Get(layerIndex)->layer_as_SplitterLayer()->descriptor();
2671 auto flatBufferViewSizes = flatBufferViewsDescriptor->viewSizes();
2672 auto flatBufferOriginsDescriptor = flatBufferViewsDescriptor->origins();
2673 auto flatBufferViewOrigins = flatBufferOriginsDescriptor->viewOrigins();
2674 uint32_t numViews = flatBufferOriginsDescriptor->numViews();
2675 uint32_t numDimensions = flatBufferOriginsDescriptor->numDimensions();
2682 for(
unsigned int vIdx = 0; vIdx < numViews; ++vIdx)
2684 for (
unsigned int dIdx = 0; dIdx < numDimensions; ++dIdx)
2686 viewsDescriptor.
SetViewSize(vIdx, dIdx, flatBufferViewSizes->Get(vIdx)->data()->Get(dIdx));
2687 viewsDescriptor.
SetViewOriginCoord(vIdx, dIdx, flatBufferViewOrigins->Get(vIdx)->data()->Get(dIdx));
2692 IConnectableLayer* layer = m_Network->AddSplitterLayer(viewsDescriptor, layerName.c_str());
2695 for(
unsigned int vIdx = 0; vIdx < numViews; ++vIdx)
2701 RegisterInputSlots(graph, layerIndex, layer);
2702 RegisterOutputSlots(graph, layerIndex, layer);
2720 void IDeserializer::DeserializerImpl::ParseLstm(
GraphPtr graph,
unsigned int layerIndex)
2724 auto inputs =
GetInputs(graph, layerIndex);
2727 auto outputs =
GetOutputs(graph, layerIndex);
2730 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_LstmLayer();
2732 auto flatBufferDescriptor = flatBufferLayer->descriptor();
2733 auto flatBufferInputParams = flatBufferLayer->inputParams();
2763 if (!lstmDescriptor.m_CifgEnabled)
2765 inputToInputWeights =
ToConstTensor(flatBufferInputParams->inputToInputWeights());
2766 recurrentToInputWeights =
ToConstTensor(flatBufferInputParams->recurrentToInputWeights());
2767 cellToInputWeights =
ToConstTensor(flatBufferInputParams->cellToInputWeights());
2768 inputGateBias =
ToConstTensor(flatBufferInputParams->inputGateBias());
2778 if (lstmDescriptor.m_ProjectionEnabled)
2780 projectionWeights =
ToConstTensor(flatBufferInputParams->projectionWeights());
2781 projectionBias =
ToConstTensor(flatBufferInputParams->projectionBias());
2789 if (lstmDescriptor.m_PeepholeEnabled)
2791 cellToForgetWeights =
ToConstTensor(flatBufferInputParams->cellToForgetWeights());
2792 cellToOutputWeights =
ToConstTensor(flatBufferInputParams->cellToOutputWeights());
2802 if (lstmDescriptor.m_LayerNormEnabled)
2804 if (!lstmDescriptor.m_CifgEnabled)
2806 inputLayerNormWeights =
ToConstTensor(flatBufferInputParams->inputLayerNormWeights());
2809 forgetLayerNormWeights =
ToConstTensor(flatBufferInputParams->forgetLayerNormWeights());
2810 cellLayerNormWeights =
ToConstTensor(flatBufferInputParams->cellLayerNormWeights());
2811 outputLayerNormWeights =
ToConstTensor(flatBufferInputParams->outputLayerNormWeights());
2818 IConnectableLayer* layer = m_Network->AddLstmLayer(lstmDescriptor, lstmInputParams, layerName.c_str());
2832 RegisterInputSlots(graph, layerIndex, layer);
2833 RegisterOutputSlots(graph, layerIndex, layer);
2845 desc.
m_CellClip = qLstmDescriptor->cellClip();
2859 void IDeserializer::DeserializerImpl::ParseQLstm(
GraphPtr graph,
unsigned int layerIndex)
2863 auto inputs =
GetInputs(graph, layerIndex);
2866 auto outputs =
GetOutputs(graph, layerIndex);
2869 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_QLstmLayer();
2871 auto flatBufferDescriptor = flatBufferLayer->descriptor();
2872 auto flatBufferInputParams = flatBufferLayer->inputParams();
2903 if (!qLstmDescriptor.m_CifgEnabled)
2905 inputToInputWeights =
ToConstTensor(flatBufferInputParams->inputToInputWeights());
2906 recurrentToInputWeights =
ToConstTensor(flatBufferInputParams->recurrentToInputWeights());
2907 inputGateBias =
ToConstTensor(flatBufferInputParams->inputGateBias());
2918 if (qLstmDescriptor.m_ProjectionEnabled)
2920 projectionWeights =
ToConstTensor(flatBufferInputParams->projectionWeights());
2921 projectionBias =
ToConstTensor(flatBufferInputParams->projectionBias());
2932 if (qLstmDescriptor.m_PeepholeEnabled)
2934 if (!qLstmDescriptor.m_CifgEnabled)
2936 cellToInputWeights =
ToConstTensor(flatBufferInputParams->cellToInputWeights());
2940 cellToForgetWeights =
ToConstTensor(flatBufferInputParams->cellToForgetWeights());
2941 cellToOutputWeights =
ToConstTensor(flatBufferInputParams->cellToOutputWeights());
2953 if (qLstmDescriptor.m_LayerNormEnabled)
2955 if (!qLstmDescriptor.m_CifgEnabled)
2957 inputLayerNormWeights =
ToConstTensor(flatBufferInputParams->inputLayerNormWeights());
2961 forgetLayerNormWeights =
ToConstTensor(flatBufferInputParams->forgetLayerNormWeights());
2962 cellLayerNormWeights =
ToConstTensor(flatBufferInputParams->cellLayerNormWeights());
2963 outputLayerNormWeights =
ToConstTensor(flatBufferInputParams->outputLayerNormWeights());
2970 IConnectableLayer* layer = m_Network->AddQLstmLayer(qLstmDescriptor, qLstmInputParams, layerName.c_str());
2981 RegisterInputSlots(graph, layerIndex, layer);
2982 RegisterOutputSlots(graph, layerIndex, layer);
2985 void IDeserializer::DeserializerImpl::ParseQuantizedLstm(
GraphPtr graph,
unsigned int layerIndex)
2989 auto inputs =
GetInputs(graph, layerIndex);
2992 auto outputs =
GetOutputs(graph, layerIndex);
2995 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_QuantizedLstmLayer();
2997 auto flatBufferInputParams = flatBufferLayer->inputParams();
3027 IConnectableLayer* layer = m_Network->AddQuantizedLstmLayer(lstmInputParams, layerName.c_str());
3035 RegisterInputSlots(graph, layerIndex, layer);
3036 RegisterOutputSlots(graph, layerIndex, layer);
3039 void IDeserializer::DeserializerImpl::ParseDequantize(
GraphPtr graph,
unsigned int layerIndex)
3049 const std::string layerName =
GetLayerName(graph, layerIndex);
3055 RegisterInputSlots(graph, layerIndex, layer);
3056 RegisterOutputSlots(graph, layerIndex, layer);
3059 void IDeserializer::DeserializerImpl::ParseMerge(
GraphPtr graph,
unsigned int layerIndex)
3069 const std::string layerName =
GetLayerName(graph, layerIndex);
3075 RegisterInputSlots(graph, layerIndex, layer);
3076 RegisterOutputSlots(graph, layerIndex, layer);
3079 void IDeserializer::DeserializerImpl::ParseSwitch(
GraphPtr graph,
unsigned int layerIndex)
3082 auto inputs =
GetInputs(graph, layerIndex);
3086 auto outputs =
GetOutputs(graph, layerIndex);
3098 RegisterInputSlots(graph, layerIndex, layer);
3099 RegisterOutputSlots(graph, layerIndex, layer);
3102 void IDeserializer::DeserializerImpl::ParsePrelu(
GraphPtr graph,
unsigned int layerIndex)
3105 auto inputs =
GetInputs(graph, layerIndex);
3109 auto outputs =
GetOutputs(graph, layerIndex);
3118 RegisterInputSlots(graph, layerIndex, layer);
3119 RegisterOutputSlots(graph, layerIndex, layer);
3122 void IDeserializer::DeserializerImpl::ParseTranspose(
GraphPtr graph,
unsigned int layerIndex)
3126 auto dimsMapping = graph->layers()->Get(layerIndex)->layer_as_TransposeLayer()->descriptor()->dimMappings();
3128 auto inputs =
GetInputs(graph, layerIndex);
3131 auto outputs =
GetOutputs(graph, layerIndex);
3138 IConnectableLayer* layer = m_Network->AddTransposeLayer(descriptor, layerName.c_str());
3141 RegisterInputSlots(graph, layerIndex, layer);
3142 RegisterOutputSlots(graph, layerIndex, layer);
3145 void IDeserializer::DeserializerImpl::ParseTransposeConvolution2d(
GraphPtr graph,
unsigned int layerIndex)
3149 auto inputs =
GetInputs(graph, layerIndex);
3152 auto outputs =
GetOutputs(graph, layerIndex);
3155 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_TransposeConvolution2dLayer();
3157 auto serializerDescriptor = serializerLayer->descriptor();
3160 descriptor.
m_PadLeft = serializerDescriptor->padLeft();
3161 descriptor.
m_PadRight = serializerDescriptor->padRight();
3162 descriptor.
m_PadTop = serializerDescriptor->padTop();
3163 descriptor.
m_PadBottom = serializerDescriptor->padBottom();
3164 descriptor.
m_StrideX = serializerDescriptor->strideX();
3165 descriptor.
m_StrideY = serializerDescriptor->strideY();;
3166 descriptor.
m_BiasEnabled = serializerDescriptor->biasEnabled();;
3175 optionalBiases = armnn::MakeOptional<armnn::ConstTensor>(biases);
3178 IConnectableLayer* layer = m_Network->AddTransposeConvolution2dLayer(descriptor,
3184 layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo);
3186 RegisterInputSlots(graph, layerIndex, layer);
3187 RegisterOutputSlots(graph, layerIndex, layer);
3190 void IDeserializer::DeserializerImpl::ParseStack(
GraphPtr graph,
unsigned int layerIndex)
3193 auto inputs =
GetInputs(graph, layerIndex);
3195 auto outputs =
GetOutputs(graph, layerIndex);
3198 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_StackLayer()->descriptor();
3199 unsigned int axis = flatBufferDescriptor->axis();
3200 unsigned int numInputs = flatBufferDescriptor->numInputs();
3203 auto flatBufferInputShape = flatBufferDescriptor->inputShape();
3204 std::vector<uint32_t> vectorInputShape(flatBufferInputShape->begin(),
3205 flatBufferInputShape->begin() + flatBufferInputShape->size());
3207 TensorShape inputShape(static_cast<unsigned int>(vectorInputShape.size()), vectorInputShape.data());
3210 for (
unsigned int i=0; i<inputs.size(); ++i)
3213 if (descriptor.m_InputShape != inputShape)
3215 std::stringstream ss;
3216 ss <<
"Shape of input " 3220 <<
" does not equal defined input shape " 3221 << descriptor.m_InputShape
3229 IConnectableLayer* layer = m_Network->AddStackLayer(descriptor, layerName.c_str());
3234 RegisterInputSlots(graph, layerIndex, layer);
3235 RegisterOutputSlots(graph, layerIndex, layer);
3238 void IDeserializer::DeserializerImpl::ParseStandIn(
GraphPtr graph,
unsigned int layerIndex)
3242 auto inputs =
GetInputs(graph, layerIndex);
3243 auto outputs =
GetOutputs(graph, layerIndex);
3245 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_StandInLayer();
3246 auto fbDescriptor = fbLayer->descriptor();
3249 descriptor.
m_NumInputs = fbDescriptor->numInputs();
3255 const std::string layerName =
GetLayerName(graph, layerIndex);
3258 for (
unsigned int i = 0u; i < descriptor.
m_NumOutputs; ++i)
3264 RegisterInputSlots(graph, layerIndex, layer);
3265 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.
bool m_ConstantWeights
Enable/disable constant weights and biases.
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 })