示例#1
0
def pc_propagation_Knn(sequence, frame, pred, CFG, save_ri):
    sequence_str = "%02d" % sequence
    frame_str = "%06d" % frame

    dirpath = os.path.join("sequences", sequence_str, "predictions")

    scan_name = CONFIG.LIDAR_DATASET + "/sequences/" + sequence_str + "/velodyne/" + "%06d" % (frame) + ".bin"

    color_dict = CFG["color_map"]
    learning_map = CFG["learning_map"]
    nclasses = len(color_dict)
    scan = SemLaserScan(nclasses, map_dict=learning_map, sem_color_dict=color_dict, project=True, W=CONFIG.IMAGE_WIDTH)
    scan.open_scan(scan_name)
    label = np.zeros(scan.points.shape[0])

    X_train, y_train = get_trainig_data(pred, scan)
    knn = KNeighborsClassifier(n_neighbors=3, weights='distance')
    knn.fit(X_train, y_train)
    label = knn.predict(scan.points)

    # Translate to original learning map
    for i in range(scan.points.shape[0]):
        label[i] = CFG["learning_map_inv"][label[i]]

    print(os.path.join(dirpath, frame_str) + ".label")
    labels = label.astype(np.uint32)
    labels.tofile(os.path.join(dirpath, frame_str) + ".label")
    if save_ri == True:
        np.save(os.path.join(dirpath, frame_str), pred)
def pc_propagation_Knn(sequence,frame,pred,CFG,save_ri = False):
        sequence_str = "%02d" % (sequence)
        frame_str = "%06d" % (frame)

        dirpath = os.path.join("sequences",sequence_str,"predictions")

        scan_name = os.path.join(GT_velodyne_path, sequence_str , "velodyne" , "%06d" % (frame)+".bin")

        color_dict = CFG["color_map"]
        learning_map = CFG["learning_map"]
        nclasses = len(color_dict)
        scan = SemLaserScan(nclasses, map_dict = learning_map, sem_color_dict=color_dict,project=True ,W=2048)
        scan.open_scan(scan_name)
        label = np.zeros(scan.points.shape[0])

        if (pred_data == "xyz"):
                X_train, y_train = get_trainig_data(pred,scan,CFG)
                knn = KNeighborsClassifier(n_neighbors = 3,weights='distance')
                knn.fit(X_train,y_train)
                label = knn.predict(scan.points)
                if (reasign_RI == True):
                    label = reasign_RI_values(pred,scan,label)
        if (pred_data == "di"):
                X_train, y_train = get_trainig_data_D_R(pred,scan,CFG)
                #print(X_train.shape)
                knn = KNeighborsClassifier(n_neighbors = 3)
                knn.fit(X_train,y_train)
                array_=np.transpose(np.array((scan.unproj_range,scan.remissions)))
                #print(array_.shape)
                label = knn.predict(array_)
        if (pred_data == "xyzi"):
                rem_scaled = True
                X_train, y_train = get_trainig_data_xyzi(pred,scan,CFG,rem_scaled)
                knn = KNeighborsClassifier(n_neighbors = 3)
                knn.fit(X_train,y_train)
                X_test = np.zeros((scan.points.shape[0],4))
                X_test[:,0:3]=scan.points
                remiss = (scan.remissions)
                if rem_scaled == True:
                    remiss = (scan.remissions*100)-50
                X_test[:,3]=remiss
                #print(array_.shape)
                label = knn.predict(X_test)
        if (pred_data == "simple"):
            	for i in range (scan.points.shape[0]):
            	    	label[i] = pred[scan.proj_y[i],scan.proj_x[i]]   
                        
                        
        #Translate to original learning map
        for i in range (scan.points.shape[0]):
                label[i] = CFG["learning_map_inv"][label[i]]


        print(os.path.join(dirpath,frame_str) + ".label")
        labels = label.astype(np.uint32)
        labels.tofile(os.path.join(dirpath,frame_str) + ".label")
        if save_ri == True:
                np.save(os.path.join(dirpath,frame_str),pred)
示例#3
0
def get_range_image(CFG, bin_file, label_names=None):
    color_dict = CFG["color_map"]
    learning_map = CFG["learning_map"]

    nclasses = len(color_dict)
    scan = SemLaserScan(nclasses,
                        map_dict=learning_map,
                        sem_color_dict=color_dict,
                        project=True,
                        W=CONFIG.IMAGE_WIDTH)
    scan.open_scan(bin_file)
    if label_names is not None:
        scan.open_label(label_names)
        scan.colorize()
        label_channel = scan.proj_sem_label_map.reshape(
            (scan.proj_H, scan.proj_W, 1))
    else:
        label_channel = np.zeros((scan.proj_H, scan.proj_W, 1))
    # Construct tensor with x,y,z,i,d,l
    range_image = np.concatenate((scan.proj_xyz, \
                                  scan.proj_remission.reshape((scan.proj_H, scan.proj_W, 1)), \
                                  scan.proj_range.reshape((scan.proj_H, scan.proj_W, 1)), \
                                  label_channel), \
                                 axis=2)
    return range_image
示例#4
0
def pc_propagation(sequence, frame, pred, CFG, save_ri=False):
    sequence_str = "%02d" % (sequence)
    frame_str = "%06d" % (frame)

    dirpath = os.path.join("sequences", sequence_str, "predictions")

    scan_name = CONFIG.LIDAR_DATASET + "/sequences/" + sequence_str + "/velodyne/" + "%06d" % (frame) + ".bin"

    color_dict = CFG["color_map"]
    learning_map = CFG["learning_map"]
    nclasses = len(color_dict)
    scan = SemLaserScan(nclasses, map_dict=learning_map, sem_color_dict=color_dict, project=True, W=1024)
    scan.open_scan(scan_name)
    label = np.zeros(scan.points.shape[0])

    for i in range(scan.points.shape[0]):
        label[i] = pred[scan.proj_y[i], scan.proj_x[i]]
        # Translate to original learning map
        label[i] = CFG["learning_map_inv"][label[i]]
    print(os.path.join(dirpath, frame_str) + ".label")
    labels = label.astype(np.uint32)
    labels.tofile(os.path.join(dirpath, frame_str) + ".label")
    if save_ri:
        np.save(os.path.join(dirpath, frame_str), pred)
示例#5
0
        # populate the pointclouds
        label_names = [
            os.path.join(dp, f)
            for dp, dn, fn in os.walk(os.path.expanduser(label_paths))
            for f in fn
        ]
        label_names.sort()

        # check that there are same amount of labels and scans
        print(len(label_names))
        print(len(scan_names))
        assert (len(label_names) == len(scan_names))

        # create a scan
        nclasses = len(CFG["labels"])
        scan = SemLaserScan(nclasses, CFG["color_map"], project=False)

        for idx in range(len(scan_names)):
            # open scan
            print(label_names[idx])
            scan.open_scan(scan_names[idx])
            scan.open_label(label_names[idx])
            # make histogram and accumulate
            count = np.bincount(scan.sem_label)
            seq_total += count.sum()
            for key, data in seq_accum.items():
                if count.size > key:
                    seq_accum[key] += count[key]
                    # zero the count
                    count[key] = 0
            for i, c in enumerate(count):
示例#6
0
            for f in fn
        ]
        label_names.sort()

        # check that there are same amount of labels and scans
        if not FLAGS.ignore_safety:
            assert (len(label_names) == len(scan_names))

    # create a scan
    if FLAGS.ignore_semantics:
        scan = LaserScan(
            project=True)  # project all opened scans to spheric proj
    else:
        color_dict = CFG["color_map"]
        nclasses = len(color_dict)
        scan = SemLaserScan(nclasses, color_dict, project=True)

    # create a visualizer
    semantics = not FLAGS.ignore_semantics
    instances = FLAGS.do_instances
    if not semantics:
        label_names = None
    vis = LaserScanVis(scan=scan,
                       scan_names=scan_names,
                       label_names=label_names,
                       offset=FLAGS.offset,
                       semantics=semantics,
                       instances=instances and semantics)

    # print instructions
    print("To navigate:")
示例#7
0
if __name__ == '__main__':
    seq_id = sys.argv[1]

    laser_scan_object = LaserScan()
    CFG = yaml.load(open('config/semantic-kitti.yaml', 'r'))
    color_dict = CFG["color_map"]
    learning_map = CFG["learning_map"]
    color_map_one_shot = {}
    for class_id, color in color_dict.items():
        if learning_map[class_id] in color_map_one_shot:
            continue
        else:
            color_map_one_shot[learning_map[class_id]] = color
    nclasses = len(color_dict)
    sem_laser_scan_object = SemLaserScan(nclasses, color_dict)
    scans = [filename for filename in sorted(glob.glob(os.path.join('/home/ayush/Downloads/sequence01/sequences/' + seq_id + '/velodyne/', '*.bin')))]
    #gt_labels = [filename for filename in sorted(glob.glob(os.path.join('/home/ayush/Downloads/sequence01/sequences/' + seq_id + '/labels/', '*.label')))]
    prediction_labels = [filename for filename in sorted(glob.glob(os.path.join('/home/ayush/Downloads/sequence01/sequences/' + seq_id + '/predictions/', '*.png')))]
    count = 0
    training_data = dict(zip(scans, prediction_labels))
    for scan_filename, prediction_filename in training_data.items():
        sem_laser_scan_object.open_scan(scan_filename)
#     sem_laser_scan_object.open_label(gt_filename)
        sem_laser_scan_object.do_range_projection()
        range_image = sem_laser_scan_object.proj_range
        depth = (range_image * 500)/65536
        depth = cv2.convertScaleAbs(depth, alpha=255)

        prediction = cv2.imread(prediction_filename, -1)
#