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():
metric = ['mAP']
result = dict(boxes_3d=boxes_3d, labels_3d=labels_3d, scores_3d=scores_3d)
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_moderate'], 3.0303030303030307)
assert np.isclose(ap_dict['KITTI/Overall_3D_hard'], 3.0303030303030307)
assert np.isclose(ap_dict['KITTI/Overall_3D_AP11_easy'],
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():
......
......@@ -207,9 +207,11 @@ def test_evaluate():
metric = ['mAP']
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_moderate'], 6.0606)
assert np.isclose(ap_dict['img_bbox/KITTI/Overall_3D_hard'], 6.0606)
assert np.isclose(ap_dict['img_bbox2d/KITTI/Overall_2D_easy'], 3.0303)
assert np.isclose(ap_dict['img_bbox2d/KITTI/Overall_2D_moderate'], 6.0606)
assert np.isclose(ap_dict['img_bbox2d/KITTI/Overall_2D_hard'], 6.0606)
assert np.isclose(ap_dict['img_bbox/KITTI/Overall_3D_AP11_easy'], 3.0303)
assert np.isclose(ap_dict['img_bbox/KITTI/Overall_3D_AP11_moderate'],
6.0606)
assert np.isclose(ap_dict['img_bbox/KITTI/Overall_3D_AP11_hard'], 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_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():
# kitti protocol
metric = ['kitti']
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_moderate'], 3.0303030303030307)
assert np.isclose(ap_dict['KITTI/Overall_3D_hard'], 3.0303030303030307)
assert np.isclose(ap_dict['KITTI/Overall_3D_AP11_easy'],
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
metric = ['waymo']
......
......@@ -12,11 +12,11 @@ def test_dgcnn_gf_module():
self = DGCNNGFModule(
mlp_channels=[18, 64, 64],
num_sample=20,
knn_mod='D-KNN',
knn_mode='D-KNN',
radius=None,
norm_cfg=dict(type='BN2d'),
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.out_channels == 64
......@@ -36,11 +36,11 @@ def test_dgcnn_gf_module():
self = DGCNNGFModule(
mlp_channels=[6, 64, 64],
num_sample=20,
knn_mod='F-KNN',
knn_mode='F-KNN',
radius=None,
norm_cfg=dict(type='BN2d'),
act_cfg=dict(type='ReLU'),
pool_mod='max').cuda()
pool_mode='max').cuda()
# test forward
new_points = self(xyz)
......@@ -50,11 +50,11 @@ def test_dgcnn_gf_module():
self = DGCNNGFModule(
mlp_channels=[6, 64, 64],
num_sample=20,
knn_mod='F-KNN',
knn_mode='F-KNN',
radius=0.2,
norm_cfg=dict(type='BN2d'),
act_cfg=dict(type='ReLU'),
pool_mod='max').cuda()
pool_mode='max').cuda()
def test_dgcnn_fa_module():
......
......@@ -473,11 +473,11 @@ def test_imvoxelnet():
assert labels_3d.shape[0] >= 0
def test_pointrcnn():
def test_point_rcnn():
if not torch.cuda.is_available():
pytest.skip('test requires GPU and torch+cuda')
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()
points_0 = torch.rand([1000, 4], device='cuda')
points_1 = torch.rand([1000, 4], device='cuda')
......@@ -539,9 +539,8 @@ def test_smoke():
attr_labels = None
img_metas = [
dict(
cam_intrinsic=[[721.5377, 0., 609.5593, 0.],
[0., 721.5377, 172.854, 0.], [0., 0., 1., 0.],
[0., 0., 0., 1.]],
cam2img=[[721.5377, 0., 609.5593, 0.], [0., 721.5377, 172.854, 0.],
[0., 0., 1., 0.], [0., 0., 0., 1.]],
scale_factor=np.array([1., 1., 1., 1.], dtype=np.float32),
pad_shape=[384, 1280],
trans_mat=np.array([[0.25, 0., 0.], [0., 0.25, 0], [0., 0., 1.]],
......
......@@ -52,7 +52,6 @@ def _get_head_cfg(fname):
These are deep copied to allow for safe modification of parameters without
influencing other tests.
"""
import mmcv
config = _get_config_module(fname)
model = copy.deepcopy(config.model)
train_cfg = mmcv.Config(copy.deepcopy(config.model.train_cfg))
......@@ -70,7 +69,6 @@ def _get_rpn_head_cfg(fname):
These are deep copied to allow for safe modification of parameters without
influencing other tests.
"""
import mmcv
config = _get_config_module(fname)
model = copy.deepcopy(config.model)
train_cfg = mmcv.Config(copy.deepcopy(config.model.train_cfg))
......@@ -88,7 +86,6 @@ def _get_roi_head_cfg(fname):
These are deep copied to allow for safe modification of parameters without
influencing other tests.
"""
import mmcv
config = _get_config_module(fname)
model = copy.deepcopy(config.model)
train_cfg = mmcv.Config(copy.deepcopy(config.model.train_cfg))
......@@ -106,7 +103,6 @@ def _get_pts_bbox_head_cfg(fname):
These are deep copied to allow for safe modification of parameters without
influencing other tests.
"""
import mmcv
config = _get_config_module(fname)
model = copy.deepcopy(config.model)
train_cfg = mmcv.Config(copy.deepcopy(config.model.train_cfg.pts))
......@@ -132,7 +128,7 @@ def _get_pointrcnn_rpn_head_cfg(fname):
rpn_head = model.rpn_head
rpn_head.update(train_cfg=train_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):
......@@ -141,7 +137,6 @@ def _get_vote_head_cfg(fname):
These are deep copied to allow for safe modification of parameters without
influencing other tests.
"""
import mmcv
config = _get_config_module(fname)
model = copy.deepcopy(config.model)
train_cfg = mmcv.Config(copy.deepcopy(config.model.train_cfg))
......@@ -290,11 +285,11 @@ def test_parta2_rpnhead_getboxes():
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():
pytest.skip('test requires GPU and torch+cuda')
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.cuda()
......@@ -315,7 +310,7 @@ def test_pointrcnn_rpnhead_getboxes():
assert cls_preds.shape == (2, 1024, 3)
points = torch.rand([2, 1024, 3], dtype=torch.float32).cuda()
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]
assert bbox.tensor.shape == (max_num, 7)
assert score_selected.shape == (max_num, )
......@@ -515,22 +510,24 @@ def test_smoke_mono3d_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/hv_PartA2_secfpn_2x8_cyclic_80e_kitti-3d-3class.py')
self = build_head(parta2_bbox_head_cfg)
seg_feats = torch.rand([256, 14, 14, 14, 16])
part_feats = torch.rand([256, 14, 14, 14, 4])
self = build_head(parta2_bbox_head_cfg).cuda()
seg_feats = torch.rand([256, 14, 14, 14, 16]).cuda()
part_feats = torch.rand([256, 14, 14, 14, 4]).cuda()
cls_score, bbox_pred = self.forward(seg_feats, part_feats)
assert cls_score.shape == (256, 1)
assert bbox_pred.shape == (256, 7)
def test_pointrcnn_bbox_head():
def test_point_rcnn_bbox_head():
if not torch.cuda.is_available():
pytest.skip('test requires GPU and torch+cuda')
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()
feats = torch.rand([100, 512, 133]).cuda()
rcnn_cls, rcnn_reg = self.forward(feats)
......@@ -612,12 +609,12 @@ def test_part_aggregation_ROI_head():
assert labels_3d.shape == (12, )
def test_pointrcnn_roi_head():
def test_point_rcnn_roi_head():
if not torch.cuda.is_available():
pytest.skip('test requires GPU and torch+cuda')
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()
......
......@@ -37,8 +37,7 @@ def test_single_roipoint_extractor():
if not torch.cuda.is_available():
pytest.skip('test requires GPU and torch+cuda')
roi_layer_cfg = dict(
type='RoIPointPool3d', num_sampled_points=512, pool_extra_width=0)
roi_layer_cfg = dict(type='RoIPointPool3d', num_sampled_points=512)
self = Single3DRoIPointExtractor(roi_layer=roi_layer_cfg)
......
......@@ -114,7 +114,7 @@ def test_dla_neck():
for i in range(len(in_channels))
]
outputs = neck(feats)
assert outputs.shape == (4, 64, 8, 8)
assert outputs[0].shape == (4, 64, 8, 8)
else:
# Test DLA Neck without DCNv2 on CPU
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