-
Notifications
You must be signed in to change notification settings - Fork 11
/
demo2.py
42 lines (32 loc) · 1.05 KB
/
demo2.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
import torch
import numpy as np
import random
from PIL import Image, ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True
from LIQE import LIQE
from torchvision.transforms import ToTensor
seed = 20200626
num_patch = 15
torch.manual_seed(seed)
random.seed(seed)
np.random.seed(seed)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
device = 'cuda:1' if torch.cuda.is_available() else 'cpu'
ckpt = './checkpoints/LIQE.pt'
model = LIQE(ckpt, device)
img1 = 'data/6898804586.jpg'
img2 = 'data/I02_01_03.png'
print('###Image loading###')
I1 = Image.open(img1)
I2 = Image.open(img2)
I1 = ToTensor()(I1).unsqueeze(0)
I2 = ToTensor()(I2).unsqueeze(0)
print('###Preprocessing###')
with torch.no_grad():
q1, s1, d1 = model(I1)
q2, s2, d2 = model(I2)
print('Image #1 is a photo of {} with {} artifacts, which has a perceptual quality of {} as quantified by LIQE'.
format(s1, d1, q1.item()))
print('Image #2 is a photo of {} with {} artifacts, which has a perceptual quality of {} as quantified by LIQE'.
format(s2, d2, q2.item()))