From d109a4d0fb980f2e97c05cd86451eda0b53f37ef Mon Sep 17 00:00:00 2001 From: Sadik Armagan Date: Tue, 28 Jul 2020 10:42:13 +0100 Subject: IVGCVSW-4932 Introduce ShapeInferenceMethod to TfLite Parser * Introduced ShapeInferenceMethod::InferAndValidate to TfLiteParser * Added unit tests Signed-off-by: Sadik Armagan Change-Id: Iad4aadce92912e7645b1652019ec4af478b7fc32 --- src/armnnTfLiteParser/test/Conv2D.cpp | 26 ++++++++++++++++++++++ .../test/DepthwiseConvolution2D.cpp | 26 ++++++++++++++++++++++ src/armnnTfLiteParser/test/Div.cpp | 26 ++++++++++++++++++++++ src/armnnTfLiteParser/test/FullyConnected.cpp | 24 ++++++++++++++++++++ .../test/ParserFlatbuffersFixture.hpp | 11 +++++---- src/armnnTfLiteParser/test/Reshape.cpp | 18 +++++++++++++++ src/armnnTfLiteParser/test/Slice.cpp | 17 ++++++++++++++ src/armnnTfLiteParser/test/Sub.cpp | 17 ++++++++++++++ 8 files changed, 161 insertions(+), 4 deletions(-) (limited to 'src/armnnTfLiteParser/test') diff --git a/src/armnnTfLiteParser/test/Conv2D.cpp b/src/armnnTfLiteParser/test/Conv2D.cpp index 2eae5f5a1a..8ef827ce7f 100644 --- a/src/armnnTfLiteParser/test/Conv2D.cpp +++ b/src/armnnTfLiteParser/test/Conv2D.cpp @@ -234,6 +234,32 @@ BOOST_FIXTURE_TEST_CASE( ParseConv2DWithBias, SimpleConv2DWithBiasesFixture ) }); } +struct DynamicConv2DWithBiasesFixture : Conv2DWithBiasesFixture +{ + DynamicConv2DWithBiasesFixture() + : Conv2DWithBiasesFixture("[ 1, 2, 2, 1 ]", // inputShape + "[ ]", // outputShape + "[ 1, 2, 2, 1 ]", // filterShape + "[ 2,1, 0,6 ]", // filterData + "[ 1 ]", // biasShape + "[ 10, 0, 0, 0 ]", // biasData + "1") // stride w and h + {} +}; + +BOOST_FIXTURE_TEST_CASE( ParseDynamicConv2DWithBias, DynamicConv2DWithBiasesFixture ) +{ + RunTest<4, + armnn::DataType::QAsymmU8, + armnn::DataType::QAsymmU8>(0, + { { "inputTensor", { 1, 2, 3, 4, } } }, + { { "outputTensor", { (1*2 + 2*1 + 3*0 + 4*6 + 10)/2, + (2*2 + 0*1 + 4*0 + 0*6 + 10)/2, + (3*2 + 4*1 + 0*0 + 0*6 + 10)/2, + (4*2 + 0*1 + 0*0 + 0*6 + 10)/2} } }, + true); +} + struct Conv2DShapeTestFixture : Conv2DWithBiasesFixture { static std::string GenerateInts(unsigned int n) diff --git a/src/armnnTfLiteParser/test/DepthwiseConvolution2D.cpp b/src/armnnTfLiteParser/test/DepthwiseConvolution2D.cpp index 2bf08fa79f..5d220ebf23 100644 --- a/src/armnnTfLiteParser/test/DepthwiseConvolution2D.cpp +++ b/src/armnnTfLiteParser/test/DepthwiseConvolution2D.cpp @@ -196,4 +196,30 @@ BOOST_FIXTURE_TEST_CASE(ParseDepthwiseConv2DSameBias, DepthwiseConvolution2dSame (110+10)/2, (197+10)/2, (158+10)/2 }); } +struct DynamicDepthwiseConvolution2dSameBiasFixture : DepthwiseConvolution2dFixture +{ + DynamicDepthwiseConvolution2dSameBiasFixture() + : DepthwiseConvolution2dFixture("[ 1, 3, 3, 1 ]", // inputShape + "[ ]", // outputShape + "[ 1, 3, 3, 1 ]", // filterShape + "[ 9,8,7, 6,5,4, 3,2,1 ]", // filterData + "1", // stride w and h + "SAME", // padding type + "[ 1 ]", // biasShape + "[ 10, 0, 0, 0 ]") // biasData + {} +}; + +BOOST_FIXTURE_TEST_CASE(ParseDynamicDepthwiseConv2DSameBias, DynamicDepthwiseConvolution2dSameBiasFixture) +{ + RunTest<4, armnn::DataType::QAsymmU8, armnn::DataType::QAsymmU8>(0, + { { "inputTensor", { 0, 1, 2, + 3, 4, 5, + 6, 7, 8 } } }, + { { "outputTensor", { ( 14+10)/2, ( 35+10)/2, ( 38+10)/2, + ( 57+10)/2, (120+10)/2, (111+10)/2, + (110+10)/2, (197+10)/2, (158+10)/2 } } }, + true); +} + BOOST_AUTO_TEST_SUITE_END() diff --git a/src/armnnTfLiteParser/test/Div.cpp b/src/armnnTfLiteParser/test/Div.cpp index f83e455a56..10be29d755 100644 --- a/src/armnnTfLiteParser/test/Div.cpp +++ b/src/armnnTfLiteParser/test/Div.cpp @@ -112,4 +112,30 @@ BOOST_FIXTURE_TEST_CASE(ParseDiv, SimpleDivFixture) 1.0f, 1.0f, -1.0f } } }); } + +struct DynamicDivFixture : public DivFixture +{ + DynamicDivFixture() : DivFixture("[ 1, 2, 2, 3 ]", "[ 1, 2, 2, 3 ]", "[ ]") {} +}; + +BOOST_FIXTURE_TEST_CASE(ParseDynamicDiv, DynamicDivFixture) +{ + using armnn::DataType; + float Inf = std::numeric_limits::infinity(); + float NaN = std::numeric_limits::quiet_NaN(); + + RunTest<4, DataType::Float32, DataType::Float32>(0, {{ "inputTensor1", { 0.0f, 1.0f, 2.0f, + 3.0f, 4.0f, 5.0f, + 6.0f, 7.0f, 8.0f, + 9.0f, 10.0f, -11.0f } }, + { "inputTensor2", { 0.0f, 0.0f, 4.0f, + 3.0f, 40.0f, 5.0f, + 6.0f, 7.0f, 8.0f, + 9.0f, 10.0f, 11.0f} } }, + {{ "outputTensor", { NaN, Inf, 0.5f, + 1.0f, 0.1f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, -1.0f } } }, true); +} + BOOST_AUTO_TEST_SUITE_END() diff --git a/src/armnnTfLiteParser/test/FullyConnected.cpp b/src/armnnTfLiteParser/test/FullyConnected.cpp index d1223d5af2..e7aa9082e2 100644 --- a/src/armnnTfLiteParser/test/FullyConnected.cpp +++ b/src/armnnTfLiteParser/test/FullyConnected.cpp @@ -171,4 +171,28 @@ BOOST_FIXTURE_TEST_CASE(FullyConnectedWithBiasMultipleOutputs, FullyConnectedWit { (40+10)/2, (400+10)/2 }); } +struct DynamicFullyConnectedWithBiasMultipleOutputsFixture : FullyConnectedFixture +{ + DynamicFullyConnectedWithBiasMultipleOutputsFixture() + : FullyConnectedFixture("[ 1, 4, 2, 1 ]", // inputShape + "[ ]", // outputShape + "[ 1, 4 ]", // filterShape + "[ 2, 3, 4, 5 ]", // filterData + "[ 1 ]", // biasShape + "[ 10, 0, 0, 0 ]" ) // biasData + { } +}; + +BOOST_FIXTURE_TEST_CASE( + DynamicFullyConnectedWithBiasMultipleOutputs, + DynamicFullyConnectedWithBiasMultipleOutputsFixture) +{ + RunTest<2, + armnn::DataType::QAsymmU8, + armnn::DataType::QAsymmU8>(0, + { { "inputTensor", { 1, 2, 3, 4, 10, 20, 30, 40} } }, + { { "outputTensor", { (40+10)/2, (400+10)/2 } } }, + true); +} + BOOST_AUTO_TEST_SUITE_END() diff --git a/src/armnnTfLiteParser/test/ParserFlatbuffersFixture.hpp b/src/armnnTfLiteParser/test/ParserFlatbuffersFixture.hpp index 891e0be499..f2f723b5d5 100644 --- a/src/armnnTfLiteParser/test/ParserFlatbuffersFixture.hpp +++ b/src/armnnTfLiteParser/test/ParserFlatbuffersFixture.hpp @@ -42,6 +42,7 @@ struct ParserFlatbuffersFixture { ITfLiteParser::TfLiteParserOptions options; options.m_StandInLayerForUnsupported = true; + options.m_InferAndValidate = true; m_Parser.reset(ITfLiteParser::CreateRaw(armnn::Optional(options))); } @@ -149,7 +150,8 @@ struct ParserFlatbuffersFixture armnn::DataType ArmnnType2> void RunTest(size_t subgraphId, const std::map>>& inputData, - const std::map>>& expectedOutputData); + const std::map>>& expectedOutputData, + bool isDynamic = false); /// Multiple Inputs, Multiple Outputs w/ Variable Datatypes and different dimension sizes. @@ -248,7 +250,8 @@ template void ParserFlatbuffersFixture::RunTest(size_t subgraphId, const std::map>>& inputData, - const std::map>>& expectedOutputData) + const std::map>>& expectedOutputData, + bool isDynamic) { using DataType2 = armnn::ResolveType; @@ -289,8 +292,8 @@ void ParserFlatbuffersFixture::RunTest(size_t subgraphId, for (auto&& it : expectedOutputData) { armnn::BindingPointInfo bindingInfo = m_Parser->GetNetworkOutputBindingInfo(subgraphId, it.first); - auto outputExpected = MakeTensor(bindingInfo.second, it.second); - BOOST_TEST(CompareTensors(outputExpected, outputStorage[it.first])); + auto outputExpected = MakeTensor(bindingInfo.second, it.second, isDynamic); + BOOST_TEST(CompareTensors(outputExpected, outputStorage[it.first], false, isDynamic)); } } diff --git a/src/armnnTfLiteParser/test/Reshape.cpp b/src/armnnTfLiteParser/test/Reshape.cpp index 6ed568ceff..025612f097 100644 --- a/src/armnnTfLiteParser/test/Reshape.cpp +++ b/src/armnnTfLiteParser/test/Reshape.cpp @@ -138,4 +138,22 @@ BOOST_FIXTURE_TEST_CASE(ParseReshapeWithReshapeDimsFlattenOneDim, ReshapeFixture == armnn::TensorShape({2,3,3}))); } +struct DynamicReshapeFixtureWithReshapeDimsFlattenOneDim : ReshapeFixture +{ + DynamicReshapeFixtureWithReshapeDimsFlattenOneDim() : ReshapeFixture("[ 2, 9 ]", + "[ ]", + "[ 2, -1, 3 ]") {} +}; + +BOOST_FIXTURE_TEST_CASE(DynParseReshapeWithReshapeDimsFlattenOneDim, DynamicReshapeFixtureWithReshapeDimsFlattenOneDim) +{ + SetupSingleInputSingleOutput("inputTensor", "outputTensor"); + RunTest<3, + armnn::DataType::QAsymmU8, + armnn::DataType::QAsymmU8>(0, + { { "inputTensor", { 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6 } } }, + { { "outputTensor", { 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6 } } }, + true); +} + BOOST_AUTO_TEST_SUITE_END() diff --git a/src/armnnTfLiteParser/test/Slice.cpp b/src/armnnTfLiteParser/test/Slice.cpp index 17d1b1a68c..b94a9832b7 100644 --- a/src/armnnTfLiteParser/test/Slice.cpp +++ b/src/armnnTfLiteParser/test/Slice.cpp @@ -173,4 +173,21 @@ BOOST_FIXTURE_TEST_CASE(SliceD213, SliceFixtureD213) == armnn::TensorShape({2,1,3}))); } +struct DynamicSliceFixtureD213 : SliceFixture +{ + DynamicSliceFixtureD213() : SliceFixture("[ 3, 2, 3 ]", + "[ ]", + "[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]", + "[ 2, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0 ]") {} +}; + +BOOST_FIXTURE_TEST_CASE(DynamicSliceD213, DynamicSliceFixtureD213) +{ + RunTest<3, armnn::DataType::Float32, armnn::DataType::Float32>( + 0, + {{"inputTensor", { 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6 }}}, + {{"outputTensor", { 3, 3, 3, 5, 5, 5 }}}, + true); +} + BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/src/armnnTfLiteParser/test/Sub.cpp b/src/armnnTfLiteParser/test/Sub.cpp index 6a251a5f74..2854d81197 100644 --- a/src/armnnTfLiteParser/test/Sub.cpp +++ b/src/armnnTfLiteParser/test/Sub.cpp @@ -104,4 +104,21 @@ BOOST_FIXTURE_TEST_CASE(SimpleSub, SimpleSubFixture) {{"outputTensor", { 1, 3, 5, 7 }}}); } +struct DynamicSubFixture : SubFixture +{ + DynamicSubFixture() : SubFixture("[ 1, 4 ]", + "[ 1, 4 ]", + "[ ]") {} +}; + +BOOST_FIXTURE_TEST_CASE(DynamicSub, DynamicSubFixture) +{ + RunTest<2, armnn::DataType::QAsymmU8, armnn::DataType::QAsymmU8>( + 0, + {{"inputTensor1", { 4, 5, 6, 7 }}, + {"inputTensor2", { 3, 2, 1, 0 }}}, + {{"outputTensor", { 1, 3, 5, 7 }}}, + true); +} + BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.1