blob: 6278565aa3e3c00d706f22becf67fdfc7e80e25f [file] [log] [blame]
Sheri Zhang16dddd22020-05-27 15:03:48 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2020 Arm Limited.
Sheri Zhang16dddd22020-05-27 15:03:48 +01003 *
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
33using namespace arm_compute::graph;
34using namespace arm_compute::utils;
35
36class GraphYoloV3OutputDetector
37{
38public:
39 GraphYoloV3OutputDetector()
40 : _graph(0, "GraphYoloV3OutputDetector")
41 {
42 }
43
Michele Di Giorgiod3556532020-06-24 16:57:46 +010044 bool setup(const CommonGraphParams &common_params, const SimpleOption<std::string> &expected_output_filename)
Sheri Zhang16dddd22020-05-27 15:03:48 +010045 {
46 using namespace arm_compute;
47 using namespace graph_utils;
48
Michele Di Giorgiod3556532020-06-24 16:57:46 +010049 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 Zhang16dddd22020-05-27 15:03:48 +010056 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 Giorgiod3556532020-06-24 16:57:46 +010062 data_layout });
Sheri Zhang16dddd22020-05-27 15:03:48 +010063 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 Giorgiod3556532020-06-24 16:57:46 +010065 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 Zhang16dddd22020-05-27 15:03:48 +010066
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 Giorgiod3556532020-06-24 16:57:46 +010073 data_layout });
Sheri Zhang16dddd22020-05-27 15:03:48 +010074 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 Giorgiod3556532020-06-24 16:57:46 +010076 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 Zhang16dddd22020-05-27 15:03:48 +010077
78 NodeID id_detector_yolo_v3_mul_6_y = _graph.add_node<ConstNode>(
79 TensorDescriptor
80 {
Michele Di Giorgiod3556532020-06-24 16:57:46 +010081 TensorShape{ 2 },
Sheri Zhang16dddd22020-05-27 15:03:48 +010082 DataType::F32,
83 QuantizationInfo(),
Michele Di Giorgiod3556532020-06-24 16:57:46 +010084 data_layout });
Sheri Zhang16dddd22020-05-27 15:03:48 +010085 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 Giorgiod3556532020-06-24 16:57:46 +010087 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 Zhang16dddd22020-05-27 15:03:48 +010088
89 NodeID id_detector_yolo_v3_mul_3_y = _graph.add_node<ConstNode>(
90 TensorDescriptor
91 {
Michele Di Giorgiod3556532020-06-24 16:57:46 +010092 TensorShape{ 2 },
Sheri Zhang16dddd22020-05-27 15:03:48 +010093 DataType::F32,
94 QuantizationInfo(),
Michele Di Giorgiod3556532020-06-24 16:57:46 +010095 data_layout });
Sheri Zhang16dddd22020-05-27 15:03:48 +010096 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 Giorgiod3556532020-06-24 16:57:46 +010098 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 Zhang16dddd22020-05-27 15:03:48 +010099
100 NodeID id_detector_yolo_v3_mul_y = _graph.add_node<ConstNode>(
101 TensorDescriptor
102 {
Michele Di Giorgiod3556532020-06-24 16:57:46 +0100103 TensorShape{ 2 },
Sheri Zhang16dddd22020-05-27 15:03:48 +0100104 DataType::F32,
105 QuantizationInfo(),
Michele Di Giorgiod3556532020-06-24 16:57:46 +0100106 data_layout });
Sheri Zhang16dddd22020-05-27 15:03:48 +0100107 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 Giorgiod3556532020-06-24 16:57:46 +0100109 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 Zhang16dddd22020-05-27 15:03:48 +0100110
111 NodeID id_detector_yolo_v3_mul_7 = _graph.add_node<ConstNode>(
112 TensorDescriptor
113 {
Michele Di Giorgiod3556532020-06-24 16:57:46 +0100114 TensorShape{ 2, 8112 },
Sheri Zhang16dddd22020-05-27 15:03:48 +0100115 DataType::F32,
116 QuantizationInfo(),
Michele Di Giorgiod3556532020-06-24 16:57:46 +0100117 data_layout });
Sheri Zhang16dddd22020-05-27 15:03:48 +0100118 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 Giorgiod3556532020-06-24 16:57:46 +0100120 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 Zhang16dddd22020-05-27 15:03:48 +0100121
122 NodeID id_detector_yolo_v3_Reshape_11 = _graph.add_node<ConstNode>(
123 TensorDescriptor
124 {
Michele Di Giorgiod3556532020-06-24 16:57:46 +0100125 TensorShape{ 2, 8112 },
Sheri Zhang16dddd22020-05-27 15:03:48 +0100126 DataType::F32,
127 QuantizationInfo(),
Michele Di Giorgiod3556532020-06-24 16:57:46 +0100128 data_layout });
Sheri Zhang16dddd22020-05-27 15:03:48 +0100129 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 Giorgiod3556532020-06-24 16:57:46 +0100131 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 Zhang16dddd22020-05-27 15:03:48 +0100132
133 NodeID id_detector_yolo_v3_mul_4 = _graph.add_node<ConstNode>(
134 TensorDescriptor
135 {
Michele Di Giorgiod3556532020-06-24 16:57:46 +0100136 TensorShape{ 2, 2028 },
Sheri Zhang16dddd22020-05-27 15:03:48 +0100137 DataType::F32,
138 QuantizationInfo(),
Michele Di Giorgiod3556532020-06-24 16:57:46 +0100139 data_layout });
Sheri Zhang16dddd22020-05-27 15:03:48 +0100140 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 Giorgiod3556532020-06-24 16:57:46 +0100142 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 Zhang16dddd22020-05-27 15:03:48 +0100143
144 NodeID id_detector_yolo_v3_Reshape_7 = _graph.add_node<ConstNode>(
145 TensorDescriptor
146 {
Michele Di Giorgiod3556532020-06-24 16:57:46 +0100147 TensorShape{ 2, 2028 },
Sheri Zhang16dddd22020-05-27 15:03:48 +0100148 DataType::F32,
149 QuantizationInfo(),
Michele Di Giorgiod3556532020-06-24 16:57:46 +0100150 data_layout });
Sheri Zhang16dddd22020-05-27 15:03:48 +0100151 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 Giorgiod3556532020-06-24 16:57:46 +0100153 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 Zhang16dddd22020-05-27 15:03:48 +0100154
155 NodeID id_detector_yolo_v3_mul_1 = _graph.add_node<ConstNode>(
156 TensorDescriptor
157 {
Michele Di Giorgiod3556532020-06-24 16:57:46 +0100158 TensorShape{ 2, 507 },
Sheri Zhang16dddd22020-05-27 15:03:48 +0100159 DataType::F32,
160 QuantizationInfo(),
Michele Di Giorgiod3556532020-06-24 16:57:46 +0100161 data_layout });
Sheri Zhang16dddd22020-05-27 15:03:48 +0100162 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 Giorgiod3556532020-06-24 16:57:46 +0100164 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 Zhang16dddd22020-05-27 15:03:48 +0100165
166 NodeID id_detector_yolo_v3_Reshape_3 = _graph.add_node<ConstNode>(
167 TensorDescriptor
168 {
Michele Di Giorgiod3556532020-06-24 16:57:46 +0100169 TensorShape{ 2, 507 },
Sheri Zhang16dddd22020-05-27 15:03:48 +0100170 DataType::F32,
171 QuantizationInfo(),
Michele Di Giorgiod3556532020-06-24 16:57:46 +0100172 data_layout });
Sheri Zhang16dddd22020-05-27 15:03:48 +0100173 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 Giorgiod3556532020-06-24 16:57:46 +0100175 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 Zhang16dddd22020-05-27 15:03:48 +0100176
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 Giorgiod3556532020-06-24 16:57:46 +0100183 data_layout });
Sheri Zhang16dddd22020-05-27 15:03:48 +0100184 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 Giorgiod3556532020-06-24 16:57:46 +0100186 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 Zhang16dddd22020-05-27 15:03:48 +0100187
188 NodeID id_detector_yolo_v3_Reshape_10 = _graph.add_node<ReshapeLayerNode>(
Michele Di Giorgiod3556532020-06-24 16:57:46 +0100189 TensorShape{ 85, 8112 });
Sheri Zhang16dddd22020-05-27 15:03:48 +0100190 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 Giorgiod3556532020-06-24 16:57:46 +0100196 0,
Sheri Zhang16dddd22020-05-27 15:03:48 +0100197 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 Giorgiod3556532020-06-24 16:57:46 +0100261 descriptors::ConcatLayerDescriptor{ x_dim });
Sheri Zhang16dddd22020-05-27 15:03:48 +0100262 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 Giorgiod3556532020-06-24 16:57:46 +0100275 data_layout });
Sheri Zhang16dddd22020-05-27 15:03:48 +0100276 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 Giorgiod3556532020-06-24 16:57:46 +0100278 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 Zhang16dddd22020-05-27 15:03:48 +0100279
280 NodeID id_detector_yolo_v3_Reshape_6 = _graph.add_node<ReshapeLayerNode>(
Michele Di Giorgiod3556532020-06-24 16:57:46 +0100281 TensorShape{ 85, 2028 });
Sheri Zhang16dddd22020-05-27 15:03:48 +0100282 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 Giorgiod3556532020-06-24 16:57:46 +0100288 0,
Sheri Zhang16dddd22020-05-27 15:03:48 +0100289 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 Giorgiod3556532020-06-24 16:57:46 +0100353 descriptors::ConcatLayerDescriptor{ x_dim });
Sheri Zhang16dddd22020-05-27 15:03:48 +0100354 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 Giorgiod3556532020-06-24 16:57:46 +0100367 data_layout });
Sheri Zhang16dddd22020-05-27 15:03:48 +0100368 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 Giorgiod3556532020-06-24 16:57:46 +0100370 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 Zhang16dddd22020-05-27 15:03:48 +0100371
372 NodeID id_detector_yolo_v3_Reshape_2 = _graph.add_node<ReshapeLayerNode>(
Michele Di Giorgiod3556532020-06-24 16:57:46 +0100373 TensorShape{ 85, 507 });
Sheri Zhang16dddd22020-05-27 15:03:48 +0100374 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 Giorgiod3556532020-06-24 16:57:46 +0100380 0,
Sheri Zhang16dddd22020-05-27 15:03:48 +0100381 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 Giorgiod3556532020-06-24 16:57:46 +0100445 descriptors::ConcatLayerDescriptor{ x_dim });
Sheri Zhang16dddd22020-05-27 15:03:48 +0100446 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 Giorgiod3556532020-06-24 16:57:46 +0100455 descriptors::ConcatLayerDescriptor{ y_dim });
Sheri Zhang16dddd22020-05-27 15:03:48 +0100456 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 Giorgiod3556532020-06-24 16:57:46 +0100464 0,
Sheri Zhang16dddd22020-05-27 15:03:48 +0100465 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 Giorgiod3556532020-06-24 16:57:46 +0100532 descriptors::ConcatLayerDescriptor{ x_dim });
Sheri Zhang16dddd22020-05-27 15:03:48 +0100533 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 Giorgiod3556532020-06-24 16:57:46 +0100545 node_output_140640247016360->input(0)->set_accessor(get_npy_output_accessor(expected_output_filename.value(), TensorShape(85U, 10647U), DataType::F32, data_layout));
Sheri Zhang16dddd22020-05-27 15:03:48 +0100546
547 return true;
548 }
549
550 Graph &graph()
551 {
552 return _graph;
553 }
554
555private:
556 Graph _graph;
557};
558class GraphYoloV3OutputDetectorExample : public Example
559{
560public:
561 GraphYoloV3OutputDetectorExample()
562 : cmd_parser(), common_opts(cmd_parser), common_params()
563 {
Michele Di Giorgiod3556532020-06-24 16:57:46 +0100564 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 Zhang16dddd22020-05-27 15:03:48 +0100566 }
Michele Di Giorgiod3556532020-06-24 16:57:46 +0100567 GraphYoloV3OutputDetectorExample(const GraphYoloV3OutputDetectorExample &) = delete;
568 GraphYoloV3OutputDetectorExample &operator=(const GraphYoloV3OutputDetectorExample &) = delete;
Sheri Zhang16dddd22020-05-27 15:03:48 +0100569
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 Giorgiod3556532020-06-24 16:57:46 +0100589 model.setup(common_params, *expected_output_filename);
Sheri Zhang16dddd22020-05-27 15:03:48 +0100590
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
610private:
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 Giorgiod3556532020-06-24 16:57:46 +0100619
620 SimpleOption<std::string> *expected_output_filename{ nullptr };
Sheri Zhang16dddd22020-05-27 15:03:48 +0100621};
622
623int main(int argc, char **argv)
624{
625 return run_example<GraphYoloV3OutputDetectorExample>(argc, argv);
626}