Matthew Sloyan | 28f177c | 2021-04-09 14:38:52 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2021 Arm Ltd and Contributors. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
Matthew Sloyan | 28f177c | 2021-04-09 14:38:52 +0100 | [diff] [blame] | 6 | #include "ParserFlatbuffersFixture.hpp" |
| 7 | #include "../TfLiteParser.hpp" |
| 8 | |
| 9 | #include <iostream> |
| 10 | #include <string> |
| 11 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 12 | TEST_SUITE("TensorflowLiteParser_ArgMinMax") |
| 13 | { |
Matthew Sloyan | 28f177c | 2021-04-09 14:38:52 +0100 | [diff] [blame] | 14 | struct ArgMinMaxFixture : public ParserFlatbuffersFixture |
| 15 | { |
| 16 | explicit ArgMinMaxFixture(const std::string& operatorCode, |
| 17 | const std::string& inputShape, |
| 18 | const std::string& outputShape, |
| 19 | const std::string& axisData) |
| 20 | { |
| 21 | m_JsonString = R"( |
| 22 | { |
| 23 | "version": 3, |
| 24 | "operator_codes": [ { "builtin_code": )" + operatorCode + R"( } ], |
| 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": "INT32", |
| 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": [ 1 ], |
| 53 | "type": "INT32", |
| 54 | "buffer": 2, |
| 55 | "name": "axis", |
| 56 | "quantization": { |
| 57 | "min": [ 0.0 ], |
| 58 | "max": [ 255.0 ], |
| 59 | "scale": [ 1.0 ], |
| 60 | "zero_point": [ 0 ], |
| 61 | } |
| 62 | }, |
| 63 | ], |
| 64 | "inputs": [ 0 ], |
| 65 | "outputs": [ 1 ], |
| 66 | "operators": [ |
| 67 | { |
| 68 | "opcode_index": 0, |
| 69 | "inputs": [ 0 , 2 ], |
| 70 | "outputs": [ 1 ], |
| 71 | "custom_options_format": "FLEXBUFFERS" |
| 72 | } |
| 73 | ], |
| 74 | } ], |
| 75 | "buffers" : [ |
| 76 | { }, |
| 77 | { }, |
| 78 | { "data": )" + axisData + R"(, }, |
| 79 | ] |
| 80 | } |
| 81 | )"; |
| 82 | |
| 83 | SetupSingleInputSingleOutput("inputTensor", "outputTensor"); |
| 84 | } |
| 85 | }; |
| 86 | |
| 87 | struct SimpleArgMaxFixture : public ArgMinMaxFixture |
| 88 | { |
| 89 | SimpleArgMaxFixture() : ArgMinMaxFixture("ARG_MAX", |
| 90 | "[ 1, 1, 1, 5 ]", |
| 91 | "[ 1, 1, 1 ]", |
| 92 | "[ 3, 0, 0, 0 ]") {} |
| 93 | }; |
| 94 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 95 | TEST_CASE_FIXTURE(SimpleArgMaxFixture, "ParseSimpleArgMax") |
Matthew Sloyan | 28f177c | 2021-04-09 14:38:52 +0100 | [diff] [blame] | 96 | { |
| 97 | RunTest<3, armnn::DataType::Float32, armnn::DataType::Signed32>( |
| 98 | 0, |
| 99 | {{ "inputTensor", { 6.0f, 2.0f, 8.0f, 10.0f, 9.0f } } }, |
| 100 | {{ "outputTensor", { 3l } } }); |
| 101 | } |
| 102 | |
| 103 | struct ArgMaxFixture : public ArgMinMaxFixture |
| 104 | { |
| 105 | ArgMaxFixture() : ArgMinMaxFixture("ARG_MAX", |
| 106 | "[ 3, 2, 1, 4 ]", |
| 107 | "[ 2, 1, 4 ]", |
| 108 | "[ 0, 0, 0, 0 ]") {} |
| 109 | }; |
| 110 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 111 | TEST_CASE_FIXTURE(ArgMaxFixture, "ParseArgMax") |
Matthew Sloyan | 28f177c | 2021-04-09 14:38:52 +0100 | [diff] [blame] | 112 | { |
| 113 | RunTest<3, armnn::DataType::Float32, armnn::DataType::Signed32>( |
| 114 | 0, |
| 115 | {{ "inputTensor", { 1.0f, 2.0f, 3.0f, 4.0f, |
| 116 | 8.0f, 7.0f, 6.0f, 6.0f, |
| 117 | 100.0f, 20.0f, 300.0f, 40.0f, |
| 118 | 500.0f, 476.0f, 450.0f, 426.0f, |
| 119 | 50.0f, 60.0f, 70.0f, 80.0f, |
| 120 | 10.0f, 200.0f, 30.0f, 400.0f } } }, |
| 121 | {{ "outputTensor", { 1, 2, 1, 2, |
| 122 | 1, 1, 1, 1 } } }); |
| 123 | } |
| 124 | |
| 125 | struct SimpleArgMinFixture : public ArgMinMaxFixture |
| 126 | { |
| 127 | SimpleArgMinFixture() : ArgMinMaxFixture("ARG_MIN", |
| 128 | "[ 1, 1, 1, 5 ]", |
| 129 | "[ 1, 1, 1 ]", |
| 130 | "[ 3, 0, 0, 0 ]") {} |
| 131 | }; |
| 132 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 133 | TEST_CASE_FIXTURE(SimpleArgMinFixture, "ParseSimpleArgMin") |
Matthew Sloyan | 28f177c | 2021-04-09 14:38:52 +0100 | [diff] [blame] | 134 | { |
| 135 | RunTest<3, armnn::DataType::Float32, armnn::DataType::Signed32>( |
| 136 | 0, |
| 137 | {{ "inputTensor", { 6.0f, 2.0f, 8.0f, 10.0f, 9.0f } } }, |
| 138 | {{ "outputTensor", { 1l } } }); |
| 139 | } |
| 140 | |
| 141 | struct ArgMinFixture : public ArgMinMaxFixture |
| 142 | { |
| 143 | ArgMinFixture() : ArgMinMaxFixture("ARG_MIN", |
| 144 | "[ 3, 2, 1, 4 ]", |
| 145 | "[ 2, 1, 4 ]", |
| 146 | "[ 0, 0, 0, 0 ]") {} |
| 147 | }; |
| 148 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 149 | TEST_CASE_FIXTURE(ArgMinFixture, "ParseArgMin") |
Matthew Sloyan | 28f177c | 2021-04-09 14:38:52 +0100 | [diff] [blame] | 150 | { |
| 151 | RunTest<3, armnn::DataType::Float32, armnn::DataType::Signed32>( |
| 152 | 0, |
| 153 | {{ "inputTensor", { 1.0f, 2.0f, 3.0f, 4.0f, |
| 154 | 8.0f, 7.0f, 6.0f, 6.0f, |
| 155 | 100.0f, 20.0f, 300.0f, 40.0f, |
| 156 | 500.0f, 476.0f, 450.0f, 426.0f, |
| 157 | 50.0f, 60.0f, 70.0f, 80.0f, |
| 158 | 10.0f, 200.0f, 30.0f, 400.0f } } }, |
| 159 | {{ "outputTensor", { 0, 0, 0, 0, |
| 160 | 0, 0, 0, 0 } } }); |
| 161 | } |
| 162 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 163 | } |