Spaces:
Running
on
Zero
Running
on
Zero
File size: 1,151 Bytes
b56342d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
import numpy as np
import torch.nn as nn
#from skimage.measure import compare_ssim as SSIM
from skimage.metrics import structural_similarity as SSIM
from util.metrics import PSNR
class DeblurModel(nn.Module):
def __init__(self):
super(DeblurModel, self).__init__()
def get_input(self, data):
img = data['a']
inputs = img
targets = data['b']
inputs, targets = inputs.cuda(), targets.cuda()
return inputs, targets
def tensor2im(self, image_tensor, imtype=np.uint8):
image_numpy = image_tensor[0].cpu().float().numpy()
image_numpy = (np.transpose(image_numpy, (1, 2, 0)) + 0.5) * 255.0
return image_numpy
def get_images_and_metrics(self, inp, output, target) -> (float, float, np.ndarray):
inp = self.tensor2im(inp)
fake = self.tensor2im(output.data)
real = self.tensor2im(target.data)
psnr = PSNR(fake, real)
ssim = SSIM(fake.astype('uint8'), real.astype('uint8'), channel_axis=2)
vis_img = np.hstack((inp, fake, real))
return psnr, ssim, vis_img
def get_model(model_config):
return DeblurModel()
|