blob: 827370ec5e9d083cf0adb7c399ac0d227d346961 [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 Iodicec13021e2018-05-09 14:11:34 +010057 const int target = argc > 1 ? std::strtol(argv[1], nullptr, 10) : 0;
58 Target target_hint = set_target_hint(target);
59 ConvolutionMethod convolution_hint = target_hint == Target::NEON ? ConvolutionMethod::GEMM : ConvolutionMethod::DEFAULT;
Giorgio Arena59631a12018-05-02 13:59:04 +010060 FastMathHint fast_math_hint = FastMathHint::DISABLED;
Georgios Pinitas28705162018-03-21 20:10:53 +000061
Georgios Pinitas240cfa62018-02-26 19:58:04 +000062 // Parse arguments
63 if(argc < 2)
64 {
65 // Print help
Giorgio Arena59631a12018-05-02 13:59:04 +010066 std::cout << "Usage: " << argv[0] << " [target] [path_to_data] [image] [labels] [fast_math_hint]\n\n";
Georgios Pinitas240cfa62018-02-26 19:58:04 +000067 std::cout << "No data folder provided: using random values\n\n";
68 }
69 else if(argc == 2)
70 {
Giorgio Arena59631a12018-05-02 13:59:04 +010071 std::cout << "Usage: " << argv[0] << " " << argv[1] << " [path_to_data] [image] [labels] [fast_math_hint]\n\n";
Georgios Pinitas240cfa62018-02-26 19:58:04 +000072 std::cout << "No data folder provided: using random values\n\n";
73 }
74 else if(argc == 3)
75 {
76 data_path = argv[2];
Giorgio Arena59631a12018-05-02 13:59:04 +010077 std::cout << "Usage: " << argv[0] << " " << argv[1] << " " << argv[2] << " [image] [labels] [fast_math_hint]\n\n";
Georgios Pinitas240cfa62018-02-26 19:58:04 +000078 std::cout << "No image provided: using random values\n\n";
79 }
80 else if(argc == 4)
81 {
82 data_path = argv[2];
83 image = argv[3];
Giorgio Arena59631a12018-05-02 13:59:04 +010084 std::cout << "Usage: " << argv[0] << " " << argv[1] << " " << argv[2] << " " << argv[3] << " [labels] [fast_math_hint]\n\n";
Georgios Pinitas240cfa62018-02-26 19:58:04 +000085 std::cout << "No text file with labels provided: skipping output accessor\n\n";
86 }
Giorgio Arena59631a12018-05-02 13:59:04 +010087 else if(argc == 5)
Georgios Pinitas240cfa62018-02-26 19:58:04 +000088 {
89 data_path = argv[2];
90 image = argv[3];
91 label = argv[4];
Giorgio Arena59631a12018-05-02 13:59:04 +010092 std::cout << "Usage: " << argv[0] << " " << argv[1] << " " << argv[2] << " " << argv[3] << " " << argv[4] << " [fast_math_hint]\n\n";
93 std::cout << "No fast math info provided: disabling fast math\n\n";
94 }
95 else
96 {
97 data_path = argv[2];
98 image = argv[3];
99 label = argv[4];
100 fast_math_hint = (std::strtol(argv[5], nullptr, 1) == 0) ? FastMathHint::DISABLED : FastMathHint::ENABLED;
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000101 }
102
Giorgio Arena59631a12018-05-02 13:59:04 +0100103 graph << target_hint
104 << fast_math_hint
105 << InputLayer(TensorDescriptor(TensorShape(299U, 299U, 3U, 1U), DataType::F32),
106 get_input_accessor(image, std::move(preprocessor), false))
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000107 // Conv2d_1a_3x3
108 << ConvolutionLayer(3U, 3U, 32U,
109 get_weights_accessor(data_path, "/cnn_data/inceptionv4_model/Conv2d_1a_3x3_weights.npy"),
110 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(2, 2, 0, 0))
111 << BatchNormalizationLayer(get_weights_accessor(data_path, "/cnn_data/inceptionv4_model/Conv2d_1a_3x3_BatchNorm_moving_mean.npy"),
112 get_weights_accessor(data_path, "/cnn_data/inceptionv4_model/Conv2d_1a_3x3_BatchNorm_moving_variance.npy"),
113 get_random_accessor(1.f, 1.f),
114 get_weights_accessor(data_path, "/cnn_data/inceptionv4_model/Conv2d_1a_3x3_BatchNorm_beta.npy"),
115 0.001f)
116 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
Georgios Pinitas28705162018-03-21 20:10:53 +0000117 << convolution_hint
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000118 // Conv2d_2a_3x3
119 << ConvolutionLayer(3U, 3U, 32U,
120 get_weights_accessor(data_path, "/cnn_data/inceptionv4_model/Conv2d_2a_3x3_weights.npy"),
121 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
122 << BatchNormalizationLayer(get_weights_accessor(data_path, "/cnn_data/inceptionv4_model/Conv2d_2a_3x3_BatchNorm_moving_mean.npy"),
123 get_weights_accessor(data_path, "/cnn_data/inceptionv4_model/Conv2d_2a_3x3_BatchNorm_moving_variance.npy"),
124 get_random_accessor(1.f, 1.f),
125 get_weights_accessor(data_path, "/cnn_data/inceptionv4_model/Conv2d_2a_3x3_BatchNorm_beta.npy"),
126 0.001f)
127 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
128 // Conv2d_2b_3x3
129 << ConvolutionLayer(3U, 3U, 64U,
130 get_weights_accessor(data_path, "/cnn_data/inceptionv4_model/Conv2d_2b_3x3_weights.npy"),
131 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 1, 1))
132 << BatchNormalizationLayer(get_weights_accessor(data_path, "/cnn_data/inceptionv4_model/Conv2d_2b_3x3_BatchNorm_moving_mean.npy"),
133 get_weights_accessor(data_path, "/cnn_data/inceptionv4_model/Conv2d_2b_3x3_BatchNorm_moving_variance.npy"),
134 get_random_accessor(1.f, 1.f),
135 get_weights_accessor(data_path, "/cnn_data/inceptionv4_model/Conv2d_2b_3x3_BatchNorm_beta.npy"),
136 0.001f)
Georgios Pinitas41c482d2018-04-17 13:23:26 +0100137 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000138
Georgios Pinitas41c482d2018-04-17 13:23:26 +0100139 graph << get_mixed_3a(data_path);
140 graph << get_mixed_4a(data_path);
141 graph << get_mixed_5a(data_path);
142 // 4 inception A blocks
143 graph << get_inceptionA_block(data_path, "Mixed_5b");
144 graph << get_inceptionA_block(data_path, "Mixed_5c");
145 graph << get_inceptionA_block(data_path, "Mixed_5d");
146 graph << get_inceptionA_block(data_path, "Mixed_5e");
147 // reduction A block
148 graph << get_reductionA_block(data_path);
149 // 7 inception B blocks
150 graph << get_inceptionB_block(data_path, "Mixed_6b");
151 graph << get_inceptionB_block(data_path, "Mixed_6c");
152 graph << get_inceptionB_block(data_path, "Mixed_6d");
153 graph << get_inceptionB_block(data_path, "Mixed_6e");
154 graph << get_inceptionB_block(data_path, "Mixed_6f");
155 graph << get_inceptionB_block(data_path, "Mixed_6g");
156 graph << get_inceptionB_block(data_path, "Mixed_6h");
157 // reduction B block
158 graph << get_reductionB_block(data_path);
159 // 3 inception C blocks
160 graph << get_inceptionC_block(data_path, "Mixed_7b");
161 graph << get_inceptionC_block(data_path, "Mixed_7c");
162 graph << get_inceptionC_block(data_path, "Mixed_7d");
163 graph << PoolingLayer(PoolingLayerInfo(PoolingType::AVG))
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000164 << FlattenLayer()
165 << FullyConnectedLayer(
166 1001U,
167 get_weights_accessor(data_path, "/cnn_data/inceptionv4_model/Logits_Logits_weights.npy"),
168 get_weights_accessor(data_path, "/cnn_data/inceptionv4_model/Logits_Logits_biases.npy"))
169 << SoftmaxLayer()
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000170 << OutputLayer(get_output_accessor(label, 5));
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000171
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000172 // Finalize graph
Georgios Pinitas9a8c6722018-03-21 17:52:35 +0000173 GraphConfig config;
Georgios Pinitas3d1489d2018-05-03 20:47:16 +0100174 config.use_tuner = (target == 2);
Georgios Pinitas9a8c6722018-03-21 17:52:35 +0000175 graph.finalize(target_hint, config);
Pablo Telloeb82fd22018-02-23 13:43:50 +0000176#else /* __aarch64__ */
177 using namespace arm_compute;
178 ARM_COMPUTE_UNUSED(argc);
179 ARM_COMPUTE_UNUSED(argv);
180#endif /* __aarch64__ */
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000181 }
182
183 void do_run() override
184 {
Pablo Telloeb82fd22018-02-23 13:43:50 +0000185#if __aarch64__
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000186 graph.run();
Pablo Telloeb82fd22018-02-23 13:43:50 +0000187#endif /* __aarch64__ */
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000188 }
189
190private:
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000191 Stream graph{ 0, "InceptionV4" };
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000192
193private:
194 BranchLayer get_mixed_3a(const std::string &data_path)
195 {
196 std::string total_path = "/cnn_data/inceptionv4_model/Mixed_3a_";
197
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000198 SubStream i_a(graph);
199 i_a << PoolingLayer(PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL), true));
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000200
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000201 SubStream i_b(graph);
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000202 i_b << ConvolutionLayer(3U, 3U, 96U,
203 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_3x3_weights.npy"),
204 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(2, 2, 0, 0))
205 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_3x3_BatchNorm_moving_mean.npy"),
206 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_3x3_BatchNorm_moving_variance.npy"),
207 get_random_accessor(1.f, 1.f),
208 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_3x3_BatchNorm_beta.npy"),
209 0.001f)
210 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
211
212 return BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_a), std::move(i_b));
213 }
214
215 BranchLayer get_mixed_4a(const std::string &data_path)
216 {
217 std::string total_path = "/cnn_data/inceptionv4_model/Mixed_4a_";
218
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000219 SubStream i_a(graph);
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000220 i_a << ConvolutionLayer(1U, 1U, 64U,
221 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_weights.npy"),
222 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
223 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
224 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
225 get_random_accessor(1.f, 1.f),
226 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_beta.npy"),
227 0.001f)
228 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
229 << ConvolutionLayer(3U, 3U, 96U,
230 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_weights.npy"),
231 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
232 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_BatchNorm_moving_mean.npy"),
233 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_BatchNorm_moving_variance.npy"),
234 get_random_accessor(1.f, 1.f),
235 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_BatchNorm_beta.npy"),
236 0.001f)
237 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
238
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000239 SubStream i_b(graph);
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000240 i_b << ConvolutionLayer(1U, 1U, 64U,
241 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_weights.npy"),
242 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
243 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
244 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
245 get_random_accessor(1.f, 1.f),
246 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_beta.npy"),
247 0.001f)
248 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
249 << ConvolutionLayer(7U, 1U, 64U,
250 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_weights.npy"),
251 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 3, 0))
252 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_moving_mean.npy"),
253 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_moving_variance.npy"),
254 get_random_accessor(1.f, 1.f),
255 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_beta.npy"),
256 0.001f)
257 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
258 << ConvolutionLayer(1U, 7U, 64U,
259 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_weights.npy"),
260 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 3))
261 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_moving_mean.npy"),
262 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_moving_variance.npy"),
263 get_random_accessor(1.f, 1.f),
264 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_beta.npy"),
265 0.001f)
266 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
267 << ConvolutionLayer(3U, 3U, 96U,
268 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_3x3_weights.npy"),
269 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
270 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_3x3_BatchNorm_moving_mean.npy"),
271 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_3x3_BatchNorm_moving_variance.npy"),
272 get_random_accessor(1.f, 1.f),
273 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_3x3_BatchNorm_beta.npy"),
274 0.001f)
275 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
276
277 return BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_a), std::move(i_b));
278 }
279
280 BranchLayer get_mixed_5a(const std::string &data_path)
281 {
282 std::string total_path = "/cnn_data/inceptionv4_model/Mixed_5a_";
283
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000284 SubStream i_a(graph);
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000285 i_a << ConvolutionLayer(3U, 3U, 192U,
286 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_weights.npy"),
287 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(2, 2, 0, 0))
288 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_BatchNorm_moving_mean.npy"),
289 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_BatchNorm_moving_variance.npy"),
290 get_random_accessor(1.f, 1.f),
291 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_BatchNorm_beta.npy"),
292 0.001f)
293 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
294
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000295 SubStream i_b(graph);
296 i_b << PoolingLayer(PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL), true));
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000297
298 return BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_a), std::move(i_b));
299 }
300
301 BranchLayer get_inceptionA_block(const std::string &data_path, std::string &&param_path)
302 {
303 std::string total_path = "/cnn_data/inceptionv4_model/" + param_path + "_";
304
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000305 SubStream i_a(graph);
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000306 i_a << ConvolutionLayer(1U, 1U, 96U,
307 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_weights.npy"),
308 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
309 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
310 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
311 get_random_accessor(1.f, 1.f),
312 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_beta.npy"),
313 0.001f)
314 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
315
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000316 SubStream i_b(graph);
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000317 i_b << ConvolutionLayer(1U, 1U, 64U,
318 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_weights.npy"),
319 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
320 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
321 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
322 get_random_accessor(1.f, 1.f),
323 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_beta.npy"),
324 0.001f)
325 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
326 << ConvolutionLayer(3U, 3U, 96U,
327 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_3x3_weights.npy"),
328 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 1, 1))
329 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_3x3_BatchNorm_moving_mean.npy"),
330 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_3x3_BatchNorm_moving_variance.npy"),
331 get_random_accessor(1.f, 1.f),
332 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_3x3_BatchNorm_beta.npy"),
333 0.001f)
334 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
335
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000336 SubStream i_c(graph);
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000337 i_c << ConvolutionLayer(1U, 1U, 64U,
338 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_weights.npy"),
339 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
340 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
341 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
342 get_random_accessor(1.f, 1.f),
343 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_beta.npy"),
344 0.001f)
345 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
346 << ConvolutionLayer(3U, 3U, 96U,
347 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_weights.npy"),
348 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 1, 1))
349 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_BatchNorm_moving_mean.npy"),
350 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_BatchNorm_moving_variance.npy"),
351 get_random_accessor(1.f, 1.f),
352 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_BatchNorm_beta.npy"),
353 0.001f)
354 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
355 << ConvolutionLayer(3U, 3U, 96U,
356 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_3x3_weights.npy"),
357 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 1, 1))
358 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_3x3_BatchNorm_moving_mean.npy"),
359 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_3x3_BatchNorm_moving_variance.npy"),
360 get_random_accessor(1.f, 1.f),
361 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_3x3_BatchNorm_beta.npy"),
362 0.001f)
363 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
364
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000365 SubStream i_d(graph);
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000366 i_d << PoolingLayer(PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 1, 1, DimensionRoundingType::CEIL), true))
367 << ConvolutionLayer(1U, 1U, 96U,
368 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_weights.npy"),
369 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
370 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_moving_mean.npy"),
371 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_moving_variance.npy"),
372 get_random_accessor(1.f, 1.f),
373 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_beta.npy"),
374 0.001f)
375 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
376
377 return BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_a), std::move(i_b), std::move(i_c), std::move(i_d));
378 }
379
380 BranchLayer get_reductionA_block(const std::string &data_path)
381 {
382 std::string total_path = "/cnn_data/inceptionv4_model/Mixed_6a_";
383
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000384 SubStream i_a(graph);
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000385 i_a << ConvolutionLayer(3U, 3U, 384U,
386 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_weights.npy"),
387 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(2, 2, 0, 0))
388 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_BatchNorm_moving_mean.npy"),
389 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_BatchNorm_moving_variance.npy"),
390 get_random_accessor(1.f, 1.f),
391 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_BatchNorm_beta.npy"),
392 0.001f)
393 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
394
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000395 SubStream i_b(graph);
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000396 i_b << ConvolutionLayer(1U, 1U, 192U,
397 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_weights.npy"),
398 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
399 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
400 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
401 get_random_accessor(1.f, 1.f),
402 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_beta.npy"),
403 0.001f)
404 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
405 << ConvolutionLayer(3U, 3U, 224U,
406 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_3x3_weights.npy"),
407 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 1, 1))
408 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_3x3_BatchNorm_moving_mean.npy"),
409 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_3x3_BatchNorm_moving_variance.npy"),
410 get_random_accessor(1.f, 1.f),
411 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_3x3_BatchNorm_beta.npy"),
412 0.001f)
413 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
414 << ConvolutionLayer(3U, 3U, 256U,
415 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_3x3_weights.npy"),
416 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(2, 2, 0, 0))
417 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_3x3_BatchNorm_moving_mean.npy"),
418 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_3x3_BatchNorm_moving_variance.npy"),
419 get_random_accessor(1.f, 1.f),
420 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_3x3_BatchNorm_beta.npy"),
421 0.001f)
422 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
423
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000424 SubStream i_c(graph);
425 i_c << PoolingLayer(PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL), true));
426
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000427 return BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_a), std::move(i_b), std::move(i_c));
428 }
429
430 BranchLayer get_inceptionB_block(const std::string &data_path, std::string &&param_path)
431 {
432 std::string total_path = "/cnn_data/inceptionv4_model/" + param_path + "_";
433
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000434 SubStream i_a(graph);
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000435 i_a << ConvolutionLayer(1U, 1U, 384U,
436 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_weights.npy"),
437 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
438 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
439 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
440 get_random_accessor(1.f, 1.f),
441 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_beta.npy"),
442 0.001f)
443 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
444
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000445 SubStream i_b(graph);
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000446 i_b << ConvolutionLayer(1U, 1U, 192U,
447 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_weights.npy"),
448 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
449 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
450 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
451 get_random_accessor(1.f, 1.f),
452 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_beta.npy"),
453 0.001f)
454 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
455 << ConvolutionLayer(7U, 1U, 224U,
456 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_weights.npy"),
457 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 3, 0))
458 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_moving_mean.npy"),
459 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_moving_variance.npy"),
460 get_random_accessor(1.f, 1.f),
461 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_beta.npy"),
462 0.001f)
463 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
464 << ConvolutionLayer(1U, 7U, 256U,
465 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_weights.npy"),
466 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 3))
467 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_moving_mean.npy"),
468 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_moving_variance.npy"),
469 get_random_accessor(1.f, 1.f),
470 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_beta.npy"),
471 0.001f)
472 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
473
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000474 SubStream i_c(graph);
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000475 i_c << ConvolutionLayer(1U, 1U, 192U,
476 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_weights.npy"),
477 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
478 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
479 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
480 get_random_accessor(1.f, 1.f),
481 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_beta.npy"),
482 0.001f)
483 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
484 << ConvolutionLayer(1U, 7U, 192U,
485 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_7x1_weights.npy"),
486 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 3))
487 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_7x1_BatchNorm_moving_mean.npy"),
488 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_7x1_BatchNorm_moving_variance.npy"),
489 get_random_accessor(1.f, 1.f),
490 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_7x1_BatchNorm_beta.npy"),
491 0.001f)
492 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
493 << ConvolutionLayer(7U, 1U, 224U,
494 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x7_weights.npy"),
495 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 3, 0))
496 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x7_BatchNorm_moving_mean.npy"),
497 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x7_BatchNorm_moving_variance.npy"),
498 get_random_accessor(1.f, 1.f),
499 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x7_BatchNorm_beta.npy"),
500 0.001f)
501 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
502 << ConvolutionLayer(1U, 7U, 224U,
503 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_7x1_weights.npy"),
504 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 3))
505 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_7x1_BatchNorm_moving_mean.npy"),
506 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_7x1_BatchNorm_moving_variance.npy"),
507 get_random_accessor(1.f, 1.f),
508 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_7x1_BatchNorm_beta.npy"),
509 0.001f)
510 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
511 << ConvolutionLayer(7U, 1U, 256U,
512 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0e_1x7_weights.npy"),
513 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 3, 0))
514 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0e_1x7_BatchNorm_moving_mean.npy"),
515 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0e_1x7_BatchNorm_moving_variance.npy"),
516 get_random_accessor(1.f, 1.f),
517 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0e_1x7_BatchNorm_beta.npy"),
518 0.001f)
519 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
520
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000521 SubStream i_d(graph);
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000522 i_d << PoolingLayer(PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 1, 1, DimensionRoundingType::CEIL), true))
523 << ConvolutionLayer(1U, 1U, 128U,
524 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_weights.npy"),
525 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
526 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_moving_mean.npy"),
527 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_moving_variance.npy"),
528 get_random_accessor(1.f, 1.f),
529 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_beta.npy"),
530 0.001f)
531 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
532
533 return BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_a), std::move(i_b), std::move(i_c), std::move(i_d));
534 }
535
536 BranchLayer get_reductionB_block(const std::string &data_path)
537 {
538 std::string total_path = "/cnn_data/inceptionv4_model/Mixed_7a_";
539
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000540 SubStream i_a(graph);
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000541 i_a << ConvolutionLayer(1U, 1U, 192U,
542 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_weights.npy"),
543 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
544 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
545 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
546 get_random_accessor(1.f, 1.f),
547 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_beta.npy"),
548 0.001f)
549 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
550 << ConvolutionLayer(3U, 3U, 192U,
551 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_weights.npy"),
552 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(2, 2, 0, 0))
553 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_BatchNorm_moving_mean.npy"),
554 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_BatchNorm_moving_variance.npy"),
555 get_random_accessor(1.f, 1.f),
556 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_BatchNorm_beta.npy"),
557 0.001f)
558 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
559
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000560 SubStream i_b(graph);
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000561 i_b << ConvolutionLayer(1U, 1U, 256U,
562 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_weights.npy"),
563 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
564 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
565 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
566 get_random_accessor(1.f, 1.f),
567 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_beta.npy"),
568 0.001f)
569 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
570 << ConvolutionLayer(7U, 1U, 256U,
571 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_weights.npy"),
572 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 3, 0))
573 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_moving_mean.npy"),
574 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_moving_variance.npy"),
575 get_random_accessor(1.f, 1.f),
576 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_beta.npy"),
577 0.001f)
578 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
579 << ConvolutionLayer(1U, 7U, 320U,
580 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_weights.npy"),
581 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 3))
582 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_moving_mean.npy"),
583 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_moving_variance.npy"),
584 get_random_accessor(1.f, 1.f),
585 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_beta.npy"),
586 0.001f)
587 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
588 << ConvolutionLayer(3U, 3U, 320U,
589 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_3x3_weights.npy"),
590 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(2, 2, 0, 0))
591 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_3x3_BatchNorm_moving_mean.npy"),
592 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_3x3_BatchNorm_moving_variance.npy"),
593 get_random_accessor(1.f, 1.f),
594 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_3x3_BatchNorm_beta.npy"),
595 0.001f)
596 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
597
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000598 SubStream i_c(graph);
599 i_c << PoolingLayer(PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL), true));
600
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000601 return BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_a), std::move(i_b), std::move(i_c));
602 }
603
604 BranchLayer get_inceptionC_block(const std::string &data_path, std::string &&param_path)
605 {
606 std::string total_path = "/cnn_data/inceptionv4_model/" + param_path + "_";
607
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000608 SubStream i_a(graph);
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000609 i_a << ConvolutionLayer(1U, 1U, 256U,
610 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_weights.npy"),
611 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
612 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
613 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
614 get_random_accessor(1.f, 1.f),
615 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_beta.npy"),
616 0.001f)
617 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
618
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000619 SubStream i_b(graph);
620 i_b << ConvolutionLayer(
621 1U, 1U, 384U,
622 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_weights.npy"),
623 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
624 PadStrideInfo(1, 1, 0, 0))
625 << BatchNormalizationLayer(
626 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
627 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
628 get_random_accessor(1.f, 1.f),
629 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_beta.npy"),
630 0.001f)
631 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
632
633 SubStream i_b1(static_cast<IStream &>(i_b));
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000634 i_b1 << ConvolutionLayer(
635 3U, 1U, 256U,
636 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x3_weights.npy"),
637 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
638 PadStrideInfo(1, 1, 1, 0))
639 << BatchNormalizationLayer(
640 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x3_BatchNorm_moving_mean.npy"),
641 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x3_BatchNorm_moving_variance.npy"),
642 get_random_accessor(1.f, 1.f),
643 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x3_BatchNorm_beta.npy"),
644 0.001f)
645 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
646
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000647 SubStream i_b2(static_cast<IStream &>(i_b));
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000648 i_b2 << ConvolutionLayer(
649 1U, 3U, 256U,
650 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_3x1_weights.npy"),
651 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
652 PadStrideInfo(1, 1, 0, 1))
653 << BatchNormalizationLayer(
654 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_3x1_BatchNorm_moving_mean.npy"),
655 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_3x1_BatchNorm_moving_variance.npy"),
656 get_random_accessor(1.f, 1.f),
657 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_3x1_BatchNorm_beta.npy"),
658 0.001f)
659 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
660
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000661 // Merge b1 and b2
662 i_b << BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_b1), std::move(i_b2));
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000663
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000664 SubStream i_c(graph);
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000665 i_c << ConvolutionLayer(
666 1U, 1U, 384U,
667 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_weights.npy"),
668 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
669 PadStrideInfo(1, 1, 0, 0))
670 << BatchNormalizationLayer(
671 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
672 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
673 get_random_accessor(1.f, 1.f),
674 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_beta.npy"),
675 0.001f)
676 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
677 << ConvolutionLayer(
678 1U, 3U, 448U,
679 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x1_weights.npy"),
680 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
681 PadStrideInfo(1, 1, 0, 1))
682 << BatchNormalizationLayer(
683 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x1_BatchNorm_moving_mean.npy"),
684 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x1_BatchNorm_moving_variance.npy"),
685 get_random_accessor(1.f, 1.f),
686 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x1_BatchNorm_beta.npy"),
687 0.001f)
688 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
689 << ConvolutionLayer(
690 3U, 1U, 512U,
691 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x3_weights.npy"),
692 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
693 PadStrideInfo(1, 1, 1, 0))
694 << BatchNormalizationLayer(
695 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x3_BatchNorm_moving_mean.npy"),
696 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x3_BatchNorm_moving_variance.npy"),
697 get_random_accessor(1.f, 1.f),
698 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x3_BatchNorm_beta.npy"),
699 0.001f)
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000700 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000701
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000702 SubStream i_c1(static_cast<IStream &>(i_c));
703 i_c1 << ConvolutionLayer(
704 3U, 1U, 256U,
705 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_1x3_weights.npy"),
706 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
707 PadStrideInfo(1, 1, 1, 0))
708 << BatchNormalizationLayer(
709 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_1x3_BatchNorm_moving_mean.npy"),
710 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_1x3_BatchNorm_moving_variance.npy"),
711 get_random_accessor(1.f, 1.f),
712 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_1x3_BatchNorm_beta.npy"),
713 0.001f)
714 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
715
716 SubStream i_c2(static_cast<IStream &>(i_c));
717 i_c2 << ConvolutionLayer(
718 1U, 3U, 256U,
719 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0e_3x1_weights.npy"),
720 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
721 PadStrideInfo(1, 1, 0, 1))
722 << BatchNormalizationLayer(
723 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0e_3x1_BatchNorm_moving_mean.npy"),
724 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0e_3x1_BatchNorm_moving_variance.npy"),
725 get_random_accessor(1.f, 1.f),
726 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0e_3x1_BatchNorm_beta.npy"),
727 0.001f)
728 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
729
730 // Merge i_c1 and i_c2
731 i_c << BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_c1), std::move(i_c2));
732
733 SubStream i_d(graph);
Georgios Pinitas240cfa62018-02-26 19:58:04 +0000734 i_d << PoolingLayer(PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 1, 1, DimensionRoundingType::CEIL), true))
735 << ConvolutionLayer(1U, 1U, 256U,
736 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_weights.npy"),
737 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
738 << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_moving_mean.npy"),
739 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_moving_variance.npy"),
740 get_random_accessor(1.f, 1.f),
741 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_beta.npy"),
742 0.001f)
743 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU));
744
745 return BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_a), std::move(i_b), std::move(i_c), std::move(i_d));
746 }
747};
748
749/** Main program for Inception V4
750 *
751 * @param[in] argc Number of arguments
Giorgio Arena59631a12018-05-02 13:59:04 +0100752 * @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 +0000753 */
754int main(int argc, char **argv)
755{
756 return arm_compute::utils::run_example<InceptionV4Example>(argc, argv);
757}