diff options
Diffstat (limited to 'src/armnnDeserializer')
-rw-r--r-- | src/armnnDeserializer/Deserializer.cpp | 74 | ||||
-rw-r--r-- | src/armnnDeserializer/Deserializer.hpp | 12 |
2 files changed, 82 insertions, 4 deletions
diff --git a/src/armnnDeserializer/Deserializer.cpp b/src/armnnDeserializer/Deserializer.cpp index 99ee0b5b2d..3bbd71a972 100644 --- a/src/armnnDeserializer/Deserializer.cpp +++ b/src/armnnDeserializer/Deserializer.cpp @@ -768,6 +768,40 @@ BindingPointInfo Deserializer::GetNetworkOutputBindingInfo(unsigned int layerInd CHECK_LOCATION().AsString())); } +unsigned int Deserializer::GetInputLayerInVector(GraphPtr graph, int targetId) +{ + for (unsigned int i = 0; i < graph->layers()->size(); i++) + { + auto layer = graph->layers()->Get(i); + if (layer->layer_type() == Layer::Layer_InputLayer) + { + auto layerBindingId = layer->layer_as_InputLayer()->base()->layerBindingId(); + if (layerBindingId == targetId) + { + return i; + } + } + } + throw ParseException("Input layer with given layerBindingId not found"); +} + +unsigned int Deserializer::GetOutputLayerInVector(GraphPtr graph, int targetId) +{ + for (unsigned int i = 0; i < graph->layers()->size(); i++) + { + auto layer = graph->layers()->Get(i); + if (layer->layer_type() == Layer::Layer_OutputLayer) + { + auto layerBindingId = layer->layer_as_OutputLayer()->base()->layerBindingId(); + if (layerBindingId == targetId) + { + return i; + } + } + } + throw ParseException("Output layer with given layerBindingId not found"); +} + unsigned int Deserializer::GetLayerIndexInVector(GraphPtr graph, unsigned int targetIndex) { for (unsigned int i = 0; i < graph->layers()->size(); i++) @@ -781,6 +815,18 @@ unsigned int Deserializer::GetLayerIndexInVector(GraphPtr graph, unsigned int ta throw ParseException("Layer with given index not found"); } +Deserializer::FeatureVersions Deserializer::GetFeatureVersions(GraphPtr graph) +{ + Deserializer::FeatureVersions versions; + + if (graph->featureVersions()) + { + versions.m_BindingIdScheme = graph->featureVersions()->bindingIdsScheme(); + } + + return versions; +} + void Deserializer::SetupInputLayers(GraphPtr graph) { CHECK_GRAPH(graph, 0); @@ -790,8 +836,18 @@ void Deserializer::SetupInputLayers(GraphPtr graph) for (unsigned int i = 0; i < numInputs; i++) { - const unsigned int inputId = graph->inputIds()->Get(i); - const unsigned int inputLayerIndex = GetLayerIndexInVector(graph, inputId); + unsigned int inputLayerIndex = 0xFFFFFFFF; + if (GetFeatureVersions(graph).m_BindingIdScheme == 0) + { + const unsigned int inputId = boost::numeric_cast<unsigned int>(graph->inputIds()->Get(i)); + inputLayerIndex = GetLayerIndexInVector(graph, inputId); + } + else + { + const int inputId = graph->inputIds()->Get(i); + inputLayerIndex = GetInputLayerInVector(graph, inputId); + } + LayerBaseRawPtr baseLayer = GetBaseLayer(graph, inputLayerIndex); // GetBindingLayerInfo expect the index to be index in the vector not index property on each layer base @@ -819,8 +875,18 @@ void Deserializer::SetupOutputLayers(GraphPtr graph) for (unsigned int i = 0; i < numOutputs; i++) { - const unsigned int outputId = graph->outputIds()->Get(i); - const unsigned int outputLayerIndex = GetLayerIndexInVector(graph, outputId); + unsigned int outputLayerIndex = 0xFFFFFFFF; + if (GetFeatureVersions(graph).m_BindingIdScheme == 0) + { + const unsigned int outputId = boost::numeric_cast<unsigned int>(graph->outputIds()->Get(i)); + outputLayerIndex = GetLayerIndexInVector(graph, outputId); + } + else + { + const int outputId = graph->outputIds()->Get(i); + outputLayerIndex = GetOutputLayerInVector(graph, outputId); + } + LayerBaseRawPtr baseLayer = GetBaseLayer(graph, outputLayerIndex); // GetBindingLayerInfo expect the index to be index in the vector not index property on each layer base diff --git a/src/armnnDeserializer/Deserializer.hpp b/src/armnnDeserializer/Deserializer.hpp index ae8be6e932..8e8fe1aca8 100644 --- a/src/armnnDeserializer/Deserializer.hpp +++ b/src/armnnDeserializer/Deserializer.hpp @@ -144,9 +144,21 @@ private: void SetupInputLayers(GraphPtr graphPtr); void SetupOutputLayers(GraphPtr graphPtr); + /// Helper to get the index of the layer in the flatbuffer vector from its bindingId property + unsigned int GetInputLayerInVector(GraphPtr graph, int targetId); + unsigned int GetOutputLayerInVector(GraphPtr graph, int targetId); + /// Helper to get the index of the layer in the flatbuffer vector from its index property unsigned int GetLayerIndexInVector(GraphPtr graph, unsigned int index); + struct FeatureVersions + { + // Default values to zero for backward compatibility + unsigned int m_BindingIdScheme = 0; + }; + + FeatureVersions GetFeatureVersions(GraphPtr graph); + /// The network we're building. Gets cleared after it is passed to the user armnn::INetworkPtr m_Network; std::vector<LayerParsingFunction> m_ParserFunctions; |