diff --git a/README.md b/README.md index 4209c2d0..af95fe39 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Alternatively you can build your own dataset by setting up the following directo | | └── test # Testing | | | ├── A # Contains domain A images (i.e. Bruce Wayne) | | | └── B # Contains domain B images (i.e. Batman) - + ### 2. Train! ``` ./train --dataroot datasets// --cuda @@ -43,7 +43,7 @@ Both generators and discriminators weights will be saved under the output direct If you don't own a GPU remove the --cuda option, although I advise you to get one! -You can also view the training progress as well as live output images by running ```python3 -m visdom``` in another terminal and opening [http://localhost:8097/](http://localhost:8097/) in your favourite web browser. This should generate training loss progress as shown below (default params, horse2zebra dataset): +You can also view the training progress as well as live output images by running ```python3 -m visdom.server``` in another terminal and opening [http://localhost:8097/](http://localhost:8097/) in your favourite web browser. This should generate training loss progress as shown below (default params, horse2zebra dataset): ![Generator loss](https://github.com/ai-tor/PyTorch-CycleGAN/raw/master/output/loss_G.png) ![Discriminator loss](https://github.com/ai-tor/PyTorch-CycleGAN/raw/master/output/loss_D.png) diff --git a/train b/train index 95160b51..21e53592 100755 --- a/train +++ b/train @@ -72,19 +72,19 @@ lr_scheduler_D_B = torch.optim.lr_scheduler.LambdaLR(optimizer_D_B, lr_lambda=La Tensor = torch.cuda.FloatTensor if opt.cuda else torch.Tensor input_A = Tensor(opt.batchSize, opt.input_nc, opt.size, opt.size) input_B = Tensor(opt.batchSize, opt.output_nc, opt.size, opt.size) -target_real = Variable(Tensor(opt.batchSize).fill_(1.0), requires_grad=False) -target_fake = Variable(Tensor(opt.batchSize).fill_(0.0), requires_grad=False) +target_real = Variable(Tensor(opt.batchSize,1).fill_(1.0), requires_grad=False) +target_fake = Variable(Tensor(opt.batchSize,1).fill_(0.0), requires_grad=False) fake_A_buffer = ReplayBuffer() fake_B_buffer = ReplayBuffer() # Dataset loader -transforms_ = [ transforms.Resize(int(opt.size*1.12), Image.BICUBIC), - transforms.RandomCrop(opt.size), +transforms_ = [ transforms.Resize(int(opt.size*1.12), Image.BICUBIC), + transforms.RandomCrop(opt.size), transforms.RandomHorizontalFlip(), transforms.ToTensor(), transforms.Normalize((0.5,0.5,0.5), (0.5,0.5,0.5)) ] -dataloader = DataLoader(ImageDataset(opt.dataroot, transforms_=transforms_, unaligned=True), +dataloader = DataLoader(ImageDataset(opt.dataroot, transforms_=transforms_, unaligned=True), batch_size=opt.batchSize, shuffle=True, num_workers=opt.n_cpu) # Loss plot @@ -128,7 +128,7 @@ for epoch in range(opt.epoch, opt.n_epochs): # Total loss loss_G = loss_identity_A + loss_identity_B + loss_GAN_A2B + loss_GAN_B2A + loss_cycle_ABA + loss_cycle_BAB loss_G.backward() - + optimizer_G.step() ################################### @@ -157,7 +157,7 @@ for epoch in range(opt.epoch, opt.n_epochs): # Real loss pred_real = netD_B(real_B) loss_D_real = criterion_GAN(pred_real, target_real) - + # Fake loss fake_B = fake_B_buffer.push_and_pop(fake_B) pred_fake = netD_B(fake_B.detach()) @@ -172,7 +172,7 @@ for epoch in range(opt.epoch, opt.n_epochs): # Progress report (http://localhost:8097) logger.log({'loss_G': loss_G, 'loss_G_identity': (loss_identity_A + loss_identity_B), 'loss_G_GAN': (loss_GAN_A2B + loss_GAN_B2A), - 'loss_G_cycle': (loss_cycle_ABA + loss_cycle_BAB), 'loss_D': (loss_D_A + loss_D_B)}, + 'loss_G_cycle': (loss_cycle_ABA + loss_cycle_BAB), 'loss_D': (loss_D_A + loss_D_B)}, images={'real_A': real_A, 'real_B': real_B, 'fake_A': fake_A, 'fake_B': fake_B}) # Update learning rates