forked from chaofengc/IQA-PyTorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inference_maniqa.py
46 lines (35 loc) · 1.14 KB
/
inference_maniqa.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
import argparse
import glob
import os
from pyiqa import create_metric
from tqdm import tqdm
def main():
"""Inference demo for pyiqa.
"""
parser = argparse.ArgumentParser()
parser.add_argument('-i', '--input', type=str, default=None, help='input image/folder path.')
args = parser.parse_args()
metric_name = 'MANIQA'.lower()
# set up IQA model
iqa_model = create_metric(metric_name, metric_mode='NR')
if os.path.isfile(args.input):
input_paths = [args.input]
else:
input_paths = sorted(glob.glob(os.path.join(args.input, '*')))
total_avg = 0
n_iter = 100
for i in range(n_iter):
avg_score = 0
test_img_num = len(input_paths)
pbar = tqdm(total=test_img_num, unit='image')
for img_path in input_paths:
score = iqa_model(img_path).cpu().item()
avg_score += score
pbar.update(1)
pbar.close()
avg_score /= test_img_num
total_avg += avg_score
print(f'MANIQA[{i}]: {round(avg_score, 4)}')
print(f'Average MANIQA: {round(total_avg / n_iter, 4)}')
if __name__ == '__main__':
main()