blob: 1dfc966ec89b846ea65277ada89426709a4c7aaa [file] [log] [blame]
Georgios Pinitas652bde52018-01-10 15:33:28 +00001/*
2 * Copyright (c) 2017-2018 ARM Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#include "arm_compute/graph/Graph.h"
25#include "arm_compute/graph/Nodes.h"
26#include "arm_compute/graph/SubGraph.h"
27#include "support/ToolchainSupport.h"
28#include "utils/GraphUtils.h"
29#include "utils/Utils.h"
30
31#include <cstdlib>
32#include <tuple>
33
34using namespace arm_compute::utils;
35using namespace arm_compute::graph;
36using namespace arm_compute::graph_utils;
37
38/** Example demonstrating how to implement InceptionV3's network using the Compute Library's graph API
39 *
40 * @param[in] argc Number of arguments
41 * @param[in] argv Arguments ( [optional] Path to the weights folder, [optional] image, [optional] labels )
42 */
43class InceptionV3Example : public Example
44{
45public:
46 void do_setup(int argc, char **argv) override
47 {
48 std::string data_path; /* Path to the trainable data */
49 std::string image; /* Image data */
50 std::string label; /* Label data */
51
Georgios Pinitas140fdc72018-02-16 11:42:38 +000052 // Create a preprocessor object
53 std::unique_ptr<IPreprocessor> preprocessor = arm_compute::support::cpp14::make_unique<TFPreproccessor>();
Georgios Pinitas652bde52018-01-10 15:33:28 +000054
Michele Di Giorgioe3fba0a2018-02-14 14:18:01 +000055 // Set target. 0 (NEON), 1 (OpenCL), 2 (OpenCL with Tuner). By default it is NEON
56 const int int_target_hint = argc > 1 ? std::strtol(argv[1], nullptr, 10) : 0;
57 TargetHint target_hint = set_target_hint(int_target_hint);
Georgios Pinitas652bde52018-01-10 15:33:28 +000058
59 // Parse arguments
60 if(argc < 2)
61 {
62 // Print help
63 std::cout << "Usage: " << argv[0] << " [target] [path_to_data] [image] [labels]\n\n";
64 std::cout << "No data folder provided: using random values\n\n";
65 }
66 else if(argc == 2)
67 {
68 std::cout << "Usage: " << argv[0] << " " << argv[1] << " [path_to_data] [image] [labels]\n\n";
69 std::cout << "No data folder provided: using random values\n\n";
70 }
71 else if(argc == 3)
72 {
73 data_path = argv[2];
74 std::cout << "Usage: " << argv[0] << " " << argv[1] << " " << argv[2] << " [image] [labels]\n\n";
75 std::cout << "No image provided: using random values\n\n";
76 }
77 else if(argc == 4)
78 {
79 data_path = argv[2];
80 image = argv[3];
81 std::cout << "Usage: " << argv[0] << " " << argv[1] << " " << argv[2] << " " << argv[3] << " [labels]\n\n";
82 std::cout << "No text file with labels provided: skipping output accessor\n\n";
83 }
84 else
85 {
86 data_path = argv[2];
87 image = argv[3];
88 label = argv[4];
89 }
90
Gian Marco2d405552018-02-05 08:54:54 +000091 graph << target_hint << Tensor(TensorInfo(TensorShape(299U, 299U, 3U, 1U), 1, DataType::F32),
Georgios Pinitas140fdc72018-02-16 11:42:38 +000092 get_input_accessor(image, std::move(preprocessor), false))
Georgios Pinitas652bde52018-01-10 15:33:28 +000093
94 << ConvolutionLayer(3U, 3U, 32U,
95 get_weights_accessor(data_path, "/cnn_data/inceptionv3_model/Conv2d_1a_3x3_weights.npy"),
96 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(2, 2, 0, 0))
97 << BatchNormalizationLayer(get_weights_accessor(data_path,
98 "/cnn_data/inceptionv3_model/Conv2d_1a_3x3_BatchNorm_moving_mean.npy"),
99 get_weights_accessor(data_path,
100 "/cnn_data/inceptionv3_model/Conv2d_1a_3x3_BatchNorm_moving_variance.npy"),
101 get_random_accessor(1.f, 1.f), get_weights_accessor(data_path,
102 "/cnn_data/inceptionv3_model/Conv2d_1a_3x3_BatchNorm_beta.npy"),
Giorgio Arena11674872018-02-07 15:38:12 +0000103 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas652bde52018-01-10 15:33:28 +0000104
105 << ConvolutionLayer(3U, 3U, 32U,
106 get_weights_accessor(data_path, "/cnn_data/inceptionv3_model/Conv2d_2a_3x3_weights.npy"),
107 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
108 << BatchNormalizationLayer(get_weights_accessor(data_path,
109 "/cnn_data/inceptionv3_model/Conv2d_2a_3x3_BatchNorm_moving_mean.npy"),
110 get_weights_accessor(data_path,
111 "/cnn_data/inceptionv3_model/Conv2d_2a_3x3_BatchNorm_moving_variance.npy"),
112 get_random_accessor(1.f, 1.f), get_weights_accessor(data_path,
113 "/cnn_data/inceptionv3_model/Conv2d_2a_3x3_BatchNorm_beta.npy"),
Giorgio Arena11674872018-02-07 15:38:12 +0000114 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas652bde52018-01-10 15:33:28 +0000115
116 << ConvolutionLayer(3U, 3U, 64U,
117 get_weights_accessor(data_path, "/cnn_data/inceptionv3_model/Conv2d_2b_3x3_weights.npy"),
118 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 1, 1))
119 << BatchNormalizationLayer(get_weights_accessor(data_path,
120 "/cnn_data/inceptionv3_model/Conv2d_2b_3x3_BatchNorm_moving_mean.npy"),
121 get_weights_accessor(data_path,
122 "/cnn_data/inceptionv3_model/Conv2d_2b_3x3_BatchNorm_moving_variance.npy"),
123 get_random_accessor(1.f, 1.f), get_weights_accessor(data_path,
124 "/cnn_data/inceptionv3_model/Conv2d_2b_3x3_BatchNorm_beta.npy"),
Giorgio Arena11674872018-02-07 15:38:12 +0000125 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas652bde52018-01-10 15:33:28 +0000126
127 << PoolingLayer(PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL)))
128
129 << ConvolutionLayer(1U, 1U, 80U,
130 get_weights_accessor(data_path, "/cnn_data/inceptionv3_model/Conv2d_3b_1x1_weights.npy"),
131 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
132 << BatchNormalizationLayer(get_weights_accessor(data_path,
133 "/cnn_data/inceptionv3_model/Conv2d_3b_1x1_BatchNorm_moving_mean.npy"),
134 get_weights_accessor(data_path,
135 "/cnn_data/inceptionv3_model/Conv2d_3b_1x1_BatchNorm_moving_variance.npy"),
136 get_random_accessor(1.f, 1.f), get_weights_accessor(data_path,
137 "/cnn_data/inceptionv3_model/Conv2d_3b_1x1_BatchNorm_beta.npy"),
Giorgio Arena11674872018-02-07 15:38:12 +0000138 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas652bde52018-01-10 15:33:28 +0000139
140 << ConvolutionLayer(3U, 3U, 192U,
141 get_weights_accessor(data_path, "/cnn_data/inceptionv3_model/Conv2d_4a_3x3_weights.npy"),
142 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
143 << BatchNormalizationLayer(get_weights_accessor(data_path,
144 "/cnn_data/inceptionv3_model/Conv2d_4a_3x3_BatchNorm_moving_mean.npy"),
145 get_weights_accessor(data_path,
146 "/cnn_data/inceptionv3_model/Conv2d_4a_3x3_BatchNorm_moving_variance.npy"),
147 get_random_accessor(1.f, 1.f), get_weights_accessor(data_path,
148 "/cnn_data/inceptionv3_model/Conv2d_4a_3x3_BatchNorm_beta.npy"),
Giorgio Arena11674872018-02-07 15:38:12 +0000149 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas652bde52018-01-10 15:33:28 +0000150
151 << PoolingLayer(PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL)))
152
153 << get_inception_node_A(data_path, "Mixed_5b", 64U, std::make_tuple(48U, 64U), std::make_tuple(64U, 96U, 96U),
154 32U)
155 << get_inception_node_A(data_path, "Mixed_5c", 64U, std::make_tuple(48U, 64U), std::make_tuple(64U, 96U, 96U),
156 64U, true)
157 << get_inception_node_A(data_path, "Mixed_5d", 64U, std::make_tuple(48U, 64U), std::make_tuple(64U, 96U, 96U),
158 64U)
159
160 << get_inception_node_B(data_path, "Mixed_6a", 384U, std::make_tuple(64U, 96U, 96U))
161
162 << get_inception_node_C(data_path, "Mixed_6b", 192U, std::make_tuple(128U, 128U, 192U),
163 std::make_tuple(128U, 128U, 128U, 128U, 192U), 192U)
164 << get_inception_node_C(data_path, "Mixed_6c", 192U, std::make_tuple(160U, 160U, 192U),
165 std::make_tuple(160U, 160U, 160U, 160U, 192U), 192U)
166 << get_inception_node_C(data_path, "Mixed_6d", 192U, std::make_tuple(160U, 160U, 192U),
167 std::make_tuple(160U, 160U, 160U, 160U, 192U), 192U)
168 << get_inception_node_C(data_path, "Mixed_6e", 192U, std::make_tuple(192U, 192U, 192U),
169 std::make_tuple(192U, 192U, 192U, 192U, 192U), 192U)
170
171 << get_inception_node_D(data_path, "Mixed_7a", std::make_tuple(192U, 320U),
172 std::make_tuple(192U, 192U, 192U, 192U))
173
174 << get_inception_node_E(data_path, "Mixed_7b", 320U, std::make_tuple(384U, 384U, 384U),
175 std::make_tuple(448U, 384U, 384U, 384U), 192U)
176 << get_inception_node_E(data_path, "Mixed_7c", 320U, std::make_tuple(384U, 384U, 384U),
177 std::make_tuple(448U, 384U, 384U, 384U), 192U, true)
178
179 << PoolingLayer(PoolingLayerInfo(PoolingType::AVG, 8, PadStrideInfo(1, 1, 0, 0, DimensionRoundingType::CEIL)))
180 << ConvolutionLayer(1U, 1U, 1001U, get_weights_accessor(data_path,
181 "/cnn_data/inceptionv3_model/Logits_Conv2d_1c_1x1_weights.npy"),
182 get_weights_accessor(data_path,
183 "/cnn_data/inceptionv3_model/Logits_Conv2d_1c_1x1_biases.npy"),
184 PadStrideInfo(1, 1, 0, 0))
185 << ReshapeLayer(TensorShape(1001U)) << SoftmaxLayer()
186 << Tensor(get_output_accessor(label, 5));
Gian Marcoc1b6e372018-02-21 18:03:26 +0000187
188 // In order to enable the OpenCL tuner, graph_init() has to be called only when all nodes have been instantiated
189 graph.graph_init(int_target_hint == 2);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000190 }
191
192 void do_run() override
193 {
194 graph.run();
195 }
196
197private:
198 Graph graph{};
199
200private:
201 BranchLayer get_inception_node_A(const std::string &data_path, std::string &&param_path,
202 unsigned int a_filt,
203 std::tuple<unsigned int, unsigned int> b_filters,
204 std::tuple<unsigned int, unsigned int, unsigned int> c_filters,
205 unsigned int d_filt,
206 bool is_name_different = false)
207 {
208 std::string total_path = "/cnn_data/inceptionv3_model/" + param_path + "_";
209 std::cout << total_path << std::endl;
210
211 // This is due to a naming issue in the tf model
212 std::string conv_id0 = "_0a_";
213 std::string conv_id1 = "2d_0b_";
214 if(is_name_different)
215 {
216 conv_id0 = "_0b_";
217 conv_id1 = "_1_0c_";
218 }
219
220 SubGraph i_a;
221 i_a << ConvolutionLayer(
222 1U, 1U, a_filt,
223 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_weights.npy"),
224 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
225 PadStrideInfo(1, 1, 0, 0))
226 << BatchNormalizationLayer(
227 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
228 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
229 get_random_accessor(1.f, 1.f),
230 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_beta.npy"),
Giorgio Arena11674872018-02-07 15:38:12 +0000231 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000232
233 SubGraph i_b;
234 i_b << ConvolutionLayer(
235 1U, 1U, std::get<0>(b_filters),
236 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d" + conv_id0 + "1x1_weights.npy"),
237 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
238 PadStrideInfo(1, 1, 0, 0))
239 << BatchNormalizationLayer(
240 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d" + conv_id0 + "1x1_BatchNorm_moving_mean.npy"),
241 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d" + conv_id0 + "1x1_BatchNorm_moving_variance.npy"),
242 get_random_accessor(1.f, 1.f),
243 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d" + conv_id0 + "1x1_BatchNorm_beta.npy"),
Giorgio Arena11674872018-02-07 15:38:12 +0000244 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas652bde52018-01-10 15:33:28 +0000245 << ConvolutionLayer(
246 5U, 5U, std::get<1>(b_filters),
247 get_weights_accessor(data_path, total_path + "Branch_1_Conv" + conv_id1 + "5x5_weights.npy"),
248 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
249 PadStrideInfo(1, 1, 2, 2))
250 << BatchNormalizationLayer(
251 get_weights_accessor(data_path, total_path + "Branch_1_Conv" + conv_id1 + "5x5_BatchNorm_moving_mean.npy"),
252 get_weights_accessor(data_path, total_path + "Branch_1_Conv" + conv_id1 + "5x5_BatchNorm_moving_variance.npy"),
253 get_random_accessor(1.f, 1.f),
254 get_weights_accessor(data_path, total_path + "Branch_1_Conv" + conv_id1 + "5x5_BatchNorm_beta.npy"),
Giorgio Arena11674872018-02-07 15:38:12 +0000255 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000256
257 SubGraph i_c;
258 i_c << ConvolutionLayer(
259 1U, 1U, std::get<0>(c_filters),
260 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_weights.npy"),
261 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
262 PadStrideInfo(1, 1, 0, 0))
263 << BatchNormalizationLayer(
264 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
265 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
266 get_random_accessor(1.f, 1.f),
267 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_beta.npy"),
Giorgio Arena11674872018-02-07 15:38:12 +0000268 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas652bde52018-01-10 15:33:28 +0000269 << ConvolutionLayer(
270 3U, 3U, std::get<1>(c_filters),
271 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_weights.npy"),
272 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
273 PadStrideInfo(1, 1, 1, 1))
274 << BatchNormalizationLayer(
275 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_BatchNorm_moving_mean.npy"),
276 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_BatchNorm_moving_variance.npy"),
277 get_random_accessor(1.f, 1.f),
278 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_BatchNorm_beta.npy"),
Giorgio Arena11674872018-02-07 15:38:12 +0000279 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas652bde52018-01-10 15:33:28 +0000280 << ConvolutionLayer(
281 3U, 3U, std::get<2>(c_filters),
282 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_3x3_weights.npy"),
283 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
284 PadStrideInfo(1, 1, 1, 1))
285 << BatchNormalizationLayer(
286 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_3x3_BatchNorm_moving_mean.npy"),
287 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_3x3_BatchNorm_moving_variance.npy"),
288 get_random_accessor(1.f, 1.f),
289 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_3x3_BatchNorm_beta.npy"),
Giorgio Arena11674872018-02-07 15:38:12 +0000290 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000291
292 SubGraph i_d;
293 i_d << PoolingLayer(PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 1, 1, DimensionRoundingType::CEIL), true))
294 << ConvolutionLayer(
295 1U, 1U, d_filt,
296 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_weights.npy"),
297 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
298 PadStrideInfo(1, 1, 0, 0))
299 << BatchNormalizationLayer(
300 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_moving_mean.npy"),
301 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_moving_variance.npy"),
302 get_random_accessor(1.f, 1.f),
303 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_beta.npy"),
Giorgio Arena11674872018-02-07 15:38:12 +0000304 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000305
306 return BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_a), std::move(i_b), std::move(i_c), std::move(i_d));
307 }
308
309 BranchLayer get_inception_node_B(const std::string &data_path, std::string &&param_path,
310 unsigned int a_filt,
311 std::tuple<unsigned int, unsigned int, unsigned int> b_filters)
312 {
313 std::string total_path = "/cnn_data/inceptionv3_model/" + param_path + "_";
314 SubGraph i_a;
315 i_a << ConvolutionLayer(
316 3U, 3U, a_filt,
317 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_1x1_weights.npy"),
318 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
319 PadStrideInfo(2, 2, 0, 0))
320 << BatchNormalizationLayer(
321 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_1x1_BatchNorm_moving_mean.npy"),
322 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_1x1_BatchNorm_moving_variance.npy"),
323 get_random_accessor(1.f, 1.f),
324 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_1x1_BatchNorm_beta.npy"),
Giorgio Arena11674872018-02-07 15:38:12 +0000325 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000326
327 SubGraph i_b;
328 i_b << ConvolutionLayer(
329 1U, 1U, std::get<0>(b_filters),
330 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_weights.npy"),
331 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
332 PadStrideInfo(1, 1, 0, 0))
333 << BatchNormalizationLayer(
334 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
335 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
336 get_random_accessor(1.f, 1.f),
337 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_beta.npy"),
Giorgio Arena11674872018-02-07 15:38:12 +0000338 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas652bde52018-01-10 15:33:28 +0000339 << ConvolutionLayer(
340 3U, 3U, std::get<1>(b_filters),
341 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_3x3_weights.npy"),
342 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
343 PadStrideInfo(1, 1, 1, 1))
344 << BatchNormalizationLayer(
345 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_3x3_BatchNorm_moving_mean.npy"),
346 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_3x3_BatchNorm_moving_variance.npy"),
347 get_random_accessor(1.f, 1.f),
348 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_3x3_BatchNorm_beta.npy"),
Giorgio Arena11674872018-02-07 15:38:12 +0000349 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas652bde52018-01-10 15:33:28 +0000350 << ConvolutionLayer(
351 3U, 3U, std::get<2>(b_filters),
352 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_1x1_weights.npy"),
353 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
354 PadStrideInfo(2, 2, 0, 0))
355 << BatchNormalizationLayer(
356 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_1x1_BatchNorm_moving_mean.npy"),
357 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_1x1_BatchNorm_moving_variance.npy"),
358 get_random_accessor(1.f, 1.f),
359 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_1x1_BatchNorm_beta.npy"),
Giorgio Arena11674872018-02-07 15:38:12 +0000360 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000361
362 SubGraph i_c;
363 i_c << PoolingLayer(PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL)))
364 // TODO (geopin01) : Remove once we understand why a single node graph does not run in CL
365 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LINEAR, 1.f, 0.f));
366
367 return BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_a), std::move(i_b), std::move(i_c));
368 }
369
370 BranchLayer get_inception_node_C(const std::string &data_path, std::string &&param_path,
371 unsigned int a_filt,
372 std::tuple<unsigned int, unsigned int, unsigned int> b_filters,
373 std::tuple<unsigned int, unsigned int, unsigned int, unsigned int, unsigned int> c_filters,
374 unsigned int d_filt)
375 {
376 std::string total_path = "/cnn_data/inceptionv3_model/" + param_path + "_";
377 SubGraph i_a;
378 i_a << ConvolutionLayer(
379 1U, 1U, a_filt,
380 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_weights.npy"),
381 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
382 PadStrideInfo(1, 1, 0, 0))
383 << BatchNormalizationLayer(
384 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
385 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
386 get_random_accessor(1.f, 1.f),
387 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_beta.npy"),
Giorgio Arena11674872018-02-07 15:38:12 +0000388 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000389
390 SubGraph i_b;
391 i_b << ConvolutionLayer(
392 1U, 1U, std::get<0>(b_filters),
393 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_weights.npy"),
394 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
395 PadStrideInfo(1, 1, 0, 0))
396 << BatchNormalizationLayer(
397 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
398 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
399 get_random_accessor(1.f, 1.f),
400 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_beta.npy"),
Giorgio Arena11674872018-02-07 15:38:12 +0000401 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas652bde52018-01-10 15:33:28 +0000402 << ConvolutionLayer(
403 7U, 1U, std::get<1>(b_filters),
404 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_weights.npy"),
405 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
406 PadStrideInfo(1, 1, 3, 0))
407 << BatchNormalizationLayer(
408 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_moving_mean.npy"),
409 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_moving_variance.npy"),
410 get_random_accessor(1.f, 1.f),
411 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_beta.npy"),
Giorgio Arena11674872018-02-07 15:38:12 +0000412 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas652bde52018-01-10 15:33:28 +0000413 << ConvolutionLayer(
414 1U, 7U, std::get<2>(b_filters),
415 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_weights.npy"),
416 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
417 PadStrideInfo(1, 1, 0, 3))
418 << BatchNormalizationLayer(
419 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_moving_mean.npy"),
420 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_moving_variance.npy"),
421 get_random_accessor(1.f, 1.f),
422 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_beta.npy"),
Giorgio Arena11674872018-02-07 15:38:12 +0000423 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000424
425 SubGraph i_c;
426 i_c << ConvolutionLayer(
427 1U, 1U, std::get<0>(c_filters),
428 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_weights.npy"),
429 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
430 PadStrideInfo(1, 1, 0, 0))
431 << BatchNormalizationLayer(
432 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
433 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
434 get_random_accessor(1.f, 1.f),
435 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_beta.npy"),
Giorgio Arena11674872018-02-07 15:38:12 +0000436 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas652bde52018-01-10 15:33:28 +0000437 << ConvolutionLayer(
438 1U, 7U, std::get<1>(c_filters),
439 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_7x1_weights.npy"),
440 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
441 PadStrideInfo(1, 1, 0, 3))
442 << BatchNormalizationLayer(
443 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_7x1_BatchNorm_moving_mean.npy"),
444 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_7x1_BatchNorm_moving_variance.npy"),
445 get_random_accessor(1.f, 1.f),
446 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_7x1_BatchNorm_beta.npy"),
Giorgio Arena11674872018-02-07 15:38:12 +0000447 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas652bde52018-01-10 15:33:28 +0000448 << ConvolutionLayer(
449 7U, 1U, std::get<2>(c_filters),
450 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x7_weights.npy"),
451 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
452 PadStrideInfo(1, 1, 3, 0))
453 << BatchNormalizationLayer(
454 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x7_BatchNorm_moving_mean.npy"),
455 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x7_BatchNorm_moving_variance.npy"),
456 get_random_accessor(1.f, 1.f),
457 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x7_BatchNorm_beta.npy"),
Giorgio Arena11674872018-02-07 15:38:12 +0000458 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas652bde52018-01-10 15:33:28 +0000459 << ConvolutionLayer(
460 1U, 7U, std::get<3>(c_filters),
461 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_7x1_weights.npy"),
462 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
463 PadStrideInfo(1, 1, 0, 3))
464 << BatchNormalizationLayer(
465 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_7x1_BatchNorm_moving_mean.npy"),
466 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_7x1_BatchNorm_moving_variance.npy"),
467 get_random_accessor(1.f, 1.f),
468 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_7x1_BatchNorm_beta.npy"),
Giorgio Arena11674872018-02-07 15:38:12 +0000469 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas652bde52018-01-10 15:33:28 +0000470 << ConvolutionLayer(
471 7U, 1U, std::get<4>(c_filters),
472 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0e_1x7_weights.npy"),
473 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
474 PadStrideInfo(1, 1, 3, 0))
475 << BatchNormalizationLayer(
476 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0e_1x7_BatchNorm_moving_mean.npy"),
477 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0e_1x7_BatchNorm_moving_variance.npy"),
478 get_random_accessor(1.f, 1.f),
479 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0e_1x7_BatchNorm_beta.npy"),
Giorgio Arena11674872018-02-07 15:38:12 +0000480 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000481
482 SubGraph i_d;
483 i_d << PoolingLayer(PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 1, 1, DimensionRoundingType::CEIL), true))
484 << ConvolutionLayer(
485 1U, 1U, d_filt,
486 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_weights.npy"),
487 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
488 PadStrideInfo(1, 1, 0, 0))
489 << BatchNormalizationLayer(
490 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_moving_mean.npy"),
491 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_moving_variance.npy"),
492 get_random_accessor(1.f, 1.f),
493 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_beta.npy"),
Giorgio Arena11674872018-02-07 15:38:12 +0000494 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000495
496 return BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_a), std::move(i_b), std::move(i_c), std::move(i_d));
497 }
498
499 BranchLayer get_inception_node_D(const std::string &data_path, std::string &&param_path,
500 std::tuple<unsigned int, unsigned int> a_filters,
501 std::tuple<unsigned int, unsigned int, unsigned int, unsigned int> b_filters)
502 {
503 std::string total_path = "/cnn_data/inceptionv3_model/" + param_path + "_";
504 SubGraph i_a;
505 i_a << ConvolutionLayer(
506 1U, 1U, std::get<0>(a_filters),
507 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_weights.npy"),
508 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
509 PadStrideInfo(1, 1, 0, 0))
510 << BatchNormalizationLayer(
511 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
512 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
513 get_random_accessor(1.f, 1.f),
514 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_beta.npy"),
Giorgio Arena11674872018-02-07 15:38:12 +0000515 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas652bde52018-01-10 15:33:28 +0000516 << ConvolutionLayer(
517 3U, 3U, std::get<1>(a_filters),
518 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_weights.npy"),
519 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
520 PadStrideInfo(2, 2, 0, 0))
521 << BatchNormalizationLayer(
522 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_BatchNorm_moving_mean.npy"),
523 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_BatchNorm_moving_variance.npy"),
524 get_random_accessor(1.f, 1.f),
525 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_BatchNorm_beta.npy"),
Giorgio Arena11674872018-02-07 15:38:12 +0000526 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000527
528 SubGraph i_b;
529 i_b << ConvolutionLayer(
530 1U, 1U, std::get<0>(b_filters),
531 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_weights.npy"),
532 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
533 PadStrideInfo(1, 1, 0, 0))
534 << BatchNormalizationLayer(
535 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
536 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
537 get_random_accessor(1.f, 1.f),
538 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_beta.npy"),
Giorgio Arena11674872018-02-07 15:38:12 +0000539 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas652bde52018-01-10 15:33:28 +0000540 << ConvolutionLayer(
541 7U, 1U, std::get<1>(b_filters),
542 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_weights.npy"),
543 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
544 PadStrideInfo(1, 1, 3, 0))
545 << BatchNormalizationLayer(
546 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_moving_mean.npy"),
547 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_moving_variance.npy"),
548 get_random_accessor(1.f, 1.f),
549 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_beta.npy"),
Giorgio Arena11674872018-02-07 15:38:12 +0000550 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas652bde52018-01-10 15:33:28 +0000551 << ConvolutionLayer(
552 1U, 7U, std::get<2>(b_filters),
553 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_weights.npy"),
554 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
555 PadStrideInfo(1, 1, 0, 3))
556 << BatchNormalizationLayer(
557 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_moving_mean.npy"),
558 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_moving_variance.npy"),
559 get_random_accessor(1.f, 1.f),
560 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_beta.npy"),
Giorgio Arena11674872018-02-07 15:38:12 +0000561 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas652bde52018-01-10 15:33:28 +0000562 << ConvolutionLayer(
563 3U, 3U, std::get<3>(b_filters),
564 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_3x3_weights.npy"),
565 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
566 PadStrideInfo(2, 2, 0, 0))
567 << BatchNormalizationLayer(
568 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_3x3_BatchNorm_moving_mean.npy"),
569 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_3x3_BatchNorm_moving_variance.npy"),
570 get_random_accessor(1.f, 1.f),
571 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_3x3_BatchNorm_beta.npy"),
Giorgio Arena11674872018-02-07 15:38:12 +0000572 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000573
574 SubGraph i_c;
575 i_c << PoolingLayer(PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL)))
576 // TODO (geopin01) : Remove once we understand why a single node graph does not run in CL
577 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LINEAR, 1.f, 0.f));
578
579 return BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_a), std::move(i_b), std::move(i_c));
580 }
581
582 BranchLayer get_inception_node_E(const std::string &data_path, std::string &&param_path,
583 unsigned int a_filt,
584 std::tuple<unsigned int, unsigned int, unsigned int> b_filters,
585 std::tuple<unsigned int, unsigned int, unsigned int, unsigned int> c_filters,
586 unsigned int d_filt,
587 bool is_name_different = false)
588 {
589 // This is due to a naming issue in the tf model
590 std::string conv_id = "_0b_";
591 if(is_name_different)
592 {
593 conv_id = "_0c_";
594 }
595
596 std::string total_path = "/cnn_data/inceptionv3_model/" + param_path + "_";
597 SubGraph i_a;
598 i_a << ConvolutionLayer(
599 1U, 1U, a_filt,
600 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_weights.npy"),
601 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
602 PadStrideInfo(1, 1, 0, 0))
603 << BatchNormalizationLayer(
604 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
605 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
606 get_random_accessor(1.f, 1.f),
607 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_beta.npy"),
Giorgio Arena11674872018-02-07 15:38:12 +0000608 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000609
610 SubGraph i_b1;
611 i_b1 << ConvolutionLayer(
612 3U, 1U, std::get<1>(b_filters),
613 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x3_weights.npy"),
614 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
615 PadStrideInfo(1, 1, 1, 0))
616 << BatchNormalizationLayer(
617 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x3_BatchNorm_moving_mean.npy"),
618 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x3_BatchNorm_moving_variance.npy"),
619 get_random_accessor(1.f, 1.f),
620 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x3_BatchNorm_beta.npy"),
Giorgio Arena11674872018-02-07 15:38:12 +0000621 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000622
623 SubGraph i_b2;
624 i_b2 << ConvolutionLayer(
625 1U, 3U, std::get<2>(b_filters),
626 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d" + conv_id + "3x1_weights.npy"),
627 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
628 PadStrideInfo(1, 1, 0, 1))
629 << BatchNormalizationLayer(
630 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d" + conv_id + "3x1_BatchNorm_moving_mean.npy"),
631 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d" + conv_id + "3x1_BatchNorm_moving_variance.npy"),
632 get_random_accessor(1.f, 1.f),
633 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d" + conv_id + "3x1_BatchNorm_beta.npy"),
Giorgio Arena11674872018-02-07 15:38:12 +0000634 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000635
636 SubGraph i_b;
637 i_b << ConvolutionLayer(
638 1U, 1U, std::get<0>(b_filters),
639 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_weights.npy"),
640 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
641 PadStrideInfo(1, 1, 0, 0))
642 << BatchNormalizationLayer(
643 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
644 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
645 get_random_accessor(1.f, 1.f),
646 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_beta.npy"),
Giorgio Arena11674872018-02-07 15:38:12 +0000647 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas652bde52018-01-10 15:33:28 +0000648 << BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_b1), std::move(i_b2));
649
650 SubGraph i_c1;
651 i_c1 << ConvolutionLayer(
652 3U, 1U, std::get<2>(c_filters),
653 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x3_weights.npy"),
654 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
655 PadStrideInfo(1, 1, 1, 0))
656 << BatchNormalizationLayer(
657 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x3_BatchNorm_moving_mean.npy"),
658 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x3_BatchNorm_moving_variance.npy"),
659 get_random_accessor(1.f, 1.f),
660 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x3_BatchNorm_beta.npy"),
Giorgio Arena11674872018-02-07 15:38:12 +0000661 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000662
663 SubGraph i_c2;
664 i_c2 << ConvolutionLayer(
665 1U, 3U, std::get<3>(c_filters),
666 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_3x1_weights.npy"),
667 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
668 PadStrideInfo(1, 1, 0, 1))
669 << BatchNormalizationLayer(
670 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_3x1_BatchNorm_moving_mean.npy"),
671 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_3x1_BatchNorm_moving_variance.npy"),
672 get_random_accessor(1.f, 1.f),
673 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_3x1_BatchNorm_beta.npy"),
Giorgio Arena11674872018-02-07 15:38:12 +0000674 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000675
676 SubGraph i_c;
677 i_c << ConvolutionLayer(
678 1U, 1U, std::get<0>(c_filters),
679 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_weights.npy"),
680 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
681 PadStrideInfo(1, 1, 0, 0))
682 << BatchNormalizationLayer(
683 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
684 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
685 get_random_accessor(1.f, 1.f),
686 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_beta.npy"),
Giorgio Arena11674872018-02-07 15:38:12 +0000687 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas652bde52018-01-10 15:33:28 +0000688 << ConvolutionLayer(
689 3U, 3U, std::get<1>(c_filters),
690 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_weights.npy"),
691 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
692 PadStrideInfo(1, 1, 1, 1))
693 << BatchNormalizationLayer(
694 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_BatchNorm_moving_mean.npy"),
695 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_BatchNorm_moving_variance.npy"),
696 get_random_accessor(1.f, 1.f),
697 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_BatchNorm_beta.npy"),
Giorgio Arena11674872018-02-07 15:38:12 +0000698 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas652bde52018-01-10 15:33:28 +0000699 << BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_c1), std::move(i_c2));
700
701 SubGraph i_d;
702 i_d << PoolingLayer(PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 1, 1, DimensionRoundingType::CEIL), true))
703 << ConvolutionLayer(
704 1U, 1U, d_filt,
705 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_weights.npy"),
706 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
707 PadStrideInfo(1, 1, 0, 0))
708 << BatchNormalizationLayer(
709 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_moving_mean.npy"),
710 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_moving_variance.npy"),
711 get_random_accessor(1.f, 1.f),
712 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_beta.npy"),
Giorgio Arena11674872018-02-07 15:38:12 +0000713 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000714
715 return BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_a), std::move(i_b), std::move(i_c), std::move(i_d));
716 }
717};
718
719/** Main program for Inception V3
720 *
721 * @param[in] argc Number of arguments
722 * @param[in] argv Arguments ( [optional] Target (0 = NEON, 1 = OpenCL), [optional] Path to the weights folder, [optional] image, [optional] labels )
723 */
724int main(int argc, char **argv)
725{
726 return arm_compute::utils::run_example<InceptionV3Example>(argc, argv);
727}