-
Notifications
You must be signed in to change notification settings - Fork 0
/
training_utils.py
70 lines (59 loc) · 1.63 KB
/
training_utils.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
import argparse
def _setup_args():
p = argparse.ArgumentParser(
description='trains a model with quantization aware training'
)
p.add_argument(
'-m',
'--model-name',
help='name of model. Must be defined in models.py',
metavar='name'
)
p.add_argument(
'-l',
'--list-models',
help='lists available models',
action='store_true'
)
p.add_argument(
'--epochs',
help='number of epochs for training. Default is 1',
type=int,
default=1,
metavar='epochs'
)
p.add_argument(
'--checkpoint-dir',
help=('directory to save checkpoint information. '
'Default is "./chkpt/checkpoints"'),
default='./chkpt/checkpoints',
type=str,
metavar='dir'
)
p.add_argument(
'--freeze',
help='freezes the model',
metavar='model name'
)
return p.parse_args(), p.print_help
def parse_args():
cmd_args, print_help = _setup_args()
from models import models
if cmd_args.list_models:
model_names = '\n'.join(m for m in models.keys())
print(f'Models\n------------\n{model_names}')
exit(0)
if cmd_args.model_name is None:
print_help()
exit(0)
if cmd_args.model_name not in models:
print(f'unknown model name: {cmd_args.model_name}')
print_help()
exit(1)
args = {
'model_fn' : models[cmd_args.model_name],
'epochs' : cmd_args.epochs,
'checkpoint_dir' : cmd_args.checkpoint_dir,
'frozen_filename': cmd_args.freeze
}
return args