diff options
-rw-r--r-- | src/armnnDeserializer/Deserializer.cpp | 27 | ||||
-rw-r--r-- | src/armnnDeserializer/Deserializer.hpp | 1 | ||||
-rw-r--r-- | src/armnnDeserializer/DeserializerSupport.md | 1 | ||||
-rw-r--r-- | src/armnnSerializer/ArmnnSchema.fbs | 16 | ||||
-rw-r--r-- | src/armnnSerializer/Serializer.cpp | 17 | ||||
-rw-r--r-- | src/armnnSerializer/SerializerSupport.md | 1 | ||||
-rw-r--r-- | src/armnnSerializer/test/SerializerTests.cpp | 55 |
7 files changed, 115 insertions, 3 deletions
diff --git a/src/armnnDeserializer/Deserializer.cpp b/src/armnnDeserializer/Deserializer.cpp index 960d300fa5..67836c5843 100644 --- a/src/armnnDeserializer/Deserializer.cpp +++ b/src/armnnDeserializer/Deserializer.cpp @@ -206,6 +206,7 @@ m_ParserFunctions(Layer_MAX+1, &Deserializer::ParseUnsupportedLayer) m_ParserFunctions[Layer_GreaterLayer] = &Deserializer::ParseGreater; m_ParserFunctions[Layer_InstanceNormalizationLayer] = &Deserializer::ParseInstanceNormalization; m_ParserFunctions[Layer_L2NormalizationLayer] = &Deserializer::ParseL2Normalization; + m_ParserFunctions[Layer_LogSoftmaxLayer] = &Deserializer::ParseLogSoftmax; m_ParserFunctions[Layer_LstmLayer] = &Deserializer::ParseLstm; m_ParserFunctions[Layer_MaximumLayer] = &Deserializer::ParseMaximum; m_ParserFunctions[Layer_MeanLayer] = &Deserializer::ParseMean; @@ -286,6 +287,8 @@ Deserializer::LayerBaseRawPtr Deserializer::GetBaseLayer(const GraphPtr& graphPt return graphPtr->layers()->Get(layerIndex)->layer_as_InstanceNormalizationLayer()->base(); case Layer::Layer_L2NormalizationLayer: return graphPtr->layers()->Get(layerIndex)->layer_as_L2NormalizationLayer()->base(); + case Layer::Layer_LogSoftmaxLayer: + return graphPtr->layers()->Get(layerIndex)->layer_as_LogSoftmaxLayer()->base(); case Layer::Layer_LstmLayer: return graphPtr->layers()->Get(layerIndex)->layer_as_LstmLayer()->base(); case Layer::Layer_MeanLayer: @@ -1351,6 +1354,30 @@ void Deserializer::ParseL2Normalization(GraphPtr graph, unsigned int layerIndex) RegisterOutputSlots(graph, layerIndex, layer); } +void Deserializer::ParseLogSoftmax(GraphPtr graph, unsigned int layerIndex) +{ + CHECK_LAYERS(graph, 0, layerIndex); + + Deserializer::TensorRawPtrVector inputs = GetInputs(graph, layerIndex); + CHECK_VALID_SIZE(inputs.size(), 1); + + Deserializer::TensorRawPtrVector outputs = GetOutputs(graph, layerIndex); + CHECK_VALID_SIZE(outputs.size(), 1); + + armnn::LogSoftmaxDescriptor descriptor; + descriptor.m_Beta = graph->layers()->Get(layerIndex)->layer_as_LogSoftmaxLayer()->descriptor()->beta(); + descriptor.m_Axis = graph->layers()->Get(layerIndex)->layer_as_LogSoftmaxLayer()->descriptor()->axis(); + auto layerName = GetLayerName(graph, layerIndex); + + IConnectableLayer* layer = m_Network->AddLogSoftmaxLayer(descriptor, layerName.c_str()); + + armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); + layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); + + RegisterInputSlots(graph, layerIndex, layer); + RegisterOutputSlots(graph, layerIndex, layer); +} + void Deserializer::ParseMinimum(GraphPtr graph, unsigned int layerIndex) { CHECK_LAYERS(graph, 0, layerIndex); diff --git a/src/armnnDeserializer/Deserializer.hpp b/src/armnnDeserializer/Deserializer.hpp index b5de6a76d0..dda588d5e3 100644 --- a/src/armnnDeserializer/Deserializer.hpp +++ b/src/armnnDeserializer/Deserializer.hpp @@ -98,6 +98,7 @@ private: void ParseGreater(GraphPtr graph, unsigned int layerIndex); void ParseInstanceNormalization(GraphPtr graph, unsigned int layerIndex); void ParseL2Normalization(GraphPtr graph, unsigned int layerIndex); + void ParseLogSoftmax(GraphPtr graph, unsigned int layerIndex); void ParseMaximum(GraphPtr graph, unsigned int layerIndex); void ParseMean(GraphPtr graph, unsigned int layerIndex); void ParseMinimum(GraphPtr graph, unsigned int layerIndex); diff --git a/src/armnnDeserializer/DeserializerSupport.md b/src/armnnDeserializer/DeserializerSupport.md index 31b975f458..3b35e5c9f4 100644 --- a/src/armnnDeserializer/DeserializerSupport.md +++ b/src/armnnDeserializer/DeserializerSupport.md @@ -28,6 +28,7 @@ The Arm NN SDK Deserialize parser currently supports the following layers: * Input * InstanceNormalization * L2Normalization +* LogSoftmax * Lstm * Maximum * Mean diff --git a/src/armnnSerializer/ArmnnSchema.fbs b/src/armnnSerializer/ArmnnSchema.fbs index 7588b9d11e..187a091ba0 100644 --- a/src/armnnSerializer/ArmnnSchema.fbs +++ b/src/armnnSerializer/ArmnnSchema.fbs @@ -142,7 +142,8 @@ enum LayerType : uint { ArgMinMax = 47, Slice = 48, DepthToSpace = 49, - InstanceNormalization = 50 + InstanceNormalization = 50, + LogSoftmax = 51 } // Base layer table to be used as part of other layers @@ -273,6 +274,16 @@ table InstanceNormalizationDescriptor { dataLayout:DataLayout; } +table LogSoftmaxLayer { + base:LayerBase; + descriptor:LogSoftmaxDescriptor; +} + +table LogSoftmaxDescriptor { + beta:float = 1; + axis:int = -1; +} + table L2NormalizationLayer { base:LayerBase; descriptor:L2NormalizationDescriptor; @@ -748,7 +759,8 @@ union Layer { ArgMinMaxLayer, SliceLayer, DepthToSpaceLayer, - InstanceNormalizationLayer + InstanceNormalizationLayer, + LogSoftmaxLayer } table AnyLayer { diff --git a/src/armnnSerializer/Serializer.cpp b/src/armnnSerializer/Serializer.cpp index 0e8c894e46..11f833c5b7 100644 --- a/src/armnnSerializer/Serializer.cpp +++ b/src/armnnSerializer/Serializer.cpp @@ -467,7 +467,22 @@ void SerializerVisitor::VisitLogSoftmaxLayer(const armnn::IConnectableLayer* lay const armnn::LogSoftmaxDescriptor& logSoftmaxDescriptor, const char* name) { - throw armnn::UnimplementedException("SerializerVisitor::VisitLogSoftmaxLayer() is not implemented"); + // Create FlatBuffer BaseLayer + auto flatBufferLogSoftmaxBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_LogSoftmax); + + // Create the FlatBuffer LogSoftmaxDescriptor + auto flatBufferLogSoftmaxDesc = + serializer::CreateLogSoftmaxDescriptor(m_flatBufferBuilder, + logSoftmaxDescriptor.m_Beta, + logSoftmaxDescriptor.m_Axis); + + // Create the FlatBuffer LogSoftmaxLayer + auto flatBufferLogSoftmaxLayer = + serializer::CreateLogSoftmaxLayer(m_flatBufferBuilder, + flatBufferLogSoftmaxBaseLayer, + flatBufferLogSoftmaxDesc); + + CreateAnyLayer(flatBufferLogSoftmaxLayer.o, serializer::Layer::Layer_LogSoftmaxLayer); } void SerializerVisitor::VisitLstmLayer(const armnn::IConnectableLayer* layer, diff --git a/src/armnnSerializer/SerializerSupport.md b/src/armnnSerializer/SerializerSupport.md index e628253f19..2def918f21 100644 --- a/src/armnnSerializer/SerializerSupport.md +++ b/src/armnnSerializer/SerializerSupport.md @@ -28,6 +28,7 @@ The Arm NN SDK Serializer currently supports the following layers: * Input * InstanceNormalization * L2Normalization +* LogSoftmax * Lstm * Maximum * Mean diff --git a/src/armnnSerializer/test/SerializerTests.cpp b/src/armnnSerializer/test/SerializerTests.cpp index 98893a59cf..a70c891849 100644 --- a/src/armnnSerializer/test/SerializerTests.cpp +++ b/src/armnnSerializer/test/SerializerTests.cpp @@ -1437,6 +1437,61 @@ BOOST_AUTO_TEST_CASE(EnsureL2NormalizationBackwardCompatibility) deserializedNetwork->Accept(verifier); } +BOOST_AUTO_TEST_CASE(SerializeLogSoftmax) +{ + class LogSoftmaxLayerVerifier : public LayerVerifierBase + { + public: + LogSoftmaxLayerVerifier(const std::string& layerName, + const std::vector<armnn::TensorInfo>& inputInfos, + const std::vector<armnn::TensorInfo>& outputInfos, + const armnn::LogSoftmaxDescriptor& descriptor) + : LayerVerifierBase(layerName, inputInfos, outputInfos) + , m_Descriptor(descriptor) {} + + void VisitLogSoftmaxLayer(const armnn::IConnectableLayer* layer, + const armnn::LogSoftmaxDescriptor& descriptor, + const char* name) override + { + VerifyNameAndConnections(layer, name); + VerifyDescriptor(descriptor); + } + + private: + void VerifyDescriptor(const armnn::LogSoftmaxDescriptor& descriptor) + { + BOOST_TEST(descriptor.m_Beta == m_Descriptor.m_Beta); + BOOST_TEST(descriptor.m_Axis == m_Descriptor.m_Axis); + } + + armnn::LogSoftmaxDescriptor m_Descriptor; + }; + + const std::string layerName("log_softmax"); + const armnn::TensorInfo info({1, 10}, armnn::DataType::Float32); + + armnn::LogSoftmaxDescriptor descriptor; + descriptor.m_Beta = 1.0f; + descriptor.m_Axis = -1; + + armnn::INetworkPtr network = armnn::INetwork::Create(); + armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); + armnn::IConnectableLayer* const logSoftmaxLayer = network->AddLogSoftmaxLayer(descriptor, layerName.c_str()); + armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); + + inputLayer->GetOutputSlot(0).Connect(logSoftmaxLayer->GetInputSlot(0)); + logSoftmaxLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); + + inputLayer->GetOutputSlot(0).SetTensorInfo(info); + logSoftmaxLayer->GetOutputSlot(0).SetTensorInfo(info); + + armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); + BOOST_CHECK(deserializedNetwork); + + LogSoftmaxLayerVerifier verifier(layerName, {info}, {info}, descriptor); + deserializedNetwork->Accept(verifier); +} + BOOST_AUTO_TEST_CASE(SerializeMaximum) { class MaximumLayerVerifier : public LayerVerifierBase |