Michalis Spyrou | 177a9a5 | 2018-09-06 15:10:22 +0100 | [diff] [blame] | 1 | /* |
SiCong Li | 4841c97 | 2021-02-03 12:17:35 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2021 Arm Limited. |
Michalis Spyrou | 177a9a5 | 2018-09-06 15:10:22 +0100 | [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 | */ |
| 24 | #include "arm_compute/graph.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 25 | |
Michalis Spyrou | 177a9a5 | 2018-09-06 15:10:22 +0100 | [diff] [blame] | 26 | #include "support/ToolchainSupport.h" |
| 27 | #include "utils/CommonGraphOptions.h" |
| 28 | #include "utils/GraphUtils.h" |
| 29 | #include "utils/Utils.h" |
| 30 | |
| 31 | using namespace arm_compute::utils; |
| 32 | using namespace arm_compute::graph::frontend; |
| 33 | using namespace arm_compute::graph_utils; |
| 34 | |
Georgios Pinitas | 108ab0b | 2018-09-14 18:35:11 +0100 | [diff] [blame] | 35 | /** Example demonstrating how to implement YOLOv3 network using the Compute Library's graph API */ |
Michalis Spyrou | 177a9a5 | 2018-09-06 15:10:22 +0100 | [diff] [blame] | 36 | class GraphYOLOv3Example : public Example |
| 37 | { |
| 38 | public: |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 39 | GraphYOLOv3Example() : cmd_parser(), common_opts(cmd_parser), common_params(), graph(0, "YOLOv3") |
Michalis Spyrou | 177a9a5 | 2018-09-06 15:10:22 +0100 | [diff] [blame] | 40 | { |
| 41 | } |
Michalis Spyrou | e22aa13 | 2018-09-13 10:35:33 +0100 | [diff] [blame] | 42 | |
Michalis Spyrou | 177a9a5 | 2018-09-06 15:10:22 +0100 | [diff] [blame] | 43 | bool do_setup(int argc, char **argv) override |
| 44 | { |
| 45 | // Parse arguments |
| 46 | cmd_parser.parse(argc, argv); |
Georgios Pinitas | cd60a5f | 2019-08-21 17:06:54 +0100 | [diff] [blame] | 47 | cmd_parser.validate(); |
Michalis Spyrou | 177a9a5 | 2018-09-06 15:10:22 +0100 | [diff] [blame] | 48 | |
| 49 | // Consume common parameters |
| 50 | common_params = consume_common_graph_parameters(common_opts); |
| 51 | |
| 52 | // Return when help menu is requested |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 53 | if (common_params.help) |
Michalis Spyrou | 177a9a5 | 2018-09-06 15:10:22 +0100 | [diff] [blame] | 54 | { |
| 55 | cmd_parser.print_help(argv[0]); |
| 56 | return false; |
| 57 | } |
| 58 | |
| 59 | // Checks |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 60 | ARM_COMPUTE_EXIT_ON_MSG(arm_compute::is_data_type_quantized_asymmetric(common_params.data_type), |
| 61 | "QASYMM8 not supported for this graph"); |
Michalis Spyrou | 177a9a5 | 2018-09-06 15:10:22 +0100 | [diff] [blame] | 62 | |
| 63 | // Print parameter values |
| 64 | std::cout << common_params << std::endl; |
| 65 | |
| 66 | // Get trainable parameters data path |
| 67 | std::string data_path = common_params.data_path; |
| 68 | |
| 69 | // Create a preprocessor object |
Georgios Pinitas | 40f51a6 | 2020-11-21 03:04:18 +0000 | [diff] [blame] | 70 | std::unique_ptr<IPreprocessor> preprocessor = std::make_unique<TFPreproccessor>(0.f); |
Michalis Spyrou | 177a9a5 | 2018-09-06 15:10:22 +0100 | [diff] [blame] | 71 | |
| 72 | // Create input descriptor |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 73 | const TensorShape tensor_shape = |
| 74 | permute_shape(TensorShape(608U, 608U, 3U, 1U), DataLayout::NCHW, common_params.data_layout); |
| 75 | TensorDescriptor input_descriptor = |
| 76 | TensorDescriptor(tensor_shape, common_params.data_type).set_layout(common_params.data_layout); |
Michalis Spyrou | 177a9a5 | 2018-09-06 15:10:22 +0100 | [diff] [blame] | 77 | |
| 78 | // Set weights trained layout |
| 79 | const DataLayout weights_layout = DataLayout::NCHW; |
| 80 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 81 | graph << common_params.target << common_params.fast_math_hint |
Michalis Spyrou | e22aa13 | 2018-09-13 10:35:33 +0100 | [diff] [blame] | 82 | << InputLayer(input_descriptor, get_input_accessor(common_params, std::move(preprocessor), false)); |
| 83 | std::pair<SubStream, SubStream> intermediate_layers = darknet53(data_path, weights_layout); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 84 | graph |
| 85 | << ConvolutionLayer( |
| 86 | 1U, 1U, 512U, |
| 87 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/conv2d_53_w.npy", weights_layout), |
| 88 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0)) |
| 89 | .set_name("conv2d_53") |
| 90 | << BatchNormalizationLayer( |
| 91 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_53_mean.npy"), |
| 92 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_53_var.npy"), |
| 93 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_53_gamma.npy"), |
| 94 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_53_beta.npy"), 0.000001f) |
| 95 | .set_name("conv2d_53/BatchNorm") |
| 96 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LEAKY_RELU, 0.1f)) |
| 97 | .set_name("conv2d_53/LeakyRelu") |
| 98 | << ConvolutionLayer( |
| 99 | 3U, 3U, 1024U, |
| 100 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/conv2d_54_w.npy", weights_layout), |
| 101 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 1, 1)) |
| 102 | .set_name("conv2d_54") |
| 103 | << BatchNormalizationLayer( |
| 104 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_54_mean.npy"), |
| 105 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_54_var.npy"), |
| 106 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_54_gamma.npy"), |
| 107 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_54_beta.npy"), 0.000001f) |
| 108 | .set_name("conv2d_54/BatchNorm") |
| 109 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LEAKY_RELU, 0.1f)) |
| 110 | .set_name("conv2d_54/LeakyRelu") |
| 111 | << ConvolutionLayer( |
| 112 | 1U, 1U, 512U, |
| 113 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/conv2d_55_w.npy", weights_layout), |
| 114 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0)) |
| 115 | .set_name("conv2d_55") |
| 116 | << BatchNormalizationLayer( |
| 117 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_55_mean.npy"), |
| 118 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_55_var.npy"), |
| 119 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_55_gamma.npy"), |
| 120 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_55_beta.npy"), 0.000001f) |
| 121 | .set_name("conv2d_55/BatchNorm") |
| 122 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LEAKY_RELU, 0.1f)) |
| 123 | .set_name("conv2d_55/LeakyRelu") |
| 124 | << ConvolutionLayer( |
| 125 | 3U, 3U, 1024U, |
| 126 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/conv2d_56_w.npy", weights_layout), |
| 127 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 1, 1)) |
| 128 | .set_name("conv2d_56") |
| 129 | << BatchNormalizationLayer( |
| 130 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_56_mean.npy"), |
| 131 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_56_var.npy"), |
| 132 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_56_gamma.npy"), |
| 133 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_56_beta.npy"), 0.000001f) |
| 134 | .set_name("conv2d_56/BatchNorm") |
| 135 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LEAKY_RELU, 0.1f)) |
| 136 | .set_name("conv2d_56/LeakyRelu") |
| 137 | << ConvolutionLayer( |
| 138 | 1U, 1U, 512U, |
| 139 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/conv2d_57_w.npy", weights_layout), |
| 140 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0)) |
| 141 | .set_name("conv2d_57") |
| 142 | << BatchNormalizationLayer( |
| 143 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_57_mean.npy"), |
| 144 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_57_var.npy"), |
| 145 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_57_gamma.npy"), |
| 146 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_57_beta.npy"), 0.000001f) |
| 147 | .set_name("conv2d_57/BatchNorm") |
| 148 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LEAKY_RELU, 0.1f)) |
| 149 | .set_name("conv2d_57/LeakyRelu"); |
Michalis Spyrou | e22aa13 | 2018-09-13 10:35:33 +0100 | [diff] [blame] | 150 | SubStream route_1(graph); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 151 | graph |
| 152 | << ConvolutionLayer( |
| 153 | 3U, 3U, 1024U, |
| 154 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/conv2d_58_w.npy", weights_layout), |
| 155 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 1, 1)) |
| 156 | .set_name("conv2d_58") |
| 157 | << BatchNormalizationLayer( |
| 158 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_58_mean.npy"), |
| 159 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_58_var.npy"), |
| 160 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_58_gamma.npy"), |
| 161 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_58_beta.npy"), 0.000001f) |
| 162 | .set_name("conv2d_58/BatchNorm") |
| 163 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LEAKY_RELU, 0.1f)) |
| 164 | .set_name("conv2d_58/LeakyRelu") |
| 165 | << ConvolutionLayer( |
| 166 | 1U, 1U, 255U, |
| 167 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/conv2d_59_w.npy", weights_layout), |
| 168 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/conv2d_59_b.npy", weights_layout), |
| 169 | PadStrideInfo(1, 1, 0, 0)) |
| 170 | .set_name("conv2d_59") |
| 171 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LINEAR, 1.f)) |
| 172 | .set_name("conv2d_59/Linear") |
| 173 | << YOLOLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC, 0.1f)).set_name("Yolo1") |
| 174 | << OutputLayer(get_output_accessor(common_params, 5)); |
Michalis Spyrou | e22aa13 | 2018-09-13 10:35:33 +0100 | [diff] [blame] | 175 | route_1 << ConvolutionLayer( |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 176 | 1U, 1U, 256U, |
| 177 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/conv2d_60_w.npy", weights_layout), |
| 178 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0)) |
| 179 | .set_name("conv2d_60") |
Michalis Spyrou | e22aa13 | 2018-09-13 10:35:33 +0100 | [diff] [blame] | 180 | << BatchNormalizationLayer( |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 181 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_59_mean.npy"), |
| 182 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_59_var.npy"), |
| 183 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_59_gamma.npy"), |
| 184 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_59_beta.npy"), |
| 185 | 0.000001f) |
| 186 | .set_name("conv2d_59/BatchNorm") |
| 187 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LEAKY_RELU, 0.1f)) |
| 188 | .set_name("conv2d_60/LeakyRelu") |
Georgios Pinitas | c53266e | 2020-12-09 03:11:53 +0000 | [diff] [blame] | 189 | << ResizeLayer(InterpolationPolicy::NEAREST_NEIGHBOR, 2, 2).set_name("Upsample_60"); |
Michalis Spyrou | e22aa13 | 2018-09-13 10:35:33 +0100 | [diff] [blame] | 190 | SubStream concat_1(route_1); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 191 | concat_1 |
| 192 | << ConcatLayer(std::move(route_1), std::move(intermediate_layers.second)).set_name("Route1") |
| 193 | << ConvolutionLayer( |
| 194 | 1U, 1U, 256U, |
| 195 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/conv2d_61_w.npy", weights_layout), |
| 196 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0)) |
| 197 | .set_name("conv2d_61") |
| 198 | << BatchNormalizationLayer( |
| 199 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_60_mean.npy"), |
| 200 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_60_var.npy"), |
| 201 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_60_gamma.npy"), |
| 202 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_60_beta.npy"), 0.000001f) |
| 203 | .set_name("conv2d_60/BatchNorm") |
| 204 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LEAKY_RELU, 0.1f)) |
| 205 | .set_name("conv2d_61/LeakyRelu") |
| 206 | << ConvolutionLayer( |
| 207 | 3U, 3U, 512U, |
| 208 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/conv2d_62_w.npy", weights_layout), |
| 209 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 1, 1)) |
| 210 | .set_name("conv2d_62") |
| 211 | << BatchNormalizationLayer( |
| 212 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_61_mean.npy"), |
| 213 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_61_var.npy"), |
| 214 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_61_gamma.npy"), |
| 215 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_61_beta.npy"), 0.000001f) |
| 216 | .set_name("conv2d_61/BatchNorm") |
| 217 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LEAKY_RELU, 0.1f)) |
| 218 | .set_name("conv2d_62/LeakyRelu") |
| 219 | << ConvolutionLayer( |
| 220 | 1U, 1U, 256U, |
| 221 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/conv2d_63_w.npy", weights_layout), |
| 222 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0)) |
| 223 | .set_name("conv2d_63") |
| 224 | << BatchNormalizationLayer( |
| 225 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_62_mean.npy"), |
| 226 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_62_var.npy"), |
| 227 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_62_gamma.npy"), |
| 228 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_62_beta.npy"), 0.000001f) |
| 229 | .set_name("conv2d_62/BatchNorm") |
| 230 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LEAKY_RELU, 0.1f)) |
| 231 | .set_name("conv2d_63/LeakyRelu") |
| 232 | << ConvolutionLayer( |
| 233 | 3U, 3U, 512U, |
| 234 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/conv2d_64_w.npy", weights_layout), |
| 235 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 1, 1)) |
| 236 | .set_name("conv2d_64") |
| 237 | << BatchNormalizationLayer( |
| 238 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_63_mean.npy"), |
| 239 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_63_var.npy"), |
| 240 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_63_gamma.npy"), |
| 241 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_63_beta.npy"), 0.000001f) |
| 242 | .set_name("conv2d_63/BatchNorm") |
| 243 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LEAKY_RELU, 0.1f)) |
| 244 | .set_name("conv2d_64/LeakyRelu") |
| 245 | << ConvolutionLayer( |
| 246 | 1U, 1U, 256U, |
| 247 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/conv2d_65_w.npy", weights_layout), |
| 248 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0)) |
| 249 | .set_name("conv2d_65") |
| 250 | << BatchNormalizationLayer( |
| 251 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_64_mean.npy"), |
| 252 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_64_var.npy"), |
| 253 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_64_gamma.npy"), |
| 254 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_64_beta.npy"), 0.000001f) |
| 255 | .set_name("conv2d_65/BatchNorm") |
| 256 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LEAKY_RELU, 0.1f)) |
| 257 | .set_name("conv2d_65/LeakyRelu"); |
Michalis Spyrou | e22aa13 | 2018-09-13 10:35:33 +0100 | [diff] [blame] | 258 | SubStream route_2(concat_1); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 259 | concat_1 |
| 260 | << ConvolutionLayer( |
| 261 | 3U, 3U, 512U, |
| 262 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/conv2d_66_w.npy", weights_layout), |
| 263 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 1, 1)) |
| 264 | .set_name("conv2d_66") |
| 265 | << BatchNormalizationLayer( |
| 266 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_65_mean.npy"), |
| 267 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_65_var.npy"), |
| 268 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_65_gamma.npy"), |
| 269 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_65_beta.npy"), 0.000001f) |
| 270 | .set_name("conv2d_65/BatchNorm") |
| 271 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LEAKY_RELU, 0.1f)) |
| 272 | .set_name("conv2d_66/LeakyRelu") |
| 273 | << ConvolutionLayer( |
| 274 | 1U, 1U, 255U, |
| 275 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/conv2d_67_w.npy", weights_layout), |
| 276 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/conv2d_67_b.npy", weights_layout), |
| 277 | PadStrideInfo(1, 1, 0, 0)) |
| 278 | .set_name("conv2d_67") |
| 279 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LINEAR, 1.f)) |
| 280 | .set_name("conv2d_67/Linear") |
| 281 | << YOLOLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC, 0.1f)).set_name("Yolo2") |
| 282 | << OutputLayer(get_output_accessor(common_params, 5)); |
Michalis Spyrou | e22aa13 | 2018-09-13 10:35:33 +0100 | [diff] [blame] | 283 | route_2 << ConvolutionLayer( |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 284 | 1U, 1U, 128U, |
| 285 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/conv2d_68_w.npy", weights_layout), |
| 286 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0)) |
| 287 | .set_name("conv2d_68") |
Michalis Spyrou | e22aa13 | 2018-09-13 10:35:33 +0100 | [diff] [blame] | 288 | << BatchNormalizationLayer( |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 289 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_66_mean.npy"), |
| 290 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_66_var.npy"), |
| 291 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_66_gamma.npy"), |
| 292 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_66_beta.npy"), |
| 293 | 0.000001f) |
| 294 | .set_name("conv2d_66/BatchNorm") |
| 295 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LEAKY_RELU, 0.1f)) |
| 296 | .set_name("conv2d_68/LeakyRelu") |
Georgios Pinitas | c53266e | 2020-12-09 03:11:53 +0000 | [diff] [blame] | 297 | << ResizeLayer(InterpolationPolicy::NEAREST_NEIGHBOR, 2, 2).set_name("Upsample_68"); |
Michalis Spyrou | e22aa13 | 2018-09-13 10:35:33 +0100 | [diff] [blame] | 298 | SubStream concat_2(route_2); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 299 | concat_2 |
| 300 | << ConcatLayer(std::move(route_2), std::move(intermediate_layers.first)).set_name("Route2") |
| 301 | << ConvolutionLayer( |
| 302 | 1U, 1U, 128U, |
| 303 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/conv2d_69_w.npy", weights_layout), |
| 304 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0)) |
| 305 | .set_name("conv2d_69") |
| 306 | << BatchNormalizationLayer( |
| 307 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_67_mean.npy"), |
| 308 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_67_var.npy"), |
| 309 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_67_gamma.npy"), |
| 310 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_67_beta.npy"), 0.000001f) |
| 311 | .set_name("conv2d_67/BatchNorm") |
| 312 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LEAKY_RELU, 0.1f)) |
| 313 | .set_name("conv2d_69/LeakyRelu") |
| 314 | << ConvolutionLayer( |
| 315 | 3U, 3U, 256U, |
| 316 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/conv2d_70_w.npy", weights_layout), |
| 317 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 1, 1)) |
| 318 | .set_name("conv2d_70") |
| 319 | << BatchNormalizationLayer( |
| 320 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_68_mean.npy"), |
| 321 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_68_var.npy"), |
| 322 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_68_gamma.npy"), |
| 323 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_68_beta.npy"), 0.000001f) |
| 324 | .set_name("conv2d_68/BatchNorm") |
| 325 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LEAKY_RELU, 0.1f)) |
| 326 | .set_name("conv2d_70/LeakyRelu") |
| 327 | << ConvolutionLayer( |
| 328 | 1U, 1U, 128U, |
| 329 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/conv2d_71_w.npy", weights_layout), |
| 330 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0)) |
| 331 | .set_name("conv2d_71") |
| 332 | << BatchNormalizationLayer( |
| 333 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_69_mean.npy"), |
| 334 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_69_var.npy"), |
| 335 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_69_gamma.npy"), |
| 336 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_69_beta.npy"), 0.000001f) |
| 337 | .set_name("conv2d_69/BatchNorm") |
| 338 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LEAKY_RELU, 0.1f)) |
| 339 | .set_name("conv2d_71/LeakyRelu") |
| 340 | << ConvolutionLayer( |
| 341 | 3U, 3U, 256U, |
| 342 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/conv2d_72_w.npy", weights_layout), |
| 343 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 1, 1)) |
| 344 | .set_name("conv2d_72") |
| 345 | << BatchNormalizationLayer( |
| 346 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_70_mean.npy"), |
| 347 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_70_var.npy"), |
| 348 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_70_gamma.npy"), |
| 349 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_70_beta.npy"), 0.000001f) |
| 350 | .set_name("conv2d_70/BatchNorm") |
| 351 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LEAKY_RELU, 0.1f)) |
| 352 | .set_name("conv2d_72/LeakyRelu") |
| 353 | << ConvolutionLayer( |
| 354 | 1U, 1U, 128U, |
| 355 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/conv2d_73_w.npy", weights_layout), |
| 356 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0)) |
| 357 | .set_name("conv2d_73") |
| 358 | << BatchNormalizationLayer( |
| 359 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_71_mean.npy"), |
| 360 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_71_var.npy"), |
| 361 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_71_gamma.npy"), |
| 362 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_71_beta.npy"), 0.000001f) |
| 363 | .set_name("conv2d_71/BatchNorm") |
| 364 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LEAKY_RELU, 0.1f)) |
| 365 | .set_name("conv2d_73/LeakyRelu") |
| 366 | << ConvolutionLayer( |
| 367 | 3U, 3U, 256U, |
| 368 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/conv2d_74_w.npy", weights_layout), |
| 369 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 1, 1)) |
| 370 | .set_name("conv2d_74") |
| 371 | << BatchNormalizationLayer( |
| 372 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_72_mean.npy"), |
| 373 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_72_var.npy"), |
| 374 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_72_gamma.npy"), |
| 375 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_72_beta.npy"), 0.000001f) |
| 376 | .set_name("conv2d_72/BatchNorm") |
| 377 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LEAKY_RELU, 0.1f)) |
| 378 | .set_name("conv2d_74/LeakyRelu") |
| 379 | << ConvolutionLayer( |
| 380 | 1U, 1U, 255U, |
| 381 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/conv2d_75_w.npy", weights_layout), |
| 382 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/conv2d_75_b.npy", weights_layout), |
| 383 | PadStrideInfo(1, 1, 0, 0)) |
| 384 | .set_name("conv2d_75") |
| 385 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LINEAR, 1.f)) |
| 386 | .set_name("conv2d_75/Linear") |
| 387 | << YOLOLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC, 0.1f)).set_name("Yolo3") |
| 388 | << OutputLayer(get_output_accessor(common_params, 5)); |
Michalis Spyrou | e22aa13 | 2018-09-13 10:35:33 +0100 | [diff] [blame] | 389 | |
| 390 | // Finalize graph |
| 391 | GraphConfig config; |
| 392 | config.num_threads = common_params.threads; |
| 393 | config.use_tuner = common_params.enable_tuner; |
Vidhya Sudhan Loganathan | 050471e | 2019-04-25 09:27:24 +0100 | [diff] [blame] | 394 | config.tuner_mode = common_params.tuner_mode; |
Michalis Spyrou | e22aa13 | 2018-09-13 10:35:33 +0100 | [diff] [blame] | 395 | config.tuner_file = common_params.tuner_file; |
SiCong Li | 4841c97 | 2021-02-03 12:17:35 +0000 | [diff] [blame] | 396 | config.mlgo_file = common_params.mlgo_file; |
Michalis Spyrou | e22aa13 | 2018-09-13 10:35:33 +0100 | [diff] [blame] | 397 | |
| 398 | graph.finalize(common_params.target, config); |
| 399 | |
| 400 | return true; |
| 401 | } |
| 402 | void do_run() override |
| 403 | { |
| 404 | // Run graph |
| 405 | graph.run(); |
| 406 | } |
| 407 | |
| 408 | private: |
| 409 | CommandLineParser cmd_parser; |
| 410 | CommonGraphOptions common_opts; |
| 411 | CommonGraphParams common_params; |
| 412 | Stream graph; |
| 413 | |
| 414 | std::pair<SubStream, SubStream> darknet53(const std::string &data_path, DataLayout weights_layout) |
| 415 | { |
| 416 | graph << ConvolutionLayer( |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 417 | 3U, 3U, 32U, |
| 418 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/conv2d_1_w.npy", weights_layout), |
| 419 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 1, 1)) |
| 420 | .set_name("conv2d_1/Conv2D") |
Michalis Spyrou | 177a9a5 | 2018-09-06 15:10:22 +0100 | [diff] [blame] | 421 | << BatchNormalizationLayer( |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 422 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_1_mean.npy"), |
| 423 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_1_var.npy"), |
| 424 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_1_gamma.npy"), |
| 425 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_1_beta.npy"), |
| 426 | 0.000001f) |
| 427 | .set_name("conv2d_1/BatchNorm") |
| 428 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LEAKY_RELU, 0.1f)) |
| 429 | .set_name("conv2d_1/LeakyRelu") |
Michalis Spyrou | 177a9a5 | 2018-09-06 15:10:22 +0100 | [diff] [blame] | 430 | << ConvolutionLayer( |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 431 | 3U, 3U, 64U, |
| 432 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/conv2d_2_w.npy", weights_layout), |
| 433 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(2, 2, 1, 1)) |
| 434 | .set_name("conv2d_2/Conv2D") |
Michalis Spyrou | 177a9a5 | 2018-09-06 15:10:22 +0100 | [diff] [blame] | 435 | << BatchNormalizationLayer( |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 436 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_2_mean.npy"), |
| 437 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_2_var.npy"), |
| 438 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_2_gamma.npy"), |
| 439 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_2_beta.npy"), |
| 440 | 0.000001f) |
| 441 | .set_name("conv2d_2/BatchNorm") |
| 442 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LEAKY_RELU, 0.1f)) |
| 443 | .set_name("conv2d_2/LeakyRelu"); |
Michalis Spyrou | 177a9a5 | 2018-09-06 15:10:22 +0100 | [diff] [blame] | 444 | darknet53_block(data_path, "3", weights_layout, 32U); |
| 445 | graph << ConvolutionLayer( |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 446 | 3U, 3U, 128U, |
| 447 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/conv2d_5_w.npy", weights_layout), |
| 448 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(2, 2, 1, 1)) |
| 449 | .set_name("conv2d_5/Conv2D") |
Michalis Spyrou | 177a9a5 | 2018-09-06 15:10:22 +0100 | [diff] [blame] | 450 | << BatchNormalizationLayer( |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 451 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_5_mean.npy"), |
| 452 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_5_var.npy"), |
| 453 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_5_gamma.npy"), |
| 454 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_5_beta.npy"), |
| 455 | 0.000001f) |
| 456 | .set_name("conv2d_5/BatchNorm") |
| 457 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LEAKY_RELU, 0.1f)) |
| 458 | .set_name("conv2d_5/LeakyRelu"); |
Michalis Spyrou | 177a9a5 | 2018-09-06 15:10:22 +0100 | [diff] [blame] | 459 | darknet53_block(data_path, "6", weights_layout, 64U); |
| 460 | darknet53_block(data_path, "8", weights_layout, 64U); |
| 461 | graph << ConvolutionLayer( |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 462 | 3U, 3U, 256U, |
| 463 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/conv2d_10_w.npy", weights_layout), |
| 464 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(2, 2, 1, 1)) |
| 465 | .set_name("conv2d_10/Conv2D") |
Michalis Spyrou | 177a9a5 | 2018-09-06 15:10:22 +0100 | [diff] [blame] | 466 | << BatchNormalizationLayer( |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 467 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_10_mean.npy"), |
| 468 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_10_var.npy"), |
| 469 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_10_gamma.npy"), |
| 470 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_10_beta.npy"), |
| 471 | 0.000001f) |
| 472 | .set_name("conv2d_10/BatchNorm") |
| 473 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LEAKY_RELU, 0.1f)) |
| 474 | .set_name("conv2d_10/LeakyRelu"); |
Michalis Spyrou | 177a9a5 | 2018-09-06 15:10:22 +0100 | [diff] [blame] | 475 | darknet53_block(data_path, "11", weights_layout, 128U); |
| 476 | darknet53_block(data_path, "13", weights_layout, 128U); |
| 477 | darknet53_block(data_path, "15", weights_layout, 128U); |
| 478 | darknet53_block(data_path, "17", weights_layout, 128U); |
| 479 | darknet53_block(data_path, "19", weights_layout, 128U); |
| 480 | darknet53_block(data_path, "21", weights_layout, 128U); |
| 481 | darknet53_block(data_path, "23", weights_layout, 128U); |
| 482 | darknet53_block(data_path, "25", weights_layout, 128U); |
Michalis Spyrou | e22aa13 | 2018-09-13 10:35:33 +0100 | [diff] [blame] | 483 | SubStream layer_36(graph); |
Michalis Spyrou | 177a9a5 | 2018-09-06 15:10:22 +0100 | [diff] [blame] | 484 | graph << ConvolutionLayer( |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 485 | 3U, 3U, 512U, |
| 486 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/conv2d_27_w.npy", weights_layout), |
| 487 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(2, 2, 1, 1)) |
| 488 | .set_name("conv2d_27/Conv2D") |
Michalis Spyrou | 177a9a5 | 2018-09-06 15:10:22 +0100 | [diff] [blame] | 489 | << BatchNormalizationLayer( |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 490 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_27_mean.npy"), |
| 491 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_27_var.npy"), |
| 492 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_27_gamma.npy"), |
| 493 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_27_beta.npy"), |
| 494 | 0.000001f) |
| 495 | .set_name("conv2d_27/BatchNorm") |
| 496 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LEAKY_RELU, 0.1f)) |
| 497 | .set_name("conv2d_27/LeakyRelu"); |
Michalis Spyrou | 177a9a5 | 2018-09-06 15:10:22 +0100 | [diff] [blame] | 498 | darknet53_block(data_path, "28", weights_layout, 256U); |
| 499 | darknet53_block(data_path, "30", weights_layout, 256U); |
| 500 | darknet53_block(data_path, "32", weights_layout, 256U); |
| 501 | darknet53_block(data_path, "34", weights_layout, 256U); |
| 502 | darknet53_block(data_path, "36", weights_layout, 256U); |
| 503 | darknet53_block(data_path, "38", weights_layout, 256U); |
| 504 | darknet53_block(data_path, "40", weights_layout, 256U); |
| 505 | darknet53_block(data_path, "42", weights_layout, 256U); |
Michalis Spyrou | e22aa13 | 2018-09-13 10:35:33 +0100 | [diff] [blame] | 506 | SubStream layer_61(graph); |
Michalis Spyrou | 177a9a5 | 2018-09-06 15:10:22 +0100 | [diff] [blame] | 507 | graph << ConvolutionLayer( |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 508 | 3U, 3U, 1024U, |
| 509 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/conv2d_44_w.npy", weights_layout), |
| 510 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(2, 2, 1, 1)) |
| 511 | .set_name("conv2d_44/Conv2D") |
Michalis Spyrou | 177a9a5 | 2018-09-06 15:10:22 +0100 | [diff] [blame] | 512 | << BatchNormalizationLayer( |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 513 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_44_mean.npy"), |
| 514 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_44_var.npy"), |
| 515 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_44_gamma.npy"), |
| 516 | get_weights_accessor(data_path, "/cnn_data/yolov3_model/batch_normalization_44_beta.npy"), |
| 517 | 0.000001f) |
| 518 | .set_name("conv2d_44/BatchNorm") |
| 519 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LEAKY_RELU, 0.1f)) |
| 520 | .set_name("conv2d_44/LeakyRelu"); |
Michalis Spyrou | 177a9a5 | 2018-09-06 15:10:22 +0100 | [diff] [blame] | 521 | darknet53_block(data_path, "45", weights_layout, 512U); |
| 522 | darknet53_block(data_path, "47", weights_layout, 512U); |
| 523 | darknet53_block(data_path, "49", weights_layout, 512U); |
| 524 | darknet53_block(data_path, "51", weights_layout, 512U); |
Michalis Spyrou | 177a9a5 | 2018-09-06 15:10:22 +0100 | [diff] [blame] | 525 | |
Michalis Spyrou | e22aa13 | 2018-09-13 10:35:33 +0100 | [diff] [blame] | 526 | return std::pair<SubStream, SubStream>(layer_36, layer_61); |
Michalis Spyrou | 177a9a5 | 2018-09-06 15:10:22 +0100 | [diff] [blame] | 527 | } |
Michalis Spyrou | 177a9a5 | 2018-09-06 15:10:22 +0100 | [diff] [blame] | 528 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 529 | void darknet53_block(const std::string &data_path, |
| 530 | std::string &¶m_path, |
| 531 | DataLayout weights_layout, |
| 532 | unsigned int filter_size) |
Michalis Spyrou | 177a9a5 | 2018-09-06 15:10:22 +0100 | [diff] [blame] | 533 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 534 | std::string total_path = "/cnn_data/yolov3_model/"; |
| 535 | std::string param_path2 = |
| 536 | arm_compute::support::cpp11::to_string(arm_compute::support::cpp11::stoi(param_path) + 1); |
| 537 | SubStream i_a(graph); |
| 538 | SubStream i_b(graph); |
Michalis Spyrou | 177a9a5 | 2018-09-06 15:10:22 +0100 | [diff] [blame] | 539 | i_a << ConvolutionLayer( |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 540 | 1U, 1U, filter_size, |
| 541 | get_weights_accessor(data_path, total_path + "conv2d_" + param_path + "_w.npy", weights_layout), |
| 542 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0)) |
| 543 | .set_name("conv2d_" + param_path + "/Conv2D") |
Michalis Spyrou | 177a9a5 | 2018-09-06 15:10:22 +0100 | [diff] [blame] | 544 | << BatchNormalizationLayer( |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 545 | get_weights_accessor(data_path, total_path + "batch_normalization_" + param_path + "_mean.npy"), |
| 546 | get_weights_accessor(data_path, total_path + "batch_normalization_" + param_path + "_var.npy"), |
| 547 | get_weights_accessor(data_path, total_path + "batch_normalization_" + param_path + "_gamma.npy"), |
| 548 | get_weights_accessor(data_path, total_path + "batch_normalization_" + param_path + "_beta.npy"), |
| 549 | 0.000001f) |
| 550 | .set_name("conv2d_" + param_path + "/BatchNorm") |
| 551 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LEAKY_RELU, 0.1f)) |
| 552 | .set_name("conv2d_" + param_path + "/LeakyRelu") |
Michalis Spyrou | 177a9a5 | 2018-09-06 15:10:22 +0100 | [diff] [blame] | 553 | << ConvolutionLayer( |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 554 | 3U, 3U, filter_size * 2, |
| 555 | get_weights_accessor(data_path, total_path + "conv2d_" + param_path2 + "_w.npy", weights_layout), |
| 556 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 1, 1)) |
| 557 | .set_name("conv2d_" + param_path2 + "/Conv2D") |
Michalis Spyrou | 177a9a5 | 2018-09-06 15:10:22 +0100 | [diff] [blame] | 558 | << BatchNormalizationLayer( |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 559 | get_weights_accessor(data_path, total_path + "batch_normalization_" + param_path2 + "_mean.npy"), |
| 560 | get_weights_accessor(data_path, total_path + "batch_normalization_" + param_path2 + "_var.npy"), |
| 561 | get_weights_accessor(data_path, total_path + "batch_normalization_" + param_path2 + "_gamma.npy"), |
| 562 | get_weights_accessor(data_path, total_path + "batch_normalization_" + param_path2 + "_beta.npy"), |
| 563 | 0.000001f) |
| 564 | .set_name("conv2d_" + param_path2 + "/BatchNorm") |
| 565 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LEAKY_RELU, 0.1f)) |
| 566 | .set_name("conv2d_" + param_path2 + "/LeakyRelu"); |
Michalis Spyrou | 177a9a5 | 2018-09-06 15:10:22 +0100 | [diff] [blame] | 567 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 568 | graph << EltwiseLayer(std::move(i_a), std::move(i_b), EltwiseOperation::Add) |
| 569 | .set_name("") |
| 570 | .set_name("add_" + param_path + "_" + param_path2); |
Michalis Spyrou | 177a9a5 | 2018-09-06 15:10:22 +0100 | [diff] [blame] | 571 | } |
| 572 | }; |
| 573 | |
| 574 | /** Main program for YOLOv3 |
| 575 | * |
Georgios Pinitas | bdbbbe8 | 2018-11-07 16:06:47 +0000 | [diff] [blame] | 576 | * Model is based on: |
| 577 | * https://arxiv.org/abs/1804.02767 |
| 578 | * "YOLOv3: An Incremental Improvement" |
| 579 | * Joseph Redmon, Ali Farhadi |
| 580 | * |
Michalis Spyrou | 177a9a5 | 2018-09-06 15:10:22 +0100 | [diff] [blame] | 581 | * @note To list all the possible arguments execute the binary appended with the --help option |
| 582 | * |
| 583 | * @param[in] argc Number of arguments |
| 584 | * @param[in] argv Arguments |
| 585 | * |
| 586 | * @return Return code |
| 587 | */ |
| 588 | int main(int argc, char **argv) |
| 589 | { |
| 590 | return arm_compute::utils::run_example<GraphYOLOv3Example>(argc, argv); |
| 591 | } |