def visualize_progession(self, i, iters, epoch, errD, errG, D_x, D_G_z1,
                             D_G_z2):
        """
        Handle the printing and plotting of the loss
        :return:
        """
        # Output training stats
        if i:
            print(
                '[%d/%d][%d/%d]\tLoss_D: %.4f\tLoss_G: %.4f\tD(x): %.4f\tD(G(z)): %.4f / %.4f'
                % (epoch, num_epochs, i, len(self.dataloader), errD.item(),
                   errG.item(), D_x, D_G_z1, D_G_z2))
            # Visualization with visdom
            viz.line([errD.item()], [iters],
                     win='ErrorD',
                     update='append' if iters > 0 else None,
                     name='Loss Discriminator',
                     opts=dict(xlabel='Step', ylabel='Loss', title='Losses'))
            # Visualization with visdom
            viz.line([errG.item()], [epoch],
                     win='ErrorD',
                     update='append' if iters > 0 else None,
                     name='Loss Generator',
                     opts=dict(xlabel='Step', ylabel='Loss', title='Losses'))

        # Check how the generator is doing by saving G's output on fixed_noise
        if (iters % 20 == 0) or ((epoch == num_epochs - 1) and
                                 (i == len(self.dataloader) - 1)):
            with torch.no_grad():
                fake = self.netG(self.fixed_noise).detach().cpu()
                display_city(fake[0], win_name='Test Example')
示例#2
0
 def save_observations(self, epoch):
     """
     Save the n_observations generated cities for a given layer
     :param n_observations: number of observations to save
     """
     logging.info('Save {} observations at epoch {}'.format(
         self.n_observations, epoch))
     with torch.no_grad():
         fake = self.netG(self.fixed_noise).detach().cpu()
         for i in range(self.n_observations):
             display_city(fake[i],
                          win_name='Test Example',
                          folder_name=self.experiment_name,
                          epoch='observation_{}_epoch_{}'.format(i, epoch))
示例#3
0
    def visualize_progession(self, epoch, loss_discriminator, loss_generator,
                             G1, D):
        """
        Handle the printing and plotting of the loss
        :return:
        """
        # Output training stats
        logging.info(
            '[{}/{}]\tLoss_D: {:.4f}\tLoss_G: {:.4f} %Fake as Real: {:.1f} %Real as real: {:.1f}'
            .format(epoch, self.num_epochs + self.start_epoch,
                    loss_discriminator, loss_generator, G1 * 100, D * 100))
        if self.viz:
            # Visualization with visdom
            self.viz.line([loss_discriminator], [epoch],
                          win='ErrorD',
                          update='append' if epoch > 0 else None,
                          name='Loss Discriminator',
                          opts=dict(xlabel='Step',
                                    ylabel='Loss',
                                    title='Losses'))
            # Visualization with visdom
            self.viz.line([loss_generator], [epoch],
                          win='ErrorD',
                          update='append' if epoch > 0 else None,
                          name='Loss Generator',
                          opts=dict(xlabel='Step',
                                    ylabel='Loss',
                                    title='Losses'))

            # Check how the generator is doing by saving G's output on fixed_noise
            if (epoch % 10 == 0):
                with torch.no_grad():
                    fake = self.netG(self.fixed_noise).detach().cpu()
                    display_city(fake[0],
                                 win_name='Test Example',
                                 viz=self.viz,
                                 folder_name=self.experiment_name,
                                 epoch=epoch)