blob: 8edecb1196272b889db7eedf9b6e3bb119e69644 [file] [log] [blame]
Sadikb94967b2018-09-19 15:30:00 +01001//
Finn Williamsb49ed182021-06-29 15:50:08 +01002// Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
Sadikb94967b2018-09-19 15:30:00 +01003// SPDX-License-Identifier: MIT
4//
5
Sadikb94967b2018-09-19 15:30:00 +01006#include "ParserFlatbuffersFixture.hpp"
Sadikb94967b2018-09-19 15:30:00 +01007
Sadikb94967b2018-09-19 15:30:00 +01008
Sadik Armagan1625efc2021-06-10 18:24:34 +01009TEST_SUITE("TensorflowLiteParser_Reshape")
10{
Sadikb94967b2018-09-19 15:30:00 +010011struct ReshapeFixture : public ParserFlatbuffersFixture
12{
13 explicit ReshapeFixture(const std::string& inputShape,
14 const std::string& outputShape,
15 const std::string& newShape)
16 {
17 m_JsonString = R"(
18 {
19 "version": 3,
20 "operator_codes": [ { "builtin_code": "RESHAPE" } ],
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": "ReshapeOptions",
60 "builtin_options": {)";
61 if (!newShape.empty())
62 {
63 m_JsonString += R"("new_shape" : )" + newShape;
64 }
65 m_JsonString += R"(},
66 "custom_options_format": "FLEXBUFFERS"
67 }
68 ],
69 } ],
70 "buffers" : [ {}, {} ]
71 }
72 )";
73
74 }
75};
76
77struct ReshapeFixtureWithReshapeDims : ReshapeFixture
78{
79 ReshapeFixtureWithReshapeDims() : ReshapeFixture("[ 1, 9 ]", "[ 3, 3 ]", "[ 3, 3 ]") {}
80};
81
Sadik Armagan1625efc2021-06-10 18:24:34 +010082TEST_CASE_FIXTURE(ReshapeFixtureWithReshapeDims, "ParseReshapeWithReshapeDims")
Sadikb94967b2018-09-19 15:30:00 +010083{
84 SetupSingleInputSingleOutput("inputTensor", "outputTensor");
Derek Lambertif90c56d2020-01-10 17:14:08 +000085 RunTest<2, armnn::DataType::QAsymmU8>(0,
Nattapat Chaimanowong649dd952019-01-22 16:10:44 +000086 { 1, 2, 3, 4, 5, 6, 7, 8, 9 },
87 { 1, 2, 3, 4, 5, 6, 7, 8, 9 });
Sadik Armagan1625efc2021-06-10 18:24:34 +010088 CHECK((m_Parser->GetNetworkOutputBindingInfo(0, "outputTensor").second.GetShape()
Sadikb94967b2018-09-19 15:30:00 +010089 == armnn::TensorShape({3,3})));
90}
91
92struct ReshapeFixtureWithReshapeDimsFlatten : ReshapeFixture
93{
Narumol Prangnawarat672de572019-04-23 15:28:06 +010094 ReshapeFixtureWithReshapeDimsFlatten() : ReshapeFixture("[ 3, 3 ]", "[ 9 ]", "[ -1 ]") {}
Sadikb94967b2018-09-19 15:30:00 +010095};
96
Sadik Armagan1625efc2021-06-10 18:24:34 +010097TEST_CASE_FIXTURE(ReshapeFixtureWithReshapeDimsFlatten, "ParseReshapeWithReshapeDimsFlatten")
Sadikb94967b2018-09-19 15:30:00 +010098{
99 SetupSingleInputSingleOutput("inputTensor", "outputTensor");
Derek Lambertif90c56d2020-01-10 17:14:08 +0000100 RunTest<1, armnn::DataType::QAsymmU8>(0,
Nattapat Chaimanowong649dd952019-01-22 16:10:44 +0000101 { 1, 2, 3, 4, 5, 6, 7, 8, 9 },
102 { 1, 2, 3, 4, 5, 6, 7, 8, 9 });
Sadik Armagan1625efc2021-06-10 18:24:34 +0100103 CHECK((m_Parser->GetNetworkOutputBindingInfo(0, "outputTensor").second.GetShape()
Narumol Prangnawarat672de572019-04-23 15:28:06 +0100104 == armnn::TensorShape({9})));
Sadikb94967b2018-09-19 15:30:00 +0100105}
106
107struct ReshapeFixtureWithReshapeDimsFlattenTwoDims : ReshapeFixture
108{
109 ReshapeFixtureWithReshapeDimsFlattenTwoDims() : ReshapeFixture("[ 3, 2, 3 ]", "[ 2, 9 ]", "[ 2, -1 ]") {}
110};
111
Sadik Armagan1625efc2021-06-10 18:24:34 +0100112TEST_CASE_FIXTURE(ReshapeFixtureWithReshapeDimsFlattenTwoDims, "ParseReshapeWithReshapeDimsFlattenTwoDims")
Sadikb94967b2018-09-19 15:30:00 +0100113{
114 SetupSingleInputSingleOutput("inputTensor", "outputTensor");
Derek Lambertif90c56d2020-01-10 17:14:08 +0000115 RunTest<2, armnn::DataType::QAsymmU8>(0,
Nattapat Chaimanowong649dd952019-01-22 16:10:44 +0000116 { 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6 },
117 { 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6 });
Sadik Armagan1625efc2021-06-10 18:24:34 +0100118 CHECK((m_Parser->GetNetworkOutputBindingInfo(0, "outputTensor").second.GetShape()
Sadikb94967b2018-09-19 15:30:00 +0100119 == armnn::TensorShape({2,9})));
120}
121
122struct ReshapeFixtureWithReshapeDimsFlattenOneDim : ReshapeFixture
123{
124 ReshapeFixtureWithReshapeDimsFlattenOneDim() : ReshapeFixture("[ 2, 9 ]", "[ 2, 3, 3 ]", "[ 2, -1, 3 ]") {}
125};
126
Sadik Armagan1625efc2021-06-10 18:24:34 +0100127TEST_CASE_FIXTURE(ReshapeFixtureWithReshapeDimsFlattenOneDim, "ParseReshapeWithReshapeDimsFlattenOneDim")
Sadikb94967b2018-09-19 15:30:00 +0100128{
129 SetupSingleInputSingleOutput("inputTensor", "outputTensor");
Derek Lambertif90c56d2020-01-10 17:14:08 +0000130 RunTest<3, armnn::DataType::QAsymmU8>(0,
Nattapat Chaimanowong649dd952019-01-22 16:10:44 +0000131 { 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6 },
132 { 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6 });
Sadik Armagan1625efc2021-06-10 18:24:34 +0100133 CHECK((m_Parser->GetNetworkOutputBindingInfo(0, "outputTensor").second.GetShape()
Sadikb94967b2018-09-19 15:30:00 +0100134 == armnn::TensorShape({2,3,3})));
135}
136
Sadik Armagand109a4d2020-07-28 10:42:13 +0100137struct DynamicReshapeFixtureWithReshapeDimsFlattenOneDim : ReshapeFixture
138{
139 DynamicReshapeFixtureWithReshapeDimsFlattenOneDim() : ReshapeFixture("[ 2, 9 ]",
140 "[ ]",
141 "[ 2, -1, 3 ]") {}
142};
143
Sadik Armagan1625efc2021-06-10 18:24:34 +0100144TEST_CASE_FIXTURE(DynamicReshapeFixtureWithReshapeDimsFlattenOneDim, "DynParseReshapeWithReshapeDimsFlattenOneDim")
Sadik Armagand109a4d2020-07-28 10:42:13 +0100145{
146 SetupSingleInputSingleOutput("inputTensor", "outputTensor");
147 RunTest<3,
148 armnn::DataType::QAsymmU8,
149 armnn::DataType::QAsymmU8>(0,
150 { { "inputTensor", { 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6 } } },
151 { { "outputTensor", { 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6 } } },
152 true);
153}
154
Sadik Armagan1625efc2021-06-10 18:24:34 +0100155}