示例#1
0
def visualize_samples(images, name="results/test.png", layout=[5,5], vrange=[-1., 1.]):
    images = (images - vrange[0]) / (vrange[1]-vrange[0]) * 255.
    images = np.rint(images).astype(np.uint8)
    view = uf.tile_images(images, size=layout)
    if name is None:
        return view
    view = Image.fromarray(view, 'RGB')
    view.save(name)
示例#2
0
    vl_mgen = um.RandomRectangleMaskGenerator(img_shape[0],
                                              img_shape[1],
                                              max_ratio=.5)

    ckpt_file = args.save_dir + '/params_' + args.data_set + '.ckpt'
    print('restoring parameters from', ckpt_file)
    saver.restore(sess, ckpt_file)

    sample_mgen = um.CenterMaskGenerator(obs_shape[0], obs_shape[1], .875)

    d = next(test_data)

    from PIL import Image
    img = Image.fromarray(
        uf.tile_images(np.rint(d).astype(np.uint8), size=(5, 5)), 'RGB')
    img.save(
        os.path.join("plots", '%s_original_%s.png' % (args.data_set, "test")))

    feed_dict = vl.make_feed_dict(d, vl_mgen)
    ret = sess.run([vl.mxs] + vl.zs + vl.x_hats, feed_dict=feed_dict)
    mxs = np.concatenate(ret[0], axis=0)
    mxs *= 255.
    ret = ret[1:]
    zs, x_hats = ret[:len(ret) // 2], ret[len(ret) // 2:]
    x_hats = np.concatenate(x_hats, axis=0)
    x_hats *= 255.

    img = Image.fromarray(
        uf.tile_images(np.rint(mxs).astype(np.uint8), size=(5, 5)), 'RGB')
    img.save(
示例#3
0
    ckpt_file = args.save_dir + '/params_' + args.data_set + '.ckpt'
    print('restoring parameters from', ckpt_file)
    saver.restore(sess, ckpt_file)

    # generate samples from the model
    sample_x = []
    all_data = []
    for i in range(args.num_samples):
        d = next(test_data)
        for k in range(d.shape[0]):
            d[k] = d[2].copy()
        all_data.append(d)
        sample_x.append(sample_from_model(sess, data=all_data[-1]))  ##
    sample_x = np.concatenate(sample_x, axis=0)
    all_data = np.concatenate(all_data, axis=0)
    sample_x = np.rint(sample_x * 127.5 + 127.5)
    all_data = np.rint(all_data)

    for i in range(sample_x.shape[0]):
        ms = sample_mgen.gen(1)[0]
        contour = 1 - uf.find_contour(ms)[:, :, None]
        contour[contour < 1] = 0.8
        sample_x[i] *= contour

    from PIL import Image
    img = Image.fromarray(
        uf.tile_images(sample_x.astype(np.uint8), size=(4, 4)), 'RGB')
    img.save(
        os.path.join("plots",
                     '%s_complete_%s.png' % (args.data_set, exp_label)))
示例#4
0
    all_data = []
    for i in range(args.num_samples):
        all_data.append(next(test_data))
        sample_x.append(sample_from_model(sess, data=all_data[-1])) ##
    sample_x = np.concatenate(sample_x, axis=0)
    all_data = np.concatenate(all_data, axis=0)
    sample_x = np.rint(sample_x * 127.5 + 127.5)
    all_data = np.rint(all_data)
    np.savez(os.path.join("plots",'%s_original_%s.npz' % (args.data_set, exp_label)), all_data)
    np.savez(os.path.join("plots",'%s_complete_%s.npz' % (args.data_set, exp_label)), sample_x)

    print(uf.evaluate(all_data[-100:].astype(np.float64), sample_x[-100:].astype(np.float64)))

    for i in range(sample_x.shape[0]):
        ms = test_mgen.gen(1)[0]
        contour = 1-uf.find_contour(ms)[:, :, None]
        contour[contour<1] = 0.8
        sample_x[i] *= contour

    from PIL import Image
    img = Image.fromarray(uf.tile_images(sample_x.astype(np.uint8), size=(10,10)), 'RGB')
    img.save(os.path.join("plots", '%s_complete_%s.png' % (args.data_set, exp_label)))

    #
    # img_tile = plotting.img_tile(sample_x[:100], aspect_ratio=1.0, border_color=1.0, stretch=True)
    # img = plotting.plot_img(img_tile, title=args.data_set + ' samples')
    # plotting.plt.savefig(os.path.join("plots",'%s_complete_%s.png' % (args.data_set, exp_label)))
    # plotting.plt.close('all')

    # np.savez(os.path.join("plots",'%s_complete_%s.npz' % (args.data_set, exp_label)), sample_x)
示例#5
0
    v.load_vae(sess, v.saver)

    test_mgen = m.RandomRectangleMaskGenerator(64,
                                               64,
                                               min_ratio=0.25,
                                               max_ratio=0.5)

    data = next(test_data)
    data = next(test_data)

    # img_tile = plotting.img_tile(data[:25], aspect_ratio=1.0, border_color=1.0, stretch=True)
    # img = plotting.plot_img(img_tile, title=v.FLAGS.data_set + ' samples')
    # plotting.plt.savefig(os.path.join("plots",'%s_vae_original.png' % (v.FLAGS.data_set)))

    feed_dict = v.make_feed_dict(data, test_mgen)
    ret = sess.run([v.mxs] + v.x_hats, feed_dict=feed_dict)
    mx, x_hat = ret[0], ret[1:]
    mx, x_hat = np.concatenate(mx, axis=0), np.concatenate(x_hat, axis=0)
    mx = np.rint(mx * 255.)
    x_hat = np.rint(x_hat * 255.)

    from PIL import Image
    img = Image.fromarray(uf.tile_images(mx.astype(np.uint8), size=(4, 4)),
                          'RGB')
    img.save(os.path.join("plots", '%s_vae_ori_%s.png' % ('celeba64', "test")))

    img = Image.fromarray(uf.tile_images(x_hat.astype(np.uint8), size=(4, 4)),
                          'RGB')
    img.save(
        os.path.join("plots", '%s_vae_recon_%s.png' % ('celeba64', "test")))