示例#1
0
    def __getitem__(self, index):
        lidar_file, label_file = self.dataset[index]

        scan = SemLaserScan(self.nclasses,self.color_dict)
        scan.open_scan(lidar_file)
        scan.open_label(label_file)
        ground_indices = np.zeros(scan.sem_label.shape)

        # Find all lidar points associated with ground labels in semantic-kitti dataset
        for label in self.ground_labels:
            ground_indices += (scan.sem_label == label)

        ground_points = scan.points[ground_indices.astype(np.bool)]
        grid = BEVOccupancyGrid(scan.points, 
                                n_x=self.n_x, 
                                n_y=self.n_y, 
                                n_z=self.n_z, 
                                side_range = self.side_range,
                                fwd_range = self.fwd_range,
                                height_range = self.height_range, 
                                filter_external = True
                                )
        grid.compute()
        
        # best-fit quadratic curve (2nd-order)
        A = np.c_[np.ones(ground_points.shape[0]), ground_points[:,:2], np.prod(ground_points[:,:2], axis=1), ground_points[:,:2]**2]
        C,_,_,_ = scipy.linalg.lstsq(A, ground_points[:,2])

        # evaluate it on a grid
        Y, X = np.meshgrid(np.flip(grid.midsegments[0]),np.flip(grid.midsegments[1]))
        XX = X.flatten()
        YY = Y.flatten()
        Z = np.dot(np.c_[np.ones(XX.shape), XX, YY, XX*YY, XX**2, YY**2], C).reshape(X.shape)

        return torch.FloatTensor(grid.grid).permute(2,0,1), torch.FloatTensor(Z).unsqueeze(dim=0)
    print("U-Net MSE Average", np.mean(unet_losses))
    print("U-Net MSE Standard deviation", np.std(unet_losses))

    lidar_height_model_MSE = np.zeros(len(lidar_files))
    lidar_height = -1.73

    i = 0
    for lidar_file in tqdm(lidar_files):

        name = os.path.split(lidar_file)[-1]
        label_file = os.path.join(label_dir,
                                  os.path.splitext(name)[0] + '.label')
        scan = SemLaserScan(nclasses, color_dict)
        scan.open_scan(lidar_file)
        scan.open_label(label_file)
        ground_indices = np.zeros(scan.sem_label.shape)

        # Find all lidar points associated with ground labels in semantic-kitti dataset
        for label in ground_labels:
            ground_indices += (scan.sem_label == label)

        ground_points = scan.points[ground_indices.astype(np.bool)]
        n, _ = ground_points.shape
        ground_height = np.mean(ground_points[:, 2])
        lidar_height_model_MSE[i] = MSE(np.repeat(lidar_height, n),
                                        ground_points[:, 2])

        i += 1

    print("Lidar Height MSE", np.mean(lidar_height_model_MSE))
示例#3
0
    def __call__(self, label_desc):
        label_dir, label_id, cfg = label_desc
        laser = SemLaserScan(sem_color_dict=cfg['color_map'],
                             project=True,
                             H=cfg['sensor']['img_prop']['height'],
                             W=cfg['sensor']['img_prop']['width'],
                             fov_up=cfg['sensor']['fov_up'],
                             fov_down=cfg['sensor']['fov_down'])
        laser.open_scan(
            path.join(self.base_dir, label_dir, 'velodyne',
                      label_id.split('_')[1] + '.bin'))
        laser.open_label(
            path.join(self.base_dir, label_dir, 'labels',
                      label_id.split('_')[1] + '.label'))

        if self.point_cloud:
            ids = np.unique(laser.inst_label)
            ids_sem = np.unique(laser.sem_label)
            depth = laser.unproj_range
            lbl_out = np.zeros(laser.inst_label.shape + (2, ), np.int32)
        else:
            ids = np.unique(laser.proj_inst_label)
            ids_sem = np.unique(laser.proj_sem_label)
            depth = laser.proj_range
            lbl_out = np.zeros(laser.proj_inst_label.shape + (2, ), np.int32)

        for id_sem in ids_sem:
            cls_i = id_sem
            iss_class_id = cfg['learning_map'][cls_i]
            if cfg['instances'][iss_class_id]:
                continue

            else:
                if self.point_cloud:
                    lbl_out[laser.sem_label == cls_i, 0] = iss_class_id
                else:
                    lbl_out[laser.proj_sem_label == cls_i, 0] = iss_class_id

        if self.point_cloud and self.depth_flag:
            laser.inst_label[depth > self.depth_cutoff] = 0
            laser.sem_label[depth > self.depth_cutoff] = 0
            ids = np.unique(laser.inst_label)
            ids_sem = np.unique(laser.sem_label)

        elif self.depth_flag:
            laser.proj_inst_label[depth > self.depth_cutoff] = 0
            laser.proj_sem_label[depth > self.depth_cutoff] = 0
            ids = np.unique(laser.proj_inst_label)
            ids_sem = np.unique(laser.proj_sem_label)

        for id_sem in ids_sem:
            cls_i = id_sem
            iss_class_id = cfg['learning_map'][cls_i]

            if cfg['instances'][iss_class_id]:
                for id_ in ids:
                    if self.point_cloud:
                        mask_i = np.logical_and(laser.sem_label == cls_i,
                                                laser.inst_label == id_)
                    else:
                        mask_i = np.logical_and(laser.proj_sem_label == cls_i,
                                                laser.proj_inst_label == id_)
                    if np.sum(mask_i) < 1:
                        continue
                    lbl_out[mask_i, 1] = int(cls_i) * 1000 + int(id_) + 1
                    lbl_out[mask_i, 0] = iss_class_id
        np.save(path.join(self.out_dir, label_id + ".bin"), lbl_out)
        return True