Exemple #1
0
def plot_interpolation_generator():
    # config
    config = began.config

    num_col = 10
    num_generation = 20
    batchsize = 2 * num_generation
    base_z = began.sample_z(batchsize)

    mix_z = np.zeros((num_col * num_generation, config.ndim_z),
                     dtype=np.float32)
    for g in xrange(num_generation):
        for i in xrange(num_col):
            mix_z[g * num_col +
                  i] = base_z[2 * g] * (i / float(num_col)) + base_z[
                      2 * g + 1] * (1 - i / float(num_col))

    x = began.generate_x_from_z(mix_z, test=True, as_numpy=True)
    x = (x + 1.0) / 2.0

    plot.tile_rgb_images(x.transpose(0, 2, 3, 1),
                         dir=args.plot_dir,
                         filename="interpolation_generator",
                         row=num_generation,
                         col=num_col)
Exemple #2
0
def run_method_1():
	# config
	discriminator_config = gan.config_discriminator
	generator_config = gan.config_generator

	num_col = 10
	num_generation = 20
	batchsize = 2 * num_generation
	base_z = gan.sample_z(batchsize)

	mix_z = np.zeros((num_col * num_generation, generator_config.ndim_input), dtype=np.float32)
	for g in xrange(num_generation):
		for i in xrange(num_col):
			mix_z[g * num_col + i] = base_z[2 * g] * (i / float(num_col)) + base_z[2 * g + 1] * (1 - i / float(num_col))

	x_negative = gan.generate_x_from_z(mix_z, test=True, as_numpy=True)
	x_negative = (x_negative + 1.0) / 2.0
	
	# optimize z
	# xp = gan.xp
	# x_fake = gan.generate_x_from_z(mix_z, test=True, as_numpy=False)
	# x_fake.unchain_backward()
	# for n in xrange(500):
	# 	discrimination_fake, _ = gan.discriminate(x_fake, test=True)
	# 	opt = F.sum(discrimination_fake)
	# 	print opt.data
	# 	opt.backward()
	# 	# gan.backprop_generator(-F.sum(discrimination_fake))
	# 	x_fake = gan.to_variable(xp.clip(x_fake.data + x_fake.grad * 0.01, -1, 1))

	# x_negative = gan.to_numpy(x_fake)
	# x_negative = (x_negative + 1.0) / 2.0

	plot.tile_rgb_images(x_negative.transpose(0, 2, 3, 1), dir=args.plot_dir, filename="analogy_1", row=num_generation, col=num_col)
Exemple #3
0
def plot_interpolation_discriminator():
    # config
    config = began.config

    num_col = 10
    num_generation = 20
    batchsize = 2 * num_generation
    base_h = np.random.uniform(-1, 1,
                               (batchsize, config.ndim_h)).astype(np.float32)

    mix_h = np.zeros((num_col * num_generation, config.ndim_h),
                     dtype=np.float32)
    for g in xrange(num_generation):
        for i in xrange(num_col):
            mix_h[g * num_col +
                  i] = base_h[2 * g] * (i / float(num_col)) + base_h[
                      2 * g + 1] * (1 - i / float(num_col))

    x = began.decode(mix_h, test=True, as_numpy=True)
    x = (x + 1.0) / 2.0
    plot.tile_rgb_images(x.transpose(0, 2, 3, 1),
                         dir=args.plot_dir,
                         filename="interpolation_discriminator",
                         row=num_generation,
                         col=num_col)