def visualize_pascal(plot_probabilities=False):
    data = load_pascal('val')
    ds = PascalSegmentation()
    for x, y, f, sps in zip(data.X, data.Y, data.file_names, data.superpixels):
        fig, ax = plt.subplots(2, 3)
        ax = ax.ravel()
        image = ds.get_image(f)
        y_pixel = ds.get_ground_truth(f)
        x_raw = load_kraehenbuehl(f)

        boundary_image = mark_boundaries(image, sps)

        ax[0].imshow(image)
        ax[1].imshow(y_pixel, cmap=ds.cmap)
        ax[2].imshow(boundary_image)
        ax[3].imshow(np.argmax(x_raw, axis=-1), cmap=ds.cmap, vmin=0, vmax=256)
        ax[4].imshow(y[sps], cmap=ds.cmap, vmin=0, vmax=256)
        ax[5].imshow(np.argmax(x, axis=-1)[sps], cmap=ds.cmap, vmin=0,
                     vmax=256)
        for a in ax:
            a.set_xticks(())
            a.set_yticks(())
        plt.savefig("figures_pascal_val/%s.png" % f, bbox_inches='tight')
        plt.close()
        if plot_probabilities:
            fig, ax = plt.subplots(3, 7)
            for k in range(21):
                ax.ravel()[k].matshow(x[:, :, k], vmin=0, vmax=1)
            for a in ax.ravel():
                a.set_xticks(())
                a.set_yticks(())
            plt.savefig("figures_pascal_val/%s_prob.png" % f,
                        bbox_inches='tight')
            plt.close()
    tracer()
示例#2
0
def load_pascal_pixelwise(which='train', year="2010"):
    pascal = PascalSegmentation()
    if which not in ["train", "val"]:
        raise ValueError("Expected 'which' to be 'train' or 'val', got %s." %
                         which)
    split_file = pascal_path + "/ImageSets/Segmentation/%s.txt" % which
    files = np.loadtxt(split_file, dtype=np.str)
    files = [f for f in files if f.split("_")[0] <= year]
    X, Y = [], []
    for f in files:
        X.append(load_kraehenbuehl(f))
        Y.append(pascal.get_ground_truth(f))

    return DataBunchNoSP(X, Y, files)
def eval_segment_best_possible():
    ds = PascalSegmentation()
    print("loading")
    data = load_pascal('train')
    print("getting edges")
    data = add_edges(data)
    print("computing segments")
    segments = [get_km_segments(x, ds.get_image(image_name), sps,
                                n_segments=25) for x, image_name, sps in
                zip(data.X, data.file_names, data.superpixels)]
    print("combining superpixels")
    segments = [seg[sp] for seg, sp in zip(segments, data.superpixels)]
    predictions = [gt_in_sp(ds, f, seg)[seg]
                   for seg, f in zip(segments, data.file_names)]
    Y_true = [ds.get_ground_truth(f) for f in data.file_names]
    hamming, jaccard = eval_on_pixels(ds, Y_true, predictions,
                                      print_results=True)
    tracer()