forked from NVIDIA-AI-IOT/redtail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nvsmall_1025x321_net.cpp
370 lines (301 loc) · 18.9 KB
/
nvsmall_1025x321_net.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
// Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
// Full license terms provided in LICENSE.md file.
//-------------------------------------------------------------------
// !!! This file was automatically generated. Do not edit. !!!
//-------------------------------------------------------------------
#include <NvInfer.h>
#include <cassert>
#include <string>
#include <unordered_map>
#include "redtail_tensorrt_plugins.h"
namespace redtail { namespace tensorrt
{
using namespace nvinfer1;
using weight_map = std::unordered_map<std::string, Weights>;
INetworkDefinition* createNVSmall1025x321Network(IBuilder& builder, IPluginContainer& plugin_factory,
DimsCHW img_dims, const weight_map& weights, DataType data_type,
ILogger& log)
{
INetworkDefinition* network = builder.createNetwork();
assert(network != nullptr);
// Input tensor.
auto left = network->addInput("left", DataType::kFLOAT, img_dims);
assert(left != nullptr);
// Input tensor.
auto right = network->addInput("right", DataType::kFLOAT, img_dims);
assert(right != nullptr);
// Scaling op.
auto left_scale = network->addScale(*left, ScaleMode::kUNIFORM,
weights.at("left_scale_shift"), weights.at("left_scale_scale"), weights.at("left_scale_power"));
assert(left_scale != nullptr);
// Scaling op.
auto right_scale = network->addScale(*right, ScaleMode::kUNIFORM,
weights.at("right_scale_shift"), weights.at("right_scale_scale"), weights.at("right_scale_power"));
assert(right_scale != nullptr);
// left_conv1 convolution op.
auto left_conv1 = network->addConvolution(*left_scale->getOutput(0), 32, DimsHW {5, 5},
weights.at("left_conv1_k"), weights.at("left_conv1_b"));
assert(left_conv1 != nullptr);
left_conv1->setStride( DimsHW {2, 2});
left_conv1->setPadding(DimsHW {2, 2});
// left_conv1_act ELU activation op.
auto left_conv1_act = addElu(plugin_factory, *network, *left_conv1->getOutput(0), data_type, "left_conv1_act");
assert(left_conv1_act != nullptr);
// right_conv1 convolution op.
auto right_conv1 = network->addConvolution(*right_scale->getOutput(0), 32, DimsHW {5, 5},
weights.at("right_conv1_k"), weights.at("right_conv1_b"));
assert(right_conv1 != nullptr);
right_conv1->setStride( DimsHW {2, 2});
right_conv1->setPadding(DimsHW {2, 2});
// right_conv1_act ELU activation op.
auto right_conv1_act = addElu(plugin_factory, *network, *right_conv1->getOutput(0), data_type, "right_conv1_act");
assert(right_conv1_act != nullptr);
// left_conv2 convolution op.
auto left_conv2 = network->addConvolution(*left_conv1_act->getOutput(0), 32, DimsHW {3, 3},
weights.at("left_conv2_k"), weights.at("left_conv2_b"));
assert(left_conv2 != nullptr);
left_conv2->setStride( DimsHW {1, 1});
left_conv2->setPadding(DimsHW {1, 1});
// left_conv2_act ELU activation op.
auto left_conv2_act = addElu(plugin_factory, *network, *left_conv2->getOutput(0), data_type, "left_conv2_act");
assert(left_conv2_act != nullptr);
// right_conv2 convolution op.
auto right_conv2 = network->addConvolution(*right_conv1_act->getOutput(0), 32, DimsHW {3, 3},
weights.at("right_conv2_k"), weights.at("right_conv2_b"));
assert(right_conv2 != nullptr);
right_conv2->setStride( DimsHW {1, 1});
right_conv2->setPadding(DimsHW {1, 1});
// right_conv2_act ELU activation op.
auto right_conv2_act = addElu(plugin_factory, *network, *right_conv2->getOutput(0), data_type, "right_conv2_act");
assert(right_conv2_act != nullptr);
// left_conv3 convolution op.
auto left_conv3 = network->addConvolution(*left_conv2_act->getOutput(0), 32, DimsHW {3, 3},
weights.at("left_conv3_k"), weights.at("left_conv3_b"));
assert(left_conv3 != nullptr);
left_conv3->setStride( DimsHW {1, 1});
left_conv3->setPadding(DimsHW {1, 1});
// left_conv3_act ELU activation op.
auto left_conv3_act = addElu(plugin_factory, *network, *left_conv3->getOutput(0), data_type, "left_conv3_act");
assert(left_conv3_act != nullptr);
// right_conv3 convolution op.
auto right_conv3 = network->addConvolution(*right_conv2_act->getOutput(0), 32, DimsHW {3, 3},
weights.at("right_conv3_k"), weights.at("right_conv3_b"));
assert(right_conv3 != nullptr);
right_conv3->setStride( DimsHW {1, 1});
right_conv3->setPadding(DimsHW {1, 1});
// right_conv3_act ELU activation op.
auto right_conv3_act = addElu(plugin_factory, *network, *right_conv3->getOutput(0), data_type, "right_conv3_act");
assert(right_conv3_act != nullptr);
// left_conv4 convolution op.
auto left_conv4 = network->addConvolution(*left_conv3_act->getOutput(0), 32, DimsHW {3, 3},
weights.at("left_conv4_k"), weights.at("left_conv4_b"));
assert(left_conv4 != nullptr);
left_conv4->setStride( DimsHW {1, 1});
left_conv4->setPadding(DimsHW {1, 1});
// left_conv4_act ELU activation op.
auto left_conv4_act = addElu(plugin_factory, *network, *left_conv4->getOutput(0), data_type, "left_conv4_act");
assert(left_conv4_act != nullptr);
// right_conv4 convolution op.
auto right_conv4 = network->addConvolution(*right_conv3_act->getOutput(0), 32, DimsHW {3, 3},
weights.at("right_conv4_k"), weights.at("right_conv4_b"));
assert(right_conv4 != nullptr);
right_conv4->setStride( DimsHW {1, 1});
right_conv4->setPadding(DimsHW {1, 1});
// right_conv4_act ELU activation op.
auto right_conv4_act = addElu(plugin_factory, *network, *right_conv4->getOutput(0), data_type, "right_conv4_act");
assert(right_conv4_act != nullptr);
// left_conv5 convolution op.
auto left_conv5 = network->addConvolution(*left_conv4_act->getOutput(0), 32, DimsHW {3, 3},
weights.at("left_conv5_k"), weights.at("left_conv5_b"));
assert(left_conv5 != nullptr);
left_conv5->setStride( DimsHW {1, 1});
left_conv5->setPadding(DimsHW {1, 1});
// right_conv5 convolution op.
auto right_conv5 = network->addConvolution(*right_conv4_act->getOutput(0), 32, DimsHW {3, 3},
weights.at("right_conv5_k"), weights.at("right_conv5_b"));
assert(right_conv5 != nullptr);
right_conv5->setStride( DimsHW {1, 1});
right_conv5->setPadding(DimsHW {1, 1});
// cost_vol cost volume op.
auto cost_vol = addCostVolume(plugin_factory, *network, *left_conv5->getOutput(0), *right_conv5->getOutput(0),
CostVolumeType::kDefault, 48, "cost_vol");
assert(cost_vol != nullptr);
// conv3D_1 3D convolution op.
auto conv3D_1 = addConv3D(plugin_factory, *network, *cost_vol->getOutput(0),
Conv3DType::kTensorFlow, {5, {32, 3, 64, 3, 3}},
Dims{3, {1, 1, 1}}, Dims{3, {1, 1, 1}}, Dims{3, {1, 1, 1}},
weights.at("conv3D_1_k"), weights.at("conv3D_1_b"),
"conv3D_1");
assert(conv3D_1 != nullptr);
// Transpose output: KDHW -> DKHW for conv3d and DKHW -> KDHW for conv3d_transpose
auto conv3D_1_tran = addTransform(plugin_factory, *network, *conv3D_1->getOutput(0), {1, 0, 2, 3}, "conv3D_1_tran_transform");
assert(conv3D_1_tran != nullptr);
// conv3D_1_act ELU activation op.
auto conv3D_1_act = addElu(plugin_factory, *network, *conv3D_1_tran->getOutput(0), data_type, "conv3D_1_act");
assert(conv3D_1_act != nullptr);
// conv3D_2 3D convolution op.
auto conv3D_2 = addConv3D(plugin_factory, *network, *conv3D_1_act->getOutput(0),
Conv3DType::kTensorFlow, {5, {32, 3, 32, 3, 3}},
Dims{3, {1, 1, 1}}, Dims{3, {1, 1, 1}}, Dims{3, {1, 1, 1}},
weights.at("conv3D_2_k"), weights.at("conv3D_2_b"),
"conv3D_2");
assert(conv3D_2 != nullptr);
// Transpose output: KDHW -> DKHW for conv3d and DKHW -> KDHW for conv3d_transpose
auto conv3D_2_tran = addTransform(plugin_factory, *network, *conv3D_2->getOutput(0), {1, 0, 2, 3}, "conv3D_2_tran_transform");
assert(conv3D_2_tran != nullptr);
// conv3D_2_act ELU activation op.
auto conv3D_2_act = addElu(plugin_factory, *network, *conv3D_2_tran->getOutput(0), data_type, "conv3D_2_act");
assert(conv3D_2_act != nullptr);
// conv3D_3ds_pad padding op.
auto conv3D_3ds_pad = addPad(plugin_factory, *network, *conv3D_2_act->getOutput(0), {0, 0, 0, 0}, {1, 0, 0, 0}, "conv3D_3ds_pad");
assert(conv3D_3ds_pad != nullptr);
// conv3D_3ds 3D convolution op.
auto conv3D_3ds = addConv3D(plugin_factory, *network, *conv3D_3ds_pad->getOutput(0),
Conv3DType::kTensorFlow, {5, {64, 3, 32, 3, 3}},
Dims{3, {2, 2, 2}}, Dims{3, {0, 1, 1}}, Dims{3, {1, 1, 1}},
weights.at("conv3D_3ds_k"), weights.at("conv3D_3ds_b"),
"conv3D_3ds");
assert(conv3D_3ds != nullptr);
// Transpose output: KDHW -> DKHW for conv3d and DKHW -> KDHW for conv3d_transpose
auto conv3D_3ds_tran = addTransform(plugin_factory, *network, *conv3D_3ds->getOutput(0), {1, 0, 2, 3}, "conv3D_3ds_tran_transform");
assert(conv3D_3ds_tran != nullptr);
// conv3D_3ds_act ELU activation op.
auto conv3D_3ds_act = addElu(plugin_factory, *network, *conv3D_3ds_tran->getOutput(0), data_type, "conv3D_3ds_act");
assert(conv3D_3ds_act != nullptr);
// conv3D_4 3D convolution op.
auto conv3D_4 = addConv3D(plugin_factory, *network, *conv3D_3ds_act->getOutput(0),
Conv3DType::kTensorFlow, {5, {64, 3, 64, 3, 3}},
Dims{3, {1, 1, 1}}, Dims{3, {1, 1, 1}}, Dims{3, {1, 1, 1}},
weights.at("conv3D_4_k"), weights.at("conv3D_4_b"),
"conv3D_4");
assert(conv3D_4 != nullptr);
// Transpose output: KDHW -> DKHW for conv3d and DKHW -> KDHW for conv3d_transpose
auto conv3D_4_tran = addTransform(plugin_factory, *network, *conv3D_4->getOutput(0), {1, 0, 2, 3}, "conv3D_4_tran_transform");
assert(conv3D_4_tran != nullptr);
// conv3D_4_act ELU activation op.
auto conv3D_4_act = addElu(plugin_factory, *network, *conv3D_4_tran->getOutput(0), data_type, "conv3D_4_act");
assert(conv3D_4_act != nullptr);
// conv3D_5 3D convolution op.
auto conv3D_5 = addConv3D(plugin_factory, *network, *conv3D_4_act->getOutput(0),
Conv3DType::kTensorFlow, {5, {64, 3, 64, 3, 3}},
Dims{3, {1, 1, 1}}, Dims{3, {1, 1, 1}}, Dims{3, {1, 1, 1}},
weights.at("conv3D_5_k"), weights.at("conv3D_5_b"),
"conv3D_5");
assert(conv3D_5 != nullptr);
// Transpose output: KDHW -> DKHW for conv3d and DKHW -> KDHW for conv3d_transpose
auto conv3D_5_tran = addTransform(plugin_factory, *network, *conv3D_5->getOutput(0), {1, 0, 2, 3}, "conv3D_5_tran_transform");
assert(conv3D_5_tran != nullptr);
// conv3D_5_act ELU activation op.
auto conv3D_5_act = addElu(plugin_factory, *network, *conv3D_5_tran->getOutput(0), data_type, "conv3D_5_act");
assert(conv3D_5_act != nullptr);
// conv3D_6ds_pad padding op.
auto conv3D_6ds_pad = addPad(plugin_factory, *network, *conv3D_5_act->getOutput(0), {0, 0, 0, 0}, {1, 0, 0, 0}, "conv3D_6ds_pad");
assert(conv3D_6ds_pad != nullptr);
// conv3D_6ds 3D convolution op.
auto conv3D_6ds = addConv3D(plugin_factory, *network, *conv3D_6ds_pad->getOutput(0),
Conv3DType::kTensorFlow, {5, {128, 3, 64, 3, 3}},
Dims{3, {2, 2, 2}}, Dims{3, {0, 1, 1}}, Dims{3, {1, 1, 1}},
weights.at("conv3D_6ds_k"), weights.at("conv3D_6ds_b"),
"conv3D_6ds");
assert(conv3D_6ds != nullptr);
// Transpose output: KDHW -> DKHW for conv3d and DKHW -> KDHW for conv3d_transpose
auto conv3D_6ds_tran = addTransform(plugin_factory, *network, *conv3D_6ds->getOutput(0), {1, 0, 2, 3}, "conv3D_6ds_tran_transform");
assert(conv3D_6ds_tran != nullptr);
// conv3D_6ds_act ELU activation op.
auto conv3D_6ds_act = addElu(plugin_factory, *network, *conv3D_6ds_tran->getOutput(0), data_type, "conv3D_6ds_act");
assert(conv3D_6ds_act != nullptr);
// conv3D_7 3D convolution op.
auto conv3D_7 = addConv3D(plugin_factory, *network, *conv3D_6ds_act->getOutput(0),
Conv3DType::kTensorFlow, {5, {128, 3, 128, 3, 3}},
Dims{3, {1, 1, 1}}, Dims{3, {1, 1, 1}}, Dims{3, {1, 1, 1}},
weights.at("conv3D_7_k"), weights.at("conv3D_7_b"),
"conv3D_7");
assert(conv3D_7 != nullptr);
// Transpose output: KDHW -> DKHW for conv3d and DKHW -> KDHW for conv3d_transpose
auto conv3D_7_tran = addTransform(plugin_factory, *network, *conv3D_7->getOutput(0), {1, 0, 2, 3}, "conv3D_7_tran_transform");
assert(conv3D_7_tran != nullptr);
// conv3D_7_act ELU activation op.
auto conv3D_7_act = addElu(plugin_factory, *network, *conv3D_7_tran->getOutput(0), data_type, "conv3D_7_act");
assert(conv3D_7_act != nullptr);
// conv3D_8 3D convolution op.
auto conv3D_8 = addConv3D(plugin_factory, *network, *conv3D_7_act->getOutput(0),
Conv3DType::kTensorFlow, {5, {128, 3, 128, 3, 3}},
Dims{3, {1, 1, 1}}, Dims{3, {1, 1, 1}}, Dims{3, {1, 1, 1}},
weights.at("conv3D_8_k"), weights.at("conv3D_8_b"),
"conv3D_8");
assert(conv3D_8 != nullptr);
// conv3D_8_act ELU activation op.
auto conv3D_8_act = addElu(plugin_factory, *network, *conv3D_8->getOutput(0), data_type, "conv3D_8_act");
assert(conv3D_8_act != nullptr);
// deconv3D_1 3D transposed convolution op.
Dims deconv3D_1_out_dims{4, {25, 64, 81, 257}};
auto deconv3D_1 = addConv3DTranspose(plugin_factory, *network, *conv3D_8_act->getOutput(0),
Conv3DType::kTensorFlow, {5, {128, 3, 64, 3, 3}}, deconv3D_1_out_dims,
Dims{3, {2, 2, 2}}, Dims{3, {0, 1, 1}}, Dims{3, {0, 1, 1}},
weights.at("deconv3D_1_k"), weights.at("deconv3D_1_b"),
"deconv3D_1");
assert(deconv3D_1 != nullptr);
// deconv3D_1 output slice op.
auto deconv3D_1_slice_layer = addSlice(plugin_factory, *network, *deconv3D_1->getOutput(0),
deconv3D_1_out_dims,
{4, {0, 0, 0, 0}},
{4, {deconv3D_1_out_dims.d[0] - 1, deconv3D_1_out_dims.d[1], deconv3D_1_out_dims.d[2], deconv3D_1_out_dims.d[3]}},
"deconv3D_1_slice");
assert(deconv3D_1_slice_layer != nullptr);
// deconv3D_1_add_skip tensor add op.
auto deconv3D_1_add_skip = network->addElementWise(*(deconv3D_1_slice_layer->getOutput(0)), *(conv3D_5_act->getOutput(0)), ElementWiseOperation::kSUM);
assert(deconv3D_1_add_skip != nullptr);
// deconv3D_1_act ELU activation op.
auto deconv3D_1_act = addElu(plugin_factory, *network, *deconv3D_1_add_skip->getOutput(0), data_type, "deconv3D_1_act");
assert(deconv3D_1_act != nullptr);
// Transpose output: KDHW -> DKHW for conv3d and DKHW -> KDHW for conv3d_transpose
auto deconv3D_1_transform = addTransform(plugin_factory, *network, *deconv3D_1_act->getOutput(0), {1, 0, 2, 3}, "deconv3D_1_transform_transform");
assert(deconv3D_1_transform != nullptr);
// deconv3D_2 3D transposed convolution op.
Dims deconv3D_2_out_dims{4, {49, 32, 161, 513}};
auto deconv3D_2 = addConv3DTranspose(plugin_factory, *network, *deconv3D_1_transform->getOutput(0),
Conv3DType::kTensorFlow, {5, {64, 3, 32, 3, 3}}, deconv3D_2_out_dims,
Dims{3, {2, 2, 2}}, Dims{3, {0, 1, 1}}, Dims{3, {0, 1, 1}},
weights.at("deconv3D_2_k"), weights.at("deconv3D_2_b"),
"deconv3D_2");
assert(deconv3D_2 != nullptr);
// deconv3D_2 output slice op.
auto deconv3D_2_slice_layer = addSlice(plugin_factory, *network, *deconv3D_2->getOutput(0),
deconv3D_2_out_dims,
{4, {0, 0, 0, 0}},
{4, {deconv3D_2_out_dims.d[0] - 1, deconv3D_2_out_dims.d[1], deconv3D_2_out_dims.d[2], deconv3D_2_out_dims.d[3]}},
"deconv3D_2_slice");
assert(deconv3D_2_slice_layer != nullptr);
// deconv3D_2_add_skip tensor add op.
auto deconv3D_2_add_skip = network->addElementWise(*(deconv3D_2_slice_layer->getOutput(0)), *(conv3D_2_act->getOutput(0)), ElementWiseOperation::kSUM);
assert(deconv3D_2_add_skip != nullptr);
// deconv3D_2_act ELU activation op.
auto deconv3D_2_act = addElu(plugin_factory, *network, *deconv3D_2_add_skip->getOutput(0), data_type, "deconv3D_2_act");
assert(deconv3D_2_act != nullptr);
// Transpose output: KDHW -> DKHW for conv3d and DKHW -> KDHW for conv3d_transpose
auto deconv3D_2_transform = addTransform(plugin_factory, *network, *deconv3D_2_act->getOutput(0), {1, 0, 2, 3}, "deconv3D_2_transform_transform");
assert(deconv3D_2_transform != nullptr);
// deconv3D_3 3D transposed convolution op.
Dims deconv3D_3_out_dims{4, {97, 1, 321, 1025}};
auto deconv3D_3 = addConv3DTranspose(plugin_factory, *network, *deconv3D_2_transform->getOutput(0),
Conv3DType::kTensorFlow, {5, {32, 3, 1, 3, 3}}, deconv3D_3_out_dims,
Dims{3, {2, 2, 2}}, Dims{3, {0, 1, 1}}, Dims{3, {0, 1, 1}},
weights.at("deconv3D_3_k"), weights.at("deconv3D_3_b"),
"deconv3D_3");
assert(deconv3D_3 != nullptr);
// deconv3D_3 output slice op.
auto deconv3D_3_slice_layer = addSlice(plugin_factory, *network, *deconv3D_3->getOutput(0),
deconv3D_3_out_dims,
{4, {0, 0, 0, 0}},
{4, {deconv3D_3_out_dims.d[0] - 1, deconv3D_3_out_dims.d[1], deconv3D_3_out_dims.d[2], deconv3D_3_out_dims.d[3]}},
"deconv3D_3_slice");
assert(deconv3D_3_slice_layer != nullptr);
// Softargmax.
auto disp = addSoftargmax(plugin_factory, *network, *deconv3D_3_slice_layer->getOutput(0), SoftargmaxType::kMin, "disp_softargmax");
assert(disp != nullptr);
auto disp_out = disp->getOutput(0);
disp_out->setName("disp");
network->markOutput(*disp_out);
return network;
}
} } // namespace