35 class GraphYOLOv3Example :
public Example 39 : cmd_parser(), common_opts(cmd_parser), common_params(), graph(0,
"YOLOv3")
43 bool do_setup(
int argc,
char **argv)
override 46 cmd_parser.parse(argc, argv);
47 cmd_parser.validate();
53 if(common_params.help)
55 cmd_parser.print_help(argv[0]);
63 std::cout << common_params << std::endl;
66 std::string data_path = common_params.data_path;
69 std::unique_ptr<IPreprocessor> preprocessor = std::make_unique<TFPreproccessor>(0.f);
78 graph << common_params.target
79 << common_params.fast_math_hint
81 std::pair<SubStream, SubStream> intermediate_layers = darknet53(data_path, weights_layout);
85 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr),
86 PadStrideInfo(1, 1, 0, 0))
99 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr),
100 PadStrideInfo(1, 1, 1, 1))
113 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr),
114 PadStrideInfo(1, 1, 0, 0))
127 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr),
128 PadStrideInfo(1, 1, 1, 1))
141 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr),
142 PadStrideInfo(1, 1, 0, 0))
156 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr),
157 PadStrideInfo(1, 1, 1, 1))
171 PadStrideInfo(1, 1, 0, 0))
179 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr),
180 PadStrideInfo(1, 1, 0, 0))
192 concat_1 <<
ConcatLayer(std::move(route_1), std::move(intermediate_layers.second)).
set_name(
"Route1")
196 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr),
197 PadStrideInfo(1, 1, 0, 0))
210 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr),
211 PadStrideInfo(1, 1, 1, 1))
224 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr),
225 PadStrideInfo(1, 1, 0, 0))
238 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr),
239 PadStrideInfo(1, 1, 1, 1))
252 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr),
253 PadStrideInfo(1, 1, 0, 0))
267 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr),
268 PadStrideInfo(1, 1, 1, 1))
282 PadStrideInfo(1, 1, 0, 0))
290 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr),
291 PadStrideInfo(1, 1, 0, 0))
303 concat_2 <<
ConcatLayer(std::move(route_2), std::move(intermediate_layers.first)).
set_name(
"Route2")
307 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr),
308 PadStrideInfo(1, 1, 0, 0))
321 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr),
322 PadStrideInfo(1, 1, 1, 1))
335 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr),
336 PadStrideInfo(1, 1, 0, 0))
349 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr),
350 PadStrideInfo(1, 1, 1, 1))
363 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr),
364 PadStrideInfo(1, 1, 0, 0))
377 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr),
378 PadStrideInfo(1, 1, 1, 1))
392 PadStrideInfo(1, 1, 0, 0))
401 config.
use_tuner = common_params.enable_tuner;
404 config.
mlgo_file = common_params.mlgo_file;
406 graph.finalize(common_params.target, config);
410 void do_run()
override 422 std::pair<SubStream, SubStream> darknet53(
const std::string &data_path,
DataLayout weights_layout)
427 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr),
428 PadStrideInfo(1, 1, 1, 1))
441 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr),
442 PadStrideInfo(2, 2, 1, 1))
452 darknet53_block(data_path,
"3", weights_layout, 32U);
456 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr),
457 PadStrideInfo(2, 2, 1, 1))
467 darknet53_block(data_path,
"6", weights_layout, 64U);
468 darknet53_block(data_path,
"8", weights_layout, 64U);
472 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr),
473 PadStrideInfo(2, 2, 1, 1))
483 darknet53_block(data_path,
"11", weights_layout, 128U);
484 darknet53_block(data_path,
"13", weights_layout, 128U);
485 darknet53_block(data_path,
"15", weights_layout, 128U);
486 darknet53_block(data_path,
"17", weights_layout, 128U);
487 darknet53_block(data_path,
"19", weights_layout, 128U);
488 darknet53_block(data_path,
"21", weights_layout, 128U);
489 darknet53_block(data_path,
"23", weights_layout, 128U);
490 darknet53_block(data_path,
"25", weights_layout, 128U);
495 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr),
496 PadStrideInfo(2, 2, 1, 1))
506 darknet53_block(data_path,
"28", weights_layout, 256U);
507 darknet53_block(data_path,
"30", weights_layout, 256U);
508 darknet53_block(data_path,
"32", weights_layout, 256U);
509 darknet53_block(data_path,
"34", weights_layout, 256U);
510 darknet53_block(data_path,
"36", weights_layout, 256U);
511 darknet53_block(data_path,
"38", weights_layout, 256U);
512 darknet53_block(data_path,
"40", weights_layout, 256U);
513 darknet53_block(data_path,
"42", weights_layout, 256U);
518 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr),
519 PadStrideInfo(2, 2, 1, 1))
529 darknet53_block(data_path,
"45", weights_layout, 512U);
530 darknet53_block(data_path,
"47", weights_layout, 512U);
531 darknet53_block(data_path,
"49", weights_layout, 512U);
532 darknet53_block(data_path,
"51", weights_layout, 512U);
534 return std::pair<SubStream, SubStream>(layer_36, layer_61);
537 void darknet53_block(
const std::string &data_path, std::string &¶m_path,
DataLayout weights_layout,
538 unsigned int filter_size)
540 std::string total_path =
"/cnn_data/yolov3_model/";
546 get_weights_accessor(data_path, total_path +
"conv2d_" + param_path +
"_w.npy", weights_layout),
547 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr),
548 PadStrideInfo(1, 1, 0, 0))
549 .
set_name(
"conv2d_" + param_path +
"/Conv2D")
551 get_weights_accessor(data_path, total_path +
"batch_normalization_" + param_path +
"_mean.npy"),
553 get_weights_accessor(data_path, total_path +
"batch_normalization_" + param_path +
"_gamma.npy"),
554 get_weights_accessor(data_path, total_path +
"batch_normalization_" + param_path +
"_beta.npy"),
556 .
set_name(
"conv2d_" + param_path +
"/BatchNorm")
559 3U, 3U, filter_size * 2,
560 get_weights_accessor(data_path, total_path +
"conv2d_" + param_path2 +
"_w.npy", weights_layout),
561 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr),
562 PadStrideInfo(1, 1, 1, 1))
563 .
set_name(
"conv2d_" + param_path2 +
"/Conv2D")
565 get_weights_accessor(data_path, total_path +
"batch_normalization_" + param_path2 +
"_mean.npy"),
566 get_weights_accessor(data_path, total_path +
"batch_normalization_" + param_path2 +
"_var.npy"),
567 get_weights_accessor(data_path, total_path +
"batch_normalization_" + param_path2 +
"_gamma.npy"),
568 get_weights_accessor(data_path, total_path +
"batch_normalization_" + param_path2 +
"_beta.npy"),
570 .
set_name(
"conv2d_" + param_path2 +
"/BatchNorm")
573 graph <<
EltwiseLayer(std::move(i_a), std::move(i_b), EltwiseOperation::Add).
set_name(
"").
set_name(
"add_" + param_path +
"_" + param_path2);
591 int main(
int argc,
char **argv)
593 return arm_compute::utils::run_example<GraphYOLOv3Example>(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. ...
std::string to_string(T &&value)
Convert integer and float values to string.
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.
Output values are defined to match the source pixel whose center is nearest to the sample position...
Class to parse command line arguments.
std::string mlgo_file
Filename to load MLGO heuristics from.
std::string tuner_file
File to load/store tuning values from.
#define ARM_COMPUTE_EXIT_ON_MSG(cond, msg)
If the condition is true, the given message is printed and program exits.
int stoi(const std::string &str, std::size_t *pos=0, NumericBase base=NumericBase::BASE_10)
Convert string values to integer.
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.
bool is_data_type_quantized_asymmetric(DataType dt)
Check if a given data type is of asymmetric quantized type.
TensorDescriptor & set_layout(DataLayout data_layout)
Sets tensor descriptor data layout.
Structure holding all the common graph parameters.
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.
int main(int argc, char **argv)
Main program for YOLOv3.
Stream frontend class to construct simple graphs in a stream fashion.
Batchnormalization Layer.
DataLayout
[DataLayout enum definition]
ILayer & set_name(std::string name)
Sets the name of the layer.