test_imvoxelnet.py 1.75 KB
Newer Older
Tai-Wang's avatar
Tai-Wang committed
1
2
3
4
5
6
import unittest

import torch
from mmengine import DefaultScope

from mmdet3d.registry import MODELS
7
8
from mmdet3d.testing import (create_detector_inputs, get_detector_cfg,
                             setup_seed)
Tai-Wang's avatar
Tai-Wang committed
9
10
11
12


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
        import mmdet3d.models

        assert hasattr(mmdet3d.models, 'ImVoxelNet')
        DefaultScope.get_instance('test_ImVoxelNet', scope_name='mmdet3d')
18
19
        setup_seed(0)
        imvoxel_net_cfg = get_detector_cfg(
20
            'imvoxelnet/imvoxelnet_8xb4_kitti-3d-car.py')
Tai-Wang's avatar
Tai-Wang committed
21
22
        model = MODELS.build(imvoxel_net_cfg)
        num_gt_instance = 1
23
        packed_inputs = create_detector_inputs(
24
25
26
27
28
29
            with_points=False,
            with_img=True,
            img_size=(128, 128),
            num_gt_instance=num_gt_instance,
            with_pts_semantic_mask=False,
            with_pts_instance_mask=False)
Tai-Wang's avatar
Tai-Wang committed
30
31
32
33
34

        if torch.cuda.is_available():
            model = model.cuda()
            # test simple_test
            with torch.no_grad():
35
                data = model.data_preprocessor(packed_inputs, True)
zhangshilong's avatar
zhangshilong committed
36
                torch.cuda.empty_cache()
37
38
                results = model.forward(**data, mode='predict')
            self.assertEqual(len(results), 1)
Tai-Wang's avatar
Tai-Wang committed
39
40
41
42
43
44
            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():
45
                losses = model.forward(**data, mode='loss')
Tai-Wang's avatar
Tai-Wang committed
46

47
48
49
            self.assertGreaterEqual(losses['loss_cls'][0], 0)
            self.assertGreaterEqual(losses['loss_bbox'][0], 0)
            self.assertGreaterEqual(losses['loss_dir'][0], 0)