blob: 6b7e9c52baeb58866e2524018ad0f1ad82c7aa2b [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
Sadik Armagan26868492021-01-22 14:25:31 +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_DepthToSpace")
13{
Sadik Armagan26868492021-01-22 14:25:31 +000014struct DepthToSpaceFixture : public ParserFlatbuffersFixture
15{
16 explicit DepthToSpaceFixture(const std::string& inputShape,
17 const std::string& outputShape,
18 const std::string& dataType = "FLOAT32",
19 const std::string& scale = "1.0",
20 const std::string& offset = "0")
21 {
22 m_JsonString = R"(
23 {
24 "version": 3,
25 "operator_codes": [ { "builtin_code": "DEPTH_TO_SPACE" } ],
26 "subgraphs": [ {
27 "tensors": [
28 {
29 "shape": )" + inputShape + R"(,
30 "type": )" + dataType + R"(,
31 "buffer": 0,
32 "name": "inputTensor",
33 "quantization": {
34 "min": [ 0.0 ],
35 "max": [ 255.0 ],
36 "scale": [ )" + scale + R"( ],
37 "zero_point": [ )" + offset + R"( ],
38 }
39 },
40 {
41 "shape": )" + outputShape + R"(,
42 "type": )" + dataType + R"(,
43 "buffer": 1,
44 "name": "outputTensor",
45 "quantization": {
46 "min": [ 0.0 ],
47 "max": [ 255.0 ],
48 "scale": [ )" + scale + R"( ],
49 "zero_point": [ )" + offset + R"( ],
50 }
51 }
52 ],
53 "inputs": [ 0 ],
54 "outputs": [ 1 ],
55 "operators": [
56 {
57 "opcode_index": 0,
58 "inputs": [ 0 ],
59 "outputs": [ 1 ],
60 "builtin_options_type": "DepthToSpaceOptions",
61 "builtin_options": {
62 "block_size": 2
63 },
64 "custom_options_format": "FLEXBUFFERS"
65 }
66 ],
67 } ],
68 "buffers" : [
69 { },
70 { },
71 ]
72 }
73 )";
74 SetupSingleInputSingleOutput("inputTensor", "outputTensor");
75 }
76};
77
78struct SimpleDepthToSpaceFixture : public DepthToSpaceFixture
79{
80 SimpleDepthToSpaceFixture() : DepthToSpaceFixture("[ 1, 2, 2, 4 ]", "[ 1, 4, 4, 1 ]") {}
81};
82
Sadik Armagan1625efc2021-06-10 18:24:34 +010083TEST_CASE_FIXTURE(SimpleDepthToSpaceFixture, "ParseDepthToSpace")
Sadik Armagan26868492021-01-22 14:25:31 +000084{
85 RunTest<4, armnn::DataType::Float32>
86 (0,
87 {{ "inputTensor", { 1.f, 2.f, 3.f, 4.f,
88 5.f, 6.f, 7.f, 8.f,
89 9.f, 10.f, 11.f, 12.f,
90 13.f, 14.f, 15.f, 16.f }}},
91 {{ "outputTensor", { 1.f, 2.f, 5.f, 6.f,
92 3.f, 4.f, 7.f, 8.f,
93 9.f, 10.f, 13.f, 14.f,
94 11.f, 12.f, 15.f, 16.f }}});
95}
96
Sadik Armagan1625efc2021-06-10 18:24:34 +010097}