Example #1
0
def plot():
    import matplotlib.pyplot as plt
    import matplotlib as mpl
    mpl.rcParams['font.family'] = 'serif'
    mpl.rcParams['image.interpolation'] = 'none'
    with open('results.pkl') as f:
        transform_parser, transform_vects, train_losses, tests_losses = pickle.load(f)

    RS = RandomState((seed, "plotting"))
    fig = plt.figure(0)
    fig.clf()
    ax = fig.add_subplot(111)
    omniglot.show_alphabets(omniglot.load_rotated_alphabets(RS, normalize=False, angle=90), ax=ax)
    ax.plot([0, 20 * 28], [5 * 28, 5 * 28], '--k')
    ax.text(-15, 5 * 28 * 3 / 2 - 60, "Rotated alphabets", rotation='vertical')
    plt.savefig("all_alphabets.png")
    # Plotting transformations
    names = ['no_sharing', 'full_sharing', 'learned_sharing']
    title_strings = {'no_sharing'      : 'Independent nets',
                     'full_sharing'    : 'Shared bottom layer',
                     'learned_sharing' : 'Learned sharing'}
    covar_imgs = {name : build_covar_image(transform_vects[name]) for name in names}

    for i, name in enumerate(names):
        fig = plt.figure(0)
        fig.clf()
        fig.set_size_inches((2, 6))
        ax = fig.add_subplot(111)
        ax.matshow(covar_imgs[name], cmap = mpl.cm.binary)
        ax.set_xticks([])
        ax.set_yticks([])
        plt.savefig('learned_corr_{0}.png'.format(i))
        plt.savefig('learned_corr_{0}.pdf'.format(i))
Example #2
0
def plot():
    import matplotlib.pyplot as plt
    import matplotlib as mpl
    mpl.rcParams['font.family'] = 'serif'
    mpl.rcParams['image.interpolation'] = 'none'
    with open('results.pkl') as f:
        transform_parser, transform_vects, train_losses, tests_losses = pickle.load(
            f)

    RS = RandomState((seed, "plotting"))
    fig = plt.figure(0)
    fig.clf()
    ax = fig.add_subplot(111)
    alphabets = omniglot.load_rotated_alphabets(RS, normalize=False, angle=90)
    num_cols = 15
    num_rows = 5
    omniglot.show_alphabets(alphabets, ax=ax, n_cols=num_cols)
    ax.plot([0, num_cols * 28], [num_rows * 28, num_rows * 28], '--k')
    #ax.text(-15, 5 * 28 * 3 / 2 - 60, "Rotated alphabets", rotation='vertical')
    plt.savefig("all_alphabets.png", bbox_inches='tight')

    # Plotting transformations
    names = ['no_sharing', 'full_sharing', 'learned_sharing']
    title_strings = {
        'no_sharing': 'Independent nets',
        'full_sharing': 'Shared bottom layer',
        'learned_sharing': 'Learned sharing'
    }
    covar_imgs = {
        name: build_covar_image(transform_vects[name])
        for name in names
    }

    for model_ix, model_name in enumerate(names):
        image_list = covar_imgs[model_name]
        for layer_ix, image in enumerate(image_list):
            fig = plt.figure(0)
            fig.clf()
            fig.set_size_inches((1, 1))
            ax = fig.add_subplot(111)
            ax.matshow(image, cmap=mpl.cm.binary, vmin=0.0, vmax=1.0)
            ax.set_xticks([])
            ax.set_yticks([])
            plt.savefig('minifigs/learned_corr_{0}_{1}.png'.format(
                model_name, layer_ix),
                        bbox_inches='tight')
            plt.savefig('minifigs/learned_corr_{0}_{1}.pdf'.format(
                model_name, layer_ix),
                        bbox_inches='tight')

    # Write results to a nice latex table for paper.
    with open('results_table.tex', 'w') as f:
        f.write(" & No Sharing & Full Sharing & Learned \\\\\n")
        f.write("Training loss & {:2.2f} & {:2.2f} & {:2.2f} \\\\\n".format(
            train_losses['no_sharing'], train_losses['full_sharing'],
            train_losses['learned_sharing']))
        f.write("Test loss & {:2.2f} & {:2.2f} & \\bf {:2.2f} ".format(
            tests_losses['no_sharing'], tests_losses['full_sharing'],
            tests_losses['learned_sharing']))
Example #3
0
def plot():
    import matplotlib.pyplot as plt
    import matplotlib as mpl

    mpl.rcParams["font.family"] = "serif"
    mpl.rcParams["image.interpolation"] = "none"
    with open("results.pkl") as f:
        transform_parser, transform_vects, train_losses, tests_losses = pickle.load(f)

    RS = RandomState((seed, "plotting"))
    fig = plt.figure(0)
    fig.clf()
    ax = fig.add_subplot(111)
    alphabets = omniglot.load_rotated_alphabets(RS, normalize=False, angle=90)
    num_cols = 15
    num_rows = 5
    omniglot.show_alphabets(alphabets, ax=ax, n_cols=num_cols)
    ax.plot([0, num_cols * 28], [num_rows * 28, num_rows * 28], "--k")
    # ax.text(-15, 5 * 28 * 3 / 2 - 60, "Rotated alphabets", rotation='vertical')
    plt.savefig("all_alphabets.png", bbox_inches="tight")

    # Plotting transformations
    names = ["no_sharing", "full_sharing", "learned_sharing"]
    title_strings = {
        "no_sharing": "Independent nets",
        "full_sharing": "Shared bottom layer",
        "learned_sharing": "Learned sharing",
    }
    covar_imgs = {name: build_covar_image(transform_vects[name]) for name in names}

    for model_ix, model_name in enumerate(names):
        image_list = covar_imgs[model_name]
        for layer_ix, image in enumerate(image_list):
            fig = plt.figure(0)
            fig.clf()
            fig.set_size_inches((1, 1))
            ax = fig.add_subplot(111)
            ax.matshow(image, cmap=mpl.cm.binary, vmin=0.0, vmax=1.0)
            ax.set_xticks([])
            ax.set_yticks([])
            plt.savefig("minifigs/learned_corr_{0}_{1}.png".format(model_name, layer_ix), bbox_inches="tight")
            plt.savefig("minifigs/learned_corr_{0}_{1}.pdf".format(model_name, layer_ix), bbox_inches="tight")

    # Write results to a nice latex table for paper.
    with open("results_table.tex", "w") as f:
        f.write(" & No Sharing & Full Sharing & Learned \\\\\n")
        f.write(
            "Training loss & {:2.2f} & {:2.2f} & {:2.2f} \\\\\n".format(
                train_losses["no_sharing"], train_losses["full_sharing"], train_losses["learned_sharing"]
            )
        )
        f.write(
            "Test loss & {:2.2f} & {:2.2f} & \\bf {:2.2f} ".format(
                tests_losses["no_sharing"], tests_losses["full_sharing"], tests_losses["learned_sharing"]
            )
        )
Example #4
0
def plot():
    import matplotlib.pyplot as plt
    import matplotlib as mpl
    mpl.rcParams['font.family'] = 'serif'

    with open('results.pkl') as f:
        transform_parser, transform_vects, train_losses, tests_losses = pickle.load(
            f)

    omniglot.show_alphabets(omniglot.load_flipped_alphabets(normalize=False))

    # Plotting transformations
    names = ['no_sharing', 'full_sharing', 'learned_sharing']
    title_strings = {
        'no_sharing': 'Independent nets',
        'full_sharing': 'Shared bottom layer',
        'learned_sharing': 'Learned sharing'
    }
    covar_imgs = {
        name: build_covar_image(transform_vects[name])
        for name in names
    }

    prop = {'family': 'serif', 'size': '12'}

    fig = plt.figure(0)
    fig.clf()
    fig.set_size_inches((6, 6))
    for i, name in enumerate(names):
        ax = fig.add_subplot(1, 3, i + 1)
        ax.imshow(covar_imgs[name], cmap=mpl.cm.binary)
        ax.set_title(title_strings[name])
        ax.set_xticks([])
        ax.set_yticks([])
        if i == 0:
            labels = ["Layer {0}".format(layer) for layer in [3, 2, 1]]
            ypos = [5, 15, 25]
            for s, y in zip(labels, ypos):
                ax.text(-2, y, s, rotation='vertical')
    plt.tight_layout()
    plt.savefig('learned_corr.png')
    plt.savefig('learned_corr.pdf')
Example #5
0
def plot():
    import matplotlib.pyplot as plt
    import matplotlib as mpl

    mpl.rcParams["font.family"] = "serif"

    with open("results.pkl") as f:
        transform_parser, transform_vects, train_losses, tests_losses = pickle.load(f)

    omniglot.show_alphabets(omniglot.load_flipped_alphabets(normalize=False))

    # Plotting transformations
    names = ["no_sharing", "full_sharing", "learned_sharing"]
    title_strings = {
        "no_sharing": "Independent nets",
        "full_sharing": "Shared bottom layer",
        "learned_sharing": "Learned sharing",
    }
    covar_imgs = {name: build_covar_image(transform_vects[name]) for name in names}

    prop = {"family": "serif", "size": "12"}

    fig = plt.figure(0)
    fig.clf()
    fig.set_size_inches((6, 6))
    for i, name in enumerate(names):
        ax = fig.add_subplot(1, 3, i + 1)
        ax.imshow(covar_imgs[name], cmap=mpl.cm.binary)
        ax.set_title(title_strings[name])
        ax.set_xticks([])
        ax.set_yticks([])
        if i == 0:
            labels = ["Layer {0}".format(layer) for layer in [3, 2, 1]]
            ypos = [5, 15, 25]
            for s, y in zip(labels, ypos):
                ax.text(-2, y, s, rotation="vertical")
    plt.tight_layout()
    plt.savefig("learned_corr.png")
    plt.savefig("learned_corr.pdf")
Example #6
0
def plot():
    import matplotlib.pyplot as plt
    import matplotlib as mpl
    mpl.rcParams['font.family'] = 'serif'

    with open('results.pkl') as f:
        transform_parser, transform_vects, train_losses, tests_losses = pickle.load(f)
    RS = RandomState((seed, "top_rs"))
    omniglot.show_alphabets(omniglot.load_flipped_alphabets(RS, normalize=False))

    # Plotting transformations
    names = ['no_sharing', 'full_sharing', 'learned_sharing']
    title_strings = {'no_sharing'      : 'Independent\nnets',
                     'full_sharing'    : 'Shared\nbottom layer',
                     'learned_sharing' : 'Learned\nsharing'}
    covar_imgs = {name : build_covar_image(transform_vects[name]) for name in names}

    prop={'family':'serif', 'size':'12'}

    fig = plt.figure(0)
    fig.clf()
    fig.set_size_inches((4,4))
    for i, name in enumerate(names):
        ax = fig.add_subplot(1, 3, i + 1)
        ax.matshow(covar_imgs[name], cmap = mpl.cm.binary)
        ax.set_title(title_strings[name])
        ax.set_xticks([])
        ax.set_yticks([])
        if i == 0:
            labels = ["Layer {0}".format(layer) for layer in [3, 2, 1]]            
            ypos   = [5, 15, 25]
            for s, y in zip(labels, ypos):
                ax.text(-3, y, s, rotation='vertical')
    plt.tight_layout()
    plt.savefig('learned_corr.png')
    plt.savefig('learned_corr.pdf')