blob: ed79ba65d856cd83f31e3c6fe91d8ad51099c85f [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 */
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010024#include "arm_compute/graph.h"
Georgios Pinitas652bde52018-01-10 15:33:28 +000025#include "support/ToolchainSupport.h"
26#include "utils/GraphUtils.h"
27#include "utils/Utils.h"
28
29#include <cstdlib>
30#include <tuple>
31
32using namespace arm_compute::utils;
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010033using namespace arm_compute::graph::frontend;
Georgios Pinitas652bde52018-01-10 15:33:28 +000034using namespace arm_compute::graph_utils;
35
36/** Example demonstrating how to implement InceptionV3's network using the Compute Library's graph API
37 *
38 * @param[in] argc Number of arguments
Georgios Pinitasd8734b52017-12-22 15:27:52 +000039 * @param[in] argv Arguments ( [optional] Path to the weights folder, [optional] image, [optional] labels )
Georgios Pinitas652bde52018-01-10 15:33:28 +000040 */
Georgios Pinitasd8734b52017-12-22 15:27:52 +000041class InceptionV3Example : public Example
Georgios Pinitas652bde52018-01-10 15:33:28 +000042{
43public:
44 void do_setup(int argc, char **argv) override
45 {
46 std::string data_path; /* Path to the trainable data */
47 std::string image; /* Image data */
48 std::string label; /* Label data */
49
Georgios Pinitas140fdc72018-02-16 11:42:38 +000050 // Create a preprocessor object
51 std::unique_ptr<IPreprocessor> preprocessor = arm_compute::support::cpp14::make_unique<TFPreproccessor>();
Georgios Pinitas652bde52018-01-10 15:33:28 +000052
Michele Di Giorgioe3fba0a2018-02-14 14:18:01 +000053 // Set target. 0 (NEON), 1 (OpenCL), 2 (OpenCL with Tuner). By default it is NEON
Georgios Pinitas9a8c6722018-03-21 17:52:35 +000054 const int target = argc > 1 ? std::strtol(argv[1], nullptr, 10) : 0;
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010055 Target target_hint = set_target_hint(target);
Georgios Pinitas652bde52018-01-10 15:33:28 +000056
Georgios Pinitas28705162018-03-21 20:10:53 +000057 ConvolutionMethod convolution_hint = (target_hint == Target::CL) ? ConvolutionMethod::WINOGRAD : ConvolutionMethod::GEMM;
58
Georgios Pinitas652bde52018-01-10 15:33:28 +000059 // 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
Georgios Pinitasd8734b52017-12-22 15:27:52 +000091 graph << target_hint << InputLayer(TensorDescriptor(TensorShape(299U, 299U, 3U, 1U), DataType::F32),
92 get_input_accessor(image, std::move(preprocessor), false))
Georgios Pinitas652bde52018-01-10 15:33:28 +000093 << ConvolutionLayer(3U, 3U, 32U,
94 get_weights_accessor(data_path, "/cnn_data/inceptionv3_model/Conv2d_1a_3x3_weights.npy"),
95 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(2, 2, 0, 0))
96 << BatchNormalizationLayer(get_weights_accessor(data_path,
97 "/cnn_data/inceptionv3_model/Conv2d_1a_3x3_BatchNorm_moving_mean.npy"),
98 get_weights_accessor(data_path,
99 "/cnn_data/inceptionv3_model/Conv2d_1a_3x3_BatchNorm_moving_variance.npy"),
100 get_random_accessor(1.f, 1.f), get_weights_accessor(data_path,
101 "/cnn_data/inceptionv3_model/Conv2d_1a_3x3_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000102 0.001f)
103 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas28705162018-03-21 20:10:53 +0000104 << convolution_hint
Georgios Pinitas652bde52018-01-10 15:33:28 +0000105 << 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"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000114 0.001f)
115 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas652bde52018-01-10 15:33:28 +0000116
117 << ConvolutionLayer(3U, 3U, 64U,
118 get_weights_accessor(data_path, "/cnn_data/inceptionv3_model/Conv2d_2b_3x3_weights.npy"),
119 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 1, 1))
120 << BatchNormalizationLayer(get_weights_accessor(data_path,
121 "/cnn_data/inceptionv3_model/Conv2d_2b_3x3_BatchNorm_moving_mean.npy"),
122 get_weights_accessor(data_path,
123 "/cnn_data/inceptionv3_model/Conv2d_2b_3x3_BatchNorm_moving_variance.npy"),
124 get_random_accessor(1.f, 1.f), get_weights_accessor(data_path,
125 "/cnn_data/inceptionv3_model/Conv2d_2b_3x3_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000126 0.001f)
127 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas652bde52018-01-10 15:33:28 +0000128
129 << PoolingLayer(PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL)))
130
131 << ConvolutionLayer(1U, 1U, 80U,
132 get_weights_accessor(data_path, "/cnn_data/inceptionv3_model/Conv2d_3b_1x1_weights.npy"),
133 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
134 << BatchNormalizationLayer(get_weights_accessor(data_path,
135 "/cnn_data/inceptionv3_model/Conv2d_3b_1x1_BatchNorm_moving_mean.npy"),
136 get_weights_accessor(data_path,
137 "/cnn_data/inceptionv3_model/Conv2d_3b_1x1_BatchNorm_moving_variance.npy"),
138 get_random_accessor(1.f, 1.f), get_weights_accessor(data_path,
139 "/cnn_data/inceptionv3_model/Conv2d_3b_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000140 0.001f)
141 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas652bde52018-01-10 15:33:28 +0000142
143 << ConvolutionLayer(3U, 3U, 192U,
144 get_weights_accessor(data_path, "/cnn_data/inceptionv3_model/Conv2d_4a_3x3_weights.npy"),
145 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
146 << BatchNormalizationLayer(get_weights_accessor(data_path,
147 "/cnn_data/inceptionv3_model/Conv2d_4a_3x3_BatchNorm_moving_mean.npy"),
148 get_weights_accessor(data_path,
149 "/cnn_data/inceptionv3_model/Conv2d_4a_3x3_BatchNorm_moving_variance.npy"),
150 get_random_accessor(1.f, 1.f), get_weights_accessor(data_path,
151 "/cnn_data/inceptionv3_model/Conv2d_4a_3x3_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000152 0.001f)
153 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas652bde52018-01-10 15:33:28 +0000154
Georgios Pinitas41c482d2018-04-17 13:23:26 +0100155 << PoolingLayer(PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL)));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000156
Georgios Pinitas41c482d2018-04-17 13:23:26 +0100157 graph << get_inception_node_A(data_path, "Mixed_5b", 64U, std::make_tuple(48U, 64U), std::make_tuple(64U, 96U, 96U),
158 32U);
159 graph << get_inception_node_A(data_path, "Mixed_5c", 64U, std::make_tuple(48U, 64U), std::make_tuple(64U, 96U, 96U),
160 64U, true);
161 graph << get_inception_node_A(data_path, "Mixed_5d", 64U, std::make_tuple(48U, 64U), std::make_tuple(64U, 96U, 96U),
162 64U);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000163
Georgios Pinitas41c482d2018-04-17 13:23:26 +0100164 graph << get_inception_node_B(data_path, "Mixed_6a", 384U, std::make_tuple(64U, 96U, 96U));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000165
Georgios Pinitas41c482d2018-04-17 13:23:26 +0100166 graph << get_inception_node_C(data_path, "Mixed_6b", 192U, std::make_tuple(128U, 128U, 192U),
167 std::make_tuple(128U, 128U, 128U, 128U, 192U), 192U);
168 graph << get_inception_node_C(data_path, "Mixed_6c", 192U, std::make_tuple(160U, 160U, 192U),
169 std::make_tuple(160U, 160U, 160U, 160U, 192U), 192U);
170 graph << get_inception_node_C(data_path, "Mixed_6d", 192U, std::make_tuple(160U, 160U, 192U),
171 std::make_tuple(160U, 160U, 160U, 160U, 192U), 192U);
172 graph << get_inception_node_C(data_path, "Mixed_6e", 192U, std::make_tuple(192U, 192U, 192U),
173 std::make_tuple(192U, 192U, 192U, 192U, 192U), 192U);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000174
Georgios Pinitas41c482d2018-04-17 13:23:26 +0100175 graph << get_inception_node_D(data_path, "Mixed_7a", std::make_tuple(192U, 320U),
176 std::make_tuple(192U, 192U, 192U, 192U));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000177
Georgios Pinitas41c482d2018-04-17 13:23:26 +0100178 graph << get_inception_node_E(data_path, "Mixed_7b", 320U, std::make_tuple(384U, 384U, 384U),
179 std::make_tuple(448U, 384U, 384U, 384U), 192U);
180 graph << get_inception_node_E(data_path, "Mixed_7c", 320U, std::make_tuple(384U, 384U, 384U),
181 std::make_tuple(448U, 384U, 384U, 384U), 192U, true);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000182
Georgios Pinitas41c482d2018-04-17 13:23:26 +0100183 graph << PoolingLayer(PoolingLayerInfo(PoolingType::AVG, 8, PadStrideInfo(1, 1, 0, 0, DimensionRoundingType::CEIL)))
Georgios Pinitas652bde52018-01-10 15:33:28 +0000184 << ConvolutionLayer(1U, 1U, 1001U, get_weights_accessor(data_path,
185 "/cnn_data/inceptionv3_model/Logits_Conv2d_1c_1x1_weights.npy"),
186 get_weights_accessor(data_path,
187 "/cnn_data/inceptionv3_model/Logits_Conv2d_1c_1x1_biases.npy"),
188 PadStrideInfo(1, 1, 0, 0))
189 << ReshapeLayer(TensorShape(1001U)) << SoftmaxLayer()
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000190 << OutputLayer(get_output_accessor(label, 5));
Gian Marcoc1b6e372018-02-21 18:03:26 +0000191
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000192 // Finalize graph
Georgios Pinitas9a8c6722018-03-21 17:52:35 +0000193 GraphConfig config;
194 config.use_function_memory_manager = true;
195 config.use_tuner = (target == 2);
196 graph.finalize(target_hint, config);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000197 }
198
199 void do_run() override
200 {
201 graph.run();
202 }
203
204private:
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000205 Stream graph{ 0, "InceptionV3" };
Georgios Pinitas652bde52018-01-10 15:33:28 +0000206
207private:
208 BranchLayer get_inception_node_A(const std::string &data_path, std::string &&param_path,
209 unsigned int a_filt,
210 std::tuple<unsigned int, unsigned int> b_filters,
211 std::tuple<unsigned int, unsigned int, unsigned int> c_filters,
212 unsigned int d_filt,
213 bool is_name_different = false)
214 {
215 std::string total_path = "/cnn_data/inceptionv3_model/" + param_path + "_";
Georgios Pinitas652bde52018-01-10 15:33:28 +0000216
217 // This is due to a naming issue in the tf model
218 std::string conv_id0 = "_0a_";
219 std::string conv_id1 = "2d_0b_";
220 if(is_name_different)
221 {
222 conv_id0 = "_0b_";
223 conv_id1 = "_1_0c_";
224 }
225
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000226 SubStream i_a(graph);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000227 i_a << ConvolutionLayer(
228 1U, 1U, a_filt,
229 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_weights.npy"),
230 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
231 PadStrideInfo(1, 1, 0, 0))
232 << BatchNormalizationLayer(
233 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
234 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
235 get_random_accessor(1.f, 1.f),
236 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000237 0.001f)
238 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000239
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000240 SubStream i_b(graph);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000241 i_b << ConvolutionLayer(
242 1U, 1U, std::get<0>(b_filters),
243 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d" + conv_id0 + "1x1_weights.npy"),
244 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
245 PadStrideInfo(1, 1, 0, 0))
246 << BatchNormalizationLayer(
247 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d" + conv_id0 + "1x1_BatchNorm_moving_mean.npy"),
248 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d" + conv_id0 + "1x1_BatchNorm_moving_variance.npy"),
249 get_random_accessor(1.f, 1.f),
250 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d" + conv_id0 + "1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000251 0.001f)
252 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas652bde52018-01-10 15:33:28 +0000253 << ConvolutionLayer(
254 5U, 5U, std::get<1>(b_filters),
255 get_weights_accessor(data_path, total_path + "Branch_1_Conv" + conv_id1 + "5x5_weights.npy"),
256 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
257 PadStrideInfo(1, 1, 2, 2))
258 << BatchNormalizationLayer(
259 get_weights_accessor(data_path, total_path + "Branch_1_Conv" + conv_id1 + "5x5_BatchNorm_moving_mean.npy"),
260 get_weights_accessor(data_path, total_path + "Branch_1_Conv" + conv_id1 + "5x5_BatchNorm_moving_variance.npy"),
261 get_random_accessor(1.f, 1.f),
262 get_weights_accessor(data_path, total_path + "Branch_1_Conv" + conv_id1 + "5x5_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000263 0.001f)
264 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000265
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000266 SubStream i_c(graph);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000267 i_c << ConvolutionLayer(
268 1U, 1U, std::get<0>(c_filters),
269 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_weights.npy"),
270 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
271 PadStrideInfo(1, 1, 0, 0))
272 << BatchNormalizationLayer(
273 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
274 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
275 get_random_accessor(1.f, 1.f),
276 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000277 0.001f)
278 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas652bde52018-01-10 15:33:28 +0000279 << ConvolutionLayer(
280 3U, 3U, std::get<1>(c_filters),
281 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_weights.npy"),
282 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
283 PadStrideInfo(1, 1, 1, 1))
284 << BatchNormalizationLayer(
285 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_BatchNorm_moving_mean.npy"),
286 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_BatchNorm_moving_variance.npy"),
287 get_random_accessor(1.f, 1.f),
288 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000289 0.001f)
290 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas652bde52018-01-10 15:33:28 +0000291 << ConvolutionLayer(
292 3U, 3U, std::get<2>(c_filters),
293 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_3x3_weights.npy"),
294 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
295 PadStrideInfo(1, 1, 1, 1))
296 << BatchNormalizationLayer(
297 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_3x3_BatchNorm_moving_mean.npy"),
298 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_3x3_BatchNorm_moving_variance.npy"),
299 get_random_accessor(1.f, 1.f),
300 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_3x3_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000301 0.001f)
302 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000303
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000304 SubStream i_d(graph);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000305 i_d << PoolingLayer(PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 1, 1, DimensionRoundingType::CEIL), true))
306 << ConvolutionLayer(
307 1U, 1U, d_filt,
308 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_weights.npy"),
309 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
310 PadStrideInfo(1, 1, 0, 0))
311 << BatchNormalizationLayer(
312 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_moving_mean.npy"),
313 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_moving_variance.npy"),
314 get_random_accessor(1.f, 1.f),
315 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000316 0.001f)
317 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000318
319 return BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_a), std::move(i_b), std::move(i_c), std::move(i_d));
320 }
321
322 BranchLayer get_inception_node_B(const std::string &data_path, std::string &&param_path,
323 unsigned int a_filt,
324 std::tuple<unsigned int, unsigned int, unsigned int> b_filters)
325 {
326 std::string total_path = "/cnn_data/inceptionv3_model/" + param_path + "_";
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000327 SubStream i_a(graph);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000328 i_a << ConvolutionLayer(
329 3U, 3U, a_filt,
330 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_1x1_weights.npy"),
331 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
332 PadStrideInfo(2, 2, 0, 0))
333 << BatchNormalizationLayer(
334 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_1x1_BatchNorm_moving_mean.npy"),
335 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_1x1_BatchNorm_moving_variance.npy"),
336 get_random_accessor(1.f, 1.f),
337 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000338 0.001f)
339 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000340
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000341 SubStream i_b(graph);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000342 i_b << ConvolutionLayer(
343 1U, 1U, std::get<0>(b_filters),
344 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_weights.npy"),
345 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
346 PadStrideInfo(1, 1, 0, 0))
347 << BatchNormalizationLayer(
348 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
349 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
350 get_random_accessor(1.f, 1.f),
351 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000352 0.001f)
353 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas652bde52018-01-10 15:33:28 +0000354 << ConvolutionLayer(
355 3U, 3U, std::get<1>(b_filters),
356 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_3x3_weights.npy"),
357 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
358 PadStrideInfo(1, 1, 1, 1))
359 << BatchNormalizationLayer(
360 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_3x3_BatchNorm_moving_mean.npy"),
361 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_3x3_BatchNorm_moving_variance.npy"),
362 get_random_accessor(1.f, 1.f),
363 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_3x3_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000364 0.001f)
365 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas652bde52018-01-10 15:33:28 +0000366 << ConvolutionLayer(
367 3U, 3U, std::get<2>(b_filters),
368 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_1x1_weights.npy"),
369 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
370 PadStrideInfo(2, 2, 0, 0))
371 << BatchNormalizationLayer(
372 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_1x1_BatchNorm_moving_mean.npy"),
373 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_1x1_BatchNorm_moving_variance.npy"),
374 get_random_accessor(1.f, 1.f),
375 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000376 0.001f)
377 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000378
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000379 SubStream i_c(graph);
380 i_c << PoolingLayer(PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL)));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000381
382 return BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_a), std::move(i_b), std::move(i_c));
383 }
384
385 BranchLayer get_inception_node_C(const std::string &data_path, std::string &&param_path,
386 unsigned int a_filt,
387 std::tuple<unsigned int, unsigned int, unsigned int> b_filters,
388 std::tuple<unsigned int, unsigned int, unsigned int, unsigned int, unsigned int> c_filters,
389 unsigned int d_filt)
390 {
391 std::string total_path = "/cnn_data/inceptionv3_model/" + param_path + "_";
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000392 SubStream i_a(graph);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000393 i_a << ConvolutionLayer(
394 1U, 1U, a_filt,
395 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_weights.npy"),
396 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
397 PadStrideInfo(1, 1, 0, 0))
398 << BatchNormalizationLayer(
399 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
400 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
401 get_random_accessor(1.f, 1.f),
402 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000403 0.001f)
404 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000405
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000406 SubStream i_b(graph);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000407 i_b << ConvolutionLayer(
408 1U, 1U, std::get<0>(b_filters),
409 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_weights.npy"),
410 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
411 PadStrideInfo(1, 1, 0, 0))
412 << BatchNormalizationLayer(
413 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
414 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
415 get_random_accessor(1.f, 1.f),
416 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000417 0.001f)
418 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas652bde52018-01-10 15:33:28 +0000419 << ConvolutionLayer(
420 7U, 1U, std::get<1>(b_filters),
421 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_weights.npy"),
422 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
423 PadStrideInfo(1, 1, 3, 0))
424 << BatchNormalizationLayer(
425 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_moving_mean.npy"),
426 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_moving_variance.npy"),
427 get_random_accessor(1.f, 1.f),
428 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000429 0.001f)
430 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas652bde52018-01-10 15:33:28 +0000431 << ConvolutionLayer(
432 1U, 7U, std::get<2>(b_filters),
433 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_weights.npy"),
434 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
435 PadStrideInfo(1, 1, 0, 3))
436 << BatchNormalizationLayer(
437 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_moving_mean.npy"),
438 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_moving_variance.npy"),
439 get_random_accessor(1.f, 1.f),
440 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000441 0.001f)
442 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000443
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000444 SubStream i_c(graph);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000445 i_c << ConvolutionLayer(
446 1U, 1U, std::get<0>(c_filters),
447 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_weights.npy"),
448 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
449 PadStrideInfo(1, 1, 0, 0))
450 << BatchNormalizationLayer(
451 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
452 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
453 get_random_accessor(1.f, 1.f),
454 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000455 0.001f)
456 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas652bde52018-01-10 15:33:28 +0000457 << ConvolutionLayer(
458 1U, 7U, std::get<1>(c_filters),
459 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_7x1_weights.npy"),
460 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
461 PadStrideInfo(1, 1, 0, 3))
462 << BatchNormalizationLayer(
463 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_7x1_BatchNorm_moving_mean.npy"),
464 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_7x1_BatchNorm_moving_variance.npy"),
465 get_random_accessor(1.f, 1.f),
466 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_7x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000467 0.001f)
468 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas652bde52018-01-10 15:33:28 +0000469 << ConvolutionLayer(
470 7U, 1U, std::get<2>(c_filters),
471 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x7_weights.npy"),
472 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
473 PadStrideInfo(1, 1, 3, 0))
474 << BatchNormalizationLayer(
475 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x7_BatchNorm_moving_mean.npy"),
476 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x7_BatchNorm_moving_variance.npy"),
477 get_random_accessor(1.f, 1.f),
478 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x7_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000479 0.001f)
480 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas652bde52018-01-10 15:33:28 +0000481 << ConvolutionLayer(
482 1U, 7U, std::get<3>(c_filters),
483 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_7x1_weights.npy"),
484 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
485 PadStrideInfo(1, 1, 0, 3))
486 << BatchNormalizationLayer(
487 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_7x1_BatchNorm_moving_mean.npy"),
488 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_7x1_BatchNorm_moving_variance.npy"),
489 get_random_accessor(1.f, 1.f),
490 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_7x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000491 0.001f)
492 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas652bde52018-01-10 15:33:28 +0000493 << ConvolutionLayer(
494 7U, 1U, std::get<4>(c_filters),
495 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0e_1x7_weights.npy"),
496 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
497 PadStrideInfo(1, 1, 3, 0))
498 << BatchNormalizationLayer(
499 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0e_1x7_BatchNorm_moving_mean.npy"),
500 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0e_1x7_BatchNorm_moving_variance.npy"),
501 get_random_accessor(1.f, 1.f),
502 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0e_1x7_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000503 0.001f)
504 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000505
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000506 SubStream i_d(graph);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000507 i_d << PoolingLayer(PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 1, 1, DimensionRoundingType::CEIL), true))
508 << ConvolutionLayer(
509 1U, 1U, d_filt,
510 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_weights.npy"),
511 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
512 PadStrideInfo(1, 1, 0, 0))
513 << BatchNormalizationLayer(
514 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_moving_mean.npy"),
515 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_moving_variance.npy"),
516 get_random_accessor(1.f, 1.f),
517 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000518 0.001f)
519 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000520
521 return BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_a), std::move(i_b), std::move(i_c), std::move(i_d));
522 }
523
524 BranchLayer get_inception_node_D(const std::string &data_path, std::string &&param_path,
525 std::tuple<unsigned int, unsigned int> a_filters,
526 std::tuple<unsigned int, unsigned int, unsigned int, unsigned int> b_filters)
527 {
528 std::string total_path = "/cnn_data/inceptionv3_model/" + param_path + "_";
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000529 SubStream i_a(graph);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000530 i_a << ConvolutionLayer(
531 1U, 1U, std::get<0>(a_filters),
532 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_weights.npy"),
533 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
534 PadStrideInfo(1, 1, 0, 0))
535 << BatchNormalizationLayer(
536 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
537 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
538 get_random_accessor(1.f, 1.f),
539 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000540 0.001f)
541 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas652bde52018-01-10 15:33:28 +0000542 << ConvolutionLayer(
543 3U, 3U, std::get<1>(a_filters),
544 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_weights.npy"),
545 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
546 PadStrideInfo(2, 2, 0, 0))
547 << BatchNormalizationLayer(
548 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_BatchNorm_moving_mean.npy"),
549 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_BatchNorm_moving_variance.npy"),
550 get_random_accessor(1.f, 1.f),
551 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000552 0.001f)
553 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000554
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000555 SubStream i_b(graph);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000556 i_b << ConvolutionLayer(
557 1U, 1U, std::get<0>(b_filters),
558 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_weights.npy"),
559 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
560 PadStrideInfo(1, 1, 0, 0))
561 << BatchNormalizationLayer(
562 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
563 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
564 get_random_accessor(1.f, 1.f),
565 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000566 0.001f)
567 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas652bde52018-01-10 15:33:28 +0000568 << ConvolutionLayer(
569 7U, 1U, std::get<1>(b_filters),
570 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_weights.npy"),
571 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
572 PadStrideInfo(1, 1, 3, 0))
573 << BatchNormalizationLayer(
574 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_moving_mean.npy"),
575 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_moving_variance.npy"),
576 get_random_accessor(1.f, 1.f),
577 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000578 0.001f)
579 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas652bde52018-01-10 15:33:28 +0000580 << ConvolutionLayer(
581 1U, 7U, std::get<2>(b_filters),
582 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_weights.npy"),
583 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
584 PadStrideInfo(1, 1, 0, 3))
585 << BatchNormalizationLayer(
586 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_moving_mean.npy"),
587 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_moving_variance.npy"),
588 get_random_accessor(1.f, 1.f),
589 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000590 0.001f)
591 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas652bde52018-01-10 15:33:28 +0000592 << ConvolutionLayer(
593 3U, 3U, std::get<3>(b_filters),
594 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_3x3_weights.npy"),
595 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
596 PadStrideInfo(2, 2, 0, 0))
597 << BatchNormalizationLayer(
598 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_3x3_BatchNorm_moving_mean.npy"),
599 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_3x3_BatchNorm_moving_variance.npy"),
600 get_random_accessor(1.f, 1.f),
601 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_3x3_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000602 0.001f)
603 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000604
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000605 SubStream i_c(graph);
606 i_c << PoolingLayer(PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL)));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000607
608 return BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_a), std::move(i_b), std::move(i_c));
609 }
610
611 BranchLayer get_inception_node_E(const std::string &data_path, std::string &&param_path,
612 unsigned int a_filt,
613 std::tuple<unsigned int, unsigned int, unsigned int> b_filters,
614 std::tuple<unsigned int, unsigned int, unsigned int, unsigned int> c_filters,
615 unsigned int d_filt,
616 bool is_name_different = false)
617 {
618 // This is due to a naming issue in the tf model
619 std::string conv_id = "_0b_";
620 if(is_name_different)
621 {
622 conv_id = "_0c_";
623 }
624
625 std::string total_path = "/cnn_data/inceptionv3_model/" + param_path + "_";
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000626 SubStream i_a(graph);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000627 i_a << ConvolutionLayer(
628 1U, 1U, a_filt,
629 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_weights.npy"),
630 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
631 PadStrideInfo(1, 1, 0, 0))
632 << BatchNormalizationLayer(
633 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
634 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
635 get_random_accessor(1.f, 1.f),
636 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000637 0.001f)
638 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000639
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000640 SubStream i_b(graph);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000641 i_b << ConvolutionLayer(
642 1U, 1U, std::get<0>(b_filters),
643 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_weights.npy"),
644 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
645 PadStrideInfo(1, 1, 0, 0))
646 << BatchNormalizationLayer(
647 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
648 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
649 get_random_accessor(1.f, 1.f),
650 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000651 0.001f)
652 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000653
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000654 SubStream i_b1(static_cast<IStream &>(i_b));
655 i_b1 << ConvolutionLayer(
656 3U, 1U, std::get<1>(b_filters),
657 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x3_weights.npy"),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000658 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
659 PadStrideInfo(1, 1, 1, 0))
660 << BatchNormalizationLayer(
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000661 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x3_BatchNorm_moving_mean.npy"),
662 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x3_BatchNorm_moving_variance.npy"),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000663 get_random_accessor(1.f, 1.f),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000664 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x3_BatchNorm_beta.npy"),
665 0.001f)
666 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000667
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000668 SubStream i_b2(static_cast<IStream &>(i_b));
669 i_b2 << ConvolutionLayer(
670 1U, 3U, std::get<2>(b_filters),
671 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d" + conv_id + "3x1_weights.npy"),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000672 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
673 PadStrideInfo(1, 1, 0, 1))
674 << BatchNormalizationLayer(
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000675 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d" + conv_id + "3x1_BatchNorm_moving_mean.npy"),
676 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d" + conv_id + "3x1_BatchNorm_moving_variance.npy"),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000677 get_random_accessor(1.f, 1.f),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000678 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d" + conv_id + "3x1_BatchNorm_beta.npy"),
679 0.001f)
680 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000681
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000682 // Merge b1 and b2
683 i_b << BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_b1), std::move(i_b2));
684
685 SubStream i_c(graph);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000686 i_c << ConvolutionLayer(
687 1U, 1U, std::get<0>(c_filters),
688 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_weights.npy"),
689 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
690 PadStrideInfo(1, 1, 0, 0))
691 << BatchNormalizationLayer(
692 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
693 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
694 get_random_accessor(1.f, 1.f),
695 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000696 0.001f)
697 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas652bde52018-01-10 15:33:28 +0000698 << ConvolutionLayer(
699 3U, 3U, std::get<1>(c_filters),
700 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_weights.npy"),
701 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
702 PadStrideInfo(1, 1, 1, 1))
703 << BatchNormalizationLayer(
704 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_BatchNorm_moving_mean.npy"),
705 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_BatchNorm_moving_variance.npy"),
706 get_random_accessor(1.f, 1.f),
707 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000708 0.001f)
709 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000710
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000711 SubStream i_c1(static_cast<IStream &>(i_c));
712 i_c1 << ConvolutionLayer(
713 3U, 1U, std::get<2>(c_filters),
714 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x3_weights.npy"),
715 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
716 PadStrideInfo(1, 1, 1, 0))
717 << BatchNormalizationLayer(
718 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x3_BatchNorm_moving_mean.npy"),
719 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x3_BatchNorm_moving_variance.npy"),
720 get_random_accessor(1.f, 1.f),
721 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x3_BatchNorm_beta.npy"),
722 0.001f)
723 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
724
725 SubStream i_c2(static_cast<IStream &>(i_c));
726 i_c2 << ConvolutionLayer(
727 1U, 3U, std::get<3>(c_filters),
728 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_3x1_weights.npy"),
729 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
730 PadStrideInfo(1, 1, 0, 1))
731 << BatchNormalizationLayer(
732 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_3x1_BatchNorm_moving_mean.npy"),
733 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_3x1_BatchNorm_moving_variance.npy"),
734 get_random_accessor(1.f, 1.f),
735 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_3x1_BatchNorm_beta.npy"),
736 0.001f)
737 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
738
739 // Merge i_c1 and i_c2
740 i_c << BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_c1), std::move(i_c2));
741
742 SubStream i_d(graph);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000743 i_d << PoolingLayer(PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 1, 1, DimensionRoundingType::CEIL), true))
744 << ConvolutionLayer(
745 1U, 1U, d_filt,
746 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_weights.npy"),
747 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
748 PadStrideInfo(1, 1, 0, 0))
749 << BatchNormalizationLayer(
750 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_moving_mean.npy"),
751 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_moving_variance.npy"),
752 get_random_accessor(1.f, 1.f),
753 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000754 0.001f)
755 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000756
757 return BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_a), std::move(i_b), std::move(i_c), std::move(i_d));
758 }
759};
760
761/** Main program for Inception V3
762 *
763 * @param[in] argc Number of arguments
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000764 * @param[in] argv Arguments ( [optional] Target (0 = NEON, 1 = OpenCL, 2 = OpenCL with Tuner), [optional] Path to the weights folder, [optional] image, [optional] labels )
Georgios Pinitas652bde52018-01-10 15:33:28 +0000765 */
766int main(int argc, char **argv)
767{
768 return arm_compute::utils::run_example<InceptionV3Example>(argc, argv);
769}