Sadik | b94967b | 2018-09-19 15:30:00 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
Sadik | b94967b | 2018-09-19 15:30:00 +0100 | [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_Reshape") |
| 13 | { |
Sadik | b94967b | 2018-09-19 15:30:00 +0100 | [diff] [blame] | 14 | struct ReshapeFixture : public ParserFlatbuffersFixture |
| 15 | { |
| 16 | explicit ReshapeFixture(const std::string& inputShape, |
| 17 | const std::string& outputShape, |
| 18 | const std::string& newShape) |
| 19 | { |
| 20 | m_JsonString = R"( |
| 21 | { |
| 22 | "version": 3, |
| 23 | "operator_codes": [ { "builtin_code": "RESHAPE" } ], |
| 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": "ReshapeOptions", |
| 63 | "builtin_options": {)"; |
| 64 | if (!newShape.empty()) |
| 65 | { |
| 66 | m_JsonString += R"("new_shape" : )" + newShape; |
| 67 | } |
| 68 | m_JsonString += R"(}, |
| 69 | "custom_options_format": "FLEXBUFFERS" |
| 70 | } |
| 71 | ], |
| 72 | } ], |
| 73 | "buffers" : [ {}, {} ] |
| 74 | } |
| 75 | )"; |
| 76 | |
| 77 | } |
| 78 | }; |
| 79 | |
| 80 | struct ReshapeFixtureWithReshapeDims : ReshapeFixture |
| 81 | { |
| 82 | ReshapeFixtureWithReshapeDims() : ReshapeFixture("[ 1, 9 ]", "[ 3, 3 ]", "[ 3, 3 ]") {} |
| 83 | }; |
| 84 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 85 | TEST_CASE_FIXTURE(ReshapeFixtureWithReshapeDims, "ParseReshapeWithReshapeDims") |
Sadik | b94967b | 2018-09-19 15:30:00 +0100 | [diff] [blame] | 86 | { |
| 87 | SetupSingleInputSingleOutput("inputTensor", "outputTensor"); |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 88 | RunTest<2, armnn::DataType::QAsymmU8>(0, |
Nattapat Chaimanowong | 649dd95 | 2019-01-22 16:10:44 +0000 | [diff] [blame] | 89 | { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, |
| 90 | { 1, 2, 3, 4, 5, 6, 7, 8, 9 }); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 91 | CHECK((m_Parser->GetNetworkOutputBindingInfo(0, "outputTensor").second.GetShape() |
Sadik | b94967b | 2018-09-19 15:30:00 +0100 | [diff] [blame] | 92 | == armnn::TensorShape({3,3}))); |
| 93 | } |
| 94 | |
| 95 | struct ReshapeFixtureWithReshapeDimsFlatten : ReshapeFixture |
| 96 | { |
Narumol Prangnawarat | 672de57 | 2019-04-23 15:28:06 +0100 | [diff] [blame] | 97 | ReshapeFixtureWithReshapeDimsFlatten() : ReshapeFixture("[ 3, 3 ]", "[ 9 ]", "[ -1 ]") {} |
Sadik | b94967b | 2018-09-19 15:30:00 +0100 | [diff] [blame] | 98 | }; |
| 99 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 100 | TEST_CASE_FIXTURE(ReshapeFixtureWithReshapeDimsFlatten, "ParseReshapeWithReshapeDimsFlatten") |
Sadik | b94967b | 2018-09-19 15:30:00 +0100 | [diff] [blame] | 101 | { |
| 102 | SetupSingleInputSingleOutput("inputTensor", "outputTensor"); |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 103 | RunTest<1, armnn::DataType::QAsymmU8>(0, |
Nattapat Chaimanowong | 649dd95 | 2019-01-22 16:10:44 +0000 | [diff] [blame] | 104 | { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, |
| 105 | { 1, 2, 3, 4, 5, 6, 7, 8, 9 }); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 106 | CHECK((m_Parser->GetNetworkOutputBindingInfo(0, "outputTensor").second.GetShape() |
Narumol Prangnawarat | 672de57 | 2019-04-23 15:28:06 +0100 | [diff] [blame] | 107 | == armnn::TensorShape({9}))); |
Sadik | b94967b | 2018-09-19 15:30:00 +0100 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | struct ReshapeFixtureWithReshapeDimsFlattenTwoDims : ReshapeFixture |
| 111 | { |
| 112 | ReshapeFixtureWithReshapeDimsFlattenTwoDims() : ReshapeFixture("[ 3, 2, 3 ]", "[ 2, 9 ]", "[ 2, -1 ]") {} |
| 113 | }; |
| 114 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 115 | TEST_CASE_FIXTURE(ReshapeFixtureWithReshapeDimsFlattenTwoDims, "ParseReshapeWithReshapeDimsFlattenTwoDims") |
Sadik | b94967b | 2018-09-19 15:30:00 +0100 | [diff] [blame] | 116 | { |
| 117 | SetupSingleInputSingleOutput("inputTensor", "outputTensor"); |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 118 | RunTest<2, armnn::DataType::QAsymmU8>(0, |
Nattapat Chaimanowong | 649dd95 | 2019-01-22 16:10:44 +0000 | [diff] [blame] | 119 | { 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6 }, |
| 120 | { 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6 }); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 121 | CHECK((m_Parser->GetNetworkOutputBindingInfo(0, "outputTensor").second.GetShape() |
Sadik | b94967b | 2018-09-19 15:30:00 +0100 | [diff] [blame] | 122 | == armnn::TensorShape({2,9}))); |
| 123 | } |
| 124 | |
| 125 | struct ReshapeFixtureWithReshapeDimsFlattenOneDim : ReshapeFixture |
| 126 | { |
| 127 | ReshapeFixtureWithReshapeDimsFlattenOneDim() : ReshapeFixture("[ 2, 9 ]", "[ 2, 3, 3 ]", "[ 2, -1, 3 ]") {} |
| 128 | }; |
| 129 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 130 | TEST_CASE_FIXTURE(ReshapeFixtureWithReshapeDimsFlattenOneDim, "ParseReshapeWithReshapeDimsFlattenOneDim") |
Sadik | b94967b | 2018-09-19 15:30:00 +0100 | [diff] [blame] | 131 | { |
| 132 | SetupSingleInputSingleOutput("inputTensor", "outputTensor"); |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 133 | RunTest<3, armnn::DataType::QAsymmU8>(0, |
Nattapat Chaimanowong | 649dd95 | 2019-01-22 16:10:44 +0000 | [diff] [blame] | 134 | { 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6 }, |
| 135 | { 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6 }); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 136 | CHECK((m_Parser->GetNetworkOutputBindingInfo(0, "outputTensor").second.GetShape() |
Sadik | b94967b | 2018-09-19 15:30:00 +0100 | [diff] [blame] | 137 | == armnn::TensorShape({2,3,3}))); |
| 138 | } |
| 139 | |
Sadik Armagan | d109a4d | 2020-07-28 10:42:13 +0100 | [diff] [blame] | 140 | struct DynamicReshapeFixtureWithReshapeDimsFlattenOneDim : ReshapeFixture |
| 141 | { |
| 142 | DynamicReshapeFixtureWithReshapeDimsFlattenOneDim() : ReshapeFixture("[ 2, 9 ]", |
| 143 | "[ ]", |
| 144 | "[ 2, -1, 3 ]") {} |
| 145 | }; |
| 146 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 147 | TEST_CASE_FIXTURE(DynamicReshapeFixtureWithReshapeDimsFlattenOneDim, "DynParseReshapeWithReshapeDimsFlattenOneDim") |
Sadik Armagan | d109a4d | 2020-07-28 10:42:13 +0100 | [diff] [blame] | 148 | { |
| 149 | SetupSingleInputSingleOutput("inputTensor", "outputTensor"); |
| 150 | RunTest<3, |
| 151 | armnn::DataType::QAsymmU8, |
| 152 | armnn::DataType::QAsymmU8>(0, |
| 153 | { { "inputTensor", { 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6 } } }, |
| 154 | { { "outputTensor", { 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6 } } }, |
| 155 | true); |
| 156 | } |
| 157 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 158 | } |