5
5
from ...utils import box_utils
6
6
7
7
8
- def random_flip_along (dim , gt_boxes , points , return_flip = False , enable = None ):
8
+ def random_flip_along (dim , return_flip = False , enable = None ):
9
9
"""
10
10
Args:
11
11
gt_boxes: (*, 7 + C), [x, y, z, dx, dy, dz, heading, [vx], [vy]]
@@ -16,19 +16,31 @@ def random_flip_along(dim, gt_boxes, points, return_flip=False, enable=None):
16
16
other_dim = 1 - dim
17
17
if enable is None :
18
18
enable = np .random .choice ([False , True ], replace = False , p = [0.5 , 0.5 ])
19
+
19
20
if enable :
20
- gt_boxes [..., other_dim ] = - gt_boxes [..., other_dim ]
21
- gt_boxes [..., 6 ] = - (gt_boxes [..., 6 ] + np .pi * dim )
22
- points [..., other_dim ] = - points [..., other_dim ]
21
+ def flip_pointlike (points ):
22
+ points [..., other_dim ] = - points [..., other_dim ]
23
+ return points
24
+
25
+ def flip_boxlike (boxes ):
26
+ boxes [..., other_dim ] = - boxes [..., other_dim ]
27
+ boxes [..., 6 ] = - (boxes [..., 6 ] + np .pi * dim )
28
+
29
+ if boxes .shape [- 1 ] > 7 :
30
+ boxes [..., 7 + other_dim ] = - boxes [..., 7 + other_dim ]
31
+
32
+ return boxes
33
+
34
+ tfs = dict (point = flip_pointlike , box = flip_boxlike )
35
+ else :
36
+ tfs = dict ()
23
37
24
- if gt_boxes .shape [- 1 ] > 7 :
25
- gt_boxes [..., 7 + other_dim ] = - gt_boxes [..., 7 + other_dim ]
26
38
if return_flip :
27
- return gt_boxes , points , enable
28
- return gt_boxes , points
39
+ return tfs , enable
40
+ return tfs
29
41
30
42
31
- def global_rotation (gt_boxes , points , rot_range , return_rot = False , noise_rotation = None ):
43
+ def global_rotation (rot_range , return_rot = False , noise_rotation = None ):
32
44
"""
33
45
Args:
34
46
gt_boxes: (*, 7 + C), [x, y, z, dx, dy, dz, heading, [vx], [vy]]
@@ -38,61 +50,59 @@ def global_rotation(gt_boxes, points, rot_range, return_rot=False, noise_rotatio
38
50
"""
39
51
if noise_rotation is None :
40
52
noise_rotation = np .random .uniform (rot_range [0 ], rot_range [1 ])
41
- points = common_utils .rotate_points_along_z (points [np .newaxis , :, :], np .array ([noise_rotation ]))[0 ]
42
- gt_boxes [..., 0 :3 ] = common_utils .rotate_points_along_z (gt_boxes [np .newaxis , ..., 0 :3 ], np .array ([noise_rotation ]))[0 ]
43
- gt_boxes [..., 6 ] += noise_rotation
44
- if gt_boxes .shape [- 1 ] > 7 :
45
- gt_boxes [..., 7 :9 ] = common_utils .rotate_points_along_z (
46
- np .concatenate ((gt_boxes [..., 7 :9 ], np .zeros ((* gt_boxes .shape [:- 1 ], 1 ))), axis = - 1 )[np .newaxis , ...],
47
- np .array ([noise_rotation ])
48
- )[0 , ..., 0 :2 ]
53
+
54
+ def rotate_pointlike (points ):
55
+ points = common_utils .rotate_points_along_z (points [np .newaxis , :, :], np .array ([noise_rotation ]))[0 ]
56
+ return points
57
+
58
+ def rotate_boxlike (boxes ):
59
+ boxes [..., 0 :3 ] = common_utils .rotate_points_along_z (boxes [np .newaxis , ..., 0 :3 ], np .array ([noise_rotation ]))[0 ]
60
+ boxes [..., 6 ] += noise_rotation
61
+ if boxes .shape [- 1 ] > 7 :
62
+ boxes [..., 7 :9 ] = common_utils .rotate_points_along_z (
63
+ np .concatenate ((boxes [..., 7 :9 ], np .zeros ((* boxes .shape [:- 1 ], 1 ))), axis = - 1 )[np .newaxis , ...],
64
+ np .array ([noise_rotation ])
65
+ )[0 , ..., 0 :2 ]
66
+ return boxes
67
+
68
+ tfs = dict (point = rotate_pointlike , box = rotate_boxlike )
49
69
50
70
if return_rot :
51
- return gt_boxes , points , noise_rotation
52
- return gt_boxes , points
71
+ return tfs , noise_rotation
72
+ return tfs
53
73
54
74
55
- def global_scaling (gt_boxes , points , scale_range , return_scale = False ):
75
+ def global_scaling (scale_range , return_scale = False ):
56
76
"""
57
77
Args:
58
- gt_boxes: (N , 7), [x, y, z, dx, dy, dz, heading, [vx], [vy]]
78
+ gt_boxes: (* , 7), [x, y, z, dx, dy, dz, heading, [vx], [vy]]
59
79
points: (M, 3 + C),
60
80
scale_range: [min, max]
61
81
Returns:
62
82
"""
63
83
if scale_range [1 ] - scale_range [0 ] < 1e-3 :
64
- return gt_boxes , points
84
+ noise_scale = sum (scale_range ) / len (scale_range )
85
+ assert noise_scale == 1.0 , (noise_scale , scale_range )
65
86
noise_scale = np .random .uniform (scale_range [0 ], scale_range [1 ])
66
- points [:, :3 ] *= noise_scale
67
- gt_boxes [:, :6 ] *= noise_scale
68
- if gt_boxes .shape [1 ] > 7 :
69
- gt_boxes [:, 7 :9 ] *= noise_scale
70
-
71
- if return_scale :
72
- return gt_boxes , points , noise_scale
73
- return gt_boxes , points
74
87
75
- def global_scaling_with_roi_boxes (gt_boxes , roi_boxes , points , scale_range , return_scale = False ):
76
- """
77
- Args:
78
- gt_boxes: (N, 7), [x, y, z, dx, dy, dz, heading, [vx], [vy]]
79
- points: (M, 3 + C),
80
- scale_range: [min, max]
81
- Returns:
82
- """
83
- if scale_range [1 ] - scale_range [0 ] < 1e-3 :
84
- return gt_boxes , points
85
- noise_scale = np .random .uniform (scale_range [0 ], scale_range [1 ])
86
- points [:, :3 ] *= noise_scale
87
- gt_boxes [:, :6 ] *= noise_scale
88
- if gt_boxes .shape [1 ] > 7 :
89
- gt_boxes [:, 7 :9 ] *= noise_scale
88
+ def scale_pointlike (points ):
89
+ points [:, :3 ] *= noise_scale
90
+ return points
91
+
92
+ def scale_boxlike (boxes ):
93
+ boxes [..., :6 ] *= noise_scale
94
+ if boxes .shape [- 1 ] > 7 :
95
+ boxes [..., 7 :9 ] *= noise_scale
96
+ return boxes
90
97
91
- roi_boxes [:,:, [0 ,1 ,2 ,3 ,4 ,5 ,7 ,8 ]] *= noise_scale
98
+ if noise_scale != 1.0 :
99
+ tfs = dict (point = scale_pointlike , box = scale_boxlike )
100
+ else :
101
+ tfs = {}
92
102
93
103
if return_scale :
94
- return gt_boxes , roi_boxes , points , noise_scale
95
- return gt_boxes , roi_boxes , points
104
+ return tfs , noise_scale
105
+ return tfs
96
106
97
107
98
108
def random_image_flip_horizontal (image , depth_map , gt_boxes , calib ):
0 commit comments