"megatron/model/realm_model.py" did not exist on "fd33e9303732416c47c95e6941147839912700bb"
test_imvoxelnet.py 1.88 KB
Newer Older
Tai-Wang's avatar
Tai-Wang committed
1
2
3
4
5
6
7
8
9
10
11
12
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 TestImVoxelNet(unittest.TestCase):

zhangshilong's avatar
zhangshilong committed
13
    def test_imvoxelnet(self):
Tai-Wang's avatar
Tai-Wang committed
14
15
16
17
18
19
20
21
22
23
24
25
26
        import mmdet3d.models

        assert hasattr(mmdet3d.models, 'ImVoxelNet')
        DefaultScope.get_instance('test_ImVoxelNet', scope_name='mmdet3d')
        _setup_seed(0)
        imvoxel_net_cfg = _get_detector_cfg(
            'imvoxelnet/imvoxelnet_4x8_kitti-3d-car.py')
        model = MODELS.build(imvoxel_net_cfg)
        num_gt_instance = 1
        data = [
            _create_detector_inputs(
                with_points=False,
                with_img=True,
zhangshilong's avatar
zhangshilong committed
27
                img_size=(128, 128),
Tai-Wang's avatar
Tai-Wang committed
28
29
30
31
32
33
34
35
36
37
38
                num_gt_instance=num_gt_instance,
                with_pts_semantic_mask=False,
                with_pts_instance_mask=False)
        ]

        if torch.cuda.is_available():
            model = model.cuda()
            # test simple_test
            with torch.no_grad():
                batch_inputs, data_samples = model.data_preprocessor(
                    data, True)
zhangshilong's avatar
zhangshilong committed
39
                torch.cuda.empty_cache()
Tai-Wang's avatar
Tai-Wang committed
40
41
42
43
44
45
46
47
48
49
50
51
52
53
                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)

            # save the memory
            with torch.no_grad():
                losses = model.forward(batch_inputs, data_samples, mode='loss')

            self.assertGreater(losses['loss_cls'], 0)
            self.assertGreater(losses['loss_bbox'], 0)
            self.assertGreater(losses['loss_dir'], 0)