def test(self):
    torch.set_grad_enabled(False)
    epoch = self.optimizer.get_last_epoch()
    self.ckp.write_log('\nEvaluation:')
    self.ckp.add_log(torch.zeros(1, len(self.loader_test), len(self.scale)))
    self.model.eval()
    timer_test = utility.timer()
    if self.args.save_results:
        self.ckp.begin_background()
    for (idx_data, d) in enumerate(self.loader_test):
        for (idx_scale, scale) in enumerate(self.scale):
            d.dataset.set_scale(idx_scale)
            for (lr, hr, filename) in tqdm(d, ncols=80):
                (lr, hr) = self.prepare(lr, hr)
                sr = self.model(lr, idx_scale)
                sr = utility.quantize(sr, self.args.rgb_range)
                save_list = [sr]
                self.ckp.log[((- 1), idx_data, idx_scale)] += utility.calc_psnr(sr, hr, scale, self.args.rgb_range, dataset=d)
                if self.args.save_gt:
                    save_list.extend([lr, hr])
                if self.args.save_results:
                    self.ckp.save_results(d, filename[0], save_list, scale)
            self.ckp.log[((- 1), idx_data, idx_scale)] /= len(d)
            best = self.ckp.log.max(0)
            self.ckp.write_log('[{} x{}]\tPSNR: {:.3f} (Best: {:.3f} @epoch {})'.format(d.dataset.name, scale, self.ckp.log[((- 1), idx_data, idx_scale)], best[0][(idx_data, idx_scale)], (best[1][(idx_data, idx_scale)] + 1)))
    self.ckp.write_log('Forward: {:.2f}s\n'.format(timer_test.toc()))
    self.ckp.write_log('Saving...')
    if self.args.save_results:
        self.ckp.end_background()
    if (not self.args.test_only):
        self.ckp.save(self, epoch, is_best=((best[1][(0, 0)] + 1) == epoch))
    self.ckp.write_log('Total: {:.2f}s\n'.format(timer_test.toc()), refresh=True)
    torch.set_grad_enabled(True)
def test(self):
    torch.set_grad_enabled(False)
    epoch = self.optimizer.get_last_epoch()
    self.ckp.write_log('\nEvaluation:')
    self.ckp.add_log(torch.zeros(1, len(self.loader_test), len(self.scale)))
    self.model.eval()
    timer_test = utility.timer()
    if self.args.save_results:
        self.ckp.begin_background()
    for (idx_data, d) in enumerate(self.loader_test):
        for (idx_scale, scale) in enumerate(self.scale):
            d.dataset.set_scale(idx_scale)
            for (lr, hr, filename) in tqdm(d, ncols=80):
                (lr, hr) = self.prepare(lr, hr)
                sr = self.model(lr, idx_scale)
                sr = utility.quantize(sr, self.args.rgb_range)
                save_list = [sr]
                self.ckp.log[((- 1), idx_data, idx_scale)] += utility.calc_psnr(sr, hr, scale, self.args.rgb_range, dataset=d)
                if self.args.save_gt:
                    save_list.extend([lr, hr])
                if self.args.save_results:
                    self.ckp.save_results(d, filename[0], save_list, scale)
            self.ckp.log[((- 1), idx_data, idx_scale)] /= len(d)
            best = self.ckp.log.max(0)
            self.ckp.write_log('[{} x{}]\tPSNR: {:.3f} (Best: {:.3f} @epoch {})'.format(d.dataset.name, scale, self.ckp.log[((- 1), idx_data, idx_scale)], best[0][(idx_data, idx_scale)], (best[1][(idx_data, idx_scale)] + 1)))
    self.ckp.write_log('Forward: {:.2f}s\n'.format(timer_test.toc()))
    self.ckp.write_log('Saving...')
    if self.args.save_results:
        self.ckp.end_background()
    if (not self.args.test_only):
        self.ckp.save(self, epoch, is_best=((best[1][(0, 0)] + 1) == epoch))
    self.ckp.write_log('Total: {:.2f}s\n'.format(timer_test.toc()), refresh=True)
    torch.set_grad_enabled(True)