test_minkunet_backbone.py 944 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
import torch.nn.functional as F

from mmdet3d.registry import MODELS


def test_minkunet_backbone():
    if not torch.cuda.is_available():
        pytest.skip('test requires GPU and torch+cuda')

    try:
        import torchsparse  # noqa: F401
    except ImportError:
        pytest.skip('test requires Torchsparse installation')

    coordinates, features = [], []
    for i in range(2):
20
        c = torch.randint(0, 16, (100, 3)).int()
21
22
23
24
25
26
27
28
29
30
31
32
        c = F.pad(c, (0, 1), mode='constant', value=i)
        coordinates.append(c)
        f = torch.rand(100, 4)
        features.append(f)
    features = torch.cat(features, dim=0).cuda()
    coordinates = torch.cat(coordinates, dim=0).cuda()

    cfg = dict(type='MinkUNetBackbone')
    self = MODELS.build(cfg).cuda()
    self.init_weights()

    y = self(features, coordinates)
33
    assert y.shape == torch.Size([200, 96])