40 class GraphResNet50Example :
public Example 43 void do_setup(
int argc,
char **argv)
override 45 std::string data_path;
50 const std::array<float, 3> mean_rgb{ { 122.68f, 116.67f, 104.01f } };
51 std::unique_ptr<IPreprocessor> preprocessor = arm_compute::support::cpp14::make_unique<CaffePreproccessor>(mean_rgb,
55 const int target = argc > 1 ? std::strtol(argv[1],
nullptr, 10) : 0;
63 std::cout <<
"Usage: " << argv[0] <<
" [target] [path_to_data] [image] [labels] [fast_math_hint]\n\n";
64 std::cout <<
"No data folder provided: using random values\n\n";
68 std::cout <<
"Usage: " << argv[0] <<
" " << argv[1] <<
" [path_to_data] [image] [labels] [fast_math_hint]\n\n";
69 std::cout <<
"No data folder provided: using random values\n\n";
74 std::cout <<
"Usage: " << argv[0] <<
" " << argv[1] <<
" " << argv[2] <<
" [image] [labels] [fast_math_hint]\n\n";
75 std::cout <<
"No image provided: using random values\n\n";
81 std::cout <<
"Usage: " << argv[0] <<
" " << argv[1] <<
" " << argv[2] <<
" " << argv[3] <<
" [labels] [fast_math_hint]\n\n";
82 std::cout <<
"No text file with labels provided: skipping output accessor\n\n";
89 std::cout <<
"Usage: " << argv[0] <<
" " << argv[1] <<
" " << argv[2] <<
" " << argv[3] <<
" " << argv[4] <<
" [fast_math_hint]\n\n";
90 std::cout <<
"No fast math info provided: disabling fast math\n\n";
97 fast_math_hint = (std::strtol(argv[5],
nullptr, 1) == 0) ? FastMathHint::DISABLED : FastMathHint::ENABLED;
107 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr),
108 PadStrideInfo(2, 2, 3, 3))
112 get_weights_accessor(data_path,
"/cnn_data/resnet50_model/conv1_BatchNorm_moving_variance.npy"),
120 add_residual_block(data_path,
"block1", 64, 3, 2);
121 add_residual_block(data_path,
"block2", 128, 4, 2);
122 add_residual_block(data_path,
"block3", 256, 6, 2);
123 add_residual_block(data_path,
"block4", 512, 3, 1);
130 PadStrideInfo(1, 1, 0, 0))
138 config.use_tuner = (target == 2);
139 graph.finalize(target_hint, config);
142 void do_run()
override 149 Stream graph{ 0,
"ResNet50" };
151 void add_residual_block(
const std::string &data_path,
const std::string &name,
unsigned int base_depth,
unsigned int num_units,
unsigned int stride)
153 for(
unsigned int i = 0; i < num_units; ++i)
155 std::stringstream unit_path_ss;
156 unit_path_ss <<
"/cnn_data/resnet50_model/" << name <<
"_unit_" << (i + 1) <<
"_bottleneck_v1_";
157 std::stringstream unit_name_ss;
158 unit_name_ss << name <<
"/unit" << (i + 1) <<
"/bottleneck_v1/";
160 std::string unit_path = unit_path_ss.str();
161 std::string unit_name = unit_name_ss.str();
163 unsigned int middle_stride = 1;
165 if(i == (num_units - 1))
167 middle_stride = stride;
174 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr),
175 PadStrideInfo(1, 1, 0, 0))
176 .
set_name(unit_name +
"conv1/convolution")
183 .
set_name(unit_name +
"conv1/BatchNorm")
189 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr),
190 PadStrideInfo(middle_stride, middle_stride, 1, 1))
191 .
set_name(unit_name +
"conv2/convolution")
198 .
set_name(unit_name +
"conv2/BatchNorm")
202 1U, 1U, base_depth * 4,
204 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr),
205 PadStrideInfo(1, 1, 0, 0))
206 .
set_name(unit_name +
"conv3/convolution")
213 .
set_name(unit_name +
"conv2/BatchNorm");
219 1U, 1U, base_depth * 4,
221 std::unique_ptr<arm_compute::graph::ITensorAccessor>(
nullptr),
222 PadStrideInfo(1, 1, 0, 0))
223 .
set_name(unit_name +
"shortcut/convolution")
230 .
set_name(unit_name +
"shortcut/BatchNorm");
234 else if(middle_stride > 1)
257 int main(
int argc,
char **argv)
259 return arm_compute::utils::run_example<GraphResNet50Example>(argc, argv);
graph::Target set_target_hint(int target)
Utility function to return the TargetHint.
std::unique_ptr< graph::ITensorAccessor > get_output_accessor(const std::string &labels_path, size_t top_n=5, std::ostream &output_stream=std::cout)
Generates appropriate output accessor according to the specified labels_path.
1 channel, 1 F32 per channel
int main(int argc, char **argv)
Main program for ResNet50.
std::unique_ptr< graph::ITensorAccessor > get_input_accessor(const std::string &ppm_path, std::unique_ptr< IPreprocessor > preprocessor=nullptr, bool bgr=true)
Generates appropriate input accessor according to the specified ppm_path.
FastMathHint
Enable or disable fast math for Convolution layer.
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.
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.