From bcca1f4a7ba8364f7b5e58e8e8866ccd7d530f92 Mon Sep 17 00:00:00 2001 From: Matthew Jackson Date: Tue, 16 Jul 2019 11:39:21 +0100 Subject: IVGCVSW-3423 Add TfLite parser support for Stack (Pack) layer * Added ParsePack method * New unit test Pack.cpp * Updated TensorFlowLiteSupport.md with new supported operator Signed-off-by: Matthew Jackson Change-Id: I2310b33ee26959b036bb4452a25c90cc1d4cbf20 --- src/armnnTfLiteParser/test/Pack.cpp | 153 ++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 src/armnnTfLiteParser/test/Pack.cpp (limited to 'src/armnnTfLiteParser/test') diff --git a/src/armnnTfLiteParser/test/Pack.cpp b/src/armnnTfLiteParser/test/Pack.cpp new file mode 100644 index 0000000000..011312f7c9 --- /dev/null +++ b/src/armnnTfLiteParser/test/Pack.cpp @@ -0,0 +1,153 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include +#include "ParserFlatbuffersFixture.hpp" +#include "../TfLiteParser.hpp" + +#include +#include + +BOOST_AUTO_TEST_SUITE(TensorflowLiteParser) + +struct PackFixture : public ParserFlatbuffersFixture +{ + explicit PackFixture(const std::string & inputShape, + const unsigned int numInputs, + const std::string & outputShape, + const std::string & axis) + { + m_JsonString = R"( + { + "version": 3, + "operator_codes": [ { "builtin_code": "PACK" } ], + "subgraphs": [ { + "tensors": [)"; + + for (unsigned int i = 0; i < numInputs; ++i) + { + m_JsonString += R"( + { + "shape": )" + inputShape + R"(, + "type": "FLOAT32", + "buffer": )" + std::to_string(i) + R"(, + "name": "inputTensor)" + std::to_string(i + 1) + R"(", + "quantization": { + "min": [ 0.0 ], + "max": [ 255.0 ], + "scale": [ 1.0 ], + "zero_point": [ 0 ], + } + },)"; + } + + std::string inputIndexes; + for (unsigned int i = 0; i < numInputs-1; ++i) + { + inputIndexes += std::to_string(i) + R"(, )"; + } + inputIndexes += std::to_string(numInputs-1); + + m_JsonString += R"( + { + "shape": )" + outputShape + R"( , + "type": "FLOAT32", + "buffer": )" + std::to_string(numInputs) + R"(, + "name": "outputTensor", + "quantization": { + "min": [ 0.0 ], + "max": [ 255.0 ], + "scale": [ 1.0 ], + "zero_point": [ 0 ], + } + } + ], + "inputs": [ )" + inputIndexes + R"( ], + "outputs": [ 2 ], + "operators": [ + { + "opcode_index": 0, + "inputs": [ )" + inputIndexes + R"( ], + "outputs": [ 2 ], + "builtin_options_type": "PackOptions", + "builtin_options": { + "axis": )" + axis + R"(, + "values_count": )" + std::to_string(numInputs) + R"( + }, + "custom_options_format": "FLEXBUFFERS" + } + ], + } ], + "buffers" : [)"; + + for (unsigned int i = 0; i < numInputs-1; ++i) + { + m_JsonString += R"( + { },)"; + } + m_JsonString += R"( + { } + ] + })"; + Setup(); + } +}; + +struct SimplePackFixture : PackFixture +{ + SimplePackFixture() : PackFixture("[ 3, 2, 3 ]", + 2, + "[ 3, 2, 3, 2 ]", + "3") {} +}; + +BOOST_FIXTURE_TEST_CASE(ParsePack, SimplePackFixture) +{ + RunTest<4, armnn::DataType::Float32>( + 0, + { {"inputTensor1", { 1, 2, 3, + 4, 5, 6, + + 7, 8, 9, + 10, 11, 12, + + 13, 14, 15, + 16, 17, 18 } }, + {"inputTensor2", { 19, 20, 21, + 22, 23, 24, + + 25, 26, 27, + 28, 29, 30, + + 31, 32, 33, + 34, 35, 36 } } }, + { {"outputTensor", { 1, 19, + 2, 20, + 3, 21, + + 4, 22, + 5, 23, + 6, 24, + + + 7, 25, + 8, 26, + 9, 27, + + 10, 28, + 11, 29, + 12, 30, + + + 13, 31, + 14, 32, + 15, 33, + + 16, 34, + 17, 35, + 18, 36 } } }); +} + +BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.1