return output NetD = Discriminator() NetG = Generator() MSE_LOSS = torch.nn.MSELoss() optimizerD = torch.optim.Adam(NetD.parameters(), lr=LEARNING_RATE, betas=(0.5, 0.999)) optimizerG = torch.optim.Adam(NetG.parameters(), lr=LEARNING_RATE, betas=(0.5, 0.999)) dataset = epfd.MNISTDataSetForPytorch(root=DATA_PATH, transform=tv.transforms.Compose( [tv.transforms.ToTensor()])) train_loader = torch.utils.data.DataLoader(dataset, batch_size=BATCH_SIZE, shuffle=True) fix_noise = torch.randn(100, NOISE_DIM) fix_noise_var = torch.autograd.Variable(fix_noise) if torch.cuda.is_available() > 0: NetG = NetG.cuda() NetD = NetD.cuda() MSE_LOSS = MSE_LOSS.cuda() fix_noise_var = fix_noise_var.cuda() bar = eup.ProgressBar(EPOCH, len(train_loader), "D Loss:%.3f;G Loss:%.3f")
m.bias.data.zero_() elif isinstance(m, torch.nn.Linear): m.weight.data.normal_(0, 0.02) m.bias.data.zero_() NetD = Discriminator() NetG = Generator() optimizerD = torch.optim.RMSprop(NetD.parameters(), lr=LEARNING_RATE) optimizerG = torch.optim.RMSprop(NetG.parameters(), lr=LEARNING_RATE) trans = tv.transforms.Compose( [tv.transforms.ToTensor(), tv.transforms.Normalize([0.5], [0.5])]) dataset = epfd.MNISTDataSetForPytorch(root=DATA_PATH, transform=trans) train_loader = torch.utils.data.DataLoader(dataset, batch_size=BATCH_SIZE, shuffle=True) one = torch.FloatTensor([1]) mone = -1 * one one_var = torch.autograd.Variable(one) mone_var = torch.autograd.Variable(mone) fix_noise = torch.FloatTensor(100, NOISE_DIM).normal_(0, 1) fix_noise_var = torch.autograd.Variable(fix_noise) if torch.cuda.is_available() > 0: NetG = NetG.cuda() NetD = NetD.cuda()
return network NetD = Discriminator() NetG = Generator() optimizerD = torch.optim.Adam(NetD.parameters(), lr=LEARNING_RATE, betas=(0.5, 0.999)) optimizerG = torch.optim.Adam(NetG.parameters(), lr=LEARNING_RATE, betas=(0.5, 0.999)) dataset = epfd.MNISTDataSetForPytorch( root=DATA_PATH, transform=tv.transforms.Compose([ # tv.transforms.Resize(CONFIG["IMAGE_SIZE"]), tv.transforms.ToTensor(), # tv.transforms.Normalize([0.5] * 3, [0.5] * 3) ])) train_loader = torch.utils.data.DataLoader(dataset, batch_size=BATCH_SIZE, shuffle=True) fix_noise = torch.randn(100, NOISE_DIM) fix_noise_var = torch.autograd.Variable(fix_noise) if torch.cuda.is_available() > 0: NetG = NetG.cuda() NetD = NetD.cuda() fix_noise_var = fix_noise_var.cuda()