2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
6 #include <boost/test/unit_test.hpp>
7 #include "ParserFlatbuffersFixture.hpp"
8 #include "../TfLiteParser.hpp"
13 BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
15 struct ReshapeFixture : public ParserFlatbuffersFixture
17 explicit ReshapeFixture(const std::string& inputShape,
18 const std::string& outputShape,
19 const std::string& newShape)
24 "operator_codes": [ { "builtin_code": "RESHAPE" } ],
29 "shape" : )" + inputShape + ",";
33 "name": "inputTensor",
43 "shape" : )" + outputShape;
47 "name": "outputTensor",
63 "builtin_options_type": "ReshapeOptions",
64 "builtin_options": {)";
65 if (!newShape.empty())
67 m_JsonString += R"("new_shape" : )" + newShape;
70 "custom_options_format": "FLEXBUFFERS"
74 "buffers" : [ {}, {} ]
81 struct ReshapeFixtureWithReshapeDims : ReshapeFixture
83 ReshapeFixtureWithReshapeDims() : ReshapeFixture("[ 1, 9 ]", "[ 3, 3 ]", "[ 3, 3 ]") {}
86 BOOST_FIXTURE_TEST_CASE(ParseReshapeWithReshapeDims, ReshapeFixtureWithReshapeDims)
88 SetupSingleInputSingleOutput("inputTensor", "outputTensor");
89 RunTest<2, armnn::DataType::QuantisedAsymm8>(0,
90 { 1, 2, 3, 4, 5, 6, 7, 8, 9 },
91 { 1, 2, 3, 4, 5, 6, 7, 8, 9 });
92 BOOST_TEST((m_Parser->GetNetworkOutputBindingInfo(0, "outputTensor").second.GetShape()
93 == armnn::TensorShape({3,3})));
96 struct ReshapeFixtureWithReshapeDimsFlatten : ReshapeFixture
98 ReshapeFixtureWithReshapeDimsFlatten() : ReshapeFixture("[ 3, 3 ]", "[ 1, 9 ]", "[ -1 ]") {}
101 BOOST_FIXTURE_TEST_CASE(ParseReshapeWithReshapeDimsFlatten, ReshapeFixtureWithReshapeDimsFlatten)
103 SetupSingleInputSingleOutput("inputTensor", "outputTensor");
104 RunTest<2, armnn::DataType::QuantisedAsymm8>(0,
105 { 1, 2, 3, 4, 5, 6, 7, 8, 9 },
106 { 1, 2, 3, 4, 5, 6, 7, 8, 9 });
107 BOOST_TEST((m_Parser->GetNetworkOutputBindingInfo(0, "outputTensor").second.GetShape()
108 == armnn::TensorShape({1,9})));
111 struct ReshapeFixtureWithReshapeDimsFlattenTwoDims : ReshapeFixture
113 ReshapeFixtureWithReshapeDimsFlattenTwoDims() : ReshapeFixture("[ 3, 2, 3 ]", "[ 2, 9 ]", "[ 2, -1 ]") {}
116 BOOST_FIXTURE_TEST_CASE(ParseReshapeWithReshapeDimsFlattenTwoDims, ReshapeFixtureWithReshapeDimsFlattenTwoDims)
118 SetupSingleInputSingleOutput("inputTensor", "outputTensor");
119 RunTest<2, armnn::DataType::QuantisedAsymm8>(0,
120 { 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6 },
121 { 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6 });
122 BOOST_TEST((m_Parser->GetNetworkOutputBindingInfo(0, "outputTensor").second.GetShape()
123 == armnn::TensorShape({2,9})));
126 struct ReshapeFixtureWithReshapeDimsFlattenOneDim : ReshapeFixture
128 ReshapeFixtureWithReshapeDimsFlattenOneDim() : ReshapeFixture("[ 2, 9 ]", "[ 2, 3, 3 ]", "[ 2, -1, 3 ]") {}
131 BOOST_FIXTURE_TEST_CASE(ParseReshapeWithReshapeDimsFlattenOneDim, ReshapeFixtureWithReshapeDimsFlattenOneDim)
133 SetupSingleInputSingleOutput("inputTensor", "outputTensor");
134 RunTest<3, armnn::DataType::QuantisedAsymm8>(0,
135 { 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6 },
136 { 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6 });
137 BOOST_TEST((m_Parser->GetNetworkOutputBindingInfo(0, "outputTensor").second.GetShape()
138 == armnn::TensorShape({2,3,3})));
141 BOOST_AUTO_TEST_SUITE_END()