Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 1 | /* |
SiCong Li | a4a2354 | 2023-12-06 17:24:20 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2023 Arm Limited. |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
SiCong Li | a4a2354 | 2023-12-06 17:24:20 +0000 | [diff] [blame] | 24 | #include "arm_compute/core/utils/quantization/AsymmHelpers.h" |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 25 | #include "arm_compute/graph.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 26 | |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 27 | #include "support/ToolchainSupport.h" |
| 28 | #include "utils/CommonGraphOptions.h" |
| 29 | #include "utils/GraphUtils.h" |
| 30 | #include "utils/Utils.h" |
| 31 | |
| 32 | using namespace arm_compute; |
| 33 | using namespace arm_compute::utils; |
| 34 | using namespace arm_compute::graph::frontend; |
| 35 | using namespace arm_compute::graph_utils; |
| 36 | |
| 37 | /** Example demonstrating how to implement MobileNetSSD's network using the Compute Library's graph API */ |
| 38 | class GraphSSDMobilenetExample : public Example |
| 39 | { |
| 40 | public: |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 41 | GraphSSDMobilenetExample() : cmd_parser(), common_opts(cmd_parser), common_params(), graph(0, "MobileNetSSD") |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 42 | { |
Isabella Gottardi | 7234ed8 | 2018-11-27 08:51:10 +0000 | [diff] [blame] | 43 | // Add topk option |
| 44 | keep_topk_opt = cmd_parser.add_option<SimpleOption<int>>("topk", 100); |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 45 | keep_topk_opt->set_help("Top k detections results per image. Used for data type F32."); |
| 46 | // Add output option |
| 47 | detection_boxes_opt = cmd_parser.add_option<SimpleOption<std::string>>("detection_boxes_opt", ""); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 48 | detection_boxes_opt->set_help("Filename containing the reference values for the graph output detection_boxes. " |
| 49 | "Used for data type QASYMM8."); |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 50 | detection_classes_opt = cmd_parser.add_option<SimpleOption<std::string>>("detection_classes_opt", ""); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 51 | detection_classes_opt->set_help( |
| 52 | "Filename containing the reference values for the output detection_classes. Used for data type QASYMM8."); |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 53 | detection_scores_opt = cmd_parser.add_option<SimpleOption<std::string>>("detection_scores_opt", ""); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 54 | detection_scores_opt->set_help( |
| 55 | "Filename containing the reference values for the output detection_scores. Used for data type QASYMM8."); |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 56 | num_detections_opt = cmd_parser.add_option<SimpleOption<std::string>>("num_detections_opt", ""); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 57 | num_detections_opt->set_help( |
| 58 | "Filename containing the reference values for the output num_detections. Used with datatype QASYMM8."); |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 59 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 60 | GraphSSDMobilenetExample(const GraphSSDMobilenetExample &) = delete; |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 61 | GraphSSDMobilenetExample &operator=(const GraphSSDMobilenetExample &) = delete; |
Matthew Bentham | f5f2391 | 2020-03-05 22:32:16 +0000 | [diff] [blame] | 62 | ~GraphSSDMobilenetExample() override = default; |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 63 | bool do_setup(int argc, char **argv) override |
| 64 | { |
| 65 | // Parse arguments |
| 66 | cmd_parser.parse(argc, argv); |
Georgios Pinitas | cd60a5f | 2019-08-21 17:06:54 +0100 | [diff] [blame] | 67 | cmd_parser.validate(); |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 68 | |
| 69 | // Consume common parameters |
| 70 | common_params = consume_common_graph_parameters(common_opts); |
| 71 | |
| 72 | // Return when help menu is requested |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 73 | if (common_params.help) |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 74 | { |
| 75 | cmd_parser.print_help(argv[0]); |
| 76 | return false; |
| 77 | } |
| 78 | |
| 79 | // Print parameter values |
| 80 | std::cout << common_params << std::endl; |
| 81 | |
| 82 | // Create input descriptor |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 83 | const TensorShape tensor_shape = |
| 84 | permute_shape(TensorShape(300, 300, 3U, 1U), DataLayout::NCHW, common_params.data_layout); |
| 85 | TensorDescriptor input_descriptor = |
| 86 | TensorDescriptor(tensor_shape, common_params.data_type).set_layout(common_params.data_layout); |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 87 | |
| 88 | // Set graph hints |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 89 | graph << common_params.target << common_params.fast_math_hint; |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 90 | |
| 91 | // Create core graph |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 92 | if (arm_compute::is_data_type_float(common_params.data_type)) |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 93 | { |
| 94 | create_graph_float(input_descriptor); |
| 95 | } |
| 96 | else |
| 97 | { |
| 98 | create_graph_qasymm(input_descriptor); |
| 99 | } |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 100 | |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 101 | // Finalize graph |
| 102 | GraphConfig config; |
| 103 | config.num_threads = common_params.threads; |
| 104 | config.use_tuner = common_params.enable_tuner; |
| 105 | config.tuner_file = common_params.tuner_file; |
SiCong Li | 4841c97 | 2021-02-03 12:17:35 +0000 | [diff] [blame] | 106 | config.mlgo_file = common_params.mlgo_file; |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 107 | |
| 108 | graph.finalize(common_params.target, config); |
| 109 | |
| 110 | return true; |
| 111 | } |
| 112 | void do_run() override |
| 113 | { |
| 114 | // Run graph |
| 115 | graph.run(); |
| 116 | } |
| 117 | |
| 118 | private: |
| 119 | CommandLineParser cmd_parser; |
| 120 | CommonGraphOptions common_opts; |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 121 | SimpleOption<int> *keep_topk_opt{nullptr}; |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 122 | CommonGraphParams common_params; |
| 123 | Stream graph; |
| 124 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 125 | SimpleOption<std::string> *detection_boxes_opt{nullptr}; |
| 126 | SimpleOption<std::string> *detection_classes_opt{nullptr}; |
| 127 | SimpleOption<std::string> *detection_scores_opt{nullptr}; |
| 128 | SimpleOption<std::string> *num_detections_opt{nullptr}; |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 129 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 130 | ConcatLayer get_node_A_float(IStream &main_graph, |
| 131 | const std::string &data_path, |
| 132 | std::string &¶m_path, |
| 133 | unsigned int conv_filt, |
| 134 | PadStrideInfo dwc_pad_stride_info, |
| 135 | PadStrideInfo conv_pad_stride_info) |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 136 | { |
| 137 | const std::string total_path = param_path + "_"; |
ramelg01 | b4cd2dc | 2022-03-30 18:42:23 +0100 | [diff] [blame] | 138 | SubStream sg(main_graph); |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 139 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 140 | sg << DepthwiseConvolutionLayer(3U, 3U, get_weights_accessor(data_path, total_path + "dw_w.npy"), |
| 141 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), |
| 142 | dwc_pad_stride_info) |
| 143 | .set_name(param_path + "/dw") |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 144 | << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "dw_bn_mean.npy"), |
| 145 | get_weights_accessor(data_path, total_path + "dw_bn_var.npy"), |
| 146 | get_weights_accessor(data_path, total_path + "dw_scale_w.npy"), |
| 147 | get_weights_accessor(data_path, total_path + "dw_scale_b.npy"), 0.00001f) |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 148 | .set_name(param_path + "/dw/bn") |
| 149 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)) |
| 150 | .set_name(param_path + "dw/relu") |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 151 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 152 | << ConvolutionLayer(1U, 1U, conv_filt, get_weights_accessor(data_path, total_path + "w.npy"), |
| 153 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), conv_pad_stride_info) |
| 154 | .set_name(param_path + "/pw") |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 155 | << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "bn_mean.npy"), |
| 156 | get_weights_accessor(data_path, total_path + "bn_var.npy"), |
| 157 | get_weights_accessor(data_path, total_path + "scale_w.npy"), |
| 158 | get_weights_accessor(data_path, total_path + "scale_b.npy"), 0.00001f) |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 159 | .set_name(param_path + "/pw/bn") |
| 160 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)) |
| 161 | .set_name(param_path + "pw/relu"); |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 162 | |
| 163 | return ConcatLayer(std::move(sg)); |
| 164 | } |
| 165 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 166 | ConcatLayer get_node_B_float(IStream &main_graph, |
| 167 | const std::string &data_path, |
| 168 | std::string &¶m_path, |
| 169 | unsigned int conv_filt, |
| 170 | PadStrideInfo conv_pad_stride_info_1, |
| 171 | PadStrideInfo conv_pad_stride_info_2) |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 172 | { |
| 173 | const std::string total_path = param_path + "_"; |
ramelg01 | b4cd2dc | 2022-03-30 18:42:23 +0100 | [diff] [blame] | 174 | SubStream sg(main_graph); |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 175 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 176 | sg << ConvolutionLayer(1, 1, conv_filt / 2, get_weights_accessor(data_path, total_path + "1_w.npy"), |
| 177 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), conv_pad_stride_info_1) |
| 178 | .set_name(total_path + "1/conv") |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 179 | << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "1_bn_mean.npy"), |
| 180 | get_weights_accessor(data_path, total_path + "1_bn_var.npy"), |
| 181 | get_weights_accessor(data_path, total_path + "1_scale_w.npy"), |
| 182 | get_weights_accessor(data_path, total_path + "1_scale_b.npy"), 0.00001f) |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 183 | .set_name(total_path + "1/bn") |
| 184 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)) |
| 185 | .set_name(total_path + "1/relu"); |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 186 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 187 | sg << ConvolutionLayer(3, 3, conv_filt, get_weights_accessor(data_path, total_path + "2_w.npy"), |
| 188 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), conv_pad_stride_info_2) |
| 189 | .set_name(total_path + "2/conv") |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 190 | << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "2_bn_mean.npy"), |
| 191 | get_weights_accessor(data_path, total_path + "2_bn_var.npy"), |
| 192 | get_weights_accessor(data_path, total_path + "2_scale_w.npy"), |
| 193 | get_weights_accessor(data_path, total_path + "2_scale_b.npy"), 0.00001f) |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 194 | .set_name(total_path + "2/bn") |
| 195 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)) |
| 196 | .set_name(total_path + "2/relu"); |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 197 | |
| 198 | return ConcatLayer(std::move(sg)); |
| 199 | } |
| 200 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 201 | ConcatLayer get_node_C_float(IStream &main_graph, |
| 202 | const std::string &data_path, |
| 203 | std::string &¶m_path, |
| 204 | unsigned int conv_filt, |
| 205 | PadStrideInfo conv_pad_stride_info) |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 206 | { |
| 207 | const std::string total_path = param_path + "_"; |
ramelg01 | b4cd2dc | 2022-03-30 18:42:23 +0100 | [diff] [blame] | 208 | SubStream sg(main_graph); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 209 | sg << ConvolutionLayer(1U, 1U, conv_filt, get_weights_accessor(data_path, total_path + "w.npy"), |
| 210 | get_weights_accessor(data_path, total_path + "b.npy"), conv_pad_stride_info) |
| 211 | .set_name(param_path + "/conv"); |
| 212 | if (common_params.data_layout == DataLayout::NCHW) |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 213 | { |
| 214 | sg << PermuteLayer(PermutationVector(2U, 0U, 1U), DataLayout::NHWC).set_name(param_path + "/perm"); |
| 215 | } |
| 216 | sg << FlattenLayer().set_name(param_path + "/flat"); |
| 217 | |
| 218 | return ConcatLayer(std::move(sg)); |
| 219 | } |
| 220 | |
| 221 | void create_graph_float(TensorDescriptor &input_descriptor) |
| 222 | { |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 223 | // Create a preprocessor object |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 224 | const std::array<float, 3> mean_rgb{{127.5f, 127.5f, 127.5f}}; |
Georgios Pinitas | 40f51a6 | 2020-11-21 03:04:18 +0000 | [diff] [blame] | 225 | std::unique_ptr<IPreprocessor> preprocessor = std::make_unique<CaffePreproccessor>(mean_rgb, true, 0.007843f); |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 226 | |
| 227 | // Get trainable parameters data path |
| 228 | std::string data_path = common_params.data_path; |
| 229 | |
| 230 | // Add model path to data path |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 231 | if (!data_path.empty()) |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 232 | { |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 233 | data_path += "/cnn_data/ssd_mobilenet_model/"; |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 234 | } |
| 235 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 236 | graph << InputLayer(input_descriptor, get_input_accessor(common_params, std::move(preprocessor))); |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 237 | |
| 238 | SubStream conv_11(graph); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 239 | conv_11 << ConvolutionLayer(3U, 3U, 32U, get_weights_accessor(data_path, "conv0_w.npy"), |
| 240 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), |
| 241 | PadStrideInfo(2, 2, 1, 1)) |
| 242 | .set_name("conv0"); |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 243 | conv_11 << BatchNormalizationLayer(get_weights_accessor(data_path, "conv0_bn_mean.npy"), |
| 244 | get_weights_accessor(data_path, "conv0_bn_var.npy"), |
| 245 | get_weights_accessor(data_path, "conv0_scale_w.npy"), |
| 246 | get_weights_accessor(data_path, "conv0_scale_b.npy"), 0.00001f) |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 247 | .set_name("conv0/bn") |
| 248 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)) |
| 249 | .set_name("conv0/relu"); |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 250 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 251 | conv_11 << get_node_A_float(conv_11, data_path, "conv1", 64, PadStrideInfo(1, 1, 1, 1), |
| 252 | PadStrideInfo(1, 1, 0, 0)); |
| 253 | conv_11 << get_node_A_float(conv_11, data_path, "conv2", 128, PadStrideInfo(2, 2, 1, 1), |
| 254 | PadStrideInfo(1, 1, 0, 0)); |
| 255 | conv_11 << get_node_A_float(conv_11, data_path, "conv3", 128, PadStrideInfo(1, 1, 1, 1), |
| 256 | PadStrideInfo(1, 1, 0, 0)); |
| 257 | conv_11 << get_node_A_float(conv_11, data_path, "conv4", 256, PadStrideInfo(2, 2, 1, 1), |
| 258 | PadStrideInfo(1, 1, 0, 0)); |
| 259 | conv_11 << get_node_A_float(conv_11, data_path, "conv5", 256, PadStrideInfo(1, 1, 1, 1), |
| 260 | PadStrideInfo(1, 1, 0, 0)); |
| 261 | conv_11 << get_node_A_float(conv_11, data_path, "conv6", 512, PadStrideInfo(2, 2, 1, 1), |
| 262 | PadStrideInfo(1, 1, 0, 0)); |
| 263 | conv_11 << get_node_A_float(conv_11, data_path, "conv7", 512, PadStrideInfo(1, 1, 1, 1), |
| 264 | PadStrideInfo(1, 1, 0, 0)); |
| 265 | conv_11 << get_node_A_float(conv_11, data_path, "conv8", 512, PadStrideInfo(1, 1, 1, 1), |
| 266 | PadStrideInfo(1, 1, 0, 0)); |
| 267 | conv_11 << get_node_A_float(conv_11, data_path, "conv9", 512, PadStrideInfo(1, 1, 1, 1), |
| 268 | PadStrideInfo(1, 1, 0, 0)); |
| 269 | conv_11 << get_node_A_float(conv_11, data_path, "conv10", 512, PadStrideInfo(1, 1, 1, 1), |
| 270 | PadStrideInfo(1, 1, 0, 0)); |
| 271 | conv_11 << get_node_A_float(conv_11, data_path, "conv11", 512, PadStrideInfo(1, 1, 1, 1), |
| 272 | PadStrideInfo(1, 1, 0, 0)); |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 273 | |
| 274 | SubStream conv_13(conv_11); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 275 | conv_13 << get_node_A_float(conv_11, data_path, "conv12", 1024, PadStrideInfo(2, 2, 1, 1), |
| 276 | PadStrideInfo(1, 1, 0, 0)); |
| 277 | conv_13 << get_node_A_float(conv_13, data_path, "conv13", 1024, PadStrideInfo(1, 1, 1, 1), |
| 278 | PadStrideInfo(1, 1, 0, 0)); |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 279 | |
| 280 | SubStream conv_14(conv_13); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 281 | conv_14 << get_node_B_float(conv_13, data_path, "conv14", 512, PadStrideInfo(1, 1, 0, 0), |
| 282 | PadStrideInfo(2, 2, 1, 1)); |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 283 | |
| 284 | SubStream conv_15(conv_14); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 285 | conv_15 << get_node_B_float(conv_14, data_path, "conv15", 256, PadStrideInfo(1, 1, 0, 0), |
| 286 | PadStrideInfo(2, 2, 1, 1)); |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 287 | |
| 288 | SubStream conv_16(conv_15); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 289 | conv_16 << get_node_B_float(conv_15, data_path, "conv16", 256, PadStrideInfo(1, 1, 0, 0), |
| 290 | PadStrideInfo(2, 2, 1, 1)); |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 291 | |
| 292 | SubStream conv_17(conv_16); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 293 | conv_17 << get_node_B_float(conv_16, data_path, "conv17", 128, PadStrideInfo(1, 1, 0, 0), |
| 294 | PadStrideInfo(2, 2, 1, 1)); |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 295 | |
| 296 | //mbox_loc |
| 297 | SubStream conv_11_mbox_loc(conv_11); |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 298 | conv_11_mbox_loc << get_node_C_float(conv_11, data_path, "conv11_mbox_loc", 12, PadStrideInfo(1, 1, 0, 0)); |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 299 | |
| 300 | SubStream conv_13_mbox_loc(conv_13); |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 301 | conv_13_mbox_loc << get_node_C_float(conv_13, data_path, "conv13_mbox_loc", 24, PadStrideInfo(1, 1, 0, 0)); |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 302 | |
| 303 | SubStream conv_14_2_mbox_loc(conv_14); |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 304 | conv_14_2_mbox_loc << get_node_C_float(conv_14, data_path, "conv14_2_mbox_loc", 24, PadStrideInfo(1, 1, 0, 0)); |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 305 | |
| 306 | SubStream conv_15_2_mbox_loc(conv_15); |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 307 | conv_15_2_mbox_loc << get_node_C_float(conv_15, data_path, "conv15_2_mbox_loc", 24, PadStrideInfo(1, 1, 0, 0)); |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 308 | |
| 309 | SubStream conv_16_2_mbox_loc(conv_16); |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 310 | conv_16_2_mbox_loc << get_node_C_float(conv_16, data_path, "conv16_2_mbox_loc", 24, PadStrideInfo(1, 1, 0, 0)); |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 311 | |
| 312 | SubStream conv_17_2_mbox_loc(conv_17); |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 313 | conv_17_2_mbox_loc << get_node_C_float(conv_17, data_path, "conv17_2_mbox_loc", 24, PadStrideInfo(1, 1, 0, 0)); |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 314 | |
| 315 | SubStream mbox_loc(graph); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 316 | mbox_loc << ConcatLayer(std::move(conv_11_mbox_loc), std::move(conv_13_mbox_loc), conv_14_2_mbox_loc, |
| 317 | std::move(conv_15_2_mbox_loc), std::move(conv_16_2_mbox_loc), |
| 318 | std::move(conv_17_2_mbox_loc)); |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 319 | |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 320 | //mbox_conf |
| 321 | SubStream conv_11_mbox_conf(conv_11); |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 322 | conv_11_mbox_conf << get_node_C_float(conv_11, data_path, "conv11_mbox_conf", 63, PadStrideInfo(1, 1, 0, 0)); |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 323 | |
| 324 | SubStream conv_13_mbox_conf(conv_13); |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 325 | conv_13_mbox_conf << get_node_C_float(conv_13, data_path, "conv13_mbox_conf", 126, PadStrideInfo(1, 1, 0, 0)); |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 326 | |
| 327 | SubStream conv_14_2_mbox_conf(conv_14); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 328 | conv_14_2_mbox_conf << get_node_C_float(conv_14, data_path, "conv14_2_mbox_conf", 126, |
| 329 | PadStrideInfo(1, 1, 0, 0)); |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 330 | |
| 331 | SubStream conv_15_2_mbox_conf(conv_15); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 332 | conv_15_2_mbox_conf << get_node_C_float(conv_15, data_path, "conv15_2_mbox_conf", 126, |
| 333 | PadStrideInfo(1, 1, 0, 0)); |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 334 | |
| 335 | SubStream conv_16_2_mbox_conf(conv_16); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 336 | conv_16_2_mbox_conf << get_node_C_float(conv_16, data_path, "conv16_2_mbox_conf", 126, |
| 337 | PadStrideInfo(1, 1, 0, 0)); |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 338 | |
| 339 | SubStream conv_17_2_mbox_conf(conv_17); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 340 | conv_17_2_mbox_conf << get_node_C_float(conv_17, data_path, "conv17_2_mbox_conf", 126, |
| 341 | PadStrideInfo(1, 1, 0, 0)); |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 342 | |
| 343 | SubStream mbox_conf(graph); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 344 | mbox_conf << ConcatLayer(std::move(conv_11_mbox_conf), std::move(conv_13_mbox_conf), |
| 345 | std::move(conv_14_2_mbox_conf), std::move(conv_15_2_mbox_conf), |
| 346 | std::move(conv_16_2_mbox_conf), std::move(conv_17_2_mbox_conf)); |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 347 | mbox_conf << ReshapeLayer(TensorShape(21U, 1917U)).set_name("mbox_conf/reshape"); |
| 348 | mbox_conf << SoftmaxLayer().set_name("mbox_conf/softmax"); |
| 349 | mbox_conf << FlattenLayer().set_name("mbox_conf/flat"); |
| 350 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 351 | const std::vector<float> priorbox_variances = {0.1f, 0.1f, 0.2f, 0.2f}; |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 352 | const float priorbox_offset = 0.5f; |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 353 | const std::vector<float> priorbox_aspect_ratios = {2.f, 3.f}; |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 354 | |
| 355 | //mbox_priorbox branch |
| 356 | SubStream conv_11_mbox_priorbox(conv_11); |
| 357 | |
| 358 | conv_11_mbox_priorbox << PriorBoxLayer(SubStream(graph), |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 359 | PriorBoxLayerInfo({60.f}, priorbox_variances, priorbox_offset, true, |
| 360 | false, {}, {2.f})) |
| 361 | .set_name("conv11/priorbox"); |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 362 | |
| 363 | SubStream conv_13_mbox_priorbox(conv_13); |
| 364 | conv_13_mbox_priorbox << PriorBoxLayer(SubStream(graph), |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 365 | PriorBoxLayerInfo({105.f}, priorbox_variances, priorbox_offset, true, |
| 366 | false, {150.f}, priorbox_aspect_ratios)) |
| 367 | .set_name("conv13/priorbox"); |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 368 | |
| 369 | SubStream conv_14_2_mbox_priorbox(conv_14); |
| 370 | conv_14_2_mbox_priorbox << PriorBoxLayer(SubStream(graph), |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 371 | PriorBoxLayerInfo({150.f}, priorbox_variances, priorbox_offset, true, |
| 372 | false, {195.f}, priorbox_aspect_ratios)) |
| 373 | .set_name("conv14/priorbox"); |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 374 | |
| 375 | SubStream conv_15_2_mbox_priorbox(conv_15); |
| 376 | conv_15_2_mbox_priorbox << PriorBoxLayer(SubStream(graph), |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 377 | PriorBoxLayerInfo({195.f}, priorbox_variances, priorbox_offset, true, |
| 378 | false, {240.f}, priorbox_aspect_ratios)) |
| 379 | .set_name("conv15/priorbox"); |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 380 | |
| 381 | SubStream conv_16_2_mbox_priorbox(conv_16); |
| 382 | conv_16_2_mbox_priorbox << PriorBoxLayer(SubStream(graph), |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 383 | PriorBoxLayerInfo({240.f}, priorbox_variances, priorbox_offset, true, |
| 384 | false, {285.f}, priorbox_aspect_ratios)) |
| 385 | .set_name("conv16/priorbox"); |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 386 | |
| 387 | SubStream conv_17_2_mbox_priorbox(conv_17); |
| 388 | conv_17_2_mbox_priorbox << PriorBoxLayer(SubStream(graph), |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 389 | PriorBoxLayerInfo({285.f}, priorbox_variances, priorbox_offset, true, |
| 390 | false, {300.f}, priorbox_aspect_ratios)) |
| 391 | .set_name("conv17/priorbox"); |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 392 | |
| 393 | SubStream mbox_priorbox(graph); |
| 394 | |
| 395 | mbox_priorbox << ConcatLayer( |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 396 | (common_params.data_layout == DataLayout::NCHW) |
| 397 | ? arm_compute::graph::descriptors::ConcatLayerDescriptor(DataLayoutDimension::WIDTH) |
| 398 | : arm_compute::graph::descriptors::ConcatLayerDescriptor(DataLayoutDimension::CHANNEL), |
| 399 | std::move(conv_11_mbox_priorbox), std::move(conv_13_mbox_priorbox), std::move(conv_14_2_mbox_priorbox), |
| 400 | std::move(conv_15_2_mbox_priorbox), std::move(conv_16_2_mbox_priorbox), std::move(conv_17_2_mbox_priorbox)); |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 401 | |
Isabella Gottardi | 7234ed8 | 2018-11-27 08:51:10 +0000 | [diff] [blame] | 402 | const int num_classes = 21; |
| 403 | const bool share_location = true; |
| 404 | const DetectionOutputLayerCodeType detection_type = DetectionOutputLayerCodeType::CENTER_SIZE; |
| 405 | const int keep_top_k = keep_topk_opt->value(); |
| 406 | const float nms_threshold = 0.45f; |
| 407 | const int label_id_background = 0; |
| 408 | const float conf_thrs = 0.25f; |
| 409 | const int top_k = 100; |
| 410 | |
| 411 | SubStream detection_ouput(mbox_loc); |
| 412 | detection_ouput << DetectionOutputLayer(std::move(mbox_conf), std::move(mbox_priorbox), |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 413 | DetectionOutputLayerInfo(num_classes, share_location, detection_type, |
| 414 | keep_top_k, nms_threshold, top_k, |
| 415 | label_id_background, conf_thrs)); |
| 416 | detection_ouput << OutputLayer(get_detection_output_accessor(common_params, {input_descriptor.shape})); |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 417 | } |
| 418 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 419 | ConcatLayer get_node_A_qasymm(IStream &main_graph, |
| 420 | const std::string &data_path, |
| 421 | std::string &¶m_path, |
| 422 | unsigned int conv_filt, |
| 423 | PadStrideInfo dwc_pad_stride_info, |
| 424 | PadStrideInfo conv_pad_stride_info, |
| 425 | std::pair<QuantizationInfo, QuantizationInfo> depth_quant_info, |
| 426 | std::pair<QuantizationInfo, QuantizationInfo> point_quant_info) |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 427 | { |
| 428 | const std::string total_path = param_path + "_"; |
ramelg01 | b4cd2dc | 2022-03-30 18:42:23 +0100 | [diff] [blame] | 429 | SubStream sg(main_graph); |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 430 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 431 | sg << DepthwiseConvolutionLayer(3U, 3U, get_weights_accessor(data_path, total_path + "dw_w.npy"), |
| 432 | get_weights_accessor(data_path, total_path + "dw_b.npy"), dwc_pad_stride_info, |
| 433 | 1, depth_quant_info.first, depth_quant_info.second) |
| 434 | .set_name(param_path + "/dw") |
| 435 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 6.f)) |
| 436 | .set_name(param_path + "/dw/relu6"); |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 437 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 438 | sg << ConvolutionLayer(1U, 1U, conv_filt, get_weights_accessor(data_path, total_path + "w.npy"), |
| 439 | get_weights_accessor(data_path, total_path + "b.npy"), conv_pad_stride_info, 1, |
| 440 | point_quant_info.first, point_quant_info.second) |
| 441 | .set_name(param_path + "/pw") |
| 442 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 6.f)) |
| 443 | .set_name(param_path + "/pw/relu6"); |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 444 | |
| 445 | return ConcatLayer(std::move(sg)); |
| 446 | } |
| 447 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 448 | ConcatLayer get_node_B_qasymm(IStream &main_graph, |
| 449 | const std::string &data_path, |
| 450 | std::string &¶m_path, |
| 451 | unsigned int conv_filt, |
| 452 | PadStrideInfo conv_pad_stride_info_1x1, |
| 453 | PadStrideInfo conv_pad_stride_info_3x3, |
| 454 | const std::pair<QuantizationInfo, QuantizationInfo> quant_info_1x1, |
| 455 | const std::pair<QuantizationInfo, QuantizationInfo> quant_info_3x3) |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 456 | { |
| 457 | const std::string total_path = param_path + "_"; |
ramelg01 | b4cd2dc | 2022-03-30 18:42:23 +0100 | [diff] [blame] | 458 | SubStream sg(main_graph); |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 459 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 460 | sg << ConvolutionLayer(1, 1, conv_filt / 2, get_weights_accessor(data_path, total_path + "1x1_w.npy"), |
| 461 | get_weights_accessor(data_path, total_path + "1x1_b.npy"), conv_pad_stride_info_1x1, 1, |
| 462 | quant_info_1x1.first, quant_info_1x1.second) |
| 463 | .set_name(total_path + "1x1/conv") |
| 464 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 6.f)) |
| 465 | .set_name(total_path + "1x1/conv/relu6"); |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 466 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 467 | sg << ConvolutionLayer(3, 3, conv_filt, get_weights_accessor(data_path, total_path + "3x3_w.npy"), |
| 468 | get_weights_accessor(data_path, total_path + "3x3_b.npy"), conv_pad_stride_info_3x3, 1, |
| 469 | quant_info_3x3.first, quant_info_3x3.second) |
| 470 | .set_name(total_path + "3x3/conv") |
| 471 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 6.f)) |
| 472 | .set_name(total_path + "3x3/conv/relu6"); |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 473 | |
| 474 | return ConcatLayer(std::move(sg)); |
| 475 | } |
| 476 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 477 | ConcatLayer get_node_C_qasymm(IStream &main_graph, |
| 478 | const std::string &data_path, |
| 479 | std::string &¶m_path, |
| 480 | unsigned int conv_filt, |
| 481 | PadStrideInfo conv_pad_stride_info, |
| 482 | const std::pair<QuantizationInfo, QuantizationInfo> quant_info, |
| 483 | TensorShape reshape_shape) |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 484 | { |
| 485 | const std::string total_path = param_path + "_"; |
ramelg01 | b4cd2dc | 2022-03-30 18:42:23 +0100 | [diff] [blame] | 486 | SubStream sg(main_graph); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 487 | sg << ConvolutionLayer(1U, 1U, conv_filt, get_weights_accessor(data_path, total_path + "w.npy"), |
| 488 | get_weights_accessor(data_path, total_path + "b.npy"), conv_pad_stride_info, 1, |
| 489 | quant_info.first, quant_info.second) |
| 490 | .set_name(param_path + "/conv"); |
| 491 | if (common_params.data_layout == DataLayout::NCHW) |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 492 | { |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 493 | sg << PermuteLayer(PermutationVector(2U, 0U, 1U), DataLayout::NHWC); |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 494 | } |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 495 | sg << ReshapeLayer(reshape_shape).set_name(param_path + "/reshape"); |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 496 | |
| 497 | return ConcatLayer(std::move(sg)); |
| 498 | } |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 499 | |
| 500 | void create_graph_qasymm(TensorDescriptor &input_descriptor) |
| 501 | { |
| 502 | // Get trainable parameters data path |
| 503 | std::string data_path = common_params.data_path; |
| 504 | |
| 505 | // Add model path to data path |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 506 | if (!data_path.empty()) |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 507 | { |
| 508 | data_path += "/cnn_data/ssd_mobilenet_qasymm8_model/"; |
| 509 | } |
| 510 | |
| 511 | // Quantization info are saved as pair for each (pointwise/depthwise) convolution layer: <weight_quant_info, output_quant_info> |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 512 | const std::vector<std::pair<QuantizationInfo, QuantizationInfo>> conv_quant_info = { |
| 513 | {QuantizationInfo(0.03624850884079933f, 163), QuantizationInfo(0.22219789028167725f, 113)}, // conv0 |
| 514 | {QuantizationInfo(0.0028752065263688564f, 113), |
| 515 | QuantizationInfo(0.05433657020330429f, 128)}, // conv13_2_1_1 |
| 516 | {QuantizationInfo(0.0014862528769299388f, 125), |
| 517 | QuantizationInfo(0.05037643015384674f, 131)}, // conv13_2_3_3 |
| 518 | {QuantizationInfo(0.00233650766313076f, 113), QuantizationInfo(0.04468846693634987f, 126)}, // conv13_3_1_1 |
| 519 | {QuantizationInfo(0.002501056529581547f, 120), QuantizationInfo(0.06026708707213402f, 111)}, // conv13_3_3_3 |
| 520 | {QuantizationInfo(0.002896666992455721f, 121), |
| 521 | QuantizationInfo(0.037775348871946335f, 117)}, // conv13_4_1_1 |
| 522 | {QuantizationInfo(0.0023875406477600336f, 122), |
| 523 | QuantizationInfo(0.03881589323282242f, 108)}, // conv13_4_3_3 |
| 524 | {QuantizationInfo(0.0022081052884459496f, 77), |
| 525 | QuantizationInfo(0.025450613349676132f, 125)}, // conv13_5_1_1 |
| 526 | {QuantizationInfo(0.00604657270014286f, 121), QuantizationInfo(0.033533502370119095f, 109)} // conv13_5_3_3 |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 527 | }; |
| 528 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 529 | const std::vector<std::pair<QuantizationInfo, QuantizationInfo>> depth_quant_info = { |
| 530 | {QuantizationInfo(0.03408717364072f, 131), QuantizationInfo(0.29286590218544006f, 108)}, // dwsc1 |
| 531 | {QuantizationInfo(0.027518004179000854f, 107), QuantizationInfo(0.20796941220760345, 117)}, // dwsc2 |
| 532 | {QuantizationInfo(0.052489638328552246f, 85), QuantizationInfo(0.4303881824016571f, 142)}, // dwsc3 |
| 533 | {QuantizationInfo(0.016570359468460083f, 79), QuantizationInfo(0.10512150079011917f, 116)}, // dwsc4 |
| 534 | {QuantizationInfo(0.060739465057849884f, 65), QuantizationInfo(0.15331414341926575f, 94)}, // dwsc5 |
| 535 | {QuantizationInfo(0.01324534136801958f, 124), QuantizationInfo(0.13010895252227783f, 153)}, // dwsc6 |
| 536 | {QuantizationInfo(0.032326459884643555f, 124), QuantizationInfo(0.11565316468477249, 156)}, // dwsc7 |
| 537 | {QuantizationInfo(0.029948478564620018f, 155), QuantizationInfo(0.11413891613483429f, 146)}, // dwsc8 |
| 538 | {QuantizationInfo(0.028054025024175644f, 129), QuantizationInfo(0.1142905130982399f, 140)}, // dwsc9 |
| 539 | {QuantizationInfo(0.025204822421073914f, 129), QuantizationInfo(0.14668069779872894f, 149)}, // dwsc10 |
| 540 | {QuantizationInfo(0.019332280382514f, 110), QuantizationInfo(0.1480235457420349f, 91)}, // dwsc11 |
| 541 | {QuantizationInfo(0.0319712869822979f, 88), QuantizationInfo(0.10424695909023285f, 117)}, // dwsc12 |
| 542 | {QuantizationInfo(0.04378943517804146f, 164), QuantizationInfo(0.23176774382591248f, 138)} // dwsc13 |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 543 | }; |
| 544 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 545 | const std::vector<std::pair<QuantizationInfo, QuantizationInfo>> point_quant_info = { |
| 546 | {QuantizationInfo(0.028777318075299263f, 144), QuantizationInfo(0.2663874328136444f, 121)}, // pw1 |
| 547 | {QuantizationInfo(0.015796702355146408f, 127), QuantizationInfo(0.1739964485168457f, 111)}, // pw2 |
| 548 | {QuantizationInfo(0.009349990636110306f, 127), QuantizationInfo(0.1805974692106247f, 104)}, // pw3 |
| 549 | {QuantizationInfo(0.012920888140797615f, 106), QuantizationInfo(0.1205204650759697f, 100)}, // pw4 |
| 550 | {QuantizationInfo(0.008119508624076843f, 145), QuantizationInfo(0.12272439152002335f, 97)}, // pw5 |
| 551 | {QuantizationInfo(0.0070041813887655735f, 115), QuantizationInfo(0.0947074219584465f, 101)}, // pw6 |
| 552 | {QuantizationInfo(0.004827278666198254f, 115), QuantizationInfo(0.0842885747551918f, 110)}, // pw7 |
| 553 | {QuantizationInfo(0.004755120258778334f, 128), QuantizationInfo(0.08283159881830215f, 116)}, // pw8 |
| 554 | {QuantizationInfo(0.007527193054556847f, 142), QuantizationInfo(0.12555131316184998f, 137)}, // pw9 |
| 555 | {QuantizationInfo(0.006050156895071268f, 109), QuantizationInfo(0.10871313512325287f, 124)}, // pw10 |
| 556 | {QuantizationInfo(0.00490700313821435f, 127), QuantizationInfo(0.10364262014627457f, 140)}, // pw11 |
| 557 | {QuantizationInfo(0.006063731852918863, 124), QuantizationInfo(0.11241862177848816f, 125)}, // pw12 |
| 558 | {QuantizationInfo(0.007901716977357864f, 139), QuantizationInfo(0.49889302253723145f, 141)} // pw13 |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 559 | }; |
| 560 | |
| 561 | // Quantization info taken from the TfLite SSD MobileNet example |
| 562 | const QuantizationInfo in_quant_info = QuantizationInfo(0.0078125f, 128); |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 563 | // Create core graph |
| 564 | graph << InputLayer(input_descriptor.set_quantization_info(in_quant_info), |
| 565 | get_weights_accessor(data_path, common_params.image, DataLayout::NHWC)); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 566 | graph << ConvolutionLayer(3U, 3U, 32U, get_weights_accessor(data_path, "conv0_w.npy"), |
| 567 | get_weights_accessor(data_path, "conv0_b.npy"), |
| 568 | PadStrideInfo(2U, 2U, 0U, 1U, 0U, 1U, DimensionRoundingType::CEIL), 1, |
| 569 | conv_quant_info.at(0).first, conv_quant_info.at(0).second) |
| 570 | .set_name("conv0"); |
| 571 | graph << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 6.f)) |
| 572 | .set_name("conv0/relu"); |
| 573 | graph << get_node_A_qasymm(graph, data_path, "conv1", 64U, |
| 574 | PadStrideInfo(1U, 1U, 1U, 1U, 1U, 1U, DimensionRoundingType::CEIL), |
| 575 | PadStrideInfo(1U, 1U, 0U, 0U), depth_quant_info.at(0), point_quant_info.at(0)); |
| 576 | graph << get_node_A_qasymm(graph, data_path, "conv2", 128U, |
| 577 | PadStrideInfo(2U, 2U, 0U, 1U, 0U, 1U, DimensionRoundingType::CEIL), |
| 578 | PadStrideInfo(1U, 1U, 0U, 0U), depth_quant_info.at(1), point_quant_info.at(1)); |
| 579 | graph << get_node_A_qasymm(graph, data_path, "conv3", 128U, |
| 580 | PadStrideInfo(1U, 1U, 1U, 1U, 1U, 1U, DimensionRoundingType::CEIL), |
| 581 | PadStrideInfo(1U, 1U, 0U, 0U), depth_quant_info.at(2), point_quant_info.at(2)); |
| 582 | graph << get_node_A_qasymm(graph, data_path, "conv4", 256U, |
| 583 | PadStrideInfo(2U, 2U, 1U, 1U, 1U, 1U, DimensionRoundingType::CEIL), |
| 584 | PadStrideInfo(1U, 1U, 0U, 0U), depth_quant_info.at(3), point_quant_info.at(3)); |
| 585 | graph << get_node_A_qasymm(graph, data_path, "conv5", 256U, |
| 586 | PadStrideInfo(1U, 1U, 1U, 1U, 1U, 1U, DimensionRoundingType::CEIL), |
| 587 | PadStrideInfo(1U, 1U, 0U, 0U), depth_quant_info.at(4), point_quant_info.at(4)); |
| 588 | graph << get_node_A_qasymm(graph, data_path, "conv6", 512U, |
| 589 | PadStrideInfo(2U, 2U, 0U, 1U, 0U, 1U, DimensionRoundingType::CEIL), |
| 590 | PadStrideInfo(1U, 1U, 0U, 0U), depth_quant_info.at(5), point_quant_info.at(5)); |
| 591 | graph << get_node_A_qasymm(graph, data_path, "conv7", 512U, |
| 592 | PadStrideInfo(1U, 1U, 1U, 1U, 1U, 1U, DimensionRoundingType::CEIL), |
| 593 | PadStrideInfo(1U, 1U, 0U, 0U), depth_quant_info.at(6), point_quant_info.at(6)); |
| 594 | graph << get_node_A_qasymm(graph, data_path, "conv8", 512U, |
| 595 | PadStrideInfo(1U, 1U, 1U, 1U, 1U, 1U, DimensionRoundingType::CEIL), |
| 596 | PadStrideInfo(1U, 1U, 0U, 0U), depth_quant_info.at(7), point_quant_info.at(7)); |
| 597 | graph << get_node_A_qasymm(graph, data_path, "conv9", 512U, |
| 598 | PadStrideInfo(1U, 1U, 1U, 1U, 1U, 1U, DimensionRoundingType::CEIL), |
| 599 | PadStrideInfo(1U, 1U, 0U, 0U), depth_quant_info.at(8), point_quant_info.at(8)); |
| 600 | graph << get_node_A_qasymm(graph, data_path, "conv10", 512U, |
| 601 | PadStrideInfo(1U, 1U, 1U, 1U, 1U, 1U, DimensionRoundingType::CEIL), |
| 602 | PadStrideInfo(1U, 1U, 0U, 0U), depth_quant_info.at(9), point_quant_info.at(9)); |
| 603 | graph << get_node_A_qasymm(graph, data_path, "conv11", 512U, |
| 604 | PadStrideInfo(1U, 1U, 1U, 1U, 1U, 1U, DimensionRoundingType::CEIL), |
| 605 | PadStrideInfo(1U, 1U, 0U, 0U), depth_quant_info.at(10), point_quant_info.at(10)); |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 606 | |
| 607 | SubStream conv_13(graph); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 608 | conv_13 << get_node_A_qasymm(graph, data_path, "conv12", 1024U, |
| 609 | PadStrideInfo(2U, 2U, 1U, 1U, 1U, 1U, DimensionRoundingType::CEIL), |
| 610 | PadStrideInfo(1U, 1U, 0U, 0U), depth_quant_info.at(11), point_quant_info.at(11)); |
| 611 | conv_13 << get_node_A_qasymm(conv_13, data_path, "conv13", 1024U, |
| 612 | PadStrideInfo(1U, 1U, 1U, 1U, 1U, 1U, DimensionRoundingType::CEIL), |
| 613 | PadStrideInfo(1U, 1U, 0U, 0U), depth_quant_info.at(12), point_quant_info.at(12)); |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 614 | SubStream conv_14(conv_13); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 615 | conv_14 << get_node_B_qasymm(conv_13, data_path, "conv13_2", 512U, PadStrideInfo(1U, 1U, 0U, 0U), |
| 616 | PadStrideInfo(2U, 2U, 0U, 1U, 0U, 1U, DimensionRoundingType::CEIL), |
| 617 | conv_quant_info.at(1), conv_quant_info.at(2)); |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 618 | SubStream conv_15(conv_14); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 619 | conv_15 << get_node_B_qasymm(conv_14, data_path, "conv13_3", 256U, PadStrideInfo(1U, 1U, 0U, 0U), |
| 620 | PadStrideInfo(2U, 2U, 1U, 1U, 1U, 1U, DimensionRoundingType::CEIL), |
| 621 | conv_quant_info.at(3), conv_quant_info.at(4)); |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 622 | SubStream conv_16(conv_15); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 623 | conv_16 << get_node_B_qasymm(conv_15, data_path, "conv13_4", 256U, PadStrideInfo(1U, 1U, 0U, 0U), |
| 624 | PadStrideInfo(2U, 2U, 1U, 1U, 1U, 1U, DimensionRoundingType::CEIL), |
| 625 | conv_quant_info.at(5), conv_quant_info.at(6)); |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 626 | SubStream conv_17(conv_16); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 627 | conv_17 << get_node_B_qasymm(conv_16, data_path, "conv13_5", 128U, PadStrideInfo(1U, 1U, 0U, 0U), |
| 628 | PadStrideInfo(2U, 2U, 0U, 1U, 0U, 1U, DimensionRoundingType::CEIL), |
| 629 | conv_quant_info.at(7), conv_quant_info.at(8)); |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 630 | |
| 631 | // box_predictor |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 632 | const std::vector<std::pair<QuantizationInfo, QuantizationInfo>> box_enc_pred_quant_info = { |
| 633 | {QuantizationInfo(0.005202020984143019f, 136), |
| 634 | QuantizationInfo(0.08655580133199692f, 183)}, // boxpredictor0_bep |
| 635 | {QuantizationInfo(0.003121797926723957f, 132), |
| 636 | QuantizationInfo(0.03218776360154152f, 140)}, // boxpredictor1_bep |
| 637 | {QuantizationInfo(0.002995674265548587f, 130), |
| 638 | QuantizationInfo(0.029072262346744537f, 125)}, // boxpredictor2_bep |
| 639 | {QuantizationInfo(0.0023131705820560455f, 130), |
| 640 | QuantizationInfo(0.026488754898309708f, 127)}, // boxpredictor3_bep |
| 641 | {QuantizationInfo(0.0013905081432312727f, 132), |
| 642 | QuantizationInfo(0.0199890099465847f, 137)}, // boxpredictor4_bep |
| 643 | {QuantizationInfo(0.00216794665902853f, 121), |
| 644 | QuantizationInfo(0.019798893481492996f, 151)} // boxpredictor5_bep |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 645 | }; |
| 646 | |
| 647 | const std::vector<TensorShape> box_reshape = // NHWC |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 648 | { |
| 649 | TensorShape(4U, 1U, 1083U), // boxpredictor0_bep_reshape |
| 650 | TensorShape(4U, 1U, 600U), // boxpredictor1_bep_reshape |
| 651 | TensorShape(4U, 1U, 150U), // boxpredictor2_bep_reshape |
| 652 | TensorShape(4U, 1U, 54U), // boxpredictor3_bep_reshape |
| 653 | TensorShape(4U, 1U, 24U), // boxpredictor4_bep_reshape |
| 654 | TensorShape(4U, 1U, 6U) // boxpredictor5_bep_reshape |
| 655 | }; |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 656 | |
| 657 | SubStream conv_11_box_enc_pre(graph); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 658 | conv_11_box_enc_pre << get_node_C_qasymm(graph, data_path, "BoxPredictor_0_BEP", 12U, |
| 659 | PadStrideInfo(1U, 1U, 0U, 0U), box_enc_pred_quant_info.at(0), |
| 660 | box_reshape.at(0)); |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 661 | |
| 662 | SubStream conv_13_box_enc_pre(conv_13); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 663 | conv_13_box_enc_pre << get_node_C_qasymm(conv_13, data_path, "BoxPredictor_1_BEP", 24U, |
| 664 | PadStrideInfo(1U, 1U, 0U, 0U), box_enc_pred_quant_info.at(1), |
| 665 | box_reshape.at(1)); |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 666 | |
| 667 | SubStream conv_14_2_box_enc_pre(conv_14); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 668 | conv_14_2_box_enc_pre << get_node_C_qasymm(conv_14, data_path, "BoxPredictor_2_BEP", 24U, |
| 669 | PadStrideInfo(1U, 1U, 0U, 0U), box_enc_pred_quant_info.at(2), |
| 670 | box_reshape.at(2)); |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 671 | |
| 672 | SubStream conv_15_2_box_enc_pre(conv_15); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 673 | conv_15_2_box_enc_pre << get_node_C_qasymm(conv_15, data_path, "BoxPredictor_3_BEP", 24U, |
| 674 | PadStrideInfo(1U, 1U, 0U, 0U), box_enc_pred_quant_info.at(3), |
| 675 | box_reshape.at(3)); |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 676 | |
| 677 | SubStream conv_16_2_box_enc_pre(conv_16); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 678 | conv_16_2_box_enc_pre << get_node_C_qasymm(conv_16, data_path, "BoxPredictor_4_BEP", 24U, |
| 679 | PadStrideInfo(1U, 1U, 0U, 0U), box_enc_pred_quant_info.at(4), |
| 680 | box_reshape.at(4)); |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 681 | |
| 682 | SubStream conv_17_2_box_enc_pre(conv_17); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 683 | conv_17_2_box_enc_pre << get_node_C_qasymm(conv_17, data_path, "BoxPredictor_5_BEP", 24U, |
| 684 | PadStrideInfo(1U, 1U, 0U, 0U), box_enc_pred_quant_info.at(5), |
| 685 | box_reshape.at(5)); |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 686 | |
| 687 | SubStream box_enc_pre(graph); |
| 688 | const QuantizationInfo bep_concate_qinfo = QuantizationInfo(0.08655580133199692f, 183); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 689 | box_enc_pre << ConcatLayer(arm_compute::graph::descriptors::ConcatLayerDescriptor(DataLayoutDimension::HEIGHT, |
| 690 | bep_concate_qinfo), |
| 691 | std::move(conv_11_box_enc_pre), std::move(conv_13_box_enc_pre), |
| 692 | conv_14_2_box_enc_pre, std::move(conv_15_2_box_enc_pre), |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 693 | std::move(conv_16_2_box_enc_pre), std::move(conv_17_2_box_enc_pre)) |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 694 | .set_name("BoxPredictor/concat"); |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 695 | box_enc_pre << ReshapeLayer(TensorShape(4U, 1917U)).set_name("BoxPredictor/reshape"); |
| 696 | |
| 697 | // class_predictor |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 698 | const std::vector<std::pair<QuantizationInfo, QuantizationInfo>> class_pred_quant_info = { |
| 699 | {QuantizationInfo(0.002744135679677129f, 125), |
| 700 | QuantizationInfo(0.05746262148022652f, 234)}, // boxpredictor0_cp |
| 701 | {QuantizationInfo(0.0024326108396053314f, 80), |
| 702 | QuantizationInfo(0.03764628246426582f, 217)}, // boxpredictor1_cp |
| 703 | {QuantizationInfo(0.0013898586621508002f, 141), |
| 704 | QuantizationInfo(0.034081317484378815f, 214)}, // boxpredictor2_cp |
| 705 | {QuantizationInfo(0.0014176908880472183f, 133), |
| 706 | QuantizationInfo(0.033889178186655045f, 215)}, // boxpredictor3_cp |
| 707 | {QuantizationInfo(0.001090311910957098f, 125), |
| 708 | QuantizationInfo(0.02646234817802906f, 230)}, // boxpredictor4_cp |
| 709 | {QuantizationInfo(0.001134163816459477f, 115), |
| 710 | QuantizationInfo(0.026926767081022263f, 218)} // boxpredictor5_cp |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 711 | }; |
| 712 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 713 | const std::vector<TensorShape> class_reshape = { |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 714 | TensorShape(91U, 1083U), // boxpredictor0_cp_reshape |
| 715 | TensorShape(91U, 600U), // boxpredictor1_cp_reshape |
| 716 | TensorShape(91U, 150U), // boxpredictor2_cp_reshape |
| 717 | TensorShape(91U, 54U), // boxpredictor3_cp_reshape |
| 718 | TensorShape(91U, 24U), // boxpredictor4_cp_reshape |
| 719 | TensorShape(91U, 6U) // boxpredictor5_cp_reshape |
| 720 | }; |
| 721 | |
| 722 | SubStream conv_11_class_pre(graph); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 723 | conv_11_class_pre << get_node_C_qasymm(graph, data_path, "BoxPredictor_0_CP", 273U, |
| 724 | PadStrideInfo(1U, 1U, 0U, 0U), class_pred_quant_info.at(0), |
| 725 | class_reshape.at(0)); |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 726 | |
| 727 | SubStream conv_13_class_pre(conv_13); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 728 | conv_13_class_pre << get_node_C_qasymm(conv_13, data_path, "BoxPredictor_1_CP", 546U, |
| 729 | PadStrideInfo(1U, 1U, 0U, 0U), class_pred_quant_info.at(1), |
| 730 | class_reshape.at(1)); |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 731 | |
| 732 | SubStream conv_14_2_class_pre(conv_14); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 733 | conv_14_2_class_pre << get_node_C_qasymm(conv_14, data_path, "BoxPredictor_2_CP", 546U, |
| 734 | PadStrideInfo(1U, 1U, 0U, 0U), class_pred_quant_info.at(2), |
| 735 | class_reshape.at(2)); |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 736 | |
| 737 | SubStream conv_15_2_class_pre(conv_15); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 738 | conv_15_2_class_pre << get_node_C_qasymm(conv_15, data_path, "BoxPredictor_3_CP", 546U, |
| 739 | PadStrideInfo(1U, 1U, 0U, 0U), class_pred_quant_info.at(3), |
| 740 | class_reshape.at(3)); |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 741 | |
| 742 | SubStream conv_16_2_class_pre(conv_16); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 743 | conv_16_2_class_pre << get_node_C_qasymm(conv_16, data_path, "BoxPredictor_4_CP", 546U, |
| 744 | PadStrideInfo(1U, 1U, 0U, 0U), class_pred_quant_info.at(4), |
| 745 | class_reshape.at(4)); |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 746 | |
| 747 | SubStream conv_17_2_class_pre(conv_17); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 748 | conv_17_2_class_pre << get_node_C_qasymm(conv_17, data_path, "BoxPredictor_5_CP", 546U, |
| 749 | PadStrideInfo(1U, 1U, 0U, 0U), class_pred_quant_info.at(5), |
| 750 | class_reshape.at(5)); |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 751 | |
| 752 | const QuantizationInfo cp_concate_qinfo = QuantizationInfo(0.0584389753639698f, 230); |
| 753 | SubStream class_pred(graph); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 754 | class_pred << ConcatLayer(arm_compute::graph::descriptors::ConcatLayerDescriptor(DataLayoutDimension::WIDTH, |
| 755 | cp_concate_qinfo), |
| 756 | std::move(conv_11_class_pre), std::move(conv_13_class_pre), |
| 757 | std::move(conv_14_2_class_pre), std::move(conv_15_2_class_pre), |
| 758 | std::move(conv_16_2_class_pre), std::move(conv_17_2_class_pre)) |
| 759 | .set_name("ClassPrediction/concat"); |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 760 | |
SiCong Li | a4a2354 | 2023-12-06 17:24:20 +0000 | [diff] [blame] | 761 | const QuantizationInfo logistic_out_qinfo = QuantizationInfo( |
| 762 | 0.00390625f, quantization::get_min_max_values_from_quantized_data_type(common_params.data_type).first); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 763 | class_pred << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC), |
| 764 | logistic_out_qinfo) |
| 765 | .set_name("ClassPrediction/logistic"); |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 766 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 767 | const int max_detections = 10; |
| 768 | const int max_classes_per_detection = 1; |
| 769 | const float nms_score_threshold = 0.30000001192092896f; |
| 770 | const float nms_iou_threshold = 0.6000000238418579f; |
| 771 | const int num_classes = 90; |
| 772 | const float x_scale = 10.f; |
| 773 | const float y_scale = 10.f; |
| 774 | const float h_scale = 5.f; |
| 775 | const float w_scale = 5.f; |
| 776 | std::array<float, 4> scales = {y_scale, x_scale, w_scale, h_scale}; |
| 777 | const QuantizationInfo anchors_qinfo = QuantizationInfo(0.006453060545027256f, 0); |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 778 | |
| 779 | SubStream detection_ouput(box_enc_pre); |
| 780 | detection_ouput << DetectionPostProcessLayer(std::move(class_pred), |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 781 | DetectionPostProcessLayerInfo( |
| 782 | max_detections, max_classes_per_detection, nms_score_threshold, |
| 783 | nms_iou_threshold, num_classes, scales), |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 784 | get_weights_accessor(data_path, "anchors.npy"), anchors_qinfo) |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 785 | .set_name("DetectionPostProcess"); |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 786 | |
| 787 | SubStream ouput_0(detection_ouput); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 788 | ouput_0 << OutputLayer( |
| 789 | get_npy_output_accessor(detection_boxes_opt->value(), TensorShape(4U, 10U), DataType::F32), 0); |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 790 | |
| 791 | SubStream ouput_1(detection_ouput); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 792 | ouput_1 << OutputLayer(get_npy_output_accessor(detection_classes_opt->value(), TensorShape(10U), DataType::F32), |
| 793 | 1); |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 794 | |
| 795 | SubStream ouput_2(detection_ouput); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 796 | ouput_2 << OutputLayer(get_npy_output_accessor(detection_scores_opt->value(), TensorShape(10U), DataType::F32), |
| 797 | 2); |
Isabella Gottardi | c755f78 | 2019-07-22 17:40:27 +0100 | [diff] [blame] | 798 | |
| 799 | SubStream ouput_3(detection_ouput); |
| 800 | ouput_3 << OutputLayer(get_npy_output_accessor(num_detections_opt->value(), TensorShape(1U), DataType::F32), 3); |
| 801 | } |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 802 | }; |
| 803 | |
| 804 | /** Main program for MobileNetSSD |
| 805 | * |
| 806 | * Model is based on: |
| 807 | * http://arxiv.org/abs/1512.02325 |
| 808 | * SSD: Single Shot MultiBox Detector |
| 809 | * Wei Liu, Dragomir Anguelov, Dumitru Erhan, Christian Szegedy, Scott Reed, Cheng-Yang Fu, Alexander C. Berg |
| 810 | * |
Georgios Pinitas | 588ebc5 | 2018-12-21 13:39:07 +0000 | [diff] [blame] | 811 | * Provenance: https://github.com/chuanqi305/MobileNet-SSD |
| 812 | * |
Pablo Tello | fea8ec3 | 2018-11-16 13:25:30 +0000 | [diff] [blame] | 813 | * @note To list all the possible arguments execute the binary appended with the --help option |
| 814 | * |
| 815 | * @param[in] argc Number of arguments |
| 816 | * @param[in] argv Arguments |
| 817 | */ |
| 818 | int main(int argc, char **argv) |
| 819 | { |
| 820 | return arm_compute::utils::run_example<GraphSSDMobilenetExample>(argc, argv); |
| 821 | } |