blob: 6de6fe543bb9f6844c4d3649813f89dc81ef3a10 [file] [log] [blame]
Finn Williamsed66d142019-12-06 09:55:55 +00001//
2// Copyright © 2019 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
Finn Williamsed66d142019-12-06 09:55:55 +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_Dequantize")
13{
Finn Williamsed66d142019-12-06 09:55:55 +000014 struct DequantizeFixture : public ParserFlatbuffersFixture
15 {
16 explicit DequantizeFixture(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": "DEQUANTIZE" } ],
24 "subgraphs": [ {
25 "tensors": [
26 {
27 "shape": )" + inputShape + R"(,
28 "type": )" + dataType + R"(,
29 "buffer": 0,
30 "name": "inputTensor",
31 "quantization": {
32 "min": [ 0.0 ],
33 "max": [ 255.0 ],
34 "scale": [ 1.5 ],
35 "zero_point": [ 0 ],
36 }
37 },
38 {
39 "shape": )" + outputShape + R"( ,
40 "type": "FLOAT32",
41 "buffer": 1,
42 "name": "outputTensor",
43 "quantization": {
44 "min": [ 0.0 ],
45 "max": [ 255.0 ],
46 "scale": [ 1.0 ],
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": "DequantizeOptions",
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 SimpleDequantizeFixtureQAsymm8 : DequantizeFixture
76 {
77 SimpleDequantizeFixtureQAsymm8() : DequantizeFixture("[ 1, 6 ]",
78 "[ 1, 6 ]",
79 "UINT8") {}
80 };
81
Sadik Armagan1625efc2021-06-10 18:24:34 +010082 TEST_CASE_FIXTURE(SimpleDequantizeFixtureQAsymm8, "SimpleDequantizeQAsymm8")
Finn Williamsed66d142019-12-06 09:55:55 +000083 {
Derek Lambertif90c56d2020-01-10 17:14:08 +000084 RunTest<2, armnn::DataType::QAsymmU8 , armnn::DataType::Float32>(
Finn Williamsed66d142019-12-06 09:55:55 +000085 0,
86 {{"inputTensor", { 0u, 1u, 5u, 100u, 200u, 255u }}},
87 {{"outputTensor", { 0.0f, 1.5f, 7.5f, 150.0f, 300.0f, 382.5f }}});
88 }
89
90 struct SimpleDequantizeFixtureQSymm16 : DequantizeFixture
91 {
92 SimpleDequantizeFixtureQSymm16() : DequantizeFixture("[ 1, 6 ]",
93 "[ 1, 6 ]",
94 "INT16") {}
95 };
96
Sadik Armagan1625efc2021-06-10 18:24:34 +010097 TEST_CASE_FIXTURE(SimpleDequantizeFixtureQSymm16, "SimpleDequantizeQsymm16")
Finn Williamsed66d142019-12-06 09:55:55 +000098 {
Derek Lambertif90c56d2020-01-10 17:14:08 +000099 RunTest<2, armnn::DataType::QSymmS16 , armnn::DataType::Float32>(
Finn Williamsed66d142019-12-06 09:55:55 +0000100 0,
101 {{"inputTensor", { 0, 1, 5, 32767, -1, -32768 }}},
102 {{"outputTensor", { 0.0f, 1.5f, 7.5f, 49150.5f, -1.5f,-49152.0f }}});
103 }
104
Keith Davis67e6c542020-02-19 10:08:33 +0000105 struct SimpleDequantizeFixtureQAsymmS8 : DequantizeFixture
Finn Williamsed66d142019-12-06 09:55:55 +0000106 {
Keith Davis67e6c542020-02-19 10:08:33 +0000107 SimpleDequantizeFixtureQAsymmS8() : DequantizeFixture("[ 1, 6 ]",
Finn Williamsed66d142019-12-06 09:55:55 +0000108 "[ 1, 6 ]",
109 "INT8") {}
110 };
111
Sadik Armagan1625efc2021-06-10 18:24:34 +0100112 TEST_CASE_FIXTURE(SimpleDequantizeFixtureQAsymmS8, "SimpleDequantizeQAsymmS8")
Finn Williamsed66d142019-12-06 09:55:55 +0000113 {
Keith Davis67e6c542020-02-19 10:08:33 +0000114 RunTest<2, armnn::DataType::QAsymmS8 , armnn::DataType::Float32>(
Finn Williamsed66d142019-12-06 09:55:55 +0000115 0,
116 {{"inputTensor", { 0, 1, 5, 127, -128, -1 }}},
117 {{"outputTensor", { 0.0f, 1.5f, 7.5f, 190.5f, -192.0f, -1.5f }}});
118 }
119
Sadik Armagan1625efc2021-06-10 18:24:34 +0100120}