test_indoor_augment.py 5.63 KB
Newer Older
liyinhao's avatar
liyinhao committed
1
import numpy as np
wuyuefeng's avatar
wuyuefeng committed
2
import torch
liyinhao's avatar
liyinhao committed
3

wuyuefeng's avatar
wuyuefeng committed
4
from mmdet3d.core.bbox import DepthInstance3DBoxes
liyinhao's avatar
liyinhao committed
5
from mmdet3d.datasets.pipelines import IndoorFlipData, IndoorGlobalRotScale
liyinhao's avatar
liyinhao committed
6
7


8
def test_indoor_flip_data():
liyinhao's avatar
liyinhao committed
9
    np.random.seed(0)
liyinhao's avatar
liyinhao committed
10
    sunrgbd_indoor_flip_data = IndoorFlipData(1, 1)
11
    sunrgbd_results = dict()
liyinhao's avatar
liyinhao committed
12
    sunrgbd_results['points'] = np.array(
13
14
        [[1.02828765e+00, 3.65790772e+00, 1.97294697e-01, 1.61959505e+00],
         [-3.95979017e-01, 1.05465031e+00, -7.49204338e-01, 6.73096001e-01]])
wuyuefeng's avatar
wuyuefeng committed
15
16
17
18
19
20
21
22
23
    sunrgbd_results['gt_bboxes_3d'] = DepthInstance3DBoxes(
        np.array([[
            0.213684, 1.036364, -0.982323, 0.61541, 0.572574, 0.872728,
            3.07028526
        ],
                  [
                      -0.449953, 1.395455, -1.027778, 1.500956, 1.637298,
                      0.636364, -1.58242359
                  ]]))
24
    sunrgbd_results = sunrgbd_indoor_flip_data(sunrgbd_results)
25
26
    sunrgbd_points = sunrgbd_results['points']
    sunrgbd_gt_bboxes_3d = sunrgbd_results['gt_bboxes_3d']
27

liyinhao's avatar
liyinhao committed
28
    expected_sunrgbd_points = np.array(
29
30
        [[-1.02828765, 3.65790772, 0.1972947, 1.61959505],
         [0.39597902, 1.05465031, -0.74920434, 0.673096]])
wuyuefeng's avatar
wuyuefeng committed
31
32
33
    expected_sunrgbd_gt_bboxes_3d = torch.tensor(
        [[-0.2137, 1.0364, -0.9823, 0.6154, 0.5726, 0.8727, 0.0713],
         [0.4500, 1.3955, -1.0278, 1.5010, 1.6373, 0.6364, 4.7240]])
liyinhao's avatar
liyinhao committed
34
    assert np.allclose(sunrgbd_points, expected_sunrgbd_points)
wuyuefeng's avatar
wuyuefeng committed
35
36
    assert torch.allclose(sunrgbd_gt_bboxes_3d.tensor,
                          expected_sunrgbd_gt_bboxes_3d, 1e-3)
37

liyinhao's avatar
liyinhao committed
38
    np.random.seed(0)
liyinhao's avatar
liyinhao committed
39
    scannet_indoor_flip_data = IndoorFlipData(1, 1)
40
    scannet_results = dict()
liyinhao's avatar
liyinhao committed
41
    scannet_results['points'] = np.array(
42
43
        [[1.6110241e+00, -1.6903955e-01, 5.8115810e-01, 5.9897250e-01],
         [1.3978075e+00, 4.2035791e-01, 3.8729519e-01, 4.0510958e-01]])
wuyuefeng's avatar
wuyuefeng committed
44
45
46
47
48
49
50
51
52
53
54
    scannet_results['gt_bboxes_3d'] = DepthInstance3DBoxes(
        np.array([[
            0.55903838, 0.48201692, 0.65688646, 0.65370704, 0.60029864,
            0.5163464
        ],
                  [
                      -0.03226406, 1.70392646, 0.60348618, 0.65165804,
                      0.72084366, 0.64667457
                  ]]),
        box_dim=6,
        with_yaw=False)
55
    scannet_results = scannet_indoor_flip_data(scannet_results)
56
57
    scannet_points = scannet_results['points']
    scannet_gt_bboxes_3d = scannet_results['gt_bboxes_3d']
58

liyinhao's avatar
liyinhao committed
59
    expected_scannet_points = np.array(
60
61
        [[-1.6110241, 0.16903955, 0.5811581, 0.5989725],
         [-1.3978075, -0.42035791, 0.38729519, 0.40510958]])
wuyuefeng's avatar
wuyuefeng committed
62
63
64
    expected_scannet_gt_bboxes_3d = torch.tensor(
        [[-0.5590, -0.4820, 0.6569, 0.6537, 0.6003, 0.5163, 0.0000],
         [0.0323, -1.7039, 0.6035, 0.6517, 0.7208, 0.6467, 0.0000]])
liyinhao's avatar
liyinhao committed
65
    assert np.allclose(scannet_points, expected_scannet_points)
wuyuefeng's avatar
wuyuefeng committed
66
67
    assert torch.allclose(scannet_gt_bboxes_3d.tensor,
                          expected_scannet_gt_bboxes_3d, 1e-2)
68
69
70


def test_global_rot_scale():
liyinhao's avatar
liyinhao committed
71
    np.random.seed(0)
liyinhao's avatar
liyinhao committed
72
    sunrgbd_augment = IndoorGlobalRotScale(
liyinhao's avatar
liyinhao committed
73
        True, rot_range=[-1 / 6, 1 / 6], scale_range=[0.85, 1.15])
liyinhao's avatar
liyinhao committed
74
    sunrgbd_results = dict()
liyinhao's avatar
liyinhao committed
75
    sunrgbd_results['points'] = np.array(
liyinhao's avatar
liyinhao committed
76
77
        [[1.02828765e+00, 3.65790772e+00, 1.97294697e-01, 1.61959505e+00],
         [-3.95979017e-01, 1.05465031e+00, -7.49204338e-01, 6.73096001e-01]])
wuyuefeng's avatar
wuyuefeng committed
78
79
80
81
82
83
84
85
86
    sunrgbd_results['gt_bboxes_3d'] = DepthInstance3DBoxes(
        np.array([[
            0.213684, 1.036364, -0.982323, 0.61541, 0.572574, 0.872728,
            3.07028526
        ],
                  [
                      -0.449953, 1.395455, -1.027778, 1.500956, 1.637298,
                      0.636364, -1.58242359
                  ]]))
liyinhao's avatar
liyinhao committed
87
88

    sunrgbd_results = sunrgbd_augment(sunrgbd_results)
89
90
    sunrgbd_points = sunrgbd_results['points']
    sunrgbd_gt_bboxes_3d = sunrgbd_results['gt_bboxes_3d']
91

liyinhao's avatar
liyinhao committed
92
    expected_sunrgbd_points = np.array(
93
94
        [[0.89427376, 3.94489646, 0.21003141, 1.72415094],
         [-0.47835783, 1.09972989, -0.79757058, 0.71654893]])
wuyuefeng's avatar
wuyuefeng committed
95
96
97
    expected_sunrgbd_gt_bboxes_3d = torch.tensor(
        [[0.1708, 1.1135, -1.0457, 0.6551, 0.6095, 0.9291, 3.0192],
         [-0.5543, 1.4591, -1.0941, 1.5979, 1.7430, 0.6774, -1.6335]])
liyinhao's avatar
liyinhao committed
98
    assert np.allclose(sunrgbd_points, expected_sunrgbd_points)
wuyuefeng's avatar
wuyuefeng committed
99
100
    assert torch.allclose(sunrgbd_gt_bboxes_3d.tensor,
                          expected_sunrgbd_gt_bboxes_3d, 1e-3)
liyinhao's avatar
liyinhao committed
101

liyinhao's avatar
liyinhao committed
102
    np.random.seed(0)
103
    scannet_augment = IndoorGlobalRotScale(
liyinhao's avatar
liyinhao committed
104
        True, rot_range=[-1 * 1 / 36, 1 / 36], scale_range=None)
liyinhao's avatar
liyinhao committed
105
    scannet_results = dict()
liyinhao's avatar
liyinhao committed
106
    scannet_results['points'] = np.array(
liyinhao's avatar
liyinhao committed
107
108
        [[1.6110241e+00, -1.6903955e-01, 5.8115810e-01, 5.9897250e-01],
         [1.3978075e+00, 4.2035791e-01, 3.8729519e-01, 4.0510958e-01]])
wuyuefeng's avatar
wuyuefeng committed
109
110
111
112
113
114
115
116
117
118
119
    scannet_results['gt_bboxes_3d'] = DepthInstance3DBoxes(
        np.array([[
            0.55903838, 0.48201692, 0.65688646, 0.65370704, 0.60029864,
            0.5163464
        ],
                  [
                      -0.03226406, 1.70392646, 0.60348618, 0.65165804,
                      0.72084366, 0.64667457
                  ]]),
        box_dim=6,
        with_yaw=False)
liyinhao's avatar
liyinhao committed
120
    scannet_results = scannet_augment(scannet_results)
121
122
    scannet_points = scannet_results['points']
    scannet_gt_bboxes_3d = scannet_results['gt_bboxes_3d']
123

liyinhao's avatar
liyinhao committed
124
    expected_scannet_points = np.array(
125
126
        [[1.61240576, -0.15530836, 0.5811581, 0.5989725],
         [1.39417555, 0.43225122, 0.38729519, 0.40510958]])
wuyuefeng's avatar
wuyuefeng committed
127
128
129
    expected_scannet_gt_bboxes_3d = torch.tensor(
        [[0.5549, 0.4868, 0.6569, 0.6588, 0.6058, 0.5163, 0.0000],
         [-0.0468, 1.7036, 0.6035, 0.6578, 0.7264, 0.6467, 0.0000]])
liyinhao's avatar
liyinhao committed
130
    assert np.allclose(scannet_points, expected_scannet_points)
wuyuefeng's avatar
wuyuefeng committed
131
132
    assert torch.allclose(scannet_gt_bboxes_3d.tensor,
                          expected_scannet_gt_bboxes_3d, 1e-3)