-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.py
49 lines (39 loc) · 1.66 KB
/
main.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
import os
from loss import LossCalulcator
from data import get_dataloader
from optim import get_optimizer
from config import get_arguments
from network import load_network
from trainval import train, measure_accuracy
if __name__ == '__main__':
# load argument
args, device = get_arguments()
# make a network instance
network = load_network(args.model, args.model_load, args.num_class, device)
# validation data loader
val_loader = get_dataloader(train_flag = False, args = args)
if args.train_flag:
optimizer, scheduler = get_optimizer(network, args)
# load a teacher for knowledge distillation
teacher = None
if args.teacher_load:
teacher = load_network(args.teacher, args.teacher_load, args.num_class, device)
# train data loader
train_loader = get_dataloader(train_flag = True, args = args)
# make loss calculator
loss_calculator = LossCalulcator(args.temperature, args.distillation_weight).to(device)
# train the network
print("Training the network...")
network = train(student = network,
dataloader = train_loader,
optimizer = optimizer,
scheduler = scheduler,
loss_calculator = loss_calculator,
device = device,
args = args,
teacher = teacher,
val_dataloader = val_loader)
else:
# evaluate the network
print("Evalute the network...")
measure_accuracy(network, val_loader, device)