Skip to content

Commit f68aae9

Browse files
committed
Fix some autolabel bugs
1 parent 4d4ae9d commit f68aae9

3 files changed

Lines changed: 69 additions & 39 deletions

File tree

autolabeling/autolabel.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ def get_points_in_fov_90(pc, clip_distance=0.0, max_distance=500):
1111
return pc[fov_inds, :]
1212

1313

14-
def pinhole_projection(points, img, T_cam0, K_cam0):
14+
def pinhole_projection(points, T_cam0, K_cam0):
1515
points_2d = np.zeros((points.shape[0], 2), dtype=np.int32)
16-
height, width = img.shape
1716
points = np.dot(points, np.transpose(T_cam0))
1817

1918
x = points[:, 0]
@@ -24,27 +23,26 @@ def pinhole_projection(points, img, T_cam0, K_cam0):
2423
x_img = (np.dot(K_cam0[0, 0], x / z) + K_cam0[0, 2]).astype(np.int32)
2524
y_img = (np.dot(K_cam0[1, 1], y / z) + K_cam0[1, 2]).astype(np.int32)
2625

27-
# clamp values
28-
x_img = np.clip(x_img, 0, width - 1)
29-
y_img = np.clip(y_img, 0, height - 1)
30-
3126
points_2d[:, 0] = x_img
3227
points_2d[:, 1] = y_img
3328

3429
return points_2d
3530

3631

3732
def transfer_labels(points, semantic, T_cam0, K_cam0):
38-
labels = np.ones((points.shape[0], 1), dtype=points.dtype) * 255
33+
labels = np.zeros((points.shape[0], 1), dtype=points.dtype)
34+
height, width = semantic.shape
3935

40-
points_2d = pinhole_projection(points, semantic, T_cam0, K_cam0)
36+
points_2d = pinhole_projection(points, T_cam0, K_cam0)
4137
semantic = convert_classes_to_lidar_classes(semantic)
4238

4339
x_img = points_2d[:, 0]
4440
y_img = points_2d[:, 1]
4541

46-
label = semantic[y_img, x_img]
47-
labels[:, 0] = label
42+
for i in range(y_img.shape[0]):
43+
if (0 <= x_img[i] < width) and (0 <= y_img[i] < height):
44+
label = semantic[y_img[i], x_img[i]]
45+
labels[i] = label
4846

4947
return np.concatenate((points, labels), axis=1)
5048

@@ -53,7 +51,7 @@ def spherical_projection(points, height=64, width=512):
5351
x = points[:, 0]
5452
y = points[:, 1]
5553
z = points[:, 2]
56-
reflectivity = points[:, 3]
54+
i = points[:, 3]
5755
label = points[:, 4]
5856
d = np.sqrt(x ** 2 + y ** 2 + z ** 2)
5957

@@ -63,15 +61,15 @@ def spherical_projection(points, height=64, width=512):
6361
idx_h = height - 1 - ((height - 1) * (theta - theta.min()) / (theta.max() - theta.min()))
6462
idx_w = width - 1 - ((width - 1) * (phi - phi.min()) / (phi.max() - phi.min()))
6563

66-
idx_h = np.floor(idx_h).astype(np.int32)
67-
idx_w = np.floor(idx_w).astype(np.int32)
64+
idx_h = np.round(idx_h).astype(np.int32)
65+
idx_w = np.round(idx_w).astype(np.int32)
6866

6967
projected_img = np.zeros((height, width, 6), dtype=np.float32)
7068
projected_img[idx_h, idx_w, 0] = x
7169
projected_img[idx_h, idx_w, 1] = y
7270
projected_img[idx_h, idx_w, 2] = z
73-
projected_img[idx_h, idx_w, 3] = d
74-
projected_img[idx_h, idx_w, 4] = reflectivity
71+
projected_img[idx_h, idx_w, 3] = i
72+
projected_img[idx_h, idx_w, 4] = d
7573
projected_img[idx_h, idx_w, 5] = label
7674

7775
return projected_img

autolabeling/classes.py

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,56 @@
44

55
LidarClass = namedtuple('LidarClass', ['name', 'train_id', 'lidar_name', 'lidar_id',
66
'color'])
7+
8+
Class = namedtuple('Class', ['lidar_name', 'lidar_id', 'color'])
9+
10+
classes = [
11+
Class('road', 19, (128, 64, 128)),
12+
Class('sidewalk', 20, (244, 35, 232)),
13+
Class('construction', 21, (70, 70, 70)),
14+
Class('construction', 21, (70, 70, 70)),
15+
Class('unlabeled', 0, (0, 0, 0)),
16+
Class('pole', 22, (153, 153, 153)),
17+
Class('construction', 21, (70, 70, 70)),
18+
Class('traffic sign', 23, (220, 220, 0)),
19+
Class('vegetation', 24, (104, 131, 15)),
20+
Class('terrain', 25, (148, 255, 144)),
21+
Class('sky', 26, (0, 0, 0)),
22+
Class('person', 27, (220, 20, 60)),
23+
Class('rider', 28, (255, 0, 0)),
24+
Class('small vehicle', 29, (0, 0, 142)),
25+
Class('large vehicle', 30, (0, 0, 70)),
26+
Class('large vehicle', 30, (0, 0, 70)),
27+
Class('large vehicle', 30, (0, 0, 70)),
28+
Class('two wheeler', 31, (119, 11, 32)),
29+
Class('two wheeler', 31, (119, 11, 32)),
30+
]
31+
732
lidar_classes = [
8-
LidarClass('road', 0, 'road', 0, (128, 64, 128)),
9-
LidarClass('sidewalk', 1, 'sidewalk', 1, (244, 35, 232)),
10-
LidarClass('building', 2, 'construction', 2, (70, 70, 70)),
11-
LidarClass('wall', 3, 'construction', 2, (70, 70, 70)),
12-
LidarClass('fence', 4, 'unlabeled', 255, (70, 70, 70)),
13-
LidarClass('pole', 5, 'pole', 3, (153, 153, 153)),
14-
LidarClass('traffic light', 6, 'construction', 2, (70, 70, 70)),
15-
LidarClass('traffic sign', 7, 'traffic sign', 4, (220, 220, 0)),
16-
LidarClass('vegetation', 8, 'vegetation', 5, (104, 131, 15)),
17-
LidarClass('terrain', 9, 'terrain', 6, (148, 255, 144)),
18-
LidarClass('sky', 10, 'sky', 7, (0, 0, 0)),
19-
LidarClass('person', 11, 'person', 8, (220, 20, 60)),
20-
LidarClass('rider', 12, 'rider', 9, (255, 0, 0)),
21-
LidarClass('car', 13, 'small vehicle', 10, (0, 0, 142)),
22-
LidarClass('truck', 14, 'large vehicle', 11, (0, 0, 70)),
23-
LidarClass('bus', 15, 'large vehicle', 11, (0, 0, 70)),
24-
LidarClass('train', 16, 'large vehicle', 11, (0, 0, 70)),
25-
LidarClass('motorcycle', 17, 'two wheeler', 12, (119, 11, 32)),
26-
LidarClass('bicycle', 18, 'two wheeler', 12, (119, 11, 32)),
33+
LidarClass('road', 0, 'road', 19, (128, 64, 128)),
34+
LidarClass('sidewalk', 1, 'sidewalk', 20, (244, 35, 232)),
35+
LidarClass('building', 2, 'construction', 21, (70, 70, 70)),
36+
LidarClass('wall', 3, 'construction', 21, (70, 70, 70)),
37+
LidarClass('fence', 4, 'unlabeled', 0, (0, 0, 0)),
38+
LidarClass('pole', 5, 'pole', 22, (153, 153, 153)),
39+
LidarClass('traffic light', 6, 'construction', 21, (70, 70, 70)),
40+
LidarClass('traffic sign', 7, 'traffic sign', 23, (220, 220, 0)),
41+
LidarClass('vegetation', 8, 'vegetation', 24, (104, 131, 15)),
42+
LidarClass('terrain', 9, 'terrain', 25, (148, 255, 144)),
43+
LidarClass('sky', 10, 'sky', 26, (0, 0, 0)),
44+
LidarClass('person', 11, 'person', 27, (220, 20, 60)),
45+
LidarClass('rider', 12, 'rider', 28, (255, 0, 0)),
46+
LidarClass('car', 13, 'small vehicle', 29, (0, 0, 142)),
47+
LidarClass('truck', 14, 'large vehicle', 30, (0, 0, 70)),
48+
LidarClass('bus', 15, 'large vehicle', 30, (0, 0, 70)),
49+
LidarClass('train', 16, 'large vehicle', 30, (0, 0, 70)),
50+
LidarClass('motorcycle', 17, 'two wheeler', 31, (119, 11, 32)),
51+
LidarClass('bicycle', 18, 'two wheeler', 31, (119, 11, 32)),
2752
]
2853

54+
train_id_to_lidar_id = {0: 19, 1: 20, 2: 21, 3: 21, 4: 0, 5: 22, 6: 21, 7: 23, 8: 24, 9: 25, 10: 26, 11: 27, 12: 28,
55+
13: 29, 14: 30, 15: 30, 16: 30, 17: 31, 18: 31, 255: 0}
56+
2957

3058
def convert_classes_to_lidar_classes(target):
3159
target_copy = target.clone()

autolabeling/kitti_demo.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,27 @@ def convert_train_id_to_id(target):
3333

3434

3535
def show_lidar_on_image(points, image, segmentation, T_cam0, K_cam0):
36-
points_2d = autolabel.pinhole_projection(points, segmentation, T_cam0, K_cam0)
36+
points_2d = autolabel.pinhole_projection(points, T_cam0, K_cam0)
3737

3838
cmap = get_cityscapes_colormap()
3939
segmentation = convert_train_id_to_id(segmentation)
4040
vis = colorize_seg(segmentation.cpu(), cmap)
41+
height, width = segmentation.shape
4142

4243
for i in range(points.shape[0]):
4344
img_x = points_2d[i, 0]
4445
img_y = points_2d[i, 1]
46+
img_x = np.clip(img_x, 0, width - 1)
47+
img_y = np.clip(img_y, 0, height - 1)
48+
4549
color = vis[:, img_y, img_x].tolist()
4650
cv2.circle(image, (img_x, img_y), 2, color=tuple(color), thickness=-1)
4751

4852
return image
4953

5054

51-
def show_lidar_depth_on_image(pc_velo, img, segmentation, T_cam0, K_cam0):
52-
points_2d = autolabel.pinhole_projection(pc_velo, segmentation, T_cam0, K_cam0)
55+
def show_lidar_depth_on_image(pc_velo, img, T_cam0, K_cam0):
56+
points_2d = autolabel.pinhole_projection(pc_velo, T_cam0, K_cam0)
5357

5458
cmap = plt.cm.get_cmap('hsv', 256)
5559
cmap = np.array([cmap(i) for i in range(256)])[:, :3] * 255
@@ -143,8 +147,8 @@ def _normalize(x):
143147
proj_img = show_lidar_on_image(pc_velo, np.array(img), pred, dataset.calib.T_cam0_velo, dataset.calib.K_cam0)
144148

145149
record = torch.as_tensor(lidar, dtype=torch.float32).permute(2, 0, 1).contiguous()
146-
distance = record[3, :, :]
147-
reflectivity = record[4, :, :]
150+
reflectivity = record[3, :, :]
151+
distance = record[4, :, :]
148152
label = record[5, :, :]
149153

150154
plot_images(file_name, distance, reflectivity, label, pred, img, proj_img)

0 commit comments

Comments
 (0)