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