Sheri Zhang | 16dddd2 | 2020-05-27 15:03:48 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2020 ARM Limited. |
| 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 | |
| 25 | #include "arm_compute/graph.h" |
| 26 | #include "arm_compute/graph/Utils.h" |
| 27 | |
| 28 | #include "support/ToolchainSupport.h" |
| 29 | #include "utils/CommonGraphOptions.h" |
| 30 | #include "utils/GraphUtils.h" |
| 31 | #include "utils/Utils.h" |
| 32 | |
| 33 | using namespace arm_compute::graph; |
| 34 | using namespace arm_compute::utils; |
| 35 | |
| 36 | class GraphYoloV3OutputDetector |
| 37 | { |
| 38 | public: |
| 39 | GraphYoloV3OutputDetector() |
| 40 | : _graph(0, "GraphYoloV3OutputDetector") |
| 41 | { |
| 42 | } |
| 43 | |
| 44 | bool setup(const std::string &data_path, Target target) |
| 45 | { |
| 46 | using namespace arm_compute; |
| 47 | using namespace graph_utils; |
| 48 | |
| 49 | NodeID id_ConstantFolding_truediv_1_recip = _graph.add_node<ConstNode>( |
| 50 | TensorDescriptor |
| 51 | { |
| 52 | TensorShape{ 1, 1, 1 }, |
| 53 | DataType::F32, |
| 54 | QuantizationInfo(), |
| 55 | DataLayout::NHWC }); |
| 56 | INode *node_ConstantFolding_truediv_1_recip = _graph.node(id_ConstantFolding_truediv_1_recip); |
| 57 | node_ConstantFolding_truediv_1_recip->set_common_node_parameters(NodeParams{ "ConstantFolding_truediv_1_recip", target }); |
| 58 | node_ConstantFolding_truediv_1_recip->output(0)->set_accessor(get_weights_accessor(data_path, "/cnn_data/yolov3_output_detector/ConstantFolding_truediv_1_recip.npy", DataLayout::NHWC)); |
| 59 | |
| 60 | NodeID id_ConstantFolding_truediv_recip = _graph.add_node<ConstNode>( |
| 61 | TensorDescriptor |
| 62 | { |
| 63 | TensorShape{ 1, 1, 1 }, |
| 64 | DataType::F32, |
| 65 | QuantizationInfo(), |
| 66 | DataLayout::NHWC }); |
| 67 | INode *node_ConstantFolding_truediv_recip = _graph.node(id_ConstantFolding_truediv_recip); |
| 68 | node_ConstantFolding_truediv_recip->set_common_node_parameters(NodeParams{ "ConstantFolding_truediv_recip", target }); |
| 69 | node_ConstantFolding_truediv_recip->output(0)->set_accessor(get_weights_accessor(data_path, "/cnn_data/yolov3_output_detector/ConstantFolding_truediv_recip.npy", DataLayout::NHWC)); |
| 70 | |
| 71 | NodeID id_detector_yolo_v3_mul_6_y = _graph.add_node<ConstNode>( |
| 72 | TensorDescriptor |
| 73 | { |
| 74 | TensorShape{ 1, 1, 2 }, |
| 75 | DataType::F32, |
| 76 | QuantizationInfo(), |
| 77 | DataLayout::NHWC }); |
| 78 | INode *node_detector_yolo_v3_mul_6_y = _graph.node(id_detector_yolo_v3_mul_6_y); |
| 79 | node_detector_yolo_v3_mul_6_y->set_common_node_parameters(NodeParams{ "detector_yolo_v3_mul_6_y", target }); |
| 80 | node_detector_yolo_v3_mul_6_y->output(0)->set_accessor(get_weights_accessor(data_path, "/cnn_data/yolov3_output_detector/detector_yolo_v3_mul_6_y.npy", DataLayout::NHWC)); |
| 81 | |
| 82 | NodeID id_detector_yolo_v3_mul_3_y = _graph.add_node<ConstNode>( |
| 83 | TensorDescriptor |
| 84 | { |
| 85 | TensorShape{ 1, 1, 2 }, |
| 86 | DataType::F32, |
| 87 | QuantizationInfo(), |
| 88 | DataLayout::NHWC }); |
| 89 | INode *node_detector_yolo_v3_mul_3_y = _graph.node(id_detector_yolo_v3_mul_3_y); |
| 90 | node_detector_yolo_v3_mul_3_y->set_common_node_parameters(NodeParams{ "detector_yolo_v3_mul_3_y", target }); |
| 91 | node_detector_yolo_v3_mul_3_y->output(0)->set_accessor(get_weights_accessor(data_path, "/cnn_data/yolov3_output_detector/detector_yolo_v3_mul_3_y.npy", DataLayout::NHWC)); |
| 92 | |
| 93 | NodeID id_detector_yolo_v3_mul_y = _graph.add_node<ConstNode>( |
| 94 | TensorDescriptor |
| 95 | { |
| 96 | TensorShape{ 1, 1, 2 }, |
| 97 | DataType::F32, |
| 98 | QuantizationInfo(), |
| 99 | DataLayout::NHWC }); |
| 100 | INode *node_detector_yolo_v3_mul_y = _graph.node(id_detector_yolo_v3_mul_y); |
| 101 | node_detector_yolo_v3_mul_y->set_common_node_parameters(NodeParams{ "detector_yolo_v3_mul_y", target }); |
| 102 | node_detector_yolo_v3_mul_y->output(0)->set_accessor(get_weights_accessor(data_path, "/cnn_data/yolov3_output_detector/detector_yolo_v3_mul_y.npy", DataLayout::NHWC)); |
| 103 | |
| 104 | NodeID id_detector_yolo_v3_mul_7 = _graph.add_node<ConstNode>( |
| 105 | TensorDescriptor |
| 106 | { |
| 107 | TensorShape{ 1, 8112, 2 }, |
| 108 | DataType::F32, |
| 109 | QuantizationInfo(), |
| 110 | DataLayout::NHWC }); |
| 111 | INode *node_detector_yolo_v3_mul_7 = _graph.node(id_detector_yolo_v3_mul_7); |
| 112 | node_detector_yolo_v3_mul_7->set_common_node_parameters(NodeParams{ "detector_yolo_v3_mul_7", target }); |
| 113 | node_detector_yolo_v3_mul_7->output(0)->set_accessor(get_weights_accessor(data_path, "/cnn_data/yolov3_output_detector/detector_yolo_v3_mul_7.npy", DataLayout::NHWC)); |
| 114 | |
| 115 | NodeID id_detector_yolo_v3_Reshape_11 = _graph.add_node<ConstNode>( |
| 116 | TensorDescriptor |
| 117 | { |
| 118 | TensorShape{ 1, 8112, 2 }, |
| 119 | DataType::F32, |
| 120 | QuantizationInfo(), |
| 121 | DataLayout::NHWC }); |
| 122 | INode *node_detector_yolo_v3_Reshape_11 = _graph.node(id_detector_yolo_v3_Reshape_11); |
| 123 | node_detector_yolo_v3_Reshape_11->set_common_node_parameters(NodeParams{ "detector_yolo_v3_Reshape_11", target }); |
| 124 | node_detector_yolo_v3_Reshape_11->output(0)->set_accessor(get_weights_accessor(data_path, "/cnn_data/yolov3_output_detector/detector_yolo_v3_Reshape_11.npy", DataLayout::NHWC)); |
| 125 | |
| 126 | NodeID id_detector_yolo_v3_mul_4 = _graph.add_node<ConstNode>( |
| 127 | TensorDescriptor |
| 128 | { |
| 129 | TensorShape{ 1, 2028, 2 }, |
| 130 | DataType::F32, |
| 131 | QuantizationInfo(), |
| 132 | DataLayout::NHWC }); |
| 133 | INode *node_detector_yolo_v3_mul_4 = _graph.node(id_detector_yolo_v3_mul_4); |
| 134 | node_detector_yolo_v3_mul_4->set_common_node_parameters(NodeParams{ "detector_yolo_v3_mul_4", target }); |
| 135 | node_detector_yolo_v3_mul_4->output(0)->set_accessor(get_weights_accessor(data_path, "/cnn_data/yolov3_output_detector/detector_yolo_v3_mul_4.npy", DataLayout::NHWC)); |
| 136 | |
| 137 | NodeID id_detector_yolo_v3_Reshape_7 = _graph.add_node<ConstNode>( |
| 138 | TensorDescriptor |
| 139 | { |
| 140 | TensorShape{ 1, 2028, 2 }, |
| 141 | DataType::F32, |
| 142 | QuantizationInfo(), |
| 143 | DataLayout::NHWC }); |
| 144 | INode *node_detector_yolo_v3_Reshape_7 = _graph.node(id_detector_yolo_v3_Reshape_7); |
| 145 | node_detector_yolo_v3_Reshape_7->set_common_node_parameters(NodeParams{ "detector_yolo_v3_Reshape_7", target }); |
| 146 | node_detector_yolo_v3_Reshape_7->output(0)->set_accessor(get_weights_accessor(data_path, "/cnn_data/yolov3_output_detector/detector_yolo_v3_Reshape_7.npy", DataLayout::NHWC)); |
| 147 | |
| 148 | NodeID id_detector_yolo_v3_mul_1 = _graph.add_node<ConstNode>( |
| 149 | TensorDescriptor |
| 150 | { |
| 151 | TensorShape{ 1, 507, 2 }, |
| 152 | DataType::F32, |
| 153 | QuantizationInfo(), |
| 154 | DataLayout::NHWC }); |
| 155 | INode *node_detector_yolo_v3_mul_1 = _graph.node(id_detector_yolo_v3_mul_1); |
| 156 | node_detector_yolo_v3_mul_1->set_common_node_parameters(NodeParams{ "detector_yolo_v3_mul_1", target }); |
| 157 | node_detector_yolo_v3_mul_1->output(0)->set_accessor(get_weights_accessor(data_path, "/cnn_data/yolov3_output_detector/detector_yolo_v3_mul_1.npy", DataLayout::NHWC)); |
| 158 | |
| 159 | NodeID id_detector_yolo_v3_Reshape_3 = _graph.add_node<ConstNode>( |
| 160 | TensorDescriptor |
| 161 | { |
| 162 | TensorShape{ 1, 507, 2 }, |
| 163 | DataType::F32, |
| 164 | QuantizationInfo(), |
| 165 | DataLayout::NHWC }); |
| 166 | INode *node_detector_yolo_v3_Reshape_3 = _graph.node(id_detector_yolo_v3_Reshape_3); |
| 167 | node_detector_yolo_v3_Reshape_3->set_common_node_parameters(NodeParams{ "detector_yolo_v3_Reshape_3", target }); |
| 168 | node_detector_yolo_v3_Reshape_3->output(0)->set_accessor(get_weights_accessor(data_path, "/cnn_data/yolov3_output_detector/detector_yolo_v3_Reshape_3.npy", DataLayout::NHWC)); |
| 169 | |
| 170 | NodeID id_input_to_detector_3 = _graph.add_node<InputNode>( |
| 171 | TensorDescriptor |
| 172 | { |
| 173 | TensorShape{ 255, 52, 52, 1 }, |
| 174 | DataType::F32, |
| 175 | QuantizationInfo(), |
| 176 | DataLayout::NHWC }); |
| 177 | INode *node_input_to_detector_3 = _graph.node(id_input_to_detector_3); |
| 178 | node_input_to_detector_3->set_common_node_parameters(NodeParams{ "input_to_detector_3", target }); |
| 179 | node_input_to_detector_3->output(0)->set_accessor(support::cpp14::make_unique<DummyAccessor>()); |
| 180 | |
| 181 | NodeID id_detector_yolo_v3_Reshape_10 = _graph.add_node<ReshapeLayerNode>( |
| 182 | TensorShape{ 1, 8112, 85 }); |
| 183 | INode *node_detector_yolo_v3_Reshape_10 = _graph.node(id_detector_yolo_v3_Reshape_10); |
| 184 | node_detector_yolo_v3_Reshape_10->set_common_node_parameters(NodeParams{ "detector_yolo_v3_Reshape_10", target }); |
| 185 | _graph.add_connection(id_input_to_detector_3, 0, id_detector_yolo_v3_Reshape_10, 0); |
| 186 | |
| 187 | NodeID id_detector_yolo_v3_split_2 = _graph.add_node<SplitLayerNode>( |
| 188 | 4, |
| 189 | -1, |
| 190 | std::vector<int> { 2, 2, 1, 80 }); |
| 191 | INode *node_detector_yolo_v3_split_2 = _graph.node(id_detector_yolo_v3_split_2); |
| 192 | node_detector_yolo_v3_split_2->set_common_node_parameters(NodeParams{ "detector_yolo_v3_split_2", target }); |
| 193 | _graph.add_connection(id_detector_yolo_v3_Reshape_10, 0, id_detector_yolo_v3_split_2, 0); |
| 194 | |
| 195 | NodeID id_detector_yolo_v3_Sigmoid_6 = _graph.add_node<ActivationLayerNode>( |
| 196 | ActivationLayerInfo{ ActivationLayerInfo::ActivationFunction::LOGISTIC, 0, 0 }); |
| 197 | INode *node_detector_yolo_v3_Sigmoid_6 = _graph.node(id_detector_yolo_v3_Sigmoid_6); |
| 198 | node_detector_yolo_v3_Sigmoid_6->set_common_node_parameters(NodeParams{ "detector_yolo_v3_Sigmoid_6", target }); |
| 199 | _graph.add_connection(id_detector_yolo_v3_split_2, 0, id_detector_yolo_v3_Sigmoid_6, 0); |
| 200 | |
| 201 | NodeID id_detector_yolo_v3_add_2 = _graph.add_node<EltwiseLayerNode>( |
| 202 | descriptors::EltwiseLayerDescriptor |
| 203 | { |
| 204 | EltwiseOperation::Add, |
| 205 | QuantizationInfo() }); |
| 206 | INode *node_detector_yolo_v3_add_2 = _graph.node(id_detector_yolo_v3_add_2); |
| 207 | node_detector_yolo_v3_add_2->set_common_node_parameters(NodeParams{ "detector_yolo_v3_add_2", target }); |
| 208 | _graph.add_connection(id_detector_yolo_v3_Sigmoid_6, 0, id_detector_yolo_v3_add_2, 0); |
| 209 | _graph.add_connection(id_detector_yolo_v3_Reshape_11, 0, id_detector_yolo_v3_add_2, 1); |
| 210 | |
| 211 | NodeID id_detector_yolo_v3_mul_6 = _graph.add_node<EltwiseLayerNode>( |
| 212 | descriptors::EltwiseLayerDescriptor |
| 213 | { |
| 214 | EltwiseOperation::Mul, |
| 215 | QuantizationInfo() }); |
| 216 | INode *node_detector_yolo_v3_mul_6 = _graph.node(id_detector_yolo_v3_mul_6); |
| 217 | node_detector_yolo_v3_mul_6->set_common_node_parameters(NodeParams{ "detector_yolo_v3_mul_6", target }); |
| 218 | _graph.add_connection(id_detector_yolo_v3_add_2, 0, id_detector_yolo_v3_mul_6, 0); |
| 219 | _graph.add_connection(id_detector_yolo_v3_mul_6_y, 0, id_detector_yolo_v3_mul_6, 1); |
| 220 | |
| 221 | NodeID id_detector_yolo_v3_Sigmoid_7 = _graph.add_node<ActivationLayerNode>( |
| 222 | ActivationLayerInfo{ ActivationLayerInfo::ActivationFunction::LOGISTIC, 0, 0 }); |
| 223 | INode *node_detector_yolo_v3_Sigmoid_7 = _graph.node(id_detector_yolo_v3_Sigmoid_7); |
| 224 | node_detector_yolo_v3_Sigmoid_7->set_common_node_parameters(NodeParams{ "detector_yolo_v3_Sigmoid_7", target }); |
| 225 | _graph.add_connection(id_detector_yolo_v3_split_2, 2, id_detector_yolo_v3_Sigmoid_7, 0); |
| 226 | |
| 227 | NodeID id_detector_yolo_v3_Exp_2 = _graph.add_node<UnaryEltwiseLayerNode>( |
| 228 | descriptors::UnaryEltwiseLayerDescriptor |
| 229 | { |
| 230 | UnaryEltwiseOperation::Exp, |
| 231 | QuantizationInfo() }); |
| 232 | INode *node_detector_yolo_v3_Exp_2 = _graph.node(id_detector_yolo_v3_Exp_2); |
| 233 | node_detector_yolo_v3_Exp_2->set_common_node_parameters(NodeParams{ "detector_yolo_v3_Exp_2", target }); |
| 234 | _graph.add_connection(id_detector_yolo_v3_split_2, 1, id_detector_yolo_v3_Exp_2, 0); |
| 235 | |
| 236 | NodeID id_detector_yolo_v3_mul_8 = _graph.add_node<EltwiseLayerNode>( |
| 237 | descriptors::EltwiseLayerDescriptor |
| 238 | { |
| 239 | EltwiseOperation::Mul, |
| 240 | QuantizationInfo() }); |
| 241 | INode *node_detector_yolo_v3_mul_8 = _graph.node(id_detector_yolo_v3_mul_8); |
| 242 | node_detector_yolo_v3_mul_8->set_common_node_parameters(NodeParams{ "detector_yolo_v3_mul_8", target }); |
| 243 | _graph.add_connection(id_detector_yolo_v3_Exp_2, 0, id_detector_yolo_v3_mul_8, 0); |
| 244 | _graph.add_connection(id_detector_yolo_v3_mul_7, 0, id_detector_yolo_v3_mul_8, 1); |
| 245 | |
| 246 | NodeID id_detector_yolo_v3_Sigmoid_8 = _graph.add_node<ActivationLayerNode>( |
| 247 | ActivationLayerInfo{ ActivationLayerInfo::ActivationFunction::LOGISTIC, 0, 0 }); |
| 248 | INode *node_detector_yolo_v3_Sigmoid_8 = _graph.node(id_detector_yolo_v3_Sigmoid_8); |
| 249 | node_detector_yolo_v3_Sigmoid_8->set_common_node_parameters(NodeParams{ "detector_yolo_v3_Sigmoid_8", target }); |
| 250 | _graph.add_connection(id_detector_yolo_v3_split_2, 3, id_detector_yolo_v3_Sigmoid_8, 0); |
| 251 | |
| 252 | NodeID id_detector_yolo_v3_concat_8 = _graph.add_node<ConcatenateLayerNode>( |
| 253 | 4, |
| 254 | descriptors::ConcatLayerDescriptor{ DataLayoutDimension::HEIGHT }); |
| 255 | INode *node_detector_yolo_v3_concat_8 = _graph.node(id_detector_yolo_v3_concat_8); |
| 256 | node_detector_yolo_v3_concat_8->set_common_node_parameters(NodeParams{ "detector_yolo_v3_concat_8", target }); |
| 257 | _graph.add_connection(id_detector_yolo_v3_mul_6, 0, id_detector_yolo_v3_concat_8, 0); |
| 258 | _graph.add_connection(id_detector_yolo_v3_mul_8, 0, id_detector_yolo_v3_concat_8, 1); |
| 259 | _graph.add_connection(id_detector_yolo_v3_Sigmoid_7, 0, id_detector_yolo_v3_concat_8, 2); |
| 260 | _graph.add_connection(id_detector_yolo_v3_Sigmoid_8, 0, id_detector_yolo_v3_concat_8, 3); |
| 261 | |
| 262 | NodeID id_input_to_detector_2 = _graph.add_node<InputNode>( |
| 263 | TensorDescriptor |
| 264 | { |
| 265 | TensorShape{ 255, 26, 26, 1 }, |
| 266 | DataType::F32, |
| 267 | QuantizationInfo(), |
| 268 | DataLayout::NHWC }); |
| 269 | INode *node_input_to_detector_2 = _graph.node(id_input_to_detector_2); |
| 270 | node_input_to_detector_2->set_common_node_parameters(NodeParams{ "input_to_detector_2", target }); |
| 271 | node_input_to_detector_2->output(0)->set_accessor(support::cpp14::make_unique<DummyAccessor>()); |
| 272 | |
| 273 | NodeID id_detector_yolo_v3_Reshape_6 = _graph.add_node<ReshapeLayerNode>( |
| 274 | TensorShape{ 1, 2028, 85 }); |
| 275 | INode *node_detector_yolo_v3_Reshape_6 = _graph.node(id_detector_yolo_v3_Reshape_6); |
| 276 | node_detector_yolo_v3_Reshape_6->set_common_node_parameters(NodeParams{ "detector_yolo_v3_Reshape_6", target }); |
| 277 | _graph.add_connection(id_input_to_detector_2, 0, id_detector_yolo_v3_Reshape_6, 0); |
| 278 | |
| 279 | NodeID id_detector_yolo_v3_split_1 = _graph.add_node<SplitLayerNode>( |
| 280 | 4, |
| 281 | -1, |
| 282 | std::vector<int> { 2, 2, 1, 80 }); |
| 283 | INode *node_detector_yolo_v3_split_1 = _graph.node(id_detector_yolo_v3_split_1); |
| 284 | node_detector_yolo_v3_split_1->set_common_node_parameters(NodeParams{ "detector_yolo_v3_split_1", target }); |
| 285 | _graph.add_connection(id_detector_yolo_v3_Reshape_6, 0, id_detector_yolo_v3_split_1, 0); |
| 286 | |
| 287 | NodeID id_detector_yolo_v3_Sigmoid_3 = _graph.add_node<ActivationLayerNode>( |
| 288 | ActivationLayerInfo{ ActivationLayerInfo::ActivationFunction::LOGISTIC, 0, 0 }); |
| 289 | INode *node_detector_yolo_v3_Sigmoid_3 = _graph.node(id_detector_yolo_v3_Sigmoid_3); |
| 290 | node_detector_yolo_v3_Sigmoid_3->set_common_node_parameters(NodeParams{ "detector_yolo_v3_Sigmoid_3", target }); |
| 291 | _graph.add_connection(id_detector_yolo_v3_split_1, 0, id_detector_yolo_v3_Sigmoid_3, 0); |
| 292 | |
| 293 | NodeID id_detector_yolo_v3_add_1 = _graph.add_node<EltwiseLayerNode>( |
| 294 | descriptors::EltwiseLayerDescriptor |
| 295 | { |
| 296 | EltwiseOperation::Add, |
| 297 | QuantizationInfo() }); |
| 298 | INode *node_detector_yolo_v3_add_1 = _graph.node(id_detector_yolo_v3_add_1); |
| 299 | node_detector_yolo_v3_add_1->set_common_node_parameters(NodeParams{ "detector_yolo_v3_add_1", target }); |
| 300 | _graph.add_connection(id_detector_yolo_v3_Sigmoid_3, 0, id_detector_yolo_v3_add_1, 0); |
| 301 | _graph.add_connection(id_detector_yolo_v3_Reshape_7, 0, id_detector_yolo_v3_add_1, 1); |
| 302 | |
| 303 | NodeID id_detector_yolo_v3_mul_3 = _graph.add_node<EltwiseLayerNode>( |
| 304 | descriptors::EltwiseLayerDescriptor |
| 305 | { |
| 306 | EltwiseOperation::Mul, |
| 307 | QuantizationInfo() }); |
| 308 | INode *node_detector_yolo_v3_mul_3 = _graph.node(id_detector_yolo_v3_mul_3); |
| 309 | node_detector_yolo_v3_mul_3->set_common_node_parameters(NodeParams{ "detector_yolo_v3_mul_3", target }); |
| 310 | _graph.add_connection(id_detector_yolo_v3_add_1, 0, id_detector_yolo_v3_mul_3, 0); |
| 311 | _graph.add_connection(id_detector_yolo_v3_mul_3_y, 0, id_detector_yolo_v3_mul_3, 1); |
| 312 | |
| 313 | NodeID id_detector_yolo_v3_Sigmoid_4 = _graph.add_node<ActivationLayerNode>( |
| 314 | ActivationLayerInfo{ ActivationLayerInfo::ActivationFunction::LOGISTIC, 0, 0 }); |
| 315 | INode *node_detector_yolo_v3_Sigmoid_4 = _graph.node(id_detector_yolo_v3_Sigmoid_4); |
| 316 | node_detector_yolo_v3_Sigmoid_4->set_common_node_parameters(NodeParams{ "detector_yolo_v3_Sigmoid_4", target }); |
| 317 | _graph.add_connection(id_detector_yolo_v3_split_1, 2, id_detector_yolo_v3_Sigmoid_4, 0); |
| 318 | |
| 319 | NodeID id_detector_yolo_v3_Exp_1 = _graph.add_node<UnaryEltwiseLayerNode>( |
| 320 | descriptors::UnaryEltwiseLayerDescriptor |
| 321 | { |
| 322 | UnaryEltwiseOperation::Exp, |
| 323 | QuantizationInfo() }); |
| 324 | INode *node_detector_yolo_v3_Exp_1 = _graph.node(id_detector_yolo_v3_Exp_1); |
| 325 | node_detector_yolo_v3_Exp_1->set_common_node_parameters(NodeParams{ "detector_yolo_v3_Exp_1", target }); |
| 326 | _graph.add_connection(id_detector_yolo_v3_split_1, 1, id_detector_yolo_v3_Exp_1, 0); |
| 327 | |
| 328 | NodeID id_detector_yolo_v3_mul_5 = _graph.add_node<EltwiseLayerNode>( |
| 329 | descriptors::EltwiseLayerDescriptor |
| 330 | { |
| 331 | EltwiseOperation::Mul, |
| 332 | QuantizationInfo() }); |
| 333 | INode *node_detector_yolo_v3_mul_5 = _graph.node(id_detector_yolo_v3_mul_5); |
| 334 | node_detector_yolo_v3_mul_5->set_common_node_parameters(NodeParams{ "detector_yolo_v3_mul_5", target }); |
| 335 | _graph.add_connection(id_detector_yolo_v3_Exp_1, 0, id_detector_yolo_v3_mul_5, 0); |
| 336 | _graph.add_connection(id_detector_yolo_v3_mul_4, 0, id_detector_yolo_v3_mul_5, 1); |
| 337 | |
| 338 | NodeID id_detector_yolo_v3_Sigmoid_5 = _graph.add_node<ActivationLayerNode>( |
| 339 | ActivationLayerInfo{ ActivationLayerInfo::ActivationFunction::LOGISTIC, 0, 0 }); |
| 340 | INode *node_detector_yolo_v3_Sigmoid_5 = _graph.node(id_detector_yolo_v3_Sigmoid_5); |
| 341 | node_detector_yolo_v3_Sigmoid_5->set_common_node_parameters(NodeParams{ "detector_yolo_v3_Sigmoid_5", target }); |
| 342 | _graph.add_connection(id_detector_yolo_v3_split_1, 3, id_detector_yolo_v3_Sigmoid_5, 0); |
| 343 | |
| 344 | NodeID id_detector_yolo_v3_concat_5 = _graph.add_node<ConcatenateLayerNode>( |
| 345 | 4, |
| 346 | descriptors::ConcatLayerDescriptor{ DataLayoutDimension::HEIGHT }); |
| 347 | INode *node_detector_yolo_v3_concat_5 = _graph.node(id_detector_yolo_v3_concat_5); |
| 348 | node_detector_yolo_v3_concat_5->set_common_node_parameters(NodeParams{ "detector_yolo_v3_concat_5", target }); |
| 349 | _graph.add_connection(id_detector_yolo_v3_mul_3, 0, id_detector_yolo_v3_concat_5, 0); |
| 350 | _graph.add_connection(id_detector_yolo_v3_mul_5, 0, id_detector_yolo_v3_concat_5, 1); |
| 351 | _graph.add_connection(id_detector_yolo_v3_Sigmoid_4, 0, id_detector_yolo_v3_concat_5, 2); |
| 352 | _graph.add_connection(id_detector_yolo_v3_Sigmoid_5, 0, id_detector_yolo_v3_concat_5, 3); |
| 353 | |
| 354 | NodeID id_input_to_detector_1 = _graph.add_node<InputNode>( |
| 355 | TensorDescriptor |
| 356 | { |
| 357 | TensorShape{ 255, 13, 13, 1 }, |
| 358 | DataType::F32, |
| 359 | QuantizationInfo(), |
| 360 | DataLayout::NHWC }); |
| 361 | INode *node_input_to_detector_1 = _graph.node(id_input_to_detector_1); |
| 362 | node_input_to_detector_1->set_common_node_parameters(NodeParams{ "input_to_detector_1", target }); |
| 363 | node_input_to_detector_1->output(0)->set_accessor(support::cpp14::make_unique<DummyAccessor>()); |
| 364 | |
| 365 | NodeID id_detector_yolo_v3_Reshape_2 = _graph.add_node<ReshapeLayerNode>( |
| 366 | TensorShape{ 1, 507, 85 }); |
| 367 | INode *node_detector_yolo_v3_Reshape_2 = _graph.node(id_detector_yolo_v3_Reshape_2); |
| 368 | node_detector_yolo_v3_Reshape_2->set_common_node_parameters(NodeParams{ "detector_yolo_v3_Reshape_2", target }); |
| 369 | _graph.add_connection(id_input_to_detector_1, 0, id_detector_yolo_v3_Reshape_2, 0); |
| 370 | |
| 371 | NodeID id_detector_yolo_v3_split = _graph.add_node<SplitLayerNode>( |
| 372 | 4, |
| 373 | -1, |
| 374 | std::vector<int> { 2, 2, 1, 80 }); |
| 375 | INode *node_detector_yolo_v3_split = _graph.node(id_detector_yolo_v3_split); |
| 376 | node_detector_yolo_v3_split->set_common_node_parameters(NodeParams{ "detector_yolo_v3_split", target }); |
| 377 | _graph.add_connection(id_detector_yolo_v3_Reshape_2, 0, id_detector_yolo_v3_split, 0); |
| 378 | |
| 379 | NodeID id_detector_yolo_v3_Sigmoid = _graph.add_node<ActivationLayerNode>( |
| 380 | ActivationLayerInfo{ ActivationLayerInfo::ActivationFunction::LOGISTIC, 0, 0 }); |
| 381 | INode *node_detector_yolo_v3_Sigmoid = _graph.node(id_detector_yolo_v3_Sigmoid); |
| 382 | node_detector_yolo_v3_Sigmoid->set_common_node_parameters(NodeParams{ "detector_yolo_v3_Sigmoid", target }); |
| 383 | _graph.add_connection(id_detector_yolo_v3_split, 0, id_detector_yolo_v3_Sigmoid, 0); |
| 384 | |
| 385 | NodeID id_detector_yolo_v3_add = _graph.add_node<EltwiseLayerNode>( |
| 386 | descriptors::EltwiseLayerDescriptor |
| 387 | { |
| 388 | EltwiseOperation::Add, |
| 389 | QuantizationInfo() }); |
| 390 | INode *node_detector_yolo_v3_add = _graph.node(id_detector_yolo_v3_add); |
| 391 | node_detector_yolo_v3_add->set_common_node_parameters(NodeParams{ "detector_yolo_v3_add", target }); |
| 392 | _graph.add_connection(id_detector_yolo_v3_Sigmoid, 0, id_detector_yolo_v3_add, 0); |
| 393 | _graph.add_connection(id_detector_yolo_v3_Reshape_3, 0, id_detector_yolo_v3_add, 1); |
| 394 | |
| 395 | NodeID id_detector_yolo_v3_mul = _graph.add_node<EltwiseLayerNode>( |
| 396 | descriptors::EltwiseLayerDescriptor |
| 397 | { |
| 398 | EltwiseOperation::Mul, |
| 399 | QuantizationInfo() }); |
| 400 | INode *node_detector_yolo_v3_mul = _graph.node(id_detector_yolo_v3_mul); |
| 401 | node_detector_yolo_v3_mul->set_common_node_parameters(NodeParams{ "detector_yolo_v3_mul", target }); |
| 402 | _graph.add_connection(id_detector_yolo_v3_add, 0, id_detector_yolo_v3_mul, 0); |
| 403 | _graph.add_connection(id_detector_yolo_v3_mul_y, 0, id_detector_yolo_v3_mul, 1); |
| 404 | |
| 405 | NodeID id_detector_yolo_v3_Sigmoid_1 = _graph.add_node<ActivationLayerNode>( |
| 406 | ActivationLayerInfo{ ActivationLayerInfo::ActivationFunction::LOGISTIC, 0, 0 }); |
| 407 | INode *node_detector_yolo_v3_Sigmoid_1 = _graph.node(id_detector_yolo_v3_Sigmoid_1); |
| 408 | node_detector_yolo_v3_Sigmoid_1->set_common_node_parameters(NodeParams{ "detector_yolo_v3_Sigmoid_1", target }); |
| 409 | _graph.add_connection(id_detector_yolo_v3_split, 2, id_detector_yolo_v3_Sigmoid_1, 0); |
| 410 | |
| 411 | NodeID id_detector_yolo_v3_Exp = _graph.add_node<UnaryEltwiseLayerNode>( |
| 412 | descriptors::UnaryEltwiseLayerDescriptor |
| 413 | { |
| 414 | UnaryEltwiseOperation::Exp, |
| 415 | QuantizationInfo() }); |
| 416 | INode *node_detector_yolo_v3_Exp = _graph.node(id_detector_yolo_v3_Exp); |
| 417 | node_detector_yolo_v3_Exp->set_common_node_parameters(NodeParams{ "detector_yolo_v3_Exp", target }); |
| 418 | _graph.add_connection(id_detector_yolo_v3_split, 1, id_detector_yolo_v3_Exp, 0); |
| 419 | |
| 420 | NodeID id_detector_yolo_v3_mul_2 = _graph.add_node<EltwiseLayerNode>( |
| 421 | descriptors::EltwiseLayerDescriptor |
| 422 | { |
| 423 | EltwiseOperation::Mul, |
| 424 | QuantizationInfo() }); |
| 425 | INode *node_detector_yolo_v3_mul_2 = _graph.node(id_detector_yolo_v3_mul_2); |
| 426 | node_detector_yolo_v3_mul_2->set_common_node_parameters(NodeParams{ "detector_yolo_v3_mul_2", target }); |
| 427 | _graph.add_connection(id_detector_yolo_v3_Exp, 0, id_detector_yolo_v3_mul_2, 0); |
| 428 | _graph.add_connection(id_detector_yolo_v3_mul_1, 0, id_detector_yolo_v3_mul_2, 1); |
| 429 | |
| 430 | NodeID id_detector_yolo_v3_Sigmoid_2 = _graph.add_node<ActivationLayerNode>( |
| 431 | ActivationLayerInfo{ ActivationLayerInfo::ActivationFunction::LOGISTIC, 0, 0 }); |
| 432 | INode *node_detector_yolo_v3_Sigmoid_2 = _graph.node(id_detector_yolo_v3_Sigmoid_2); |
| 433 | node_detector_yolo_v3_Sigmoid_2->set_common_node_parameters(NodeParams{ "detector_yolo_v3_Sigmoid_2", target }); |
| 434 | _graph.add_connection(id_detector_yolo_v3_split, 3, id_detector_yolo_v3_Sigmoid_2, 0); |
| 435 | |
| 436 | NodeID id_detector_yolo_v3_concat_2 = _graph.add_node<ConcatenateLayerNode>( |
| 437 | 4, |
| 438 | descriptors::ConcatLayerDescriptor{ DataLayoutDimension::HEIGHT }); |
| 439 | INode *node_detector_yolo_v3_concat_2 = _graph.node(id_detector_yolo_v3_concat_2); |
| 440 | node_detector_yolo_v3_concat_2->set_common_node_parameters(NodeParams{ "detector_yolo_v3_concat_2", target }); |
| 441 | _graph.add_connection(id_detector_yolo_v3_mul, 0, id_detector_yolo_v3_concat_2, 0); |
| 442 | _graph.add_connection(id_detector_yolo_v3_mul_2, 0, id_detector_yolo_v3_concat_2, 1); |
| 443 | _graph.add_connection(id_detector_yolo_v3_Sigmoid_1, 0, id_detector_yolo_v3_concat_2, 2); |
| 444 | _graph.add_connection(id_detector_yolo_v3_Sigmoid_2, 0, id_detector_yolo_v3_concat_2, 3); |
| 445 | |
| 446 | NodeID id_detector_yolo_v3_concat_9 = _graph.add_node<ConcatenateLayerNode>( |
| 447 | 3, |
| 448 | descriptors::ConcatLayerDescriptor{ DataLayoutDimension::WIDTH }); |
| 449 | INode *node_detector_yolo_v3_concat_9 = _graph.node(id_detector_yolo_v3_concat_9); |
| 450 | node_detector_yolo_v3_concat_9->set_common_node_parameters(NodeParams{ "detector_yolo_v3_concat_9", target }); |
| 451 | _graph.add_connection(id_detector_yolo_v3_concat_2, 0, id_detector_yolo_v3_concat_9, 0); |
| 452 | _graph.add_connection(id_detector_yolo_v3_concat_5, 0, id_detector_yolo_v3_concat_9, 1); |
| 453 | _graph.add_connection(id_detector_yolo_v3_concat_8, 0, id_detector_yolo_v3_concat_9, 2); |
| 454 | |
| 455 | NodeID id_split = _graph.add_node<SplitLayerNode>( |
| 456 | 5, |
| 457 | -1, |
| 458 | std::vector<int> { 1, 1, 1, 1, -1 }); |
| 459 | INode *node_split = _graph.node(id_split); |
| 460 | node_split->set_common_node_parameters(NodeParams{ "split", target }); |
| 461 | _graph.add_connection(id_detector_yolo_v3_concat_9, 0, id_split, 0); |
| 462 | |
| 463 | NodeID id_truediv = _graph.add_node<EltwiseLayerNode>( |
| 464 | descriptors::EltwiseLayerDescriptor |
| 465 | { |
| 466 | EltwiseOperation::Mul, |
| 467 | QuantizationInfo() }); |
| 468 | INode *node_truediv = _graph.node(id_truediv); |
| 469 | node_truediv->set_common_node_parameters(NodeParams{ "truediv", target }); |
| 470 | _graph.add_connection(id_split, 2, id_truediv, 0); |
| 471 | _graph.add_connection(id_ConstantFolding_truediv_recip, 0, id_truediv, 1); |
| 472 | |
| 473 | NodeID id_sub = _graph.add_node<EltwiseLayerNode>( |
| 474 | descriptors::EltwiseLayerDescriptor |
| 475 | { |
| 476 | EltwiseOperation::Sub, |
| 477 | QuantizationInfo() }); |
| 478 | INode *node_sub = _graph.node(id_sub); |
| 479 | node_sub->set_common_node_parameters(NodeParams{ "sub", target }); |
| 480 | _graph.add_connection(id_split, 0, id_sub, 0); |
| 481 | _graph.add_connection(id_truediv, 0, id_sub, 1); |
| 482 | |
| 483 | NodeID id_add = _graph.add_node<EltwiseLayerNode>( |
| 484 | descriptors::EltwiseLayerDescriptor |
| 485 | { |
| 486 | EltwiseOperation::Add, |
| 487 | QuantizationInfo() }); |
| 488 | INode *node_add = _graph.node(id_add); |
| 489 | node_add->set_common_node_parameters(NodeParams{ "add", target }); |
| 490 | _graph.add_connection(id_split, 0, id_add, 0); |
| 491 | _graph.add_connection(id_truediv, 0, id_add, 1); |
| 492 | |
| 493 | NodeID id_truediv_1 = _graph.add_node<EltwiseLayerNode>( |
| 494 | descriptors::EltwiseLayerDescriptor |
| 495 | { |
| 496 | EltwiseOperation::Mul, |
| 497 | QuantizationInfo() }); |
| 498 | INode *node_truediv_1 = _graph.node(id_truediv_1); |
| 499 | node_truediv_1->set_common_node_parameters(NodeParams{ "truediv_1", target }); |
| 500 | _graph.add_connection(id_split, 3, id_truediv_1, 0); |
| 501 | _graph.add_connection(id_ConstantFolding_truediv_1_recip, 0, id_truediv_1, 1); |
| 502 | |
| 503 | NodeID id_sub_1 = _graph.add_node<EltwiseLayerNode>( |
| 504 | descriptors::EltwiseLayerDescriptor |
| 505 | { |
| 506 | EltwiseOperation::Sub, |
| 507 | QuantizationInfo() }); |
| 508 | INode *node_sub_1 = _graph.node(id_sub_1); |
| 509 | node_sub_1->set_common_node_parameters(NodeParams{ "sub_1", target }); |
| 510 | _graph.add_connection(id_split, 1, id_sub_1, 0); |
| 511 | _graph.add_connection(id_truediv_1, 0, id_sub_1, 1); |
| 512 | |
| 513 | NodeID id_add_1 = _graph.add_node<EltwiseLayerNode>( |
| 514 | descriptors::EltwiseLayerDescriptor |
| 515 | { |
| 516 | EltwiseOperation::Add, |
| 517 | QuantizationInfo() }); |
| 518 | INode *node_add_1 = _graph.node(id_add_1); |
| 519 | node_add_1->set_common_node_parameters(NodeParams{ "add_1", target }); |
| 520 | _graph.add_connection(id_split, 1, id_add_1, 0); |
| 521 | _graph.add_connection(id_truediv_1, 0, id_add_1, 1); |
| 522 | |
| 523 | NodeID id_output_boxes = _graph.add_node<ConcatenateLayerNode>( |
| 524 | 5, |
| 525 | descriptors::ConcatLayerDescriptor{ DataLayoutDimension::HEIGHT }); |
| 526 | INode *node_output_boxes = _graph.node(id_output_boxes); |
| 527 | node_output_boxes->set_common_node_parameters(NodeParams{ "output_boxes", target }); |
| 528 | _graph.add_connection(id_sub, 0, id_output_boxes, 0); |
| 529 | _graph.add_connection(id_sub_1, 0, id_output_boxes, 1); |
| 530 | _graph.add_connection(id_add, 0, id_output_boxes, 2); |
| 531 | _graph.add_connection(id_add_1, 0, id_output_boxes, 3); |
| 532 | _graph.add_connection(id_split, 4, id_output_boxes, 4); |
| 533 | |
| 534 | NodeID id_output_140640247016360 = _graph.add_node<OutputNode>(); |
| 535 | INode *node_output_140640247016360 = _graph.node(id_output_140640247016360); |
| 536 | node_output_140640247016360->set_common_node_parameters(NodeParams{ "output_140640247016360", target }); |
| 537 | _graph.add_connection(id_output_boxes, 0, id_output_140640247016360, 0); |
| 538 | node_output_140640247016360->input(0)->set_accessor(support::cpp14::make_unique<DummyAccessor>(0)); |
| 539 | |
| 540 | return true; |
| 541 | } |
| 542 | |
| 543 | Graph &graph() |
| 544 | { |
| 545 | return _graph; |
| 546 | } |
| 547 | |
| 548 | private: |
| 549 | Graph _graph; |
| 550 | }; |
| 551 | class GraphYoloV3OutputDetectorExample : public Example |
| 552 | { |
| 553 | public: |
| 554 | GraphYoloV3OutputDetectorExample() |
| 555 | : cmd_parser(), common_opts(cmd_parser), common_params() |
| 556 | { |
| 557 | } |
| 558 | |
| 559 | bool do_setup(int argc, char **argv) override |
| 560 | { |
| 561 | // Parse arguments |
| 562 | cmd_parser.parse(argc, argv); |
| 563 | cmd_parser.validate(); |
| 564 | |
| 565 | // Consume common parameters |
| 566 | common_params = consume_common_graph_parameters(common_opts); |
| 567 | |
| 568 | // Return when help menu is requested |
| 569 | if(common_params.help) |
| 570 | { |
| 571 | cmd_parser.print_help(argv[0]); |
| 572 | return false; |
| 573 | } |
| 574 | |
| 575 | // Print parameter values |
| 576 | std::cout << common_params << std::endl; |
| 577 | |
| 578 | model.setup(common_params.data_path, common_params.target); |
| 579 | |
| 580 | GraphConfig config; |
| 581 | config.num_threads = common_params.threads; |
| 582 | config.use_tuner = common_params.enable_tuner; |
| 583 | config.tuner_mode = common_params.tuner_mode; |
| 584 | config.tuner_file = common_params.tuner_file; |
| 585 | |
| 586 | context.set_config(config); |
| 587 | |
| 588 | auto pass_manager = create_default_pass_manager(common_params.target, config); |
| 589 | manager.finalize_graph(model.graph(), context, pass_manager, common_params.target); |
| 590 | |
| 591 | return true; |
| 592 | } |
| 593 | |
| 594 | void do_run() override |
| 595 | { |
| 596 | manager.execute_graph(model.graph()); |
| 597 | } |
| 598 | |
| 599 | private: |
| 600 | CommandLineParser cmd_parser; |
| 601 | CommonGraphOptions common_opts; |
| 602 | CommonGraphParams common_params; |
| 603 | |
| 604 | GraphContext context{}; |
| 605 | GraphManager manager{}; |
| 606 | |
| 607 | GraphYoloV3OutputDetector model{}; |
| 608 | }; |
| 609 | |
| 610 | int main(int argc, char **argv) |
| 611 | { |
| 612 | return run_example<GraphYoloV3OutputDetectorExample>(argc, argv); |
| 613 | } |