diff options
author | Sadik Armagan <sadik.armagan@arm.com> | 2019-10-14 13:00:47 +0100 |
---|---|---|
committer | Sadik Armagan <sadik.armagan@arm.com> | 2019-10-14 13:00:47 +0100 |
commit | 262578500338274b5fa0bcfeb2d72c13e717f4ff (patch) | |
tree | a7ec5fee3c7c8354540b61a37408865abfde0b5f /src/armnnSerializer | |
parent | c626345daafe9c0f49c88eb336d30bac5a58bf71 (diff) | |
download | armnn-262578500338274b5fa0bcfeb2d72c13e717f4ff.tar.gz |
IVGCVSW-3974 Add serialization support for LOG_SOFTMAX
Signed-off-by: Sadik Armagan <sadik.armagan@arm.com>
Change-Id: I0777abc672dd7d5c9fadaed27b0e776ac591d2c7
Diffstat (limited to 'src/armnnSerializer')
-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 |
4 files changed, 86 insertions, 3 deletions
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 |