29 #include "utils/Utils.h"
37 class GraphMobilenetV2Example :
public Example
40 GraphMobilenetV2Example() : cmd_parser(), common_opts(cmd_parser), common_params(), graph(0,
"MobileNetV2")
43 GraphMobilenetV2Example(
const GraphMobilenetV2Example &) =
delete;
44 GraphMobilenetV2Example &operator=(
const GraphMobilenetV2Example &) =
delete;
45 ~GraphMobilenetV2Example()
override =
default;
47 bool do_setup(
int argc,
char **argv)
override
50 cmd_parser.parse(argc, argv);
51 cmd_parser.validate();
57 if (common_params.help)
59 cmd_parser.print_help(argv[0]);
64 std::cout << common_params << std::endl;
73 graph << common_params.
target << common_params.fast_math_hint;
78 create_graph_float(input_descriptor);
82 create_graph_qasymm8(input_descriptor);
91 config.
use_tuner = common_params.enable_tuner;
94 config.
mlgo_file = common_params.mlgo_file;
96 graph.finalize(common_params.target, config);
101 void do_run()
override
114 enum class IsResidual
130 const std::string model_path =
"/cnn_data/mobilenet_v2_1.0_224_model/";
133 std::unique_ptr<IPreprocessor> preprocessor = std::make_unique<TFPreproccessor>();
136 std::string data_path = common_params.
data_path;
139 if (!data_path.empty())
141 data_path += model_path;
146 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr),
153 0.0010000000474974513f)
158 get_expanded_conv_float(data_path,
"expanded_conv", 32U, 16U,
PadStrideInfo(1, 1, 1, 1));
159 get_expanded_conv_float(data_path,
"expanded_conv_1", 16U, 24U,
161 get_expanded_conv_float(data_path,
"expanded_conv_2", 24U, 24U,
PadStrideInfo(1, 1, 1, 1), HasExpand::Yes,
163 get_expanded_conv_float(data_path,
"expanded_conv_3", 24U, 32U,
165 get_expanded_conv_float(data_path,
"expanded_conv_4", 32U, 32U,
PadStrideInfo(1, 1, 1, 1), HasExpand::Yes,
167 get_expanded_conv_float(data_path,
"expanded_conv_5", 32U, 32U,
PadStrideInfo(1, 1, 1, 1), HasExpand::Yes,
169 get_expanded_conv_float(data_path,
"expanded_conv_6", 32U, 64U,
171 get_expanded_conv_float(data_path,
"expanded_conv_7", 64U, 64U,
PadStrideInfo(1, 1, 1, 1), HasExpand::Yes,
173 get_expanded_conv_float(data_path,
"expanded_conv_8", 64U, 64U,
PadStrideInfo(1, 1, 1, 1), HasExpand::Yes,
175 get_expanded_conv_float(data_path,
"expanded_conv_9", 64U, 64U,
PadStrideInfo(1, 1, 1, 1), HasExpand::Yes,
177 get_expanded_conv_float(data_path,
"expanded_conv_10", 64U, 96U,
PadStrideInfo(1, 1, 1, 1), HasExpand::Yes);
178 get_expanded_conv_float(data_path,
"expanded_conv_11", 96U, 96U,
PadStrideInfo(1, 1, 1, 1), HasExpand::Yes,
180 get_expanded_conv_float(data_path,
"expanded_conv_12", 96U, 96U,
PadStrideInfo(1, 1, 1, 1), HasExpand::Yes,
182 get_expanded_conv_float(data_path,
"expanded_conv_13", 96U, 160U,
184 get_expanded_conv_float(data_path,
"expanded_conv_14", 160U, 160U,
PadStrideInfo(1, 1, 1, 1), HasExpand::Yes,
186 get_expanded_conv_float(data_path,
"expanded_conv_15", 160U, 160U,
PadStrideInfo(1, 1, 1, 1), HasExpand::Yes,
188 get_expanded_conv_float(data_path,
"expanded_conv_16", 160U, 320U,
PadStrideInfo(1, 1, 1, 1), HasExpand::Yes);
192 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr),
PadStrideInfo(1, 1, 0, 0))
198 0.0010000000474974513f)
210 void get_expanded_conv_float(
const std::string &data_path,
211 std::string &¶m_path,
212 unsigned int input_channels,
213 unsigned int output_channels,
215 HasExpand has_expand = HasExpand::No,
216 IsResidual is_residual = IsResidual::No,
217 unsigned int expansion_size = 6)
219 std::string total_path = param_path +
"_";
223 if (has_expand == HasExpand::Yes)
226 1U, 1U, input_channels * expansion_size,
228 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr),
PadStrideInfo(1, 1, 0, 0))
229 .
set_name(param_path +
"/expand/Conv2D")
235 0.0010000000474974513f)
236 .
set_name(param_path +
"/expand/BatchNorm")
238 .
set_name(param_path +
"/expand/Relu6");
245 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr), dwc_pad_stride_info)
246 .
set_name(param_path +
"/depthwise/depthwise")
252 0.0010000000474974513f)
253 .
set_name(param_path +
"/depthwise/BatchNorm")
255 .
set_name(param_path +
"/depthwise/Relu6");
260 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr),
262 .
set_name(param_path +
"/project/Conv2D")
267 get_weights_accessor(data_path, total_path +
"project_BatchNorm_beta.npy"), 0.0010000000474974513)
268 .
set_name(param_path +
"/project/BatchNorm");
270 if (is_residual == IsResidual::Yes)
275 <<
EltwiseLayer(std::move(left), std::move(right), EltwiseOperation::Add).
set_name(param_path +
"/add");
286 const std::string model_path =
"/cnn_data/mobilenet_v2_1.0_224_quantized_model/";
289 std::string data_path = common_params.
data_path;
292 if (!data_path.empty())
294 data_path += model_path;
300 const std::vector<QuantizationInfo> conv_weights_quant_info = {
307 const std::vector<QuantizationInfo> pwc_q = {
327 const std::vector<QuantizationInfo> dwc_q = {
347 const std::vector<QuantizationInfo> prwc_q = {
372 conv_weights_quant_info.at(0), mid_quant_info)
380 .
set_name(
"expanded_conv/depthwise/depthwise")
382 .
set_name(
"expanded_conv/depthwise/Relu6")
386 .
set_name(
"expanded_conv/project/Conv2D");
388 get_expanded_conv_qasymm8(data_path,
"expanded_conv_1", IsResidual::No, 96U, 24U,
390 dwc_q.at(1), prwc_q.at(1));
391 get_expanded_conv_qasymm8(data_path,
"expanded_conv_2", IsResidual::Yes, 144U, 24U,
PadStrideInfo(1, 1, 1, 1),
392 pwc_q.at(2), dwc_q.at(2), prwc_q.at(2));
393 get_expanded_conv_qasymm8(data_path,
"expanded_conv_3", IsResidual::No, 144U, 32U,
395 dwc_q.at(3), prwc_q.at(3));
396 get_expanded_conv_qasymm8(data_path,
"expanded_conv_4", IsResidual::Yes, 192U, 32U,
PadStrideInfo(1, 1, 1, 1),
397 pwc_q.at(4), dwc_q.at(4), prwc_q.at(4));
398 get_expanded_conv_qasymm8(data_path,
"expanded_conv_5", IsResidual::Yes, 192U, 32U,
PadStrideInfo(1, 1, 1, 1),
399 pwc_q.at(5), dwc_q.at(5), prwc_q.at(5));
400 get_expanded_conv_qasymm8(data_path,
"expanded_conv_6", IsResidual::No, 192U, 64U,
402 dwc_q.at(6), prwc_q.at(6));
403 get_expanded_conv_qasymm8(data_path,
"expanded_conv_7", IsResidual::Yes, 384U, 64U,
PadStrideInfo(1, 1, 1, 1),
404 pwc_q.at(7), dwc_q.at(7), prwc_q.at(7));
405 get_expanded_conv_qasymm8(data_path,
"expanded_conv_8", IsResidual::Yes, 384U, 64U,
PadStrideInfo(1, 1, 1, 1),
406 pwc_q.at(8), dwc_q.at(8), prwc_q.at(8));
407 get_expanded_conv_qasymm8(data_path,
"expanded_conv_9", IsResidual::Yes, 384U, 64U,
PadStrideInfo(1, 1, 1, 1),
408 pwc_q.at(9), dwc_q.at(9), prwc_q.at(9));
409 get_expanded_conv_qasymm8(data_path,
"expanded_conv_10", IsResidual::No, 384U, 96U,
PadStrideInfo(1, 1, 1, 1),
410 pwc_q.at(10), dwc_q.at(10), prwc_q.at(10));
411 get_expanded_conv_qasymm8(data_path,
"expanded_conv_11", IsResidual::Yes, 576U, 96U,
PadStrideInfo(1, 1, 1, 1),
412 pwc_q.at(11), dwc_q.at(11), prwc_q.at(11));
413 get_expanded_conv_qasymm8(data_path,
"expanded_conv_12", IsResidual::Yes, 576U, 96U,
PadStrideInfo(1, 1, 1, 1),
414 pwc_q.at(12), dwc_q.at(12), prwc_q.at(12));
415 get_expanded_conv_qasymm8(data_path,
"expanded_conv_13", IsResidual::No, 576U, 160U,
417 dwc_q.at(13), prwc_q.at(13));
418 get_expanded_conv_qasymm8(data_path,
"expanded_conv_14", IsResidual::Yes, 960U, 160U,
PadStrideInfo(1, 1, 1, 1),
419 pwc_q.at(14), dwc_q.at(14), prwc_q.at(14));
420 get_expanded_conv_qasymm8(data_path,
"expanded_conv_15", IsResidual::Yes, 960U, 160U,
PadStrideInfo(1, 1, 1, 1),
421 pwc_q.at(15), dwc_q.at(15), prwc_q.at(15));
422 get_expanded_conv_qasymm8(data_path,
"expanded_conv_16", IsResidual::No, 960U, 320U,
PadStrideInfo(1, 1, 1, 1),
423 pwc_q.at(16), dwc_q.at(16), prwc_q.at(16));
427 conv_weights_quant_info.at(1))
438 void get_expanded_conv_qasymm8(
const std::string &data_path,
439 std::string &¶m_path,
440 IsResidual is_residual,
441 unsigned int input_channels,
442 unsigned int output_channels,
448 std::string total_path = param_path +
"_";
457 .
set_name(param_path +
"/Conv2D/Relu6")
460 get_weights_accessor(data_path, total_path +
"depthwise_depthwise_biases.npy"), dwc_pad_stride_info,
462 .
set_name(param_path +
"/depthwise/depthwise")
464 .
set_name(param_path +
"/depthwise/Relu6")
469 .
set_name(param_path +
"/project/Conv2D");
471 if (is_residual == IsResidual::Yes)
476 <<
EltwiseLayer(std::move(left), std::move(right), EltwiseOperation::Add).
set_name(param_path +
"/add");
499 int main(
int argc,
char **argv)
501 return arm_compute::utils::run_example<GraphMobilenetV2Example>(argc, argv);