blob: 3d35117891f0e5dc1d8c225d75731b3b7578a9aa [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
Georgios Pinitas6ed43b52018-07-12 17:34:22 +010068 ARM_COMPUTE_EXIT_ON_MSG(arm_compute::is_data_type_quantized_asymmetric(common_params.data_type), "Unsupported data type!");
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010069
70 // Print parameter values
71 std::cout << common_params << std::endl;
72
73 // Get trainable parameters data path
74 std::string data_path = common_params.data_path;
Georgios Pinitas652bde52018-01-10 15:33:28 +000075
Georgios Pinitas140fdc72018-02-16 11:42:38 +000076 // Create a preprocessor object
77 std::unique_ptr<IPreprocessor> preprocessor = arm_compute::support::cpp14::make_unique<TFPreproccessor>();
Georgios Pinitas652bde52018-01-10 15:33:28 +000078
Georgios Pinitase2220552018-07-20 13:23:44 +010079 // Create input descriptor
80 const TensorShape tensor_shape = permute_shape(TensorShape(299U, 299U, 3U, 1U), DataLayout::NCHW, common_params.data_layout);
81 TensorDescriptor input_descriptor = TensorDescriptor(tensor_shape, common_params.data_type).set_layout(common_params.data_layout);
82
83 // Set weights trained layout
84 const DataLayout weights_layout = DataLayout::NCHW;
85
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010086 graph << common_params.target
87 << common_params.fast_math_hint
Georgios Pinitase2220552018-07-20 13:23:44 +010088 << InputLayer(input_descriptor, get_input_accessor(common_params, std::move(preprocessor), false))
Georgios Pinitas652bde52018-01-10 15:33:28 +000089 << ConvolutionLayer(3U, 3U, 32U,
Georgios Pinitase2220552018-07-20 13:23:44 +010090 get_weights_accessor(data_path, "/cnn_data/inceptionv3_model/Conv2d_1a_3x3_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +000091 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(2, 2, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +010092 .set_name("Conv2d_1a_3x3/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +000093 << BatchNormalizationLayer(get_weights_accessor(data_path,
94 "/cnn_data/inceptionv3_model/Conv2d_1a_3x3_BatchNorm_moving_mean.npy"),
95 get_weights_accessor(data_path,
96 "/cnn_data/inceptionv3_model/Conv2d_1a_3x3_BatchNorm_moving_variance.npy"),
97 get_random_accessor(1.f, 1.f), get_weights_accessor(data_path,
98 "/cnn_data/inceptionv3_model/Conv2d_1a_3x3_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +000099 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100100 .set_name("Conv2d_1a_3x3/BatchNorm/batchnorm")
101 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("Conv2d_1a_3x3/Relu")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000102 << ConvolutionLayer(3U, 3U, 32U,
Georgios Pinitase2220552018-07-20 13:23:44 +0100103 get_weights_accessor(data_path, "/cnn_data/inceptionv3_model/Conv2d_2a_3x3_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000104 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100105 .set_name("Conv2d_2a_3x3/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000106 << BatchNormalizationLayer(get_weights_accessor(data_path,
107 "/cnn_data/inceptionv3_model/Conv2d_2a_3x3_BatchNorm_moving_mean.npy"),
108 get_weights_accessor(data_path,
109 "/cnn_data/inceptionv3_model/Conv2d_2a_3x3_BatchNorm_moving_variance.npy"),
110 get_random_accessor(1.f, 1.f), get_weights_accessor(data_path,
111 "/cnn_data/inceptionv3_model/Conv2d_2a_3x3_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000112 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100113 .set_name("Conv2d_2a_3x3/BatchNorm/batchnorm")
114 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("Conv2d_2a_3x3/Relu")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000115
116 << ConvolutionLayer(3U, 3U, 64U,
Georgios Pinitase2220552018-07-20 13:23:44 +0100117 get_weights_accessor(data_path, "/cnn_data/inceptionv3_model/Conv2d_2b_3x3_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000118 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 1, 1))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100119 .set_name("Conv2d_2b_3x3/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000120 << BatchNormalizationLayer(get_weights_accessor(data_path,
121 "/cnn_data/inceptionv3_model/Conv2d_2b_3x3_BatchNorm_moving_mean.npy"),
122 get_weights_accessor(data_path,
123 "/cnn_data/inceptionv3_model/Conv2d_2b_3x3_BatchNorm_moving_variance.npy"),
124 get_random_accessor(1.f, 1.f), get_weights_accessor(data_path,
125 "/cnn_data/inceptionv3_model/Conv2d_2b_3x3_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000126 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100127 .set_name("Conv2d_2b_3x3/BatchNorm/batchnorm")
128 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("Conv2d_2b_3x3/Relu")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000129
Georgios Pinitas130986a2018-05-14 19:25:37 +0100130 << 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 +0000131
132 << ConvolutionLayer(1U, 1U, 80U,
Georgios Pinitase2220552018-07-20 13:23:44 +0100133 get_weights_accessor(data_path, "/cnn_data/inceptionv3_model/Conv2d_3b_1x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000134 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100135 .set_name("Conv2d_3b_1x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000136 << BatchNormalizationLayer(get_weights_accessor(data_path,
137 "/cnn_data/inceptionv3_model/Conv2d_3b_1x1_BatchNorm_moving_mean.npy"),
138 get_weights_accessor(data_path,
139 "/cnn_data/inceptionv3_model/Conv2d_3b_1x1_BatchNorm_moving_variance.npy"),
140 get_random_accessor(1.f, 1.f), get_weights_accessor(data_path,
141 "/cnn_data/inceptionv3_model/Conv2d_3b_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000142 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100143 .set_name("Conv2d_3b_1x1/BatchNorm/batchnorm")
144 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("Conv2d_3b_1x1/Relu")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000145
146 << ConvolutionLayer(3U, 3U, 192U,
Georgios Pinitase2220552018-07-20 13:23:44 +0100147 get_weights_accessor(data_path, "/cnn_data/inceptionv3_model/Conv2d_4a_3x3_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000148 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100149 .set_name("Conv2d_4a_3x3/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000150 << BatchNormalizationLayer(get_weights_accessor(data_path,
151 "/cnn_data/inceptionv3_model/Conv2d_4a_3x3_BatchNorm_moving_mean.npy"),
152 get_weights_accessor(data_path,
153 "/cnn_data/inceptionv3_model/Conv2d_4a_3x3_BatchNorm_moving_variance.npy"),
154 get_random_accessor(1.f, 1.f), get_weights_accessor(data_path,
155 "/cnn_data/inceptionv3_model/Conv2d_4a_3x3_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000156 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100157 .set_name("Conv2d_4a_3x3/BatchNorm/batchnorm")
158 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("Conv2d_4a_3x3/Relu")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000159
Georgios Pinitas130986a2018-05-14 19:25:37 +0100160 << 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 +0000161
Georgios Pinitase2220552018-07-20 13:23:44 +0100162 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 +0100163 32U)
164 .set_name("Mixed_5b/concat");
Georgios Pinitase2220552018-07-20 13:23:44 +0100165 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 +0100166 64U, true)
167 .set_name("Mixed_5c/concat");
Georgios Pinitase2220552018-07-20 13:23:44 +0100168 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 +0100169 64U)
170 .set_name("Mixed_5d/concat");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000171
Georgios Pinitase2220552018-07-20 13:23:44 +0100172 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 +0000173
Georgios Pinitase2220552018-07-20 13:23:44 +0100174 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 +0100175 std::make_tuple(128U, 128U, 128U, 128U, 192U), 192U)
176 .set_name("Mixed_6b/concat");
Georgios Pinitase2220552018-07-20 13:23:44 +0100177 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 +0100178 std::make_tuple(160U, 160U, 160U, 160U, 192U), 192U)
179 .set_name("Mixed_6c/concat");
Georgios Pinitase2220552018-07-20 13:23:44 +0100180 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 +0100181 std::make_tuple(160U, 160U, 160U, 160U, 192U), 192U)
182 .set_name("Mixed_6d/concat");
Georgios Pinitase2220552018-07-20 13:23:44 +0100183 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 +0100184 std::make_tuple(192U, 192U, 192U, 192U, 192U), 192U)
185 .set_name("Mixed_6e/concat");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000186
Georgios Pinitase2220552018-07-20 13:23:44 +0100187 graph << get_inception_node_D(data_path, "Mixed_7a", weights_layout, std::make_tuple(192U, 320U),
Georgios Pinitas130986a2018-05-14 19:25:37 +0100188 std::make_tuple(192U, 192U, 192U, 192U))
189 .set_name("Mixed_7a/concat");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000190
Georgios Pinitase2220552018-07-20 13:23:44 +0100191 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 +0100192 std::make_tuple(448U, 384U, 384U, 384U), 192U)
193 .set_name("Mixed_7b/concat");
Georgios Pinitase2220552018-07-20 13:23:44 +0100194 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 +0100195 std::make_tuple(448U, 384U, 384U, 384U), 192U, true)
196 .set_name("Mixed_7c/concat");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000197
Georgios Pinitas130986a2018-05-14 19:25:37 +0100198 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 +0000199 << ConvolutionLayer(1U, 1U, 1001U, get_weights_accessor(data_path,
Georgios Pinitase2220552018-07-20 13:23:44 +0100200 "/cnn_data/inceptionv3_model/Logits_Conv2d_1c_1x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000201 get_weights_accessor(data_path,
202 "/cnn_data/inceptionv3_model/Logits_Conv2d_1c_1x1_biases.npy"),
203 PadStrideInfo(1, 1, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100204 .set_name("Logits/Conv2d_1c_1x1/convolution")
205 << ReshapeLayer(TensorShape(1001U)).set_name("Predictions/Reshape")
206 << SoftmaxLayer().set_name("Predictions/Softmax")
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100207 << OutputLayer(get_output_accessor(common_params, 5));
Gian Marcoc1b6e372018-02-21 18:03:26 +0000208
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000209 // Finalize graph
Georgios Pinitas9a8c6722018-03-21 17:52:35 +0000210 GraphConfig config;
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100211 config.num_threads = common_params.threads;
212 config.use_tuner = common_params.enable_tuner;
Anthony Barbier7b607dc2018-07-13 15:55:24 +0100213 config.tuner_file = common_params.tuner_file;
214
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100215 graph.finalize(common_params.target, config);
216
217 return true;
Georgios Pinitas652bde52018-01-10 15:33:28 +0000218 }
219
220 void do_run() override
221 {
222 graph.run();
223 }
224
225private:
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100226 CommandLineParser cmd_parser;
227 CommonGraphOptions common_opts;
228 CommonGraphParams common_params;
229 Stream graph;
Georgios Pinitas652bde52018-01-10 15:33:28 +0000230
231private:
Georgios Pinitase2220552018-07-20 13:23:44 +0100232 BranchLayer get_inception_node_A(const std::string &data_path, std::string &&param_path, DataLayout weights_layout,
Georgios Pinitas652bde52018-01-10 15:33:28 +0000233 unsigned int a_filt,
234 std::tuple<unsigned int, unsigned int> b_filters,
235 std::tuple<unsigned int, unsigned int, unsigned int> c_filters,
236 unsigned int d_filt,
237 bool is_name_different = false)
238 {
239 std::string total_path = "/cnn_data/inceptionv3_model/" + param_path + "_";
Georgios Pinitas652bde52018-01-10 15:33:28 +0000240
241 // This is due to a naming issue in the tf model
242 std::string conv_id0 = "_0a_";
243 std::string conv_id1 = "2d_0b_";
244 if(is_name_different)
245 {
246 conv_id0 = "_0b_";
247 conv_id1 = "_1_0c_";
248 }
249
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000250 SubStream i_a(graph);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000251 i_a << ConvolutionLayer(
252 1U, 1U, a_filt,
Georgios Pinitase2220552018-07-20 13:23:44 +0100253 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000254 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
255 PadStrideInfo(1, 1, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100256 .set_name(param_path + "/Branch_0/Conv2d_0a_1x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000257 << BatchNormalizationLayer(
258 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
259 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
260 get_random_accessor(1.f, 1.f),
261 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000262 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100263 .set_name(param_path + "/Branch_0/Conv2d_0a_1x1/BatchNorm/batchnorm")
264 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_0/Conv2d_0a_1x1/Relu");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000265
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000266 SubStream i_b(graph);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000267 i_b << ConvolutionLayer(
268 1U, 1U, std::get<0>(b_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100269 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d" + conv_id0 + "1x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000270 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
271 PadStrideInfo(1, 1, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100272 .set_name(param_path + "/Branch_1/Conv2d" + conv_id0 + "1x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000273 << BatchNormalizationLayer(
274 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d" + conv_id0 + "1x1_BatchNorm_moving_mean.npy"),
275 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d" + conv_id0 + "1x1_BatchNorm_moving_variance.npy"),
276 get_random_accessor(1.f, 1.f),
277 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d" + conv_id0 + "1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000278 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100279 .set_name(param_path + "/Branch_1/Conv2d" + conv_id0 + "1x1/BatchNorm/batchnorm")
280 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_1/Conv2d" + conv_id0 + "1x1/Relu")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000281 << ConvolutionLayer(
282 5U, 5U, std::get<1>(b_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100283 get_weights_accessor(data_path, total_path + "Branch_1_Conv" + conv_id1 + "5x5_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000284 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
285 PadStrideInfo(1, 1, 2, 2))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100286 .set_name(param_path + "/Branch_1/Conv2d" + conv_id1 + "5x5/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000287 << BatchNormalizationLayer(
288 get_weights_accessor(data_path, total_path + "Branch_1_Conv" + conv_id1 + "5x5_BatchNorm_moving_mean.npy"),
289 get_weights_accessor(data_path, total_path + "Branch_1_Conv" + conv_id1 + "5x5_BatchNorm_moving_variance.npy"),
290 get_random_accessor(1.f, 1.f),
291 get_weights_accessor(data_path, total_path + "Branch_1_Conv" + conv_id1 + "5x5_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000292 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100293 .set_name(param_path + "/Branch_1/Conv2d" + conv_id1 + "5x5/BatchNorm/batchnorm")
294 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_1/Conv2d" + conv_id1 + "5x5/Relu");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000295
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000296 SubStream i_c(graph);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000297 i_c << ConvolutionLayer(
298 1U, 1U, std::get<0>(c_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100299 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000300 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
301 PadStrideInfo(1, 1, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100302 .set_name(param_path + "/Branch_2/Conv2d_0a_1x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000303 << BatchNormalizationLayer(
304 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
305 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
306 get_random_accessor(1.f, 1.f),
307 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000308 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100309 .set_name(param_path + "/Branch_2/Conv2d_0a_1x1/BatchNorm/batchnorm")
310 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_2/Conv2d_0a_1x1/Relu")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000311 << ConvolutionLayer(
312 3U, 3U, std::get<1>(c_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100313 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000314 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
315 PadStrideInfo(1, 1, 1, 1))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100316 .set_name(param_path + "/Branch_2/Conv2d_0b_3x3/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000317 << BatchNormalizationLayer(
318 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_BatchNorm_moving_mean.npy"),
319 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_BatchNorm_moving_variance.npy"),
320 get_random_accessor(1.f, 1.f),
321 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000322 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100323 .set_name(param_path + "/Branch_2/Conv2d_0b_3x3/BatchNorm/batchnorm")
324 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_2/Conv2d_0b_3x3/Relu")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000325 << ConvolutionLayer(
326 3U, 3U, std::get<2>(c_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100327 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_3x3_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000328 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
329 PadStrideInfo(1, 1, 1, 1))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100330 .set_name(param_path + "/Branch_2/Conv2d_0c_3x3/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000331 << BatchNormalizationLayer(
332 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_3x3_BatchNorm_moving_mean.npy"),
333 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_3x3_BatchNorm_moving_variance.npy"),
334 get_random_accessor(1.f, 1.f),
335 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_3x3_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000336 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100337 .set_name(param_path + "/Branch_2/Conv2d_0c_3x3/BatchNorm/batcnorm")
338 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_2/Conv2d_0c_3x3/Relu");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000339
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000340 SubStream i_d(graph);
Georgios Pinitas130986a2018-05-14 19:25:37 +0100341 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 +0000342 << ConvolutionLayer(
343 1U, 1U, d_filt,
Georgios Pinitase2220552018-07-20 13:23:44 +0100344 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000345 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
346 PadStrideInfo(1, 1, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100347 .set_name(param_path + "/Branch_3/Conv2d_0b_1x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000348 << BatchNormalizationLayer(
349 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_moving_mean.npy"),
350 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_moving_variance.npy"),
351 get_random_accessor(1.f, 1.f),
352 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000353 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100354 .set_name(param_path + "/Branch_3/Conv2d_0b_1x1/BatchNorm/batchnorm")
355 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_3/Conv2d_0b_1x1/Relu");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000356
357 return BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_a), std::move(i_b), std::move(i_c), std::move(i_d));
358 }
359
Georgios Pinitase2220552018-07-20 13:23:44 +0100360 BranchLayer get_inception_node_B(const std::string &data_path, std::string &&param_path, DataLayout weights_layout,
Georgios Pinitas652bde52018-01-10 15:33:28 +0000361 unsigned int a_filt,
362 std::tuple<unsigned int, unsigned int, unsigned int> b_filters)
363 {
364 std::string total_path = "/cnn_data/inceptionv3_model/" + param_path + "_";
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000365 SubStream i_a(graph);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000366 i_a << ConvolutionLayer(
367 3U, 3U, a_filt,
Georgios Pinitase2220552018-07-20 13:23:44 +0100368 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_1x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000369 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
370 PadStrideInfo(2, 2, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100371 .set_name(param_path + "/Branch_0/Conv2d_1a_1x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000372 << BatchNormalizationLayer(
373 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_1x1_BatchNorm_moving_mean.npy"),
374 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_1x1_BatchNorm_moving_variance.npy"),
375 get_random_accessor(1.f, 1.f),
376 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000377 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100378 .set_name(param_path + "/Branch_0/Conv2d_1a_1x1/BatchNorm/batchnorm")
379 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_0/Conv2d_1a_1x1/Relu");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000380
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000381 SubStream i_b(graph);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000382 i_b << ConvolutionLayer(
383 1U, 1U, std::get<0>(b_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100384 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000385 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
386 PadStrideInfo(1, 1, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100387 .set_name(param_path + "/Branch_1/Conv2d_0a_1x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000388 << BatchNormalizationLayer(
389 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
390 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
391 get_random_accessor(1.f, 1.f),
392 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000393 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100394 .set_name(param_path + "/Branch_1/Conv2d_0a_1x1/BatchNorm/batchnorm")
395 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_1/Conv2d_0a_1x1/Relu")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000396 << ConvolutionLayer(
397 3U, 3U, std::get<1>(b_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100398 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_3x3_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000399 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
400 PadStrideInfo(1, 1, 1, 1))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100401 .set_name(param_path + "/Branch_1/Conv2d_0b_3x3/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000402 << BatchNormalizationLayer(
403 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_3x3_BatchNorm_moving_mean.npy"),
404 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_3x3_BatchNorm_moving_variance.npy"),
405 get_random_accessor(1.f, 1.f),
406 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_3x3_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000407 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100408 .set_name(param_path + "/Branch_1/Conv2d_0b_3x3/BatchNorm/batchnorm")
409 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_1/Conv2d_0b_3x3/Relu")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000410 << ConvolutionLayer(
411 3U, 3U, std::get<2>(b_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100412 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_1x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000413 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
414 PadStrideInfo(2, 2, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100415 .set_name(param_path + "/Branch_1/Conv2d_1a_1x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000416 << BatchNormalizationLayer(
417 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_1x1_BatchNorm_moving_mean.npy"),
418 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_1x1_BatchNorm_moving_variance.npy"),
419 get_random_accessor(1.f, 1.f),
420 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000421 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100422 .set_name(param_path + "/Branch_1/Conv2d_1a_1x1/BatchNorm/batchnorm")
423 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_1/Conv2d_1a_1x1/Relu");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000424
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000425 SubStream i_c(graph);
Georgios Pinitas130986a2018-05-14 19:25:37 +0100426 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 +0000427
428 return BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_a), std::move(i_b), std::move(i_c));
429 }
430
Georgios Pinitase2220552018-07-20 13:23:44 +0100431 BranchLayer get_inception_node_C(const std::string &data_path, std::string &&param_path, DataLayout weights_layout,
Georgios Pinitas652bde52018-01-10 15:33:28 +0000432 unsigned int a_filt,
433 std::tuple<unsigned int, unsigned int, unsigned int> b_filters,
434 std::tuple<unsigned int, unsigned int, unsigned int, unsigned int, unsigned int> c_filters,
435 unsigned int d_filt)
436 {
437 std::string total_path = "/cnn_data/inceptionv3_model/" + param_path + "_";
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000438 SubStream i_a(graph);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000439 i_a << ConvolutionLayer(
440 1U, 1U, a_filt,
Georgios Pinitase2220552018-07-20 13:23:44 +0100441 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000442 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
443 PadStrideInfo(1, 1, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100444 .set_name(param_path + "/Branch_0/Conv2d_0a_1x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000445 << BatchNormalizationLayer(
446 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
447 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
448 get_random_accessor(1.f, 1.f),
449 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000450 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100451 .set_name(param_path + "/Branch_0/Conv2d_0a_1x1/BatchNorm/batchnorm")
452 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_0/Conv2d_0a_1x1/Relu");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000453
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000454 SubStream i_b(graph);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000455 i_b << ConvolutionLayer(
456 1U, 1U, std::get<0>(b_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100457 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000458 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
459 PadStrideInfo(1, 1, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100460 .set_name(param_path + "/Branch_1/Conv2d_0a_1x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000461 << BatchNormalizationLayer(
462 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
463 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
464 get_random_accessor(1.f, 1.f),
465 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000466 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100467 .set_name(param_path + "/Branch_1/Conv2d_0a_1x1/BatchNorm/batchnorm")
468 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_1/Conv2d_0a_1x1/Relu")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000469 << ConvolutionLayer(
470 7U, 1U, std::get<1>(b_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100471 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000472 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
473 PadStrideInfo(1, 1, 3, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100474 .set_name(param_path + "/Branch_1/Conv2d_0b_1x7/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000475 << BatchNormalizationLayer(
476 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_moving_mean.npy"),
477 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_moving_variance.npy"),
478 get_random_accessor(1.f, 1.f),
479 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000480 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100481 .set_name(param_path + "/Branch_1/Conv2d_0b_1x7/BatchNorm/batchnorm")
482 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_1/Conv2d_0b_1x7/Relu")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000483 << ConvolutionLayer(
484 1U, 7U, std::get<2>(b_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100485 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000486 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
487 PadStrideInfo(1, 1, 0, 3))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100488 .set_name(param_path + "/Branch_1/Conv2d_0c_7x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000489 << BatchNormalizationLayer(
490 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_moving_mean.npy"),
491 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_moving_variance.npy"),
492 get_random_accessor(1.f, 1.f),
493 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000494 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100495 .set_name(param_path + "/Branch_1/Conv2d_0c_7x1/BatchNorm/batchnorm")
496 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_0/Conv2d_0c_7x1/Relu");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000497
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000498 SubStream i_c(graph);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000499 i_c << ConvolutionLayer(
500 1U, 1U, std::get<0>(c_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100501 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000502 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
503 PadStrideInfo(1, 1, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100504 .set_name(param_path + "/Branch_2/Conv2d_0a_1x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000505 << BatchNormalizationLayer(
506 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
507 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
508 get_random_accessor(1.f, 1.f),
509 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000510 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100511 .set_name(param_path + "/Branch_2/Conv2d_0a_1x1/BatchNorm/batchnorm")
512 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_2/Conv2d_0a_1x1/Relu")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000513 << ConvolutionLayer(
514 1U, 7U, std::get<1>(c_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100515 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_7x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000516 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
517 PadStrideInfo(1, 1, 0, 3))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100518 .set_name(param_path + "/Branch_2/Conv2d_0b_7x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000519 << BatchNormalizationLayer(
520 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_7x1_BatchNorm_moving_mean.npy"),
521 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_7x1_BatchNorm_moving_variance.npy"),
522 get_random_accessor(1.f, 1.f),
523 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_7x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000524 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100525 .set_name(param_path + "/Branch_2/Conv2d_0b_7x1/BatchNorm/batchnorm")
526 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_2/Conv2d_0b_7x1/Relu")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000527 << ConvolutionLayer(
528 7U, 1U, std::get<2>(c_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100529 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x7_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000530 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
531 PadStrideInfo(1, 1, 3, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100532 .set_name(param_path + "/Branch_2/Conv2d_0c_1x7/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000533 << BatchNormalizationLayer(
534 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x7_BatchNorm_moving_mean.npy"),
535 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x7_BatchNorm_moving_variance.npy"),
536 get_random_accessor(1.f, 1.f),
537 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x7_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000538 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100539 .set_name(param_path + "/Branch_2/Conv2d_0c_1x7/BatchNorm/batchnorm")
540 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_2/Conv2d_0c_1x7/Relu")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000541 << ConvolutionLayer(
542 1U, 7U, std::get<3>(c_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100543 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_7x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000544 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
545 PadStrideInfo(1, 1, 0, 3))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100546 .set_name(param_path + "/Branch_2/Conv2d_0d_7x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000547 << BatchNormalizationLayer(
548 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_7x1_BatchNorm_moving_mean.npy"),
549 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_7x1_BatchNorm_moving_variance.npy"),
550 get_random_accessor(1.f, 1.f),
551 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_7x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000552 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100553 .set_name(param_path + "/Branch_2/Conv2d_0d_7x1/BatchNorm/batchnorm")
554 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_2/Conv2d_0d_7x1/Relu")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000555 << ConvolutionLayer(
556 7U, 1U, std::get<4>(c_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100557 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0e_1x7_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000558 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
559 PadStrideInfo(1, 1, 3, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100560 .set_name(param_path + "/Branch_2/Conv2d_0e_1x7/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000561 << BatchNormalizationLayer(
562 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0e_1x7_BatchNorm_moving_mean.npy"),
563 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0e_1x7_BatchNorm_moving_variance.npy"),
564 get_random_accessor(1.f, 1.f),
565 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0e_1x7_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000566 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100567 .set_name(param_path + "/Branch_2/Conv2d_0e_1x7/BatchNorm/batchnorm")
568 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_2/Conv2d_0e_1x7/Relu");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000569
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000570 SubStream i_d(graph);
Georgios Pinitas130986a2018-05-14 19:25:37 +0100571 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 +0000572 << ConvolutionLayer(
573 1U, 1U, d_filt,
Georgios Pinitase2220552018-07-20 13:23:44 +0100574 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000575 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
576 PadStrideInfo(1, 1, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100577 .set_name(param_path + "/Branch_3/Conv2d_0b_1x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000578 << BatchNormalizationLayer(
579 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_moving_mean.npy"),
580 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_moving_variance.npy"),
581 get_random_accessor(1.f, 1.f),
582 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000583 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100584 .set_name(param_path + "/Branch_3/Conv2d_0b_1x1/BatchNorm/batchnorm")
585 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_3/Conv2d_0b_1x1/Relu");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000586
587 return BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_a), std::move(i_b), std::move(i_c), std::move(i_d));
588 }
589
Georgios Pinitase2220552018-07-20 13:23:44 +0100590 BranchLayer get_inception_node_D(const std::string &data_path, std::string &&param_path, DataLayout weights_layout,
591 std::tuple<unsigned int, unsigned int> a_filters,
Georgios Pinitas652bde52018-01-10 15:33:28 +0000592 std::tuple<unsigned int, unsigned int, unsigned int, unsigned int> b_filters)
593 {
594 std::string total_path = "/cnn_data/inceptionv3_model/" + param_path + "_";
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000595 SubStream i_a(graph);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000596 i_a << ConvolutionLayer(
597 1U, 1U, std::get<0>(a_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100598 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000599 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
600 PadStrideInfo(1, 1, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100601 .set_name(param_path + "/Branch_0/Conv2d_0a_1x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000602 << BatchNormalizationLayer(
603 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
604 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
605 get_random_accessor(1.f, 1.f),
606 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000607 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100608 .set_name(param_path + "/Branch_0/Conv2d_0a_1x1/BatchNorm/batchnorm")
609 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_0/Conv2d_0a_1x1/Relu")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000610 << ConvolutionLayer(
611 3U, 3U, std::get<1>(a_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100612 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000613 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
614 PadStrideInfo(2, 2, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100615 .set_name(param_path + "/Branch_0/Conv2d_1a_3x3/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000616 << BatchNormalizationLayer(
617 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_BatchNorm_moving_mean.npy"),
618 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_BatchNorm_moving_variance.npy"),
619 get_random_accessor(1.f, 1.f),
620 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000621 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100622 .set_name(param_path + "/Branch_0/Conv2d_1a_3x3/BatchNorm/batchnorm")
623 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_0/Conv2d_1a_3x3/Relu");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000624
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000625 SubStream i_b(graph);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000626 i_b << ConvolutionLayer(
627 1U, 1U, std::get<0>(b_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100628 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000629 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
630 PadStrideInfo(1, 1, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100631 .set_name(param_path + "/Branch_1/Conv2d_0a_1x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000632 << BatchNormalizationLayer(
633 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
634 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
635 get_random_accessor(1.f, 1.f),
636 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000637 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100638 .set_name(param_path + "/Branch_1/Conv2d_0a_1x1/BatchNorm/batchnorm")
639 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_1/Conv2d_0a_1x1/Relu")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000640 << ConvolutionLayer(
641 7U, 1U, std::get<1>(b_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100642 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000643 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
644 PadStrideInfo(1, 1, 3, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100645 .set_name(param_path + "/Branch_1/Conv2d_0b_1x7/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000646 << BatchNormalizationLayer(
647 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_moving_mean.npy"),
648 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_moving_variance.npy"),
649 get_random_accessor(1.f, 1.f),
650 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000651 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100652 .set_name(param_path + "/Branch_1/Conv2d_0b_1x7/BatchNorm/batchnorm")
653 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_1/Conv2d_0b_1x7/Relu")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000654 << ConvolutionLayer(
655 1U, 7U, std::get<2>(b_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100656 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000657 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
658 PadStrideInfo(1, 1, 0, 3))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100659 .set_name(param_path + "/Branch_1/Conv2d_0c_7x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000660 << BatchNormalizationLayer(
661 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_moving_mean.npy"),
662 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_moving_variance.npy"),
663 get_random_accessor(1.f, 1.f),
664 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000665 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100666 .set_name(param_path + "/Branch_1/Conv2d_0c_7x1/BatchNorm/batchnorm")
667 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_1/Conv2d_0c_7x1/Relu")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000668 << ConvolutionLayer(
669 3U, 3U, std::get<3>(b_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100670 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_3x3_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000671 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
672 PadStrideInfo(2, 2, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100673 .set_name(param_path + "/Branch_1/Conv2d_1a_3x3/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000674 << BatchNormalizationLayer(
675 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_3x3_BatchNorm_moving_mean.npy"),
676 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_3x3_BatchNorm_moving_variance.npy"),
677 get_random_accessor(1.f, 1.f),
678 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_3x3_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000679 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100680 .set_name(param_path + "/Branch_1/Conv2d_1a_3x3/BatchNorm/batchnorm")
681 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_1/Conv2d_1a_3x3/Relu");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000682
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000683 SubStream i_c(graph);
Georgios Pinitas130986a2018-05-14 19:25:37 +0100684 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 +0000685
686 return BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_a), std::move(i_b), std::move(i_c));
687 }
688
Georgios Pinitase2220552018-07-20 13:23:44 +0100689 BranchLayer get_inception_node_E(const std::string &data_path, std::string &&param_path, DataLayout weights_layout,
Georgios Pinitas652bde52018-01-10 15:33:28 +0000690 unsigned int a_filt,
691 std::tuple<unsigned int, unsigned int, unsigned int> b_filters,
692 std::tuple<unsigned int, unsigned int, unsigned int, unsigned int> c_filters,
693 unsigned int d_filt,
694 bool is_name_different = false)
695 {
696 // This is due to a naming issue in the tf model
697 std::string conv_id = "_0b_";
698 if(is_name_different)
699 {
700 conv_id = "_0c_";
701 }
702
703 std::string total_path = "/cnn_data/inceptionv3_model/" + param_path + "_";
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000704 SubStream i_a(graph);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000705 i_a << ConvolutionLayer(
706 1U, 1U, a_filt,
Georgios Pinitase2220552018-07-20 13:23:44 +0100707 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000708 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
709 PadStrideInfo(1, 1, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100710 .set_name(param_path + "/Branch_0/Conv2d_0a_1x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000711 << BatchNormalizationLayer(
712 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
713 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
714 get_random_accessor(1.f, 1.f),
715 get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000716 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100717 .set_name(param_path + "/Branch_0/Conv2d_0a_1x1/BatchNorm/batchnorm")
718 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_0/Conv2d_0a_1x1/Relu");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000719
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000720 SubStream i_b(graph);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000721 i_b << ConvolutionLayer(
722 1U, 1U, std::get<0>(b_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100723 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000724 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
725 PadStrideInfo(1, 1, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100726 .set_name(param_path + "/Branch_1/Conv2d_0a_1x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000727 << BatchNormalizationLayer(
728 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
729 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
730 get_random_accessor(1.f, 1.f),
731 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000732 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100733 .set_name(param_path + "/Branch_1/Conv2d_0a_1x1/BatchNorm/batchnorm")
734 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_1/Conv2d_0a_1x1/Relu");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000735
Georgios Pinitas772e17f2018-07-13 12:25:33 +0100736 SubStream i_b1(i_b);
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000737 i_b1 << ConvolutionLayer(
738 3U, 1U, std::get<1>(b_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100739 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x3_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000740 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
741 PadStrideInfo(1, 1, 1, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100742 .set_name(param_path + "/Branch_1/Conv2d_0b_1x3/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000743 << BatchNormalizationLayer(
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000744 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x3_BatchNorm_moving_mean.npy"),
745 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x3_BatchNorm_moving_variance.npy"),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000746 get_random_accessor(1.f, 1.f),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000747 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x3_BatchNorm_beta.npy"),
748 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100749 .set_name(param_path + "/Branch_1/Conv2d_0b_1x3/BatchNorm/batchnorm")
750 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_1/Conv2d_0b_1x3/Relu");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000751
Georgios Pinitas772e17f2018-07-13 12:25:33 +0100752 SubStream i_b2(i_b);
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000753 i_b2 << ConvolutionLayer(
754 1U, 3U, std::get<2>(b_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100755 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d" + conv_id + "3x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000756 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
757 PadStrideInfo(1, 1, 0, 1))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100758 .set_name(param_path + "/Branch_1/Conv2d" + conv_id + "3x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000759 << BatchNormalizationLayer(
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000760 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d" + conv_id + "3x1_BatchNorm_moving_mean.npy"),
761 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d" + conv_id + "3x1_BatchNorm_moving_variance.npy"),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000762 get_random_accessor(1.f, 1.f),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000763 get_weights_accessor(data_path, total_path + "Branch_1_Conv2d" + conv_id + "3x1_BatchNorm_beta.npy"),
764 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100765 .set_name(param_path + "/Branch_1/Conv2d" + conv_id + "3x1/BatchNorm/batchnorm")
766 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_1/Conv2d" + conv_id + "3x1/Relu");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000767
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000768 // Merge b1 and b2
Georgios Pinitas130986a2018-05-14 19:25:37 +0100769 i_b << BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_b1), std::move(i_b2)).set_name(param_path + "/Branch_1/concat");
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000770
771 SubStream i_c(graph);
Georgios Pinitas652bde52018-01-10 15:33:28 +0000772 i_c << ConvolutionLayer(
773 1U, 1U, std::get<0>(c_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100774 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000775 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
776 PadStrideInfo(1, 1, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100777 .set_name(param_path + "/Branch_2/Conv2d_0a_1x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000778 << BatchNormalizationLayer(
779 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"),
780 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"),
781 get_random_accessor(1.f, 1.f),
782 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000783 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100784 .set_name(param_path + "/Branch_2/Conv2d_0a_1x1/BatchNorm/batchnorm")
785 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_2/Conv2d_0a_1x1/Relu")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000786 << ConvolutionLayer(
787 3U, 3U, std::get<1>(c_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100788 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000789 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
790 PadStrideInfo(1, 1, 1, 1))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100791 .set_name(param_path + "/Branch_2/Conv2d_0b_3x3/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000792 << BatchNormalizationLayer(
793 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_BatchNorm_moving_mean.npy"),
794 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_BatchNorm_moving_variance.npy"),
795 get_random_accessor(1.f, 1.f),
796 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000797 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100798 .set_name(param_path + "/Branch_2/Conv2d_0b_3x3/BatchNorm/batchnorm")
799 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_2/Conv2d_0b_3x3/Relu");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000800
Georgios Pinitas772e17f2018-07-13 12:25:33 +0100801 SubStream i_c1(i_c);
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000802 i_c1 << ConvolutionLayer(
803 3U, 1U, std::get<2>(c_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100804 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x3_weights.npy", weights_layout),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000805 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
806 PadStrideInfo(1, 1, 1, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100807 .set_name(param_path + "/Branch_2/Conv2d_0c_1x3/convolution")
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000808 << BatchNormalizationLayer(
809 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x3_BatchNorm_moving_mean.npy"),
810 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x3_BatchNorm_moving_variance.npy"),
811 get_random_accessor(1.f, 1.f),
812 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x3_BatchNorm_beta.npy"),
813 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100814 .set_name(param_path + "/Branch_2/Conv2d_0c_1x3/BatchNorm/batchnorm")
815 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_2/Conv2d_0c_1x3/Relu");
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000816
Georgios Pinitas772e17f2018-07-13 12:25:33 +0100817 SubStream i_c2(i_c);
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000818 i_c2 << ConvolutionLayer(
819 1U, 3U, std::get<3>(c_filters),
Georgios Pinitase2220552018-07-20 13:23:44 +0100820 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_3x1_weights.npy", weights_layout),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000821 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
822 PadStrideInfo(1, 1, 0, 1))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100823 .set_name(param_path + "/Branch_2/Conv2d_0d_3x1/convolution")
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000824 << BatchNormalizationLayer(
825 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_3x1_BatchNorm_moving_mean.npy"),
826 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_3x1_BatchNorm_moving_variance.npy"),
827 get_random_accessor(1.f, 1.f),
828 get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_3x1_BatchNorm_beta.npy"),
829 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100830 .set_name(param_path + "/Branch_2/Conv2d_0d_3x1/BatchNorm/batchnorm")
831 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_2/Conv2d_0d_3x1/Relu");
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000832
833 // Merge i_c1 and i_c2
Georgios Pinitas130986a2018-05-14 19:25:37 +0100834 i_c << BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_c1), std::move(i_c2)).set_name(param_path + "/Branch_2/concat");
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000835
836 SubStream i_d(graph);
Georgios Pinitas130986a2018-05-14 19:25:37 +0100837 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 +0000838 << ConvolutionLayer(
839 1U, 1U, d_filt,
Georgios Pinitase2220552018-07-20 13:23:44 +0100840 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_weights.npy", weights_layout),
Georgios Pinitas652bde52018-01-10 15:33:28 +0000841 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
842 PadStrideInfo(1, 1, 0, 0))
Georgios Pinitas130986a2018-05-14 19:25:37 +0100843 .set_name(param_path + "/Branch_3/Conv2d_0b_1x1/convolution")
Georgios Pinitas652bde52018-01-10 15:33:28 +0000844 << BatchNormalizationLayer(
845 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_moving_mean.npy"),
846 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_moving_variance.npy"),
847 get_random_accessor(1.f, 1.f),
848 get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000849 0.001f)
Georgios Pinitas130986a2018-05-14 19:25:37 +0100850 .set_name(param_path + "/Branch_3/Conv2d_0b_1x1/BatchNorm/batchnorm")
851 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name(param_path + "/Branch_3/Conv2d_0b_1x1/Relu");
Georgios Pinitas652bde52018-01-10 15:33:28 +0000852
853 return BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_a), std::move(i_b), std::move(i_c), std::move(i_d));
854 }
855};
856
857/** Main program for Inception V3
858 *
Georgios Pinitas9f28b392018-07-18 20:01:53 +0100859 * @note To list all the possible arguments execute the binary appended with the --help option
860 *
Georgios Pinitas652bde52018-01-10 15:33:28 +0000861 * @param[in] argc Number of arguments
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100862 * @param[in] argv Arguments
Georgios Pinitas652bde52018-01-10 15:33:28 +0000863 */
864int main(int argc, char **argv)
865{
866 return arm_compute::utils::run_example<InceptionV3Example>(argc, argv);
867}