forked from youngskkim/CRN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BEVDepth_r50_256x704_128x128_4key.py
279 lines (256 loc) · 10.9 KB
/
BEVDepth_r50_256x704_128x128_4key.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
# Copyright (c) Megvii Inc. All rights reserved.
"""
mAP: 0.3672
mATE: 0.6827
mASE: 0.2833
mAOE: 0.5354
mAVE: 0.4156
mAAE: 0.2066
NDS: 0.4712
Eval time: 199.7s
Per-class results:
Object Class AP ATE ASE AOE AVE AAE
car 0.540 0.488 0.165 0.153 0.493 0.216
truck 0.302 0.707 0.225 0.182 0.380 0.202
bus 0.387 0.722 0.224 0.121 0.755 0.302
trailer 0.176 1.071 0.255 0.516 0.268 0.086
construction_vehicle 0.103 1.061 0.522 1.298 0.127 0.353
pedestrian 0.310 0.745 0.290 0.829 0.465 0.253
motorcycle 0.390 0.624 0.257 0.691 0.654 0.232
bicycle 0.379 0.494 0.268 0.828 0.183 0.009
traffic_cone 0.516 0.487 0.347 nan nan nan
barrier 0.568 0.426 0.280 0.202 nan nan
img: 24.63
img_backbone: 11.21
img_dep: 6.67
img_transform: 5.11
img_pool: 0.99
head: 9.04
head_backbone: 3.10
head_head: 5.94
total: 33.68
FPS: 29.70
| Name | Type | Params
-----------------------------------------------------------------------
0 | model | BaseBEVDepth | 77.6 M
1 | model.backbone_img | BaseLSSFPN | 53.3 M
2 | model.backbone_img.img_backbone | ResNet | 23.5 M
3 | model.backbone_img.img_neck | SECONDFPN | 2.0 M
4 | model.backbone_img.depth_net | DepthNet | 27.8 M
5 | model.head | BEVDepthHead | 24.4 M
6 | model.head.loss_cls | GaussianFocalLoss | 0
7 | model.head.loss_bbox | L1Loss | 0
8 | model.head.shared_conv | ConvModule | 147 K
9 | model.head.task_heads | ModuleList | 1.4 M
10 | model.head.trunk | ResNet | 19.8 M
11 | model.head.neck | SECONDFPN | 3.0 M
-----------------------------------------------------------------------
"""
import torch
from utils.torch_dist import synchronize
from exps.base_cli import run_cli
from exps.base_exp import BEVDepthLightningModel as BaseBEVDepthLightningModel
from models.base_bev_depth import BaseBEVDepth
class BEVDepthLightningModel(BaseBEVDepthLightningModel):
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self.return_image = True
self.return_depth = True
self.return_radar_pv = False
################################################
self.optimizer_config = dict(
type='AdamW',
lr=2e-4,
weight_decay=1e-4)
################################################
self.ida_aug_conf = {
'resize_lim': (0.386, 0.55),
'final_dim': (256, 704),
'rot_lim': (-5.4, 5.4),
'H': 900,
'W': 1600,
'rand_flip': True,
'bot_pct_lim': (0.0, 0.0),
'cams': [
'CAM_FRONT_LEFT', 'CAM_FRONT', 'CAM_FRONT_RIGHT',
'CAM_BACK_LEFT', 'CAM_BACK', 'CAM_BACK_RIGHT'
],
'Ncams': 6,
}
self.bda_aug_conf = {
'rot_ratio': 1.0,
'rot_lim': (-22.5, 22.5),
'scale_lim': (0.95, 1.05),
'flip_dx_ratio': 0.5,
'flip_dy_ratio': 0.5
}
################################################
self.backbone_img_conf = {
'x_bound': [-51.2, 51.2, 0.8],
'y_bound': [-51.2, 51.2, 0.8],
'z_bound': [-5, 3, 8],
'd_bound': [2.0, 58.0, 0.5],
'final_dim': (256, 704),
'downsample_factor': 16,
'img_backbone_conf': dict(
type='ResNet',
depth=50,
frozen_stages=0,
out_indices=[0, 1, 2, 3],
norm_eval=False,
init_cfg=dict(type='Pretrained', checkpoint='torchvision://resnet50'),
),
'img_neck_conf': dict(
type='SECONDFPN',
in_channels=[256, 512, 1024, 2048],
upsample_strides=[0.25, 0.5, 1, 2],
out_channels=[128, 128, 128, 128],
),
'depth_net_conf':
dict(in_channels=512, mid_channels=512),
'camera_aware': True,
'output_channels': 80,
}
################################################
self.head_conf = {
'bev_backbone_conf': dict(
type='ResNet',
in_channels=128,
depth=18,
num_stages=3,
strides=(1, 2, 2),
dilations=(1, 1, 1),
out_indices=[0, 1, 2],
norm_eval=False,
base_channels=160,
),
'bev_neck_conf': dict(
type='SECONDFPN',
in_channels=[80, 160, 320, 640],
upsample_strides=[1, 2, 4, 8],
out_channels=[64, 64, 64, 64]
),
'tasks': [
dict(num_class=1, class_names=['car']),
dict(num_class=2, class_names=['truck', 'construction_vehicle']),
dict(num_class=2, class_names=['bus', 'trailer']),
dict(num_class=1, class_names=['barrier']),
dict(num_class=2, class_names=['motorcycle', 'bicycle']),
dict(num_class=2, class_names=['pedestrian', 'traffic_cone']),
],
'common_heads': dict(
reg=(2, 2), height=(1, 2), dim=(3, 2), rot=(2, 2), vel=(2, 2)),
'bbox_coder': dict(
type='CenterPointBBoxCoder',
post_center_range=[-61.2, -61.2, -10.0, 61.2, 61.2, 10.0],
max_num=500,
score_threshold=0.01,
out_size_factor=4,
voxel_size=[0.2, 0.2, 8],
pc_range=[-51.2, -51.2, -5, 51.2, 51.2, 3],
code_size=9,
),
'train_cfg': dict(
point_cloud_range=[-51.2, -51.2, -5, 51.2, 51.2, 3],
grid_size=[512, 512, 1],
voxel_size=[0.2, 0.2, 8],
out_size_factor=4,
dense_reg=1,
gaussian_overlap=0.1,
max_objs=500,
min_radius=2,
code_weights=[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
),
'test_cfg': dict(
post_center_limit_range=[-61.2, -61.2, -10.0, 61.2, 61.2, 10.0],
max_per_img=500,
max_pool_nms=False,
min_radius=[4, 12, 10, 1, 0.85, 0.175],
score_threshold=0.01,
out_size_factor=4,
voxel_size=[0.2, 0.2, 8],
nms_type='circle',
pre_max_size=1000,
post_max_size=200,
nms_thr=0.2,
),
'in_channels': 256, # Equal to bev_neck output_channels.
'loss_cls': dict(type='GaussianFocalLoss', reduction='mean'),
'loss_bbox': dict(type='L1Loss', reduction='mean', loss_weight=0.25),
'gaussian_overlap': 0.1,
'min_radius': 2,
}
################################################
self.key_idxes = [-2, -4, -6]
self.head_conf['bev_backbone_conf']['in_channels'] = 80 * (
len(self.key_idxes) + 1)
self.head_conf['bev_neck_conf']['in_channels'] = [
80 * (len(self.key_idxes) + 1), 160, 320, 640
]
self.dbound = self.backbone_img_conf['d_bound']
self.depth_channels = int(
(self.dbound[1] - self.dbound[0]) / self.dbound[2])
self.model = BaseBEVDepth(self.backbone_img_conf,
self.head_conf)
def forward(self, sweep_imgs, mats, is_train=False, **inputs):
return self.model(sweep_imgs, mats, is_train=is_train)
def training_step(self, batch):
if self.global_rank == 0:
for pg in self.trainer.optimizers[0].param_groups:
self.log('learning_rate', pg["lr"])
(sweep_imgs, mats, _, gt_boxes_3d, gt_labels_3d, _, depth_labels, _) = batch
if torch.cuda.is_available():
if self.return_image:
sweep_imgs = sweep_imgs.cuda()
for key, value in mats.items():
mats[key] = value.cuda()
gt_boxes_3d = [gt_box.cuda() for gt_box in gt_boxes_3d]
gt_labels_3d = [gt_label.cuda() for gt_label in gt_labels_3d]
preds, depth_preds = self(sweep_imgs, mats, is_train=True)
targets = self.model.get_targets(gt_boxes_3d, gt_labels_3d)
loss_detection, loss_heatmap, loss_bbox = self.model.loss(targets, preds)
if len(depth_labels.shape) == 5:
# only key-frame will calculate depth loss
depth_labels = depth_labels[:, 0, ...].contiguous()
loss_depth = self.get_depth_loss(depth_labels.cuda(), depth_preds, weight=3.)
self.log('train/detection', loss_detection)
self.log('train/heatmap', loss_heatmap)
self.log('train/bbox', loss_bbox)
self.log('train/depth', loss_depth)
return loss_detection + loss_depth
def validation_epoch_end(self, validation_step_outputs):
detection_losses = list()
heatmap_losses = list()
bbox_losses = list()
depth_losses = list()
for validation_step_output in validation_step_outputs:
detection_losses.append(validation_step_output[0])
heatmap_losses.append(validation_step_output[1])
bbox_losses.append(validation_step_output[2])
depth_losses.append(validation_step_output[3])
synchronize()
self.log('val/detection', torch.mean(torch.stack(detection_losses)), on_epoch=True)
self.log('val/heatmap', torch.mean(torch.stack(heatmap_losses)), on_epoch=True)
self.log('val/bbox', torch.mean(torch.stack(bbox_losses)), on_epoch=True)
self.log('val/depth', torch.mean(torch.stack(depth_losses)), on_epoch=True)
def validation_step(self, batch, batch_idx):
(sweep_imgs, mats, _, gt_boxes_3d, gt_labels_3d, _, depth_labels, _) = batch
if torch.cuda.is_available():
if self.return_image:
sweep_imgs = sweep_imgs.cuda()
for key, value in mats.items():
mats[key] = value.cuda()
gt_boxes_3d = [gt_box.cuda() for gt_box in gt_boxes_3d]
gt_labels_3d = [gt_label.cuda() for gt_label in gt_labels_3d]
with torch.no_grad():
preds, depth_preds = self(sweep_imgs, mats, is_train=True)
targets = self.model.get_targets(gt_boxes_3d, gt_labels_3d)
loss_detection, loss_heatmap, loss_bbox = self.model.loss(targets, preds)
if len(depth_labels.shape) == 5:
# only key-frame will calculate depth loss
depth_labels = depth_labels[:, 0, ...].contiguous()
loss_depth = self.get_depth_loss(depth_labels.cuda(), depth_preds, weight=3.)
return loss_detection, loss_heatmap, loss_bbox, loss_depth
if __name__ == '__main__':
run_cli(BEVDepthLightningModel,
'det/BEVDepth_r50_256x704_128x128_4key')