-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsave_trained_luts.py
58 lines (49 loc) · 1.87 KB
/
save_trained_luts.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
import argparse
import torch
from models_x import *
from datasets import *
parser = argparse.ArgumentParser()
parser.add_argument("--epoch", type=int, default=321, help="epoch to start training from")
parser.add_argument("--model_dir", type=str, default="LUTs/paired/fiveK_480p_3LUT_sm_1e-4_mn_0_sRGB", help="path to save model")
opt = parser.parse_args()
cuda = True if torch.cuda.is_available() else False
criterion_pixelwise = torch.nn.MSELoss()
# Initialize generator and discriminator
LUT1 = Generator3DLUT_identity()
LUT2 = Generator3DLUT_zero()
LUT3 = Generator3DLUT_zero()
#LUT4 = Generator3DLUT_2()
#LUT5 = Generator3DLUT_2()
# Load pretrained models
LUTs = torch.load("saved_models/%s/LUTs_%d.pth" % (opt.model_dir, opt.epoch))
LUT1.load_state_dict(LUTs["0"])
LUT2.load_state_dict(LUTs["1"])
LUT3.load_state_dict(LUTs["2"])
#LUT4.load_state_dict(LUTs["4"])
#LUT5.load_state_dict(LUTs["5"])
LUT1.eval()
LUT2.eval()
LUT3.eval()
#LUT4.eval()
#LUT5.eval()
f = open('visualization_lut/onlysm_LUT_%d_1.txt'%opt.epoch,'a')
for p in range(0,LUT1.LUT.shape[0]):
for i in range(0,LUT1.LUT.shape[1]):
for j in range(0,LUT1.LUT.shape[2]):
for k in range(0,LUT1.LUT.shape[3]):
f.write("%f\n"%LUT1.LUT[p,i,j,k].detach().numpy())
f.close()
f = open('visualization_lut/onlysm_LUT_%d_2.txt'%opt.epoch,'a')
for p in range(0,LUT2.LUT.shape[0]):
for i in range(0,LUT2.LUT.shape[1]):
for j in range(0,LUT2.LUT.shape[2]):
for k in range(0,LUT2.LUT.shape[3]):
f.write("%f\n"%LUT2.LUT[p,i,j,k].detach().numpy())
f.close()
f = open('visualization_lut/onlysm_LUT_%d_3.txt'%opt.epoch,'a')
for p in range(0,LUT3.LUT.shape[0]):
for i in range(0,LUT3.LUT.shape[1]):
for j in range(0,LUT3.LUT.shape[2]):
for k in range(0,LUT3.LUT.shape[3]):
f.write("%f\n"%LUT3.LUT[p,i,j,k].detach().numpy())
f.close()