Bruno Goncalves | bbeae26 | 2019-02-07 18:37:39 -0200 | [diff] [blame] | 1 | // |
Finn Williams | b49ed18 | 2021-06-29 15:50:08 +0100 | [diff] [blame] | 2 | // Copyright © 2017 Arm Ltd and Contributors. All rights reserved. |
Bruno Goncalves | bbeae26 | 2019-02-07 18:37:39 -0200 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
Bruno Goncalves | bbeae26 | 2019-02-07 18:37:39 -0200 | [diff] [blame] | 6 | #include "ParserFlatbuffersFixture.hpp" |
Bruno Goncalves | bbeae26 | 2019-02-07 18:37:39 -0200 | [diff] [blame] | 7 | |
Bruno Goncalves | bbeae26 | 2019-02-07 18:37:39 -0200 | [diff] [blame] | 8 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 9 | TEST_SUITE("TensorflowLiteParser_Sub") |
| 10 | { |
Bruno Goncalves | bbeae26 | 2019-02-07 18:37:39 -0200 | [diff] [blame] | 11 | struct SubFixture : public ParserFlatbuffersFixture |
| 12 | { |
| 13 | explicit SubFixture(const std::string & inputShape1, |
| 14 | const std::string & inputShape2, |
| 15 | const std::string & outputShape, |
| 16 | const std::string & activation="NONE") |
| 17 | { |
| 18 | m_JsonString = R"( |
| 19 | { |
| 20 | "version": 3, |
| 21 | "operator_codes": [ { "builtin_code": "SUB" } ], |
| 22 | "subgraphs": [ { |
| 23 | "tensors": [ |
| 24 | { |
| 25 | "shape": )" + inputShape1 + R"(, |
| 26 | "type": "UINT8", |
| 27 | "buffer": 0, |
| 28 | "name": "inputTensor1", |
| 29 | "quantization": { |
| 30 | "min": [ 0.0 ], |
| 31 | "max": [ 255.0 ], |
| 32 | "scale": [ 1.0 ], |
| 33 | "zero_point": [ 0 ], |
| 34 | } |
| 35 | }, |
| 36 | { |
| 37 | "shape": )" + inputShape2 + R"(, |
| 38 | "type": "UINT8", |
| 39 | "buffer": 1, |
| 40 | "name": "inputTensor2", |
| 41 | "quantization": { |
| 42 | "min": [ 0.0 ], |
| 43 | "max": [ 255.0 ], |
| 44 | "scale": [ 1.0 ], |
| 45 | "zero_point": [ 0 ], |
| 46 | } |
| 47 | }, |
| 48 | { |
| 49 | "shape": )" + outputShape + R"( , |
| 50 | "type": "UINT8", |
| 51 | "buffer": 2, |
| 52 | "name": "outputTensor", |
| 53 | "quantization": { |
| 54 | "min": [ 0.0 ], |
| 55 | "max": [ 255.0 ], |
| 56 | "scale": [ 1.0 ], |
| 57 | "zero_point": [ 0 ], |
| 58 | } |
| 59 | } |
| 60 | ], |
| 61 | "inputs": [ 0, 1 ], |
| 62 | "outputs": [ 2 ], |
| 63 | "operators": [ |
| 64 | { |
| 65 | "opcode_index": 0, |
| 66 | "inputs": [ 0, 1 ], |
| 67 | "outputs": [ 2 ], |
| 68 | "builtin_options_type": "SubOptions", |
| 69 | "builtin_options": { |
| 70 | "fused_activation_function": )" + activation + R"( |
| 71 | }, |
| 72 | "custom_options_format": "FLEXBUFFERS" |
| 73 | } |
| 74 | ], |
| 75 | } ], |
| 76 | "buffers" : [ |
| 77 | { }, |
| 78 | { } |
| 79 | ] |
| 80 | } |
| 81 | )"; |
| 82 | Setup(); |
| 83 | } |
| 84 | }; |
| 85 | |
| 86 | |
| 87 | struct SimpleSubFixture : SubFixture |
| 88 | { |
| 89 | SimpleSubFixture() : SubFixture("[ 1, 4 ]", |
| 90 | "[ 1, 4 ]", |
| 91 | "[ 1, 4 ]") {} |
| 92 | }; |
| 93 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 94 | TEST_CASE_FIXTURE(SimpleSubFixture, "SimpleSub") |
Bruno Goncalves | bbeae26 | 2019-02-07 18:37:39 -0200 | [diff] [blame] | 95 | { |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 96 | RunTest<2, armnn::DataType::QAsymmU8>( |
Bruno Goncalves | bbeae26 | 2019-02-07 18:37:39 -0200 | [diff] [blame] | 97 | 0, |
| 98 | {{"inputTensor1", { 4, 5, 6, 7 }}, |
| 99 | {"inputTensor2", { 3, 2, 1, 0 }}}, |
| 100 | {{"outputTensor", { 1, 3, 5, 7 }}}); |
| 101 | } |
| 102 | |
Sadik Armagan | d109a4d | 2020-07-28 10:42:13 +0100 | [diff] [blame] | 103 | struct DynamicSubFixture : SubFixture |
| 104 | { |
| 105 | DynamicSubFixture() : SubFixture("[ 1, 4 ]", |
| 106 | "[ 1, 4 ]", |
| 107 | "[ ]") {} |
| 108 | }; |
| 109 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 110 | TEST_CASE_FIXTURE(DynamicSubFixture, "DynamicSub") |
Sadik Armagan | d109a4d | 2020-07-28 10:42:13 +0100 | [diff] [blame] | 111 | { |
| 112 | RunTest<2, armnn::DataType::QAsymmU8, armnn::DataType::QAsymmU8>( |
| 113 | 0, |
| 114 | {{"inputTensor1", { 4, 5, 6, 7 }}, |
| 115 | {"inputTensor2", { 3, 2, 1, 0 }}}, |
| 116 | {{"outputTensor", { 1, 3, 5, 7 }}}, |
| 117 | true); |
| 118 | } |
| 119 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 120 | } |