From 3ab85485968c0e70d0378de3243119fb7b2f7e94 Mon Sep 17 00:00:00 2001 From: Teresa Charlin Date: Tue, 8 Jun 2021 16:59:29 +0100 Subject: IVGCVSW-6075 Add ParseExpandDims to TfliteParser * Add ExpandDims tests in tfliteparser * Add support for negative axis to squeeze Signed-off-by: Teresa Charlin Signed-off-by: Finn Williams Change-Id: I604c9b4ac6514895e9e3d4d85c2937e797d288e0 --- src/armnnTfLiteParser/test/ExpandDims.cpp | 106 ++++++++++++++++++++++++++++++ src/armnnTfLiteParser/test/Squeeze.cpp | 40 +++++++++-- 2 files changed, 141 insertions(+), 5 deletions(-) create mode 100644 src/armnnTfLiteParser/test/ExpandDims.cpp (limited to 'src/armnnTfLiteParser/test') diff --git a/src/armnnTfLiteParser/test/ExpandDims.cpp b/src/armnnTfLiteParser/test/ExpandDims.cpp new file mode 100644 index 0000000000..a9f021f76e --- /dev/null +++ b/src/armnnTfLiteParser/test/ExpandDims.cpp @@ -0,0 +1,106 @@ +// +// Copyright © 2021 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// +#include "ParserFlatbuffersFixture.hpp" +#include "../TfLiteParser.hpp" + +#include +#include + +TEST_SUITE("TensorflowLiteParser_ExpandDims") +{ +struct ExpandDimsFixture : public ParserFlatbuffersFixture +{ + explicit ExpandDimsFixture(const std::string& inputShape, + const std::string& outputShape, + const std::string& axis) + { + m_JsonString = R"( + { + "version": 3, + "operator_codes": [ { "builtin_code": "EXPAND_DIMS" } ], + "subgraphs": [ { + "tensors": [ + { + "shape": )" + inputShape + R"(, + "type": "UINT8", + "buffer": 0, + "name": "inputTensor", + "quantization": { + "min": [ 0.0 ], + "max": [ 255.0 ], + "scale": [ 1.0 ], + "zero_point": [ 0 ], + } + }, + { + "shape": )" + outputShape + R"( , + "type": "UINT8", + "buffer": 1, + "name": "outputTensor", + "quantization": { + "min": [ 0.0 ], + "max": [ 255.0 ], + "scale": [ 1.0 ], + "zero_point": [ 0 ], + } + }, + { + "shape": [ 1 ], + "type": "UINT8", + "buffer": 2, + "name": "expand_dims", + "quantization": { + "min": [ 0.0 ], + "max": [ 255.0 ], + "scale": [ 1.0 ], + "zero_point": [ 0 ], + } + }, + ], + "inputs": [ 0 ], + "outputs": [ 1 ], + "operators": [ + { + "opcode_index": 0, + "inputs": [ 0 , 2 ], + "outputs": [ 1 ], + "custom_options_format": "FLEXBUFFERS" + } + ], + } ], + "buffers" : [ + { }, + { }, + { "data": )" + axis + R"(, }, + ] + } + )"; + SetupSingleInputSingleOutput("inputTensor", "outputTensor"); + } +}; + +struct ExpandDimsFixture3dto4Daxis0 : ExpandDimsFixture +{ + ExpandDimsFixture3dto4Daxis0() : ExpandDimsFixture("[ 2, 2, 1 ]", "[ 1, 2, 2, 1 ]", "[ 0, 0, 0, 0 ]") {} +}; + +TEST_CASE_FIXTURE(ExpandDimsFixture3dto4Daxis0, "ParseExpandDims3Dto4Daxis0") +{ + RunTest<4, armnn::DataType::QAsymmU8>(0, {{ "inputTensor", { 1, 2, 3, 4 } } }, + {{ "outputTensor", { 1, 2, 3, 4 } } }); +} + +struct ExpandDimsFixture3dto4Daxis3 : ExpandDimsFixture +{ + ExpandDimsFixture3dto4Daxis3() : ExpandDimsFixture("[ 1, 2, 2 ]", "[ 1, 2, 2, 1 ]", "[ 3, 0, 0, 0 ]") {} +}; + +TEST_CASE_FIXTURE(ExpandDimsFixture3dto4Daxis3, "ParseExpandDims3Dto4Daxis3") +{ + RunTest<4, armnn::DataType::QAsymmU8>(0, {{ "inputTensor", { 1, 2, 3, 4 } } }, + {{ "outputTensor", { 1, 2, 3, 4 } } }); +} + +} \ No newline at end of file diff --git a/src/armnnTfLiteParser/test/Squeeze.cpp b/src/armnnTfLiteParser/test/Squeeze.cpp index da870fd4c9..6f533ba4ff 100644 --- a/src/armnnTfLiteParser/test/Squeeze.cpp +++ b/src/armnnTfLiteParser/test/Squeeze.cpp @@ -128,14 +128,44 @@ TEST_CASE_FIXTURE(SqueezeFixtureWithSqueezeDimsSizeInvalid, "ParseSqueezeInvalid } -struct SqueezeFixtureWithNegativeSqueezeDims : SqueezeFixture +struct SqueezeFixtureWithNegativeSqueezeDims1 : SqueezeFixture { - SqueezeFixtureWithNegativeSqueezeDims() : SqueezeFixture("[ 1, 2, 2, 1 ]", - "[ 1, 2, 2, 1 ]", - "[ -2 , 2 ]") {} + SqueezeFixtureWithNegativeSqueezeDims1() : SqueezeFixture("[ 1, 2, 2, 1 ]", + "[ 2, 2, 1 ]", + "[ -1 ]") {} }; -TEST_CASE_FIXTURE(SqueezeFixtureWithNegativeSqueezeDims, "ParseSqueezeNegativeSqueezeDims") +TEST_CASE_FIXTURE(SqueezeFixtureWithNegativeSqueezeDims1, "ParseSqueezeNegativeSqueezeDims1") +{ + SetupSingleInputSingleOutput("inputTensor", "outputTensor"); + RunTest<3, armnn::DataType::QAsymmU8>(0, { 1, 2, 3, 4 }, { 1, 2, 3, 4 }); + CHECK((m_Parser->GetNetworkOutputBindingInfo(0, "outputTensor").second.GetShape() + == armnn::TensorShape({ 2, 2, 1 }))); +} + +struct SqueezeFixtureWithNegativeSqueezeDims2 : SqueezeFixture +{ + SqueezeFixtureWithNegativeSqueezeDims2() : SqueezeFixture("[ 1, 2, 2, 1 ]", + "[ 1, 2, 2 ]", + "[ -1 ]") {} +}; + +TEST_CASE_FIXTURE(SqueezeFixtureWithNegativeSqueezeDims2, "ParseSqueezeNegativeSqueezeDims2") +{ + SetupSingleInputSingleOutput("inputTensor", "outputTensor"); + RunTest<3, armnn::DataType::QAsymmU8>(0, { 1, 2, 3, 4 }, { 1, 2, 3, 4 }); + CHECK((m_Parser->GetNetworkOutputBindingInfo(0, "outputTensor").second.GetShape() + == armnn::TensorShape({ 1, 2, 2 }))); +} + +struct SqueezeFixtureWithNegativeSqueezeDimsInvalid : SqueezeFixture +{ + SqueezeFixtureWithNegativeSqueezeDimsInvalid() : SqueezeFixture("[ 1, 2, 2, 1 ]", + "[ 1, 2, 2, 1 ]", + "[ -2 , 2 ]") {} +}; + +TEST_CASE_FIXTURE(SqueezeFixtureWithNegativeSqueezeDimsInvalid, "ParseSqueezeNegativeSqueezeDimsInvalid") { CHECK_THROWS_AS((SetupSingleInputSingleOutput("inputTensor", "outputTensor")), armnn::ParseException); } -- cgit v1.2.1