-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvectormapnet_nusc.py
333 lines (315 loc) · 9.79 KB
/
vectormapnet_nusc.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
_base_ = [
'../_base_/default_runtime.py'
]
# model type
type = 'Mapper'
plugin = True
# plugin code dir
plugin_dir = 'plugin/'
# img configs
img_norm_cfg = dict(
mean=[103.530, 116.280, 123.675], std=[1.0, 1.0, 1.0], to_rgb=False)
img_size = (int(128*2), int((16/9*128)*2))
# category configs
cat2id = {
'ped_crossing': 0,
'divider': 1,
'boundary': 2,
}
num_class = max(list(cat2id.values())) + 1
# bev configs
roi_size = (60, 30) # bev range, 60m in x-axis, 30m in y-axis
canvas_size = (200, 100) # bev feature size
# vectorize params
coords_dim = 2 # polylines coordinates dimension, 2 or 3
sample_dist = -1 # sampling params, vectormapnet uses simplify
sample_num = -1 # sampling params, vectormapnet uses simplify
simplify = True # sampling params, vectormapnet uses simplify
# meta info for submission pkl
meta = dict(
use_lidar=False,
use_camera=True,
use_radar=False,
use_external=False,
output_format='vector')
# model configs
head_dim = 256
norm_cfg = dict(type='BN2d')
num_class = max(list(cat2id.values()))+1
num_points = 30
model = dict(
type='VectorMapNet',
backbone_cfg=dict(
type='IPMEncoder',
img_backbone=dict(
type='ResNet',
with_cp=False,
pretrained='open-mmlab://detectron2/resnet50_caffe',
depth=50,
num_stages=4,
out_indices=(0, 1, 2, 3),
frozen_stages=-1,
norm_cfg=norm_cfg,
norm_eval=True,
style='caffe',
dcn=dict(type='DCNv2', deform_groups=1, fallback_on_stride=False),
stage_with_dcn=(False, False, True, True)),
img_neck=dict(
type='FPN',
in_channels=[256, 512, 1024, 2048],
out_channels=128,
start_level=0,
add_extra_convs=True,
# extra_convs_on_inputs=False, # use P5
num_outs=4,
norm_cfg=norm_cfg,
relu_before_extra_convs=True),
upsample=dict(
zoom_size=(1, 2, 4, 8),
in_channels=128,
out_channels=128,),
xbound=[-roi_size[0]/2, roi_size[0]/2, roi_size[0]/canvas_size[0]],
ybound=[-roi_size[1]/2, roi_size[1]/2, roi_size[1]/canvas_size[1]],
heights=[-1.1, 0, 0.5, 1.1],
out_channels=128,
pretrained=None,
num_cam=6,
),
head_cfg=dict(
type='DGHead',
augmentation=True,
augmentation_kwargs=dict(
p=0.3,scale=0.01,
bbox_type='xyxy',
),
det_net_cfg=dict(
type='MapElementDetector',
num_query=120,
max_lines=35,
bbox_size=2,
canvas_size=canvas_size,
separate_detect=False,
discrete_output=False,
num_classes=num_class,
in_channels=128,
score_thre=0.1,
num_reg_fcs=2,
num_points=4,
iterative=False,
pc_range=[-15, -30, -5.0, 15, 30, 3.0],
sync_cls_avg_factor=True,
transformer=dict(
type='DeformableDetrTransformer_',
encoder=dict(
type='PlaceHolderEncoder',
embed_dims=head_dim,
),
decoder=dict(
type='DeformableDetrTransformerDecoder_',
num_layers=6,
return_intermediate=True,
transformerlayers=dict(
type='DetrTransformerDecoderLayer',
attn_cfgs=[
dict(
type='MultiheadAttention',
embed_dims=head_dim,
num_heads=8,
attn_drop=0.1,
proj_drop=0.1,
dropout_layer=dict(type='Dropout', drop_prob=0.1),),
dict(
type='MultiScaleDeformableAttention',
embed_dims=head_dim,
num_heads=8,
num_levels=1,
),
],
ffn_cfgs=dict(
type='FFN',
embed_dims=head_dim,
feedforward_channels=head_dim*2,
num_fcs=2,
ffn_drop=0.1,
act_cfg=dict(type='ReLU', inplace=True),
),
feedforward_channels=head_dim*2,
ffn_dropout=0.1,
operation_order=('norm', 'self_attn', 'norm', 'cross_attn',
'norm', 'ffn',)))
),
positional_encoding=dict(
type='SinePositionalEncoding',
num_feats=head_dim//2,
normalize=True,
offset=-0.5),
loss_cls=dict(
type='FocalLoss',
use_sigmoid=True,
gamma=2.0,
alpha=0.25,
loss_weight=2.0),
loss_reg=dict(
type='LinesLoss',
loss_weight=0.1),
train_cfg=dict(
assigner=dict(
type='HungarianLinesAssigner',
cost=dict(
type='MapQueriesCost',
cls_cost=dict(type='FocalLossCost', weight=2.0),
reg_cost=dict(type='BBoxCostC', weight=0.1), # continues
iou_cost=dict(type='IoUCostC', weight=1,box_format='xyxy'), # continues
),
),
),
),
gen_net_cfg=dict(
type='PolylineGenerator',
in_channels=128,
encoder_config=None,
decoder_config={
'layer_config': {
'd_model': 256,
'nhead': 8,
'dim_feedforward': 512,
'dropout': 0.2,
'norm_first': True,
're_zero': True,
},
'num_layers': 6,
},
class_conditional=True,
num_classes=num_class,
canvas_size=canvas_size, #xy
max_seq_length=500,
decoder_cross_attention=False,
use_discrete_vertex_embeddings=True,
),
max_num_vertices=80,
top_p_gen_model=0.9,
sync_cls_avg_factor=True,
),
with_auxiliary_head=False,
model_name='VectorMapNet'
)
# data processing pipelines
train_pipeline = [
dict(
type='VectorizeMap',
coords_dim=coords_dim,
roi_size=roi_size,
simplify=True,
normalize=True,
),
dict(
type='PolygonizeLocalMapBbox',
canvas_size=canvas_size,
coord_dim=2,
num_class=num_class,
threshold=4/200,
),
dict(type='LoadMultiViewImagesFromFiles'),
dict(type='ResizeMultiViewImages',
size = img_size, # H, W
change_intrinsics=True,
),
dict(type='Normalize3D', **img_norm_cfg),
dict(type='PadMultiViewImages', size_divisor=32, change_intrinsics=True),
dict(type='FormatBundleMap'),
dict(type='Collect3D', keys=['img', 'polys', 'vectors'], meta_keys=(
'token', 'ego2img'))
]
# configs for evaluation code
# DO NOT CHANGE
eval_config = dict(
type='NuscDataset',
data_root='./datasets/nuScenes',
ann_file='./datasets/nuScenes/nuscenes_map_infos_val.pkl',
meta=meta,
roi_size=roi_size,
cat2id=cat2id,
pipeline=[
dict(
type='VectorizeMap',
coords_dim=coords_dim,
roi_size=roi_size,
simplify=True,
normalize=False,
),
dict(type='FormatBundleMap'),
dict(type='Collect3D', keys=['vectors'], meta_keys=['token'])
],
interval=1,
)
# dataset configs
data = dict(
samples_per_gpu=5,
workers_per_gpu=5,
train=dict(
type='NuscDataset',
data_root='./datasets/nuScenes',
ann_file='./datasets/nuScenes/nuscenes_map_infos_train.pkl',
meta=meta,
roi_size=roi_size,
cat2id=cat2id,
pipeline=train_pipeline,
interval=1,
),
val=dict(
type='NuscDataset',
data_root='./datasets/nuScenes',
ann_file='./datasets/nuScenes/nuscenes_map_infos_val.pkl',
meta=meta,
roi_size=roi_size,
cat2id=cat2id,
pipeline=train_pipeline,
eval_config=eval_config,
test_mode=True,
interval=1,
),
test=dict(
type='NuscDataset',
data_root='./datasets/nuScenes',
ann_file='./datasets/nuScenes/nuscenes_map_infos_val.pkl',
meta=meta,
roi_size=roi_size,
cat2id=cat2id,
pipeline=train_pipeline,
eval_config=eval_config,
test_mode=True,
interval=1,
),
)
# optimizer
optimizer = dict(
type='AdamW',
lr=1e-3,
paramwise_cfg=dict(
custom_keys={
'backbone': dict(lr_mult=0.1),
}),
weight_decay=0.01)
optimizer_config = dict(grad_clip=dict(max_norm=.5, norm_type=2))
# learning policy & schedule
lr_config = dict(
policy='step',
warmup='linear',
warmup_iters=400,
warmup_ratio=0.1,
step=[100, 120])
checkpoint_config = dict(interval=5)
total_epochs = 130
# kwargs for dataset evaluation
eval_kwargs = dict()
evaluation = dict(
interval=5,
**eval_kwargs)
runner = dict(type='EpochBasedRunner', max_epochs=total_epochs)
find_unused_parameters = True
log_config = dict(
interval=50,
hooks=[
dict(type='TextLoggerHook'),
dict(type='TensorboardLoggerHook')
])