コード例 #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)
コード例 #2
0
                for dp, dn, fn in os.walk(os.path.expanduser(bboxes_paths))
                for f in fn
            ]
            bboxes_names.sort()

            # check that there are same amount of bboxes and scans
            if not FLAGS.ignore_safety:
                assert (len(bboxes_names) == len(scan_names))
    # create a scan
    if FLAGS.ignore_semantics:
        scan = LaserScan(
            project=True)  # project all opened scans to spheric proj
        bboxes_names = None
    else:
        color_dict = CFG["color_map"]
        scan = SemLaserScan(color_dict, project=True)

    # create a visualizer
    semantics = not FLAGS.ignore_semantics
    draw_clusters = FLAGS.draw_clusters
    roi_filter = FLAGS.use_roi_filter
    if not draw_clusters:
        bboxes_names = None
    if not semantics:
        label_names = None
    vis = LaserScanVis(scan=scan,
                       scan_names=scan_names,
                       label_names=label_names,
                       offset=FLAGS.offset,
                       semantics=semantics,
                       bboxes_names=bboxes_names,
    criterion = nn.MSELoss()
    unet_losses = test(test_loader, net, criterion, device)

    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
コード例 #4
0
import os
from laserscan import LaserScan, SemLaserScan


parser = argparse.ArgumentParser("./visualize.py")
parser.add_argument(
    '--config', '-c',
    type=str,
    required=False,
    default="config/labels/semantic-kitti.yaml",
    help='Dataset config file. Defaults to %(default)s',
)
FLAGS, unparsed = parser.parse_known_args()

color_dict = None
scan = SemLaserScan(color_dict, project=False)


data_root = r'G:\MyProject\data\BMVC20\Synthia_results\ssg_atten_results'
save_root = r'G:\MyProject\data\BMVC20\Synthia_results\ssg_atten_results_test'
seqs= ['SYNTHIA-SEQS-01-DAWN', 'SYNTHIA-SEQS-01-FALL', 'SYNTHIA-SEQS-01-NIGHT', 'SYNTHIA-SEQS-01-SUMMER',
        'SYNTHIA-SEQS-01-WINTER', 'SYNTHIA-SEQS-01-WINTERNIGHT', 'SYNTHIA-SEQS-02-DAWN', 'SYNTHIA-SEQS-02-FALL',
        'SYNTHIA-SEQS-02-NIGHT', 'SYNTHIA-SEQS-02-RAINNIGHT', 'SYNTHIA-SEQS-02-SOFTRAIN', 'SYNTHIA-SEQS-02-SUMMER',
        'SYNTHIA-SEQS-02-WINTER', 'SYNTHIA-SEQS-04-DAWN', 'SYNTHIA-SEQS-04-FALL', 'SYNTHIA-SEQS-04-NIGHT',
        'SYNTHIA-SEQS-04-RAINNIGHT', 'SYNTHIA-SEQS-04-SOFTRAIN', 'SYNTHIA-SEQS-04-SUMMER', 'SYNTHIA-SEQS-04-WINTER',
        'SYNTHIA-SEQS-04-WINTERNIGHT', 'SYNTHIA-SEQS-05-FOG', 'SYNTHIA-SEQS-06-SPRING', 'SYNTHIA-SEQS-06-SUNSET']
# 0, 6, 13, 21, 22
# (3, 3), (11, 476), (22, 420)
seq_idx = 22
frame_idx = 420
コード例 #5
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