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),
278 auto layerType = graphPtr->layers()->Get(layerIndex)->layer_type();
283 return graphPtr->layers()->Get(layerIndex)->layer_as_AbsLayer()->base();
285 return graphPtr->layers()->Get(layerIndex)->layer_as_ActivationLayer()->base();
287 return graphPtr->layers()->Get(layerIndex)->layer_as_AdditionLayer()->base();
289 return graphPtr->layers()->Get(layerIndex)->layer_as_ArgMinMaxLayer()->base();
291 return graphPtr->layers()->Get(layerIndex)->layer_as_BatchToSpaceNdLayer()->base();
293 return graphPtr->layers()->Get(layerIndex)->layer_as_BatchNormalizationLayer()->base();
295 return graphPtr->layers()->Get(layerIndex)->layer_as_CastLayer()->base();
297 return graphPtr->layers()->Get(layerIndex)->layer_as_ComparisonLayer()->base();
299 return graphPtr->layers()->Get(layerIndex)->layer_as_ConcatLayer()->base();
301 return graphPtr->layers()->Get(layerIndex)->layer_as_ConstantLayer()->base();
303 return graphPtr->layers()->Get(layerIndex)->layer_as_Convolution2dLayer()->base();
305 return graphPtr->layers()->Get(layerIndex)->layer_as_DepthToSpaceLayer()->base();
307 return graphPtr->layers()->Get(layerIndex)->layer_as_DepthwiseConvolution2dLayer()->base();
309 return graphPtr->layers()->Get(layerIndex)->layer_as_DequantizeLayer()->base();
311 return graphPtr->layers()->Get(layerIndex)->layer_as_DetectionPostProcessLayer()->base();
313 return graphPtr->layers()->Get(layerIndex)->layer_as_DivisionLayer()->base();
315 return graphPtr->layers()->Get(layerIndex)->layer_as_EqualLayer()->base();
317 return graphPtr->layers()->Get(layerIndex)->layer_as_ElementwiseUnaryLayer()->base();
319 return graphPtr->layers()->Get(layerIndex)->layer_as_FullyConnectedLayer()->base();
321 return graphPtr->layers()->Get(layerIndex)->layer_as_FillLayer()->base();
323 return graphPtr->layers()->Get(layerIndex)->layer_as_FloorLayer()->base();
325 return graphPtr->layers()->Get(layerIndex)->layer_as_GatherLayer()->base();
327 return graphPtr->layers()->Get(layerIndex)->layer_as_GreaterLayer()->base();
329 return graphPtr->layers()->Get(layerIndex)->layer_as_InputLayer()->base()->base();
331 return graphPtr->layers()->Get(layerIndex)->layer_as_InstanceNormalizationLayer()->base();
333 return graphPtr->layers()->Get(layerIndex)->layer_as_L2NormalizationLayer()->base();
335 return graphPtr->layers()->Get(layerIndex)->layer_as_LogicalBinaryLayer()->base();
337 return graphPtr->layers()->Get(layerIndex)->layer_as_LogSoftmaxLayer()->base();
339 return graphPtr->layers()->Get(layerIndex)->layer_as_LstmLayer()->base();
341 return graphPtr->layers()->Get(layerIndex)->layer_as_MeanLayer()->base();
343 return graphPtr->layers()->Get(layerIndex)->layer_as_MinimumLayer()->base();
345 return graphPtr->layers()->Get(layerIndex)->layer_as_MaximumLayer()->base();
347 return graphPtr->layers()->Get(layerIndex)->layer_as_MergeLayer()->base();
349 return graphPtr->layers()->Get(layerIndex)->layer_as_MergerLayer()->base();
351 return graphPtr->layers()->Get(layerIndex)->layer_as_MultiplicationLayer()->base();
353 return graphPtr->layers()->Get(layerIndex)->layer_as_NormalizationLayer()->base();
355 return graphPtr->layers()->Get(layerIndex)->layer_as_OutputLayer()->base()->base();
357 return graphPtr->layers()->Get(layerIndex)->layer_as_PadLayer()->base();
359 return graphPtr->layers()->Get(layerIndex)->layer_as_PermuteLayer()->base();
361 return graphPtr->layers()->Get(layerIndex)->layer_as_Pooling2dLayer()->base();
363 return graphPtr->layers()->Get(layerIndex)->layer_as_PreluLayer()->base();
365 return graphPtr->layers()->Get(layerIndex)->layer_as_QLstmLayer()->base();
367 return graphPtr->layers()->Get(layerIndex)->layer_as_QuantizeLayer()->base();
369 return graphPtr->layers()->Get(layerIndex)->layer_as_QuantizedLstmLayer()->base();
371 return graphPtr->layers()->Get(layerIndex)->layer_as_RankLayer()->base();
373 return graphPtr->layers()->Get(layerIndex)->layer_as_ReduceLayer()->base();
375 return graphPtr->layers()->Get(layerIndex)->layer_as_ReshapeLayer()->base();
377 return graphPtr->layers()->Get(layerIndex)->layer_as_ResizeBilinearLayer()->base();
379 return graphPtr->layers()->Get(layerIndex)->layer_as_ResizeLayer()->base();
381 return graphPtr->layers()->Get(layerIndex)->layer_as_RsqrtLayer()->base();
383 return graphPtr->layers()->Get(layerIndex)->layer_as_ShapeLayer()->base();
385 return graphPtr->layers()->Get(layerIndex)->layer_as_SliceLayer()->base();
387 return graphPtr->layers()->Get(layerIndex)->layer_as_SoftmaxLayer()->base();
389 return graphPtr->layers()->Get(layerIndex)->layer_as_SpaceToBatchNdLayer()->base();
391 return graphPtr->layers()->Get(layerIndex)->layer_as_SpaceToDepthLayer()->base();
393 return graphPtr->layers()->Get(layerIndex)->layer_as_SplitterLayer()->base();
395 return graphPtr->layers()->Get(layerIndex)->layer_as_StackLayer()->base();
397 return graphPtr->layers()->Get(layerIndex)->layer_as_StandInLayer()->base();
399 return graphPtr->layers()->Get(layerIndex)->layer_as_StridedSliceLayer()->base();
401 return graphPtr->layers()->Get(layerIndex)->layer_as_SubtractionLayer()->base();
403 return graphPtr->layers()->Get(layerIndex)->layer_as_SwitchLayer()->base();
405 return graphPtr->layers()->Get(layerIndex)->layer_as_TransposeConvolution2dLayer()->base();
407 return graphPtr->layers()->Get(layerIndex)->layer_as_TransposeLayer()->base();
409 return graphPtr->layers()->Get(layerIndex)->layer_as_UnidirectionalSequenceLstmLayer()->base();
412 throw ParseException(fmt::format(
"Layer type {} not recognized", layerType));
420 return layer->layerName()->str();
425 auto layerType = graphPtr->layers()->Get(layerIndex)->layer_type();
429 return graphPtr->layers()->Get(layerIndex)->layer_as_InputLayer()->base()->layerBindingId();
433 return graphPtr->layers()->Get(layerIndex)->layer_as_OutputLayer()->base()->layerBindingId();
586 switch (tensorPtr->dataType())
620 throw ParseException(fmt::format(
"Unsupported data type {0} = {1}. {2}",
621 tensorPtr->dataType(),
627 float quantizationScale = tensorPtr->quantizationScale();
628 int32_t quantizationOffset = tensorPtr->quantizationOffset();
630 if (tensorPtr->dimensionality() ==
static_cast<unsigned int>(Dimensionality::Scalar))
637 else if (tensorPtr->dimensionality() ==
static_cast<unsigned int>(Dimensionality::NotSpecified))
646 auto dimensions = tensorPtr->dimensions();
647 unsigned int size = dimensions->size();
648 std::vector<unsigned int> outputDims(dimensions->begin(), dimensions->begin() + size);
653 if (tensorPtr->dimensionSpecificity() !=
nullptr)
655 auto dimensionSpecificity = tensorPtr->dimensionSpecificity();
656 size = dimensionSpecificity->size();
657 for (
unsigned int i = 0; i < size; ++i)
659 dimensionsSpecificity[i] = dimensionSpecificity->Get(i);
663 TensorShape shape(size, outputDims.data(), dimensionsSpecificity);
665 auto quantizationScales = tensorPtr->quantizationScales();
666 if (quantizationScales)
668 unsigned int quantizationScalesSize = quantizationScales->size();
669 std::vector<float> scales(quantizationScales->begin(), quantizationScales->begin() + quantizationScalesSize);
670 unsigned int quantizationDim = tensorPtr->quantizationDim();
693 switch (constTensorPtr->data_type())
697 auto byteData = constTensorPtr->data_as_ByteData()->data();
703 auto shortData = constTensorPtr->data_as_ShortData()->data();
709 auto intData = constTensorPtr->data_as_IntData()->data();
715 auto longData = constTensorPtr->data_as_LongData()->data();
722 throw ParseException(fmt::format(
"Unsupported data type {0} = {1}. {2}",
723 constTensorPtr->data_type(),
734 const auto& numInputs = layer->inputSlots()->size();
738 for (
unsigned int i=0; i<numInputs; ++i)
741 (layer->inputSlots()->Get(i)->connection()->sourceLayerIndex()));
742 result[i] =
GetBaseLayer(graphPtr, inputId)->outputSlots()->Get(0)->tensorInfo();
751 const auto& numOutputs = layer->outputSlots()->size();
755 for (
unsigned int i=0; i<numOutputs; ++i)
757 result[i] = layer->outputSlots()->Get(i)->tensorInfo();
762 void IDeserializer::DeserializerImpl::ParseUnsupportedLayer(
GraphPtr graph,
unsigned int layerIndex)
765 const auto layerName =
GetBaseLayer(graph, layerIndex)->layerName()->c_str();
766 throw ParseException(fmt::format(
"Layer not supported. layerIndex: {0} " 767 "layerName: {1} / {2}",
773 void IDeserializer::DeserializerImpl::ResetParser()
776 m_InputBindings.clear();
777 m_OutputBindings.clear();
785 return CreateNetworkFromGraph(graph);
791 std::vector<uint8_t> content((std::istreambuf_iterator<char>(binaryContent)), std::istreambuf_iterator<char>());
793 return CreateNetworkFromGraph(graph);
798 if (binaryContent ==
nullptr)
803 flatbuffers::Verifier verifier(binaryContent, len);
804 if (verifier.VerifyBuffer<SerializedGraph>() ==
false)
806 throw ParseException(fmt::format(
"Buffer doesn't conform to the expected Armnn " 807 "flatbuffers format. size:{0} {1}",
816 m_Network = INetwork::Create();
818 unsigned int layerIndex = 0;
819 for (AnyLayer
const* layer : *graph->layers())
825 auto& parserFunction = m_ParserFunctions[layer->layer_type()];
826 (this->*parserFunction)(graph, layerIndex);
831 SetupInputLayers(graph);
832 SetupOutputLayers(graph);
835 for (
auto&& graphIt : m_GraphConnections)
837 Connections& connections = graphIt.second;
838 for (
auto&& outputIt : connections.outputSlots)
840 const unsigned int outputSlotIndex = outputIt.first;
842 if (connections.inputSlots.find(outputSlotIndex) != connections.inputSlots.end())
844 for (
IInputSlot* inputSlot : connections.inputSlots[outputSlotIndex])
846 outputSlot->
Connect(*inputSlot);
852 return std::move(m_Network);
856 const std::string& name)
const 859 for (
auto inputBinding : m_InputBindings)
861 if (inputBinding.first == name)
863 return inputBinding.second;
866 throw ParseException(fmt::format(
"No input binding found for layer:{0} / {1}",
872 const std::string& name)
const 875 for (
auto outputBinding : m_OutputBindings)
877 if (outputBinding.first == name)
879 return outputBinding.second;
882 throw ParseException(fmt::format(
"No output binding found for layer:{0} / {1}",
887 unsigned int IDeserializer::DeserializerImpl::GetInputLayerInVector(
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_InputLayer()->base()->layerBindingId();
895 if (layerBindingId == targetId)
901 throw ParseException(
"Input layer with given layerBindingId not found");
904 unsigned int IDeserializer::DeserializerImpl::GetOutputLayerInVector(
GraphPtr graph,
int targetId)
906 for (
unsigned int i = 0; i < graph->layers()->size(); i++)
908 auto layer = graph->layers()->Get(i);
911 auto layerBindingId = layer->layer_as_OutputLayer()->base()->layerBindingId();
912 if (layerBindingId == targetId)
918 throw ParseException(
"Output layer with given layerBindingId not found");
921 unsigned int IDeserializer::DeserializerImpl::GetLayerIndexInVector(
GraphPtr graph,
unsigned int targetIndex)
923 for (
unsigned int i = 0; i < graph->layers()->size(); i++)
926 if (layer->index() == targetIndex)
934 IDeserializer::DeserializerImpl::FeatureVersions IDeserializer::DeserializerImpl::GetFeatureVersions(
GraphPtr graph)
936 IDeserializer::DeserializerImpl::FeatureVersions versions;
938 if (graph->featureVersions())
940 versions.m_BindingIdScheme = graph->featureVersions()->bindingIdsScheme();
941 versions.m_WeightsLayoutScheme = graph->featureVersions()->weightsLayoutScheme();
942 versions.m_ConstTensorsAsInputs = graph->featureVersions()->constantTensorsAsInputs();
948 void IDeserializer::DeserializerImpl::SetupInputLayers(
GraphPtr graph)
951 const unsigned int numInputs = graph->inputIds()->size();
952 m_InputBindings.clear();
953 m_InputBindings.reserve(numInputs);
955 for (
unsigned int i = 0; i < numInputs; i++)
957 unsigned int inputLayerIndex = 0xFFFFFFFF;
958 if (GetFeatureVersions(graph).m_BindingIdScheme == 0)
961 inputLayerIndex = GetLayerIndexInVector(graph, inputId);
965 const int inputId = graph->inputIds()->Get(i);
966 inputLayerIndex = GetInputLayerInVector(graph, inputId);
976 m_Network->AddInputLayer(bindingId, baseLayer->layerName()->c_str());
979 inputLayer->GetOutputSlot(0).SetTensorInfo(tensorInfo);
980 RegisterOutputSlots(graph, inputLayerIndex, inputLayer);
983 m_InputBindings.push_back(std::make_pair(baseLayer->layerName()->c_str(), bindingInfo));
987 void IDeserializer::DeserializerImpl::SetupOutputLayers(
GraphPtr graph)
990 const unsigned int numOutputs = graph->outputIds()->size();
991 m_OutputBindings.clear();
992 m_OutputBindings.reserve(numOutputs);
994 for (
unsigned int i = 0; i < numOutputs; i++)
996 unsigned int outputLayerIndex = 0xFFFFFFFF;
997 if (GetFeatureVersions(graph).m_BindingIdScheme == 0)
999 const unsigned int outputId =
armnn::numeric_cast<
unsigned int>(graph->outputIds()->Get(i));
1000 outputLayerIndex = GetLayerIndexInVector(graph, outputId);
1004 const int outputId = graph->outputIds()->Get(i);
1005 outputLayerIndex = GetOutputLayerInVector(graph, outputId);
1015 m_Network->AddOutputLayer(bindingId, baseLayer->layerName()->c_str());
1017 RegisterInputSlots(graph, outputLayerIndex, outputLayer);
1018 unsigned int sourceLayerIndex =
1019 GetLayerIndexInVector(graph, baseLayer->inputSlots()->Get(0)->connection()->sourceLayerIndex());
1020 unsigned int outputSlotIndex =
1021 GetLayerIndexInVector(graph, baseLayer->inputSlots()->Get(0)->connection()->outputSlotIndex());
1024 sourceBaseLayer->outputSlots()->Get(outputSlotIndex)->tensorInfo());
1026 m_OutputBindings.push_back(std::make_pair(baseLayer->layerName()->c_str(), bindingInfo));
1030 void IDeserializer::DeserializerImpl::RegisterOutputSlots(
GraphPtr graph,
1031 uint32_t layerIndex,
1039 throw ParseException(fmt::format(
"The number of outputslots ({0}) does not match the number expected ({1})" 1040 " for layer index: {2} {3}",
1041 baseLayer->outputSlots()->size(),
1049 const unsigned int slotIndex = baseLayer->outputSlots()->Get(i)->index();
1052 RegisterOutputSlotOfConnection(baseLayer->index(), slotIndex, outputSlot);
1056 void IDeserializer::DeserializerImpl::RegisterInputSlots(
GraphPtr graph,
1057 uint32_t layerIndex,
1059 std::vector<unsigned int> ignoreSlots)
1065 if (baseLayer->inputSlots()->size() != (layer->
GetNumInputSlots() - ignoreSlots.size()))
1067 throw ParseException(fmt::format(
"The number of inputslots ({0}) does not match the number expected ({1})" 1068 " for layer index:{2} {3}",
1069 baseLayer->inputSlots()->size(),
1078 if (std::find(ignoreSlots.begin(), ignoreSlots.end(), i) == ignoreSlots.end())
1080 auto fbInputSlot = baseLayer->inputSlots()->Get(i);
1081 auto fbConnection = fbInputSlot->connection();
1083 RegisterInputSlotOfConnection(fbConnection->sourceLayerIndex(), fbConnection->outputSlotIndex(), inputSlot);
1088 void IDeserializer::DeserializerImpl::RegisterInputSlotOfConnection(uint32_t sourceLayerIndex,
1089 uint32_t outputSlotIndex,
1092 if (m_GraphConnections.find(sourceLayerIndex) == m_GraphConnections.end())
1094 m_GraphConnections[sourceLayerIndex] = Connections();
1097 Connections& connections = m_GraphConnections[sourceLayerIndex];
1098 if (connections.inputSlots.find(outputSlotIndex) == connections.inputSlots.end())
1100 connections.inputSlots[outputSlotIndex] = {inputSlot};
1104 connections.inputSlots[outputSlotIndex].push_back(inputSlot);
1108 void IDeserializer::DeserializerImpl::RegisterOutputSlotOfConnection(uint32_t sourceLayerIndex,
1109 uint32_t outputSlotIndex,
1112 if (m_GraphConnections.find(sourceLayerIndex) == m_GraphConnections.end())
1114 m_GraphConnections[sourceLayerIndex] = Connections();
1117 Connections& connections = m_GraphConnections[sourceLayerIndex];
1118 if (connections.outputSlots.find(outputSlotIndex) != connections.outputSlots.end())
1123 connections.outputSlots[outputSlotIndex] = outputSlot;
1126 void IDeserializer::DeserializerImpl::ParseAbs(
GraphPtr graph,
unsigned int layerIndex)
1129 auto inputs =
GetInputs(graph, layerIndex);
1133 auto outputs =
GetOutputs(graph, layerIndex);
1139 IConnectableLayer* layer = m_Network->AddElementwiseUnaryLayer(descriptor, layerName.c_str());
1143 RegisterInputSlots(graph, layerIndex, layer);
1144 RegisterOutputSlots(graph, layerIndex, layer);
1147 void IDeserializer::DeserializerImpl::ParseActivation(
GraphPtr graph,
unsigned int layerIndex)
1150 auto inputs =
GetInputs(graph, layerIndex);
1154 auto outputs =
GetOutputs(graph, layerIndex);
1157 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_ActivationLayer();
1159 auto serializerDescriptor = serializerLayer->descriptor();
1163 descriptor.
m_A = serializerDescriptor->a();
1164 descriptor.
m_B = serializerDescriptor->b();
1171 RegisterInputSlots(graph, layerIndex, layer);
1172 RegisterOutputSlots(graph, layerIndex, layer);
1175 void IDeserializer::DeserializerImpl::ParseAdd(
GraphPtr graph,
unsigned int layerIndex)
1178 auto inputs =
GetInputs(graph, layerIndex);
1182 auto outputs =
GetOutputs(graph, layerIndex);
1191 RegisterInputSlots(graph, layerIndex, layer);
1192 RegisterOutputSlots(graph, layerIndex, layer);
1195 void IDeserializer::DeserializerImpl::ParseArgMinMax(
GraphPtr graph,
unsigned int layerIndex)
1198 auto inputs =
GetInputs(graph, layerIndex);
1202 auto outputs =
GetOutputs(graph, layerIndex);
1205 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_ArgMinMaxLayer();
1206 auto serializerDescriptor = serializerLayer->descriptor();
1210 descriptor.
m_Axis = serializerDescriptor->axis();
1212 IConnectableLayer* layer = m_Network->AddArgMinMaxLayer(descriptor, layerName.c_str());
1217 RegisterInputSlots(graph, layerIndex, layer);
1218 RegisterOutputSlots(graph, layerIndex, layer);
1221 void IDeserializer::DeserializerImpl::ParseBatchToSpaceNd(
GraphPtr graph,
unsigned int layerIndex)
1231 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_BatchToSpaceNdLayer()->descriptor();
1232 auto flatBufferCrops = flatBufferDescriptor->crops();
1233 auto flatBufferBlockShape = flatBufferDescriptor->blockShape();
1235 if (flatBufferCrops->Length() % 2 != 0)
1240 std::vector<std::pair<unsigned int, unsigned int>> crops;
1241 crops.reserve(flatBufferCrops->Length() / 2);
1242 for (
unsigned int i = 0; i < flatBufferCrops->Length() - 1; i += 2)
1244 crops.emplace_back(flatBufferCrops->Get(i), flatBufferCrops->Get(i+1));
1250 std::vector<unsigned int>(flatBufferBlockShape->begin(), flatBufferBlockShape->end());
1254 IConnectableLayer* layer = m_Network->AddBatchToSpaceNdLayer(descriptor, layerName.c_str());
1259 RegisterInputSlots(graph, layerIndex, layer);
1260 RegisterOutputSlots(graph, layerIndex, layer);
1263 void IDeserializer::DeserializerImpl::ParseBatchNormalization(
GraphPtr graph,
unsigned int layerIndex)
1267 auto inputs =
GetInputs(graph, layerIndex);
1270 auto outputs =
GetOutputs(graph, layerIndex);
1276 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_BatchNormalizationLayer();
1277 auto serializerDescriptor = serializerLayer->descriptor();
1280 descriptor.
m_Eps = serializerDescriptor->eps();
1294 layer->GetOutputSlot(0).SetTensorInfo(outputInfo);
1296 RegisterInputSlots(graph, layerIndex, layer);
1297 RegisterOutputSlots(graph, layerIndex, layer);
1300 void IDeserializer::DeserializerImpl::ParseCast(
GraphPtr graph,
unsigned int layerIndex)
1317 RegisterInputSlots(graph, layerIndex, layer);
1318 RegisterOutputSlots(graph, layerIndex, layer);
1321 void IDeserializer::DeserializerImpl::ParseConstant(
GraphPtr graph,
unsigned int layerIndex)
1326 auto outputs =
GetOutputs(graph, layerIndex);
1331 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_ConstantLayer();
1332 auto serializerInput = serializerLayer->input();
1336 IConnectableLayer* layer = m_Network->AddConstantLayer(input, layerName.c_str());
1341 RegisterOutputSlots(graph, layerIndex, layer);
1344 void IDeserializer::DeserializerImpl::ParseConvolution2d(
GraphPtr graph,
unsigned int layerIndex)
1347 auto inputs =
GetInputs(graph, layerIndex);
1351 auto outputs =
GetOutputs(graph, layerIndex);
1354 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_Convolution2dLayer();
1356 auto serializerDescriptor = serializerLayer->descriptor();
1359 descriptor.
m_PadLeft = serializerDescriptor->padLeft();
1360 descriptor.
m_PadRight = serializerDescriptor->padRight();
1361 descriptor.
m_PadTop = serializerDescriptor->padTop();
1362 descriptor.
m_PadBottom = serializerDescriptor->padBottom();
1363 descriptor.
m_StrideX = serializerDescriptor->strideX();
1364 descriptor.
m_StrideY = serializerDescriptor->strideY();;
1365 descriptor.
m_DilationX = serializerDescriptor->dilationX();
1366 descriptor.
m_DilationY = serializerDescriptor->dilationY();;
1367 descriptor.
m_BiasEnabled = serializerDescriptor->biasEnabled();;
1384 layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo);
1386 RegisterInputSlots(graph, layerIndex, layer);
1387 RegisterOutputSlots(graph, layerIndex, layer);
1390 void IDeserializer::DeserializerImpl::ParseDepthToSpace(
GraphPtr graph,
unsigned int layerIndex)
1394 auto inputs =
GetInputs(graph, layerIndex);
1397 auto outputs =
GetOutputs(graph, layerIndex);
1400 auto fbDescriptor = graph->layers()->Get(layerIndex)->layer_as_DepthToSpaceLayer()->descriptor();
1403 descriptor.
m_BlockSize = fbDescriptor->blockSize();
1407 IConnectableLayer* layer = m_Network->AddDepthToSpaceLayer(descriptor, layerName.c_str());
1412 RegisterInputSlots(graph, layerIndex, layer);
1413 RegisterOutputSlots(graph, layerIndex, layer);
1416 void IDeserializer::DeserializerImpl::ParseDepthwiseConvolution2d(
GraphPtr graph,
unsigned int layerIndex)
1419 auto inputs =
GetInputs(graph, layerIndex);
1423 auto outputs =
GetOutputs(graph, layerIndex);
1426 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_DepthwiseConvolution2dLayer();
1428 auto serializerDescriptor = serializerLayer->descriptor();
1431 descriptor.
m_PadLeft = serializerDescriptor->padLeft();
1432 descriptor.
m_PadRight = serializerDescriptor->padRight();
1433 descriptor.
m_PadTop = serializerDescriptor->padTop();
1434 descriptor.
m_PadBottom = serializerDescriptor->padBottom();
1435 descriptor.
m_StrideX = serializerDescriptor->strideX();
1436 descriptor.
m_StrideY = serializerDescriptor->strideY();
1437 descriptor.
m_DilationX = serializerDescriptor->dilationX();
1438 descriptor.
m_DilationY = serializerDescriptor->dilationY();
1439 descriptor.
m_BiasEnabled = serializerDescriptor->biasEnabled();;
1454 if (this->GetFeatureVersions(graph).m_WeightsLayoutScheme <= 0)
1460 std::unique_ptr<unsigned char[]> permuteBuffer(
new unsigned char[weightsInfo.
GetNumBytes()]);
1463 weights.GetMemoryArea(), permuteBuffer.get(),
1467 auto weightsShape = weightsInfo.GetShape();
1468 weightsInfo.SetShape({1,
1471 weightsShape[2]*weightsShape[3]});
1475 layer = m_Network->AddDepthwiseConvolution2dLayer(descriptor,
1482 layer = m_Network->AddDepthwiseConvolution2dLayer(descriptor,
1489 layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo);
1491 RegisterInputSlots(graph, layerIndex, layer);
1492 RegisterOutputSlots(graph, layerIndex, layer);
1495 void IDeserializer::DeserializerImpl::ParseDetectionPostProcess(
GraphPtr graph,
unsigned int layerIndex)
1498 auto inputs =
GetInputs(graph, layerIndex);
1502 auto outputs =
GetOutputs(graph, layerIndex);
1505 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_DetectionPostProcessLayer();
1507 auto flatBufferDescriptor = flatBufferLayer->descriptor();
1515 descriptor.
m_NumClasses = flatBufferDescriptor->numClasses();
1517 descriptor.
m_ScaleX = flatBufferDescriptor->scaleX();
1518 descriptor.
m_ScaleY = flatBufferDescriptor->scaleY();
1519 descriptor.
m_ScaleW = flatBufferDescriptor->scaleW();
1520 descriptor.
m_ScaleH = flatBufferDescriptor->scaleH();
1528 for (
unsigned int i = 0; i < 4; i++)
1530 layer->GetOutputSlot(i).SetTensorInfo(
ToTensorInfo(outputs[i]));
1533 RegisterInputSlots(graph, layerIndex, layer);
1534 RegisterOutputSlots(graph, layerIndex, layer);
1537 void IDeserializer::DeserializerImpl::ParseDivision(
GraphPtr graph,
unsigned int layerIndex)
1540 auto inputs =
GetInputs(graph, layerIndex);
1544 auto outputs =
GetOutputs(graph, layerIndex);
1553 RegisterInputSlots(graph, layerIndex, layer);
1554 RegisterOutputSlots(graph, layerIndex, layer);
1557 void IDeserializer::DeserializerImpl::ParseEqual(
GraphPtr graph,
unsigned int layerIndex)
1560 auto inputs =
GetInputs(graph, layerIndex);
1564 auto outputs =
GetOutputs(graph, layerIndex);
1569 IConnectableLayer* layer = m_Network->AddComparisonLayer(descriptor, layerName.c_str());
1574 RegisterInputSlots(graph, layerIndex, layer);
1575 RegisterOutputSlots(graph, layerIndex, layer);
1578 void IDeserializer::DeserializerImpl::ParseFill(
GraphPtr graph,
unsigned int layerIndex)
1581 auto inputs =
GetInputs(graph, layerIndex);
1585 auto outputs =
GetOutputs(graph, layerIndex);
1590 IConnectableLayer* layer = m_Network->AddFillLayer(descriptor, layerName.c_str());
1595 RegisterInputSlots(graph, layerIndex, layer);
1596 RegisterOutputSlots(graph, layerIndex, layer);
1599 void IDeserializer::DeserializerImpl::ParseGreater(
GraphPtr graph,
unsigned int layerIndex)
1602 auto inputs =
GetInputs(graph, layerIndex);
1606 auto outputs =
GetOutputs(graph, layerIndex);
1611 IConnectableLayer* layer = m_Network->AddComparisonLayer(descriptor, layerName.c_str());
1616 RegisterInputSlots(graph, layerIndex, layer);
1617 RegisterOutputSlots(graph, layerIndex, layer);
1620 void IDeserializer::DeserializerImpl::ParseInstanceNormalization(
GraphPtr graph,
unsigned int layerIndex)
1624 auto inputs =
GetInputs(graph, layerIndex);
1627 auto outputs =
GetOutputs(graph, layerIndex);
1630 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_InstanceNormalizationLayer();
1631 auto fbDescriptor = fbLayer->descriptor();
1634 descriptor.
m_Gamma = fbDescriptor->gamma();
1635 descriptor.
m_Beta = fbDescriptor->beta();
1636 descriptor.
m_Eps = fbDescriptor->eps();
1639 const std::string layerName =
GetLayerName(graph, layerIndex);
1642 IConnectableLayer* layer = m_Network->AddInstanceNormalizationLayer(descriptor, layerName.c_str());
1645 RegisterInputSlots(graph, layerIndex, layer);
1646 RegisterOutputSlots(graph, layerIndex, layer);
1649 void IDeserializer::DeserializerImpl::ParseL2Normalization(
GraphPtr graph,
unsigned int layerIndex)
1653 auto inputs =
GetInputs(graph, layerIndex);
1656 auto outputs =
GetOutputs(graph, layerIndex);
1660 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_L2NormalizationLayer();
1661 auto flatBufferDescriptor = flatBufferLayer->descriptor();
1666 descriptor.
m_Eps = flatBufferDescriptor->eps();
1668 IConnectableLayer* layer = m_Network->AddL2NormalizationLayer(descriptor, layerName.c_str());
1671 RegisterInputSlots(graph, layerIndex, layer);
1672 RegisterOutputSlots(graph, layerIndex, layer);
1675 void IDeserializer::DeserializerImpl::ParseLogicalBinary(
GraphPtr graph,
unsigned int layerIndex)
1680 auto inputs =
GetInputs(graph, layerIndex);
1683 auto outputs =
GetOutputs(graph, layerIndex);
1686 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_LogicalBinaryLayer();
1687 auto fbDescriptor = fbLayer->descriptor();
1692 const std::string& layerName =
GetLayerName(graph, layerIndex);
1693 IConnectableLayer* layer = m_Network->AddLogicalBinaryLayer(descriptor, layerName.c_str());
1698 RegisterInputSlots(graph, layerIndex, layer);
1699 RegisterOutputSlots(graph, layerIndex, layer);
1702 void IDeserializer::DeserializerImpl::ParseLogSoftmax(
GraphPtr graph,
unsigned int layerIndex)
1713 descriptor.
m_Beta = graph->layers()->Get(layerIndex)->layer_as_LogSoftmaxLayer()->descriptor()->beta();
1714 descriptor.m_Axis = graph->layers()->Get(layerIndex)->layer_as_LogSoftmaxLayer()->descriptor()->axis();
1717 IConnectableLayer* layer = m_Network->AddLogSoftmaxLayer(descriptor, layerName.c_str());
1722 RegisterInputSlots(graph, layerIndex, layer);
1723 RegisterOutputSlots(graph, layerIndex, layer);
1726 void IDeserializer::DeserializerImpl::ParseMinimum(
GraphPtr graph,
unsigned int layerIndex)
1729 auto inputs =
GetInputs(graph, layerIndex);
1733 auto outputs =
GetOutputs(graph, layerIndex);
1742 RegisterInputSlots(graph, layerIndex, layer);
1743 RegisterOutputSlots(graph, layerIndex, layer);
1746 void IDeserializer::DeserializerImpl::ParseMaximum(
GraphPtr graph,
unsigned int layerIndex)
1749 auto inputs =
GetInputs(graph, layerIndex);
1753 auto outputs =
GetOutputs(graph, layerIndex);
1762 RegisterInputSlots(graph, layerIndex, layer);
1763 RegisterOutputSlots(graph, layerIndex, layer);
1767 unsigned int layerIndex)
1769 auto layerType = graph->layers()->Get(layerIndex)->layer_type();
1774 return graph->layers()->Get(layerIndex)->layer_as_ConcatLayer()->descriptor();
1776 return graph->layers()->Get(layerIndex)->layer_as_MergerLayer()->descriptor();
1782 void IDeserializer::DeserializerImpl::ParseComparison(
GraphPtr graph,
unsigned int layerIndex)
1787 auto inputs =
GetInputs(graph, layerIndex);
1790 auto outputs =
GetOutputs(graph, layerIndex);
1793 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_ComparisonLayer();
1794 auto fbDescriptor = fbLayer->descriptor();
1799 const std::string& layerName =
GetLayerName(graph, layerIndex);
1800 IConnectableLayer* layer = m_Network->AddComparisonLayer(descriptor, layerName.c_str());
1805 RegisterInputSlots(graph, layerIndex, layer);
1806 RegisterOutputSlots(graph, layerIndex, layer);
1809 void IDeserializer::DeserializerImpl::ParseElementwiseUnary(
GraphPtr graph,
unsigned int layerIndex)
1814 auto inputs =
GetInputs(graph, layerIndex);
1817 auto outputs =
GetOutputs(graph, layerIndex);
1820 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_ElementwiseUnaryLayer();
1821 auto fbDescriptor = fbLayer->descriptor();
1826 const std::string& layerName =
GetLayerName(graph, layerIndex);
1827 IConnectableLayer* layer = m_Network->AddElementwiseUnaryLayer(descriptor, layerName.c_str());
1832 RegisterInputSlots(graph, layerIndex, layer);
1833 RegisterOutputSlots(graph, layerIndex, layer);
1836 void IDeserializer::DeserializerImpl::ParseConcat(
GraphPtr graph,
unsigned int layerIndex)
1841 auto outputs =
GetOutputs(graph, layerIndex);
1846 unsigned int numViews = originsDescriptor->numViews();
1847 unsigned int numDimensions = originsDescriptor->numDimensions();
1850 auto inputs =
GetInputs(graph, layerIndex);
1854 auto originsPtr = originsDescriptor->viewOrigins();
1855 for (
unsigned int v = 0; v < numViews; ++v)
1857 auto originPtr = originsPtr->Get(v);
1858 for (
unsigned int d = 0; d < numDimensions; ++d)
1860 uint32_t value = originPtr->data()->Get(d);
1861 descriptor.SetViewOriginCoord(v, d, value);
1864 descriptor.SetConcatAxis(originsDescriptor->concatAxis());
1866 IConnectableLayer* layer = m_Network->AddConcatLayer(descriptor, layerName.c_str());
1870 RegisterInputSlots(graph, layerIndex, layer);
1871 RegisterOutputSlots(graph, layerIndex, layer);
1874 void IDeserializer::DeserializerImpl::ParseMultiplication(
GraphPtr graph,
unsigned int layerIndex)
1877 auto inputs =
GetInputs(graph, layerIndex);
1881 auto outputs =
GetOutputs(graph, layerIndex);
1885 IConnectableLayer* layer = m_Network->AddMultiplicationLayer(layerName.c_str());
1890 RegisterInputSlots(graph, layerIndex, layer);
1891 RegisterOutputSlots(graph, layerIndex, layer);
1894 void IDeserializer::DeserializerImpl::ParseFloor(
GraphPtr graph,
unsigned int layerIndex)
1899 auto inputs =
GetInputs(graph, layerIndex);
1902 auto outputs =
GetOutputs(graph, layerIndex);
1909 layer = m_Network->AddFloorLayer(layerName.c_str());
1914 RegisterInputSlots(graph, layerIndex, layer);
1915 RegisterOutputSlots(graph, layerIndex, layer);
1918 void IDeserializer::DeserializerImpl::ParseFullyConnected(
GraphPtr graph,
unsigned int layerIndex)
1921 auto inputs =
GetInputs(graph, layerIndex);
1924 auto outputs =
GetOutputs(graph, layerIndex);
1927 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_FullyConnectedLayer();
1929 auto flatBufferDescriptor = flatBufferLayer->descriptor();
1932 fullyConnectedDescriptor.
m_BiasEnabled = flatBufferDescriptor->biasEnabled();
1934 fullyConnectedDescriptor.
m_ConstantWeights = flatBufferDescriptor->constantWeights();
1937 std::vector<unsigned int> ignoreSlots {};
1941 if (this->GetFeatureVersions(graph).m_ConstTensorsAsInputs <= 0)
1946 layer = m_Network->AddFullyConnectedLayer(fullyConnectedDescriptor,
1950 auto weightsLayer = m_Network->AddConstantLayer(weightsTensor);
1951 weightsLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(1u));
1952 weightsLayer->GetOutputSlot(0).SetTensorInfo(weightsTensor.
GetInfo());
1953 ignoreSlots.emplace_back(1u);
1958 auto biasLayer = m_Network->AddConstantLayer(biasTensor);
1959 biasLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(2u));
1960 biasLayer->GetOutputSlot(0).SetTensorInfo(biasTensor.
GetInfo());
1961 ignoreSlots.emplace_back(2u);
1966 layer = m_Network->AddFullyConnectedLayer(fullyConnectedDescriptor,
1968 uint32_t numInputs = fullyConnectedDescriptor.
GetNumInputs();
1975 RegisterInputSlots(graph, layerIndex, layer, ignoreSlots);
1976 RegisterOutputSlots(graph, layerIndex, layer);
1979 void IDeserializer::DeserializerImpl::ParsePad(
GraphPtr graph,
unsigned int layerIndex)
1989 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_PadLayer()->descriptor();
1990 auto flatBufferPadList = flatBufferDescriptor->padList();
1991 float padValue = flatBufferDescriptor->padValue();
1993 if (flatBufferPadList->Length() % 2 != 0)
1995 throw ParseException(fmt::format(
"The size of the pad list must be divisible by 2 {}",
1999 std::vector<std::pair<unsigned int, unsigned int>> padList;
2000 padList.reserve(flatBufferPadList->Length() / 2);
2001 for (
unsigned int i = 0; i < flatBufferPadList->Length() - 1; i += 2)
2003 padList.emplace_back(flatBufferPadList->Get(i), flatBufferPadList->Get(i+1));
2009 IConnectableLayer* layer = m_Network->AddPadLayer(descriptor, layerName.c_str());
2014 RegisterInputSlots(graph, layerIndex, layer);
2015 RegisterOutputSlots(graph, layerIndex, layer);
2018 void IDeserializer::DeserializerImpl::ParsePermute(
GraphPtr graph,
unsigned int layerIndex)
2023 graph->layers()->Get(layerIndex)->layer_as_PermuteLayer()->descriptor()->dimMappings();
2025 auto inputs =
GetInputs(graph, layerIndex);
2028 auto outputs =
GetOutputs(graph, layerIndex);
2035 IConnectableLayer* layer = m_Network->AddPermuteLayer(descriptor, layerName.c_str());
2038 RegisterInputSlots(graph, layerIndex, layer);
2039 RegisterOutputSlots(graph, layerIndex, layer);
2043 unsigned int layerIndex)
2048 switch (pooling2dDesc->poolType())
2071 switch (pooling2dDesc->outputShapeRounding())
2089 switch (pooling2dDesc->paddingMethod())
2107 switch (pooling2dDesc->dataLayout())
2126 desc.
m_PadLeft = pooling2dDesc->padLeft();
2128 desc.
m_PadTop = pooling2dDesc->padTop();
2129 desc.
m_StrideX = pooling2dDesc->strideX();
2130 desc.
m_StrideY = pooling2dDesc->strideY();
2139 void IDeserializer::DeserializerImpl::ParsePooling2d(
GraphPtr graph,
unsigned int layerIndex)
2143 auto pooling2dDes = graph->layers()->Get(layerIndex)->layer_as_Pooling2dLayer()->descriptor();
2144 auto inputs =
GetInputs(graph, layerIndex);
2147 auto outputs =
GetOutputs(graph, layerIndex);
2153 IConnectableLayer* layer = m_Network->AddPooling2dLayer(pooling2dDescriptor, layerName.c_str());
2156 RegisterInputSlots(graph, layerIndex, layer);
2157 RegisterOutputSlots(graph, layerIndex, layer);
2160 void IDeserializer::DeserializerImpl::ParseQuantize(
GraphPtr graph,
unsigned int layerIndex)
2164 auto inputs =
GetInputs(graph, layerIndex);
2167 auto outputs =
GetOutputs(graph, layerIndex);
2175 RegisterInputSlots(graph, layerIndex, layer);
2176 RegisterOutputSlots(graph, layerIndex, layer);
2180 const std::vector<uint32_t>& targetDimsIn)
2182 std::vector<unsigned int> outputDims(targetDimsIn.begin(), targetDimsIn.end());
2183 const auto stretchDim = std::find(targetDimsIn.begin(), targetDimsIn.end(), -1);
2185 if (stretchDim != targetDimsIn.end())
2187 if (std::find(std::next(stretchDim), targetDimsIn.end(), -1) != targetDimsIn.end())
2189 throw ParseException(fmt::format(
"At most one component of shape can be -1 {}",
2193 auto targetNumElements =
2195 std::accumulate(targetDimsIn.begin(), targetDimsIn.end(), -1, std::multiplies<int32_t>()));
2197 auto stretchIndex =
static_cast<size_t>(std::distance(targetDimsIn.begin(), stretchDim));
2198 outputDims[stretchIndex] = inputTensorInfo.
GetNumElements() / targetNumElements;
2209 void IDeserializer::DeserializerImpl::ParseRank(
GraphPtr graph,
unsigned int layerIndex)
2225 RegisterInputSlots(graph, layerIndex, layer);
2226 RegisterOutputSlots(graph, layerIndex, layer);
2229 void IDeserializer::DeserializerImpl::ParseReduce(
GraphPtr graph,
unsigned int layerIndex)
2234 auto inputs =
GetInputs(graph, layerIndex);
2237 auto outputs =
GetOutputs(graph, layerIndex);
2240 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_ReduceLayer();
2241 auto fbDescriptor = fbLayer->descriptor();
2242 auto flatBufferAxis = fbDescriptor->axis();
2245 descriptor.
m_KeepDims = fbDescriptor->keepDims();
2246 descriptor.
m_vAxis = std::vector<unsigned int>(flatBufferAxis->begin(), flatBufferAxis->end());
2249 const std::string& layerName =
GetLayerName(graph, layerIndex);
2250 IConnectableLayer* layer = m_Network->AddReduceLayer(descriptor, layerName.c_str());
2255 RegisterInputSlots(graph, layerIndex, layer);
2256 RegisterOutputSlots(graph, layerIndex, layer);
2259 void IDeserializer::DeserializerImpl::ParseReshape(
GraphPtr graph,
unsigned int layerIndex)
2262 auto inputs =
GetInputs(graph, layerIndex);
2264 auto outputs =
GetOutputs(graph, layerIndex);
2270 const auto targetDims = graph->layers()->Get(layerIndex)->layer_as_ReshapeLayer()->descriptor()->targetShape();
2271 std::vector<uint32_t> outputDims(targetDims->begin(), targetDims->begin() + targetDims->size());
2274 const armnn::TensorShape& reshapeOutputTensorShape = reshapeOutputTensorInfo.GetShape();
2276 const std::vector<uint32_t> expectedDims(outputs[0]->dimensions()->begin(),
2277 outputs[0]->dimensions()->begin() + outputs[0]->dimensions()->size());
2279 if (inputs.size() > 1 && !
CheckShape(reshapeOutputTensorShape, expectedDims))
2281 std::stringstream ss;
2282 ss <<
"New shape defined in reshape parameters " 2283 << reshapeOutputTensorShape
2284 <<
" does not equal output shape " 2285 << actualOutputTensorInfo.
GetShape()
2295 IConnectableLayer* layer = m_Network->AddReshapeLayer(reshapeDesc, layerName.c_str());
2298 RegisterInputSlots(graph, layerIndex, layer);
2299 RegisterOutputSlots(graph, layerIndex, layer);
2302 void IDeserializer::DeserializerImpl::ParseResize(
GraphPtr graph,
unsigned int layerIndex)
2312 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_ResizeLayer()->descriptor();
2315 descriptor.
m_TargetWidth = flatBufferDescriptor->targetWidth();
2316 descriptor.
m_TargetHeight = flatBufferDescriptor->targetHeight();
2319 descriptor.
m_AlignCorners = flatBufferDescriptor->alignCorners();
2323 IConnectableLayer* layer = m_Network->AddResizeLayer(descriptor, layerName.c_str());
2328 RegisterInputSlots(graph, layerIndex, layer);
2329 RegisterOutputSlots(graph, layerIndex, layer);
2332 void IDeserializer::DeserializerImpl::ParseResizeBilinear(
GraphPtr graph,
unsigned int layerIndex)
2342 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_ResizeBilinearLayer()->descriptor();
2345 descriptor.
m_TargetWidth = flatBufferDescriptor->targetWidth();
2346 descriptor.
m_TargetHeight = flatBufferDescriptor->targetHeight();
2349 descriptor.
m_AlignCorners = flatBufferDescriptor->alignCorners();
2353 IConnectableLayer* layer = m_Network->AddResizeLayer(descriptor, layerName.c_str());
2358 RegisterInputSlots(graph, layerIndex, layer);
2359 RegisterOutputSlots(graph, layerIndex, layer);
2362 void IDeserializer::DeserializerImpl::ParseShape(
GraphPtr graph,
unsigned int layerIndex)
2378 RegisterInputSlots(graph, layerIndex, layer);
2379 RegisterOutputSlots(graph, layerIndex, layer);
2382 void IDeserializer::DeserializerImpl::ParseSoftmax(
GraphPtr graph,
unsigned int layerIndex)
2393 descriptor.
m_Beta = graph->layers()->Get(layerIndex)->layer_as_SoftmaxLayer()->descriptor()->beta();
2396 IConnectableLayer* layer = m_Network->AddSoftmaxLayer(descriptor, layerName.c_str());
2401 RegisterInputSlots(graph, layerIndex, layer);
2402 RegisterOutputSlots(graph, layerIndex, layer);
2405 void IDeserializer::DeserializerImpl::ParseSpaceToBatchNd(
GraphPtr graph,
unsigned int layerIndex)
2415 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_SpaceToBatchNdLayer()->descriptor();
2416 auto flatBufferPadList = flatBufferDescriptor->padList();
2417 auto flatBufferBlockShape = flatBufferDescriptor->blockShape();
2419 if (flatBufferPadList->Length() % 2 != 0)
2421 throw ParseException(fmt::format(
"The size of the pad list must be divisible by 2 {}",
2425 std::vector<std::pair<unsigned int, unsigned int>> padList;
2426 padList.reserve(flatBufferPadList->Length() / 2);
2427 for (
unsigned int i = 0; i < flatBufferPadList->Length() - 1; i += 2)
2429 padList.emplace_back(flatBufferPadList->Get(i), flatBufferPadList->Get(i+1));
2435 std::vector<unsigned int>(flatBufferBlockShape->begin(), flatBufferBlockShape->end());
2439 IConnectableLayer* layer = m_Network->AddSpaceToBatchNdLayer(descriptor, layerName.c_str());
2444 RegisterInputSlots(graph, layerIndex, layer);
2445 RegisterOutputSlots(graph, layerIndex, layer);
2448 void IDeserializer::DeserializerImpl::ParseSpaceToDepth(
GraphPtr graph,
unsigned int layerIndex)
2458 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_SpaceToDepthLayer()->descriptor();
2461 descriptor.
m_BlockSize = flatBufferDescriptor->blockSize();
2465 IConnectableLayer* layer = m_Network->AddSpaceToDepthLayer(descriptor, layerName.c_str());
2470 RegisterInputSlots(graph, layerIndex, layer);
2471 RegisterOutputSlots(graph, layerIndex, layer);
2476 unsigned int layerIndex)
2481 switch (normalizationDescriptor->normChannelType())
2499 switch (normalizationDescriptor->normMethodType())
2517 switch (normalizationDescriptor->dataLayout())
2535 desc.
m_Alpha = normalizationDescriptor->alpha();
2536 desc.
m_Beta = normalizationDescriptor->beta();
2537 desc.
m_K = normalizationDescriptor->k();
2538 desc.
m_NormSize = normalizationDescriptor->normSize();
2543 void IDeserializer::DeserializerImpl::ParseNormalization(
GraphPtr graph,
unsigned int layerIndex)
2547 auto normalizationDes = graph->layers()->Get(layerIndex)->layer_as_NormalizationLayer()->descriptor();
2560 IConnectableLayer* layer = m_Network->AddNormalizationLayer(normalizationDescriptor, layerName.c_str());
2563 RegisterInputSlots(graph, layerIndex, layer);
2564 RegisterOutputSlots(graph, layerIndex, layer);
2567 void IDeserializer::DeserializerImpl::ParseRsqrt(
GraphPtr graph,
unsigned int layerIndex)
2570 auto inputs =
GetInputs(graph, layerIndex);
2574 auto outputs =
GetOutputs(graph, layerIndex);
2580 IConnectableLayer* layer = m_Network->AddElementwiseUnaryLayer(descriptor, layerName.c_str());
2584 RegisterInputSlots(graph, layerIndex, layer);
2585 RegisterOutputSlots(graph, layerIndex, layer);
2588 void IDeserializer::DeserializerImpl::ParseSlice(
GraphPtr graph,
unsigned int layerIndex)
2592 auto inputs =
GetInputs(graph, layerIndex);
2595 auto outputs =
GetOutputs(graph, layerIndex);
2598 auto fbDescriptor = graph->layers()->Get(layerIndex)->layer_as_SliceLayer()->descriptor();
2600 auto fbBegin = fbDescriptor->begin();
2601 auto fbSize = fbDescriptor->size();
2603 if (fbBegin->Length() != fbSize->Length())
2605 throw ParseException(fmt::format(
"Begin and size descriptors must have the same length {}",
2610 descriptor.
m_Begin.insert(descriptor.
m_Begin.end(), fbBegin->begin(), fbBegin->end());
2611 descriptor.
m_Size.insert(descriptor.
m_Size.end(), fbSize->begin(), fbSize->end());
2614 IConnectableLayer* layer = m_Network->AddSliceLayer(descriptor, layerName.c_str());
2619 RegisterInputSlots(graph, layerIndex, layer);
2620 RegisterOutputSlots(graph, layerIndex, layer);
2623 void IDeserializer::DeserializerImpl::ParseStridedSlice(
GraphPtr graph,
unsigned int layerIndex)
2633 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_StridedSliceLayer()->descriptor();
2635 auto flatBufferBegin = flatBufferDescriptor->begin();
2636 auto flatBufferEnd = flatBufferDescriptor->end();
2637 auto flatBufferStride = flatBufferDescriptor->stride();
2639 if (!(flatBufferBegin->Length() == flatBufferEnd->Length() &&
2640 flatBufferBegin->Length() == flatBufferStride->Length()))
2642 throw ParseException(fmt::format(
"The size of the begin, end, and stride must be equal {}",
2646 std::vector<int> begin(flatBufferBegin->begin(), flatBufferBegin->end());
2647 std::vector<int> end(flatBufferEnd->begin(), flatBufferEnd->end());
2648 std::vector<int> stride(flatBufferStride->begin(), flatBufferStride->end());
2651 descriptor.m_BeginMask = flatBufferDescriptor->beginMask();
2652 descriptor.m_EndMask = flatBufferDescriptor->endMask();
2653 descriptor.m_ShrinkAxisMask = flatBufferDescriptor->shrinkAxisMask();
2654 descriptor.m_EllipsisMask = flatBufferDescriptor->ellipsisMask();
2655 descriptor.m_NewAxisMask = flatBufferDescriptor->newAxisMask();
2656 descriptor.m_DataLayout =
ToDataLayout(flatBufferDescriptor->dataLayout());
2659 IConnectableLayer* layer = m_Network->AddStridedSliceLayer(descriptor, layerName.c_str());
2664 RegisterInputSlots(graph, layerIndex, layer);
2665 RegisterOutputSlots(graph, layerIndex, layer);
2668 void IDeserializer::DeserializerImpl::ParseSubtraction(
GraphPtr graph,
unsigned int layerIndex)
2671 auto inputs =
GetInputs(graph, layerIndex);
2675 auto outputs =
GetOutputs(graph, layerIndex);
2684 RegisterInputSlots(graph, layerIndex, layer);
2685 RegisterOutputSlots(graph, layerIndex, layer);
2688 void IDeserializer::DeserializerImpl::ParseGather(
GraphPtr graph,
unsigned int layerIndex)
2699 descriptor.
m_Axis = graph->layers()->Get(layerIndex)->layer_as_GatherLayer()->descriptor()->axis();
2702 IConnectableLayer* layer = m_Network->AddGatherLayer(descriptor, layerName.c_str());
2707 RegisterInputSlots(graph, layerIndex, layer);
2708 RegisterOutputSlots(graph, layerIndex, layer);
2711 void IDeserializer::DeserializerImpl::ParseMean(
GraphPtr graph,
unsigned int layerIndex)
2721 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_MeanLayer()->descriptor();
2722 auto flatBufferAxis = flatBufferDescriptor->axis();
2723 auto flatBufferKeepDims = flatBufferDescriptor->keepDims();
2726 descriptor.
m_Axis = std::vector<unsigned int>(flatBufferAxis->begin(), flatBufferAxis->end());
2730 IConnectableLayer* layer = m_Network->AddMeanLayer(descriptor, layerName.c_str());
2735 RegisterInputSlots(graph, layerIndex, layer);
2736 RegisterOutputSlots(graph, layerIndex, layer);
2739 void IDeserializer::DeserializerImpl::ParseSplitter(
GraphPtr graph,
unsigned int layerIndex)
2748 auto flatBufferViewsDescriptor = graph->layers()->Get(layerIndex)->layer_as_SplitterLayer()->descriptor();
2749 auto flatBufferViewSizes = flatBufferViewsDescriptor->viewSizes();
2750 auto flatBufferOriginsDescriptor = flatBufferViewsDescriptor->origins();
2751 auto flatBufferViewOrigins = flatBufferOriginsDescriptor->viewOrigins();
2752 uint32_t numViews = flatBufferOriginsDescriptor->numViews();
2753 uint32_t numDimensions = flatBufferOriginsDescriptor->numDimensions();
2760 for(
unsigned int vIdx = 0; vIdx < numViews; ++vIdx)
2762 for (
unsigned int dIdx = 0; dIdx < numDimensions; ++dIdx)
2764 viewsDescriptor.
SetViewSize(vIdx, dIdx, flatBufferViewSizes->Get(vIdx)->data()->Get(dIdx));
2765 viewsDescriptor.
SetViewOriginCoord(vIdx, dIdx, flatBufferViewOrigins->Get(vIdx)->data()->Get(dIdx));
2770 IConnectableLayer* layer = m_Network->AddSplitterLayer(viewsDescriptor, layerName.c_str());
2773 for(
unsigned int vIdx = 0; vIdx < numViews; ++vIdx)
2779 RegisterInputSlots(graph, layerIndex, layer);
2780 RegisterOutputSlots(graph, layerIndex, layer);
2798 void IDeserializer::DeserializerImpl::ParseLstm(
GraphPtr graph,
unsigned int layerIndex)
2802 auto inputs =
GetInputs(graph, layerIndex);
2805 auto outputs =
GetOutputs(graph, layerIndex);
2808 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_LstmLayer();
2810 auto flatBufferDescriptor = flatBufferLayer->descriptor();
2811 auto flatBufferInputParams = flatBufferLayer->inputParams();
2841 if (!lstmDescriptor.m_CifgEnabled)
2843 inputToInputWeights =
ToConstTensor(flatBufferInputParams->inputToInputWeights());
2844 recurrentToInputWeights =
ToConstTensor(flatBufferInputParams->recurrentToInputWeights());
2845 cellToInputWeights =
ToConstTensor(flatBufferInputParams->cellToInputWeights());
2846 inputGateBias =
ToConstTensor(flatBufferInputParams->inputGateBias());
2856 if (lstmDescriptor.m_ProjectionEnabled)
2858 projectionWeights =
ToConstTensor(flatBufferInputParams->projectionWeights());
2859 projectionBias =
ToConstTensor(flatBufferInputParams->projectionBias());
2867 if (lstmDescriptor.m_PeepholeEnabled)
2869 cellToForgetWeights =
ToConstTensor(flatBufferInputParams->cellToForgetWeights());
2870 cellToOutputWeights =
ToConstTensor(flatBufferInputParams->cellToOutputWeights());
2880 if (lstmDescriptor.m_LayerNormEnabled)
2882 if (!lstmDescriptor.m_CifgEnabled)
2884 inputLayerNormWeights =
ToConstTensor(flatBufferInputParams->inputLayerNormWeights());
2887 forgetLayerNormWeights =
ToConstTensor(flatBufferInputParams->forgetLayerNormWeights());
2888 cellLayerNormWeights =
ToConstTensor(flatBufferInputParams->cellLayerNormWeights());
2889 outputLayerNormWeights =
ToConstTensor(flatBufferInputParams->outputLayerNormWeights());
2896 IConnectableLayer* layer = m_Network->AddLstmLayer(lstmDescriptor, lstmInputParams, layerName.c_str());
2910 RegisterInputSlots(graph, layerIndex, layer);
2911 RegisterOutputSlots(graph, layerIndex, layer);
2923 desc.
m_CellClip = qLstmDescriptor->cellClip();
2937 void IDeserializer::DeserializerImpl::ParseQLstm(
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_QLstmLayer();
2949 auto flatBufferDescriptor = flatBufferLayer->descriptor();
2950 auto flatBufferInputParams = flatBufferLayer->inputParams();
2981 if (!qLstmDescriptor.m_CifgEnabled)
2983 inputToInputWeights =
ToConstTensor(flatBufferInputParams->inputToInputWeights());
2984 recurrentToInputWeights =
ToConstTensor(flatBufferInputParams->recurrentToInputWeights());
2985 inputGateBias =
ToConstTensor(flatBufferInputParams->inputGateBias());
2996 if (qLstmDescriptor.m_ProjectionEnabled)
2998 projectionWeights =
ToConstTensor(flatBufferInputParams->projectionWeights());
2999 projectionBias =
ToConstTensor(flatBufferInputParams->projectionBias());
3010 if (qLstmDescriptor.m_PeepholeEnabled)
3012 if (!qLstmDescriptor.m_CifgEnabled)
3014 cellToInputWeights =
ToConstTensor(flatBufferInputParams->cellToInputWeights());
3018 cellToForgetWeights =
ToConstTensor(flatBufferInputParams->cellToForgetWeights());
3019 cellToOutputWeights =
ToConstTensor(flatBufferInputParams->cellToOutputWeights());
3031 if (qLstmDescriptor.m_LayerNormEnabled)
3033 if (!qLstmDescriptor.m_CifgEnabled)
3035 inputLayerNormWeights =
ToConstTensor(flatBufferInputParams->inputLayerNormWeights());
3039 forgetLayerNormWeights =
ToConstTensor(flatBufferInputParams->forgetLayerNormWeights());
3040 cellLayerNormWeights =
ToConstTensor(flatBufferInputParams->cellLayerNormWeights());
3041 outputLayerNormWeights =
ToConstTensor(flatBufferInputParams->outputLayerNormWeights());
3048 IConnectableLayer* layer = m_Network->AddQLstmLayer(qLstmDescriptor, qLstmInputParams, layerName.c_str());
3059 RegisterInputSlots(graph, layerIndex, layer);
3060 RegisterOutputSlots(graph, layerIndex, layer);
3063 void IDeserializer::DeserializerImpl::ParseQuantizedLstm(
GraphPtr graph,
unsigned int layerIndex)
3067 auto inputs =
GetInputs(graph, layerIndex);
3070 auto outputs =
GetOutputs(graph, layerIndex);
3073 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_QuantizedLstmLayer();
3075 auto flatBufferInputParams = flatBufferLayer->inputParams();
3105 IConnectableLayer* layer = m_Network->AddQuantizedLstmLayer(lstmInputParams, layerName.c_str());
3113 RegisterInputSlots(graph, layerIndex, layer);
3114 RegisterOutputSlots(graph, layerIndex, layer);
3117 void IDeserializer::DeserializerImpl::ParseDequantize(
GraphPtr graph,
unsigned int layerIndex)
3127 const std::string layerName =
GetLayerName(graph, layerIndex);
3133 RegisterInputSlots(graph, layerIndex, layer);
3134 RegisterOutputSlots(graph, layerIndex, layer);
3137 void IDeserializer::DeserializerImpl::ParseMerge(
GraphPtr graph,
unsigned int layerIndex)
3147 const std::string layerName =
GetLayerName(graph, layerIndex);
3153 RegisterInputSlots(graph, layerIndex, layer);
3154 RegisterOutputSlots(graph, layerIndex, layer);
3157 void IDeserializer::DeserializerImpl::ParseSwitch(
GraphPtr graph,
unsigned int layerIndex)
3160 auto inputs =
GetInputs(graph, layerIndex);
3164 auto outputs =
GetOutputs(graph, layerIndex);
3176 RegisterInputSlots(graph, layerIndex, layer);
3177 RegisterOutputSlots(graph, layerIndex, layer);
3180 void IDeserializer::DeserializerImpl::ParsePrelu(
GraphPtr graph,
unsigned int layerIndex)
3183 auto inputs =
GetInputs(graph, layerIndex);
3187 auto outputs =
GetOutputs(graph, layerIndex);
3196 RegisterInputSlots(graph, layerIndex, layer);
3197 RegisterOutputSlots(graph, layerIndex, layer);
3200 void IDeserializer::DeserializerImpl::ParseTranspose(
GraphPtr graph,
unsigned int layerIndex)
3204 auto dimsMapping = graph->layers()->Get(layerIndex)->layer_as_TransposeLayer()->descriptor()->dimMappings();
3206 auto inputs =
GetInputs(graph, layerIndex);
3209 auto outputs =
GetOutputs(graph, layerIndex);
3216 IConnectableLayer* layer = m_Network->AddTransposeLayer(descriptor, layerName.c_str());
3219 RegisterInputSlots(graph, layerIndex, layer);
3220 RegisterOutputSlots(graph, layerIndex, layer);
3223 void IDeserializer::DeserializerImpl::ParseTransposeConvolution2d(
GraphPtr graph,
unsigned int layerIndex)
3227 auto inputs =
GetInputs(graph, layerIndex);
3230 auto outputs =
GetOutputs(graph, layerIndex);
3233 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_TransposeConvolution2dLayer();
3235 auto serializerDescriptor = serializerLayer->descriptor();
3238 descriptor.
m_PadLeft = serializerDescriptor->padLeft();
3239 descriptor.
m_PadRight = serializerDescriptor->padRight();
3240 descriptor.
m_PadTop = serializerDescriptor->padTop();
3241 descriptor.
m_PadBottom = serializerDescriptor->padBottom();
3242 descriptor.
m_StrideX = serializerDescriptor->strideX();
3243 descriptor.
m_StrideY = serializerDescriptor->strideY();;
3244 descriptor.
m_BiasEnabled = serializerDescriptor->biasEnabled();;
3253 optionalBiases = armnn::MakeOptional<armnn::ConstTensor>(biases);
3256 IConnectableLayer* layer = m_Network->AddTransposeConvolution2dLayer(descriptor,
3262 layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo);
3264 RegisterInputSlots(graph, layerIndex, layer);
3265 RegisterOutputSlots(graph, layerIndex, layer);
3268 void IDeserializer::DeserializerImpl::ParseStack(
GraphPtr graph,
unsigned int layerIndex)
3271 auto inputs =
GetInputs(graph, layerIndex);
3273 auto outputs =
GetOutputs(graph, layerIndex);
3276 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_StackLayer()->descriptor();
3277 unsigned int axis = flatBufferDescriptor->axis();
3278 unsigned int numInputs = flatBufferDescriptor->numInputs();
3281 auto flatBufferInputShape = flatBufferDescriptor->inputShape();
3282 std::vector<uint32_t> vectorInputShape(flatBufferInputShape->begin(),
3283 flatBufferInputShape->begin() + flatBufferInputShape->size());
3285 TensorShape inputShape(static_cast<unsigned int>(vectorInputShape.size()), vectorInputShape.data());
3288 for (
unsigned int i=0; i<inputs.size(); ++i)
3291 if (descriptor.m_InputShape != inputShape)
3293 std::stringstream ss;
3294 ss <<
"Shape of input " 3298 <<
" does not equal defined input shape " 3299 << descriptor.m_InputShape
3307 IConnectableLayer* layer = m_Network->AddStackLayer(descriptor, layerName.c_str());
3312 RegisterInputSlots(graph, layerIndex, layer);
3313 RegisterOutputSlots(graph, layerIndex, layer);
3316 void IDeserializer::DeserializerImpl::ParseStandIn(
GraphPtr graph,
unsigned int layerIndex)
3320 auto inputs =
GetInputs(graph, layerIndex);
3321 auto outputs =
GetOutputs(graph, layerIndex);
3323 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_StandInLayer();
3324 auto fbDescriptor = fbLayer->descriptor();
3327 descriptor.
m_NumInputs = fbDescriptor->numInputs();
3333 const std::string layerName =
GetLayerName(graph, layerIndex);
3336 for (
unsigned int i = 0u; i < descriptor.
m_NumOutputs; ++i)
3342 RegisterInputSlots(graph, layerIndex, layer);
3343 RegisterOutputSlots(graph, layerIndex, layer);
3363 void IDeserializer::DeserializerImpl::ParseUnidirectionalSequenceLstm(
GraphPtr graph,
unsigned int layerIndex)
3367 auto inputs =
GetInputs(graph, layerIndex);
3370 auto outputs =
GetOutputs(graph, layerIndex);
3373 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_UnidirectionalSequenceLstmLayer();
3375 auto flatBufferDescriptor = flatBufferLayer->descriptor();
3376 auto flatBufferInputParams = flatBufferLayer->inputParams();
3406 if (!descriptor.m_CifgEnabled)
3408 inputToInputWeights =
ToConstTensor(flatBufferInputParams->inputToInputWeights());
3409 recurrentToInputWeights =
ToConstTensor(flatBufferInputParams->recurrentToInputWeights());
3410 inputGateBias =
ToConstTensor(flatBufferInputParams->inputGateBias());
3416 if (descriptor.m_PeepholeEnabled)
3418 cellToInputWeights =
ToConstTensor(flatBufferInputParams->cellToInputWeights());
3425 if (descriptor.m_ProjectionEnabled)
3427 projectionWeights =
ToConstTensor(flatBufferInputParams->projectionWeights());
3428 projectionBias =
ToConstTensor(flatBufferInputParams->projectionBias());
3436 if (descriptor.m_PeepholeEnabled)
3438 cellToForgetWeights =
ToConstTensor(flatBufferInputParams->cellToForgetWeights());
3439 cellToOutputWeights =
ToConstTensor(flatBufferInputParams->cellToOutputWeights());
3449 if (descriptor.m_LayerNormEnabled)
3451 if (!descriptor.m_CifgEnabled)
3453 inputLayerNormWeights =
ToConstTensor(flatBufferInputParams->inputLayerNormWeights());
3456 forgetLayerNormWeights =
ToConstTensor(flatBufferInputParams->forgetLayerNormWeights());
3457 cellLayerNormWeights =
ToConstTensor(flatBufferInputParams->cellLayerNormWeights());
3458 outputLayerNormWeights =
ToConstTensor(flatBufferInputParams->outputLayerNormWeights());
3465 IConnectableLayer* layer = m_Network->AddUnidirectionalSequenceLstmLayer(descriptor,
3472 RegisterInputSlots(graph, layerIndex, layer);
3473 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
static armnn::UnidirectionalSequenceLstmDescriptor GetUnidirectionalSequenceLstmDescriptor(UnidirectionalSequenceLstmDescriptorPtr descriptor)
bool m_KeepDims
if true then output shape has no change.
float m_HiddenStateScale
Hidden State quantization scale.
const char * EnumNameConstTensorData(ConstTensorData e)
bool m_BiasEnabled
Enable/disable bias.
unsigned int GetNumBytes() const
float m_OutputIntermediateScale
Output intermediate quantization scale.
ResizeMethod m_Method
The Interpolation method to use (Bilinear, NearestNeighbor).
float m_Gamma
Gamma, the scale scalar value applied for the normalized tensor. Defaults to 1.0. ...
float m_Beta
Exponentiation value.
BindingPointInfo GetNetworkInputBindingInfo(unsigned int layerId, const std::string &name) const
Retrieve binding info (layer id and tensor info) for the network input identified by the given layer ...
std::vector< unsigned int > m_Size
Size of the slice in each dimension.
armnn::INetworkPtr CreateNetworkFromBinary(const std::vector< uint8_t > &binaryContent)
Create an input network from binary file contents.
The padding fields don't count and are ignored.
float m_Eps
Value to add to the variance. Used to avoid dividing by zero.
PaddingMethod m_PaddingMethod
The padding method to be used. (Exclude, IgnoreValue).
ArgMinMaxFunction m_Function
Specify if the function is to find Min or Max.
uint32_t m_DetectionsPerClass
Detections per classes, used in Regular NMS.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
void CheckLayers(Graph &graph)
const armnnSerializer::SerializedGraph * GetSerializedGraph(const void *buf)
uint32_t m_PadTop
Padding top value in the height dimension.
A LogicalBinaryDescriptor for the LogicalBinaryLayer.
uint32_t m_PadRight
Padding right value in the width dimension.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
ReduceOperation m_ReduceOperation
Specifies the reduction operation to execute.
bool m_TimeMajor
Enable/disable time major.
Copyright (c) 2021 ARM Limited and Contributors.
void IgnoreUnused(Ts &&...)
uint32_t m_PadBottom
Padding bottom value in the height dimension.
#define CHECK_GRAPH(GRAPH, LAYERS_INDEX)
uint32_t m_DilationY
Dilation along y axis.
A SpaceToDepthDescriptor for the SpaceToDepthLayer.
const armnnSerializer::SerializedGraph * GraphPtr
std::vector< std::pair< unsigned int, unsigned int > > m_PadList
Specifies the padding values for the input dimension: heightPad{top, bottom} widthPad{left, right}.
uint32_t m_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
void Permute(const armnn::TensorShape &dstShape, const armnn::PermutationVector &mappings, const void *src, void *dst, size_t dataTypeSize)
#define CHECK_CONST_TENSOR_SIZE(CONST_TENSOR_SIZE, TENSOR_SIZE)
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
const armnnSerializer::UnidirectionalSequenceLstmDescriptor * UnidirectionalSequenceLstmDescriptorPtr
armnn::INetworkPtr CreateNetworkFromBinary(const std::vector< uint8_t > &binaryContent)
Create an input network from binary file contents.
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
bool m_LayerNormEnabled
Enable/disable layer normalization.
const armnnSerializer::LstmDescriptor * LstmDescriptorPtr
armnn::DataLayout ToDataLayout(armnnSerializer::DataLayout dataLayout)
bool CheckShape(const armnn::TensorShape &actual, const std::vector< uint32_t > &expected)
float m_NmsIouThreshold
Intersection over union threshold.
static armnn::LstmDescriptor GetLstmDescriptor(LstmDescriptorPtr lstmDescriptor)
An LstmDescriptor for the LstmLayer.
uint32_t m_PadRight
Padding right value in the width dimension.
uint32_t m_DilationX
Dilation factor value for width dimension.
uint32_t m_PadTop
Padding top value in the height dimension.
std::string FileLine() const
Status SetViewSize(uint32_t view, uint32_t coord, uint32_t value)
Set the size of the views.
#define ARMNN_ASSERT_MSG(COND, MSG)
std::vector< unsigned int > m_Begin
Beginning indices of the slice in each dimension.
bool m_KeepDims
Enable/disable keep dimensions. If true, then the reduced dimensions that are of length 1 are kept...
std::vector< unsigned int > m_BlockShape
Block shape values.
float m_Eps
Epsilon, small scalar value added to variance to avoid dividing by zero. Defaults to 1e-12f...
An output connection slot for a layer.
A L2NormalizationDescriptor for the L2NormalizationLayer.
static TensorRawPtrVector GetInputs(const GraphPtr &graph, unsigned int layerIndex)
An ArgMinMaxDescriptor for ArgMinMaxLayer.
An OriginsDescriptor for the ConcatLayer.
A ReduceDescriptor for the REDUCE operators.
float m_ProjectionClip
Clipping threshold value for the projection.
A FullyConnectedDescriptor for the FullyConnectedLayer.
BindingPointInfo GetNetworkOutputBindingInfo(unsigned int layerId, const std::string &name) const
Retrieve binding info (layer id and tensor info) for the network output identified by the given layer...
bool m_BiasEnabled
Enable/disable bias.
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
float m_InputIntermediateScale
Input intermediate quantization scale.
static armnn::Pooling2dDescriptor GetPoolingDescriptor(PoolingDescriptor pooling2dDescriptor, unsigned int layerIndex)
uint32_t m_TargetWidth
Target width value.
A GatherDescriptor for the GatherLayer.
#define CHECK_VALID_SIZE(ACTUAL,...)
bool m_PeepholeEnabled
Enable/disable peephole.
uint32_t m_NumClasses
Number of classes.
#define CHECKED_NON_NEGATIVE(VALUE)
bool m_HalfPixelCenters
Half Pixel Centers.
std::unique_ptr< IDeserializer, void(*)(IDeserializer *parser)> IDeserializerPtr
armnn::ConstTensor ToConstTensor(ConstTensorRawPtr constTensorPtr)
armnn::ActivationFunction ToActivationFunction(armnnSerializer::ActivationFunction function)
uint32_t m_PadTop
Padding top value in the height dimension.
armnn::UnaryOperation ToUnaryOperation(armnnSerializer::UnaryOperation operation)
#define ARMNN_ASSERT(COND)
A StandInDescriptor for the StandIn layer.
A QLstmDescriptor for the QLstmLayer.
#define CHECK_CONST_TENSOR_PTR(TENSOR_PTR)
bool m_UseRegularNms
Use Regular NMS.
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.
const TensorInfo & GetInfo() const
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 GetNumInputs() const
Get the number of views/inputs.
uint32_t m_PadLeft
Padding left value in the width dimension.
EmptyOptional is used to initialize the Optional class in case we want to have default value for an O...
bool m_AlignCorners
Aligned corners.
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
int32_t m_Axis
The axis in params to gather indices from.
A ElementwiseUnaryDescriptor for the ElementwiseUnaryLayer.
PoolingAlgorithm m_PoolType
The pooling algorithm to use (Max. Average, L2).
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
The padding fields count, but are ignored.
std::vector< std::pair< unsigned int, unsigned int > > m_Crops
The values to crop from the input dimension.
Base class for all ArmNN exceptions so that users can filter to just those.
static std::string GetLayerName(const GraphPtr &graph, unsigned int index)
unsigned int GetNumDimensions() const
Function that returns the tensor rank.
bool m_ProjectionEnabled
Enable/disable the projection layer.
Jarret 2009: Local Contrast Normalization.
OutputShapeRounding m_OutputShapeRounding
The rounding method for the output shape. (Floor, Ceiling).
uint32_t m_NumInputs
Number of input tensors.
virtual const IInputSlot & GetInputSlot(unsigned int index) const =0
Get a const input slot handle by slot index.
A MeanDescriptor for the MeanLayer.
void SetConstant(const bool IsConstant=true)
Marks the data corresponding to this tensor info as constant.
static armnn::QLstmDescriptor GetQLstmDescriptor(QLstmDescriptorPtr qLstmDescriptorPtr)
static armnn::TensorInfo OutputShapeOfReshape(const armnn::TensorInfo &inputTensorInfo, const std::vector< uint32_t > &targetDimsIn)
bool m_LayerNormEnabled
Enable/disable layer normalization.
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
armnn::TensorInfo ToTensorInfo(TensorRawPtr tensorPtr)
uint32_t m_PadRight
Padding right value in the width dimension.
A TransposeDescriptor for the TransposeLayer.
A StridedSliceDescriptor for the StridedSliceLayer.
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).
armnn::TensorShape Permuted(const armnn::TensorShape &srcShape, const armnn::PermutationVector &mappings)
A SoftmaxDescriptor for the SoftmaxLayer.
float m_Beta
Beta value for the normalization equation.
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
constexpr unsigned int GetDataTypeSize(DataType dataType)
A PermuteDescriptor for the PermuteLayer.
uint32_t m_PadRight
Padding right value in the width dimension.
int32_t m_HiddenStateZeroPoint
Hidden State zero point.
bool m_ConstantWeights
Enable/disable constant weights and biases.