Esempio n. 1
0
def test(dataset, loader, model, args, device, tag=''):
    psnr = AverageMeter()

    # Set the model to evaluation mode
    model.eval()

    with tqdm(total=len(dataset)) as t:
        t.set_description(tag)

        for data in loader:
            lr, hr = data
            lr = lr.to(device)
            hr = hr.to(device)

            if args.self_ensemble:
                sr = forward_x8(lr)
            else:
                sr = forward(lr)

            # Quantize results
            sr = quantize(sr, args.rgb_range)

            # Update PSNR
            psnr.update(calc_psnr(sr, hr, scale=args.scale, max_value=args.rgb_range[1]), lr.shape[0])

            t.update(lr.shape[0])

    print('DIV2K (val) PSNR: {:.4f} dB'.format(psnr.avg))
Esempio n. 2
0
def test(dataset, loader, model, device, args, tag=''):
    psnr = AverageMeter()

    # Set the model to evaluation mode
    model.eval()
    count = 0
    with tqdm(total=len(dataset)) as t:
        t.set_description(tag)

        for data in loader:
            count = count + 1

            lr, hr = data
            # pdb.set_trace()

            lr = lr.to(device)
            hr = hr.to(device)

            if args.self_ensemble:
                sr = forward_x8(lr)
            else:
                sr = forward(lr)

            # pdb.set_trace()
            # (Pdb) lr.size()
            # torch.Size([1, 3, 678, 1020])
            # (Pdb) sr.size()
            # torch.Size([1, 3, 1356, 2040])

            # Quantize results
            sr = quantize(sr, args.rgb_range)

            # Update PSNR
            psnr.update(
                calc_psnr(sr,
                          hr,
                          scale=args.scale,
                          max_value=args.rgb_range[1]), lr.shape[0])

            t.update(lr.shape[0])

            # if count > 100:
            #     srimg = torchvision.transforms.ToPILImage()(sr.squeeze().div(255).cpu())
            #     srimg.save("result/{:03d}.png".format(count - 100))

            #     #     srimg.show()
            #     #     pdb.set_trace()

    print('SDR (val) PSNR: {:.4f} dB'.format(psnr.avg))
Esempio n. 3
0
def test(dataset, loader, model, args, device, tag=''):
    psnr = AverageMeter()

    # Set the model to evaluation mode
    model.eval()

    with tqdm(total=len(dataset)) as t:
        t.set_description(tag)

        count = 0
        for data in loader:
            lr, hr = data
            lr = lr.to(device)
            hr = hr.to(device)

            if args.self_ensemble:
                sr = forward_x8(lr, model)
            else:
                sr = forward(lr, model)

            # Quantize results
            sr = quantize(sr, args.rgb_range)

            if args.output_dir:
                im = Image.fromarray(np.uint8(sr.squeeze().cpu().numpy().transpose(2, 1, 0))).transpose(Image.ROTATE_270)
                im_lr = Image.fromarray(np.uint8(lr.squeeze().cpu().numpy().transpose(2, 1, 0))).transpose(Image.ROTATE_270)
                im.save(args.output_dir + str(count) + ".png")
                im_lr.save(args.output_dir + str(count) + "_lr.png")
                count += 1

            # to save activation layers
            # act = activation['deconv'].squeeze()
            #
            # for idx in range(50):
            #     plt.imsave('results/output/act/activation%d_.png' % idx, act[idx], vmin=act[idx].min(), vmax=act[idx].max())

            # Update PSNR
            # psnr.update(calc_psnr(sr, hr, scale=args.scale, max_value=args.rgb_range[1]), lr.shape[0])

            t.update(lr.shape[0])

    print('DIV2K (val) PSNR: {:.4f} dB'.format(psnr.avg))
Esempio n. 4
0
def test(dataset, loader, model, criterion, args, tag=''):
    losses = AverageMeter()
    psnr = AverageMeter()

    # Set the model to evaluation mode
    model.eval()

    with tqdm(total=len(dataset)) as t:
        t.set_description(tag)

        for data in loader:
            lr, hr = data
            lr = lr.to(device)
            hr = hr.to(device)

            # Predict results without calculating gradients
            with torch.no_grad():
                sr = model(lr)

            loss = criterion(sr, hr)

            # Update loss
            losses.update(loss.item(), lr.shape[0])

            # Quantize results
            sr = quantize(sr, args.rgb_range)

            # Update PSNR
            psnr.update(
                calc_psnr(sr,
                          hr,
                          scale=args.scale,
                          max_value=args.rgb_range[1]), lr.shape[0])

            t.set_postfix(loss='{:.4f}'.format(losses.avg))
            t.update(lr.shape[0])

        return losses.avg, psnr.avg