if batches_done % opt.sample_interval == 0: # Keep a record of losses for plotting. epochs.append(epoch + i / len(dataloader_train)) g_losses.append(g_loss.item()) d_losses.append(d_loss.item()) # Generate 5 images from the validation set. batch_A, batch_B = next(iter(dataloader_val)) imgs_val_A = Variable(batch_A.type(Tensor)) imgs_val_B = Variable(batch_B.type(Tensor)) imgs_fake_B = generator(imgs_val_A).detach().data # For visualization purposes. imgs_val_A = imgs_val_A.add_(1).div_(2) imgs_fake_B = imgs_fake_B.add_(1).div_(2) fake_val = torch.cat((imgs_val_A, imgs_fake_B), dim=2) # Display results on visdom page. vis.line(X=torch.stack([Tensor(epochs)] * len(loss_legend), dim=1), Y=torch.stack((Tensor(d_losses), Tensor(g_losses)), dim=1), opts={ 'title': 'loss over time', 'legend': loss_legend, 'xlabel': 'epoch', 'ylabel': 'loss', 'width': 512, 'height': 512
imgs_fake_hr = generator(imgs_val_lr).detach().data # For visualization purposes. imgs_val_lr = torch.nn.functional.upsample( imgs_val_lr, size=(imgs_fake_hr.size(2), imgs_fake_hr.size(3)), mode='bilinear') imgs_val_lr = imgs_val_lr.mul_( Tensor([0.229, 0.224, 0.225]).view(1, 3, 1, 1)).add_( Tensor([0.485, 0.456, 0.406]).view(1, 3, 1, 1)) imgs_val_hr = imgs_val_hr.mul_( Tensor([0.229, 0.224, 0.225]).view(1, 3, 1, 1)).add_( Tensor([0.485, 0.456, 0.406]).view(1, 3, 1, 1)) imgs_fake_hr = imgs_fake_hr.add_( torch.abs(torch.min(imgs_fake_hr))).div_( torch.max(imgs_fake_hr) - torch.min(imgs_fake_hr)) fake_val = torch.cat((imgs_val_lr, imgs_val_hr, imgs_fake_hr), dim=2) # Display results on visdom page. vis.line(X=torch.stack([Tensor(epochs)] * len(loss_legend), dim=1), Y=torch.stack((Tensor(d_losses), Tensor(g_losses)), dim=1), opts={ 'title': 'loss over time', 'legend': loss_legend, 'xlabel': 'epoch', 'ylabel': 'loss', 'width': 512,