29 #include "utils/Utils.h"
36 class GraphResNeXt50Example :
public Example
39 GraphResNeXt50Example() : cmd_parser(), common_opts(cmd_parser), common_params(), graph(0,
"ResNeXt50")
42 bool do_setup(
int argc,
char **argv)
override
45 cmd_parser.parse(argc, argv);
46 cmd_parser.validate();
52 if (common_params.help)
54 cmd_parser.print_help(argv[0]);
60 "QASYMM8 not supported for this graph");
63 std::cout << common_params << std::endl;
66 std::string data_path = common_params.data_path;
69 const auto operation_layout = common_params.data_layout;
70 const TensorShape tensor_shape =
78 graph << common_params.target << common_params.fast_math_hint
89 <<
ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
95 add_residual_block(data_path, weights_layout, 256, 1, 3,
97 add_residual_block(data_path, weights_layout, 512, 2, 4, 2);
98 add_residual_block(data_path, weights_layout, 1024, 3, 6, 2);
99 add_residual_block(data_path, weights_layout, 2048, 4, 3, 2);
108 config.
use_tuner = common_params.enable_tuner;
111 config.
mlgo_file = common_params.mlgo_file;
113 graph.finalize(common_params.target, config);
118 void do_run()
override
130 void add_residual_block(
const std::string &data_path,
132 unsigned int base_depth,
134 unsigned int num_units,
135 unsigned int stride_conv_unit1)
137 for (
unsigned int i = 0; i < num_units; ++i)
139 std::stringstream unit_path_ss;
140 unit_path_ss <<
"/cnn_data/resnext50_model/stage" << stage <<
"_unit" << (i + 1) <<
"_";
141 std::string unit_path = unit_path_ss.str();
143 std::stringstream unit_name_ss;
144 unit_name_ss <<
"stage" << stage <<
"/unit" << (i + 1) <<
"/";
145 std::string unit_name = unit_name_ss.str();
147 PadStrideInfo pad_grouped_conv(1, 1, 1, 1);
150 pad_grouped_conv = (stage == 1) ? PadStrideInfo(stride_conv_unit1, stride_conv_unit1, 1, 1)
151 : PadStrideInfo(stride_conv_unit1, stride_conv_unit1, 0, 1, 0, 1,
159 PadStrideInfo(1, 1, 0, 0))
160 .
set_name(unit_name +
"conv1/convolution")
161 <<
ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
166 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr), pad_grouped_conv,
168 .
set_name(unit_name +
"conv2/convolution")
171 .
set_name(unit_name +
"conv1/Scale")
172 <<
ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
178 PadStrideInfo(1, 1, 0, 0))
179 .
set_name(unit_name +
"conv3/convolution");
186 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr),
187 PadStrideInfo(stride_conv_unit1, stride_conv_unit1, 0, 0))
188 .
set_name(unit_name +
"sc/convolution")
194 graph <<
EltwiseLayer(std::move(left), std::move(right), EltwiseOperation::Add).
set_name(unit_name +
"add");
195 graph <<
ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
213 int main(
int argc,
char **argv)
215 return arm_compute::utils::run_example<GraphResNeXt50Example>(argc, argv);