-
Notifications
You must be signed in to change notification settings - Fork 39
/
config.py
executable file
·157 lines (130 loc) · 5.39 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
from easydict import EasyDict as edict
import json
import os
import collections
import numpy as np
def get_config(project = '', mode = '', config_ = ''):
## GLOBAL
config = edict()
config.project = project
config.mode = mode
config.config = config_
config.is_train = False
config.thread_num = 8
config.resume = None # 'resume epoch'
config.resume_abs = None # 'resume abs name'
config.manual_seed = 0
config.is_verbose = False
config.save_sample = False
config.is_amp = False
config.cuda = True
if config.cuda == True:
config.device = 'cuda'
else:
config.device = 'cpu'
config.dist = False
##################################### TRAIN #####################################
config.trainer = ''
config.network = ''
config.in_bit = 8
config.norm_val = (2**config.in_bit - 1)
config.batch_size = 8
config.batch_size_test = 1
config.height = 256
config.width = 256
# learning rate
config.lr_init = 1e-4
config.gc = 1.0
## Naive Decay
config.LRS = 'LD' # LD
config.total_itr = 600000
config.decay_period = [500000, 550000]
config.decay_rate = 0.5
config.warmup_itr = -1
# adam
config.beta1 = 0.9
# data dir
config.data_offset = '/data1/junyonglee/defocus_deblur'
#config.data_offset = 'datasets/defocus_deblur'
config.c_path = os.path.join(config.data_offset, 'DPDD/train_c')
config.l_path = os.path.join(config.data_offset, 'DPDD/train_l')
config.r_path = os.path.join(config.data_offset, 'DPDD/train_r')
config.input_path = 'source'
config.gt_path = 'target'
# logs
config.max_ckpt_num = 100
config.write_ckpt_every_epoch = 4
config.refresh_image_log_every_epoch = {'train':20, 'valid':20}
config.write_log_every_itr = {'train':200, 'valid': 1}
# log dirs
config.LOG_DIR = edict()
# log_offset = './logs'
log_offset = '/Bean/logs/junyonglee'
log_offset = os.path.join(log_offset, config.project)
log_offset = os.path.join(log_offset, '{}'.format(mode))
config.LOG_DIR.offset = log_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.c_path = os.path.join(config.data_offset, 'DPDD/val_c')
config.VAL.l_path = os.path.join(config.data_offset, 'DPDD/val_l')
config.VAL.r_path = os.path.join(config.data_offset, 'DPDD/val_r')
config.VAL.input_path = 'source'
config.VAL.gt_path = 'target'
##################################### EVAL ######################################
config.EVAL = edict()
config.EVAL.eval_mode = 'quan'
config.EVAL.data = 'DPDD' # DPDD/PixelDP/RealDOF/CUHK
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.c_path = None
config.EVAL.l_path = None
config.EVAL.r_path = None
config.EVAL.input_path = None
config.EVAL.gt_path = None
# log dir
config.EVAL.LOG_DIR = edict()
config.output_offset = os.path.join(config.LOG_DIR.offset, 'result')
config.EVAL.LOG_DIR.save = config.output_offset
return config
def set_eval_path(config, data):
if data == 'DPDD':
config.EVAL.c_path = os.path.join(config.data_offset, 'DPDD/test_c')
config.EVAL.l_path = os.path.join(config.data_offset, 'DPDD/test_l')
config.EVAL.r_path = os.path.join(config.data_offset, 'DPDD/test_r')
# child paths
config.EVAL.input_path = 'source'
config.EVAL.gt_path = 'target'
elif data == 'PixelDP':
config.EVAL.c_path = os.path.join(config.data_offset, 'PixelDP/test_c')
config.EVAL.l_path = os.path.join(config.data_offset, 'PixelDP/test_l')
config.EVAL.r_path = os.path.join(config.data_offset, 'PixelDP/test_r')
elif data == 'RealDOF':
config.EVAL.c_path = os.path.join(config.data_offset, 'RealDOF')
# child paths
config.EVAL.input_path = 'source'
config.EVAL.gt_path = 'target'
elif data == 'CUHK':
config.EVAL.c_path = os.path.join(config.data_offset, 'CUHK')
elif data == 'random':
config.EVAL.c_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))