-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.py
440 lines (430 loc) · 19 KB
/
util.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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
import sys
from PIL import Image, ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True
def get_network(args):
""" return given network
"""
if args.dataset == "cifar10":
if args.net == 'vgg16':
from models.net.cifar10.vgg import vgg16_bn
net = vgg16_bn()
elif args.net == 'vgg13':
from models.net.cifar10.vgg import vgg13_bn
net = vgg13_bn()
elif args.net == 'vgg11':
from models.net.cifar10.vgg import vgg11_bn
net = vgg11_bn()
elif args.net == 'vgg19':
from models.net.cifar10.vgg import vgg19_bn
net = vgg19_bn()
elif args.net == 'densenet121':
from models.net.cifar10.densenet import densenet121
net = densenet121()
elif args.net == 'densenet161':
from models.net.cifar10.densenet import densenet161
net = densenet161()
elif args.net == 'densenet169':
from models.net.cifar10.densenet import densenet169
net = densenet169()
elif args.net == 'densenet201':
from models.net.cifar10.densenet import densenet201
net = densenet201()
elif args.net == 'googlenet':
from models.net.cifar10.googlenet import googlenet
net = googlenet()
elif args.net == 'inceptionv3':
from models.net.cifar10.inceptionv3 import inceptionv3
net = inceptionv3()
elif args.net == 'inceptionv4':
from models.net.cifar10.inceptionv4 import inceptionv4
net = inceptionv4()
elif args.net == 'inceptionresnetv2':
from models.net.cifar10.inceptionv4 import inception_resnet_v2
net = inception_resnet_v2()
elif args.net == 'xception':
from models.net.cifar10.xception import xception
net = xception()
elif args.net == 'resnet18':
from models.net.cifar10.resnet import resnet18
net = resnet18()
elif args.net == 'resnet34':
from models.net.cifar10.resnet import resnet34
net = resnet34()
elif args.net == 'resnet50':
from models.net.cifar10.resnet import resnet50
net = resnet50()
elif args.net == 'resnet101':
from models.net.cifar10.resnet import resnet101
net = resnet101()
elif args.net == 'resnet152':
from models.net.cifar10.resnet import resnet152
net = resnet152()
elif args.net == 'preactresnet18':
from models.net.cifar10.preactresnet import preactresnet18
net = preactresnet18()
elif args.net == 'preactresnet34':
from models.net.cifar10.preactresnet import preactresnet34
net = preactresnet34()
elif args.net == 'preactresnet50':
from models.net.cifar10.preactresnet import preactresnet50
net = preactresnet50()
elif args.net == 'preactresnet101':
from models.net.cifar10.preactresnet import preactresnet101
net = preactresnet101()
elif args.net == 'preactresnet152':
from models.net.cifar10.preactresnet import preactresnet152
net = preactresnet152()
elif args.net == 'resnext50':
from models.net.cifar10.resnext import resnext50
net = resnext50()
elif args.net == 'resnext101':
from models.net.cifar10.resnext import resnext101
net = resnext101()
elif args.net == 'resnext152':
from models.net.cifar10.resnext import resnext152
net = resnext152()
elif args.net == 'shufflenet':
from models.net.cifar10.shufflenet import shufflenet
net = shufflenet()
elif args.net == 'shufflenetv2':
from models.net.cifar10.shufflenetv2 import shufflenetv2
net = shufflenetv2()
elif args.net == 'squeezenet':
from models.net.cifar10.squeezenet import squeezenet
net = squeezenet()
elif args.net == 'mobilenet':
from models.net.cifar10.mobilenet import mobilenet
net = mobilenet()
elif args.net == 'mobilenetv2':
from models.net.cifar10.mobilenetv2 import mobilenetv2
net = mobilenetv2()
elif args.net == 'nasnet':
from models.net.cifar10.nasnet import nasnet
net = nasnet()
elif args.net == 'attention56':
from models.net.cifar10.attention import attention56
net = attention56()
elif args.net == 'attention92':
from models.net.cifar10.attention import attention92
net = attention92()
elif args.net == 'seresnet18':
from models.net.cifar10.senet import seresnet18
net = seresnet18()
elif args.net == 'seresnet34':
from models.net.cifar10.senet import seresnet34
net = seresnet34()
elif args.net == 'seresnet50':
from models.net.cifar10.senet import seresnet50
net = seresnet50()
elif args.net == 'seresnet101':
from models.net.cifar10.senet import seresnet101
net = seresnet101()
elif args.net == 'seresnet152':
from models.net.cifar10.senet import seresnet152
net = seresnet152()
elif args.net == 'wideresnet':
from models.net.cifar10.wideresidual import wideresnet
net = wideresnet()
elif args.net == 'stochasticdepth18':
from models.net.cifar10.stochasticdepth import \
stochastic_depth_resnet18
net = stochastic_depth_resnet18()
elif args.net == 'stochasticdepth34':
from models.net.cifar10.stochasticdepth import \
stochastic_depth_resnet34
net = stochastic_depth_resnet34()
elif args.net == 'stochasticdepth50':
from models.net.cifar10.stochasticdepth import \
stochastic_depth_resnet50
net = stochastic_depth_resnet50()
elif args.net == 'stochasticdepth101':
from models.net.cifar10.stochasticdepth import \
stochastic_depth_resnet101
net = stochastic_depth_resnet101()
else:
print('the network name you have entered is not supported yet')
sys.exit()
elif args.dataset == "cifar100":
if args.net == 'vgg16':
from models.net.cifar100.vgg import vgg16_bn
net = vgg16_bn()
elif args.net == 'vgg13':
from models.net.cifar100.vgg import vgg13_bn
net = vgg13_bn()
elif args.net == 'vgg11':
from models.net.cifar100.vgg import vgg11_bn
net = vgg11_bn()
elif args.net == 'vgg19':
from models.net.cifar100.vgg import vgg19_bn
net = vgg19_bn()
elif args.net == 'densenet121':
from models.net.cifar100.densenet import densenet121
net = densenet121()
elif args.net == 'densenet161':
from models.net.cifar100.densenet import densenet161
net = densenet161()
elif args.net == 'densenet169':
from models.net.cifar100.densenet import densenet169
net = densenet169()
elif args.net == 'densenet201':
from models.net.cifar100.densenet import densenet201
net = densenet201()
elif args.net == 'googlenet':
from models.net.cifar100.googlenet import googlenet
net = googlenet()
elif args.net == 'inceptionv3':
from models.net.cifar100.inceptionv3 import inceptionv3
net = inceptionv3()
elif args.net == 'inceptionv4':
from models.net.cifar100.inceptionv4 import inceptionv4
net = inceptionv4()
elif args.net == 'inceptionresnetv2':
from models.net.cifar100.inceptionv4 import inception_resnet_v2
net = inception_resnet_v2()
elif args.net == 'xception':
from models.net.cifar100.xception import xception
net = xception()
elif args.net == 'resnet18':
from models.net.cifar100.resnet import resnet18
net = resnet18()
elif args.net == 'resnet34':
from models.net.cifar100.resnet import resnet34
net = resnet34()
elif args.net == 'resnet50':
from models.net.cifar100.resnet import resnet50
net = resnet50()
elif args.net == 'resnet101':
from models.net.cifar100.resnet import resnet101
net = resnet101()
elif args.net == 'resnet152':
from models.net.cifar100.resnet import resnet152
net = resnet152()
elif args.net == 'preactresnet18':
from models.net.cifar100.preactresnet import preactresnet18
net = preactresnet18()
elif args.net == 'preactresnet34':
from models.net.cifar100.preactresnet import preactresnet34
net = preactresnet34()
elif args.net == 'preactresnet50':
from models.net.cifar100.preactresnet import preactresnet50
net = preactresnet50()
elif args.net == 'preactresnet101':
from models.net.cifar100.preactresnet import preactresnet101
net = preactresnet101()
elif args.net == 'preactresnet152':
from models.net.cifar100.preactresnet import preactresnet152
net = preactresnet152()
elif args.net == 'resnext50':
from models.net.cifar100.resnext import resnext50
net = resnext50()
elif args.net == 'resnext101':
from models.net.cifar100.resnext import resnext101
net = resnext101()
elif args.net == 'resnext152':
from models.net.cifar100.resnext import resnext152
net = resnext152()
elif args.net == 'shufflenet':
from models.net.cifar100.shufflenet import shufflenet
net = shufflenet()
elif args.net == 'shufflenetv2':
from models.net.cifar100.shufflenetv2 import shufflenetv2
net = shufflenetv2()
elif args.net == 'squeezenet':
from models.net.cifar100.squeezenet import squeezenet
net = squeezenet()
elif args.net == 'mobilenet':
from models.net.cifar100.mobilenet import mobilenet
net = mobilenet()
elif args.net == 'mobilenetv2':
from models.net.cifar100.mobilenetv2 import mobilenetv2
net = mobilenetv2()
elif args.net == 'nasnet':
from models.net.cifar100.nasnet import nasnet
net = nasnet()
elif args.net == 'attention56':
from models.net.cifar100.attention import attention56
net = attention56()
elif args.net == 'attention92':
from models.net.cifar100.attention import attention92
net = attention92()
elif args.net == 'seresnet18':
from models.net.cifar100.senet import seresnet18
net = seresnet18()
elif args.net == 'seresnet34':
from models.net.cifar100.senet import seresnet34
net = seresnet34()
elif args.net == 'seresnet50':
from models.net.cifar100.senet import seresnet50
net = seresnet50()
elif args.net == 'seresnet101':
from models.net.cifar100.senet import seresnet101
net = seresnet101()
elif args.net == 'seresnet152':
from models.net.cifar100.senet import seresnet152
net = seresnet152()
elif args.net == 'wideresnet':
from models.net.cifar100.wideresidual import wideresnet
net = wideresnet()
elif args.net == 'stochasticdepth18':
from models.net.cifar100.stochasticdepth import \
stochastic_depth_resnet18
net = stochastic_depth_resnet18()
elif args.net == 'stochasticdepth34':
from models.net.cifar100.stochasticdepth import \
stochastic_depth_resnet34
net = stochastic_depth_resnet34()
elif args.net == 'stochasticdepth50':
from models.net.cifar100.stochasticdepth import \
stochastic_depth_resnet50
net = stochastic_depth_resnet50()
elif args.net == 'stochasticdepth101':
from models.net.cifar100.stochasticdepth import \
stochastic_depth_resnet101
net = stochastic_depth_resnet101()
else:
print('the network name you have entered is not supported yet')
sys.exit()
elif args.dataset == "tinyimagenet":
if args.net == 'vgg16':
from models.net.tinyimagenet.vgg import vgg16_bn
net = vgg16_bn()
elif args.net == 'vgg13':
from models.net.tinyimagenet.vgg import vgg13_bn
net = vgg13_bn()
elif args.net == 'vgg11':
from models.net.tinyimagenet.vgg import vgg11_bn
net = vgg11_bn()
elif args.net == 'vgg19':
from models.net.tinyimagenet.vgg import vgg19_bn
net = vgg19_bn()
elif args.net == 'densenet121':
from models.net.tinyimagenet.densenet import densenet121
net = densenet121()
elif args.net == 'densenet161':
from models.net.tinyimagenet.densenet import densenet161
net = densenet161()
elif args.net == 'densenet169':
from models.net.tinyimagenet.densenet import densenet169
net = densenet169()
elif args.net == 'densenet201':
from models.net.tinyimagenet.densenet import densenet201
net = densenet201()
elif args.net == 'googlenet':
from models.net.tinyimagenet.googlenet import googlenet
net = googlenet()
elif args.net == 'inceptionv3':
from models.net.tinyimagenet.inceptionv3 import inceptionv3
net = inceptionv3()
elif args.net == 'inceptionv4':
from models.net.tinyimagenet.inceptionv4 import inceptionv4
net = inceptionv4()
elif args.net == 'inceptionresnetv2':
from models.net.tinyimagenet.inceptionv4 import inception_resnet_v2
net = inception_resnet_v2()
elif args.net == 'xception':
from models.net.tinyimagenet.xception import xception
net = xception()
elif args.net == 'resnet18':
from models.net.tinyimagenet.resnet import resnet18
net = resnet18()
elif args.net == 'resnet34':
from models.net.tinyimagenet.resnet import resnet34
net = resnet34()
elif args.net == 'resnet50':
from models.net.tinyimagenet.resnet import resnet50
net = resnet50()
elif args.net == 'resnet101':
from models.net.tinyimagenet.resnet import resnet101
net = resnet101()
elif args.net == 'resnet152':
from models.net.tinyimagenet.resnet import resnet152
net = resnet152()
elif args.net == 'preactresnet18':
from models.net.tinyimagenet.preactresnet import preactresnet18
net = preactresnet18()
elif args.net == 'preactresnet34':
from models.net.tinyimagenet.preactresnet import preactresnet34
net = preactresnet34()
elif args.net == 'preactresnet50':
from models.net.tinyimagenet.preactresnet import preactresnet50
net = preactresnet50()
elif args.net == 'preactresnet101':
from models.net.tinyimagenet.preactresnet import preactresnet101
net = preactresnet101()
elif args.net == 'preactresnet152':
from models.net.tinyimagenet.preactresnet import preactresnet152
net = preactresnet152()
elif args.net == 'resnext50':
from models.net.tinyimagenet.resnext import resnext50
net = resnext50()
elif args.net == 'resnext101':
from models.net.tinyimagenet.resnext import resnext101
net = resnext101()
elif args.net == 'resnext152':
from models.net.tinyimagenet.resnext import resnext152
net = resnext152()
elif args.net == 'shufflenet':
from models.net.tinyimagenet.shufflenet import shufflenet
net = shufflenet()
elif args.net == 'shufflenetv2':
from models.net.tinyimagenet.shufflenetv2 import shufflenetv2
net = shufflenetv2()
elif args.net == 'squeezenet':
from models.net.tinyimagenet.squeezenet import squeezenet
net = squeezenet()
elif args.net == 'mobilenet':
from models.net.tinyimagenet.mobilenet import mobilenet
net = mobilenet()
elif args.net == 'mobilenetv2':
from models.net.tinyimagenet.mobilenetv2 import mobilenetv2
net = mobilenetv2()
elif args.net == 'nasnet':
from models.net.tinyimagenet.nasnet import nasnet
net = nasnet()
elif args.net == 'attention56':
from models.net.tinyimagenet.attention import attention56
net = attention56()
elif args.net == 'attention92':
from models.net.tinyimagenet.attention import attention92
net = attention92()
elif args.net == 'seresnet18':
from models.net.tinyimagenet.senet import seresnet18
net = seresnet18()
elif args.net == 'seresnet34':
from models.net.tinyimagenet.senet import seresnet34
net = seresnet34()
elif args.net == 'seresnet50':
from models.net.tinyimagenet.senet import seresnet50
net = seresnet50()
elif args.net == 'seresnet101':
from models.net.tinyimagenet.senet import seresnet101
net = seresnet101()
elif args.net == 'seresnet152':
from models.net.tinyimagenet.senet import seresnet152
net = seresnet152()
elif args.net == 'wideresnet':
from models.net.tinyimagenet.wideresidual import wideresnet
net = wideresnet()
elif args.net == 'stochasticdepth18':
from models.net.tinyimagenet.stochasticdepth import \
stochastic_depth_resnet18
net = stochastic_depth_resnet18()
elif args.net == 'stochasticdepth34':
from models.net.tinyimagenet.stochasticdepth import \
stochastic_depth_resnet34
net = stochastic_depth_resnet34()
elif args.net == 'stochasticdepth50':
from models.net.tinyimagenet.stochasticdepth import \
stochastic_depth_resnet50
net = stochastic_depth_resnet50()
elif args.net == 'stochasticdepth101':
from models.net.tinyimagenet.stochasticdepth import \
stochastic_depth_resnet101
net = stochastic_depth_resnet101()
else:
print('the network name you have entered is not supported yet')
sys.exit()
else:
print('the dataset you have entered is not supported yet')
sys.exit()
return net