-
Notifications
You must be signed in to change notification settings - Fork 5
/
msd_args.py
215 lines (195 loc) · 11.6 KB
/
msd_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
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
import os
import glob
import time
import argparse
# model_names = list(map(lambda n: os.path.basename(n)[:-3],
# glob.glob('models/[A-Za-z]*.py')))
model_names = ['msdnet', 'msdnet_ge', 'IMTA_MSDNet', 'mobilenet_imagenet']
arg_parser = argparse.ArgumentParser(
description='Image classification PK main script')
exp_group = arg_parser.add_argument_group('exp', 'experiment setting')
exp_group.add_argument('--save', default='save/default-{}'.format(time.time()),
type=str, metavar='SAVE',
help='path to the experiment logging directory'
'(default: save/debug)')
exp_group.add_argument('--resume', action='store_true',
help='path to latest checkpoint (default: none)')
exp_group.add_argument('--eval', '--evaluate', dest='evalmode', default=None,
choices=['anytime', 'dynamic'],
help='way to evaluate')
exp_group.add_argument('--evaluate-from', default=None, type=str, metavar='PATH',
help='path to saved checkpoint (default: none)')
exp_group.add_argument('--print-freq', '-p', default=200, type=int,
metavar='N', help='print frequency (default: 100)')
exp_group.add_argument('--seed', default=0, type=int,
help='random seed')
exp_group.add_argument('--gpu', default='0',
help='GPU available.')
# dataset related
data_group = arg_parser.add_argument_group('data', 'dataset setting')
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
data_group.add_argument('--data', metavar='D', default='cifar100',
choices=['cifar10', 'cifar100', 'ImageNet'],
help='data to work on')
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
data_group.add_argument('--data-root', metavar='DIR', default='data',
help='path to dataset (default: data)')
data_group.add_argument('--use-valid', action='store_true',
help='use validation set or not')
data_group.add_argument('-j', '--workers', default=4, type=int, metavar='N',
help='number of data loading workers (default: 4)')
# data_group.add_argument('--normalized', action='store_true',
# help='normalize the data into zero mean and unit std')
# data_group.add_argument('--augmentation', default=0.08, type=float, metavar='M',
# help='')
# model arch related
arch_group = arg_parser.add_argument_group('arch',
'model architecture setting')
arch_group.add_argument('--arch', '-a', metavar='ARCH', default='msdnet_ge',
type=str, choices=model_names,
help='model architecture: ' +
' | '.join(model_names) +
' (default: resnet)')
arch_group.add_argument('-d', '--depth', default=56, type=int, metavar='D',
help='depth (default=56)')
arch_group.add_argument('--drop-rate', default=0.0, type=float,
metavar='DROPRATE', help='dropout rate (default: 0.2)')
arch_group.add_argument('--death-mode', default='none',
choices=['none', 'linear', 'uniform'],
help='death mode (default: none)')
arch_group.add_argument('--death-rate', default=0.5, type=float,
help='death rate rate (default: 0.5)')
# arch_group.add_argument('--growth-rate', default=12, type=int,
# metavar='GR', help='Growth rate of DenseNet'
# ' (1 means dot\'t use compression) (default: 0.5)')
arch_group.add_argument('--bn-size', default=4, type=int,
metavar='B', help='bottle neck ratio of DenseNet'
' (0 means dot\'t use bottle necks) (default: 4)')
arch_group.add_argument('--reduction', default=0.5, type=float,
metavar='C', help='compression ratio of DenseNet'
' (1 means dot\'t use compression) (default: 0.5)')
# used to set the argument when to resume automatically
arch_resume_names = ['arch', 'depth', 'death_mode', 'death_rate', 'death_rate',
'growth_rate', 'bn_size', 'compression']
# msdnet config
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
step=4
arch_group.add_argument('--nBlocks', type=int, default=5)
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
arch_group.add_argument('--nChannels', type=int, default=32)
arch_group.add_argument('--base', type=int, default=step)
arch_group.add_argument('--stepmode', type=str, default='even', choices=['even', 'lin_grow'])
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
arch_group.add_argument('--step', type=int, default=step)
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
arch_group.add_argument('--growthRate', type=int, default=6)
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
arch_group.add_argument('--grFactor', default='1-2-4', type=str)
arch_group.add_argument('--prune', default='max', choices=['min', 'max'])
arch_group.add_argument('--bnFactor', default='1-2-4')
arch_group.add_argument('--bottleneck', default=True, type=bool)
arch_group.add_argument('--pretrained', default=None, type=str, metavar='PATH',
help='path to load pretrained msdnet (default: none)')
arch_group.add_argument('--priornet', default=None, type=str, metavar='PATH',
help='path to load pretrained priornet (default: none)')
# training related
optim_group = arg_parser.add_argument_group('optimization',
'optimization setting')
optim_group.add_argument('--trainer', default='train', type=str,
help='trainer file name without ".py"'
' (default: train)')
optim_group.add_argument('--epochs', default=1, type=int, metavar='N',
help='number of total epochs to run (default: 164)')
optim_group.add_argument('--start-epoch', default=0, type=int, metavar='N',
help='manual epoch number (useful on restarts)')
optim_group.add_argument('--switch-mode', default=300, type=int, metavar='N',
help='number of epochs to switch mode (default: 300)')
optim_group.add_argument('--patience', default=0, type=int, metavar='N',
help='patience for early stopping'
'(0 means no early stopping)')
optim_group.add_argument('-b', '--batch-size', default=64, type=int,
metavar='N', help='mini-batch size (default: 64)')
optim_group.add_argument('--optimizer', default='sgd',
choices=['sgd', 'rmsprop', 'adam'], metavar='N',
help='optimizer (default=sgd)')
optim_group.add_argument('--lr', '--learning-rate', default=0.1, type=float,
metavar='LR',
help='initial learning rate (default: 0.1)')
optim_group.add_argument('--lr-type', default='multistep', type=str, metavar='T',
help='learning rate strategy (default: multistep)',
choices=['cosine', 'multistep'])
optim_group.add_argument('--decay-rate', default=0.1, type=float, metavar='N',
help='decay rate of learning rate (default: 0.1)')
optim_group.add_argument('--momentum', default=0.9, type=float, metavar='M',
help='momentum (default=0.9)')
optim_group.add_argument('--alpha', default=0.99, type=float, metavar='M',
help='alpha for ')
optim_group.add_argument('--beta1', default=0.9, type=float, metavar='M',
help='beta1 for Adam (default: 0.9)')
optim_group.add_argument('--beta2', default=0.999, type=float, metavar='M',
help='beta2 for Adam (default: 0.999)')
optim_group.add_argument('--weight-decay', '--wd', default=1e-4, type=float,
metavar='W', help='weight decay (default: 1e-4)')
### add kd hyperparameters
optim_group.add_argument('--gamma', default=0.9, type=float, metavar='M',
help='gamma for kld loss')
optim_group.add_argument('-T', default=3.0, type=float, metavar='M',
help='Temperature for KD')
mood_group = arg_parser.add_argument_group('mood',
'mood setting')
mood_group.add_argument('-ms', '--score', type=str,
default='energy',
help='basic score for MOOD method, choose from: energy, msp, odin, mahalanobis')
mood_group.add_argument('-mf', '--file', type=str,
default='trained_model/msdnet_cifar10.pth.tar',
help='model file for MSDNet')
mood_group.add_argument('-ml', '--layer', type=int,
default=5,
help='# of exits for MSDNet')
mood_group.add_argument('-mi', '--id', type=str,
default='cifar10',
help='in distribution dataset: cifar10 or cifar100')
mood_group.add_argument('-mo', '--od', type=list,
default=['mnist',
'kmnist',
'fasionmnist',
'lsun',
'svhn',
'dtd',
'stl10',
'place365',
'isun',
'lsunR'
],
help='all 10 OOD datasets used in experiment')
mood_group.add_argument('-mc', '--compressor', type=str,
default='png',
help='compressor for complexity')
mood_group.add_argument('-mt', '--threshold', type=int,
default=[0,
1*2700/5,
2*2700/5,
3*2700/5,
4*2700/5,
9999],
help='the complex thresholds for different exits in MSDNet')
mood_group.add_argument('-ma', '--adjusted', type=int,
default=1,
help='adjusted energy score: mode 1: minus mean; mode 0: keep as original')
mood_group.add_argument('-mb', '--bs', type=int,
default=64,
help='batch size')