-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathoption.py
More file actions
75 lines (59 loc) · 2.1 KB
/
option.py
File metadata and controls
75 lines (59 loc) · 2.1 KB
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
import os
import argparse
import yaml
from datetime import datetime
def get_option():
parser = argparse.ArgumentParser()
parser.add_argument(
'-task',
default='train',
type=str,
choices=['train', 'test', 'demo'],
help='choose the task for running the model'
)
parser.add_argument(
'-model_task',
default='lle',
type=str,
choices=['isp', 'lle', 'sr'],
help='the model of the task'
)
parser.add_argument(
'-device',
default='cuda',
type=str,
help='choose the device to run the model'
)
opt = parser.parse_args()
opt = opt_format(opt)
return opt
def load_yaml(path):
with open(path, 'r') as f:
model_config = yaml.load(f, Loader=yaml.FullLoader)
return model_config
def save_yaml(path, file_dict):
with open(path, 'w') as f:
f.write(yaml.dump(file_dict, allow_unicode=True))
def opt_format(opt):
opt.root = os.getcwd()
opt.config = r'{}/config/{}.yaml'.format(opt.root, opt.model_task)
opt.config = load_yaml(opt.config)
proper_time = str(datetime.now()).split('.')[0].replace(':', '-')
opt.config['exp_name'] = '{}_{}'.format(opt.task, opt.config['exp_name'])
opt.experiments = r'{}/experiments/{}'.format(opt.root, '{} {}'.format(proper_time, opt.config['exp_name']))
if not os.path.exists(opt.experiments):
os.mkdir(opt.experiments)
config_path = r'{}/config.yaml'.format(opt.experiments)
save_yaml(config_path, opt.config)
if opt.task == 'demo' or (opt.task == 'test' and opt.config['test']['save'] != False):
opt.save_image = True
opt.save_image_dir = r'{}/{}'.format(opt.experiments, 'images')
if not os.path.exists(opt.save_image_dir):
os.mkdir(opt.save_image_dir)
opt.log_path = r'{}/logger.log'.format(opt.experiments)
if opt.task == 'train':
opt.save_model = True
opt.save_model_dir = r'{}/{}'.format(opt.experiments, 'models')
if not os.path.exists(opt.save_model_dir):
os.mkdir(opt.save_model_dir)
return opt