blob: 35ab2247001bf25653a692b37f50fd5ebab25897 [file] [log] [blame]
Georgios Pinitas236bfe72017-11-23 15:59:55 +00001/*
Georgios Pinitas7f530b32018-01-22 11:20:44 +00002 * Copyright (c) 2017-2018 ARM Limited.
Georgios Pinitas236bfe72017-11-23 15:59:55 +00003 *
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 Pinitas236bfe72017-11-23 15:59:55 +000025#include "support/ToolchainSupport.h"
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010026#include "utils/CommonGraphOptions.h"
Georgios Pinitas236bfe72017-11-23 15:59:55 +000027#include "utils/GraphUtils.h"
28#include "utils/Utils.h"
29
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010030using namespace arm_compute;
Michalis Spyrou2b5f0f22018-01-10 14:08:50 +000031using namespace arm_compute::utils;
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010032using namespace arm_compute::graph::frontend;
Georgios Pinitas236bfe72017-11-23 15:59:55 +000033using namespace arm_compute::graph_utils;
34
Georgios Pinitas236bfe72017-11-23 15:59:55 +000035/** Example demonstrating how to implement MobileNet's network using the Compute Library's graph API
36 *
37 * @param[in] argc Number of arguments
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010038 * @param[in] argv Arguments
Georgios Pinitas236bfe72017-11-23 15:59:55 +000039 */
Gian Marco Iodice11a7e322018-07-05 15:42:02 +010040class GraphMobilenetExample : public Example
Georgios Pinitas236bfe72017-11-23 15:59:55 +000041{
Michalis Spyrou2b5f0f22018-01-10 14:08:50 +000042public:
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010043 GraphMobilenetExample()
44 : cmd_parser(), common_opts(cmd_parser), common_params(), graph(0, "MobileNetV1")
Michalis Spyrou2b5f0f22018-01-10 14:08:50 +000045 {
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010046 // Add model id option
47 model_id_opt = cmd_parser.add_option<SimpleOption<int>>("model-id", 0);
48 model_id_opt->set_help("Mobilenet model id (0: 1.0_224, else: 0.75_160");
49 }
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010050 GraphMobilenetExample(const GraphMobilenetExample &) = delete;
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010051 GraphMobilenetExample &operator=(const GraphMobilenetExample &) = delete;
Gian Marco Iodice11a7e322018-07-05 15:42:02 +010052 GraphMobilenetExample(GraphMobilenetExample &&) = default; // NOLINT
53 GraphMobilenetExample &operator=(GraphMobilenetExample &&) = default; // NOLINT
54 ~GraphMobilenetExample() override = default;
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010055 bool do_setup(int argc, char **argv) override
56 {
57 // Parse arguments
58 cmd_parser.parse(argc, argv);
59
60 // Consume common parameters
61 common_params = consume_common_graph_parameters(common_opts);
62
63 // Return when help menu is requested
64 if(common_params.help)
65 {
66 cmd_parser.print_help(argv[0]);
67 return false;
68 }
69
70 // Print parameter values
71 std::cout << common_params << std::endl;
72
73 // Get model parameters
74 int model_id = model_id_opt->value();
75
76 // Create input descriptor
77 unsigned int spatial_size = (model_id == 0 || common_params.data_type == DataType::QASYMM8) ? 224 : 160;
Georgios Pinitas7d66a8e2018-07-17 12:28:42 +010078
79 // Create input descriptor
80 const TensorShape tensor_shape = permute_shape(TensorShape(spatial_size, spatial_size, 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);
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010082
83 // Set graph hints
84 graph << common_params.target
Georgios Pinitase2220552018-07-20 13:23:44 +010085 << DepthwiseConvolutionMethod::Optimized3x3 // FIXME(COMPMID-1073): Add heuristics to automatically call the optimized 3x3 method
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010086 << common_params.fast_math_hint;
87
88 // Create core graph
89 if(arm_compute::is_data_type_float(common_params.data_type))
90 {
91 create_graph_float(input_descriptor, model_id);
92 }
93 else
94 {
95 create_graph_qasymm(input_descriptor);
96 }
97
98 // Create common tail
99 graph << ReshapeLayer(TensorShape(1001U)).set_name("Reshape")
100 << SoftmaxLayer().set_name("Softmax")
101 << OutputLayer(get_output_accessor(common_params, 5));
102
103 // Finalize graph
104 GraphConfig config;
105 config.num_threads = common_params.threads;
106 config.use_tuner = common_params.enable_tuner;
Anthony Barbier7b607dc2018-07-13 15:55:24 +0100107 config.tuner_file = common_params.tuner_file;
108
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100109 graph.finalize(common_params.target, config);
110
111 return true;
112 }
113 void do_run() override
114 {
115 // Run graph
116 graph.run();
117 }
118
119private:
120 CommandLineParser cmd_parser;
121 CommonGraphOptions common_opts;
122 SimpleOption<int> *model_id_opt{ nullptr };
123 CommonGraphParams common_params;
124 Stream graph;
125
126 void create_graph_float(TensorDescriptor &input_descriptor, int model_id)
127 {
128 float depth_scale = (model_id == 0) ? 1.f : 0.75;
129 std::string model_path = (model_id == 0) ? "/cnn_data/mobilenet_v1_1_224_model/" : "/cnn_data/mobilenet_v1_075_160_model/";
Georgios Pinitas236bfe72017-11-23 15:59:55 +0000130
Georgios Pinitas140fdc72018-02-16 11:42:38 +0000131 // Create a preprocessor object
132 std::unique_ptr<IPreprocessor> preprocessor = arm_compute::support::cpp14::make_unique<TFPreproccessor>();
Georgios Pinitas236bfe72017-11-23 15:59:55 +0000133
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100134 // Get trainable parameters data path
135 std::string data_path = common_params.data_path;
Georgios Pinitas7f530b32018-01-22 11:20:44 +0000136
137 // Add model path to data path
138 if(!data_path.empty())
139 {
140 data_path += model_path;
Michalis Spyrou2b5f0f22018-01-10 14:08:50 +0000141 }
142
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100143 graph << InputLayer(input_descriptor,
144 get_input_accessor(common_params, std::move(preprocessor), false))
Michalis Spyrou2b5f0f22018-01-10 14:08:50 +0000145 << ConvolutionLayer(
Georgios Pinitas7f530b32018-01-22 11:20:44 +0000146 3U, 3U, 32U * depth_scale,
Georgios Pinitascac13b12018-04-27 19:07:19 +0100147 get_weights_accessor(data_path, "Conv2d_0_weights.npy", DataLayout::NCHW),
Michalis Spyrou2b5f0f22018-01-10 14:08:50 +0000148 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
149 PadStrideInfo(2, 2, 0, 1, 0, 1, DimensionRoundingType::FLOOR))
Georgios Pinitas5c2fb3f2018-05-01 15:26:20 +0100150 .set_name("Conv2d_0")
Michalis Spyrou2b5f0f22018-01-10 14:08:50 +0000151 << BatchNormalizationLayer(
Georgios Pinitas7f530b32018-01-22 11:20:44 +0000152 get_weights_accessor(data_path, "Conv2d_0_BatchNorm_moving_mean.npy"),
153 get_weights_accessor(data_path, "Conv2d_0_BatchNorm_moving_variance.npy"),
154 get_weights_accessor(data_path, "Conv2d_0_BatchNorm_gamma.npy"),
155 get_weights_accessor(data_path, "Conv2d_0_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000156 0.001f)
Georgios Pinitas5c2fb3f2018-05-01 15:26:20 +0100157 .set_name("Conv2d_0/BatchNorm")
158 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 6.f)).set_name("Conv2d_0/Relu6");
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100159 graph << get_dwsc_node_float(data_path, "Conv2d_1", 64 * depth_scale, PadStrideInfo(1, 1, 1, 1), PadStrideInfo(1, 1, 0, 0));
160 graph << get_dwsc_node_float(data_path, "Conv2d_2", 128 * depth_scale, PadStrideInfo(2, 2, 0, 1, 0, 1, DimensionRoundingType::CEIL), PadStrideInfo(1, 1, 0, 0));
161 graph << get_dwsc_node_float(data_path, "Conv2d_3", 128 * depth_scale, PadStrideInfo(1, 1, 1, 1, 1, 1, DimensionRoundingType::CEIL), PadStrideInfo(1, 1, 0, 0));
162 graph << get_dwsc_node_float(data_path, "Conv2d_4", 256 * depth_scale, PadStrideInfo(2, 2, 0, 1, 0, 1, DimensionRoundingType::CEIL), PadStrideInfo(1, 1, 0, 0));
163 graph << get_dwsc_node_float(data_path, "Conv2d_5", 256 * depth_scale, PadStrideInfo(1, 1, 1, 1, 1, 1, DimensionRoundingType::CEIL), PadStrideInfo(1, 1, 0, 0));
164 graph << get_dwsc_node_float(data_path, "Conv2d_6", 512 * depth_scale, PadStrideInfo(2, 2, 0, 1, 0, 1, DimensionRoundingType::CEIL), PadStrideInfo(1, 1, 0, 0));
165 graph << get_dwsc_node_float(data_path, "Conv2d_7", 512 * depth_scale, PadStrideInfo(1, 1, 1, 1, 1, 1, DimensionRoundingType::CEIL), PadStrideInfo(1, 1, 0, 0));
166 graph << get_dwsc_node_float(data_path, "Conv2d_8", 512 * depth_scale, PadStrideInfo(1, 1, 1, 1, 1, 1, DimensionRoundingType::CEIL), PadStrideInfo(1, 1, 0, 0));
167 graph << get_dwsc_node_float(data_path, "Conv2d_9", 512 * depth_scale, PadStrideInfo(1, 1, 1, 1, 1, 1, DimensionRoundingType::CEIL), PadStrideInfo(1, 1, 0, 0));
168 graph << get_dwsc_node_float(data_path, "Conv2d_10", 512 * depth_scale, PadStrideInfo(1, 1, 1, 1, 1, 1, DimensionRoundingType::CEIL), PadStrideInfo(1, 1, 0, 0));
169 graph << get_dwsc_node_float(data_path, "Conv2d_11", 512 * depth_scale, PadStrideInfo(1, 1, 1, 1, 1, 1, DimensionRoundingType::CEIL), PadStrideInfo(1, 1, 0, 0));
170 graph << get_dwsc_node_float(data_path, "Conv2d_12", 1024 * depth_scale, PadStrideInfo(2, 2, 0, 1, 0, 1, DimensionRoundingType::CEIL), PadStrideInfo(1, 1, 0, 0));
171 graph << get_dwsc_node_float(data_path, "Conv2d_13", 1024 * depth_scale, PadStrideInfo(1, 1, 1, 1, 1, 1, DimensionRoundingType::CEIL), PadStrideInfo(1, 1, 0, 0));
Georgios Pinitas5c2fb3f2018-05-01 15:26:20 +0100172 graph << PoolingLayer(PoolingLayerInfo(PoolingType::AVG)).set_name("Logits/AvgPool_1a")
Michalis Spyrou2b5f0f22018-01-10 14:08:50 +0000173 << ConvolutionLayer(
174 1U, 1U, 1001U,
Georgios Pinitascac13b12018-04-27 19:07:19 +0100175 get_weights_accessor(data_path, "Logits_Conv2d_1c_1x1_weights.npy", DataLayout::NCHW),
Georgios Pinitas7f530b32018-01-22 11:20:44 +0000176 get_weights_accessor(data_path, "Logits_Conv2d_1c_1x1_biases.npy"),
Michalis Spyrou2b5f0f22018-01-10 14:08:50 +0000177 PadStrideInfo(1, 1, 0, 0))
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100178 .set_name("Logits/Conv2d_1c_1x1");
Georgios Pinitas236bfe72017-11-23 15:59:55 +0000179 }
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100180
181 void create_graph_qasymm(TensorDescriptor &input_descriptor)
Georgios Pinitas236bfe72017-11-23 15:59:55 +0000182 {
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100183 // Get trainable parameters data path
184 std::string data_path = common_params.data_path;
185
186 // Quantization info taken from the AndroidNN QASYMM8 MobileNet example
187 const QuantizationInfo in_quant_info = QuantizationInfo(0.0078125f, 128);
188 const QuantizationInfo mid_quant_info = QuantizationInfo(0.0784313753247f, 128);
189
190 const std::vector<QuantizationInfo> conv_weights_quant_info =
191 {
192 QuantizationInfo(0.031778190285f, 156), // conv0
193 QuantizationInfo(0.00604454148561f, 66) // conv14
194 };
195
196 const std::vector<QuantizationInfo> depth_weights_quant_info =
197 {
198 QuantizationInfo(0.254282623529f, 129), // dwsc1
199 QuantizationInfo(0.12828284502f, 172), // dwsc2
200 QuantizationInfo(0.265911251307f, 83), // dwsc3
201 QuantizationInfo(0.0985597148538f, 30), // dwsc4
202 QuantizationInfo(0.0631204470992f, 54), // dwsc5
203 QuantizationInfo(0.0137207424268f, 141), // dwsc6
204 QuantizationInfo(0.0817828401923f, 125), // dwsc7
205 QuantizationInfo(0.0393880493939f, 164), // dwsc8
206 QuantizationInfo(0.211694166064f, 129), // dwsc9
207 QuantizationInfo(0.158015936613f, 103), // dwsc10
208 QuantizationInfo(0.0182712618262f, 137), // dwsc11
209 QuantizationInfo(0.0127998134121f, 134), // dwsc12
210 QuantizationInfo(0.299285322428f, 161) // dwsc13
211 };
212
213 const std::vector<QuantizationInfo> point_weights_quant_info =
214 {
215 QuantizationInfo(0.0425766184926f, 129), // dwsc1
216 QuantizationInfo(0.0250773020089f, 94), // dwsc2
217 QuantizationInfo(0.015851572156f, 93), // dwsc3
218 QuantizationInfo(0.0167811904103f, 98), // dwsc4
219 QuantizationInfo(0.00951790809631f, 135), // dwsc5
220 QuantizationInfo(0.00999817531556f, 128), // dwsc6
221 QuantizationInfo(0.00590536883101f, 126), // dwsc7
222 QuantizationInfo(0.00576109671965f, 133), // dwsc8
223 QuantizationInfo(0.00830461271107f, 142), // dwsc9
224 QuantizationInfo(0.0152327232063f, 72), // dwsc10
225 QuantizationInfo(0.00741417845711f, 125), // dwsc11
226 QuantizationInfo(0.0135628981516f, 142), // dwsc12
227 QuantizationInfo(0.0338749065995f, 140) // dwsc13
228 };
229
230 graph << InputLayer(input_descriptor.set_quantization_info(in_quant_info),
231 get_weights_accessor(data_path, "/cnn_data/mobilenet_qasymm8_model/" + common_params.image))
232 << ConvolutionLayer(
233 3U, 3U, 32U,
234 get_weights_accessor(data_path, "/cnn_data/mobilenet_qasymm8_model/Conv2d_0_weights.npy"),
235 get_weights_accessor(data_path, "/cnn_data/mobilenet_qasymm8_model/Conv2d_0_bias.npy"),
236 PadStrideInfo(2U, 2U, 0U, 1U, 0U, 1U, DimensionRoundingType::FLOOR),
237 1, conv_weights_quant_info.at(0), mid_quant_info)
238 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 6.f));
239 graph << get_dwsc_node_qasymm(data_path, "Conv2d_1", 64U, PadStrideInfo(1U, 1U, 1U, 1U), PadStrideInfo(1U, 1U, 0U, 0U), depth_weights_quant_info.at(0), point_weights_quant_info.at(0));
240 graph << get_dwsc_node_qasymm(data_path, "Conv2d_2", 128U, PadStrideInfo(2U, 2U, 0U, 1U, 0U, 1U, DimensionRoundingType::FLOOR), PadStrideInfo(1U, 1U, 0U, 0U), depth_weights_quant_info.at(1),
241 point_weights_quant_info.at(1));
242 graph << get_dwsc_node_qasymm(data_path, "Conv2d_3", 128U, PadStrideInfo(1U, 1U, 1U, 1U, 1U, 1U, DimensionRoundingType::FLOOR), PadStrideInfo(1U, 1U, 0U, 0U), depth_weights_quant_info.at(2),
243 point_weights_quant_info.at(2));
244 graph << get_dwsc_node_qasymm(data_path, "Conv2d_4", 256U, PadStrideInfo(2U, 2U, 0U, 1U, 0U, 1U, DimensionRoundingType::FLOOR), PadStrideInfo(1U, 1U, 0U, 0U), depth_weights_quant_info.at(3),
245 point_weights_quant_info.at(3));
246 graph << get_dwsc_node_qasymm(data_path, "Conv2d_5", 256U, PadStrideInfo(1U, 1U, 1U, 1U, 1U, 1U, DimensionRoundingType::FLOOR), PadStrideInfo(1U, 1U, 0U, 0U), depth_weights_quant_info.at(4),
247 point_weights_quant_info.at(4));
248 graph << get_dwsc_node_qasymm(data_path, "Conv2d_6", 512U, PadStrideInfo(2U, 2U, 0U, 1U, 0U, 1U, DimensionRoundingType::FLOOR), PadStrideInfo(1U, 1U, 0U, 0U), depth_weights_quant_info.at(5),
249 point_weights_quant_info.at(5));
250 graph << get_dwsc_node_qasymm(data_path, "Conv2d_7", 512U, PadStrideInfo(1U, 1U, 1U, 1U, 1U, 1U, DimensionRoundingType::FLOOR), PadStrideInfo(1U, 1U, 0U, 0U), depth_weights_quant_info.at(6),
251 point_weights_quant_info.at(6));
252 graph << get_dwsc_node_qasymm(data_path, "Conv2d_8", 512U, PadStrideInfo(1U, 1U, 1U, 1U, 1U, 1U, DimensionRoundingType::FLOOR), PadStrideInfo(1U, 1U, 0U, 0U), depth_weights_quant_info.at(7),
253 point_weights_quant_info.at(7));
254 graph << get_dwsc_node_qasymm(data_path, "Conv2d_9", 512U, PadStrideInfo(1U, 1U, 1U, 1U, 1U, 1U, DimensionRoundingType::FLOOR), PadStrideInfo(1U, 1U, 0U, 0U), depth_weights_quant_info.at(8),
255 point_weights_quant_info.at(8));
256 graph << get_dwsc_node_qasymm(data_path, "Conv2d_10", 512U, PadStrideInfo(1U, 1U, 1U, 1U, 1U, 1U, DimensionRoundingType::FLOOR), PadStrideInfo(1U, 1U, 0U, 0U), depth_weights_quant_info.at(9),
257 point_weights_quant_info.at(9));
258 graph << get_dwsc_node_qasymm(data_path, "Conv2d_11", 512U, PadStrideInfo(1U, 1U, 1U, 1U, 1U, 1U, DimensionRoundingType::FLOOR), PadStrideInfo(1U, 1U, 0U, 0U), depth_weights_quant_info.at(10),
259 point_weights_quant_info.at(10));
260 graph << get_dwsc_node_qasymm(data_path, "Conv2d_12", 1024U, PadStrideInfo(2U, 2U, 0U, 1U, 0U, 1U, DimensionRoundingType::FLOOR), PadStrideInfo(1U, 1U, 0U, 0U), depth_weights_quant_info.at(11),
261 point_weights_quant_info.at(11));
262 graph << get_dwsc_node_qasymm(data_path, "Conv2d_13", 1024U, PadStrideInfo(1U, 1U, 1U, 1U, 1U, 1U, DimensionRoundingType::FLOOR), PadStrideInfo(1U, 1U, 0U, 0U), depth_weights_quant_info.at(12),
263 point_weights_quant_info.at(12))
264 << PoolingLayer(PoolingLayerInfo(PoolingType::AVG))
265 << ConvolutionLayer(
266 1U, 1U, 1001U,
267 get_weights_accessor(data_path, "/cnn_data/mobilenet_qasymm8_model/Logits_Conv2d_1c_1x1_weights.npy"),
268 get_weights_accessor(data_path, "/cnn_data/mobilenet_qasymm8_model/Logits_Conv2d_1c_1x1_bias.npy"),
269 PadStrideInfo(1U, 1U, 0U, 0U), 1, conv_weights_quant_info.at(1));
Georgios Pinitas236bfe72017-11-23 15:59:55 +0000270 }
271
Georgios Pinitas427bbbf2018-08-28 13:32:02 +0100272 ConcatLayer get_dwsc_node_float(const std::string &data_path, std::string &&param_path,
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100273 unsigned int conv_filt,
274 PadStrideInfo dwc_pad_stride_info, PadStrideInfo conv_pad_stride_info)
Michalis Spyrou2b5f0f22018-01-10 14:08:50 +0000275 {
Georgios Pinitas7f530b32018-01-22 11:20:44 +0000276 std::string total_path = param_path + "_";
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000277 SubStream sg(graph);
Michalis Spyrou2b5f0f22018-01-10 14:08:50 +0000278 sg << DepthwiseConvolutionLayer(
279 3U, 3U,
Georgios Pinitascac13b12018-04-27 19:07:19 +0100280 get_weights_accessor(data_path, total_path + "depthwise_depthwise_weights.npy", DataLayout::NCHW),
Michalis Spyrou2b5f0f22018-01-10 14:08:50 +0000281 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000282 dwc_pad_stride_info)
Georgios Pinitas5c2fb3f2018-05-01 15:26:20 +0100283 .set_name(total_path + "depthwise/depthwise")
Michalis Spyrou2b5f0f22018-01-10 14:08:50 +0000284 << BatchNormalizationLayer(
285 get_weights_accessor(data_path, total_path + "depthwise_BatchNorm_moving_mean.npy"),
286 get_weights_accessor(data_path, total_path + "depthwise_BatchNorm_moving_variance.npy"),
Michalis Spyrou2b5f0f22018-01-10 14:08:50 +0000287 get_weights_accessor(data_path, total_path + "depthwise_BatchNorm_gamma.npy"),
Georgios Pinitas7f530b32018-01-22 11:20:44 +0000288 get_weights_accessor(data_path, total_path + "depthwise_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000289 0.001f)
Georgios Pinitas5c2fb3f2018-05-01 15:26:20 +0100290 .set_name(total_path + "depthwise/BatchNorm")
291 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 6.f)).set_name(total_path + "depthwise/Relu6")
Michalis Spyrou2b5f0f22018-01-10 14:08:50 +0000292 << ConvolutionLayer(
293 1U, 1U, conv_filt,
Georgios Pinitascac13b12018-04-27 19:07:19 +0100294 get_weights_accessor(data_path, total_path + "pointwise_weights.npy", DataLayout::NCHW),
Michalis Spyrou2b5f0f22018-01-10 14:08:50 +0000295 std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
296 conv_pad_stride_info)
Georgios Pinitas5c2fb3f2018-05-01 15:26:20 +0100297 .set_name(total_path + "pointwise/Conv2D")
Michalis Spyrou2b5f0f22018-01-10 14:08:50 +0000298 << BatchNormalizationLayer(
299 get_weights_accessor(data_path, total_path + "pointwise_BatchNorm_moving_mean.npy"),
300 get_weights_accessor(data_path, total_path + "pointwise_BatchNorm_moving_variance.npy"),
Michalis Spyrou2b5f0f22018-01-10 14:08:50 +0000301 get_weights_accessor(data_path, total_path + "pointwise_BatchNorm_gamma.npy"),
Georgios Pinitas7f530b32018-01-22 11:20:44 +0000302 get_weights_accessor(data_path, total_path + "pointwise_BatchNorm_beta.npy"),
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000303 0.001f)
Georgios Pinitas5c2fb3f2018-05-01 15:26:20 +0100304 .set_name(total_path + "pointwise/BatchNorm")
305 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 6.f)).set_name(total_path + "pointwise/Relu6");
Gian Marcobfa3b522017-12-12 10:08:38 +0000306
Georgios Pinitas427bbbf2018-08-28 13:32:02 +0100307 return ConcatLayer(std::move(sg));
Michalis Spyrou2b5f0f22018-01-10 14:08:50 +0000308 }
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100309
Georgios Pinitas427bbbf2018-08-28 13:32:02 +0100310 ConcatLayer get_dwsc_node_qasymm(const std::string &data_path, std::string &&param_path,
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100311 const unsigned int conv_filt,
312 PadStrideInfo dwc_pad_stride_info, PadStrideInfo conv_pad_stride_info,
313 QuantizationInfo depth_weights_quant_info, QuantizationInfo point_weights_quant_info)
314 {
315 std::string total_path = "/cnn_data/mobilenet_qasymm8_model/" + param_path + "_";
316 SubStream sg(graph);
317
318 sg << DepthwiseConvolutionLayer(
319 3U, 3U,
320 get_weights_accessor(data_path, total_path + "depthwise_weights.npy"),
321 get_weights_accessor(data_path, total_path + "depthwise_bias.npy"),
322 dwc_pad_stride_info, depth_weights_quant_info)
323 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 6.f))
324 << ConvolutionLayer(
325 1U, 1U, conv_filt,
326 get_weights_accessor(data_path, total_path + "pointwise_weights.npy"),
327 get_weights_accessor(data_path, total_path + "pointwise_bias.npy"),
328 conv_pad_stride_info, 1, point_weights_quant_info)
329 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 6.f));
330
Georgios Pinitas427bbbf2018-08-28 13:32:02 +0100331 return ConcatLayer(std::move(sg));
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100332 }
Michalis Spyrou2b5f0f22018-01-10 14:08:50 +0000333};
Georgios Pinitas236bfe72017-11-23 15:59:55 +0000334
335/** Main program for MobileNetV1
336 *
Georgios Pinitas9f28b392018-07-18 20:01:53 +0100337 * @note To list all the possible arguments execute the binary appended with the --help option
338 *
Georgios Pinitas236bfe72017-11-23 15:59:55 +0000339 * @param[in] argc Number of arguments
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100340 * @param[in] argv Arguments
Georgios Pinitas236bfe72017-11-23 15:59:55 +0000341 */
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000342int main(int argc, char **argv)
Georgios Pinitas236bfe72017-11-23 15:59:55 +0000343{
Michalis Spyrou2b5f0f22018-01-10 14:08:50 +0000344 return arm_compute::utils::run_example<GraphMobilenetExample>(argc, argv);
Georgios Pinitas236bfe72017-11-23 15:59:55 +0000345}