blob: 80e771b135e11e6799c14224ca632b721cb5785e [file] [log] [blame]
Georgios Pinitas652bde52018-01-10 15:33:28 +00001/*
2 * Copyright (c) 2017-2018 ARM Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010024#include "arm_compute/graph.h"
Georgios Pinitas652bde52018-01-10 15:33:28 +000025#include "support/ToolchainSupport.h"
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010026#include "utils/CommonGraphOptions.h"
Georgios Pinitas652bde52018-01-10 15:33:28 +000027#include "utils/GraphUtils.h"
28#include "utils/Utils.h"
29
Georgios Pinitas652bde52018-01-10 15:33:28 +000030using namespace arm_compute::utils;
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010031using namespace arm_compute::graph::frontend;
Georgios Pinitas652bde52018-01-10 15:33:28 +000032using namespace arm_compute::graph_utils;
33
34/** Example demonstrating how to implement InceptionV3's network using the Compute Library's graph API
35 *
36 * @param[in] argc Number of arguments
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010037 * @param[in] argv Arguments
Georgios Pinitas652bde52018-01-10 15:33:28 +000038 */
Georgios Pinitasd8734b52017-12-22 15:27:52 +000039class InceptionV3Example : public Example
Georgios Pinitas652bde52018-01-10 15:33:28 +000040{
41public:
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010042 InceptionV3Example()
43 : cmd_parser(), common_opts(cmd_parser), common_params(), graph(0, "InceptionV3")
Georgios Pinitas652bde52018-01-10 15:33:28 +000044 {
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010045 }
46 bool do_setup(int argc, char **argv) override
47 {
48 // Parse arguments
49 cmd_parser.parse(argc, argv);
50
51 // Consume common parameters
52 common_params = consume_common_graph_parameters(common_opts);
53
54 // Return when help menu is requested
55 if(common_params.help)
56 {
57 cmd_parser.print_help(argv[0]);
58 return false;
59 }
60
Georgios Pinitas415a2bf2018-07-30 12:05:25 +010061 // Set default layout if needed
62 if(!common_opts.data_layout->is_set() && common_params.target == Target::NEON)
63 {
64 common_params.data_layout = DataLayout::NCHW;
65 }
66
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010067 // Checks
Anthony Barbiercdd68c02018-08-23 15:03:41 +010068 ARM_COMPUTE_EXIT_ON_MSG(arm_compute::is_data_type_quantized_asymmetric(common_params.data_type), "QASYMM8 not supported for this graph");
69 ARM_COMPUTE_EXIT_ON_MSG(common_params.data_type == DataType::F16 && common_params.target == Target::NEON, "F16 NEON not supported for this graph");
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010070
71 // Print parameter values
72 std::cout << common_params << std::endl;
73
74 // Get trainable parameters data path
75 std::string data_path = common_params.data_path;
Georgios Pinitas652bde52018-01-10 15:33:28 +000076
Georgios Pinitas140fdc72018-02-16 11:42:38 +000077 // Create a preprocessor object
78 std::unique_ptr<IPreprocessor> preprocessor = arm_compute::support::cpp14::make_unique<TFPreproccessor>();
Georgios Pinitas652bde52018-01-10 15:33:28 +000079
Georgios Pinitase2220552018-07-20 13:23:44 +010080 // Create input descriptor
81 const TensorShape tensor_shape = permute_shape(TensorShape(299U, 299U, 3U, 1U), DataLayout::NCHW, common_params.data_layout);
82 TensorDescriptor input_descriptor = TensorDescriptor(tensor_shape, common_params.data_type).set_layout(common_params.data_layout);
83
84 // Set weights trained layout
85 const DataLayout weights_layout = DataLayout::NCHW;
86
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010087 graph << common_params.target
88 << common_params.fast_math_hint
Georgios Pinitase2220552018-07-20 13:23:44 +010089 << InputLayer(input_descriptor, get_input_accessor(common_params, std::move(preprocessor), false))
Georgios Pinitas652bde52018-01-10 15:33:28 +000090 << ConvolutionLayer(3U, 3U, 32U,
Georgios Pinitase2220552018-07-20 13:23:44 +010091 get_weights_accessor(data_path, "/cnn_data/inceptionv3_model/Conv2d_1a_3x3_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +000092 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(2, 2, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +010093 .set_name("Conv2d_1a_3x3/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +000094 << BatchNormalizationLayer(get_weights_accessor(data_path,
95 "/cnn_data/inceptionv3_model/Conv2d_1a_3x3_BatchNorm_moving_mean.npy"),
96 get_weights_accessor(data_path,
97 "/cnn_data/inceptionv3_model/Conv2d_1a_3x3_BatchNorm_moving_variance.npy"),
98 get_random_accessor(1.f, 1.f), get_weights_accessor(data_path,
99 "/cnn_data/inceptionv3_model/Conv2d_1a_3x3_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000100 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100101 .set_name("Conv2d_1a_3x3/BatchNorm/batchnorm")
102 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("Conv2d_1a_3x3/Relu")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000103 << ConvolutionLayer(3U, 3U, 32U,
Georgios Pinitase2220552018-07-20 13:23:44 +0100104 get_weights_accessor(data_path, "/cnn_data/inceptionv3_model/Conv2d_2a_3x3_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000105 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100106 .set_name("Conv2d_2a_3x3/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000107 << BatchNormalizationLayer(get_weights_accessor(data_path,
108 "/cnn_data/inceptionv3_model/Conv2d_2a_3x3_BatchNorm_moving_mean.npy"),
109 get_weights_accessor(data_path,
110 "/cnn_data/inceptionv3_model/Conv2d_2a_3x3_BatchNorm_moving_variance.npy"),
111 get_random_accessor(1.f, 1.f), get_weights_accessor(data_path,
112 "/cnn_data/inceptionv3_model/Conv2d_2a_3x3_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000113 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100114 .set_name("Conv2d_2a_3x3/BatchNorm/batchnorm")
115 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("Conv2d_2a_3x3/Relu")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000116
117 << ConvolutionLayer(3U, 3U, 64U,
Georgios Pinitase2220552018-07-20 13:23:44 +0100118 get_weights_accessor(data_path, "/cnn_data/inceptionv3_model/Conv2d_2b_3x3_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000119 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 1, 1))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100120 .set_name("Conv2d_2b_3x3/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000121 << BatchNormalizationLayer(get_weights_accessor(data_path,
122 "/cnn_data/inceptionv3_model/Conv2d_2b_3x3_BatchNorm_moving_mean.npy"),
123 get_weights_accessor(data_path,
124 "/cnn_data/inceptionv3_model/Conv2d_2b_3x3_BatchNorm_moving_variance.npy"),
125 get_random_accessor(1.f, 1.f), get_weights_accessor(data_path,
126 "/cnn_data/inceptionv3_model/Conv2d_2b_3x3_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000127 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100128 .set_name("Conv2d_2b_3x3/BatchNorm/batchnorm")
129 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("Conv2d_2b_3x3/Relu")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000130
Georgios Pinitas130986a2018-05-14 19:25:37 +0100131 << PoolingLayer(PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))).set_name("MaxPool_3a_3x3/MaxPool")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000132
133 << ConvolutionLayer(1U, 1U, 80U,
Georgios Pinitase2220552018-07-20 13:23:44 +0100134 get_weights_accessor(data_path, "/cnn_data/inceptionv3_model/Conv2d_3b_1x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000135 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100136 .set_name("Conv2d_3b_1x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000137 << BatchNormalizationLayer(get_weights_accessor(data_path,
138 "/cnn_data/inceptionv3_model/Conv2d_3b_1x1_BatchNorm_moving_mean.npy"),
139 get_weights_accessor(data_path,
140 "/cnn_data/inceptionv3_model/Conv2d_3b_1x1_BatchNorm_moving_variance.npy"),
141 get_random_accessor(1.f, 1.f), get_weights_accessor(data_path,
142 "/cnn_data/inceptionv3_model/Conv2d_3b_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000143 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100144 .set_name("Conv2d_3b_1x1/BatchNorm/batchnorm")
145 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("Conv2d_3b_1x1/Relu")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000146
147 << ConvolutionLayer(3U, 3U, 192U,
Georgios Pinitase2220552018-07-20 13:23:44 +0100148 get_weights_accessor(data_path, "/cnn_data/inceptionv3_model/Conv2d_4a_3x3_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000149 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100150 .set_name("Conv2d_4a_3x3/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000151 << BatchNormalizationLayer(get_weights_accessor(data_path,
152 "/cnn_data/inceptionv3_model/Conv2d_4a_3x3_BatchNorm_moving_mean.npy"),
153 get_weights_accessor(data_path,
154 "/cnn_data/inceptionv3_model/Conv2d_4a_3x3_BatchNorm_moving_variance.npy"),
155 get_random_accessor(1.f, 1.f), get_weights_accessor(data_path,
156 "/cnn_data/inceptionv3_model/Conv2d_4a_3x3_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000157 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100158 .set_name("Conv2d_4a_3x3/BatchNorm/batchnorm")
159 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("Conv2d_4a_3x3/Relu")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000160
Georgios Pinitas130986a2018-05-14 19:25:37 +0100161 << PoolingLayer(PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))).set_name("MaxPool_5a_3x3/MaxPool");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000162
Georgios Pinitase2220552018-07-20 13:23:44 +0100163 graph << get_inception_node_A(data_path, "Mixed_5b", weights_layout, 64U, std::make_tuple(48U, 64U), std::make_tuple(64U, 96U, 96U),
Georgios Pinitas130986a2018-05-14 19:25:37 +0100164 32U)
165 .set_name("Mixed_5b/concat");
Georgios Pinitase2220552018-07-20 13:23:44 +0100166 graph << get_inception_node_A(data_path, "Mixed_5c", weights_layout, 64U, std::make_tuple(48U, 64U), std::make_tuple(64U, 96U, 96U),
Georgios Pinitas130986a2018-05-14 19:25:37 +0100167 64U, true)
168 .set_name("Mixed_5c/concat");
Georgios Pinitase2220552018-07-20 13:23:44 +0100169 graph << get_inception_node_A(data_path, "Mixed_5d", weights_layout, 64U, std::make_tuple(48U, 64U), std::make_tuple(64U, 96U, 96U),
Georgios Pinitas130986a2018-05-14 19:25:37 +0100170 64U)
171 .set_name("Mixed_5d/concat");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000172
Georgios Pinitase2220552018-07-20 13:23:44 +0100173 graph << get_inception_node_B(data_path, "Mixed_6a", weights_layout, 384U, std::make_tuple(64U, 96U, 96U)).set_name("Mixed_6a/concat");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000174
Georgios Pinitase2220552018-07-20 13:23:44 +0100175 graph << get_inception_node_C(data_path, "Mixed_6b", weights_layout, 192U, std::make_tuple(128U, 128U, 192U),
Georgios Pinitas130986a2018-05-14 19:25:37 +0100176 std::make_tuple(128U, 128U, 128U, 128U, 192U), 192U)
177 .set_name("Mixed_6b/concat");
Georgios Pinitase2220552018-07-20 13:23:44 +0100178 graph << get_inception_node_C(data_path, "Mixed_6c", weights_layout, 192U, std::make_tuple(160U, 160U, 192U),
Georgios Pinitas130986a2018-05-14 19:25:37 +0100179 std::make_tuple(160U, 160U, 160U, 160U, 192U), 192U)
180 .set_name("Mixed_6c/concat");
Georgios Pinitase2220552018-07-20 13:23:44 +0100181 graph << get_inception_node_C(data_path, "Mixed_6d", weights_layout, 192U, std::make_tuple(160U, 160U, 192U),
Georgios Pinitas130986a2018-05-14 19:25:37 +0100182 std::make_tuple(160U, 160U, 160U, 160U, 192U), 192U)
183 .set_name("Mixed_6d/concat");
Georgios Pinitase2220552018-07-20 13:23:44 +0100184 graph << get_inception_node_C(data_path, "Mixed_6e", weights_layout, 192U, std::make_tuple(192U, 192U, 192U),
Georgios Pinitas130986a2018-05-14 19:25:37 +0100185 std::make_tuple(192U, 192U, 192U, 192U, 192U), 192U)
186 .set_name("Mixed_6e/concat");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000187
Georgios Pinitase2220552018-07-20 13:23:44 +0100188 graph << get_inception_node_D(data_path, "Mixed_7a", weights_layout, std::make_tuple(192U, 320U),
Georgios Pinitas130986a2018-05-14 19:25:37 +0100189 std::make_tuple(192U, 192U, 192U, 192U))
190 .set_name("Mixed_7a/concat");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000191
Georgios Pinitase2220552018-07-20 13:23:44 +0100192 graph << get_inception_node_E(data_path, "Mixed_7b", weights_layout, 320U, std::make_tuple(384U, 384U, 384U),
Georgios Pinitas130986a2018-05-14 19:25:37 +0100193 std::make_tuple(448U, 384U, 384U, 384U), 192U)
194 .set_name("Mixed_7b/concat");
Georgios Pinitase2220552018-07-20 13:23:44 +0100195 graph << get_inception_node_E(data_path, "Mixed_7c", weights_layout, 320U, std::make_tuple(384U, 384U, 384U),
Georgios Pinitas130986a2018-05-14 19:25:37 +0100196 std::make_tuple(448U, 384U, 384U, 384U), 192U, true)
197 .set_name("Mixed_7c/concat");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000198
Georgios Pinitas130986a2018-05-14 19:25:37 +0100199 graph << PoolingLayer(PoolingLayerInfo(PoolingType::AVG, 8, PadStrideInfo(1, 1, 0, 0, DimensionRoundingType::CEIL))).set_name("Logits/AvgPool_1a_8x8/AvgPool")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000200 << ConvolutionLayer(1U, 1U, 1001U, get_weights_accessor(data_path,
Georgios Pinitase2220552018-07-20 13:23:44 +0100201 "/cnn_data/inceptionv3_model/Logits_Conv2d_1c_1x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000202 get_weights_accessor(data_path,
203 "/cnn_data/inceptionv3_model/Logits_Conv2d_1c_1x1_biases.npy"),
204 PadStrideInfo(1, 1, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100205 .set_name("Logits/Conv2d_1c_1x1/convolution")
206 << ReshapeLayer(TensorShape(1001U)).set_name("Predictions/Reshape")
207 << SoftmaxLayer().set_name("Predictions/Softmax")
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100208 << OutputLayer(get_output_accessor(common_params, 5));
Gian Marcoc1b6e372018-02-21 18:03:26 +0000209
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000210 // Finalize graph
Georgios Pinitas9a8c6722018-03-21 17:52:35 +0000211 GraphConfig config;
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100212 config.num_threads = common_params.threads;
213 config.use_tuner = common_params.enable_tuner;
Anthony Barbier7b607dc2018-07-13 15:55:24 +0100214 config.tuner_file = common_params.tuner_file;
215
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100216 graph.finalize(common_params.target, config);
217
218 return true;
Georgios Pinitas652bde52018-01-10 15:33:28 +0000219 }
220
221 void do_run() override
222 {
223 graph.run();
224 }
225
226private:
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100227 CommandLineParser cmd_parser;
228 CommonGraphOptions common_opts;
229 CommonGraphParams common_params;
230 Stream graph;
Georgios Pinitas652bde52018-01-10 15:33:28 +0000231
232private:
Georgios Pinitas427bbbf2018-08-28 13:32:02 +0100233 ConcatLayer get_inception_node_A(const std::string &data_path, std::string &&param_path, DataLayout weights_layout,
Georgios Pinitas652bde52018-01-10 15:33:28 +0000234 unsigned int a_filt,
235 std::tuple<unsigned int, unsigned int> b_filters,
236 std::tuple<unsigned int, unsigned int, unsigned int> c_filters,
237 unsigned int d_filt,
238 bool is_name_different = false)
239 {
240 std::string total_path = "/cnn_data/inceptionv3_model/" + param_path + "_";
Georgios Pinitas652bde52018-01-10 15:33:28 +0000241
242 // This is due to a naming issue in the tf model
243 std::string conv_id0 = "_0a_";
244 std::string conv_id1 = "2d_0b_";
245 if(is_name_different)
246 {
247 conv_id0 = "_0b_";
248 conv_id1 = "_1_0c_";
249 }
250
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000251 SubStream i_a(graph);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000252 i_a << ConvolutionLayer(
253 1U, 1U, a_filt,
Georgios Pinitase2220552018-07-20 13:23:44 +0100254 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000255 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
256 PadStrideInfo(1, 1, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100257 .set_name(param_path + "/Branch_0/Conv2d_0a_1x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000258 << BatchNormalizationLayer(
259 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
260 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
261 get_random_accessor(1.f, 1.f),
262 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000263 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100264 .set_name(param_path + "/Branch_0/Conv2d_0a_1x1/BatchNorm/batchnorm")
265 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_0/Conv2d_0a_1x1/Relu");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000266
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000267 SubStream i_b(graph);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000268 i_b << ConvolutionLayer(
269 1U, 1U, std::get<0>(b_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100270 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d" + conv_id0 + "1x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000271 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
272 PadStrideInfo(1, 1, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100273 .set_name(param_path + "/Branch_1/Conv2d" + conv_id0 + "1x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000274 << BatchNormalizationLayer(
275 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d" + conv_id0 + "1x1_BatchNorm_moving_mean.npy"),
276 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d" + conv_id0 + "1x1_BatchNorm_moving_variance.npy"),
277 get_random_accessor(1.f, 1.f),
278 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d" + conv_id0 + "1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000279 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100280 .set_name(param_path + "/Branch_1/Conv2d" + conv_id0 + "1x1/BatchNorm/batchnorm")
281 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_1/Conv2d" + conv_id0 + "1x1/Relu")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000282 << ConvolutionLayer(
283 5U, 5U, std::get<1>(b_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100284 get_weights_accessor(data_path, total_path + "Branch_1_Conv" + conv_id1 + "5x5_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000285 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
286 PadStrideInfo(1, 1, 2, 2))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100287 .set_name(param_path + "/Branch_1/Conv2d" + conv_id1 + "5x5/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000288 << BatchNormalizationLayer(
289 get_weights_accessor(data_path, total_path + "Branch_1_Conv" + conv_id1 + "5x5_BatchNorm_moving_mean.npy"),
290 get_weights_accessor(data_path, total_path + "Branch_1_Conv" + conv_id1 + "5x5_BatchNorm_moving_variance.npy"),
291 get_random_accessor(1.f, 1.f),
292 get_weights_accessor(data_path, total_path + "Branch_1_Conv" + conv_id1 + "5x5_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000293 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100294 .set_name(param_path + "/Branch_1/Conv2d" + conv_id1 + "5x5/BatchNorm/batchnorm")
295 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_1/Conv2d" + conv_id1 + "5x5/Relu");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000296
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000297 SubStream i_c(graph);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000298 i_c << ConvolutionLayer(
299 1U, 1U, std::get<0>(c_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100300 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000301 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
302 PadStrideInfo(1, 1, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100303 .set_name(param_path + "/Branch_2/Conv2d_0a_1x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000304 << BatchNormalizationLayer(
305 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
306 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
307 get_random_accessor(1.f, 1.f),
308 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000309 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100310 .set_name(param_path + "/Branch_2/Conv2d_0a_1x1/BatchNorm/batchnorm")
311 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_2/Conv2d_0a_1x1/Relu")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000312 << ConvolutionLayer(
313 3U, 3U, std::get<1>(c_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100314 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000315 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
316 PadStrideInfo(1, 1, 1, 1))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100317 .set_name(param_path + "/Branch_2/Conv2d_0b_3x3/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000318 << BatchNormalizationLayer(
319 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_BatchNorm_moving_mean.npy"),
320 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_BatchNorm_moving_variance.npy"),
321 get_random_accessor(1.f, 1.f),
322 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000323 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100324 .set_name(param_path + "/Branch_2/Conv2d_0b_3x3/BatchNorm/batchnorm")
325 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_2/Conv2d_0b_3x3/Relu")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000326 << ConvolutionLayer(
327 3U, 3U, std::get<2>(c_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100328 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_3x3_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000329 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
330 PadStrideInfo(1, 1, 1, 1))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100331 .set_name(param_path + "/Branch_2/Conv2d_0c_3x3/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000332 << BatchNormalizationLayer(
333 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_3x3_BatchNorm_moving_mean.npy"),
334 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_3x3_BatchNorm_moving_variance.npy"),
335 get_random_accessor(1.f, 1.f),
336 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_3x3_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000337 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100338 .set_name(param_path + "/Branch_2/Conv2d_0c_3x3/BatchNorm/batcnorm")
339 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_2/Conv2d_0c_3x3/Relu");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000340
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000341 SubStream i_d(graph);
Georgios Pinitas130986a2018-05-14 19:25:37 +0100342 i_d << PoolingLayer(PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 1, 1, DimensionRoundingType::CEIL), true)).set_name(param_path + "/Branch_3/AvgPool_0a_3x3/AvgPool")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000343 << ConvolutionLayer(
344 1U, 1U, d_filt,
Georgios Pinitase2220552018-07-20 13:23:44 +0100345 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000346 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
347 PadStrideInfo(1, 1, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100348 .set_name(param_path + "/Branch_3/Conv2d_0b_1x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000349 << BatchNormalizationLayer(
350 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_moving_mean.npy"),
351 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_moving_variance.npy"),
352 get_random_accessor(1.f, 1.f),
353 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000354 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100355 .set_name(param_path + "/Branch_3/Conv2d_0b_1x1/BatchNorm/batchnorm")
356 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_3/Conv2d_0b_1x1/Relu");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000357
Georgios Pinitas427bbbf2018-08-28 13:32:02 +0100358 return ConcatLayer(std::move(i_a), std::move(i_b), std::move(i_c), std::move(i_d));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000359 }
360
Georgios Pinitas427bbbf2018-08-28 13:32:02 +0100361 ConcatLayer get_inception_node_B(const std::string &data_path, std::string &&param_path, DataLayout weights_layout,
Georgios Pinitas652bde52018-01-10 15:33:28 +0000362 unsigned int a_filt,
363 std::tuple<unsigned int, unsigned int, unsigned int> b_filters)
364 {
365 std::string total_path = "/cnn_data/inceptionv3_model/" + param_path + "_";
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000366 SubStream i_a(graph);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000367 i_a << ConvolutionLayer(
368 3U, 3U, a_filt,
Georgios Pinitase2220552018-07-20 13:23:44 +0100369 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_1x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000370 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
371 PadStrideInfo(2, 2, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100372 .set_name(param_path + "/Branch_0/Conv2d_1a_1x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000373 << BatchNormalizationLayer(
374 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_1x1_BatchNorm_moving_mean.npy"),
375 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_1x1_BatchNorm_moving_variance.npy"),
376 get_random_accessor(1.f, 1.f),
377 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000378 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100379 .set_name(param_path + "/Branch_0/Conv2d_1a_1x1/BatchNorm/batchnorm")
380 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_0/Conv2d_1a_1x1/Relu");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000381
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000382 SubStream i_b(graph);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000383 i_b << ConvolutionLayer(
384 1U, 1U, std::get<0>(b_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100385 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000386 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
387 PadStrideInfo(1, 1, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100388 .set_name(param_path + "/Branch_1/Conv2d_0a_1x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000389 << BatchNormalizationLayer(
390 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
391 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
392 get_random_accessor(1.f, 1.f),
393 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000394 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100395 .set_name(param_path + "/Branch_1/Conv2d_0a_1x1/BatchNorm/batchnorm")
396 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_1/Conv2d_0a_1x1/Relu")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000397 << ConvolutionLayer(
398 3U, 3U, std::get<1>(b_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100399 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_3x3_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000400 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
401 PadStrideInfo(1, 1, 1, 1))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100402 .set_name(param_path + "/Branch_1/Conv2d_0b_3x3/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000403 << BatchNormalizationLayer(
404 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_3x3_BatchNorm_moving_mean.npy"),
405 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_3x3_BatchNorm_moving_variance.npy"),
406 get_random_accessor(1.f, 1.f),
407 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_3x3_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000408 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100409 .set_name(param_path + "/Branch_1/Conv2d_0b_3x3/BatchNorm/batchnorm")
410 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_1/Conv2d_0b_3x3/Relu")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000411 << ConvolutionLayer(
412 3U, 3U, std::get<2>(b_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100413 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_1x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000414 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
415 PadStrideInfo(2, 2, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100416 .set_name(param_path + "/Branch_1/Conv2d_1a_1x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000417 << BatchNormalizationLayer(
418 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_1x1_BatchNorm_moving_mean.npy"),
419 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_1x1_BatchNorm_moving_variance.npy"),
420 get_random_accessor(1.f, 1.f),
421 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000422 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100423 .set_name(param_path + "/Branch_1/Conv2d_1a_1x1/BatchNorm/batchnorm")
424 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_1/Conv2d_1a_1x1/Relu");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000425
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000426 SubStream i_c(graph);
Georgios Pinitas130986a2018-05-14 19:25:37 +0100427 i_c << PoolingLayer(PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))).set_name(param_path + "/Branch_2/MaxPool_1a_3x3/MaxPool");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000428
Georgios Pinitas427bbbf2018-08-28 13:32:02 +0100429 return ConcatLayer(std::move(i_a), std::move(i_b), std::move(i_c));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000430 }
431
Georgios Pinitas427bbbf2018-08-28 13:32:02 +0100432 ConcatLayer get_inception_node_C(const std::string &data_path, std::string &&param_path, DataLayout weights_layout,
Georgios Pinitas652bde52018-01-10 15:33:28 +0000433 unsigned int a_filt,
434 std::tuple<unsigned int, unsigned int, unsigned int> b_filters,
435 std::tuple<unsigned int, unsigned int, unsigned int, unsigned int, unsigned int> c_filters,
436 unsigned int d_filt)
437 {
438 std::string total_path = "/cnn_data/inceptionv3_model/" + param_path + "_";
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000439 SubStream i_a(graph);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000440 i_a << ConvolutionLayer(
441 1U, 1U, a_filt,
Georgios Pinitase2220552018-07-20 13:23:44 +0100442 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000443 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
444 PadStrideInfo(1, 1, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100445 .set_name(param_path + "/Branch_0/Conv2d_0a_1x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000446 << BatchNormalizationLayer(
447 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
448 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
449 get_random_accessor(1.f, 1.f),
450 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000451 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100452 .set_name(param_path + "/Branch_0/Conv2d_0a_1x1/BatchNorm/batchnorm")
453 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_0/Conv2d_0a_1x1/Relu");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000454
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000455 SubStream i_b(graph);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000456 i_b << ConvolutionLayer(
457 1U, 1U, std::get<0>(b_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100458 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000459 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
460 PadStrideInfo(1, 1, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100461 .set_name(param_path + "/Branch_1/Conv2d_0a_1x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000462 << BatchNormalizationLayer(
463 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
464 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
465 get_random_accessor(1.f, 1.f),
466 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000467 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100468 .set_name(param_path + "/Branch_1/Conv2d_0a_1x1/BatchNorm/batchnorm")
469 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_1/Conv2d_0a_1x1/Relu")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000470 << ConvolutionLayer(
471 7U, 1U, std::get<1>(b_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100472 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000473 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
474 PadStrideInfo(1, 1, 3, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100475 .set_name(param_path + "/Branch_1/Conv2d_0b_1x7/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000476 << BatchNormalizationLayer(
477 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_moving_mean.npy"),
478 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_moving_variance.npy"),
479 get_random_accessor(1.f, 1.f),
480 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000481 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100482 .set_name(param_path + "/Branch_1/Conv2d_0b_1x7/BatchNorm/batchnorm")
483 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_1/Conv2d_0b_1x7/Relu")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000484 << ConvolutionLayer(
485 1U, 7U, std::get<2>(b_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100486 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000487 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
488 PadStrideInfo(1, 1, 0, 3))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100489 .set_name(param_path + "/Branch_1/Conv2d_0c_7x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000490 << BatchNormalizationLayer(
491 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_moving_mean.npy"),
492 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_moving_variance.npy"),
493 get_random_accessor(1.f, 1.f),
494 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000495 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100496 .set_name(param_path + "/Branch_1/Conv2d_0c_7x1/BatchNorm/batchnorm")
497 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_0/Conv2d_0c_7x1/Relu");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000498
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000499 SubStream i_c(graph);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000500 i_c << ConvolutionLayer(
501 1U, 1U, std::get<0>(c_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100502 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000503 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
504 PadStrideInfo(1, 1, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100505 .set_name(param_path + "/Branch_2/Conv2d_0a_1x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000506 << BatchNormalizationLayer(
507 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
508 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
509 get_random_accessor(1.f, 1.f),
510 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000511 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100512 .set_name(param_path + "/Branch_2/Conv2d_0a_1x1/BatchNorm/batchnorm")
513 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_2/Conv2d_0a_1x1/Relu")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000514 << ConvolutionLayer(
515 1U, 7U, std::get<1>(c_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100516 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_7x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000517 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
518 PadStrideInfo(1, 1, 0, 3))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100519 .set_name(param_path + "/Branch_2/Conv2d_0b_7x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000520 << BatchNormalizationLayer(
521 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_7x1_BatchNorm_moving_mean.npy"),
522 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_7x1_BatchNorm_moving_variance.npy"),
523 get_random_accessor(1.f, 1.f),
524 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_7x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000525 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100526 .set_name(param_path + "/Branch_2/Conv2d_0b_7x1/BatchNorm/batchnorm")
527 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_2/Conv2d_0b_7x1/Relu")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000528 << ConvolutionLayer(
529 7U, 1U, std::get<2>(c_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100530 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x7_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000531 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
532 PadStrideInfo(1, 1, 3, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100533 .set_name(param_path + "/Branch_2/Conv2d_0c_1x7/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000534 << BatchNormalizationLayer(
535 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x7_BatchNorm_moving_mean.npy"),
536 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x7_BatchNorm_moving_variance.npy"),
537 get_random_accessor(1.f, 1.f),
538 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x7_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000539 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100540 .set_name(param_path + "/Branch_2/Conv2d_0c_1x7/BatchNorm/batchnorm")
541 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_2/Conv2d_0c_1x7/Relu")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000542 << ConvolutionLayer(
543 1U, 7U, std::get<3>(c_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100544 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_7x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000545 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
546 PadStrideInfo(1, 1, 0, 3))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100547 .set_name(param_path + "/Branch_2/Conv2d_0d_7x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000548 << BatchNormalizationLayer(
549 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_7x1_BatchNorm_moving_mean.npy"),
550 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_7x1_BatchNorm_moving_variance.npy"),
551 get_random_accessor(1.f, 1.f),
552 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_7x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000553 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100554 .set_name(param_path + "/Branch_2/Conv2d_0d_7x1/BatchNorm/batchnorm")
555 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_2/Conv2d_0d_7x1/Relu")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000556 << ConvolutionLayer(
557 7U, 1U, std::get<4>(c_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100558 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0e_1x7_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000559 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
560 PadStrideInfo(1, 1, 3, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100561 .set_name(param_path + "/Branch_2/Conv2d_0e_1x7/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000562 << BatchNormalizationLayer(
563 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0e_1x7_BatchNorm_moving_mean.npy"),
564 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0e_1x7_BatchNorm_moving_variance.npy"),
565 get_random_accessor(1.f, 1.f),
566 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0e_1x7_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000567 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100568 .set_name(param_path + "/Branch_2/Conv2d_0e_1x7/BatchNorm/batchnorm")
569 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_2/Conv2d_0e_1x7/Relu");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000570
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000571 SubStream i_d(graph);
Georgios Pinitas130986a2018-05-14 19:25:37 +0100572 i_d << PoolingLayer(PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 1, 1, DimensionRoundingType::CEIL), true)).set_name(param_path + "/Branch_3/AvgPool_0a_3x3/AvgPool")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000573 << ConvolutionLayer(
574 1U, 1U, d_filt,
Georgios Pinitase2220552018-07-20 13:23:44 +0100575 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000576 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
577 PadStrideInfo(1, 1, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100578 .set_name(param_path + "/Branch_3/Conv2d_0b_1x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000579 << BatchNormalizationLayer(
580 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_moving_mean.npy"),
581 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_moving_variance.npy"),
582 get_random_accessor(1.f, 1.f),
583 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000584 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100585 .set_name(param_path + "/Branch_3/Conv2d_0b_1x1/BatchNorm/batchnorm")
586 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_3/Conv2d_0b_1x1/Relu");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000587
Georgios Pinitas427bbbf2018-08-28 13:32:02 +0100588 return ConcatLayer(std::move(i_a), std::move(i_b), std::move(i_c), std::move(i_d));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000589 }
590
Georgios Pinitas427bbbf2018-08-28 13:32:02 +0100591 ConcatLayer get_inception_node_D(const std::string &data_path, std::string &&param_path, DataLayout weights_layout,
Georgios Pinitase2220552018-07-20 13:23:44 +0100592 std::tuple<unsigned int, unsigned int> a_filters,
Georgios Pinitas652bde52018-01-10 15:33:28 +0000593 std::tuple<unsigned int, unsigned int, unsigned int, unsigned int> b_filters)
594 {
595 std::string total_path = "/cnn_data/inceptionv3_model/" + param_path + "_";
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000596 SubStream i_a(graph);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000597 i_a << ConvolutionLayer(
598 1U, 1U, std::get<0>(a_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100599 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000600 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
601 PadStrideInfo(1, 1, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100602 .set_name(param_path + "/Branch_0/Conv2d_0a_1x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000603 << BatchNormalizationLayer(
604 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
605 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
606 get_random_accessor(1.f, 1.f),
607 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000608 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100609 .set_name(param_path + "/Branch_0/Conv2d_0a_1x1/BatchNorm/batchnorm")
610 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_0/Conv2d_0a_1x1/Relu")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000611 << ConvolutionLayer(
612 3U, 3U, std::get<1>(a_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100613 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000614 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
615 PadStrideInfo(2, 2, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100616 .set_name(param_path + "/Branch_0/Conv2d_1a_3x3/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000617 << BatchNormalizationLayer(
618 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_BatchNorm_moving_mean.npy"),
619 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_BatchNorm_moving_variance.npy"),
620 get_random_accessor(1.f, 1.f),
621 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000622 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100623 .set_name(param_path + "/Branch_0/Conv2d_1a_3x3/BatchNorm/batchnorm")
624 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_0/Conv2d_1a_3x3/Relu");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000625
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000626 SubStream i_b(graph);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000627 i_b << ConvolutionLayer(
628 1U, 1U, std::get<0>(b_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100629 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000630 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
631 PadStrideInfo(1, 1, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100632 .set_name(param_path + "/Branch_1/Conv2d_0a_1x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000633 << BatchNormalizationLayer(
634 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
635 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
636 get_random_accessor(1.f, 1.f),
637 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000638 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100639 .set_name(param_path + "/Branch_1/Conv2d_0a_1x1/BatchNorm/batchnorm")
640 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_1/Conv2d_0a_1x1/Relu")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000641 << ConvolutionLayer(
642 7U, 1U, std::get<1>(b_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100643 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000644 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
645 PadStrideInfo(1, 1, 3, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100646 .set_name(param_path + "/Branch_1/Conv2d_0b_1x7/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000647 << BatchNormalizationLayer(
648 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_moving_mean.npy"),
649 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_moving_variance.npy"),
650 get_random_accessor(1.f, 1.f),
651 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000652 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100653 .set_name(param_path + "/Branch_1/Conv2d_0b_1x7/BatchNorm/batchnorm")
654 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_1/Conv2d_0b_1x7/Relu")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000655 << ConvolutionLayer(
656 1U, 7U, std::get<2>(b_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100657 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000658 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
659 PadStrideInfo(1, 1, 0, 3))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100660 .set_name(param_path + "/Branch_1/Conv2d_0c_7x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000661 << BatchNormalizationLayer(
662 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_moving_mean.npy"),
663 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_moving_variance.npy"),
664 get_random_accessor(1.f, 1.f),
665 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000666 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100667 .set_name(param_path + "/Branch_1/Conv2d_0c_7x1/BatchNorm/batchnorm")
668 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_1/Conv2d_0c_7x1/Relu")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000669 << ConvolutionLayer(
670 3U, 3U, std::get<3>(b_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100671 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_3x3_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000672 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
673 PadStrideInfo(2, 2, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100674 .set_name(param_path + "/Branch_1/Conv2d_1a_3x3/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000675 << BatchNormalizationLayer(
676 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_3x3_BatchNorm_moving_mean.npy"),
677 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_3x3_BatchNorm_moving_variance.npy"),
678 get_random_accessor(1.f, 1.f),
679 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_3x3_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000680 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100681 .set_name(param_path + "/Branch_1/Conv2d_1a_3x3/BatchNorm/batchnorm")
682 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_1/Conv2d_1a_3x3/Relu");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000683
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000684 SubStream i_c(graph);
Georgios Pinitas130986a2018-05-14 19:25:37 +0100685 i_c << PoolingLayer(PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))).set_name(param_path + "/Branch_2/MaxPool_1a_3x3/MaxPool");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000686
Georgios Pinitas427bbbf2018-08-28 13:32:02 +0100687 return ConcatLayer(std::move(i_a), std::move(i_b), std::move(i_c));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000688 }
689
Georgios Pinitas427bbbf2018-08-28 13:32:02 +0100690 ConcatLayer get_inception_node_E(const std::string &data_path, std::string &&param_path, DataLayout weights_layout,
Georgios Pinitas652bde52018-01-10 15:33:28 +0000691 unsigned int a_filt,
692 std::tuple<unsigned int, unsigned int, unsigned int> b_filters,
693 std::tuple<unsigned int, unsigned int, unsigned int, unsigned int> c_filters,
694 unsigned int d_filt,
695 bool is_name_different = false)
696 {
697 // This is due to a naming issue in the tf model
698 std::string conv_id = "_0b_";
699 if(is_name_different)
700 {
701 conv_id = "_0c_";
702 }
703
704 std::string total_path = "/cnn_data/inceptionv3_model/" + param_path + "_";
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000705 SubStream i_a(graph);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000706 i_a << ConvolutionLayer(
707 1U, 1U, a_filt,
Georgios Pinitase2220552018-07-20 13:23:44 +0100708 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000709 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
710 PadStrideInfo(1, 1, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100711 .set_name(param_path + "/Branch_0/Conv2d_0a_1x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000712 << BatchNormalizationLayer(
713 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
714 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
715 get_random_accessor(1.f, 1.f),
716 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000717 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100718 .set_name(param_path + "/Branch_0/Conv2d_0a_1x1/BatchNorm/batchnorm")
719 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_0/Conv2d_0a_1x1/Relu");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000720
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000721 SubStream i_b(graph);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000722 i_b << ConvolutionLayer(
723 1U, 1U, std::get<0>(b_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100724 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000725 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
726 PadStrideInfo(1, 1, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100727 .set_name(param_path + "/Branch_1/Conv2d_0a_1x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000728 << BatchNormalizationLayer(
729 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
730 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
731 get_random_accessor(1.f, 1.f),
732 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000733 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100734 .set_name(param_path + "/Branch_1/Conv2d_0a_1x1/BatchNorm/batchnorm")
735 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_1/Conv2d_0a_1x1/Relu");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000736
Georgios Pinitas772e17f2018-07-13 12:25:33 +0100737 SubStream i_b1(i_b);
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000738 i_b1 << ConvolutionLayer(
739 3U, 1U, std::get<1>(b_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100740 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x3_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000741 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
742 PadStrideInfo(1, 1, 1, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100743 .set_name(param_path + "/Branch_1/Conv2d_0b_1x3/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000744 << BatchNormalizationLayer(
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000745 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x3_BatchNorm_moving_mean.npy"),
746 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x3_BatchNorm_moving_variance.npy"),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000747 get_random_accessor(1.f, 1.f),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000748 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x3_BatchNorm_beta.npy"),
749 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100750 .set_name(param_path + "/Branch_1/Conv2d_0b_1x3/BatchNorm/batchnorm")
751 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_1/Conv2d_0b_1x3/Relu");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000752
Georgios Pinitas772e17f2018-07-13 12:25:33 +0100753 SubStream i_b2(i_b);
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000754 i_b2 << ConvolutionLayer(
755 1U, 3U, std::get<2>(b_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100756 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d" + conv_id + "3x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000757 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
758 PadStrideInfo(1, 1, 0, 1))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100759 .set_name(param_path + "/Branch_1/Conv2d" + conv_id + "3x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000760 << BatchNormalizationLayer(
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000761 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d" + conv_id + "3x1_BatchNorm_moving_mean.npy"),
762 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d" + conv_id + "3x1_BatchNorm_moving_variance.npy"),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000763 get_random_accessor(1.f, 1.f),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000764 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d" + conv_id + "3x1_BatchNorm_beta.npy"),
765 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100766 .set_name(param_path + "/Branch_1/Conv2d" + conv_id + "3x1/BatchNorm/batchnorm")
767 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_1/Conv2d" + conv_id + "3x1/Relu");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000768
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000769 // Merge b1 and b2
Georgios Pinitas427bbbf2018-08-28 13:32:02 +0100770 i_b << ConcatLayer(std::move(i_b1), std::move(i_b2)).set_name(param_path + "/Branch_1/concat");
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000771
772 SubStream i_c(graph);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000773 i_c << ConvolutionLayer(
774 1U, 1U, std::get<0>(c_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100775 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000776 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
777 PadStrideInfo(1, 1, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100778 .set_name(param_path + "/Branch_2/Conv2d_0a_1x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000779 << BatchNormalizationLayer(
780 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
781 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
782 get_random_accessor(1.f, 1.f),
783 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000784 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100785 .set_name(param_path + "/Branch_2/Conv2d_0a_1x1/BatchNorm/batchnorm")
786 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_2/Conv2d_0a_1x1/Relu")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000787 << ConvolutionLayer(
788 3U, 3U, std::get<1>(c_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100789 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000790 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
791 PadStrideInfo(1, 1, 1, 1))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100792 .set_name(param_path + "/Branch_2/Conv2d_0b_3x3/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000793 << BatchNormalizationLayer(
794 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_BatchNorm_moving_mean.npy"),
795 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_BatchNorm_moving_variance.npy"),
796 get_random_accessor(1.f, 1.f),
797 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000798 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100799 .set_name(param_path + "/Branch_2/Conv2d_0b_3x3/BatchNorm/batchnorm")
800 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_2/Conv2d_0b_3x3/Relu");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000801
Georgios Pinitas772e17f2018-07-13 12:25:33 +0100802 SubStream i_c1(i_c);
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000803 i_c1 << ConvolutionLayer(
804 3U, 1U, std::get<2>(c_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100805 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x3_weights.npy", weights_layout),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000806 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
807 PadStrideInfo(1, 1, 1, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100808 .set_name(param_path + "/Branch_2/Conv2d_0c_1x3/convolution")
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000809 << BatchNormalizationLayer(
810 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x3_BatchNorm_moving_mean.npy"),
811 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x3_BatchNorm_moving_variance.npy"),
812 get_random_accessor(1.f, 1.f),
813 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x3_BatchNorm_beta.npy"),
814 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100815 .set_name(param_path + "/Branch_2/Conv2d_0c_1x3/BatchNorm/batchnorm")
816 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_2/Conv2d_0c_1x3/Relu");
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000817
Georgios Pinitas772e17f2018-07-13 12:25:33 +0100818 SubStream i_c2(i_c);
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000819 i_c2 << ConvolutionLayer(
820 1U, 3U, std::get<3>(c_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100821 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_3x1_weights.npy", weights_layout),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000822 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
823 PadStrideInfo(1, 1, 0, 1))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100824 .set_name(param_path + "/Branch_2/Conv2d_0d_3x1/convolution")
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000825 << BatchNormalizationLayer(
826 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_3x1_BatchNorm_moving_mean.npy"),
827 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_3x1_BatchNorm_moving_variance.npy"),
828 get_random_accessor(1.f, 1.f),
829 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_3x1_BatchNorm_beta.npy"),
830 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100831 .set_name(param_path + "/Branch_2/Conv2d_0d_3x1/BatchNorm/batchnorm")
832 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_2/Conv2d_0d_3x1/Relu");
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000833
834 // Merge i_c1 and i_c2
Georgios Pinitas427bbbf2018-08-28 13:32:02 +0100835 i_c << ConcatLayer(std::move(i_c1), std::move(i_c2)).set_name(param_path + "/Branch_2/concat");
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000836
837 SubStream i_d(graph);
Georgios Pinitas130986a2018-05-14 19:25:37 +0100838 i_d << PoolingLayer(PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 1, 1, DimensionRoundingType::CEIL), true)).set_name(param_path + "/Branch_3/AvgPool_0a_3x3/AvgPool")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000839 << ConvolutionLayer(
840 1U, 1U, d_filt,
Georgios Pinitase2220552018-07-20 13:23:44 +0100841 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000842 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
843 PadStrideInfo(1, 1, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100844 .set_name(param_path + "/Branch_3/Conv2d_0b_1x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000845 << BatchNormalizationLayer(
846 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_moving_mean.npy"),
847 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_moving_variance.npy"),
848 get_random_accessor(1.f, 1.f),
849 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000850 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100851 .set_name(param_path + "/Branch_3/Conv2d_0b_1x1/BatchNorm/batchnorm")
852 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_3/Conv2d_0b_1x1/Relu");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000853
Georgios Pinitas427bbbf2018-08-28 13:32:02 +0100854 return ConcatLayer(std::move(i_a), std::move(i_b), std::move(i_c), std::move(i_d));
Georgios Pinitas652bde52018-01-10 15:33:28 +0000855 }
856};
857
858/** Main program for Inception V3
859 *
Georgios Pinitas9f28b392018-07-18 20:01:53 +0100860 * @note To list all the possible arguments execute the binary appended with the --help option
861 *
Georgios Pinitas652bde52018-01-10 15:33:28 +0000862 * @param[in] argc Number of arguments
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100863 * @param[in] argv Arguments
Georgios Pinitas652bde52018-01-10 15:33:28 +0000864 */
865int main(int argc, char **argv)
866{
867 return arm_compute::utils::run_example<InceptionV3Example>(argc, argv);
868}