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