2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // See LICENSE file in the project root for full license information.
6 #include <boost/test/unit_test.hpp>
7 #include "ParserFlatbuffersFixture.hpp"
8 #include "../TfLiteParser.hpp"
13 BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
15 struct DepthwiseConvolution2dFixture : public ParserFlatbuffersFixture
17 explicit DepthwiseConvolution2dFixture(const std::string& inputShape,
18 const std::string& outputShape,
19 const std::string& filterShape,
20 const std::string& filterData,
21 const std::string& strides,
22 const std::string& paddingType,
23 const std::string biasShape = "",
24 const std::string biasData = "")
26 std::string inputTensors = "[ 0, 2 ]";
27 std::string biasTensor = "";
28 std::string biasBuffer = "";
29 if (biasShape.size() > 0 && biasData.size() > 0)
31 inputTensors = "[ 0, 2, 3 ]";
34 "shape": )" + biasShape + R"( ,
46 { "data": )" + biasData + R"(, }, )";
51 "operator_codes": [ { "builtin_code": "DEPTHWISE_CONV_2D" } ],
55 "shape": )" + inputShape + R"(,
58 "name": "inputTensor",
67 "shape": )" + outputShape + R"(,
70 "name": "outputTensor",
79 "shape": )" + filterShape + R"(,
82 "name": "filterTensor",
89 }, )" + biasTensor + R"(
96 "inputs": )" + inputTensors + R"(,
98 "builtin_options_type": "DepthwiseConv2DOptions",
100 "padding": ")" + paddingType + R"(",
101 "stride_w": )" + strides+ R"(,
102 "stride_h": )" + strides+ R"(,
103 "depth_multiplier": 1,
104 "fused_activation_function": "NONE"
106 "custom_options_format": "FLEXBUFFERS"
113 { "data": )" + filterData + R"(, }, )"
118 SetupSingleInputSingleOutput("inputTensor", "outputTensor");
122 struct DepthwiseConvolution2dSameFixture : DepthwiseConvolution2dFixture
124 DepthwiseConvolution2dSameFixture()
125 : DepthwiseConvolution2dFixture("[ 1, 3, 3, 1 ]", // inputShape
126 "[ 1, 3, 3, 1 ]", // outputShape
127 "[ 1, 3, 3, 1 ]", // filterShape
128 "[ 9,8,7, 6,5,4, 3,2,1 ]", // filterData
129 "1", // stride w and h
130 "SAME") // padding type
134 BOOST_FIXTURE_TEST_CASE(ParseDepthwiseConv2DSame, DepthwiseConvolution2dSameFixture)
141 // the expected values were generated using the example python implementation at
142 // https://eli.thegreenplace.net/2018/depthwise-separable-convolutions-for-machine-learning/
143 // divide the expected values by the output scale, as it is not 1.0
146 110/2, 197/2, 158/2 });
149 struct DepthwiseConvolution2dValidFixture : DepthwiseConvolution2dFixture
151 DepthwiseConvolution2dValidFixture ()
152 : DepthwiseConvolution2dFixture("[ 1, 3, 3, 1 ]", // inputShape
153 "[ 1, 1, 1, 1 ]", // outputShape
154 "[ 1, 3, 3, 1 ]", // filterShape
155 "[ 9,8,7, 6,5,4, 3,2,1 ]", // filterData
156 "1", // stride w and h
157 "VALID") // padding type
161 BOOST_FIXTURE_TEST_CASE(ParseDepthwiseConv2DValid, DepthwiseConvolution2dValidFixture)
168 // divide the expected values by the output scale, as it is not 1.0
172 struct DepthwiseConvolution2dSameBiasFixture : DepthwiseConvolution2dFixture
174 DepthwiseConvolution2dSameBiasFixture()
175 : DepthwiseConvolution2dFixture("[ 1, 3, 3, 1 ]", // inputShape
176 "[ 1, 3, 3, 1 ]", // outputShape
177 "[ 1, 3, 3, 1 ]", // filterShape
178 "[ 9,8,7, 6,5,4, 3,2,1 ]", // filterData
179 "1", // stride w and h
180 "SAME", // padding type
181 "[ 1 ]", // biasShape
182 "[ 10, 0, 0, 0 ]") // biasData
186 BOOST_FIXTURE_TEST_CASE(ParseDepthwiseConv2DSameBias, DepthwiseConvolution2dSameBiasFixture)
193 // divide the expected values by the output scale, as it is not 1.0
194 { ( 14+10)/2, ( 35+10)/2, ( 38+10)/2,
195 ( 57+10)/2, (120+10)/2, (111+10)/2,
196 (110+10)/2, (197+10)/2, (158+10)/2 });
199 BOOST_AUTO_TEST_SUITE_END()