1 // 2 // Copyright © 2017 Arm Ltd and Contributors. All rights reserved. 3 // SPDX-License-Identifier: MIT 4 // 5 6 #include "ParserFlatbuffersFixture.hpp" 7 8 9 TEST_SUITE("TensorflowLiteParser_SpaceToBatchND") 10 { 11 struct SpaceToBatchNDFixture : public ParserFlatbuffersFixture 12 { SpaceToBatchNDFixtureSpaceToBatchNDFixture13 explicit SpaceToBatchNDFixture(const std::string & inputShape, 14 const std::string & outputShape, 15 const std::string & blockShapeData, 16 const std::string & padListData) 17 { 18 m_JsonString = R"( 19 { 20 "version": 3, 21 "operator_codes": [ { "builtin_code": "SPACE_TO_BATCH_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": "padListTensor", 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": )" + padListData + R"(, }, 89 ] 90 } 91 )"; 92 Setup(); 93 } 94 }; 95 96 struct SpaceToBatchNDFixtureSimpleTest : public SpaceToBatchNDFixture 97 { SpaceToBatchNDFixtureSimpleTestSpaceToBatchNDFixtureSimpleTest98 SpaceToBatchNDFixtureSimpleTest() : SpaceToBatchNDFixture("[ 1, 4, 4, 1 ]", 99 "[ 4, 2, 2, 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 104 TEST_CASE_FIXTURE(SpaceToBatchNDFixtureSimpleTest, "SpaceToBatchNdSimpleTest") 105 { 106 RunTest<4, armnn::DataType::Float32> 107 (0, 108 {{ "inputTensor", { 1.0f, 2.0f, 3.0f, 4.0f, 109 5.0f, 6.0f, 7.0f, 8.0f, 110 9.0f, 10.0f, 11.0f, 12.0f, 111 13.0f, 14.0f, 15.0f, 16.0f }}}, 112 {{ "outputTensor", { 1.0f, 3.0f, 9.0f, 11.0f, 113 2.0f, 4.0f, 10.0f, 12.0f, 114 5.0f, 7.0f, 13.0f, 15.0f, 115 6.0f, 8.0f, 14.0f, 16.0f }}}); 116 } 117 118 119 struct SpaceToBatchNDFixtureMultipleInputBatchesTest : public SpaceToBatchNDFixture 120 { SpaceToBatchNDFixtureMultipleInputBatchesTestSpaceToBatchNDFixtureMultipleInputBatchesTest121 SpaceToBatchNDFixtureMultipleInputBatchesTest() : SpaceToBatchNDFixture("[ 2, 2, 4, 1 ]", 122 "[ 8, 1, 2, 1 ]", 123 "[ 2,0,0,0, 2,0,0,0 ]", 124 "[ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 ]") {} 125 }; 126 127 TEST_CASE_FIXTURE(SpaceToBatchNDFixtureMultipleInputBatchesTest, "SpaceToBatchNdMultipleInputBatchesTest") 128 { 129 RunTest<4, armnn::DataType::Float32> 130 (0, 131 {{ "inputTensor", { 1.0f, 2.0f, 3.0f, 4.0f, 132 5.0f, 6.0f, 7.0f, 8.0f, 133 9.0f, 10.0f, 11.0f, 12.0f, 134 13.0f, 14.0f, 15.0f, 16.0f }}}, 135 {{ "outputTensor", { 1.0f, 3.0f, 9.0f, 11.0f, 136 2.0f, 4.0f, 10.0f, 12.0f, 137 5.0f, 7.0f, 13.0f, 15.0f, 138 6.0f, 8.0f, 14.0f, 16.0f }}}); 139 } 140 141 struct SpaceToBatchNDFixturePaddingTest : public SpaceToBatchNDFixture 142 { SpaceToBatchNDFixturePaddingTestSpaceToBatchNDFixturePaddingTest143 SpaceToBatchNDFixturePaddingTest() : SpaceToBatchNDFixture("[ 1, 5, 2, 1 ]", 144 "[ 6, 2, 2, 1 ]", 145 "[ 3,0,0,0, 2,0,0,0 ]", 146 "[ 1,0,0,0, 0,0,0,0, 2,0,0,0, 0,0,0,0 ]") {} 147 }; 148 149 TEST_CASE_FIXTURE(SpaceToBatchNDFixturePaddingTest, "SpaceToBatchNdPaddingTest") 150 { 151 RunTest<4, armnn::DataType::Float32> 152 (0, 153 {{ "inputTensor", { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 154 6.0f, 7.0f, 8.0f, 9.0f, 10.0f }}}, 155 {{ "outputTensor", { 0.0f, 0.0f, 156 0.0f, 5.0f, 157 158 0.0f, 0.0f, 159 0.0f, 6.0f, 160 161 0.0f, 1.0f, 162 0.0f, 7.0f, 163 164 0.0f, 2.0f, 165 0.0f, 8.0f, 166 167 0.0f, 3.0f, 168 0.0f, 9.0f, 169 170 0.0f, 4.0f, 171 0.0f, 10.0f, }}}); 172 } 173 174 } 175