blob: 108bf38e8eb78f2b501ceaf766858e2f0f86781e [file] [log] [blame]
Bruno Goncalvesdb947e22019-02-08 18:52:21 -02001//
Finn Williamsb49ed182021-06-29 15:50:08 +01002// Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
Bruno Goncalvesdb947e22019-02-08 18:52:21 -02003// SPDX-License-Identifier: MIT
4//
5
Bruno Goncalvesdb947e22019-02-08 18:52:21 -02006#include "ParserFlatbuffersFixture.hpp"
Bruno Goncalvesdb947e22019-02-08 18:52:21 -02007
Bruno Goncalvesdb947e22019-02-08 18:52:21 -02008
Sadik Armagan1625efc2021-06-10 18:24:34 +01009TEST_SUITE("TensorflowLiteParser_BatchToSpaceND")
10{
Bruno Goncalvesdb947e22019-02-08 18:52:21 -020011struct BatchToSpaceNDFixture : public ParserFlatbuffersFixture
12{
13 explicit BatchToSpaceNDFixture(const std::string & inputShape,
14 const std::string & outputShape,
15 const std::string & blockShapeData,
16 const std::string & cropsData)
17 {
18 m_JsonString = R"(
19 {
20 "version": 3,
21 "operator_codes": [ { "builtin_code": "BATCH_TO_SPACE_ND" } ],
22 "subgraphs": [ {
23 "tensors": [
24 {
25 "shape": )" + inputShape + R"(,
26 "type": "FLOAT32",
27 "buffer": 0,
28 "name": "inputTensor",
29 "quantization": {
30 "min": [ 0.0 ],
31 "max": [ 255.0 ],
32 "scale": [ 1.0 ],
33 "zero_point": [ 0 ],
34 }
35 },
36 {
37 "shape": )" + outputShape + R"(,
38 "type": "FLOAT32",
39 "buffer": 1,
40 "name": "outputTensor",
41 "quantization": {
42 "min": [ 0.0 ],
43 "max": [ 255.0 ],
44 "scale": [ 1.0 ],
45 "zero_point": [ 0 ],
46 }
47 },
48 {
49 "shape": [ 2 ],
50 "type": "INT32",
51 "buffer": 2,
52 "name": "blockShapeTensor",
53 "quantization": {
54 "min": [ 0.0 ],
55 "max": [ 255.0 ],
56 "scale": [ 1.0 ],
57 "zero_point": [ 0 ],
58 }
59 },
60 {
61 "shape": [ 2, 2 ],
62 "type": "INT32",
63 "buffer": 3,
64 "name": "cropsTensor",
65 "quantization": {
66 "min": [ 0.0 ],
67 "max": [ 255.0 ],
68 "scale": [ 1.0 ],
69 "zero_point": [ 0 ],
70 }
71 }
72 ],
73 "inputs": [ 0 ],
74 "outputs": [ 1 ],
75 "operators": [
76 {
77 "opcode_index": 0,
78 "inputs": [ 0, 2, 3 ],
79 "outputs": [ 1 ],
80 "custom_options_format": "FLEXBUFFERS"
81 }
82 ],
83 } ],
84 "buffers" : [
85 { },
86 { },
87 { "data": )" + blockShapeData + R"(, },
88 { "data": )" + cropsData + R"(, },
89 ]
90 }
91 )";
92 Setup();
93 }
94};
95
96struct BatchToSpaceNDFixtureTest1 : public BatchToSpaceNDFixture
97{
98 BatchToSpaceNDFixtureTest1() : BatchToSpaceNDFixture("[ 4, 2, 2, 1 ]",
99 "[ 1, 4, 4, 1 ]",
100 "[ 2,0,0,0, 2,0,0,0 ]",
101 "[ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 ]") {}
102};
103
Sadik Armagan1625efc2021-06-10 18:24:34 +0100104TEST_CASE_FIXTURE(BatchToSpaceNDFixtureTest1, "BatchToSpaceNDTest1")
Bruno Goncalvesdb947e22019-02-08 18:52:21 -0200105{
106 RunTest<4, armnn::DataType::Float32>
107 (0,
108 {{ "inputTensor", { // Batch 0, Height 0, Width (2) x Channel (1)
109 1.0f, 3.0f,
110 // Batch 0, Height 1, Width (2) x Channel (1)
111 9.0f, 11.0f,
112
113 // Batch 1, Height 0, Width (2) x Channel (1)
114 2.0f, 4.0f,
115 // Batch 1, Height 1, Width (2) x Channel (1)
116 10.0f, 12.0f,
117
118 // Batch 2, Height 0, Width (2) x Channel (1)
119 5.0f, 7.0f,
120 // Batch 2, Height 1, Width (2) x Channel (1)
121 13.0f, 15.0f,
122
123 // Batch 3, Height 0, Width (2) x Channel (3)
124 6.0f, 8.0f,
125 // Batch 3, Height 1, Width (2) x Channel (1)
126 14.0f, 16.0f }}},
127 {{ "outputTensor", { 1.0f, 2.0f, 3.0f, 4.0f,
128 5.0f, 6.0f, 7.0f, 8.0f,
129 9.0f, 10.0f, 11.0f, 12.0f,
130 13.0f, 14.0f, 15.0f, 16.0f }}});
131}
132
133struct BatchToSpaceNDFixtureTest2 : public BatchToSpaceNDFixture
134{
135 BatchToSpaceNDFixtureTest2() : BatchToSpaceNDFixture("[ 4, 1, 1, 1 ]",
136 "[ 1, 2, 2, 1 ]",
137 "[ 2,0,0,0, 2,0,0,0 ]",
138 "[ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 ]") {}
139};
140
Sadik Armagan1625efc2021-06-10 18:24:34 +0100141TEST_CASE_FIXTURE(BatchToSpaceNDFixtureTest2, "ParseBatchToSpaceNDTest2")
Bruno Goncalvesdb947e22019-02-08 18:52:21 -0200142{
143 RunTest<4, armnn::DataType::Float32>
144 (0,
145 {{ "inputTensor", { 1.0f, 2.0f, 3.0f, 4.0f }}},
146 {{ "outputTensor", { // Batch 0, Height 0, Width (2) x Channel (1)
147 1.0f, 2.0f, 3.0f, 4.0f }}});
148}
149
150struct BatchToSpaceNDFixtureTest3 : public BatchToSpaceNDFixture
151{
152 BatchToSpaceNDFixtureTest3() : BatchToSpaceNDFixture("[ 4, 1, 1, 3 ]",
153 "[ 1, 2, 2, 3 ]",
154 "[ 2,0,0,0, 2,0,0,0 ]",
155 "[ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 ]") {}
156};
157
Sadik Armagan1625efc2021-06-10 18:24:34 +0100158TEST_CASE_FIXTURE(BatchToSpaceNDFixtureTest3, "ParseBatchToSpaceNDTest3")
Bruno Goncalvesdb947e22019-02-08 18:52:21 -0200159{
160 RunTest<4, armnn::DataType::Float32>
161 (0,
162 {{ "inputTensor", { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f }}},
163 {{ "outputTensor", { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f }}});
164}
165
Sadik Armagan1625efc2021-06-10 18:24:34 +0100166}