Unverified Commit 48342501 authored by Wenhao Wu's avatar Wenhao Wu Committed by GitHub
Browse files

[Fix] Fix unittest with GPU (#1301)

* resolve unittest with GPU

* fix rpn head

* recover point_rpn_head.py
parent 304f17b3
...@@ -250,9 +250,12 @@ def test_evaluate(): ...@@ -250,9 +250,12 @@ def test_evaluate():
metric = ['mAP'] metric = ['mAP']
result = dict(boxes_3d=boxes_3d, labels_3d=labels_3d, scores_3d=scores_3d) result = dict(boxes_3d=boxes_3d, labels_3d=labels_3d, scores_3d=scores_3d)
ap_dict = kitti_dataset.evaluate([result], metric) ap_dict = kitti_dataset.evaluate([result], metric)
assert np.isclose(ap_dict['KITTI/Overall_3D_easy'], 3.0303030303030307) assert np.isclose(ap_dict['KITTI/Overall_3D_AP11_easy'],
assert np.isclose(ap_dict['KITTI/Overall_3D_moderate'], 3.0303030303030307) 3.0303030303030307)
assert np.isclose(ap_dict['KITTI/Overall_3D_hard'], 3.0303030303030307) assert np.isclose(ap_dict['KITTI/Overall_3D_AP11_moderate'],
3.0303030303030307)
assert np.isclose(ap_dict['KITTI/Overall_3D_AP11_hard'],
3.0303030303030307)
def test_show(): def test_show():
......
...@@ -207,9 +207,11 @@ def test_evaluate(): ...@@ -207,9 +207,11 @@ def test_evaluate():
metric = ['mAP'] metric = ['mAP']
ap_dict = kitti_dataset.evaluate(results, metric) ap_dict = kitti_dataset.evaluate(results, metric)
assert np.isclose(ap_dict['img_bbox/KITTI/Overall_3D_easy'], 3.0303) assert np.isclose(ap_dict['img_bbox/KITTI/Overall_3D_AP11_easy'], 3.0303)
assert np.isclose(ap_dict['img_bbox/KITTI/Overall_3D_moderate'], 6.0606) assert np.isclose(ap_dict['img_bbox/KITTI/Overall_3D_AP11_moderate'],
assert np.isclose(ap_dict['img_bbox/KITTI/Overall_3D_hard'], 6.0606) 6.0606)
assert np.isclose(ap_dict['img_bbox2d/KITTI/Overall_2D_easy'], 3.0303) assert np.isclose(ap_dict['img_bbox/KITTI/Overall_3D_AP11_hard'], 6.0606)
assert np.isclose(ap_dict['img_bbox2d/KITTI/Overall_2D_moderate'], 6.0606) assert np.isclose(ap_dict['img_bbox2d/KITTI/Overall_2D_AP11_easy'], 3.0303)
assert np.isclose(ap_dict['img_bbox2d/KITTI/Overall_2D_hard'], 6.0606) assert np.isclose(ap_dict['img_bbox2d/KITTI/Overall_2D_AP11_moderate'],
6.0606)
assert np.isclose(ap_dict['img_bbox2d/KITTI/Overall_2D_AP11_hard'], 6.0606)
...@@ -144,9 +144,12 @@ def test_evaluate(): ...@@ -144,9 +144,12 @@ def test_evaluate():
# kitti protocol # kitti protocol
metric = ['kitti'] metric = ['kitti']
ap_dict = waymo_dataset.evaluate([result], metric=metric) ap_dict = waymo_dataset.evaluate([result], metric=metric)
assert np.isclose(ap_dict['KITTI/Overall_3D_easy'], 3.0303030303030307) assert np.isclose(ap_dict['KITTI/Overall_3D_AP11_easy'],
assert np.isclose(ap_dict['KITTI/Overall_3D_moderate'], 3.0303030303030307) 3.0303030303030307)
assert np.isclose(ap_dict['KITTI/Overall_3D_hard'], 3.0303030303030307) assert np.isclose(ap_dict['KITTI/Overall_3D_AP11_moderate'],
3.0303030303030307)
assert np.isclose(ap_dict['KITTI/Overall_3D_AP11_hard'],
3.0303030303030307)
# waymo protocol # waymo protocol
metric = ['waymo'] metric = ['waymo']
......
...@@ -12,11 +12,11 @@ def test_dgcnn_gf_module(): ...@@ -12,11 +12,11 @@ def test_dgcnn_gf_module():
self = DGCNNGFModule( self = DGCNNGFModule(
mlp_channels=[18, 64, 64], mlp_channels=[18, 64, 64],
num_sample=20, num_sample=20,
knn_mod='D-KNN', knn_mode='D-KNN',
radius=None, radius=None,
norm_cfg=dict(type='BN2d'), norm_cfg=dict(type='BN2d'),
act_cfg=dict(type='ReLU'), act_cfg=dict(type='ReLU'),
pool_mod='max').cuda() pool_mode='max').cuda()
assert self.mlps[0].layer0.conv.in_channels == 18 assert self.mlps[0].layer0.conv.in_channels == 18
assert self.mlps[0].layer0.conv.out_channels == 64 assert self.mlps[0].layer0.conv.out_channels == 64
...@@ -36,11 +36,11 @@ def test_dgcnn_gf_module(): ...@@ -36,11 +36,11 @@ def test_dgcnn_gf_module():
self = DGCNNGFModule( self = DGCNNGFModule(
mlp_channels=[6, 64, 64], mlp_channels=[6, 64, 64],
num_sample=20, num_sample=20,
knn_mod='F-KNN', knn_mode='F-KNN',
radius=None, radius=None,
norm_cfg=dict(type='BN2d'), norm_cfg=dict(type='BN2d'),
act_cfg=dict(type='ReLU'), act_cfg=dict(type='ReLU'),
pool_mod='max').cuda() pool_mode='max').cuda()
# test forward # test forward
new_points = self(xyz) new_points = self(xyz)
...@@ -50,11 +50,11 @@ def test_dgcnn_gf_module(): ...@@ -50,11 +50,11 @@ def test_dgcnn_gf_module():
self = DGCNNGFModule( self = DGCNNGFModule(
mlp_channels=[6, 64, 64], mlp_channels=[6, 64, 64],
num_sample=20, num_sample=20,
knn_mod='F-KNN', knn_mode='F-KNN',
radius=0.2, radius=0.2,
norm_cfg=dict(type='BN2d'), norm_cfg=dict(type='BN2d'),
act_cfg=dict(type='ReLU'), act_cfg=dict(type='ReLU'),
pool_mod='max').cuda() pool_mode='max').cuda()
def test_dgcnn_fa_module(): def test_dgcnn_fa_module():
......
...@@ -473,11 +473,11 @@ def test_imvoxelnet(): ...@@ -473,11 +473,11 @@ def test_imvoxelnet():
assert labels_3d.shape[0] >= 0 assert labels_3d.shape[0] >= 0
def test_pointrcnn(): def test_point_rcnn():
if not torch.cuda.is_available(): if not torch.cuda.is_available():
pytest.skip('test requires GPU and torch+cuda') pytest.skip('test requires GPU and torch+cuda')
pointrcnn_cfg = _get_detector_cfg( pointrcnn_cfg = _get_detector_cfg(
'pointrcnn/pointrcnn_2x8_kitti-3d-3classes.py') 'point_rcnn/point_rcnn_2x8_kitti-3d-3classes.py')
self = build_detector(pointrcnn_cfg).cuda() self = build_detector(pointrcnn_cfg).cuda()
points_0 = torch.rand([1000, 4], device='cuda') points_0 = torch.rand([1000, 4], device='cuda')
points_1 = torch.rand([1000, 4], device='cuda') points_1 = torch.rand([1000, 4], device='cuda')
...@@ -539,9 +539,8 @@ def test_smoke(): ...@@ -539,9 +539,8 @@ def test_smoke():
attr_labels = None attr_labels = None
img_metas = [ img_metas = [
dict( dict(
cam_intrinsic=[[721.5377, 0., 609.5593, 0.], cam2img=[[721.5377, 0., 609.5593, 0.], [0., 721.5377, 172.854, 0.],
[0., 721.5377, 172.854, 0.], [0., 0., 1., 0.], [0., 0., 1., 0.], [0., 0., 0., 1.]],
[0., 0., 0., 1.]],
scale_factor=np.array([1., 1., 1., 1.], dtype=np.float32), scale_factor=np.array([1., 1., 1., 1.], dtype=np.float32),
pad_shape=[384, 1280], pad_shape=[384, 1280],
trans_mat=np.array([[0.25, 0., 0.], [0., 0.25, 0], [0., 0., 1.]], trans_mat=np.array([[0.25, 0., 0.], [0., 0.25, 0], [0., 0., 1.]],
......
...@@ -52,7 +52,6 @@ def _get_head_cfg(fname): ...@@ -52,7 +52,6 @@ def _get_head_cfg(fname):
These are deep copied to allow for safe modification of parameters without These are deep copied to allow for safe modification of parameters without
influencing other tests. influencing other tests.
""" """
import mmcv
config = _get_config_module(fname) config = _get_config_module(fname)
model = copy.deepcopy(config.model) model = copy.deepcopy(config.model)
train_cfg = mmcv.Config(copy.deepcopy(config.model.train_cfg)) train_cfg = mmcv.Config(copy.deepcopy(config.model.train_cfg))
...@@ -70,7 +69,6 @@ def _get_rpn_head_cfg(fname): ...@@ -70,7 +69,6 @@ def _get_rpn_head_cfg(fname):
These are deep copied to allow for safe modification of parameters without These are deep copied to allow for safe modification of parameters without
influencing other tests. influencing other tests.
""" """
import mmcv
config = _get_config_module(fname) config = _get_config_module(fname)
model = copy.deepcopy(config.model) model = copy.deepcopy(config.model)
train_cfg = mmcv.Config(copy.deepcopy(config.model.train_cfg)) train_cfg = mmcv.Config(copy.deepcopy(config.model.train_cfg))
...@@ -88,7 +86,6 @@ def _get_roi_head_cfg(fname): ...@@ -88,7 +86,6 @@ def _get_roi_head_cfg(fname):
These are deep copied to allow for safe modification of parameters without These are deep copied to allow for safe modification of parameters without
influencing other tests. influencing other tests.
""" """
import mmcv
config = _get_config_module(fname) config = _get_config_module(fname)
model = copy.deepcopy(config.model) model = copy.deepcopy(config.model)
train_cfg = mmcv.Config(copy.deepcopy(config.model.train_cfg)) train_cfg = mmcv.Config(copy.deepcopy(config.model.train_cfg))
...@@ -106,7 +103,6 @@ def _get_pts_bbox_head_cfg(fname): ...@@ -106,7 +103,6 @@ def _get_pts_bbox_head_cfg(fname):
These are deep copied to allow for safe modification of parameters without These are deep copied to allow for safe modification of parameters without
influencing other tests. influencing other tests.
""" """
import mmcv
config = _get_config_module(fname) config = _get_config_module(fname)
model = copy.deepcopy(config.model) model = copy.deepcopy(config.model)
train_cfg = mmcv.Config(copy.deepcopy(config.model.train_cfg.pts)) train_cfg = mmcv.Config(copy.deepcopy(config.model.train_cfg.pts))
...@@ -132,7 +128,7 @@ def _get_pointrcnn_rpn_head_cfg(fname): ...@@ -132,7 +128,7 @@ def _get_pointrcnn_rpn_head_cfg(fname):
rpn_head = model.rpn_head rpn_head = model.rpn_head
rpn_head.update(train_cfg=train_cfg.rpn) rpn_head.update(train_cfg=train_cfg.rpn)
rpn_head.update(test_cfg=test_cfg.rpn) rpn_head.update(test_cfg=test_cfg.rpn)
return rpn_head, train_cfg.rpn.rpn_proposal return rpn_head, train_cfg.rpn
def _get_vote_head_cfg(fname): def _get_vote_head_cfg(fname):
...@@ -141,7 +137,6 @@ def _get_vote_head_cfg(fname): ...@@ -141,7 +137,6 @@ def _get_vote_head_cfg(fname):
These are deep copied to allow for safe modification of parameters without These are deep copied to allow for safe modification of parameters without
influencing other tests. influencing other tests.
""" """
import mmcv
config = _get_config_module(fname) config = _get_config_module(fname)
model = copy.deepcopy(config.model) model = copy.deepcopy(config.model)
train_cfg = mmcv.Config(copy.deepcopy(config.model.train_cfg)) train_cfg = mmcv.Config(copy.deepcopy(config.model.train_cfg))
...@@ -290,11 +285,11 @@ def test_parta2_rpnhead_getboxes(): ...@@ -290,11 +285,11 @@ def test_parta2_rpnhead_getboxes():
assert result_list[0]['boxes_3d'].tensor.shape == torch.Size([512, 7]) assert result_list[0]['boxes_3d'].tensor.shape == torch.Size([512, 7])
def test_pointrcnn_rpnhead_getboxes(): def test_point_rcnn_rpnhead_getboxes():
if not torch.cuda.is_available(): if not torch.cuda.is_available():
pytest.skip('test requires GPU and torch+cuda') pytest.skip('test requires GPU and torch+cuda')
rpn_head_cfg, proposal_cfg = _get_pointrcnn_rpn_head_cfg( rpn_head_cfg, proposal_cfg = _get_pointrcnn_rpn_head_cfg(
'./pointrcnn/pointrcnn_2x8_kitti-3d-3classes.py') './point_rcnn/point_rcnn_2x8_kitti-3d-3classes.py')
self = build_head(rpn_head_cfg) self = build_head(rpn_head_cfg)
self.cuda() self.cuda()
...@@ -315,7 +310,7 @@ def test_pointrcnn_rpnhead_getboxes(): ...@@ -315,7 +310,7 @@ def test_pointrcnn_rpnhead_getboxes():
assert cls_preds.shape == (2, 1024, 3) assert cls_preds.shape == (2, 1024, 3)
points = torch.rand([2, 1024, 3], dtype=torch.float32).cuda() points = torch.rand([2, 1024, 3], dtype=torch.float32).cuda()
result_list = self.get_bboxes(points, bbox_preds, cls_preds, input_metas) result_list = self.get_bboxes(points, bbox_preds, cls_preds, input_metas)
max_num = proposal_cfg.max_num max_num = proposal_cfg.nms_cfg.nms_post
bbox, score_selected, labels, cls_preds_selected = result_list[0] bbox, score_selected, labels, cls_preds_selected = result_list[0]
assert bbox.tensor.shape == (max_num, 7) assert bbox.tensor.shape == (max_num, 7)
assert score_selected.shape == (max_num, ) assert score_selected.shape == (max_num, )
...@@ -515,22 +510,24 @@ def test_smoke_mono3d_head(): ...@@ -515,22 +510,24 @@ def test_smoke_mono3d_head():
def test_parta2_bbox_head(): def test_parta2_bbox_head():
if not torch.cuda.is_available():
pytest.skip('test requires GPU and torch+cuda')
parta2_bbox_head_cfg = _get_parta2_bbox_head_cfg( parta2_bbox_head_cfg = _get_parta2_bbox_head_cfg(
'./parta2/hv_PartA2_secfpn_2x8_cyclic_80e_kitti-3d-3class.py') './parta2/hv_PartA2_secfpn_2x8_cyclic_80e_kitti-3d-3class.py')
self = build_head(parta2_bbox_head_cfg) self = build_head(parta2_bbox_head_cfg).cuda()
seg_feats = torch.rand([256, 14, 14, 14, 16]) seg_feats = torch.rand([256, 14, 14, 14, 16]).cuda()
part_feats = torch.rand([256, 14, 14, 14, 4]) part_feats = torch.rand([256, 14, 14, 14, 4]).cuda()
cls_score, bbox_pred = self.forward(seg_feats, part_feats) cls_score, bbox_pred = self.forward(seg_feats, part_feats)
assert cls_score.shape == (256, 1) assert cls_score.shape == (256, 1)
assert bbox_pred.shape == (256, 7) assert bbox_pred.shape == (256, 7)
def test_pointrcnn_bbox_head(): def test_point_rcnn_bbox_head():
if not torch.cuda.is_available(): if not torch.cuda.is_available():
pytest.skip('test requires GPU and torch+cuda') pytest.skip('test requires GPU and torch+cuda')
pointrcnn_bbox_head_cfg = _get_pointrcnn_bbox_head_cfg( pointrcnn_bbox_head_cfg = _get_pointrcnn_bbox_head_cfg(
'./pointrcnn/pointrcnn_2x8_kitti-3d-3classes.py') './point_rcnn/point_rcnn_2x8_kitti-3d-3classes.py')
self = build_head(pointrcnn_bbox_head_cfg).cuda() self = build_head(pointrcnn_bbox_head_cfg).cuda()
feats = torch.rand([100, 512, 133]).cuda() feats = torch.rand([100, 512, 133]).cuda()
rcnn_cls, rcnn_reg = self.forward(feats) rcnn_cls, rcnn_reg = self.forward(feats)
...@@ -612,12 +609,12 @@ def test_part_aggregation_ROI_head(): ...@@ -612,12 +609,12 @@ def test_part_aggregation_ROI_head():
assert labels_3d.shape == (12, ) assert labels_3d.shape == (12, )
def test_pointrcnn_roi_head(): def test_point_rcnn_roi_head():
if not torch.cuda.is_available(): if not torch.cuda.is_available():
pytest.skip('test requires GPU and torch+cuda') pytest.skip('test requires GPU and torch+cuda')
roi_head_cfg = _get_roi_head_cfg( roi_head_cfg = _get_roi_head_cfg(
'./pointrcnn/pointrcnn_2x8_kitti-3d-3classes.py') './point_rcnn/point_rcnn_2x8_kitti-3d-3classes.py')
self = build_head(roi_head_cfg).cuda() self = build_head(roi_head_cfg).cuda()
......
...@@ -37,8 +37,7 @@ def test_single_roipoint_extractor(): ...@@ -37,8 +37,7 @@ def test_single_roipoint_extractor():
if not torch.cuda.is_available(): if not torch.cuda.is_available():
pytest.skip('test requires GPU and torch+cuda') pytest.skip('test requires GPU and torch+cuda')
roi_layer_cfg = dict( roi_layer_cfg = dict(type='RoIPointPool3d', num_sampled_points=512)
type='RoIPointPool3d', num_sampled_points=512, pool_extra_width=0)
self = Single3DRoIPointExtractor(roi_layer=roi_layer_cfg) self = Single3DRoIPointExtractor(roi_layer=roi_layer_cfg)
......
...@@ -114,7 +114,7 @@ def test_dla_neck(): ...@@ -114,7 +114,7 @@ def test_dla_neck():
for i in range(len(in_channels)) for i in range(len(in_channels))
] ]
outputs = neck(feats) outputs = neck(feats)
assert outputs.shape == (4, 64, 8, 8) assert outputs[0].shape == (4, 64, 8, 8)
else: else:
# Test DLA Neck without DCNv2 on CPU # Test DLA Neck without DCNv2 on CPU
neck_cfg = dict( neck_cfg = dict(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment