55from ...utils import box_utils
66
77
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 ):
99 """
1010 Args:
1111 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):
1616 other_dim = 1 - dim
1717 if enable is None :
1818 enable = np .random .choice ([False , True ], replace = False , p = [0.5 , 0.5 ])
19+
1920 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 ()
2337
24- if gt_boxes .shape [- 1 ] > 7 :
25- gt_boxes [..., 7 + other_dim ] = - gt_boxes [..., 7 + other_dim ]
2638 if return_flip :
27- return gt_boxes , points , enable
28- return gt_boxes , points
39+ return tfs , enable
40+ return tfs
2941
3042
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 ):
3244 """
3345 Args:
3446 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
3850 """
3951 if noise_rotation is None :
4052 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 )
4969
5070 if return_rot :
51- return gt_boxes , points , noise_rotation
52- return gt_boxes , points
71+ return tfs , noise_rotation
72+ return tfs
5373
5474
55- def global_scaling (gt_boxes , points , scale_range , return_scale = False ):
75+ def global_scaling (scale_range , return_scale = False ):
5676 """
5777 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]]
5979 points: (M, 3 + C),
6080 scale_range: [min, max]
6181 Returns:
6282 """
6383 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 )
6586 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
7487
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
9097
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 = {}
92102
93103 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
96106
97107
98108def random_image_flip_horizontal (image , depth_map , gt_boxes , calib ):
0 commit comments