blob: efd12072978937cab2d37f62d013a6abfc0caa20 [file] [log] [blame]
Sadik Armagan26868492021-01-22 14:25:31 +00001//
2// Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include <boost/test/unit_test.hpp>
7#include "ParserFlatbuffersFixture.hpp"
8#include "../TfLiteParser.hpp"
9
10#include <string>
11#include <iostream>
12
13BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
14
15struct DepthToSpaceFixture : public ParserFlatbuffersFixture
16{
17 explicit DepthToSpaceFixture(const std::string& inputShape,
18 const std::string& outputShape,
19 const std::string& dataType = "FLOAT32",
20 const std::string& scale = "1.0",
21 const std::string& offset = "0")
22 {
23 m_JsonString = R"(
24 {
25 "version": 3,
26 "operator_codes": [ { "builtin_code": "DEPTH_TO_SPACE" } ],
27 "subgraphs": [ {
28 "tensors": [
29 {
30 "shape": )" + inputShape + R"(,
31 "type": )" + dataType + R"(,
32 "buffer": 0,
33 "name": "inputTensor",
34 "quantization": {
35 "min": [ 0.0 ],
36 "max": [ 255.0 ],
37 "scale": [ )" + scale + R"( ],
38 "zero_point": [ )" + offset + R"( ],
39 }
40 },
41 {
42 "shape": )" + outputShape + R"(,
43 "type": )" + dataType + R"(,
44 "buffer": 1,
45 "name": "outputTensor",
46 "quantization": {
47 "min": [ 0.0 ],
48 "max": [ 255.0 ],
49 "scale": [ )" + scale + R"( ],
50 "zero_point": [ )" + offset + R"( ],
51 }
52 }
53 ],
54 "inputs": [ 0 ],
55 "outputs": [ 1 ],
56 "operators": [
57 {
58 "opcode_index": 0,
59 "inputs": [ 0 ],
60 "outputs": [ 1 ],
61 "builtin_options_type": "DepthToSpaceOptions",
62 "builtin_options": {
63 "block_size": 2
64 },
65 "custom_options_format": "FLEXBUFFERS"
66 }
67 ],
68 } ],
69 "buffers" : [
70 { },
71 { },
72 ]
73 }
74 )";
75 SetupSingleInputSingleOutput("inputTensor", "outputTensor");
76 }
77};
78
79struct SimpleDepthToSpaceFixture : public DepthToSpaceFixture
80{
81 SimpleDepthToSpaceFixture() : DepthToSpaceFixture("[ 1, 2, 2, 4 ]", "[ 1, 4, 4, 1 ]") {}
82};
83
84BOOST_FIXTURE_TEST_CASE(ParseDepthToSpace, SimpleDepthToSpaceFixture)
85{
86 RunTest<4, armnn::DataType::Float32>
87 (0,
88 {{ "inputTensor", { 1.f, 2.f, 3.f, 4.f,
89 5.f, 6.f, 7.f, 8.f,
90 9.f, 10.f, 11.f, 12.f,
91 13.f, 14.f, 15.f, 16.f }}},
92 {{ "outputTensor", { 1.f, 2.f, 5.f, 6.f,
93 3.f, 4.f, 7.f, 8.f,
94 9.f, 10.f, 13.f, 14.f,
95 11.f, 12.f, 15.f, 16.f }}});
96}
97
98BOOST_AUTO_TEST_SUITE_END()