36 class GraphMobilenetV2Example :
public Example 39 GraphMobilenetV2Example()
40 : 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;
71 graph << common_params.
target 72 << common_params.fast_math_hint;
77 create_graph_float(input_descriptor);
81 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;
147 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr),
154 0.0010000000474974513f)
159 get_expanded_conv_float(data_path,
"expanded_conv", 32U, 16U,
PadStrideInfo(1, 1, 1, 1));
160 get_expanded_conv_float(data_path,
"expanded_conv_1", 16U, 24U,
PadStrideInfo(2, 2, 0, 1, 0, 1,
DimensionRoundingType::CEIL), HasExpand::Yes);
161 get_expanded_conv_float(data_path,
"expanded_conv_2", 24U, 24U,
PadStrideInfo(1, 1, 1, 1), HasExpand::Yes, IsResidual::Yes);
162 get_expanded_conv_float(data_path,
"expanded_conv_3", 24U, 32U,
PadStrideInfo(2, 2, 0, 1, 0, 1,
DimensionRoundingType::CEIL), HasExpand::Yes);
163 get_expanded_conv_float(data_path,
"expanded_conv_4", 32U, 32U,
PadStrideInfo(1, 1, 1, 1), HasExpand::Yes, IsResidual::Yes);
164 get_expanded_conv_float(data_path,
"expanded_conv_5", 32U, 32U,
PadStrideInfo(1, 1, 1, 1), HasExpand::Yes, IsResidual::Yes);
165 get_expanded_conv_float(data_path,
"expanded_conv_6", 32U, 64U,
PadStrideInfo(2, 2, 0, 1, 0, 1,
DimensionRoundingType::CEIL), HasExpand::Yes);
166 get_expanded_conv_float(data_path,
"expanded_conv_7", 64U, 64U,
PadStrideInfo(1, 1, 1, 1), HasExpand::Yes, IsResidual::Yes);
167 get_expanded_conv_float(data_path,
"expanded_conv_8", 64U, 64U,
PadStrideInfo(1, 1, 1, 1), HasExpand::Yes, IsResidual::Yes);
168 get_expanded_conv_float(data_path,
"expanded_conv_9", 64U, 64U,
PadStrideInfo(1, 1, 1, 1), HasExpand::Yes, IsResidual::Yes);
169 get_expanded_conv_float(data_path,
"expanded_conv_10", 64U, 96U,
PadStrideInfo(1, 1, 1, 1), HasExpand::Yes);
170 get_expanded_conv_float(data_path,
"expanded_conv_11", 96U, 96U,
PadStrideInfo(1, 1, 1, 1), HasExpand::Yes, IsResidual::Yes);
171 get_expanded_conv_float(data_path,
"expanded_conv_12", 96U, 96U,
PadStrideInfo(1, 1, 1, 1), HasExpand::Yes, IsResidual::Yes);
172 get_expanded_conv_float(data_path,
"expanded_conv_13", 96U, 160U,
PadStrideInfo(2, 2, 0, 1, 0, 1,
DimensionRoundingType::CEIL), HasExpand::Yes);
173 get_expanded_conv_float(data_path,
"expanded_conv_14", 160U, 160U,
PadStrideInfo(1, 1, 1, 1), HasExpand::Yes, IsResidual::Yes);
174 get_expanded_conv_float(data_path,
"expanded_conv_15", 160U, 160U,
PadStrideInfo(1, 1, 1, 1), HasExpand::Yes, IsResidual::Yes);
175 get_expanded_conv_float(data_path,
"expanded_conv_16", 160U, 320U,
PadStrideInfo(1, 1, 1, 1), HasExpand::Yes);
179 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr),
186 0.0010000000474974513f)
198 void get_expanded_conv_float(
const std::string &data_path, std::string &¶m_path,
199 unsigned int input_channels,
unsigned int output_channels,
201 HasExpand has_expand = HasExpand::No, IsResidual is_residual = IsResidual::No,
202 unsigned int expansion_size = 6)
204 std::string total_path = param_path +
"_";
208 if(has_expand == HasExpand::Yes)
212 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr),
PadStrideInfo(1, 1, 0, 0))
213 .
set_name(param_path +
"/expand/Conv2D")
218 0.0010000000474974513f)
219 .
set_name(param_path +
"/expand/BatchNorm")
221 .
set_name(param_path +
"/expand/Relu6");
227 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr),
229 .
set_name(param_path +
"/depthwise/depthwise")
234 0.0010000000474974513f)
235 .
set_name(param_path +
"/depthwise/BatchNorm")
237 .
set_name(param_path +
"/depthwise/Relu6");
242 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr),
PadStrideInfo(1, 1, 0, 0))
243 .
set_name(param_path +
"/project/Conv2D")
248 0.0010000000474974513)
249 .
set_name(param_path +
"/project/BatchNorm");
251 if(is_residual == IsResidual::Yes)
255 graph <<
EltwiseLayer(std::move(left), std::move(right), EltwiseOperation::Add).
set_name(param_path +
"/add");
266 const std::string model_path =
"/cnn_data/mobilenet_v2_1.0_224_quantized_model/";
269 std::string data_path = common_params.
data_path;
272 if(!data_path.empty())
274 data_path += model_path;
280 const std::vector<QuantizationInfo> conv_weights_quant_info =
288 const std::vector<QuantizationInfo> pwc_q =
309 const std::vector<QuantizationInfo> dwc_q =
330 const std::vector<QuantizationInfo> prwc_q =
358 1, conv_weights_quant_info.at(0), mid_quant_info)
365 .set_name(
"expanded_conv/depthwise/depthwise")
371 .set_name(
"expanded_conv/project/Conv2D");
373 get_expanded_conv_qasymm8(data_path,
"expanded_conv_1", IsResidual::No, 96U, 24U,
PadStrideInfo(2, 2, 0, 1, 0, 1,
DimensionRoundingType::CEIL),
374 pwc_q.at(1), dwc_q.at(1), prwc_q.at(1));
375 get_expanded_conv_qasymm8(data_path,
"expanded_conv_2", IsResidual::Yes, 144U, 24U,
PadStrideInfo(1, 1, 1, 1), pwc_q.at(2), dwc_q.at(2), prwc_q.at(2));
376 get_expanded_conv_qasymm8(data_path,
"expanded_conv_3", IsResidual::No, 144U, 32U,
PadStrideInfo(2, 2, 0, 1, 0, 1,
DimensionRoundingType::CEIL),
377 pwc_q.at(3), dwc_q.at(3), prwc_q.at(3));
378 get_expanded_conv_qasymm8(data_path,
"expanded_conv_4", IsResidual::Yes, 192U, 32U,
PadStrideInfo(1, 1, 1, 1), pwc_q.at(4), dwc_q.at(4), prwc_q.at(4));
379 get_expanded_conv_qasymm8(data_path,
"expanded_conv_5", IsResidual::Yes, 192U, 32U,
PadStrideInfo(1, 1, 1, 1), pwc_q.at(5), dwc_q.at(5), prwc_q.at(5));
380 get_expanded_conv_qasymm8(data_path,
"expanded_conv_6", IsResidual::No, 192U, 64U,
PadStrideInfo(2, 2, 0, 1, 0, 1,
DimensionRoundingType::CEIL),
381 pwc_q.at(6), dwc_q.at(6), prwc_q.at(6));
382 get_expanded_conv_qasymm8(data_path,
"expanded_conv_7", IsResidual::Yes, 384U, 64U,
PadStrideInfo(1, 1, 1, 1), pwc_q.at(7), dwc_q.at(7), prwc_q.at(7));
383 get_expanded_conv_qasymm8(data_path,
"expanded_conv_8", IsResidual::Yes, 384U, 64U,
PadStrideInfo(1, 1, 1, 1), pwc_q.at(8), dwc_q.at(8), prwc_q.at(8));
384 get_expanded_conv_qasymm8(data_path,
"expanded_conv_9", IsResidual::Yes, 384U, 64U,
PadStrideInfo(1, 1, 1, 1), pwc_q.at(9), dwc_q.at(9), prwc_q.at(9));
385 get_expanded_conv_qasymm8(data_path,
"expanded_conv_10", IsResidual::No, 384U, 96U,
PadStrideInfo(1, 1, 1, 1), pwc_q.at(10), dwc_q.at(10), prwc_q.at(10));
386 get_expanded_conv_qasymm8(data_path,
"expanded_conv_11", IsResidual::Yes, 576U, 96U,
PadStrideInfo(1, 1, 1, 1), pwc_q.at(11), dwc_q.at(11), prwc_q.at(11));
387 get_expanded_conv_qasymm8(data_path,
"expanded_conv_12", IsResidual::Yes, 576U, 96U,
PadStrideInfo(1, 1, 1, 1), pwc_q.at(12), dwc_q.at(12), prwc_q.at(12));
388 get_expanded_conv_qasymm8(data_path,
"expanded_conv_13", IsResidual::No, 576U, 160U,
PadStrideInfo(2, 2, 0, 1, 0, 1,
DimensionRoundingType::CEIL),
389 pwc_q.at(13), dwc_q.at(13), prwc_q.at(13));
390 get_expanded_conv_qasymm8(data_path,
"expanded_conv_14", IsResidual::Yes, 960U, 160U,
PadStrideInfo(1, 1, 1, 1), pwc_q.at(14), dwc_q.at(14), prwc_q.at(14));
391 get_expanded_conv_qasymm8(data_path,
"expanded_conv_15", IsResidual::Yes, 960U, 160U,
PadStrideInfo(1, 1, 1, 1), pwc_q.at(15), dwc_q.at(15), prwc_q.at(15));
392 get_expanded_conv_qasymm8(data_path,
"expanded_conv_16", IsResidual::No, 960U, 320U,
PadStrideInfo(1, 1, 1, 1), pwc_q.at(16), dwc_q.at(16), prwc_q.at(16));
405 .set_name(
"Logits/Conv2d_1c_1x1");
408 void get_expanded_conv_qasymm8(
const std::string &data_path, std::string &¶m_path, IsResidual is_residual,
409 unsigned int input_channels,
unsigned int output_channels,
413 std::string total_path = param_path +
"_";
425 dwc_pad_stride_info, 1, dwi)
426 .
set_name(param_path +
"/depthwise/depthwise")
432 .
set_name(param_path +
"/project/Conv2D");
434 if(is_residual == IsResidual::Yes)
438 graph <<
EltwiseLayer(std::move(left), std::move(right), EltwiseOperation::Add).
set_name(param_path +
"/add");
461 int main(
int argc,
char **argv)
463 return arm_compute::utils::run_example<GraphMobilenetV2Example>(argc, argv);
Graph configuration structure Device target types.
CLTunerMode tuner_mode
Tuner mode to be used by the CL tuner.
std::unique_ptr< graph::ITensorAccessor > get_input_accessor(const arm_compute::utils::CommonGraphParams &graph_parameters, std::unique_ptr< IPreprocessor > preprocessor=nullptr, bool bgr=true)
Generates appropriate input accessor according to the specified graph parameters. ...
Depthwise Convolution Layer.
void consume_common_graph_parameters(CommonGraphValidateOptions &options, CommonParams &common_params)
Consumes the consume_common_graph_parameters graph options and creates a structure containing any inf...
Includes all the Graph headers at once.
Common command line options used to configure the graph examples.
Class to parse command line arguments.
arm_compute::DataLayout data_layout
Activation Layer Information class.
Copyright (c) 2017-2021 Arm Limited.
std::string mlgo_file
Filename to load MLGO heuristics from.
std::string tuner_file
File to load/store tuning values from.
Quantization information.
void forward_tail(NodeID nid)
Forwards tail of stream to a given nid.
int main(int argc, char **argv)
Main program for MobileNetV2.
Pooling Layer Information struct.
Padding and stride information class.
TensorDescriptor & set_quantization_info(QuantizationInfo tensor_quant_info)
Sets tensor descriptor quantization info.
Num samples, channels, height, width.
TensorShape permute_shape(TensorShape tensor_shape, DataLayout in_data_layout, DataLayout out_data_layout)
Permutes a given tensor shape given the input and output data layout.
TensorDescriptor & set_layout(DataLayout data_layout)
Sets tensor descriptor data layout.
Lower and Upper Bounded Rectifier ( )
Structure holding all the common graph parameters.
Upper Bounded Rectifier ( )
std::unique_ptr< graph::ITensorAccessor > get_output_accessor(const arm_compute::utils::CommonGraphParams &graph_parameters, size_t top_n=5, bool is_validation=false, std::ostream &output_stream=std::cout)
Generates appropriate output accessor according to the specified graph parameters.
bool use_tuner
Use a tuner in tunable backends.
std::unique_ptr< graph::ITensorAccessor > get_weights_accessor(const std::string &path, const std::string &data_file, DataLayout file_layout=DataLayout::NCHW)
Generates appropriate weights accessor according to the specified path.
int num_threads
Number of threads to use (thread capable backends), if 0 the backend will auto-initialize, if -1 the backend will stay as it is.
Stream frontend class to construct simple graphs in a stream fashion.
Batchnormalization Layer.
ILayer & set_name(std::string name)
Sets the name of the layer.
bool is_data_type_float(DataType dt)
Check if a given data type is of floating point type.