-
Notifications
You must be signed in to change notification settings - Fork 22
/
config.py
executable file
·142 lines (116 loc) · 4.78 KB
/
config.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
from easydict import EasyDict as edict
import json
import os
import collections
import numpy as np
def get_config(project = '', mode = '', config_ = '', data = '', LRS = '', batch_size = 8):
## GLOBAL
config = edict()
config.project = project
config.mode = mode
config.config = config_
config.is_train = False
config.thread_num = batch_size
config.dist = False
config.resume = None # 'resume epoch'
config.manual_seed = 0
config.is_verbose = False
config.save_sample = False
##################################### TRAIN #####################################
config.trainer = ''
config.network = ''
config.batch_size = batch_size
config.batch_size_test = 1
config.height = 256
config.width = 256
# learning rate
config.lr_init = 1e-4
config.gc = 1.0 # gradient clipping
## Naive Decay
config.LRS = LRS # LD or CA
# adam
config.beta1 = 0.9
# data dir
config.data = 'DVD' # 'nah'
config.data_offset = '/data1/junyonglee/video_deblur'
# config.data_offset = 'datasets/video_deblur'
config.data_path = None
config.input_path = None
config.gt_path = None
# logs
config.max_ckpt_num = 100
config.write_ckpt_every_epoch = 4
config.refresh_image_log_every_epoch = {'train':16, 'valid':16}
config.write_log_every_itr = {'train':65, 'valid': 20}
# log dirs
config.LOG_DIR = edict()
log_offset = '/Jarvis/logs/junyonglee'
offset = os.path.join(log_offset, config.project)
offset = os.path.join(offset, '{}'.format(mode))
config.LOG_DIR.offset = offset
config.LOG_DIR.ckpt = os.path.join(config.LOG_DIR.offset, 'checkpoint', 'train', 'epoch')
config.LOG_DIR.ckpt_ckpt = os.path.join(config.LOG_DIR.offset, 'checkpoint', 'train', 'epoch', 'ckpt')
config.LOG_DIR.ckpt_state = os.path.join(config.LOG_DIR.offset, 'checkpoint', 'train', 'epoch', 'state')
config.LOG_DIR.log_scalar = os.path.join(config.LOG_DIR.offset, 'log', 'train', 'scalar')
config.LOG_DIR.log_image = os.path.join(config.LOG_DIR.offset, 'log', 'train', 'image', 'train')
config.LOG_DIR.sample = os.path.join(config.LOG_DIR.offset, 'sample', 'train')
config.LOG_DIR.sample_val = os.path.join(config.LOG_DIR.offset, 'sample', 'valid')
config.LOG_DIR.config = os.path.join(config.LOG_DIR.offset, 'config')
################################## VALIDATION ###################################
# data path
config.VAL = edict()
config.VAL.data_path = None
config.VAL.input_path = None
config.VAL.gt_path = None
##################################### EVAL ######################################
config.EVAL = edict()
config.EVAL.eval_mode = 'quan'
config.EVAL.data = 'nah'
config.EVAL.load_ckpt_by_score = True
config.EVAL.ckpt_name = None
config.EVAL.ckpt_epoch = None
config.EVAL.ckpt_abs_name = None
config.EVAL.low_res = False
config.EVAL.ckpt_load_path = None
# data dir
config.EVAL.data_path = None
config.EVAL.input_path = None
config.EVAL.gt_path = None
# log dir
config.EVAL.LOG_DIR = edict()
config.EVAL.LOG_DIR.save = os.path.join(config.LOG_DIR.offset, 'result')
return config
def set_train_path(config, data):
if data == 'DVD':
config.data_path = os.path.join(config.data_offset, 'train_DVD')
config.input_path = 'input'
config.gt_path = 'GT'
config.VAL.data_path = os.path.join(config.data_offset, 'test_DVD')
config.VAL.input_path = 'input'
config.VAL.gt_path = 'GT'
elif data == 'nah':
config.data_path = os.path.join(config.data_offset, 'train_nah')
config.input_path = 'blur_gamma'
config.gt_path = 'sharp'
config.VAL.data_path = os.path.join(config.data_offset, 'test_nah')
config.VAL.input_path = 'blur_gamma'
config.VAL.gt_path = 'sharp'
return config
def set_eval_path(config, data):
if data == 'DVD':
config.EVAL.data_path = os.path.join(config.data_offset, 'test_DVD')
config.EVAL.input_path = 'input'
config.EVAL.gt_path = 'GT'
elif data == 'nah':
config.EVAL.data_path = os.path.join(config.data_offset, 'test_nah')
config.EVAL.input_path = 'blur_gamma' # os.path.join(config.VAL.data_path, 'input')
config.EVAL.gt_path = 'sharp' # os.path.join(config.VAL.data_path, 'gt')
elif data == 'random':
config.EVAL.data_path = os.path.join(config.data_offset, 'random')
return config
def log_config(path, cfg):
with open(path + '/config.txt', 'w') as f:
f.write(json.dumps(cfg, indent=4))
f.close()
def print_config(cfg):
print(json.dumps(cfg, indent=4))