-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathevaluation_LOL.py
61 lines (47 loc) · 1.82 KB
/
evaluation_LOL.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
import argparse
import time
from torchvision.utils import save_image
from torch.utils.data import DataLoader
import torch.nn.functional as F
from models_x import *
from datasets_LOL import *
parser = argparse.ArgumentParser()
parser.add_argument("--epoch", type=int, default=1093, help="epoch to load the saved checkpoint")
parser.add_argument("--dataset_name", type=str, default="LOL", help="name of the dataset")
parser.add_argument("--input_color_space", type=str, default="sRGB", help="input color space: sRGB or XYZ")
parser.add_argument("--model_dir", type=str, default="LUTs/paired/LOL2_400p_3LUT_sm_1e-4_mn_10", help="directory of saved models")
opt = parser.parse_args()
opt.model_dir = opt.model_dir + '_' + opt.input_color_space
# use gpu when detect cuda
cuda = True if torch.cuda.is_available() else False
# Tensor type
Tensor = torch.cuda.FloatTensor if cuda else torch.FloatTensor
criterion_pixelwise = torch.nn.MSELoss()
LUT0 = Generator3DLUT_identity()
LUT1 = Generator3DLUT_zero()
LUT2 = Generator3DLUT_zero()
classifier = Classifier()
trilinear_ = TrilinearInterpolation()
if cuda:
LUT0 = LUT0.cuda()
LUT1 = LUT1.cuda()
LUT2 = LUT2.cuda()
classifier = classifier.cuda()
criterion_pixelwise.cuda()
# Load pretrained models
LUTs = torch.load("saved_models/%s/LUTs_%d.pth" % (opt.model_dir, opt.epoch))
LUT0.load_state_dict(LUTs["0"])
LUT1.load_state_dict(LUTs["1"])
LUT2.load_state_dict(LUTs["2"])
LUT0.eval()
LUT1.eval()
LUT2.eval()
classifier.load_state_dict(torch.load("saved_models/%s/classifier_%d.pth" % (opt.model_dir, opt.epoch)))
classifier.eval()
def generator(img):
pred = classifier(img).squeeze()
print("weight:", pred)
LUT = pred[0] * LUT0.LUT + pred[1] * LUT1.LUT + pred[2] * LUT2.LUT
combine_A = img.new(img.size())
_, combine_A = trilinear_(LUT, img)
return combine_A