-
Notifications
You must be signed in to change notification settings - Fork 5
/
train.py
65 lines (50 loc) · 1.49 KB
/
train.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
import torch
import argparse
from utils import set_seeds
# Exp
from experiment.flow import FlowExperiment, add_exp_args
# Data
from data.data import get_data, get_data_id, add_data_args
# Model
from model.model import get_model, get_model_id, add_model_args
# Optim
from optim.expdecay import get_optim, get_optim_id, add_optim_args
###########
## Setup ##
###########
parser = argparse.ArgumentParser()
add_exp_args(parser)
add_data_args(parser)
add_model_args(parser)
add_optim_args(parser)
args = parser.parse_args()
set_seeds(args.seed)
##################
## Specify data ##
##################
train_loader, eval_loader, data_shape, num_classes = get_data(args)
data_id = get_data_id(args)
###################
## Specify model ##
###################
model = get_model(args, data_shape=data_shape, num_classes=num_classes)
model_id = get_model_id(args)
#######################
## Specify optimizer ##
#######################
optimizer, scheduler_iter, scheduler_epoch = get_optim(args, model)
optim_id = get_optim_id(args)
##############
## Training ##
##############
exp = FlowExperiment(args=args,
data_id=data_id,
model_id=model_id,
optim_id=optim_id,
train_loader=train_loader,
eval_loader=eval_loader,
model=model,
optimizer=optimizer,
scheduler_iter=scheduler_iter,
scheduler_epoch=scheduler_epoch)
exp.run()