-
Notifications
You must be signed in to change notification settings - Fork 1
/
train.py
63 lines (47 loc) · 2.12 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
import os
import argparse
from libs.utils import *
from libs.train_cahr import *
from libs.train_basic import *
from omegaconf import OmegaConf
def main(args):
# loads configs
configs = OmegaConf.load(args.config_file)
# initialize environments
init_environment(configs.seed)
exp_dir = os.path.join(args.exp_root, configs.exp)
# prints information
print('-' * 100)
print('Training for BCI Dataset ...\n')
print(f'- Train Dir: {args.train_dir}')
print(f'- Val Dir: {args.val_dir}')
print(f'- Exp Dir: {exp_dir}')
print(f'- Configs : {args.config_file}')
print(f'- Trainer : {args.trainer}', '\n')
if args.trainer == 'basic':
# loads dataloder for training and validation
train_loader = get_dataloader('train', args.train_dir, configs.loader)
val_loader = get_dataloader('val', args.val_dir, configs.loader)
# initialize trainer
trainer = BCITrainerBasic(configs, exp_dir, args.resume_ckpt)
elif args.trainer == 'cahr':
# loads dataloder for training and validation
train_loader = get_cahr_dataloader('train', args.train_dir, configs.loader)
val_loader = get_cahr_dataloader('val', args.val_dir, configs.loader)
# initialize trainer
trainer = BCITrainerCAHR(configs, exp_dir, args.resume_ckpt)
# training model
trainer.forward(train_loader, val_loader)
print('-' * 100, '\n')
return
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Training for BCI Dataset')
parser.add_argument('--train_dir', type=str, help='dir path of training data')
parser.add_argument('--val_dir', type=str, help='dir path of validation data')
parser.add_argument('--exp_root', type=str, help='root dir of experiment')
parser.add_argument('--config_file', type=str, help='yaml path of configs')
parser.add_argument('--resume_ckpt', type=str, help='checkpoint path for resuming')
parser.add_argument('--trainer', type=str, help='trainer type, basic or cahr', default='basic')
args = parser.parse_args()
check_train_args(args)
main(args)