blob: ed95baa99eac53c5cab7b41f64f0b97f0d5b9f27 [file] [log] [blame]
Georgios Pinitas240cfa62018-02-26 19:58:04 +00001/*
2 * Copyright (c) 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 Pinitas240cfa62018-02-26 19:58:04 +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 Pinitas240cfa62018-02-26 19:58:04 +000034using namespace arm_compute::graph_utils;
35
36/** Example demonstrating how to implement InceptionV4's network using the Compute Library's graph API
37 *
38 * @param[in] argc Number of arguments
Giorgio Arena59631a12018-05-02 13:59:04 +010039 * @param[in] argv Arguments ( [optional] Target (0 = NEON, 1 = OpenCL, 2 = OpenCL with Tuner), [optional] Path to the weights folder, [optional] image, [optional] labels, [optional] Fast math for convolution layer (0 = DISABLED, 1 = ENABLED) )
Georgios Pinitas240cfa62018-02-26 19:58:04 +000040 */
41class InceptionV4Example final : public Example
42{
43public:
44 void do_setup(int argc, char **argv) override
45 {
Pablo Telloeb82fd22018-02-23 13:43:50 +000046 // Disabled the test for now because the process gets killed on Linux Firefly 32 bit even when using ConvolutionMethodHint::DIRECT.
47 // Needs to review/rework to run the code below.
48#if __aarch64__
Georgios Pinitas240cfa62018-02-26 19:58:04 +000049 std::string data_path; /* Path to the trainable data */
50 std::string image; /* Image data */
51 std::string label; /* Label data */
52
53 // Create a preprocessor object
54 std::unique_ptr<IPreprocessor> preprocessor = arm_compute::support::cpp14::make_unique<TFPreproccessor>();
55
Georgios Pinitasd8734b52017-12-22 15:27:52 +000056 // Set target. 0 (NEON), 1 (OpenCL). By default it is NEON
Gian Marco Iodicea8aef292018-05-14 14:21:39 +010057 const int target = argc > 1 ? std::strtol(argv[1], nullptr, 10) : 0;
58 Target target_hint = set_target_hint(target);
59 FastMathHint fast_math_hint = FastMathHint::DISABLED;
Georgios Pinitas28705162018-03-21 20:10:53 +000060
Georgios Pinitas240cfa62018-02-26 19:58:04 +000061 // Parse arguments
62 if(argc < 2)
63 {
64 // Print help
Giorgio Arena59631a12018-05-02 13:59:04 +010065 std::cout << "Usage: " << argv[0] << " [target] [path_to_data] [image] [labels] [fast_math_hint]\n\n";
Georgios Pinitas240cfa62018-02-26 19:58:04 +000066 std::cout << "No data folder provided: using random values\n\n";
67 }
68 else if(argc == 2)
69 {
Giorgio Arena59631a12018-05-02 13:59:04 +010070 std::cout << "Usage: " << argv[0] << " " << argv[1] << " [path_to_data] [image] [labels] [fast_math_hint]\n\n";
Georgios Pinitas240cfa62018-02-26 19:58:04 +000071 std::cout << "No data folder provided: using random values\n\n";
72 }
73 else if(argc == 3)
74 {
75 data_path = argv[2];
Giorgio Arena59631a12018-05-02 13:59:04 +010076 std::cout << "Usage: " << argv[0] << " " << argv[1] << " " << argv[2] << " [image] [labels] [fast_math_hint]\n\n";
Georgios Pinitas240cfa62018-02-26 19:58:04 +000077 std::cout << "No image provided: using random values\n\n";
78 }
79 else if(argc == 4)
80 {
81 data_path = argv[2];
82 image = argv[3];
Giorgio Arena59631a12018-05-02 13:59:04 +010083 std::cout << "Usage: " << argv[0] << " " << argv[1] << " " << argv[2] << " " << argv[3] << " [labels] [fast_math_hint]\n\n";
Georgios Pinitas240cfa62018-02-26 19:58:04 +000084 std::cout << "No text file with labels provided: skipping output accessor\n\n";
85 }
Giorgio Arena59631a12018-05-02 13:59:04 +010086 else if(argc == 5)
Georgios Pinitas240cfa62018-02-26 19:58:04 +000087 {
88 data_path = argv[2];
89 image = argv[3];
90 label = argv[4];
Giorgio Arena59631a12018-05-02 13:59:04 +010091 std::cout << "Usage: " << argv[0] << " " << argv[1] << " " << argv[2] << " " << argv[3] << " " << argv[4] << " [fast_math_hint]\n\n";
92 std::cout << "No fast math info provided: disabling fast math\n\n";
93 }
94 else
95 {
96 data_path = argv[2];
97 image = argv[3];
98 label = argv[4];
99 fast_math_hint = (std::strtol(argv[5], nullptr, 1) == 0) ? FastMathHint::DISABLED : FastMathHint::ENABLED;
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000100 }
101
Giorgio Arena59631a12018-05-02 13:59:04 +0100102 graph << target_hint
103 << fast_math_hint
104 << InputLayer(TensorDescriptor(TensorShape(299U, 299U, 3U, 1U), DataType::F32),
105 get_input_accessor(image, std::move(preprocessor), false))
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000106 // Conv2d_1a_3x3
107 << ConvolutionLayer(3U, 3U, 32U,
108 get_weights_accessor(data_path, "/cnn_data/inceptionv4_model/Conv2d_1a_3x3_weights.npy"),
109 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(2, 2, 0, 0))
110 << BatchNormalizationLayer(get_weights_accessor(data_path, "/cnn_data/inceptionv4_model/Conv2d_1a_3x3_BatchNorm_moving_mean.npy"),
111 get_weights_accessor(data_path, "/cnn_data/inceptionv4_model/Conv2d_1a_3x3_BatchNorm_moving_variance.npy"),
112 get_random_accessor(1.f, 1.f),
113 get_weights_accessor(data_path, "/cnn_data/inceptionv4_model/Conv2d_1a_3x3_BatchNorm_beta.npy"),
114 0.001f)
115 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
116 // Conv2d_2a_3x3
117 << ConvolutionLayer(3U, 3U, 32U,
118 get_weights_accessor(data_path, "/cnn_data/inceptionv4_model/Conv2d_2a_3x3_weights.npy"),
119 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
120 << BatchNormalizationLayer(get_weights_accessor(data_path, "/cnn_data/inceptionv4_model/Conv2d_2a_3x3_BatchNorm_moving_mean.npy"),
121 get_weights_accessor(data_path, "/cnn_data/inceptionv4_model/Conv2d_2a_3x3_BatchNorm_moving_variance.npy"),
122 get_random_accessor(1.f, 1.f),
123 get_weights_accessor(data_path, "/cnn_data/inceptionv4_model/Conv2d_2a_3x3_BatchNorm_beta.npy"),
124 0.001f)
125 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
126 // Conv2d_2b_3x3
127 << ConvolutionLayer(3U, 3U, 64U,
128 get_weights_accessor(data_path, "/cnn_data/inceptionv4_model/Conv2d_2b_3x3_weights.npy"),
129 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 1, 1))
130 << BatchNormalizationLayer(get_weights_accessor(data_path, "/cnn_data/inceptionv4_model/Conv2d_2b_3x3_BatchNorm_moving_mean.npy"),
131 get_weights_accessor(data_path, "/cnn_data/inceptionv4_model/Conv2d_2b_3x3_BatchNorm_moving_variance.npy"),
132 get_random_accessor(1.f, 1.f),
133 get_weights_accessor(data_path, "/cnn_data/inceptionv4_model/Conv2d_2b_3x3_BatchNorm_beta.npy"),
134 0.001f)
Georgios Pinitas41c482d2018-04-17 13:23:26 +0100135 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000136
Georgios Pinitas41c482d2018-04-17 13:23:26 +0100137 graph << get_mixed_3a(data_path);
138 graph << get_mixed_4a(data_path);
139 graph << get_mixed_5a(data_path);
140 // 4 inception A blocks
141 graph << get_inceptionA_block(data_path, "Mixed_5b");
142 graph << get_inceptionA_block(data_path, "Mixed_5c");
143 graph << get_inceptionA_block(data_path, "Mixed_5d");
144 graph << get_inceptionA_block(data_path, "Mixed_5e");
145 // reduction A block
146 graph << get_reductionA_block(data_path);
147 // 7 inception B blocks
148 graph << get_inceptionB_block(data_path, "Mixed_6b");
149 graph << get_inceptionB_block(data_path, "Mixed_6c");
150 graph << get_inceptionB_block(data_path, "Mixed_6d");
151 graph << get_inceptionB_block(data_path, "Mixed_6e");
152 graph << get_inceptionB_block(data_path, "Mixed_6f");
153 graph << get_inceptionB_block(data_path, "Mixed_6g");
154 graph << get_inceptionB_block(data_path, "Mixed_6h");
155 // reduction B block
156 graph << get_reductionB_block(data_path);
157 // 3 inception C blocks
158 graph << get_inceptionC_block(data_path, "Mixed_7b");
159 graph << get_inceptionC_block(data_path, "Mixed_7c");
160 graph << get_inceptionC_block(data_path, "Mixed_7d");
161 graph << PoolingLayer(PoolingLayerInfo(PoolingType::AVG))
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000162 << FlattenLayer()
163 << FullyConnectedLayer(
164 1001U,
165 get_weights_accessor(data_path, "/cnn_data/inceptionv4_model/Logits_Logits_weights.npy"),
166 get_weights_accessor(data_path, "/cnn_data/inceptionv4_model/Logits_Logits_biases.npy"))
167 << SoftmaxLayer()
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000168 << OutputLayer(get_output_accessor(label, 5));
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000169
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000170 // Finalize graph
Georgios Pinitas9a8c6722018-03-21 17:52:35 +0000171 GraphConfig config;
Georgios Pinitas3d1489d2018-05-03 20:47:16 +0100172 config.use_tuner = (target == 2);
Georgios Pinitas9a8c6722018-03-21 17:52:35 +0000173 graph.finalize(target_hint, config);
Pablo Telloeb82fd22018-02-23 13:43:50 +0000174#else /* __aarch64__ */
175 using namespace arm_compute;
176 ARM_COMPUTE_UNUSED(argc);
177 ARM_COMPUTE_UNUSED(argv);
178#endif /* __aarch64__ */
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000179 }
180
181 void do_run() override
182 {
Pablo Telloeb82fd22018-02-23 13:43:50 +0000183#if __aarch64__
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000184 graph.run();
Pablo Telloeb82fd22018-02-23 13:43:50 +0000185#endif /* __aarch64__ */
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000186 }
187
188private:
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000189 Stream graph{ 0, "InceptionV4" };
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000190
191private:
192 BranchLayer get_mixed_3a(const std::string &data_path)
193 {
194 std::string total_path = "/cnn_data/inceptionv4_model/Mixed_3a_";
195
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000196 SubStream i_a(graph);
197 i_a << PoolingLayer(PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL), true));
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000198
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000199 SubStream i_b(graph);
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000200 i_b << ConvolutionLayer(3U, 3U, 96U,
201 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_3x3_weights.npy"),
202 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(2, 2, 0, 0))
203 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_3x3_BatchNorm_moving_mean.npy"),
204 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_3x3_BatchNorm_moving_variance.npy"),
205 get_random_accessor(1.f, 1.f),
206 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_3x3_BatchNorm_beta.npy"),
207 0.001f)
208 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
209
210 return BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_a), std::move(i_b));
211 }
212
213 BranchLayer get_mixed_4a(const std::string &data_path)
214 {
215 std::string total_path = "/cnn_data/inceptionv4_model/Mixed_4a_";
216
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000217 SubStream i_a(graph);
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000218 i_a << ConvolutionLayer(1U, 1U, 64U,
219 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_weights.npy"),
220 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
221 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
222 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
223 get_random_accessor(1.f, 1.f),
224 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_beta.npy"),
225 0.001f)
226 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
227 << ConvolutionLayer(3U, 3U, 96U,
228 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_weights.npy"),
229 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
230 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_BatchNorm_moving_mean.npy"),
231 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_BatchNorm_moving_variance.npy"),
232 get_random_accessor(1.f, 1.f),
233 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_BatchNorm_beta.npy"),
234 0.001f)
235 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
236
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000237 SubStream i_b(graph);
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000238 i_b << ConvolutionLayer(1U, 1U, 64U,
239 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_weights.npy"),
240 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
241 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
242 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
243 get_random_accessor(1.f, 1.f),
244 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_beta.npy"),
245 0.001f)
246 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
247 << ConvolutionLayer(7U, 1U, 64U,
248 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_weights.npy"),
249 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 3, 0))
250 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_moving_mean.npy"),
251 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_moving_variance.npy"),
252 get_random_accessor(1.f, 1.f),
253 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_beta.npy"),
254 0.001f)
255 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
256 << ConvolutionLayer(1U, 7U, 64U,
257 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_weights.npy"),
258 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 3))
259 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_moving_mean.npy"),
260 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_moving_variance.npy"),
261 get_random_accessor(1.f, 1.f),
262 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_beta.npy"),
263 0.001f)
264 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
265 << ConvolutionLayer(3U, 3U, 96U,
266 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_3x3_weights.npy"),
267 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
268 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_3x3_BatchNorm_moving_mean.npy"),
269 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_3x3_BatchNorm_moving_variance.npy"),
270 get_random_accessor(1.f, 1.f),
271 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_3x3_BatchNorm_beta.npy"),
272 0.001f)
273 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
274
275 return BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_a), std::move(i_b));
276 }
277
278 BranchLayer get_mixed_5a(const std::string &data_path)
279 {
280 std::string total_path = "/cnn_data/inceptionv4_model/Mixed_5a_";
281
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000282 SubStream i_a(graph);
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000283 i_a << ConvolutionLayer(3U, 3U, 192U,
284 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_weights.npy"),
285 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(2, 2, 0, 0))
286 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_BatchNorm_moving_mean.npy"),
287 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_BatchNorm_moving_variance.npy"),
288 get_random_accessor(1.f, 1.f),
289 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_BatchNorm_beta.npy"),
290 0.001f)
291 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
292
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000293 SubStream i_b(graph);
294 i_b << PoolingLayer(PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL), true));
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000295
296 return BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_a), std::move(i_b));
297 }
298
299 BranchLayer get_inceptionA_block(const std::string &data_path, std::string &&param_path)
300 {
301 std::string total_path = "/cnn_data/inceptionv4_model/" + param_path + "_";
302
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000303 SubStream i_a(graph);
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000304 i_a << ConvolutionLayer(1U, 1U, 96U,
305 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_weights.npy"),
306 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
307 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
308 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
309 get_random_accessor(1.f, 1.f),
310 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_beta.npy"),
311 0.001f)
312 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
313
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000314 SubStream i_b(graph);
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000315 i_b << ConvolutionLayer(1U, 1U, 64U,
316 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_weights.npy"),
317 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
318 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
319 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
320 get_random_accessor(1.f, 1.f),
321 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_beta.npy"),
322 0.001f)
323 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
324 << ConvolutionLayer(3U, 3U, 96U,
325 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_3x3_weights.npy"),
326 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 1, 1))
327 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_3x3_BatchNorm_moving_mean.npy"),
328 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_3x3_BatchNorm_moving_variance.npy"),
329 get_random_accessor(1.f, 1.f),
330 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_3x3_BatchNorm_beta.npy"),
331 0.001f)
332 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
333
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000334 SubStream i_c(graph);
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000335 i_c << ConvolutionLayer(1U, 1U, 64U,
336 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_weights.npy"),
337 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
338 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
339 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
340 get_random_accessor(1.f, 1.f),
341 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_beta.npy"),
342 0.001f)
343 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
344 << ConvolutionLayer(3U, 3U, 96U,
345 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_weights.npy"),
346 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 1, 1))
347 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_BatchNorm_moving_mean.npy"),
348 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_BatchNorm_moving_variance.npy"),
349 get_random_accessor(1.f, 1.f),
350 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_BatchNorm_beta.npy"),
351 0.001f)
352 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
353 << ConvolutionLayer(3U, 3U, 96U,
354 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_3x3_weights.npy"),
355 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 1, 1))
356 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_3x3_BatchNorm_moving_mean.npy"),
357 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_3x3_BatchNorm_moving_variance.npy"),
358 get_random_accessor(1.f, 1.f),
359 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_3x3_BatchNorm_beta.npy"),
360 0.001f)
361 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
362
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000363 SubStream i_d(graph);
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000364 i_d << PoolingLayer(PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 1, 1, DimensionRoundingType::CEIL), true))
365 << ConvolutionLayer(1U, 1U, 96U,
366 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_weights.npy"),
367 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
368 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_moving_mean.npy"),
369 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_moving_variance.npy"),
370 get_random_accessor(1.f, 1.f),
371 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_beta.npy"),
372 0.001f)
373 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
374
375 return BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_a), std::move(i_b), std::move(i_c), std::move(i_d));
376 }
377
378 BranchLayer get_reductionA_block(const std::string &data_path)
379 {
380 std::string total_path = "/cnn_data/inceptionv4_model/Mixed_6a_";
381
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000382 SubStream i_a(graph);
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000383 i_a << ConvolutionLayer(3U, 3U, 384U,
384 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_weights.npy"),
385 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(2, 2, 0, 0))
386 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_BatchNorm_moving_mean.npy"),
387 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_BatchNorm_moving_variance.npy"),
388 get_random_accessor(1.f, 1.f),
389 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_BatchNorm_beta.npy"),
390 0.001f)
391 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
392
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000393 SubStream i_b(graph);
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000394 i_b << ConvolutionLayer(1U, 1U, 192U,
395 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_weights.npy"),
396 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
397 << BatchNormalizationLayer(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"),
401 0.001f)
402 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
403 << ConvolutionLayer(3U, 3U, 224U,
404 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_3x3_weights.npy"),
405 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 1, 1))
406 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_3x3_BatchNorm_moving_mean.npy"),
407 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_3x3_BatchNorm_moving_variance.npy"),
408 get_random_accessor(1.f, 1.f),
409 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_3x3_BatchNorm_beta.npy"),
410 0.001f)
411 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
412 << ConvolutionLayer(3U, 3U, 256U,
413 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_3x3_weights.npy"),
414 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(2, 2, 0, 0))
415 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_3x3_BatchNorm_moving_mean.npy"),
416 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_3x3_BatchNorm_moving_variance.npy"),
417 get_random_accessor(1.f, 1.f),
418 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_3x3_BatchNorm_beta.npy"),
419 0.001f)
420 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
421
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000422 SubStream i_c(graph);
423 i_c << PoolingLayer(PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL), true));
424
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000425 return BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_a), std::move(i_b), std::move(i_c));
426 }
427
428 BranchLayer get_inceptionB_block(const std::string &data_path, std::string &&param_path)
429 {
430 std::string total_path = "/cnn_data/inceptionv4_model/" + param_path + "_";
431
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000432 SubStream i_a(graph);
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000433 i_a << ConvolutionLayer(1U, 1U, 384U,
434 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_weights.npy"),
435 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
436 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
437 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
438 get_random_accessor(1.f, 1.f),
439 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_beta.npy"),
440 0.001f)
441 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
442
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000443 SubStream i_b(graph);
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000444 i_b << ConvolutionLayer(1U, 1U, 192U,
445 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_weights.npy"),
446 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
447 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
448 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
449 get_random_accessor(1.f, 1.f),
450 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_beta.npy"),
451 0.001f)
452 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
453 << ConvolutionLayer(7U, 1U, 224U,
454 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_weights.npy"),
455 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 3, 0))
456 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_moving_mean.npy"),
457 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_moving_variance.npy"),
458 get_random_accessor(1.f, 1.f),
459 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_beta.npy"),
460 0.001f)
461 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
462 << ConvolutionLayer(1U, 7U, 256U,
463 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_weights.npy"),
464 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 3))
465 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_moving_mean.npy"),
466 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_moving_variance.npy"),
467 get_random_accessor(1.f, 1.f),
468 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_beta.npy"),
469 0.001f)
470 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
471
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000472 SubStream i_c(graph);
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000473 i_c << ConvolutionLayer(1U, 1U, 192U,
474 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_weights.npy"),
475 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
476 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
477 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
478 get_random_accessor(1.f, 1.f),
479 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_beta.npy"),
480 0.001f)
481 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
482 << ConvolutionLayer(1U, 7U, 192U,
483 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_7x1_weights.npy"),
484 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 3))
485 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_7x1_BatchNorm_moving_mean.npy"),
486 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_7x1_BatchNorm_moving_variance.npy"),
487 get_random_accessor(1.f, 1.f),
488 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_7x1_BatchNorm_beta.npy"),
489 0.001f)
490 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
491 << ConvolutionLayer(7U, 1U, 224U,
492 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x7_weights.npy"),
493 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 3, 0))
494 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x7_BatchNorm_moving_mean.npy"),
495 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x7_BatchNorm_moving_variance.npy"),
496 get_random_accessor(1.f, 1.f),
497 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x7_BatchNorm_beta.npy"),
498 0.001f)
499 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
500 << ConvolutionLayer(1U, 7U, 224U,
501 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_7x1_weights.npy"),
502 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 3))
503 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_7x1_BatchNorm_moving_mean.npy"),
504 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_7x1_BatchNorm_moving_variance.npy"),
505 get_random_accessor(1.f, 1.f),
506 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_7x1_BatchNorm_beta.npy"),
507 0.001f)
508 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
509 << ConvolutionLayer(7U, 1U, 256U,
510 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0e_1x7_weights.npy"),
511 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 3, 0))
512 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0e_1x7_BatchNorm_moving_mean.npy"),
513 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0e_1x7_BatchNorm_moving_variance.npy"),
514 get_random_accessor(1.f, 1.f),
515 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0e_1x7_BatchNorm_beta.npy"),
516 0.001f)
517 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
518
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000519 SubStream i_d(graph);
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000520 i_d << PoolingLayer(PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 1, 1, DimensionRoundingType::CEIL), true))
521 << ConvolutionLayer(1U, 1U, 128U,
522 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_weights.npy"),
523 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
524 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_moving_mean.npy"),
525 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_moving_variance.npy"),
526 get_random_accessor(1.f, 1.f),
527 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_beta.npy"),
528 0.001f)
529 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
530
531 return BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_a), std::move(i_b), std::move(i_c), std::move(i_d));
532 }
533
534 BranchLayer get_reductionB_block(const std::string &data_path)
535 {
536 std::string total_path = "/cnn_data/inceptionv4_model/Mixed_7a_";
537
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000538 SubStream i_a(graph);
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000539 i_a << ConvolutionLayer(1U, 1U, 192U,
540 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_weights.npy"),
541 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
542 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
543 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
544 get_random_accessor(1.f, 1.f),
545 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_beta.npy"),
546 0.001f)
547 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
548 << ConvolutionLayer(3U, 3U, 192U,
549 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_weights.npy"),
550 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(2, 2, 0, 0))
551 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_BatchNorm_moving_mean.npy"),
552 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_BatchNorm_moving_variance.npy"),
553 get_random_accessor(1.f, 1.f),
554 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_BatchNorm_beta.npy"),
555 0.001f)
556 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
557
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000558 SubStream i_b(graph);
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000559 i_b << ConvolutionLayer(1U, 1U, 256U,
560 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_weights.npy"),
561 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
562 << BatchNormalizationLayer(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"),
566 0.001f)
567 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
568 << ConvolutionLayer(7U, 1U, 256U,
569 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_weights.npy"),
570 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 3, 0))
571 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_moving_mean.npy"),
572 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_moving_variance.npy"),
573 get_random_accessor(1.f, 1.f),
574 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_beta.npy"),
575 0.001f)
576 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
577 << ConvolutionLayer(1U, 7U, 320U,
578 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_weights.npy"),
579 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 3))
580 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_moving_mean.npy"),
581 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_moving_variance.npy"),
582 get_random_accessor(1.f, 1.f),
583 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_beta.npy"),
584 0.001f)
585 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
586 << ConvolutionLayer(3U, 3U, 320U,
587 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_3x3_weights.npy"),
588 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(2, 2, 0, 0))
589 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_3x3_BatchNorm_moving_mean.npy"),
590 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_3x3_BatchNorm_moving_variance.npy"),
591 get_random_accessor(1.f, 1.f),
592 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_3x3_BatchNorm_beta.npy"),
593 0.001f)
594 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
595
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000596 SubStream i_c(graph);
597 i_c << PoolingLayer(PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL), true));
598
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000599 return BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_a), std::move(i_b), std::move(i_c));
600 }
601
602 BranchLayer get_inceptionC_block(const std::string &data_path, std::string &&param_path)
603 {
604 std::string total_path = "/cnn_data/inceptionv4_model/" + param_path + "_";
605
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000606 SubStream i_a(graph);
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000607 i_a << ConvolutionLayer(1U, 1U, 256U,
608 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_weights.npy"),
609 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
610 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
611 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
612 get_random_accessor(1.f, 1.f),
613 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_beta.npy"),
614 0.001f)
615 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
616
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000617 SubStream i_b(graph);
618 i_b << ConvolutionLayer(
619 1U, 1U, 384U,
620 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_weights.npy"),
621 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
622 PadStrideInfo(1, 1, 0, 0))
623 << BatchNormalizationLayer(
624 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
625 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
626 get_random_accessor(1.f, 1.f),
627 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_beta.npy"),
628 0.001f)
629 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
630
631 SubStream i_b1(static_cast<IStream &>(i_b));
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000632 i_b1 << ConvolutionLayer(
633 3U, 1U, 256U,
634 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x3_weights.npy"),
635 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
636 PadStrideInfo(1, 1, 1, 0))
637 << BatchNormalizationLayer(
638 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x3_BatchNorm_moving_mean.npy"),
639 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x3_BatchNorm_moving_variance.npy"),
640 get_random_accessor(1.f, 1.f),
641 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x3_BatchNorm_beta.npy"),
642 0.001f)
643 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
644
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000645 SubStream i_b2(static_cast<IStream &>(i_b));
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000646 i_b2 << ConvolutionLayer(
647 1U, 3U, 256U,
648 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_3x1_weights.npy"),
649 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
650 PadStrideInfo(1, 1, 0, 1))
651 << BatchNormalizationLayer(
652 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_3x1_BatchNorm_moving_mean.npy"),
653 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_3x1_BatchNorm_moving_variance.npy"),
654 get_random_accessor(1.f, 1.f),
655 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_3x1_BatchNorm_beta.npy"),
656 0.001f)
657 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
658
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000659 // Merge b1 and b2
660 i_b << BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_b1), std::move(i_b2));
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000661
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000662 SubStream i_c(graph);
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000663 i_c << ConvolutionLayer(
664 1U, 1U, 384U,
665 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_weights.npy"),
666 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
667 PadStrideInfo(1, 1, 0, 0))
668 << BatchNormalizationLayer(
669 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
670 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
671 get_random_accessor(1.f, 1.f),
672 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_beta.npy"),
673 0.001f)
674 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
675 << ConvolutionLayer(
676 1U, 3U, 448U,
677 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x1_weights.npy"),
678 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
679 PadStrideInfo(1, 1, 0, 1))
680 << BatchNormalizationLayer(
681 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x1_BatchNorm_moving_mean.npy"),
682 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x1_BatchNorm_moving_variance.npy"),
683 get_random_accessor(1.f, 1.f),
684 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x1_BatchNorm_beta.npy"),
685 0.001f)
686 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
687 << ConvolutionLayer(
688 3U, 1U, 512U,
689 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x3_weights.npy"),
690 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
691 PadStrideInfo(1, 1, 1, 0))
692 << BatchNormalizationLayer(
693 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x3_BatchNorm_moving_mean.npy"),
694 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x3_BatchNorm_moving_variance.npy"),
695 get_random_accessor(1.f, 1.f),
696 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x3_BatchNorm_beta.npy"),
697 0.001f)
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000698 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000699
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000700 SubStream i_c1(static_cast<IStream &>(i_c));
701 i_c1 << ConvolutionLayer(
702 3U, 1U, 256U,
703 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_1x3_weights.npy"),
704 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
705 PadStrideInfo(1, 1, 1, 0))
706 << BatchNormalizationLayer(
707 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_1x3_BatchNorm_moving_mean.npy"),
708 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_1x3_BatchNorm_moving_variance.npy"),
709 get_random_accessor(1.f, 1.f),
710 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_1x3_BatchNorm_beta.npy"),
711 0.001f)
712 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
713
714 SubStream i_c2(static_cast<IStream &>(i_c));
715 i_c2 << ConvolutionLayer(
716 1U, 3U, 256U,
717 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0e_3x1_weights.npy"),
718 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
719 PadStrideInfo(1, 1, 0, 1))
720 << BatchNormalizationLayer(
721 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0e_3x1_BatchNorm_moving_mean.npy"),
722 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0e_3x1_BatchNorm_moving_variance.npy"),
723 get_random_accessor(1.f, 1.f),
724 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0e_3x1_BatchNorm_beta.npy"),
725 0.001f)
726 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
727
728 // Merge i_c1 and i_c2
729 i_c << BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_c1), std::move(i_c2));
730
731 SubStream i_d(graph);
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000732 i_d << PoolingLayer(PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 1, 1, DimensionRoundingType::CEIL), true))
733 << ConvolutionLayer(1U, 1U, 256U,
734 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_weights.npy"),
735 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
736 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_moving_mean.npy"),
737 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_moving_variance.npy"),
738 get_random_accessor(1.f, 1.f),
739 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_beta.npy"),
740 0.001f)
741 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
742
743 return BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_a), std::move(i_b), std::move(i_c), std::move(i_d));
744 }
745};
746
747/** Main program for Inception V4
748 *
749 * @param[in] argc Number of arguments
Giorgio Arena59631a12018-05-02 13:59:04 +0100750 * @param[in] argv Arguments ( [optional] Target (0 = NEON, 1 = OpenCL, 2 = OpenCL with Tuner), [optional] Path to the weights folder, [optional] image, [optional] labels, [optional] Fast math for convolution layer (0 = DISABLED, 1 = ENABLED) )
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000751 */
752int main(int argc, char **argv)
753{
754 return arm_compute::utils::run_example<InceptionV4Example>(argc, argv);
755}