aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKeith Davis <keith.davis@arm.com>2019-09-09 14:49:20 +0100
committerKeith Davis <keith.davis@arm.com>2019-09-10 17:37:25 +0100
commit4cd29a046c3d46917d84d12feb668969af23a39e (patch)
treec92f0ef33c640b60c5527ea89d949e5f386aded1 /src
parent501a97624e8585700a1aecd5e3133b8c3b823e62 (diff)
downloadarmnn-4cd29a046c3d46917d84d12feb668969af23a39e.tar.gz
IVGCVSW-3712 Add Transpose into TfLite Parser
Signed-off-by: Keith Davis <keith.davis@arm.com> Change-Id: I94e975ede3876c812f0f26b040e8c50a5597f86a
Diffstat (limited to 'src')
-rw-r--r--src/armnnTfLiteParser/TensorFlowLiteSupport.md2
-rw-r--r--src/armnnTfLiteParser/TfLiteParser.cpp30
-rw-r--r--src/armnnTfLiteParser/TfLiteParser.hpp1
-rw-r--r--src/armnnTfLiteParser/test/Transpose.cpp125
4 files changed, 158 insertions, 0 deletions
diff --git a/src/armnnTfLiteParser/TensorFlowLiteSupport.md b/src/armnnTfLiteParser/TensorFlowLiteSupport.md
index de4887e263..7fa299ebf8 100644
--- a/src/armnnTfLiteParser/TensorFlowLiteSupport.md
+++ b/src/armnnTfLiteParser/TensorFlowLiteSupport.md
@@ -60,6 +60,8 @@ The Arm NN SDK TensorFlow Lite parser currently supports the following operators
* TANH
+* TRANSPOSE
+
* TRANSPOSE_CONV
* UNPACK
diff --git a/src/armnnTfLiteParser/TfLiteParser.cpp b/src/armnnTfLiteParser/TfLiteParser.cpp
index d1cef31446..939640a5e3 100644
--- a/src/armnnTfLiteParser/TfLiteParser.cpp
+++ b/src/armnnTfLiteParser/TfLiteParser.cpp
@@ -460,6 +460,7 @@ TfLiteParser::TfLiteParser()
m_ParserFunctions[tflite::BuiltinOperator_PAD] = &TfLiteParser::ParsePad;
m_ParserFunctions[tflite::BuiltinOperator_SPLIT] = &TfLiteParser::ParseSplit;
m_ParserFunctions[tflite::BuiltinOperator_TANH] = &TfLiteParser::ParseTanH;
+ m_ParserFunctions[tflite::BuiltinOperator_TRANSPOSE] = &TfLiteParser::ParseTranspose;
m_ParserFunctions[tflite::BuiltinOperator_TRANSPOSE_CONV] = &TfLiteParser::ParseTransposeConv;
m_ParserFunctions[tflite::BuiltinOperator_UNPACK] = &TfLiteParser::ParseUnpack;
}
@@ -865,6 +866,35 @@ void TfLiteParser::ParseDepthwiseConv2D(size_t subgraphIndex, size_t operatorInd
RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
}
+void TfLiteParser::ParseTranspose(size_t subgraphIndex, size_t operatorIndex)
+{
+ CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
+
+ auto inputs = GetInputs(m_Model, subgraphIndex, operatorIndex);
+ CHECK_VALID_SIZE(inputs.size(), 2);
+
+ auto outputs = GetOutputs(m_Model, subgraphIndex, operatorIndex);
+ CHECK_VALID_SIZE(outputs.size(), 1);
+
+ armnn::IConnectableLayer* layer = nullptr;
+ auto layerName = boost::str(boost::format("Transpose:%1%:%2%") % subgraphIndex % operatorIndex);
+
+ PermuteDescriptor desc;
+
+ layer = m_Network->AddPermuteLayer(desc, layerName.c_str());
+
+ BOOST_ASSERT(layer != nullptr);
+
+ armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]);
+ layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo);
+
+ auto inputTensorIndexes = AsUnsignedVector(GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
+ RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
+
+ auto outputTensorIndexes = AsUnsignedVector(GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
+ RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
+}
+
void TfLiteParser::ParseTransposeConv(size_t subgraphIndex, size_t operatorIndex)
{
CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
diff --git a/src/armnnTfLiteParser/TfLiteParser.hpp b/src/armnnTfLiteParser/TfLiteParser.hpp
index dc0d6344f8..fac2599322 100644
--- a/src/armnnTfLiteParser/TfLiteParser.hpp
+++ b/src/armnnTfLiteParser/TfLiteParser.hpp
@@ -120,6 +120,7 @@ private:
void ParseStridedSlice(size_t subgraphIndex, size_t operatorIndex);
void ParseSub(size_t subgraphIndex, size_t operatorIndex);
void ParseTanH(size_t subgraphIndex, size_t operatorIndex);
+ void ParseTranspose(size_t subgraphIndex, size_t operatorIndex);
void ParseTransposeConv(size_t subgraphIndex, size_t operatorIndex);
void ParseUnpack(size_t subgraphIndex, size_t operatorIndex);
diff --git a/src/armnnTfLiteParser/test/Transpose.cpp b/src/armnnTfLiteParser/test/Transpose.cpp
new file mode 100644
index 0000000000..4430438bb9
--- /dev/null
+++ b/src/armnnTfLiteParser/test/Transpose.cpp
@@ -0,0 +1,125 @@
+//
+// Copyright © 2019 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include <boost/test/unit_test.hpp>
+#include "ParserFlatbuffersFixture.hpp"
+#include "../TfLiteParser.hpp"
+
+BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
+
+struct TransposeFixture : public ParserFlatbuffersFixture
+{
+ explicit TransposeFixture(const std::string & inputShape,
+ const std::string & outputShape)
+ {
+ m_JsonString = R"(
+ {
+ "version": 3,
+ "operator_codes": [
+ {
+ "builtin_code": "TRANSPOSE",
+ "version": 1
+ }
+ ],
+ "subgraphs": [
+ {
+ "tensors": [
+ {
+ "shape": )" + inputShape + R"(,
+ "type": "FLOAT32",
+ "buffer": 3,
+ "name": "Placeholder",
+ "quantization": {
+ "min": [
+ 0.0
+ ],
+ "max": [
+ 255.0
+ ],
+ "details_type": 0,
+ "quantized_dimension": 0
+ },
+ "is_variable": false
+ },
+ {
+ "shape": )" + outputShape + R"(,
+ "type": "FLOAT32",
+ "buffer": 2,
+ "name": "transpose",
+ "quantization": {
+ "details_type": 0,
+ "quantized_dimension": 0
+ },
+ "is_variable": false
+ },
+ {
+ "shape": [
+ 3
+ ],
+ "type": "INT32",
+ "buffer": 1,
+ "name": "transpose/perm",
+ "quantization": {
+ "details_type": 0,
+ "quantized_dimension": 0
+ },
+ "is_variable": false
+ }
+ ],
+ "inputs": [
+ 0
+ ],
+ "outputs": [
+ 1
+ ],
+ "operators": [
+ {
+ "opcode_index": 0,
+ "inputs": [
+ 0,
+ 2
+ ],
+ "outputs": [
+ 1
+ ],
+ "builtin_options_type": "TransposeOptions",
+ "builtin_options": {
+ },
+ "custom_options_format": "FLEXBUFFERS"
+ }
+ ]
+ }
+ ],
+ "description": "TOCO Converted.",
+ "buffers": [
+ { },
+ { },
+ { },
+ { }
+ ]
+ }
+ )";
+ Setup();
+ }
+};
+
+struct SimpleTransposeFixture : TransposeFixture
+{
+ SimpleTransposeFixture() : TransposeFixture("[ 2, 2, 3 ]",
+ "[ 2, 3, 2 ]") {}
+};
+
+BOOST_FIXTURE_TEST_CASE(SimpleTranspose, SimpleTransposeFixture)
+{
+ RunTest<3, armnn::DataType::Float32>(
+ 0,
+ {{"Placeholder", { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }}},
+
+ {{"transpose", { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }}});
+ BOOST_TEST((m_Parser->GetNetworkOutputBindingInfo(0, "transpose").second.GetShape()
+ == armnn::TensorShape({2,3,2})));
+}
+
+BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file