-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathconfig.py
62 lines (50 loc) · 2.5 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
import argparse
arg_lists = []
parser = argparse.ArgumentParser(description='Hyperband')
def str2bool(v):
return v.lower() in ('true', '1')
def add_argument_group(name):
arg = parser.add_argument_group(name)
arg_lists.append(arg)
return arg
# hyperband params
hyper_arg = add_argument_group('Hyperband Params')
hyper_arg.add_argument('--max_iter', type=int, default=81,
help='Maximum # of iters allocated to a given config')
hyper_arg.add_argument('--eta', type=int, default=3,
help='Proportion of configs discarded in each round of SH')
hyper_arg.add_argument('--epoch_scale', type=str2bool, default=True,
help='Compute `max_iter` in terms of epochs or mini-batch iters')
# data params
data_arg = add_argument_group('Data Params')
data_arg.add_argument('--name', type=str, default='mnist',
help='Dataset name to train and validate on')
data_arg.add_argument('--valid_size', type=float, default=0.1,
help='Proportion of training set used for validation')
data_arg.add_argument('--batch_size', type=int, default=64,
help='# of images in each batch of data')
data_arg.add_argument('--num_workers', type=int, default=4,
help='# of subprocesses to use for data loading')
data_arg.add_argument('--shuffle', type=str2bool, default=False,
help='Whether to shuffle the train and valid indices')
# optim params
train_arg = add_argument_group('Optim Params')
train_arg.add_argument('--def_lr', type=float, default=1e-3,
help='Default lr')
train_arg.add_argument('--def_optim', type=str, default='adam',
help='Default optimizer')
train_arg.add_argument('--patience', type=int, default=5,
help='# of epochs to wait before early stopping')
# misc params
misc_arg = add_argument_group('Misc.')
misc_arg.add_argument('--num_gpu', type=int, default=0,
help='0 for cpu, greater for gpu')
misc_arg.add_argument('--data_dir', type=str, default='./data/',
help='Directory in which data is stored')
misc_arg.add_argument('--ckpt_dir', type=str, default='./ckpt/',
help='Directory in which to save model checkpoints')
misc_arg.add_argument('--print_freq', type=int, default=10,
help='How frequently to print training details')
def get_args():
args, unparsed = parser.parse_known_args()
return args, unparsed