-
Notifications
You must be signed in to change notification settings - Fork 0
/
baseline_dfme.py
102 lines (78 loc) · 2.85 KB
/
baseline_dfme.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
from dfme.train import train, test
from models.resnet import *
from models.googlenet import *
from models.inception import *
from models.mobilenetv2 import *
from models.resnet_8x import ResNet18_8x
from models.gan import GeneratorA
from dfme.utils import get_dynamic_connections, get_dataloader
import torch
class ARGS:
epoch_iter = 50
g_iter = 1
s_iter = 5
num_classes = 10
dataset = 'cifar10'
data_root = './data/'
image_size = 32
image_channels = 3
batch_size = 256
student_lr = 0.1
generator_lr = 1e-4
weight_decay = 5e-4
steps = [0.1, 0.3, 0.5]
momentum = 0.9
random_noise_size = 256
grad_epsilon = 1e-3
grad_m = 1
current_budget = 0
cost_per_iteration = 0 # will be calculated within the program
query_budget = 10e6
seed = 4
generator_activation = torch.tanh
teacher = resnet34()
teacher_name = 'resnet34'
student = ResNet18_8x(num_classes)
student_name = 'resnet_18'
generator = GeneratorA(nz=random_noise_size, nc=image_channels, img_size=image_size, activation=generator_activation)
teacher_load_path = './checkpoints/teacher/resnet34.pt'
student_load_path = '' # fill after saving atleast once
generator_load_path = '' # fill after saving atleast once
student_save_folder = './checkpoints/student/'
generator_save_folder = './checkpoints/generator'
args = ARGS()
acc = {}
f = open('results.txt', "a")
# # DFME: TEACHER RESNET34
# acc[args.teacher_name] = train(args)
# f.write("\n"); f.write(f'{args.teacher_name}: {acc[args.teacher_name]}')
# DFME: TEACHER RESNET18
# args.teacher = resnet18()
# args.teacher_name = 'resnet18'
# args.teacher_load_path = './checkpoints/teacher/resnet18.pt'
# acc[args.teacher_name] = train(args)
# f.write("\n"); f.write(f'{args.teacher_name}: {acc[args.teacher_name]}')
# DFME: TEACHER RESNET50
args.teacher = resnet50()
args.teacher_name = 'resnet50'
args.teacher_load_path = './checkpoints/teacher/resnet50.pt'
acc[args.teacher_name] = train(args)
f.write("\n"); f.write(f'{args.teacher_name}: {acc[args.teacher_name]}')
# DFME: TEACHER GOOGLENET
args.teacher = googlenet()
args.teacher_name = 'googlenet'
args.teacher_load_path = './checkpoints/teacher/googlenet.pt'
acc[args.teacher_name] = train(args)
f.write("\n"); f.write(f'{args.teacher_name}: {acc[args.teacher_name]}')
# DFME: TEACHER INCEPTION V3
args.teacher = inception_v3()
args.teacher_name = 'inception_v3'
args.teacher_load_path = './checkpoints/teacher/inception_v3.pt'
acc[args.teacher_name] = train(args)
f.write("\n"); f.write(f'{args.teacher_name}: {acc[args.teacher_name]}')
# DFME: TEACHER MOBILENET
args.teacher = mobilenet_v2()
args.teacher_name = 'mobilenet_v2'
args.teacher_load_path = './checkpoints/teacher/mobilenet_v2.pt'
acc[args.teacher_name] = train(args)
f.write("\n"); f.write(f'{args.teacher_name}: {acc[args.teacher_name]}')