test_mvxnet.py 1.79 KB
Newer Older
jshilong's avatar
jshilong committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import unittest

import torch
from mmengine import DefaultScope

from mmdet3d.registry import MODELS
from tests.utils.model_utils import (_create_detector_inputs,
                                     _get_detector_cfg, _setup_seed)


class TestMVXNet(unittest.TestCase):

    def test_mvxnet(self):
        import mmdet3d.models

        assert hasattr(mmdet3d.models, 'DynamicMVXFasterRCNN')

        _setup_seed(0)
        DefaultScope.get_instance('test_mvxnet', scope_name='mmdet3d')
        mvx_net_cfg = _get_detector_cfg(
21
            'mvxnet/mvxnet_fpn_dv_second_secfpn_8xb2-80e_kitti-3d-3class.py'  # noqa
jshilong's avatar
jshilong committed
22
23
        )
        model = MODELS.build(mvx_net_cfg)
zhangshilong's avatar
zhangshilong committed
24
        num_gt_instance = 1
jshilong's avatar
jshilong committed
25
26
27
28
29
30
31
32
33
34
35
36
37
38
        data = [
            _create_detector_inputs(
                with_img=False,
                num_gt_instance=num_gt_instance,
                points_feat_dim=4)
        ]

        if torch.cuda.is_available():

            model = model.cuda()
            # test simple_test
            batch_inputs, data_samples = model.data_preprocessor(data, True)
            # save the memory when do the unitest
            with torch.no_grad():
zhangshilong's avatar
zhangshilong committed
39
                torch.cuda.empty_cache()
jshilong's avatar
jshilong committed
40
41
42
43
44
45
46
47
48
49
50
51
52
                losses = model.forward(batch_inputs, data_samples, mode='loss')
            assert losses['loss_cls'][0] >= 0
            assert losses['loss_bbox'][0] >= 0
            assert losses['loss_dir'][0] >= 0

            with torch.no_grad():
                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)
        # TODO test_aug_test