13
13
from ..utils import position , read_yaml
14
14
from ..cloudproc import filter_grid
15
15
from ..utils import normalize , load_calib
16
- from .coco import COCO_CATEGORIES , COCO_CLASSES
17
16
from .wildscenes .utils2d import METAINFO as WILDSCENES_METAINFO
18
17
from PIL import Image
19
18
from tqdm import tqdm
@@ -81,7 +80,7 @@ def __init__(self, path,
81
80
self .is_train = is_train
82
81
83
82
if lss_cfg is None :
84
- lss_cfg = read_yaml (os .path .join (monoforce_dir , 'config' , 'lss_cfg .yaml' ))
83
+ lss_cfg = read_yaml (os .path .join (monoforce_dir , 'config' , 'lss_cfg_wildscenes .yaml' ))
85
84
self .lss_cfg = lss_cfg
86
85
self .grid_res = lss_cfg ['grid_conf' ]['xbound' ][2 ]
87
86
@@ -505,28 +504,14 @@ def get_images_data(self, i):
505
504
return img_data
506
505
507
506
def seg_label_to_color (self , seg_label ):
508
- coco_colors = [(np .array (color ['color' ])).tolist () for color in COCO_CATEGORIES ] + [[0 , 0 , 0 ]]
509
- seg_label = np .asarray (seg_label )
510
- # transform segmentation labels to colors
511
- size = [s for s in seg_label .shape ] + [3 ]
512
- seg_color = np .zeros (size , dtype = np .uint8 )
513
- for color_i , color in enumerate (coco_colors ):
514
- seg_color [seg_label == color_i ] = color
507
+ label_2_rgb = {cidx : p for cidx , p in zip (WILDSCENES_METAINFO ['cidx' ], WILDSCENES_METAINFO ['palette' ])}
508
+ seg_color = np .zeros (list (seg_label .shape ) + [3 ], dtype = np .float32 )
509
+ for cidx , c in label_2_rgb .items ():
510
+ seg_color [seg_label == cidx ] = c
511
+ seg_color /= 255.
515
512
return seg_color
516
513
517
514
def get_seg_label (self , i , camera = None ):
518
- if camera is None :
519
- camera = self .camera_names [0 ]
520
- id = self .ids [i ]
521
- seg_path = os .path .join (self .path , 'images/seg/' , '%s_%s.npy' % (id , camera ))
522
- assert os .path .exists (seg_path ), f'Image path { seg_path } does not exist'
523
- seg = Image .fromarray (np .load (seg_path ))
524
- size = self .get_raw_img_size (i , camera )
525
- transform = torchvision .transforms .Resize (size )
526
- seg = transform (seg )
527
- return seg
528
-
529
- def get_seg_label_wildscenes (self , i , camera = None ):
530
515
if camera is None :
531
516
camera = self .camera_names [0 ]
532
517
id = self .ids [i ]
@@ -537,68 +522,8 @@ def get_seg_label_wildscenes(self, i, camera=None):
537
522
transform = torchvision .transforms .Resize (size )
538
523
seg = transform (seg )
539
524
return seg
540
-
541
- def get_semantic_cloud (self , i , classes = None , vis = False ):
542
- if classes is None :
543
- classes = np .copy (COCO_CLASSES )
544
- # ids of classes in COCO
545
- selected_labels = []
546
- for c in classes :
547
- if c in COCO_CLASSES :
548
- selected_labels .append (COCO_CLASSES .index (c ))
549
525
550
- lidar_points = position (self .get_cloud (i , gravity_aligned = False ))
551
- points = []
552
- labels = []
553
- for cam in self .camera_names [::- 1 ]:
554
- seg_label_cam = self .get_seg_label (i , camera = cam )
555
- seg_label_cam = np .asarray (seg_label_cam )
556
-
557
- K = self .calib [cam ]['camera_matrix' ]['data' ]
558
- K = np .asarray (K , dtype = np .float32 ).reshape ((3 , 3 ))
559
- E = self .calib ['transformations' ][f'T_base_link__{ cam } ' ]['data' ]
560
- E = np .asarray (E , dtype = np .float32 ).reshape ((4 , 4 ))
561
-
562
- lidar_points = torch .as_tensor (lidar_points )
563
- E = torch .as_tensor (E )
564
- K = torch .as_tensor (K )
565
-
566
- img_plane_points = ego_to_cam (lidar_points .T , E [:3 , :3 ], E [:3 , 3 ], K ).T
567
- mask = get_only_in_img_mask (img_plane_points .T , seg_label_cam .shape [0 ], seg_label_cam .shape [1 ])
568
- img_plane_points = img_plane_points [mask ]
569
- cam_points = lidar_points [mask ].numpy ()
570
-
571
- # colorize point cloud with values from segmentation image
572
- uv = img_plane_points [:, :2 ].numpy ().astype (int )
573
- seg_label_cam = seg_label_cam [uv [:, 1 ], uv [:, 0 ]]
574
-
575
- points .append (cam_points )
576
- labels .append (seg_label_cam )
577
-
578
- points = np .concatenate (points )
579
- labels = np .concatenate (labels )
580
- colors = self .seg_label_to_color (labels )
581
- assert len (points ) == len (colors )
582
-
583
- # mask out points with labels not in selected classes
584
- mask = np .isin (labels , selected_labels )
585
- points = points [mask ]
586
- colors = colors [mask ]
587
-
588
- # gravity-aligned cloud
589
- pose_grav_aligned = self .get_initial_pose_on_heightmap (i )
590
- points = transform_cloud (points , pose_grav_aligned )
591
-
592
- if vis :
593
- colors = normalize (colors )
594
- pcd = o3d .geometry .PointCloud ()
595
- pcd .points = o3d .utility .Vector3dVector (points )
596
- pcd .colors = o3d .utility .Vector3dVector (colors )
597
- o3d .visualization .draw_geometries ([pcd ])
598
-
599
- return points , colors
600
-
601
- def get_semantic_cloud_wildscenes (self , i , classes = None , vis = False ):
526
+ def get_semantic_cloud (self , i , classes = None , vis = False ):
602
527
mi = WILDSCENES_METAINFO
603
528
if classes is None :
604
529
classes = mi ['classes' ]
@@ -609,7 +534,7 @@ def get_semantic_cloud_wildscenes(self, i, classes=None, vis=False):
609
534
points = []
610
535
labels = []
611
536
for cam in self .camera_names [::- 1 ]:
612
- seg_label_cam = self .get_seg_label_wildscenes (i , camera = cam )
537
+ seg_label_cam = self .get_seg_label (i , camera = cam )
613
538
seg_label_cam = np .asarray (seg_label_cam )
614
539
615
540
K = self .calib [cam ]['camera_matrix' ]['data' ]
@@ -692,7 +617,7 @@ def get_terrain_height_map(self, i, cached=True, dir_name=None):
692
617
else :
693
618
traj_points = self .get_footprint_traj_points (i , T_horizon = 10.0 )
694
619
soft_classes = self .lss_cfg ['soft_classes' ]
695
- rigid_classes = [c for c in COCO_CLASSES if c not in soft_classes ]
620
+ rigid_classes = [c for c in WILDSCENES_METAINFO [ 'classes' ] if c not in soft_classes ]
696
621
seg_points , _ = self .get_semantic_cloud (i , classes = rigid_classes , vis = False )
697
622
points = np .concatenate ((seg_points , traj_points ), axis = 0 )
698
623
points = torch .as_tensor (points , dtype = torch .float32 )
0 commit comments