Exemple #1
0
    def valid(self):

        self.model.eval()

        is_, _ = inception_score(model=self.model,
                                 N=10000,
                                 splits=10,
                                 cuda=self.cuda_mode,
                                 resize=True,
                                 SNGAN=True)

        with torch.no_grad():

            if self.cuda_mode:
                z_ = self.fixed_noise.cuda()
            else:
                z_ = self.fixed_noise

            x_gen = self.model.forward(z_)

            logits = self.fid_model.forward(
                x_gen.cpu(), downsample_=False).detach().numpy()

        m = logits.mean(0)
        C = np.cov(logits, rowvar=False)

        fid = ((self.m - m)**
               2).sum() + np.matrix.trace(C + self.C -
                                          2 * sla.sqrtm(np.matmul(C, self.C)))

        return fid, is_
Exemple #2
0
    print('Min FID:', np.min(history['FID-c']))
    print('Epoch with min FID:', np.argmin(history['FID-c']))

    if not args.no_plots:
        plot_learningcurves(history, 'gen_loss')
        plot_learningcurves(history, 'disc_loss')
        plot_learningcurves(history, 'gen_loss_minibatch')
        plot_learningcurves(history, 'disc_loss_minibatch')
        plot_learningcurves(history, 'FID-c')

    test_model(model=model,
               n_tests=args.n_tests,
               cuda_mode=args.cuda,
               SNGAN=True)
    save_samples(prefix='CIFAR10_SNGAN',
                 generator=model,
                 cp_name=args.cp_path.split('/')[-1].split('.')[0],
                 cuda_mode=args.cuda,
                 im_size=32,
                 SNGAN=True)

    if args.inception:
        print(
            inception_score(model,
                            batch_size=4,
                            N=args.n_inception,
                            cuda=args.cuda,
                            resize=True,
                            splits=10,
                            SNGAN=True))
Exemple #3
0
    if args.cuda:
        model = model.cuda()

    print('Cuda Mode is: {}'.format(args.cuda))

    history = ckpt['history']

    print('Min FID:', np.min(history['FID-c']))
    print('Epoch with min FID:', np.argmin(history['FID-c']))

    if not args.no_plots:
        plot_learningcurves(history, 'gen_loss')
        plot_learningcurves(history, 'disc_loss')
        plot_learningcurves(history, 'gen_loss_minibatch')
        plot_learningcurves(history, 'disc_loss_minibatch')
        plot_learningcurves(history, 'FID-c')

    test_model(model=model, n_tests=args.n_tests, cuda_mode=args.cuda)
    save_samples(prefix='CIFAR10_DCGAN',
                 generator=model,
                 cp_name=args.cp_path.split('/')[-1].split('.')[0],
                 cuda_mode=args.cuda)

    if args.inception:
        print(
            inception_score(model,
                            N=args.n_inception,
                            cuda=args.cuda,
                            resize=True,
                            splits=10))