Files

41 lines
1.4 KiB
Python
Raw Permalink Normal View History

2020-11-14 16:56:09 +08:00
import os
2020-11-26 18:39:18 +08:00
import sys
sys.path.append('.')
2020-11-14 16:56:09 +08:00
import cv2
import math
import torch
import argparse
import numpy as np
from torch.nn import functional as F
2021-06-17 11:31:20 +08:00
from model.pytorch_msssim import ssim_matlab
2020-11-14 16:56:09 +08:00
from model.RIFE import Model
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = Model()
2021-02-25 15:45:39 +08:00
model.load_model('train_log')
2020-11-14 16:56:09 +08:00
model.eval()
model.device()
path = 'vimeo_interp_test/'
f = open(path + 'tri_testlist.txt', 'r')
psnr_list = []
2020-11-15 13:11:07 +08:00
ssim_list = []
2020-11-14 16:56:09 +08:00
for i in f:
name = str(i).strip()
if(len(name) <= 1):
continue
print(path + 'target/' + name + '/im1.png')
I0 = cv2.imread(path + 'target/' + name + '/im1.png')
I1 = cv2.imread(path + 'target/' + name + '/im2.png')
I2 = cv2.imread(path + 'target/' + name + '/im3.png')
I0 = (torch.tensor(I0.transpose(2, 0, 1)).to(device) / 255.).unsqueeze(0)
I2 = (torch.tensor(I2.transpose(2, 0, 1)).to(device) / 255.).unsqueeze(0)
mid = model.inference(I0, I2)[0]
2020-12-29 16:21:00 +08:00
ssim = ssim_matlab(torch.tensor(I1.transpose(2, 0, 1)).to(device).unsqueeze(0) / 255., torch.round(mid * 255).unsqueeze(0) / 255.).detach().cpu().numpy()
mid = np.round((mid * 255).detach().cpu().numpy()).astype('uint8').transpose(1, 2, 0) / 255.
2020-11-15 13:11:07 +08:00
I1 = I1 / 255.
psnr = -10 * math.log10(((I1 - mid) * (I1 - mid)).mean())
2020-11-14 16:56:09 +08:00
psnr_list.append(psnr)
2020-11-15 13:11:07 +08:00
ssim_list.append(ssim)
2020-11-26 18:47:55 +08:00
print("Avg PSNR: {} SSIM: {}".format(np.mean(psnr_list), np.mean(ssim_list)))