Esempio n. 1
0
import torch
import matplotlib.pyplot as plt
from model import VDSR
import cv2
import torchvision.transforms as T
import numpy as np
import math

device = torch.device('cuda:0')
transform = T.ToTensor()
net = VDSR()
checkpoint = torch.load('D:/VDSR_SGD_epoch_60.pth')
net.load_state_dict(checkpoint['model_state_dict'])
net = net.to(device)
net.eval()
image_path = 'D:/train_data/91/000tt16.bmp'
img = cv2.imread(image_path)
img_r = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img = cv2.cvtColor(img, cv2.COLOR_BGR2YCrCb)

img = cv2.resize(img, (img.shape[1], img.shape[0] // 2),
                 interpolation=cv2.INTER_CUBIC)

#img_original=img_r[200:230,300:330]
Y, Cr, Cb = cv2.split(img)

patch = Y[200:230, 300:330]

plt.imshow(img_r)
plt.show()
img = transform(Y)
Esempio n. 2
0
            preds = model(inputs)

            loss = criterion(preds, labels)

            optimizer.zero_grad()
            loss.backward()
            optimizer.step()

            print(loss.item())

            loss_arr += [loss.item()]

        print("TRAIN: EPOCH %04d / %04d | LOSS %.4f" %
              (epoch, args.num_epochs, np.mean(loss_arr)))

        model.eval()

        for data in eval_dataloader:
            inputs, labels = data

            inputs = inputs.to(device)
            labels = labels.to(device)

            with torch.no_grad():
                preds = model(inputs).clamp(0.0, 1.0)

            psnr = PSNR(preds, labels)

            print("Eval_PSNR = {}".format(psnr))

        if (epoch + 1) % 10 == 0: