aboutsummaryrefslogtreecommitdiff
path: root/src/armnnTfParser/test/DepthwiseConvolution2d.cpp
blob: 84e7a7e7a94fc22a6948ff50f825656271b1e531 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
//
// Copyright © 2017 Arm Ltd. All rights reserved.
// See LICENSE file in the project root for full license information.
//

#include <boost/test/unit_test.hpp>
#include "armnnTfParser/ITfParser.hpp"
#include "ParserPrototxtFixture.hpp"
#include <string>
#include <iostream>

BOOST_AUTO_TEST_SUITE(TensorflowParser)

struct DepthwiseConvolution2dFixture : public ParserPrototxtFixture<armnnTfParser::ITfParser>
{
    explicit DepthwiseConvolution2dFixture(const char* paddingType)
    {
        m_Prototext = "node { \n"
                      "    name: \"graphInput\" \n"
                      "    op: \"Placeholder\" \n"
                      "    attr { \n"
                      "      key: \"dtype\" \n"
                      "      value { \n"
                      "        type: DT_FLOAT \n"
                      "      } \n"
                      "    } \n"
                      "    attr { \n"
                      "      key: \"value\" \n"
                      "      value { \n"
                      "        tensor { \n"
                      "          dtype: DT_FLOAT \n"
                      "          tensor_shape { \n"
                      "            dim { \n"
                      "              size: 1 \n"
                      "            } \n"
                      "            dim { \n"
                      "              size: 1 \n"
                      "            } \n"
                      "            dim { \n"
                      "              size: 3 \n"
                      "            } \n"
                      "            dim { \n"
                      "              size: 3 \n"
                      "            } \n"
                      "          } \n"
                      "          tensor_content: \"\\000\\000\\200?\\000\\000\\000@\\000\\000@@\\000\\000\\200@"
                      "\\000\\000\\240@\\000\\000\\300@\\000\\000\\340@\\000\\000\\000A\\000\\000\\020A\" \n"
                      "        } \n"
                      "      } \n"
                      "    } \n"
                      "  } \n"
                      "  node { \n"
                      "  name: \"Const_1\" \n"
                      "  op: \"Const\" \n"
                      "  attr { \n"
                      "    key: \"dtype\" \n"
                      "    value { \n"
                      "      type: DT_FLOAT \n"
                      "    } \n"
                      "  } \n"
                      "  attr { \n"
                      "    key: \"value\" \n"
                      "    value { \n"
                      "      tensor { \n"
                      "        dtype: DT_FLOAT \n"
                      "        tensor_shape { \n"
                      "          dim { \n"
                      "            size: 1 \n"
                      "          } \n"
                      "          dim { \n"
                      "            size: 3 \n"
                      "          } \n"
                      "          dim { \n"
                      "            size: 3 \n"
                      "          } \n"
                      "          dim { \n"
                      "            size: 3 \n"
                      "          } \n"
                      "        } \n"
                      "        tensor_content: \"\\000\\000\\000?\\000\\000\\200?\\000\\000\\000?"
                      "\\000\\000\\000?\\000\\000\\200?\\000\\000\\000?"
                      "\\000\\000\\000?\\000\\000\\200?\\000\\000\\000?"
                      "\\000\\000\\000?\\000\\000\\200?\\000\\000\\000?"
                      "\\000\\000\\000?\\000\\000\\200?\\000\\000\\000?"
                      "\\000\\000\\000?\\000\\000\\200?\\000\\000\\000?"
                      "\\000\\000\\000?\\000\\000\\200?\\000\\000\\000?"
                      "\\000\\000\\000?\\000\\000\\200?\\000\\000\\000?"
                      "\\000\\000\\000?\\000\\000\\200?\\000\\000\\000?\" \n"
                      "      } \n"
                      "    } \n"
                      "  } \n"
                      "} \n"
                      "node { \n"
                      "  name: \"potato\" \n"
                      "  op: \"DepthwiseConv2dNative\" \n"
                      "  input: \"graphInput\" \n"
                      "  input: \"Const_1\" \n"
                      "  attr { \n"
                      "    key: \"T\" \n"
                      "    value { \n"
                      "      type: DT_FLOAT \n"
                      "    } \n"
                      "  } \n"
                      "  attr { \n"
                      "    key: \"data_format\" \n"
                      "    value { \n"
                      "      s: \"NHWC\" \n"
                      "    } \n"
                      "  } \n"
                      "  attr { \n"
                      "    key: \"padding\" \n"
                      "    value { \n"
                      "      s: \"";
        m_Prototext.append(paddingType);
        m_Prototext.append("\"\n"
                      "    } \n"
                      "  } \n"
                      "  attr { \n"
                      "    key: \"strides\" \n"
                      "    value { \n"
                      "      list { \n"
                      "        i: 1 \n"
                      "        i: 1 \n"
                      "        i: 1 \n"
                      "        i: 1 \n"
                      "      } \n"
                      "    } \n"
                      "  } \n"
                      "  attr { \n"
                      "    key: \"use_cudnn_on_gpu\" \n"
                      "    value { \n"
                      "      b: false \n"
                      "    } \n"
                      "  } \n"
                      "} \n");

        SetupSingleInputSingleOutput({ 1, 1, 3, 3 }, "graphInput", "potato");
    }
};

struct DepthwiseConvolution2dSameFixture : DepthwiseConvolution2dFixture
{
    DepthwiseConvolution2dSameFixture() : DepthwiseConvolution2dFixture("SAME") { }
};

BOOST_FIXTURE_TEST_CASE(ParseDepthwiseConv2DSame, DepthwiseConvolution2dSameFixture)
{
    RunTest<4>({ 1, 2, 3, 4, 5, 6, 7, 8, 9 },
               { 2.5f, 5.f,  2.5f, 3.5f, 7.f,  3.5f, 4.5f, 9.f,  4.5f,
                 6.f,  12.f, 6.f,  7.5f, 15.f, 7.5f, 9.f,  18.f, 9.f,
                 5.5f, 11.f, 5.5f, 6.5f, 13.f, 6.5f, 7.5f, 15.f, 7.5f});
}

struct DepthwiseConvolution2dValidFixture : DepthwiseConvolution2dFixture
{
    DepthwiseConvolution2dValidFixture() : DepthwiseConvolution2dFixture("VALID") { }
};

BOOST_FIXTURE_TEST_CASE(ParseDepthwiseConv2DValid, DepthwiseConvolution2dValidFixture)
{
    RunTest<4>({ 1, 2, 3, 4, 5, 6, 7, 8, 9 }, // input data
               { 6.f,  12.f, 6.f,  7.5f, 15.f, 7.5f, 9.f,  18.f, 9.f });  // output expected data
}


BOOST_AUTO_TEST_SUITE_END()