Ejemplo n.º 1
0
def save_samples(gan, i_iter):
    gan.netG.eval()

    if 'noise' not in save_samples.__dict__:
        save_samples.noise = Variable(gan.gen_latent_noise(410, opt.nz))

    if not os.path.exists(opt.path + 'tmp/'):
        os.makedirs(opt.path + 'tmp/')

    y = np.repeat(np.arange(41), 10)
    y = torch.autograd.Variable(torch.from_numpy(y))
    if gan.opt.cuda:
        y = y.cuda()

    noise = save_samples.noise
    noise = gan.join_xy((noise, y))

    fake = netG(noise)

    fake = fake.view(-1, 2, 48, 80)

    fake_01 = torch.FloatTensor(len(fake), 3, 48, 80).fill_(-1)
    fake_01[:, :2, :, :] = (fake.data.cpu() + 1.0) * 0.5
    # print(fake_01.min(), fake_01.max())

    save_image(fake_01,
               opt.path + 'tmp/' + '{:0>5}.png'.format(i_iter),
               nrow=10)
    # alkjfd
    gan.netG.train()
Ejemplo n.º 2
0
def save_samples(gan, i_iter):
    if 'noise' not in save_samples.__dict__:
        save_samples.noise = Variable(gan.gen_latent_noise(64, opt.nz))

    if not os.path.exists(opt.path + 'tmp/'):
        os.makedirs(opt.path + 'tmp/')

    fake = gan.gen_fake_data(64, opt.nz, noise=save_samples.noise)
    # fake = next(data_iter)

    fake_01 = (fake[0].data.cpu() + 1.0) * 0.5

    save_image(fake_01, opt.path + 'tmp/' + '{:0>5}.jpeg'.format(i_iter))
Ejemplo n.º 3
0
def save_samples(gan, i_iter):
    gan.netG.eval()

    if 'noise' not in save_samples.__dict__:
        save_samples.noise = Variable(gan.gen_latent_noise(41 * 34, opt.nz))

    if not os.path.exists(opt.path + 'tmp/'):
        os.makedirs(opt.path + 'tmp/')

    y1 = np.repeat(np.arange(41), 34)

    # go = np.array((41*34, 295))

    # for i, y in enumerate(y1):
    #     go[i,:] = data.go_dict[data.id2prt[y1[i]]]

    # go = torch.autograd.Variable(torch.from_numpy(go))

    y1 = torch.autograd.Variable(torch.from_numpy(y1))
    if gan.opt.cuda:
        y1 = y1.cuda()

    y2 = np.tile(np.arange(34), 41)
    y2 = torch.autograd.Variable(torch.from_numpy(y2))
    if gan.opt.cuda:
        y2 = y2.cuda()

    noise = save_samples.noise
    # noise = gan.join_xy((noise, y))

    fake = netG(noise, y1, y2)
    # fake = netG(noise)

    fake = fake.view(-1, 2, 48, 128)

    fake_01 = torch.FloatTensor(len(fake), 3, 48, 128).fill_(-1)
    fake_01[:, :2, :, :] = (fake.data.cpu() + 1.0) * 0.5
    # print(fake_01.min(), fake_01.max())

    save_image(fake_01,
               opt.path + 'tmp/' + '{:0>5}.png'.format(i_iter),
               nrow=34)
    # alkjfd
    gan.netG.train()
Ejemplo n.º 4
0
def save_samples(gan, i_iter):
    gan.netG.eval()

    if 'noise' not in save_samples.__dict__:
        save_samples.noise = Variable(gan.gen_latent_noise(64, opt.nz))

    if not os.path.exists(opt.path + 'tmp/'):
        os.makedirs(opt.path + 'tmp/')

    fake = gan.gen_fake_data(64, opt.nz, noise=save_samples.noise)
    # fake = next(data_iter)
    # print(fake.min(), fake.max())

    fake = fake.view(-1, 3, 32, 32)

    fake_01 = (fake.data.cpu() + 1.0) * 0.5
    # print(fake_01.min(), fake_01.max())

    save_image(fake_01, opt.path + 'tmp/' + '{:0>5}.jpeg'.format(i_iter))
    # alkjfd
    gan.netG.train()
Ejemplo n.º 5
0
def save_samples(gan, i_iter):
    gan.netG.eval()

    if 'noise' not in save_samples.__dict__:
        save_samples.noise = Variable(gan.gen_latent_noise(64, opt.nz))

    if not os.path.exists(opt.path + 'tmp/'):
        os.makedirs(opt.path + 'tmp/')

    fake = gan.gen_fake_data(64, opt.nz, noise=save_samples.noise)
    # fake = next(data_iter)

    fake_list = []

    for i in range(len(fake)):
        for j in range(41):
            img = torch.stack([fake[i, 0, :, :], fake[i, j + 1, :, :]], dim=0)
            fake_list.append(img)

    fake = torch.FloatTensor(len(fake_list), 3, 48, 80)
    fake_tensor = torch.stack(fake_list, dim=0)
    # print(type(fake_tensor))
    # print(type(fake))
    fake[:, :2, :, :] = fake_tensor.data
    fake[:, 2, :, :] = -1

    # fake = next(data_iter)
    # print(fake.min(), fake.max())

    # fake = fake.view(-1, 3, 32, 32)

    fake_01 = (fake.cpu() + 1.0) * 0.5
    # print(fake_01.min(), fake_01.max())

    save_image(fake_01,
               opt.path + 'tmp/' + '{:0>5}.png'.format(i_iter),
               nrow=41)
    gan.netG.train()