-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathconfig.py
179 lines (144 loc) · 6.13 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
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
config.mc_scale = 4
# learning rate
config.lr_init = 1e-4
config.lr_min = 1e-6
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_offset = '/Bean/log/junyonglee'
################################## 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 = 'quanti_quali'
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
config.EVAL.is_quan = False
config.EVAL.save_input_gt = False
# data dir
config.EVAL.data_path = None
config.EVAL.input_path = None
config.EVAL.gt_path = None
config = set_log_path(config, config.log_offset, config.mode)
return config
def set_log_path(config, offset, mode):
config.LOG_DIR = edict()
offset = os.path.join(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')
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'
elif data == 'REDS':
config.data_path = os.path.join(config.data_offset, 'REDS/reds_lmdb')
config.input_path = 'reds_train'
config.gt_path = 'reds_train_gt'
config.VAL.data_path = os.path.join(config.data_offset, 'REDS/reds_lmdb')
config.VAL.input_path = 'reds_valid'
config.VAL.gt_path = 'reds_valid_gt'
#config.VAL.input_path = 'reds_test'
#config.VAL.gt_path = 'reds_test_gt'
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 == 'REDS':
config.EVAL.data_path = os.path.join(config.data_offset, 'REDS/reds_lmdb')
config.EVAL.input_path = 'reds_valid'
config.EVAL.gt_path = 'reds_valid_gt'
config.VAL.data_path = os.path.join(config.data_offset, 'REDS/reds_lmdb')
config.VAL.input_path = 'reds_valid'
config.VAL.gt_path = 'reds_valid_gt'
elif data == 'real':
config.EVAL.data_path = os.path.join(config.data_offset, 'real')
config.EVAL.input_path = 'input'
elif data == 'real2':
config.EVAL.data_path = os.path.join(config.data_offset, 'test_real2')
config.EVAL.input_path = 'input'
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))