blob: c7c936e745ebb51f95e2d720a7cf8b2b12f5b4ab [file] [log] [blame]
Sadik Armagan66dedc72019-12-10 16:32:07 +00001//
2// Copyright © 2019 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
Sadik Armagan66dedc72019-12-10 16:32:07 +00006#include "ParserFlatbuffersFixture.hpp"
7#include "../TfLiteParser.hpp"
8
9#include <string>
10#include <iostream>
11
Sadik Armagan1625efc2021-06-10 18:24:34 +010012TEST_SUITE("TensorflowLiteParser_Quantize")
13{
Sadik Armagan66dedc72019-12-10 16:32:07 +000014 struct QuantizeFixture : public ParserFlatbuffersFixture
15 {
16 explicit QuantizeFixture(const std::string & inputShape,
17 const std::string & outputShape,
18 const std::string & dataType)
19 {
20 m_JsonString = R"(
21 {
22 "version": 3,
23 "operator_codes": [ { "builtin_code": "QUANTIZE" } ],
24 "subgraphs": [ {
25 "tensors": [
26 {
27 "shape": )" + inputShape + R"(,
28 "type": "FLOAT32",
29 "buffer": 0,
30 "name": "inputTensor",
31 "quantization": {
32 "min": [ 0.0 ],
33 "max": [ 255.0 ],
34 "scale": [ 1.0 ],
35 "zero_point": [ 0 ],
36 }
37 },
38 {
39 "shape": )" + outputShape + R"( ,
40 "type": )" + dataType + R"(,
41 "buffer": 1,
42 "name": "outputTensor",
43 "quantization": {
44 "min": [ 0.0 ],
45 "max": [ 255.0 ],
46 "scale": [ 1.5 ],
47 "zero_point": [ 0 ],
48 }
49 }
50 ],
51 "inputs": [ 0 ],
52 "outputs": [ 1 ],
53 "operators": [
54 {
55 "opcode_index": 0,
56 "inputs": [ 0 ],
57 "outputs": [ 1 ],
58 "builtin_options_type": "QuantizeOptions",
59 "builtin_options": {
60 },
61 "custom_options_format": "FLEXBUFFERS"
62 }
63 ],
64 } ],
65 "buffers" : [
66 { },
67 { },
68 ]
69 }
70 )";
71 SetupSingleInputSingleOutput("inputTensor", "outputTensor");
72 }
73 };
74
75 struct SimpleQuantizeFixtureQAsymm8 : QuantizeFixture
76 {
77 SimpleQuantizeFixtureQAsymm8() : QuantizeFixture("[ 1, 6 ]",
78 "[ 1, 6 ]",
79 "UINT8") {}
80 };
81
Sadik Armagan1625efc2021-06-10 18:24:34 +010082 TEST_CASE_FIXTURE(SimpleQuantizeQAsymm8, SimpleQuantizeFixtureQAsymm8)
Sadik Armagan66dedc72019-12-10 16:32:07 +000083 {
84 RunTest<2, armnn::DataType::Float32, armnn::DataType::QuantisedAsymm8>(
85 0,
86 {{"inputTensor", { 0.0f, 1.5f, 7.5f, 150.0f, 300.0f, 382.5f }}},
87 {{"outputTensor", { 0u, 1u, 5u, 100u, 200u, 255u }}});
88 }
89
90 struct SimpleQuantizeFixtureQSymm16 : QuantizeFixture
91 {
92 SimpleQuantizeFixtureQSymm16() : QuantizeFixture("[ 1, 6 ]",
93 "[ 1, 6 ]",
94 "INT16") {}
95 };
96
Sadik Armagan1625efc2021-06-10 18:24:34 +010097 TEST_CASE_FIXTURE(SimpleQuantizeFixtureQSymm16, "SimpleQuantizeQsymm16")
Sadik Armagan66dedc72019-12-10 16:32:07 +000098 {
99 RunTest<2, armnn::DataType::Float32, armnn::DataType::QuantisedSymm16>(
100 0,
101 {{"inputTensor", { 0.0f, 1.5f, 7.5f, 49150.5f, -1.5f,-49152.0f }}},
102 {{"outputTensor", { 0, 1, 5, 32767, -1, -32768 }}});
103 }
104
105 struct SimpleQuantizeFixtureQSymmS8 : QuantizeFixture
106 {
107 SimpleQuantizeFixtureQSymmS8() : QuantizeFixture("[ 1, 6 ]",
108 "[ 1, 6 ]",
109 "INT8") {}
110 };
111
Sadik Armagan1625efc2021-06-10 18:24:34 +0100112 TEST_CASE_FIXTURE(SimpleQuantizeFixtureQSymmS8, "SimpleQuantizeQSymmS8")
Sadik Armagan66dedc72019-12-10 16:32:07 +0000113 {
114 RunTest<2, armnn::DataType::Float32, armnn::DataType::QSymmS8>(
115 0,
116 {{"inputTensor", { 0.0f, 1.5f, 7.5f, 190.5f, -192.0f, -1.5f }}},
117 {{"outputTensor", { 0, 1, 5, 127, -128, -1 }}});
118 }
119
Sadik Armagan1625efc2021-06-10 18:24:34 +0100120}