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.netCG = build_netCG(opt.g_model, nums=self.nums) 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) label = torch.FloatTensor(opt.mb_size) if opt.condition_D: real_like_sample = torch.FloatTensor(opt.mb_size, opt.img_size*opt.img_size + opt.condition_D) fake_like_sample = torch.FloatTensor(opt.mb_size, opt.img_size*opt.img_size + opt.condition_D) else: 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) 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() 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) 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.CG_solver = torch.optim.Adam(self.netCG.parameters(), lr=2e-4, betas=(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.netCG)
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_dim = opt.condition_dim self.nums = opt.nums 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) X = torch.FloatTensor(opt.mb_size, opt.x_dim + opt.condition_dim) Z = torch.FloatTensor(opt.mb_size, opt.z_dim) C = torch.FloatTensor(opt.condition_dim) 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() 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) 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)]) init_network(self.netD) init_network(self.netGs)
lr = 1e-3 cnt = 0 nets_num = 10 cuda = False cc = CrayonClient(hostname="localhost") 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)
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)
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) self.netC = build_netD(opt.c_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) target = torch.LongTensor(opt.mb_size) 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() self.criterionEntropy = torch.nn.CrossEntropyLoss() 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() target = target.cuda() self.X = Variable(X) self.Z = Variable(Z) self.target = Variable(target) 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.class_exp = create_sigle_experiment(self.cc, 'class') self.D_solver = torch.optim.Adam(self.netD.parameters(), lr=2e-4, betas=(0.5, 0.999)) self.C_solver = torch.optim.Adam(self.netC.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)