blob: 860c5eea6577fb21626009b707c51b211e2785e0 [file] [log] [blame]
telsoa01c577f2c2018-08-31 09:22:23 +01001//
Finn Williamsb49ed182021-06-29 15:50:08 +01002// Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa01c577f2c2018-08-31 09:22:23 +01004//
5
telsoa01c577f2c2018-08-31 09:22:23 +01006#include "ParserFlatbuffersFixture.hpp"
telsoa01c577f2c2018-08-31 09:22:23 +01007
telsoa01c577f2c2018-08-31 09:22:23 +01008
Sadik Armagan1625efc2021-06-10 18:24:34 +01009TEST_SUITE("TensorflowLiteParser_Squeeze")
10{
telsoa01c577f2c2018-08-31 09:22:23 +010011struct SqueezeFixture : public ParserFlatbuffersFixture
12{
13 explicit SqueezeFixture(const std::string& inputShape,
14 const std::string& outputShape,
15 const std::string& squeezeDims)
16 {
17 m_JsonString = R"(
18 {
19 "version": 3,
20 "operator_codes": [ { "builtin_code": "SQUEEZE" } ],
21 "subgraphs": [ {
22 "tensors": [
23 {)";
24 m_JsonString += R"(
25 "shape" : )" + inputShape + ",";
26 m_JsonString += R"(
27 "type": "UINT8",
28 "buffer": 0,
29 "name": "inputTensor",
30 "quantization": {
31 "min": [ 0.0 ],
32 "max": [ 255.0 ],
33 "scale": [ 1.0 ],
34 "zero_point": [ 0 ],
35 }
36 },
37 {)";
38 m_JsonString += R"(
39 "shape" : )" + outputShape;
40 m_JsonString += R"(,
41 "type": "UINT8",
42 "buffer": 1,
43 "name": "outputTensor",
44 "quantization": {
45 "min": [ 0.0 ],
46 "max": [ 255.0 ],
47 "scale": [ 1.0 ],
48 "zero_point": [ 0 ],
49 }
50 }
51 ],
52 "inputs": [ 0 ],
53 "outputs": [ 1 ],
54 "operators": [
55 {
56 "opcode_index": 0,
57 "inputs": [ 0 ],
58 "outputs": [ 1 ],
59 "builtin_options_type": "SqueezeOptions",
60 "builtin_options": {)";
61 if (!squeezeDims.empty())
62 {
63 m_JsonString += R"("squeeze_dims" : )" + squeezeDims;
64 }
65 m_JsonString += R"(},
66 "custom_options_format": "FLEXBUFFERS"
67 }
68 ],
69 } ],
70 "buffers" : [ {}, {} ]
71 }
72 )";
73 }
74};
75
76struct SqueezeFixtureWithSqueezeDims : SqueezeFixture
77{
78 SqueezeFixtureWithSqueezeDims() : SqueezeFixture("[ 1, 2, 2, 1 ]", "[ 2, 2, 1 ]", "[ 0, 1, 2 ]") {}
79};
80
Sadik Armagan1625efc2021-06-10 18:24:34 +010081TEST_CASE_FIXTURE(SqueezeFixtureWithSqueezeDims, "ParseSqueezeWithSqueezeDims")
telsoa01c577f2c2018-08-31 09:22:23 +010082{
83 SetupSingleInputSingleOutput("inputTensor", "outputTensor");
Derek Lambertif90c56d2020-01-10 17:14:08 +000084 RunTest<3, armnn::DataType::QAsymmU8>(0, { 1, 2, 3, 4 }, { 1, 2, 3, 4 });
Sadik Armagan1625efc2021-06-10 18:24:34 +010085 CHECK((m_Parser->GetNetworkOutputBindingInfo(0, "outputTensor").second.GetShape()
telsoa01c577f2c2018-08-31 09:22:23 +010086 == armnn::TensorShape({2,2,1})));
87
88}
89
90struct SqueezeFixtureWithoutSqueezeDims : SqueezeFixture
91{
92 SqueezeFixtureWithoutSqueezeDims() : SqueezeFixture("[ 1, 2, 2, 1 ]", "[ 2, 2 ]", "") {}
93};
94
Sadik Armagan1625efc2021-06-10 18:24:34 +010095TEST_CASE_FIXTURE(SqueezeFixtureWithoutSqueezeDims, "ParseSqueezeWithoutSqueezeDims")
telsoa01c577f2c2018-08-31 09:22:23 +010096{
97 SetupSingleInputSingleOutput("inputTensor", "outputTensor");
Derek Lambertif90c56d2020-01-10 17:14:08 +000098 RunTest<2, armnn::DataType::QAsymmU8>(0, { 1, 2, 3, 4 }, { 1, 2, 3, 4 });
Sadik Armagan1625efc2021-06-10 18:24:34 +010099 CHECK((m_Parser->GetNetworkOutputBindingInfo(0, "outputTensor").second.GetShape()
telsoa01c577f2c2018-08-31 09:22:23 +0100100 == armnn::TensorShape({2,2})));
101}
102
103struct SqueezeFixtureWithInvalidInput : SqueezeFixture
104{
Matthew Jacksondba634f2019-08-15 15:14:18 +0100105 SqueezeFixtureWithInvalidInput() : SqueezeFixture("[ 1, 2, 2, 1, 2, 2 ]", "[ 1, 2, 2, 1, 2 ]", "[ ]") {}
telsoa01c577f2c2018-08-31 09:22:23 +0100106};
107
Sadik Armagan1625efc2021-06-10 18:24:34 +0100108TEST_CASE_FIXTURE(SqueezeFixtureWithInvalidInput, "ParseSqueezeInvalidInput")
telsoa01c577f2c2018-08-31 09:22:23 +0100109{
Matthew Jacksondba634f2019-08-15 15:14:18 +0100110 static_assert(armnn::MaxNumOfTensorDimensions == 5, "Please update SqueezeFixtureWithInvalidInput");
Sadik Armagan1625efc2021-06-10 18:24:34 +0100111 CHECK_THROWS_AS((SetupSingleInputSingleOutput("inputTensor", "outputTensor")),
telsoa01c577f2c2018-08-31 09:22:23 +0100112 armnn::InvalidArgumentException);
113}
114
115struct SqueezeFixtureWithSqueezeDimsSizeInvalid : SqueezeFixture
116{
117 SqueezeFixtureWithSqueezeDimsSizeInvalid() : SqueezeFixture("[ 1, 2, 2, 1 ]",
118 "[ 1, 2, 2, 1 ]",
119 "[ 1, 2, 2, 2, 2 ]") {}
120};
121
Sadik Armagan1625efc2021-06-10 18:24:34 +0100122TEST_CASE_FIXTURE(SqueezeFixtureWithSqueezeDimsSizeInvalid, "ParseSqueezeInvalidSqueezeDims")
telsoa01c577f2c2018-08-31 09:22:23 +0100123{
Sadik Armagan1625efc2021-06-10 18:24:34 +0100124 CHECK_THROWS_AS((SetupSingleInputSingleOutput("inputTensor", "outputTensor")), armnn::ParseException);
telsoa01c577f2c2018-08-31 09:22:23 +0100125}
126
127
Teresa Charlin3ab85482021-06-08 16:59:29 +0100128struct SqueezeFixtureWithNegativeSqueezeDims1 : SqueezeFixture
telsoa01c577f2c2018-08-31 09:22:23 +0100129{
Teresa Charlin3ab85482021-06-08 16:59:29 +0100130 SqueezeFixtureWithNegativeSqueezeDims1() : SqueezeFixture("[ 1, 2, 2, 1 ]",
131 "[ 2, 2, 1 ]",
132 "[ -1 ]") {}
telsoa01c577f2c2018-08-31 09:22:23 +0100133};
134
Teresa Charlin3ab85482021-06-08 16:59:29 +0100135TEST_CASE_FIXTURE(SqueezeFixtureWithNegativeSqueezeDims1, "ParseSqueezeNegativeSqueezeDims1")
136{
137 SetupSingleInputSingleOutput("inputTensor", "outputTensor");
138 RunTest<3, armnn::DataType::QAsymmU8>(0, { 1, 2, 3, 4 }, { 1, 2, 3, 4 });
139 CHECK((m_Parser->GetNetworkOutputBindingInfo(0, "outputTensor").second.GetShape()
140 == armnn::TensorShape({ 2, 2, 1 })));
141}
142
143struct SqueezeFixtureWithNegativeSqueezeDims2 : SqueezeFixture
144{
145 SqueezeFixtureWithNegativeSqueezeDims2() : SqueezeFixture("[ 1, 2, 2, 1 ]",
146 "[ 1, 2, 2 ]",
147 "[ -1 ]") {}
148};
149
150TEST_CASE_FIXTURE(SqueezeFixtureWithNegativeSqueezeDims2, "ParseSqueezeNegativeSqueezeDims2")
151{
152 SetupSingleInputSingleOutput("inputTensor", "outputTensor");
153 RunTest<3, armnn::DataType::QAsymmU8>(0, { 1, 2, 3, 4 }, { 1, 2, 3, 4 });
154 CHECK((m_Parser->GetNetworkOutputBindingInfo(0, "outputTensor").second.GetShape()
155 == armnn::TensorShape({ 1, 2, 2 })));
156}
157
158struct SqueezeFixtureWithNegativeSqueezeDimsInvalid : SqueezeFixture
159{
160 SqueezeFixtureWithNegativeSqueezeDimsInvalid() : SqueezeFixture("[ 1, 2, 2, 1 ]",
161 "[ 1, 2, 2, 1 ]",
162 "[ -2 , 2 ]") {}
163};
164
165TEST_CASE_FIXTURE(SqueezeFixtureWithNegativeSqueezeDimsInvalid, "ParseSqueezeNegativeSqueezeDimsInvalid")
telsoa01c577f2c2018-08-31 09:22:23 +0100166{
Sadik Armagan1625efc2021-06-10 18:24:34 +0100167 CHECK_THROWS_AS((SetupSingleInputSingleOutput("inputTensor", "outputTensor")), armnn::ParseException);
telsoa01c577f2c2018-08-31 09:22:23 +0100168}
169
170
Sadik Armagan1625efc2021-06-10 18:24:34 +0100171}