def main(): num_samples = 10000 samples_true = sampler.gaussian_mixture_circle( num_samples, num_cluster=generator_params["config"]["num_mixture"], scale=2, std=0.2) plot_scatter(samples_true, args.plot_dir, "scatter_true") plot_kde(samples_true, args.plot_dir, "kde_true") samples_fake = gan.to_numpy(gan.generate_x(num_samples, test=True)) plot_scatter(samples_fake, args.plot_dir, "scatter_gen") plot_kde(samples_fake, args.plot_dir, "kde_gen")
def plot_samples(epoch, progress): samples_fale = gan.generate_x(10000, from_gaussian=True) samples_fale.unchain_backward() samples_fale = gan.to_numpy(samples_fale) try: plot_scatter(samples_fale, dir=args.plot_dir, filename="scatter_epoch_{}_time_{}min".format( epoch, progress.get_total_time())) plot_kde(samples_fale, dir=args.plot_dir, filename="kde_epoch_{}_time_{}min".format( epoch, progress.get_total_time())) except: pass
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.to_variable(gan.sample_z(batchsize)) # optimize z class_true = gan.to_variable(np.zeros(batchsize, dtype=np.int32)) for n in xrange(5): x_fake = gan.generate_x_from_z(base_z, test=True, as_numpy=False) discrimination_fake, _ = gan.discriminate(x_fake, apply_softmax=False, test=True) cross_entropy = F.softmax_cross_entropy(discrimination_fake, class_true) gan.backprop_generator(cross_entropy) base_z = gan.to_variable(base_z.data + base_z.grad * 0.01) base_z = gan.to_numpy(base_z) sum_z = np.sum(base_z) if sum_z != sum_z: raise Exception("NaN") 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 visualizer.tile_rgb_images(x_negative.transpose(0, 2, 3, 1), dir=args.plot_dir, filename="analogy_1", row=num_generation, col=num_col)