-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathsomething.py
64 lines (57 loc) · 2.2 KB
/
something.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
62
63
64
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import tensorflow as tf
import numpy as np
import glob
import sys
from models import *
import yaml
import os
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import utils
####### Reading Hyperparameters #####
with open("config.yaml") as file:
data = yaml.load(file)
training_params = data['training_params']
learning_rate = float(training_params['learning_rate'])
batch_size = int(training_params['batch_size'])
epoch_size = int(training_params['epochs'])
data_path = training_params['data_path']
model_params= data['model_params']
descrip = model_params['descrip']
log_dir = model_params['log_dir']
mode = model_params['mode']
if len(descrip)==0:
raise ValueError, "Please give a proper description of the model you are training."
######## Making Directory #########
model_path = log_dir+sys.argv[1]
print "Model Path: ", model_path
if not os.path.exists(model_path):
os.makedirs(model_path)
os.makedirs(model_path+"/results")
os.makedirs(model_path+"/tf_graph")
os.makedirs(model_path+"/saved_model")
######### Loading Data ###########
train_img1 = 1/255.0*np.load(data_path+"train_haze_clear.npy") # First image of each pair is hazy image and second image is clear images
train_img2 = 1/255.0*np.load(data_path+"train_trans.npy")
val_img1 = 1/255.0*np.load(data_path+"val_haze_clear.npy")
val_img2 = 1/255.0*np.load(data_path+"val_trans.npy")
print "Data Loaded"
def main():
nnet = MSCNN(model_path)
if mode=='train':
os.system('cp config.yaml '+model_path+'/config.yaml')
os.system('cp models.py '+model_path+'/model.py')
nnet.build_model()
print "Model Build......"
nnet.train_model([train_img1, train_img2], [val_img1, val_img2], learning_rate, batch_size, epoch_size)
else:
predict_maps, predict_clear = nnet.test(train_img1[:,0,:,:,:], batch_size)
for i in range(train_img2.shape[0]):
pair = np.hstack((train_img2[i], predict_maps[i]))
pair2 = np.hstack((train_img1[i,0,:,:,:],train_img1[i,1,:,:,:], predict_clear[i]))
cv2.imwrite(model_path+"/results/train/"+str(i)+"_trans.jpg", 255.0*pair)
cv2.imwrite(model_path+"/results/train/"+str(i)+"_clear.jpg", 255.0*pair2)
if __name__ == "__main__":
main()