-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathargs.py
executable file
·83 lines (76 loc) · 3.99 KB
/
args.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
"""
Command-line argument parsing.
"""
import argparse
from functools import partial
def argument_parser():
"""
Get an argument parser for a training script.
"""
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--pretrained', help='evaluate a pre-trained model',
action='store_true', default=False)
parser.add_argument('--seed', help='random seed', default=0, type=int)
parser.add_argument('--checkpoint', help='checkpoint directory', default='model_checkpoint')
parser.add_argument('--classes', help='number of classes per inner task', default=5, type=int)
parser.add_argument('--shots', help='number of examples per class', default=5, type=int)
parser.add_argument('--train-shots', help='shots in a training batch', default=0, type=int)
parser.add_argument('--inner-batch', help='inner batch size', default=5, type=int)
parser.add_argument('--inner-iters', help='inner iterations', default=20, type=int)
parser.add_argument('--learning-rate', help='Adam step size', default=1e-3, type=float)
parser.add_argument('--meta-step', help='meta-training step size', default=0.1, type=float)
parser.add_argument('--meta-step-final', help='meta-training step size by the end',
default=0.1, type=float)
parser.add_argument('--meta-batch', help='meta-training batch size', default=1, type=int)
parser.add_argument('--meta-iters', help='meta-training iterations', default=400000, type=int)
parser.add_argument('--eval-batch', help='eval inner batch size', default=5, type=int)
parser.add_argument('--eval-iters', help='eval inner iterations', default=50, type=int)
parser.add_argument('--eval-samples', help='evaluation samples', default=10000, type=int)
parser.add_argument('--eval-interval', help='train steps per eval', default=10, type=int)
parser.add_argument('--weight-decay', help='weight decay rate', default=0, type=float)
parser.add_argument('--transductive', help='evaluate all samples at once', action='store_true')
parser.add_argument('--foml', help='use FOML instead of Reptile', action='store_true')
parser.add_argument('--sgd', help='use vanilla SGD instead of Adam', action='store_true')
parser.add_argument('--cuda', help='use cuda', action='store_true')
parser.add_argument('--pin_memory', help='copy tensors into host pinned memory', action='store_true')
parser.add_argument('--parallel', help='use multiple gpus', action='store_true')
return parser
def train_kwargs(parsed_args):
"""
Build kwargs for the train() function from the parsed
command-line arguments.
"""
return {
'num_classes': parsed_args.classes,
'num_shots': parsed_args.shots,
'train_shots': (parsed_args.train_shots or None),
'inner_batch_size': parsed_args.inner_batch,
'inner_iters': parsed_args.inner_iters,
'meta_step_size': parsed_args.meta_step,
'meta_step_size_final': parsed_args.meta_step_final,
'meta_batch_size': parsed_args.meta_batch,
'meta_iters': parsed_args.meta_iters,
'eval_inner_batch_size': parsed_args.eval_batch,
'eval_inner_iters': parsed_args.eval_iters,
'eval_interval': parsed_args.eval_interval,
'transductive': parsed_args.transductive,
'cuda': parsed_args.cuda,
'pin_memory': parsed_args.pin_memory,
'foml': parsed_args.foml
}
def evaluate_kwargs(parsed_args):
"""
Build kwargs for the evaluate() function from the
parsed command-line arguments.
"""
return {
'num_classes': parsed_args.classes,
'num_shots': parsed_args.shots,
'eval_inner_batch_size': parsed_args.eval_batch,
'eval_inner_iters': parsed_args.eval_iters,
'num_samples': parsed_args.eval_samples,
'transductive': parsed_args.transductive,
'cuda': parsed_args.cuda,
'pin_memory': parsed_args.pin_memory,
'foml': parsed_args.foml
}