• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "ParserFlatbuffersFixture.hpp"
7 
8 TEST_SUITE("TensorflowLiteParser_LRN")
9 {
10 struct LRNFixture : public ParserFlatbuffersFixture
11 {
LRNFixtureLRNFixture12     explicit LRNFixture(std::string inputdim, std::string outputdim, std::string dataType)
13     {
14         m_JsonString = R"(
15         {
16             "version": 3,
17             "operator_codes": [ { "builtin_code": "LOCAL_RESPONSE_NORMALIZATION" } ],
18             "subgraphs": [
19             {
20                 "tensors": [
21                 {
22                     "shape": )"
23                        + outputdim
24                        + R"(,
25                     "type": )"
26                        + dataType
27                        + R"(,
28                             "buffer": 0,
29                             "name": "OutputTensor",
30                             "quantization": {
31                                 "min": [ 0.0 ],
32                                 "max": [ 255.0 ],
33                                 "scale": [ 1.0 ],
34                                 "zero_point": [ 0 ]
35                             }
36                 },
37                 {
38                     "shape": )"
39                        + inputdim
40                        + R"(,
41                     "type": )"
42                        + dataType
43                        + R"(,
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                 "inputs": [ 1 ],
55                 "outputs": [ 0 ],
56                 "operators": [ {
57                         "opcode_index": 0,
58                         "inputs": [ 1 ],
59                         "outputs": [ 0 ],
60                         "builtin_options_type": "LocalResponseNormalizationOptions",
61                         "builtin_options":
62                         {
63                             "radius": 2,
64                             "bias": 1.0,
65                             "alpha": 1.0,
66                             "beta": 0.5
67                         },
68                         "custom_options_format": "FLEXBUFFERS"
69                     } ]
70                 }
71             ],
72             "description": "MaxPool2D test.",
73             "buffers" : [ {}, {} ]
74         })";
75 
76         SetupSingleInputSingleOutput("InputTensor", "OutputTensor");
77     }
78 };
79 
80 struct LRNLiteFixtureFloat4DOutput : LRNFixture
81 {
LRNLiteFixtureFloat4DOutputLRNLiteFixtureFloat4DOutput82     LRNLiteFixtureFloat4DOutput() : LRNFixture("[ 1, 1, 4, 4 ]", "[ 1, 1, 4, 4 ]", "FLOAT32") {}
83 };
84 
85 TEST_CASE_FIXTURE(LRNLiteFixtureFloat4DOutput, "LRNLiteFloat4DOutput")
86 {
87     RunTest<4, armnn::DataType::Float32>(0,
88                                          {
89                                              2.0f, 3.0f, 5.0f, 2.0f,
90                                              2.0f, 3.0f, 5.0f, 2.0f,
91                                              2.0f, 3.0f, 5.0f, 2.0f,
92                                              2.0f, 3.0f, 5.0f, 2.0f
93                                          },
94                                          {
95                                              0.320256f, 0.457496f, 0.762493f, 0.320256f,
96                                              0.320256f, 0.457496f, 0.762493f, 0.320256f,
97                                              0.320256f, 0.457496f, 0.762493f, 0.320256f,
98                                              0.320256f, 0.457496f, 0.762493f, 0.320256f
99                                          });
100 }
101 
102 TEST_CASE_FIXTURE(LRNLiteFixtureFloat4DOutput, "LRNIncorrectDataTypeError")
103 {
104     CHECK_THROWS_AS((RunTest<4, armnn::DataType::QAsymmU8>(0, { 2, 3, 5, 2 }, { 5 })), armnn::Exception);
105 }
106 
107 }
108