"libai/utils/checkpoint.py" did not exist on "fd158e88e82c3fa848017c62a7eccb49a5c64f78"
test_voxelnet.py 2.95 KB
Newer Older
1
# Copyright (c) OpenMMLab. All rights reserved.
zhangshilong's avatar
zhangshilong committed
2
3
import unittest

4
import torch
zhangshilong's avatar
zhangshilong committed
5
from mmengine import DefaultScope
6
7

from mmdet3d.registry import MODELS
zhangshilong's avatar
zhangshilong committed
8
9
10
from mmdet3d.structures import LiDARInstance3DBoxes
from tests.utils.model_utils import (_create_detector_inputs,
                                     _get_detector_cfg, _setup_seed)
jshilong's avatar
jshilong committed
11

jshilong's avatar
jshilong committed
12

zhangshilong's avatar
zhangshilong committed
13
class TestVoxelNet(unittest.TestCase):
jshilong's avatar
jshilong committed
14

zhangshilong's avatar
zhangshilong committed
15
16
    def test_voxelnet(self):
        import mmdet3d.models
jshilong's avatar
jshilong committed
17

zhangshilong's avatar
zhangshilong committed
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
        assert hasattr(mmdet3d.models, 'VoxelNet')
        DefaultScope.get_instance('test_voxelnet', scope_name='mmdet3d')
        _setup_seed(0)
        pointpillars_cfg = _get_detector_cfg(
            'pointpillars/hv_pointpillars_secfpn_6x8_160e_kitti-3d-3class.py')
        model = MODELS.build(pointpillars_cfg)
        num_gt_instance = 2
        data = [_create_detector_inputs(num_gt_instance=num_gt_instance)]
        aug_data = [
            _create_detector_inputs(num_gt_instance=num_gt_instance),
            _create_detector_inputs(num_gt_instance=num_gt_instance + 1)
        ]
        # test_aug_test
        metainfo = {
            'pcd_scale_factor': 1,
            'pcd_horizontal_flip': 1,
            'pcd_vertical_flip': 1,
            'box_type_3d': LiDARInstance3DBoxes
        }
        for item in aug_data:
            item['data_sample'].set_metainfo(metainfo)
        if torch.cuda.is_available():
            model = model.cuda()
            # test simple_test
            with torch.no_grad():
                batch_inputs, data_samples = model.data_preprocessor(
                    data, True)
                torch.cuda.empty_cache()
                results = model.forward(
                    batch_inputs, data_samples, mode='predict')
            self.assertEqual(len(results), len(data))
            self.assertIn('bboxes_3d', results[0].pred_instances_3d)
            self.assertIn('scores_3d', results[0].pred_instances_3d)
            self.assertIn('labels_3d', results[0].pred_instances_3d)
            batch_inputs, data_samples = model.data_preprocessor(
                aug_data, True)
            aug_results = model.forward(
                batch_inputs, data_samples, mode='predict')
            self.assertEqual(len(results), len(data))
            self.assertIn('bboxes_3d', aug_results[0].pred_instances_3d)
            self.assertIn('scores_3d', aug_results[0].pred_instances_3d)
            self.assertIn('labels_3d', aug_results[0].pred_instances_3d)
            self.assertIn('bboxes_3d', aug_results[1].pred_instances_3d)
            self.assertIn('scores_3d', aug_results[1].pred_instances_3d)
            self.assertIn('labels_3d', aug_results[1].pred_instances_3d)
            # save the memory
jshilong's avatar
jshilong committed
64

zhangshilong's avatar
zhangshilong committed
65
66
67
68
69
70
            with torch.no_grad():
                losses = model.forward(batch_inputs, data_samples, mode='loss')
                torch.cuda.empty_cache()
            self.assertGreater(losses['loss_dir'][0], 0)
            self.assertGreater(losses['loss_bbox'][0], 0)
            self.assertGreater(losses['loss_cls'][0], 0)