-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcalMetirc_THU_HSEVI.py
105 lines (80 loc) · 3.31 KB
/
calMetirc_THU_HSEVI.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import os
import cv2
from skimage.metrics import structural_similarity
from skimage.metrics import peak_signal_noise_ratio
def calpsnr(gt, pred):
return peak_signal_noise_ratio(gt, pred)
def calssim(gt, pred):
return structural_similarity(gt, pred, multichannel=False, gaussian_weights=True)
cate = ['balloon_bursting', 'chessboard_waving', 'cup_breaking', 'hard_disk_spining', 'water_bomb', 'firing']
core = {'cup_breaking':[600,1000], 'water_bomb':[1400,1800], 'chessboard_waving':[0,100], 'balloon_bursting':[250,350],
'hard_disk_spining':[0,400], 'firing':[300,500]}
# outputPath = './ckpt/THU-HSEVI/'
outputPath = './timelens/output_timelens/'
datasetPath = './dataset/THU-HSEVI'
psnrList = []
ssimList = []
with open(outputPath+"/res.txt", 'a+') as f:
f.writelines('Metrics on full dataset:\n')
for c in cate:
if not os.path.exists(os.path.join(outputPath, c)):
continue
start, end = 0, 2599
psnr, ssim = [], []
for folder in os.listdir(os.path.join(outputPath, c)):
path = os.path.join(outputPath, c, folder)
for k in range(start, end+1):
if not os.path.exists(os.path.join(path, '%d_output.png'%k)):
continue
op = cv2.imread(os.path.join(path, '%d_output.png' % k), cv2.IMREAD_GRAYSCALE)
gt = cv2.imread(os.path.join(datasetPath, c, folder, 'frame', '%d.jpg'%k), cv2.IMREAD_GRAYSCALE)
p = calpsnr(gt, op)
s = calssim(gt, op)
psnr.append(p)
ssim.append(s)
psnrList.append(p)
ssimList.append(s)
print(folder, k)
psnr = sum(psnr) / len(psnr)
ssim = sum(ssim) / len(ssim)
message = c + ': PSNR:%f, SSIM:%f\n'%(psnr, ssim)
print(message)
with open(outputPath + "/res.txt", 'a+') as f:
f.writelines(message)
message = '\nTotal: PSNR:%f, SSIM:%f\n'%(sum(psnrList)/len(psnrList), sum(ssimList)/len(ssimList))
print(message)
with open(outputPath+"/res.txt", 'a+') as f:
f.writelines(message)
with open(outputPath+"/res.txt", 'a+') as f:
f.writelines('\nMetrics on high-speed clips:\n')
psnrList = []
ssimList = []
for c in cate:
if not os.path.exists(os.path.join(outputPath, c)):
continue
start, end = core[c]
psnr, ssim = [], []
for folder in os.listdir(os.path.join(outputPath, c)):
path = os.path.join(outputPath, c, folder)
for k in range(start, end + 1):
if not os.path.exists(os.path.join(path, '%d_output.png' % k)):
continue
op = cv2.imread(os.path.join(path, '%d_output.png' % k), cv2.IMREAD_GRAYSCALE)
gt = cv2.imread(os.path.join('./dataset/THU-HSEVI', c, folder, 'frame', '%d.jpg' % k), cv2.IMREAD_GRAYSCALE)
p = calpsnr(gt, op)
s = calssim(gt, op)
psnr.append(p)
ssim.append(s)
psnrList.append(p)
ssimList.append(s)
print(folder, k)
psnr = sum(psnr) / len(psnr)
ssim = sum(ssim) / len(ssim)
message = c + ': PSNR:%f, SSIM:%f\n' % (psnr, ssim)
print(message)
with open(outputPath + "/res.txt", 'a+') as f:
f.writelines(message)
message = '\nTotal: PSNR:%f, SSIM:%f\n'%(sum(psnrList)/len(psnrList), sum(ssimList)/len(ssimList))
print(message)
with open(outputPath+"/res.txt", 'a+') as f:
f.writelines(message)