-
Notifications
You must be signed in to change notification settings - Fork 3
/
parser.py
168 lines (134 loc) · 4.13 KB
/
parser.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
158
159
160
161
162
163
164
165
166
import os
import argparse
import sys
def get_args(args=sys.argv[1:]):
parser = argparse.ArgumentParser(description='PyTorch CIFAR10 Training')
parser.add_argument(
'--output_dir',
type=str,
default='./result/test',
help='Path to the directory where the outputs will be saved (checkpoints, logs, etc...)')
parser.add_argument(
'--loaded_model_path',
type=str,
default='./checkpoints/',
help='Path to the pretrain model.\n \
If --loaded_model_path is a directory, then by default the loaded file will be arch_name.pt')
parser.add_argument(
'--resume',
default=False,
action='store_true',
help='to resume a finetuning')
parser.add_argument(
'--test_only',
default=False,
action='store_true',
help='If True, evalute only')
parser.add_argument(
'--mode',
type=str,
default='prune',
choices=('prune', 'finetune'),
help='Choose prune to prune the model and finetune to finetune the model')
# -------------------------- bottleneck training params
parser.add_argument(
'--batch_size',
type=int,
default=64,
help='Batch size.')
parser.add_argument(
'--nb_batches',
type=int,
default=200,
help='number of batches')
parser.add_argument(
'--Mflops_target',
type=float,
default= None,
help='targetted M of FLOPS of the pruned model')
# -------------------------- bottleneck training hyperparams
parser.add_argument(
'--lr',
default=0.6,
type=float,
help='initial learning rate')
parser.add_argument(
'--momentum',
default=0.9,
type=float,
help='momentum')
parser.add_argument(
'--beta',
default=6,
type=float,
help='beta (weight of the FLOPs loss in the computation of the final loss)')
parser.add_argument(
'--gamma',
default=0.4,
type=float,
help='gamma (weight of the boolean loss in the computation of the final loss)')
# -------------------------- params hardware
parser.add_argument(
'--gpu',
type=str,
default='0',
help='Select gpu to use')
parser.add_argument(
'--num_workers',
type=int,
default=4,
help='num of workers for dataloader'
)
# --------------------------
parser.add_argument(
'--dataset',
type=str,
default='cifar10',
# default='imagenet',
choices=('cifar10', 'imagenet'),
help='dataset')
parser.add_argument(
'--arch',
type=str,
default='resnet_56',
choices=('vgg_16_bn', 'resnet_56', 'resnet_110', 'densenet_40', 'googlenet', 'resnet_50'),
help='The architecture of the model')
parser.add_argument(
'--save_plot',
default=False,
action='store_true',
help='whether save accuracy plots or not')
parser.add_argument(
'--seed',
type=int,
default=1,
metavar='S',
help='random seed (default: 1)')
# -------------------------- finetuning
parser.add_argument(
'--lr_finetuning',
default=0.02,
type=float,
help='initial learning rate for finetuning')
parser.add_argument(
'--epoch_finetuning',
default=200,
type=int,
help='nb epochs for finetuning')
parser.add_argument(
'--wd',
default=0.002,
type=float,
help='weight decay for finetuning')
# --------------------------
args = parser.parse_args(args)
if not os.path.isfile(args.loaded_model_path):
args.loaded_model_path = os.path.join(args.loaded_model_path, args.dataset)
filename = args.arch + '.pt'
args.loaded_model_path = os.path.join(args.loaded_model_path, filename)
# Data Acquisition
args.data_dir = {
"cifar10": './data/cifar10/', # CIFAR-10
"imagenet": './data/imagenet/', # ImageNet
}[args.dataset]
return args