import util from args import args from model import conf, vae from vae_m1 import GaussianM1VAE from chainer import functions as F from PIL import Image try: os.mkdir(args.vis_dir) except: pass dist = "bernoulli" if isinstance(vae, GaussianM1VAE): dist = "gaussian" dataset, labels = util.load_labeled_images(args.test_image_dir, dist=dist) num_images = 5000 x, y_labeled, label_ids = util.sample_x_and_label_variables(num_images, conf.ndim_x, 10, dataset, labels, gpu_enabled=False) if conf.gpu_enabled: x.to_gpu() z = vae.encoder(x, test=True) _x = vae.decoder(z, True, True) if conf.gpu_enabled: z.to_cpu() _x.to_cpu() util.visualize_x(_x.data, dir=args.vis_dir) print "visualizing x" util.visualize_z(z.data, dir=args.vis_dir) print "visualizing z" util.visualize_labeled_z(z.data, label_ids.data, dir=args.vis_dir)
import sampler max_epoch = 1000 num_trains_per_epoch = 1000 batchsize = 100 n_steps_to_optimize_dis = 1 # Create labeled/unlabeled split in training set n_types_of_label = conf.ndim_y n_labeled_data = args.n_labeled_data n_validation_data = 10000 # Export result to csv csv_epoch = [] dataset, labels = util.load_labeled_images(args.train_image_dir) labeled_dataset, labels, unlabeled_dataset, validation_dataset, validation_labels = util.create_semisupervised( dataset, labels, n_validation_data, n_labeled_data, n_types_of_label) def sample_labeled_data(): x, y_onehot, y_id = util.sample_x_and_label_variables( batchsize, conf.ndim_x, conf.ndim_y, labeled_dataset, labels, gpu_enabled=conf.gpu_enabled) noise = sampler.gaussian(batchsize, conf.ndim_x, mean=0,
sys.path.append(os.path.split(os.getcwd())[0]) import util from args import args from model import conf1, vae1, conf2, vae2 from vae_m1 import GaussianM1VAE try: os.mkdir(args.vis_dir) except: pass dist = "bernoulli" if isinstance(vae1, GaussianM1VAE): dist = "gaussian" dataset, labels = util.load_labeled_images(args.test_image_dir, dist=dist) num_plot = 10000 x = util.sample_x_variable(num_plot, conf1.ndim_x, dataset, gpu_enabled=conf1.gpu_enabled) z1 = vae1.encoder(x, test=True) y = vae2.sample_x_y(z1, test=True) z2 = vae2.encode_xy_z(z1, y, test=True) _z1 = vae2.decode_zy_x(z2, y, test=True, apply_f=True) _x = vae1.decoder(_z1, test=True) if conf1.gpu_enabled: z2.to_cpu() _x.to_cpu()