Beispiel #1
0
    def __init__(self, opt):
        super(_competitionGan, self).__init__(opt)
        self.opt = opt
        self.x_dim = opt.x_dim
        self.z_dim = opt.z_dim
        self.condition_D = opt.condition_D
        self.nums = opt.nums
        self.mb_size = opt.mb_size
        self.Lambda = opt.Lambda
        self.savepath = opt.savepath
        self.cnt = 0

        self.netGs = create_nets(opt.g_model, opt.z_dim, opt.nums, type='G')
        self.netD = build_netD(opt.d_model, opt.x_dim, opt.condition_D)


        X = torch.FloatTensor(opt.mb_size, opt.x_dim, opt.img_size, opt.img_size)
        Z = torch.FloatTensor(opt.mb_size, opt.z_dim, 1, 1)

        condition_data = torch.FloatTensor(opt.mb_size, opt.img_size * opt.img_size + opt.condition_D)
        real_like_sample = torch.FloatTensor(opt.mb_size, opt.img_size*opt.img_size)
        fake_like_sample = torch.FloatTensor(opt.mb_size, opt.img_size*opt.img_size)
        
        label = torch.FloatTensor(opt.mb_size)
        self.criterionGAN = torch.nn.BCELoss()
        self.criterionL1 = torch.nn.L1Loss()

        if self.cuda:
            netD.cuda()
            netG.cuda()
            self.criterionGAN.cuda()
            self.L1loss.cuda()
            X, Z = X.cuda(), Z.cuda()
            condition_data = condition_data.cuda()
            real_like_sample, fake_like_sample = real_like_sample.cuda(), fake_like_sample.cuda()
            label = label.cuda()

        self.X = Variable(X)
        self.Z = Variable(Z)
        self.condition_data = Variable(condition_data)
        self.real_like_sample = Variable(real_like_sample)
        self.fake_like_sample = Variable(fake_like_sample)
        self.label= Variable(label)

        if self.opt.cc:
            self.create_tensorboard()
            self.index_exp = create_sigle_experiment(self.cc, 'index')
        self.D_solver = torch.optim.Adam(self.netD.parameters(), lr=2e-4, betas=(0.5, 0.999))
        self.G_solvers = create_optims(self.netGs, [2e-4, (0.5, 0.999)])

        if opt.train == False:
            self.load_networkG(self.opt.g_network_path)
            self.load_networkD(self.opt.d_network_path)
        else:
            init_network(self.netD)
            init_network(self.netGs)
Beispiel #2
0
cc.remove_all_experiments()
D_exp = create_sigle_experiment(cc, 'D_loss')
G_exps = create_experiments(cc, 10)

netG_share = build_netG(config['G'][2], z_dim)
netG_indeps = create_nets(config['G'], h_dim, nets_num)
netD = build_netD(config['D'][2], x_dim)

init_network(netG_share)
init_network(netG_indeps)
init_network(netD)

D_solver = optim.Adam(netD.parameters(), lr=lr)
G_share_solver = optim.Adam(netG_share.parameters(), lr=lr)
G_indep_solver = create_optims(netG_indeps, [
    lr,
])
G_solvers = create_couple2one_optims(netG_share, netG_indeps, [
    lr,
])

X = torch.FloatTensor(mb_size, x_dim)
z = torch.FloatTensor(mb_size, z_dim)
label = torch.FloatTensor(mb_size)

if cuda:
    X, z = X.cuda(), z.cuda()
    label = label.cuda()

X = Variable(X)
z = Variable(z)
Beispiel #3
0
    def __init__(self, opt):
        super(_competitionGan, self).__init__(opt)
        self.opt = opt
        self.x_dim = opt.x_dim
        self.z_dim = opt.z_dim
        self.condition_D = opt.condition_D
        self.mb_size = opt.mb_size
        self.Lambda = opt.Lambda
        self.continue_train = opt.continue_train
        self.train = opt.train
        self.test = True if self.continue_train and self.train else False
        self.savepath = '{}{}/'.format(opt.savepath, opt.gans_type)
        self.cnt = 0

        self.netGs = []
        for index in range(self.nums):
            netG = build_netG(opt.g_model, opt.z_dim)
            self.netGs.append(netG)
        self.netD = build_netD(opt.d_model, opt.x_dim, opt.condition_D)

        X = torch.FloatTensor(opt.mb_size, opt.x_dim, opt.img_size,
                              opt.img_size)
        Z = torch.FloatTensor(opt.mb_size, opt.z_dim, 1, 1)

        real_like_sample = torch.FloatTensor(opt.mb_size, opt.x_dim,
                                             opt.img_size, opt.img_size)
        fake_like_sample = torch.FloatTensor(opt.mb_size, opt.x_dim,
                                             opt.img_size, opt.img_size)

        label = torch.FloatTensor(opt.mb_size)
        self.criterionGAN = torch.nn.BCELoss()
        self.criterionL1 = torch.nn.L1Loss()

        if self.cuda:
            self.netD.cuda()
            for index in range(self.nums):
                self.netGs[index].cuda()
            self.criterionGAN.cuda()
            self.criterionL1.cuda()
            X, Z = X.cuda(), Z.cuda()
            real_like_sample, fake_like_sample = real_like_sample.cuda(
            ), fake_like_sample.cuda()
            label = label.cuda()

        self.X = Variable(X)
        self.Z = Variable(Z)
        self.real_like_sample = Variable(real_like_sample)
        self.fake_like_sample = Variable(fake_like_sample)
        self.label = Variable(label)

        info.log("Train: {}  Continue: {}  Test: {}".format(
            self.train, self.continue_train, self.test))

        if self.opt.cc:
            self.create_tensorboard()
            self.index_exp = create_sigle_experiment(self.cc, 'index')
        self.D_solver = torch.optim.Adam(self.netD.parameters(),
                                         lr=2e-4,
                                         betas=(0.5, 0.999))
        self.G_solvers = create_optims(self.netGs, [2e-4, (0.5, 0.999)])

        if opt.train == False:
            self.load_networkG(self.opt.g_network_path)
            self.load_networkD(self.opt.d_network_path)
        else:
            init_network(self.netD)
            init_network(self.netGs)
G_exps = create_experiments(cc, 10)

netG_indeps = create_nets(config['G'][2], z_dim, nets_num)
netG_share = build_netG(config['G'][3], h_dim)
netD = build_netD(config['D'][2], x_dim)

print netG_indeps
print netG_share

init_network(netG_share)
init_network(netG_indeps)
init_network(netD)

D_solver = optim.Adam(netD.parameters(), lr=lr)
G_share_solver = optim.Adam(netG_share.parameters(), lr=lr)
G_indep_solver = create_optims(netG_indeps, [lr, (0.5, 0.999)])

X = torch.FloatTensor(mb_size, x_dim)
z = torch.FloatTensor(mb_size, z_dim)
label = torch.FloatTensor(mb_size)

if cuda:
    X, z = X.cuda(), z.cuda()
    label = label.cuda()

X = Variable(X)
z = Variable(z)
label = Variable(label)

if netD_continue_trian:
    netD.load_state_dict(