vectormapnet.py 9.89 KB
Newer Older
yeshenglong1's avatar
yeshenglong1 committed
1
2
3
4
5
6
7
8
9
10
11
12
13
_base_ = [
    './_base_/default_runtime.py'
]

# meta info for submission file

meta = {
    'use_lidar': False,
    'use_camera': True,
    'use_external': False,
    'output_format': 'vector',

    # NOTE: please modify the information below
zhe chen's avatar
zhe chen committed
14
    'method': 'VectorMapNet',  # name of your method
yeshenglong1's avatar
yeshenglong1 committed
15
    'authors': ['Yicheng Liu', 'Tianyuan Yuan', 'Yue Wang',
zhe chen's avatar
zhe chen committed
16
17
18
19
                'Yilun Wang', 'Hang Zhao'],  # author names
    'e-mail': 'yuantianyuan01@gmail.com',  # your e-mail address
    'institution / company': 'MarsLab, Tsinghua University',  # your organization
    'country / region': 'xxx',  # (IMPORTANT) your country/region in iso3166 standard
yeshenglong1's avatar
yeshenglong1 committed
20
21
22
23
24
25
26
27
28
29
30
31
32
}

# model type
type = 'Mapper'
plugin = True

# plugin code dir
plugin_dir = 'src/'

# img configs
img_norm_cfg = dict(
    mean=[103.530, 116.280, 123.675], std=[1.0, 1.0, 1.0], to_rgb=False)

zhe chen's avatar
zhe chen committed
33
img_size = (int(128 * 2), int((16 / 9 * 128) * 2))
yeshenglong1's avatar
yeshenglong1 committed
34
35
36
37
38
39
40
41
42
43

# category configs
cat2id = {
    'ped_crossing': 0,
    'divider': 1,
    'boundary': 2,
}
num_class = max(list(cat2id.values())) + 1

# bev configs
zhe chen's avatar
zhe chen committed
44
45
roi_size = (60, 30)  # bev range, 60m in x-axis, 30m in y-axis
canvas_size = (200, 100)  # bev feature size
yeshenglong1's avatar
yeshenglong1 committed
46
47

# vectorize params
zhe chen's avatar
zhe chen committed
48
49
50
51
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
yeshenglong1's avatar
yeshenglong1 committed
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

# model configs
head_dim = 256
norm_cfg = dict(type='BN2d')
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,
zhe chen's avatar
zhe chen committed
88
89
90
            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]],
yeshenglong1's avatar
yeshenglong1 committed
91
92
93
94
        heights=[-1.1, 0, 0.5, 1.1],
        out_channels=128,
        pretrained=None,
        num_cam=7,
zhe chen's avatar
zhe chen committed
95
    ),
yeshenglong1's avatar
yeshenglong1 committed
96
97
98
99
    head_cfg=dict(
        type='DGHead',
        augmentation=True,
        augmentation_kwargs=dict(
zhe chen's avatar
zhe chen committed
100
            p=0.3, scale=0.01,
yeshenglong1's avatar
yeshenglong1 committed
101
            bbox_type='xyxy',
zhe chen's avatar
zhe chen committed
102
        ),
yeshenglong1's avatar
yeshenglong1 committed
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
        det_net_cfg=dict(
            type='MapElementDetector',
            num_query=120,
            max_lines=35,
            bbox_size=2,
            mode='xyxy',
            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,
            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,
zhe chen's avatar
zhe chen committed
138
                                dropout_layer=dict(type='Dropout', drop_prob=0.1), ),
yeshenglong1's avatar
yeshenglong1 committed
139
140
141
142
143
                            dict(
                                type='MultiScaleDeformableAttention',
                                embed_dims=head_dim,
                                num_heads=8,
                                num_levels=1,
zhe chen's avatar
zhe chen committed
144
                            ),
yeshenglong1's avatar
yeshenglong1 committed
145
146
147
148
                        ],
                        ffn_cfgs=dict(
                            type='FFN',
                            embed_dims=head_dim,
zhe chen's avatar
zhe chen committed
149
                            feedforward_channels=head_dim * 2,
yeshenglong1's avatar
yeshenglong1 committed
150
151
                            num_fcs=2,
                            ffn_drop=0.1,
zhe chen's avatar
zhe chen committed
152
                            act_cfg=dict(type='ReLU', inplace=True),
yeshenglong1's avatar
yeshenglong1 committed
153
                        ),
zhe chen's avatar
zhe chen committed
154
                        feedforward_channels=head_dim * 2,
yeshenglong1's avatar
yeshenglong1 committed
155
156
                        ffn_dropout=0.1,
                        operation_order=('norm', 'self_attn', 'norm', 'cross_attn',
zhe chen's avatar
zhe chen committed
157
158
                                         'norm', 'ffn',)))
            ),
yeshenglong1's avatar
yeshenglong1 committed
159
160
            positional_encoding=dict(
                type='SinePositionalEncoding',
zhe chen's avatar
zhe chen committed
161
                num_feats=head_dim // 2,
yeshenglong1's avatar
yeshenglong1 committed
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
                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),
zhe chen's avatar
zhe chen committed
179
180
                        reg_cost=dict(type='BBoxCostC', weight=0.1),  # continues
                        iou_cost=dict(type='IoUCostC', weight=1, box_format='xyxy'),  # continues
yeshenglong1's avatar
yeshenglong1 committed
181
182
                    ),
                ),
zhe chen's avatar
zhe chen committed
183
            ),
yeshenglong1's avatar
yeshenglong1 committed
184
185
186
187
188
189
        ),
        gen_net_cfg=dict(
            type='PolylineGenerator',
            in_channels=128,
            encoder_config=None,
            decoder_config={
zhe chen's avatar
zhe chen committed
190
191
192
193
194
195
196
                'layer_config': {
                    'd_model': 256,
                    'nhead': 8,
                    'dim_feedforward': 512,
                    'dropout': 0.2,
                    'norm_first': True,
                    're_zero': True,
yeshenglong1's avatar
yeshenglong1 committed
197
                },
zhe chen's avatar
zhe chen committed
198
199
                'num_layers': 6,
            },
yeshenglong1's avatar
yeshenglong1 committed
200
201
            class_conditional=True,
            num_classes=num_class,
zhe chen's avatar
zhe chen committed
202
            canvas_size=canvas_size,  # xy
yeshenglong1's avatar
yeshenglong1 committed
203
204
205
206
207
208
209
            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,
zhe chen's avatar
zhe chen committed
210
    ),
yeshenglong1's avatar
yeshenglong1 committed
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
    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,  # xy
        coord_dim=2,
        num_class=num_class,
zhe chen's avatar
zhe chen committed
229
        threshold=4 / 200,
yeshenglong1's avatar
yeshenglong1 committed
230
231
232
    ),
    dict(type='LoadMultiViewImagesFromFiles'),
    dict(type='ResizeMultiViewImages',
zhe chen's avatar
zhe chen committed
233
         size=(int(128 * 2), int((16 / 9 * 128) * 2)),  # H, W
yeshenglong1's avatar
yeshenglong1 committed
234
235
236
237
238
239
240
241
242
243
244
245
         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'))
]

test_pipeline = [
    dict(type='LoadMultiViewImagesFromFiles'),
    dict(type='ResizeMultiViewImages',
zhe chen's avatar
zhe chen committed
246
         size=img_size,  # H, W
yeshenglong1's avatar
yeshenglong1 committed
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
         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'], meta_keys=(
        'token', 'ego2img'))
]

# dataset configs
data = dict(
    samples_per_gpu=5,
    workers_per_gpu=5,
    train=dict(
        type='AV2Dataset',
        ann_file='./data/train_annotations.json',
        root_path='./data/argoverse2/',
        meta=meta,
        roi_size=roi_size,
        cat2id=cat2id,
        pipeline=train_pipeline,
        interval=1,
    ),
    val=dict(
        type='AV2Dataset',
        ann_file='./data/val_annotations.json',
        root_path='./data/argoverse2/',
        meta=meta,
        roi_size=roi_size,
        cat2id=cat2id,
        pipeline=test_pipeline,
        test_mode=True,
        interval=1,
    ),
    test=dict(
        type='AV2Dataset',
        ann_file='./data/test_annotations.json',
        root_path='./data/argoverse2/',
        meta=meta,
        roi_size=roi_size,
        cat2id=cat2id,
        pipeline=test_pipeline,
        test_mode=True,
        interval=1,
    ),
)

# optimizer
optimizer = dict(
    type='AdamW',
    lr=1e-3,
    paramwise_cfg=dict(
zhe chen's avatar
zhe chen committed
299
300
301
        custom_keys={
            'backbone': dict(lr_mult=0.1),
        }),
yeshenglong1's avatar
yeshenglong1 committed
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
    weight_decay=0.01)
optimizer_config = dict(grad_clip=dict(max_norm=3.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(
zhe chen's avatar
zhe chen committed
318
    interval=5,
yeshenglong1's avatar
yeshenglong1 committed
319
320
321
322
323
324
325
326
327
328
329
    **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')
    ])