From 30b0020478652e441a5dff4880261f7c7007bb6c Mon Sep 17 00:00:00 2001 From: Nattapat Chaimanowong Date: Wed, 20 Feb 2019 17:31:34 +0000 Subject: IVGCVSW-2702 Add Serializer and Deserializer for Permute Change-Id: I56322cb935de42cfa25bd1fbb0c09d00c7a5dd2b Signed-off-by: Nattapat Chaimanowong --- src/armnnSerializer/Schema.fbs | 13 ++++++++++- src/armnnSerializer/Serializer.cpp | 25 ++++++++++++++++++++++ src/armnnSerializer/Serializer.hpp | 4 ++++ src/armnnSerializer/SerializerSupport.md | 3 ++- src/armnnSerializer/test/SerializerTests.cpp | 32 +++++++++++++++++++++++++++- 5 files changed, 74 insertions(+), 3 deletions(-) (limited to 'src/armnnSerializer') diff --git a/src/armnnSerializer/Schema.fbs b/src/armnnSerializer/Schema.fbs index e81365166f..94ca23b0cd 100644 --- a/src/armnnSerializer/Schema.fbs +++ b/src/armnnSerializer/Schema.fbs @@ -90,7 +90,8 @@ enum LayerType : uint { Softmax = 6, Convolution2d = 7, DepthwiseConvolution2d = 8, - Activation = 9 + Activation = 9, + Permute = 10 } // Base layer table to be used as part of other layers @@ -225,6 +226,15 @@ table ReshapeDescriptor { targetShape:[uint]; } +table PermuteLayer { + base:LayerBase; + descriptor:PermuteDescriptor; +} + +table PermuteDescriptor { + dimMappings:[uint]; +} + union Layer { ActivationLayer, AdditionLayer, @@ -233,6 +243,7 @@ union Layer { InputLayer, MultiplicationLayer, OutputLayer, + PermuteLayer, Pooling2dLayer, ReshapeLayer, SoftmaxLayer diff --git a/src/armnnSerializer/Serializer.cpp b/src/armnnSerializer/Serializer.cpp index bee1a3cdb5..e1d22ec406 100644 --- a/src/armnnSerializer/Serializer.cpp +++ b/src/armnnSerializer/Serializer.cpp @@ -226,6 +226,31 @@ void SerializerVisitor::VisitMultiplicationLayer(const armnn::IConnectableLayer* CreateAnyLayer(flatBufferMultiplicationLayer.o, serializer::Layer::Layer_MultiplicationLayer); } +void SerializerVisitor::VisitPermuteLayer(const armnn::IConnectableLayer* layer, + const armnn::PermuteDescriptor& permuteDescriptor, + const char* name) +{ + // Create FlatBuffer BaseLayer + auto flatBufferPermuteBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Permute); + + std::vector dimMappings; + for (auto& v: permuteDescriptor.m_DimMappings) + { + dimMappings.push_back(v); + } + + auto flatBufferPermuteDesc = serializer::CreatePermuteDescriptor(m_flatBufferBuilder, + m_flatBufferBuilder.CreateVector(dimMappings)); + + // Create the FlatBuffer PermuteLayer + auto flatBufferPermuteLayer = serializer::CreatePermuteLayer(m_flatBufferBuilder, + flatBufferPermuteBaseLayer, + flatBufferPermuteDesc); + + // Add the AnyLayer to the FlatBufferLayers + CreateAnyLayer(flatBufferPermuteLayer.o, serializer::Layer::Layer_PermuteLayer); +} + // Build FlatBuffer for Reshape Layer void SerializerVisitor::VisitReshapeLayer(const armnn::IConnectableLayer* layer, const armnn::ReshapeDescriptor& reshapeDescriptor, diff --git a/src/armnnSerializer/Serializer.hpp b/src/armnnSerializer/Serializer.hpp index 0c442e0788..329b005624 100644 --- a/src/armnnSerializer/Serializer.hpp +++ b/src/armnnSerializer/Serializer.hpp @@ -72,6 +72,10 @@ public: armnn::LayerBindingId id, const char* name = nullptr) override; + void VisitPermuteLayer(const armnn::IConnectableLayer* layer, + const armnn::PermuteDescriptor& PermuteDescriptor, + const char* name = nullptr) override; + void VisitPooling2dLayer(const armnn::IConnectableLayer* layer, const armnn::Pooling2dDescriptor& pooling2dDescriptor, const char* name = nullptr) override; diff --git a/src/armnnSerializer/SerializerSupport.md b/src/armnnSerializer/SerializerSupport.md index 0153669d59..180180a654 100644 --- a/src/armnnSerializer/SerializerSupport.md +++ b/src/armnnSerializer/SerializerSupport.md @@ -11,8 +11,9 @@ The Arm NN SDK Serializer currently supports the following layers: * DepthwiseConvolution2d * FullyConnected * Multiplication +* Permute * Pooling2d * Reshape * Softmax -More machine learning layers will be supported in future releases. \ No newline at end of file +More machine learning layers will be supported in future releases. diff --git a/src/armnnSerializer/test/SerializerTests.cpp b/src/armnnSerializer/test/SerializerTests.cpp index 7dad6accd0..c4c6eedb20 100644 --- a/src/armnnSerializer/test/SerializerTests.cpp +++ b/src/armnnSerializer/test/SerializerTests.cpp @@ -364,4 +364,34 @@ BOOST_AUTO_TEST_CASE(SerializeDeserializePooling2d) outputInfo.GetShape()); } -BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file +BOOST_AUTO_TEST_CASE(SerializeDeserializePermute) +{ + unsigned int inputShape[] = { 4, 3, 2, 1 }; + unsigned int outputShape[] = { 1, 2, 3, 4 }; + unsigned int dimsMapping[] = { 3, 2, 1, 0 }; + + auto inputTensorInfo = armnn::TensorInfo(4, inputShape, armnn::DataType::Float32); + auto outputTensorInfo = armnn::TensorInfo(4, outputShape, armnn::DataType::Float32); + + armnn::PermuteDescriptor permuteDescriptor(armnn::PermutationVector(dimsMapping, 4)); + + armnn::INetworkPtr network = armnn::INetwork::Create(); + armnn::IConnectableLayer *const inputLayer = network->AddInputLayer(0); + armnn::IConnectableLayer *const permuteLayer = network->AddPermuteLayer(permuteDescriptor, "PermuteLayer"); + armnn::IConnectableLayer *const outputLayer = network->AddOutputLayer(0); + + inputLayer->GetOutputSlot(0).Connect(permuteLayer->GetInputSlot(0)); + inputLayer->GetOutputSlot(0).SetTensorInfo(inputTensorInfo); + permuteLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); + permuteLayer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); + + armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); + BOOST_CHECK(deserializedNetwork); + + CheckDeserializedNetworkAgainstOriginal(*network, + *deserializedNetwork, + inputTensorInfo.GetShape(), + outputTensorInfo.GetShape()); +} + +BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.1