-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics.py
48 lines (35 loc) · 1.11 KB
/
metrics.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
import argparse
import numpy as np
import os
import random
import tensorboardX
import time
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.optim import Adam
from torch.utils.data import DataLoader
from skimage import metrics
import cv2
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--dir', type=str, default='pinecone_dr.xml')
args = parser.parse_args()
img_list = os.listdir(args.dir)
global_psnr = 0.0
global_ssim = 0.0
idx = 0
for img_name in img_list:
if 'gt' in img_name:
img_name_output = img_name.replace('gt', 'output')
gt = cv2.imread('%s/%s' % (args.dir, img_name))
output = cv2.imread('%s/%s' % (args.dir, img_name_output))
psnr = metrics.peak_signal_noise_ratio(gt, output)
ssim = metrics.structural_similarity(gt, output, multichannel=True)
global_psnr += psnr
global_ssim += ssim
idx += 1
global_psnr /= idx
global_ssim /= idx
print('PSNR: %f' % global_psnr)
print('SSIM: %f' % global_ssim)