IVGCVSW-4375 Add support for Transpose
* Added TransposeLayer
* Added CL, Neon and Ref Workloads
* Added Transpose utilities
* Added Serializer and Deserializer support
* Added Quantizer support
Signed-off-by: Mike Kelly <mike.kelly@arm.com>
Change-Id: I04c755ba7cb5b1edf72b3c9f3c0314878032e3c7
diff --git a/src/armnnSerializer/ArmnnSchema.fbs b/src/armnnSerializer/ArmnnSchema.fbs
index 0697517..d175d41 100644
--- a/src/armnnSerializer/ArmnnSchema.fbs
+++ b/src/armnnSerializer/ArmnnSchema.fbs
@@ -149,7 +149,8 @@
LogSoftmax = 51,
Comparison = 52,
StandIn = 53,
- ElementwiseUnary = 54
+ ElementwiseUnary = 54,
+ Transpose = 55
}
// Base layer table to be used as part of other layers
@@ -732,6 +733,15 @@
dataLayout:DataLayout = NCHW;
}
+table TransposeLayer {
+ base:LayerBase;
+ descriptor:TransposeDescriptor;
+}
+
+table TransposeDescriptor {
+ dimMappings:[uint];
+}
+
table ResizeLayer {
base:LayerBase;
descriptor:ResizeDescriptor;
@@ -820,7 +830,8 @@
LogSoftmaxLayer,
ComparisonLayer,
StandInLayer,
- ElementwiseUnaryLayer
+ ElementwiseUnaryLayer,
+ TransposeLayer
}
table AnyLayer {
diff --git a/src/armnnSerializer/Serializer.cpp b/src/armnnSerializer/Serializer.cpp
index 3c01842..a3fdcf8 100644
--- a/src/armnnSerializer/Serializer.cpp
+++ b/src/armnnSerializer/Serializer.cpp
@@ -1301,6 +1301,33 @@
CreateAnyLayer(fbLayer.o, serializer::Layer::Layer_TransposeConvolution2dLayer);
}
+void SerializerVisitor::VisitTransposeLayer(const armnn::IConnectableLayer* layer,
+ const armnn::TransposeDescriptor& descriptor,
+ const char* name)
+{
+ boost::ignore_unused(name);
+
+ // Create FlatBuffer BaseLayer
+ auto flatBufferBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Transpose);
+
+ std::vector<unsigned int> dimMappings;
+ for (unsigned int i=0; i<descriptor.m_DimMappings.GetSize(); ++i)
+ {
+ dimMappings.push_back(descriptor.m_DimMappings[i]);
+ }
+
+ auto flatBufferDesc = serializer::CreateTransposeDescriptor(m_flatBufferBuilder,
+ m_flatBufferBuilder.CreateVector(dimMappings));
+
+ // Create the FlatBuffer TransposeLayer
+ auto flatBufferLayer = serializer::CreateTransposeLayer(m_flatBufferBuilder,
+ flatBufferBaseLayer,
+ flatBufferDesc);
+
+ // Add the AnyLayer to the FlatBufferLayers
+ CreateAnyLayer(flatBufferLayer.o, serializer::Layer::Layer_TransposeLayer);
+}
+
void SerializerVisitor::VisitQuantizedLstmLayer(const armnn::IConnectableLayer* layer,
const armnn::QuantizedLstmInputParams& params,
const char* name)
diff --git a/src/armnnSerializer/Serializer.hpp b/src/armnnSerializer/Serializer.hpp
index 14d2776..737cf3b 100644
--- a/src/armnnSerializer/Serializer.hpp
+++ b/src/armnnSerializer/Serializer.hpp
@@ -270,6 +270,10 @@
const armnn::Optional<armnn::ConstTensor>& biases,
const char* = nullptr) override;
+ void VisitTransposeLayer(const armnn::IConnectableLayer* layer,
+ const armnn::TransposeDescriptor& descriptor,
+ const char* name = nullptr) override;
+
private:
/// Creates the Input Slots and Output Slots and LayerBase for the layer.
diff --git a/src/armnnSerializer/test/SerializerTests.cpp b/src/armnnSerializer/test/SerializerTests.cpp
index 47804fe..8c9c92b 100644
--- a/src/armnnSerializer/test/SerializerTests.cpp
+++ b/src/armnnSerializer/test/SerializerTests.cpp
@@ -2501,6 +2501,34 @@
deserializedNetwork->Accept(verifier);
}
+BOOST_AUTO_TEST_CASE(SerializeTranspose)
+{
+ DECLARE_LAYER_VERIFIER_CLASS_WITH_DESCRIPTOR(Transpose)
+
+ const std::string layerName("transpose");
+ const armnn::TensorInfo inputTensorInfo({4, 3, 2, 1}, armnn::DataType::Float32);
+ const armnn::TensorInfo outputTensorInfo({1, 2, 3, 4}, armnn::DataType::Float32);
+
+ armnn::TransposeDescriptor descriptor(armnn::PermutationVector({3, 2, 1, 0}));
+
+ armnn::INetworkPtr network = armnn::INetwork::Create();
+ armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0);
+ armnn::IConnectableLayer* const transposeLayer = network->AddTransposeLayer(descriptor, layerName.c_str());
+ armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0);
+
+ inputLayer->GetOutputSlot(0).Connect(transposeLayer->GetInputSlot(0));
+ transposeLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0));
+
+ inputLayer->GetOutputSlot(0).SetTensorInfo(inputTensorInfo);
+ transposeLayer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo);
+
+ armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network));
+ BOOST_CHECK(deserializedNetwork);
+
+ TransposeLayerVerifier verifier(layerName, {inputTensorInfo}, {outputTensorInfo}, descriptor);
+ deserializedNetwork->Accept(verifier);
+}
+
BOOST_AUTO_TEST_CASE(SerializeTransposeConvolution2d)
{
using Descriptor = armnn::TransposeConvolution2dDescriptor;