-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathopenlane_tiofusiondq_r50e24.py
344 lines (291 loc) · 9.01 KB
/
openlane_tiofusiondq_r50e24.py
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
from mmengine import read_base
map_class = ('white-dash', 'white-solid',
'yellow-dash', 'yellow-solid',
'curbside')
from model.decoder.fusion.tiofusiondq_decoder import TransformerDecoderLayer
from model.decoder.fusion.tiofusiondq_decoder import FusionDqBevDecoder
from mmengine.config import read_base
from mmdet3d.datasets import LoadPointsFromFile
from datasets.nuscenes_map_dataset import CustomNuScenesMapDataset
from datasets.pipeline.formating import PackDataToInputs, MakeLineGts
from datasets.pipeline.loading import LoadMultiViewImageFromFiles
from datasets.pipeline.transform_3d import ScaleImageMultiViewImage, PhotoMetricDistortion3DMultiViewImage, \
NormalizeMultiViewImage, PointToDepthMultiViewImage, PadMultiViewImageAndDepth
from mmcv.ops import MultiScaleDeformableAttention
from mmcv.cnn.bricks.transformer import FFN, MultiheadAttention
from mmdet.models.backbones.resnet import ResNet
from mmdet.models.necks.fpn import FPN
from torch.nn import ReLU, Dropout
from model.pv2bev_encoder.LSSTransform import LSSTransform
from model.evaluator.fusion.tiofusion_metric import Metric
from datasets.fusion.openlane_map_dataset_fusion import CustomOpenlaneMapDatasetFusion
from model.losses.loss import SimpleLoss, PtsL1Loss, PtsDirCosLoss
from mmdet.models import FocalLoss
from model.pv2bev_encoder.BEVFormEncoder import BEVFormerEncoder
from model.pv2bev_encoder.BEVFormEncoder import BEVFormerLayer
from model.pv2bev_encoder.temporal_self_attention import TemporalSelfAttention
from model.pv2bev_encoder.geometry_kernel_attention import GeometryKernelAttention
from model.pv2bev_encoder.geometry_kernel_attention import GeometrySptialCrossAttention
with read_base():
from .default_runtime import *
from model.detectors.fusion.tiofusion import TIOFUSION
from mmengine.dataset import DefaultSampler
dim = 256
num_vec_len = 10
bev_h = 100
bev_w = 100
num_cams=1
pc_range = (-15.0, 0.0, -2.0, 15.0, 40.0, 2.0)
voxel_size = (0.15, 0.15, 4)
queue_len = 2
model_root = './'
data_root='./data/images/'
batch_size=8
bev_h = 100
bev_w = 100
num_vec_len = 10
num_vec_one2one=50
mean = (123.675, 116.28, 103.53)
std = (58.395, 57.12, 57.375)
bev_loss = False
pv_loss = False
model = dict(
type=TIOFUSION,
use_grid_mask=True,
embed_dims=dim,
num_cams=num_cams,
num_vec_len=num_vec_len,
num_vec_one2one=num_vec_one2one,
bev_h=bev_h,
bev_w=bev_w,
num_class=len(map_class),
pc_range=pc_range,
loss_sim_weight=0.1,
img_backbone=dict(
type=ResNet,
depth=50,
out_indices=(3,),
frozen_stages=1,
norm_cfg=dict(type='BN', requires_grad=False),
norm_eval=True,
init_cfg=dict(
type='Pretrained',
checkpoint='./ckpts/resnet50-11ad3fa6.pth'
)
),
img_neck=dict(
type=FPN,
in_channels=[2048],
out_channels=dim,
add_extra_convs='on_output',
num_outs=1,
relu_before_extra_convs=True
),
pv2bev_encoder=dict(
type=BEVFormerEncoder,
num_layers=1,
pc_range=pc_range,
num_points_in_pillar=4,
return_intermediate=False,
num_cams=num_cams,
bev_h=bev_h,
bev_w=bev_w,
transformerlayers=dict(
type=BEVFormerLayer,
attn_cfgs=[
dict(
type=TemporalSelfAttention,
embed_dims=dim,
num_levels=1),
dict(
type=GeometrySptialCrossAttention,
pc_range=pc_range,
num_cams=num_cams,
attention=dict(
type=GeometryKernelAttention,
embed_dims=dim,
num_heads=4,
dilation=1,
kernel_size=(3,5),
num_levels=1),
embed_dims=dim,
)
],
feedforward_channels=dim,
ffn_dropout=0.1,
operation_order=('self_attn', 'norm', 'cross_attn', 'norm',
'ffn', 'norm'))),
decoder=dict(
type=FusionDqBevDecoder,
num_layers=6,
transformerlayers=dict(
type=TransformerDecoderLayer,
attn_cfgs=[
dict(
type=MultiheadAttention,
embed_dims=dim,
num_heads=8,
attn_drop=0.1,
dropout_layer=dict(type=Dropout, p=0.1)
),
dict(
type=MultiheadAttention,
embed_dims=dim,
num_heads=8,
attn_drop=0.1,
dropout_layer=dict(type=Dropout, p=0.1)
),
dict(
type=MultiScaleDeformableAttention,
embed_dims=dim,
num_levels=1
)
],
ffn_cfgs=dict(
type=FFN,
embed_dims=256,
feedforward_channels=dim * 2,
num_fcs=2,
ffn_drop=0.1,
act_cfg=dict(type=ReLU, inplace=True),
),
operation_order=('self_attn', 'norm', 'self_attn', 'norm', 'cross_attn', 'norm',
'ffn', 'norm')
)
),
cls_loss=dict(
type=FocalLoss,
use_sigmoid=True,
gamma=2.0,
alpha=0.25,
loss_weight=2.0
),
pts_loss=dict(
type=PtsL1Loss,
loss_weight=5.0
),
dir_loss=dict(
type=PtsDirCosLoss,
loss_weight=0.005
)
)
train_pipeline = [
dict(type=LoadMultiViewImageFromFiles, to_float32=True),
dict(type=ScaleImageMultiViewImage, scale=5/12),
dict(type=PhotoMetricDistortion3DMultiViewImage),
dict(type=NormalizeMultiViewImage, mean=mean, std=std),
dict(type=PadMultiViewImageAndDepth, size_divisor=32),
dict(type=MakeLineGts,
num_vec_len=num_vec_len,
bev=(bev_h, bev_w),
bev_loss=bev_loss,
pv_loss=pv_loss,
bev_down_sample=1,
feat_down_sample=32,
z_min=3,
pts_pattern='v1'
),
dict(type=PackDataToInputs)
]
test_pipeline = [
dict(type=LoadMultiViewImageFromFiles, to_float32=True),
dict(type=ScaleImageMultiViewImage, scale=0.5),
dict(type=NormalizeMultiViewImage, mean=mean, std=std),
dict(type=PadMultiViewImageAndDepth, size_divisor=32),
dict(type=MakeLineGts,
num_vec_len=num_vec_len,
bev=(bev_h, bev_w),
bev_loss=False,
pv_loss=False,
pts_pattern='v1'
),
dict(type=PackDataToInputs)
]
train_dataloader = dict(
dataset=dict(
type=CustomOpenlaneMapDatasetFusion,
ann_file=model_root+'openlane_map_train.pkl',
data_path=data_root,
pipeline=train_pipeline,
queue_length=queue_len,
),
sampler=dict(
type='DefaultSampler',
shuffle=True),
collate_fn=dict(type='default_collate'),
batch_size=batch_size,
pin_memory=True,
num_workers=4)
val_dataloader = dict(
dataset=dict(
type=CustomOpenlaneMapDatasetFusion,
ann_file=model_root+'openlane_map_val.pkl',
data_path=data_root,
pipeline=test_pipeline,
queue_length=queue_len,
test_mode=True
),
sampler=dict(
type='DefaultSampler',
shuffle=False),
collate_fn=dict(type='default_collate'),
batch_size=1,
pin_memory=True,
num_workers=2)
test_dataloader = val_dataloader
train_cfg = dict(
by_epoch=True,
max_epochs=24,
val_begin=100,
val_interval=100
)
val_cfg = dict(type='ValLoop')
val_evaluator = dict(
type=Metric,
metric='chamfer',
classes=map_class,
score_thresh=0.00,
prefix='',
line_width=2.0,
)
test_cfg = dict(type='TestLoop')
test_evaluator = dict(
type=Metric,
metric='chamfer',
classes=map_class,
save=True,
save_path='',
score_thresh=0.00,
prefix='',
line_width=2.0,
)
optim_wrapper = dict(
type='AmpOptimWrapper',
optimizer=dict(
type='AdamW',
lr=1.5e-4,
weight_decay=0.00125
),
paramwise_cfg=dict(
custom_keys={
'img_backbone': dict(lr_mult=0.1),
}
),
clip_grad=dict(max_norm=35, norm_type=2),
)
end = 4000
param_scheduler = [
dict(
type='LinearLR', start_factor=1.0 / 3, by_epoch=False, begin=0, end=end),
dict(
type='CosineAnnealingLR',
T_max=train_cfg['max_epochs'],
by_epoch=True,
convert_to_iter_based=True,
eta_min_ratio=1e-3
)
]
randomness = dict(seed=0)
load_from = None
resume = False
default_hooks['checkpoint'] = dict(type='CheckpointHook', interval=1)