Bruno Goncalves | 3d7efe9 | 2018-12-27 14:21:43 -0200 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
Bruno Goncalves | 3d7efe9 | 2018-12-27 14:21:43 -0200 | [diff] [blame] | 6 | #include "ParserFlatbuffersFixture.hpp" |
| 7 | #include "../TfLiteParser.hpp" |
| 8 | |
| 9 | #include <string> |
| 10 | #include <iostream> |
| 11 | |
Kevin May | 7d96b16 | 2021-02-03 17:38:41 +0000 | [diff] [blame] | 12 | using armnnTfLiteParser::TfLiteParserImpl; |
Bruno Goncalves | 3d7efe9 | 2018-12-27 14:21:43 -0200 | [diff] [blame] | 13 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 14 | TEST_SUITE("TensorflowLiteParser_Constant") |
| 15 | { |
Bruno Goncalves | 3d7efe9 | 2018-12-27 14:21:43 -0200 | [diff] [blame] | 16 | struct ConstantAddFixture : public ParserFlatbuffersFixture |
| 17 | { |
| 18 | explicit ConstantAddFixture(const std::string & inputShape, |
| 19 | const std::string & outputShape, |
| 20 | const std::string & constShape, |
| 21 | const std::string & constData) |
| 22 | { |
| 23 | m_JsonString = R"( |
| 24 | { |
| 25 | "version": 3, |
| 26 | "operator_codes": [ { "builtin_code": "ADD" } ], |
| 27 | "subgraphs": [ { |
| 28 | "tensors": [ |
| 29 | { |
| 30 | "shape": )" + constShape + R"( , |
| 31 | "type": "UINT8", |
| 32 | "buffer": 3, |
| 33 | "name": "ConstTensor", |
| 34 | "quantization": { |
| 35 | "min": [ 0.0 ], |
| 36 | "max": [ 255.0 ], |
| 37 | "scale": [ 1.0 ], |
| 38 | "zero_point": [ 0 ], |
| 39 | } |
| 40 | }, |
| 41 | { |
| 42 | "shape": )" + inputShape + R"(, |
| 43 | "type": "UINT8", |
| 44 | "buffer": 1, |
| 45 | "name": "InputTensor", |
| 46 | "quantization": { |
| 47 | "min": [ 0.0 ], |
| 48 | "max": [ 255.0 ], |
| 49 | "scale": [ 1.0 ], |
| 50 | "zero_point": [ 0 ], |
| 51 | } |
| 52 | }, |
| 53 | { |
| 54 | "shape": )" + outputShape + R"( , |
| 55 | "type": "UINT8", |
| 56 | "buffer": 2, |
| 57 | "name": "OutputTensor", |
| 58 | "quantization": { |
| 59 | "min": [ 0.0 ], |
| 60 | "max": [ 255.0 ], |
| 61 | "scale": [ 1.0 ], |
| 62 | "zero_point": [ 0 ], |
| 63 | } |
| 64 | } |
| 65 | ], |
| 66 | "inputs": [ 1 ], |
| 67 | "outputs": [ 2 ], |
| 68 | "operators": [ |
| 69 | { |
| 70 | "opcode_index": 0, |
| 71 | "inputs": [ 1, 0 ], |
| 72 | "outputs": [ 2 ], |
| 73 | "builtin_options_type": "AddOptions", |
| 74 | "builtin_options": { |
| 75 | }, |
| 76 | "custom_options_format": "FLEXBUFFERS" |
| 77 | } |
| 78 | ], |
| 79 | } ], |
| 80 | "buffers" : [ |
| 81 | { }, |
| 82 | { }, |
| 83 | { }, |
| 84 | { "data": )" + constData + R"(, }, |
| 85 | ] |
| 86 | } |
| 87 | )"; |
| 88 | Setup(); |
| 89 | } |
| 90 | }; |
| 91 | |
| 92 | |
| 93 | struct SimpleConstantAddFixture : ConstantAddFixture |
| 94 | { |
| 95 | SimpleConstantAddFixture() |
| 96 | : ConstantAddFixture("[ 2, 2 ]", // inputShape |
| 97 | "[ 2, 2 ]", // outputShape |
| 98 | "[ 2, 2 ]", // constShape |
| 99 | "[ 4,5, 6,7 ]") // constData |
| 100 | {} |
| 101 | }; |
| 102 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 103 | TEST_CASE_FIXTURE(SimpleConstantAddFixture, "SimpleConstantAdd") |
Bruno Goncalves | 3d7efe9 | 2018-12-27 14:21:43 -0200 | [diff] [blame] | 104 | { |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 105 | RunTest<2, armnn::DataType::QAsymmU8>( |
Bruno Goncalves | 3d7efe9 | 2018-12-27 14:21:43 -0200 | [diff] [blame] | 106 | 0, |
| 107 | {{"InputTensor", { 0, 1, 2, 3 }}}, |
| 108 | {{"OutputTensor", { 4, 6, 8, 10 }}} |
| 109 | ); |
| 110 | } |
| 111 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 112 | } |