blob: da870fd4c9b54347070908560c5412f851c93ea3 [file] [log] [blame]
telsoa01c577f2c2018-08-31 09:22:23 +01001//
2// Copyright © 2017 Arm Ltd. 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"
7#include "../TfLiteParser.hpp"
8
9#include <string>
10#include <iostream>
11
Sadik Armagan1625efc2021-06-10 18:24:34 +010012TEST_SUITE("TensorflowLiteParser_Squeeze")
13{
telsoa01c577f2c2018-08-31 09:22:23 +010014struct SqueezeFixture : public ParserFlatbuffersFixture
15{
16 explicit SqueezeFixture(const std::string& inputShape,
17 const std::string& outputShape,
18 const std::string& squeezeDims)
19 {
20 m_JsonString = R"(
21 {
22 "version": 3,
23 "operator_codes": [ { "builtin_code": "SQUEEZE" } ],
24 "subgraphs": [ {
25 "tensors": [
26 {)";
27 m_JsonString += R"(
28 "shape" : )" + inputShape + ",";
29 m_JsonString += R"(
30 "type": "UINT8",
31 "buffer": 0,
32 "name": "inputTensor",
33 "quantization": {
34 "min": [ 0.0 ],
35 "max": [ 255.0 ],
36 "scale": [ 1.0 ],
37 "zero_point": [ 0 ],
38 }
39 },
40 {)";
41 m_JsonString += R"(
42 "shape" : )" + outputShape;
43 m_JsonString += R"(,
44 "type": "UINT8",
45 "buffer": 1,
46 "name": "outputTensor",
47 "quantization": {
48 "min": [ 0.0 ],
49 "max": [ 255.0 ],
50 "scale": [ 1.0 ],
51 "zero_point": [ 0 ],
52 }
53 }
54 ],
55 "inputs": [ 0 ],
56 "outputs": [ 1 ],
57 "operators": [
58 {
59 "opcode_index": 0,
60 "inputs": [ 0 ],
61 "outputs": [ 1 ],
62 "builtin_options_type": "SqueezeOptions",
63 "builtin_options": {)";
64 if (!squeezeDims.empty())
65 {
66 m_JsonString += R"("squeeze_dims" : )" + squeezeDims;
67 }
68 m_JsonString += R"(},
69 "custom_options_format": "FLEXBUFFERS"
70 }
71 ],
72 } ],
73 "buffers" : [ {}, {} ]
74 }
75 )";
76 }
77};
78
79struct SqueezeFixtureWithSqueezeDims : SqueezeFixture
80{
81 SqueezeFixtureWithSqueezeDims() : SqueezeFixture("[ 1, 2, 2, 1 ]", "[ 2, 2, 1 ]", "[ 0, 1, 2 ]") {}
82};
83
Sadik Armagan1625efc2021-06-10 18:24:34 +010084TEST_CASE_FIXTURE(SqueezeFixtureWithSqueezeDims, "ParseSqueezeWithSqueezeDims")
telsoa01c577f2c2018-08-31 09:22:23 +010085{
86 SetupSingleInputSingleOutput("inputTensor", "outputTensor");
Derek Lambertif90c56d2020-01-10 17:14:08 +000087 RunTest<3, armnn::DataType::QAsymmU8>(0, { 1, 2, 3, 4 }, { 1, 2, 3, 4 });
Sadik Armagan1625efc2021-06-10 18:24:34 +010088 CHECK((m_Parser->GetNetworkOutputBindingInfo(0, "outputTensor").second.GetShape()
telsoa01c577f2c2018-08-31 09:22:23 +010089 == armnn::TensorShape({2,2,1})));
90
91}
92
93struct SqueezeFixtureWithoutSqueezeDims : SqueezeFixture
94{
95 SqueezeFixtureWithoutSqueezeDims() : SqueezeFixture("[ 1, 2, 2, 1 ]", "[ 2, 2 ]", "") {}
96};
97
Sadik Armagan1625efc2021-06-10 18:24:34 +010098TEST_CASE_FIXTURE(SqueezeFixtureWithoutSqueezeDims, "ParseSqueezeWithoutSqueezeDims")
telsoa01c577f2c2018-08-31 09:22:23 +010099{
100 SetupSingleInputSingleOutput("inputTensor", "outputTensor");
Derek Lambertif90c56d2020-01-10 17:14:08 +0000101 RunTest<2, armnn::DataType::QAsymmU8>(0, { 1, 2, 3, 4 }, { 1, 2, 3, 4 });
Sadik Armagan1625efc2021-06-10 18:24:34 +0100102 CHECK((m_Parser->GetNetworkOutputBindingInfo(0, "outputTensor").second.GetShape()
telsoa01c577f2c2018-08-31 09:22:23 +0100103 == armnn::TensorShape({2,2})));
104}
105
106struct SqueezeFixtureWithInvalidInput : SqueezeFixture
107{
Matthew Jacksondba634f2019-08-15 15:14:18 +0100108 SqueezeFixtureWithInvalidInput() : SqueezeFixture("[ 1, 2, 2, 1, 2, 2 ]", "[ 1, 2, 2, 1, 2 ]", "[ ]") {}
telsoa01c577f2c2018-08-31 09:22:23 +0100109};
110
Sadik Armagan1625efc2021-06-10 18:24:34 +0100111TEST_CASE_FIXTURE(SqueezeFixtureWithInvalidInput, "ParseSqueezeInvalidInput")
telsoa01c577f2c2018-08-31 09:22:23 +0100112{
Matthew Jacksondba634f2019-08-15 15:14:18 +0100113 static_assert(armnn::MaxNumOfTensorDimensions == 5, "Please update SqueezeFixtureWithInvalidInput");
Sadik Armagan1625efc2021-06-10 18:24:34 +0100114 CHECK_THROWS_AS((SetupSingleInputSingleOutput("inputTensor", "outputTensor")),
telsoa01c577f2c2018-08-31 09:22:23 +0100115 armnn::InvalidArgumentException);
116}
117
118struct SqueezeFixtureWithSqueezeDimsSizeInvalid : SqueezeFixture
119{
120 SqueezeFixtureWithSqueezeDimsSizeInvalid() : SqueezeFixture("[ 1, 2, 2, 1 ]",
121 "[ 1, 2, 2, 1 ]",
122 "[ 1, 2, 2, 2, 2 ]") {}
123};
124
Sadik Armagan1625efc2021-06-10 18:24:34 +0100125TEST_CASE_FIXTURE(SqueezeFixtureWithSqueezeDimsSizeInvalid, "ParseSqueezeInvalidSqueezeDims")
telsoa01c577f2c2018-08-31 09:22:23 +0100126{
Sadik Armagan1625efc2021-06-10 18:24:34 +0100127 CHECK_THROWS_AS((SetupSingleInputSingleOutput("inputTensor", "outputTensor")), armnn::ParseException);
telsoa01c577f2c2018-08-31 09:22:23 +0100128}
129
130
131struct SqueezeFixtureWithNegativeSqueezeDims : SqueezeFixture
132{
133 SqueezeFixtureWithNegativeSqueezeDims() : SqueezeFixture("[ 1, 2, 2, 1 ]",
134 "[ 1, 2, 2, 1 ]",
135 "[ -2 , 2 ]") {}
136};
137
Sadik Armagan1625efc2021-06-10 18:24:34 +0100138TEST_CASE_FIXTURE(SqueezeFixtureWithNegativeSqueezeDims, "ParseSqueezeNegativeSqueezeDims")
telsoa01c577f2c2018-08-31 09:22:23 +0100139{
Sadik Armagan1625efc2021-06-10 18:24:34 +0100140 CHECK_THROWS_AS((SetupSingleInputSingleOutput("inputTensor", "outputTensor")), armnn::ParseException);
telsoa01c577f2c2018-08-31 09:22:23 +0100141}
142
143
Sadik Armagan1625efc2021-06-10 18:24:34 +0100144}