-
Notifications
You must be signed in to change notification settings - Fork 115
/
main.py
executable file
·47 lines (39 loc) · 1.38 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
from option import args
from utils import mkExpDir
from dataset import dataloader
from model import TTSR
from loss.loss import get_loss_dict
from trainer import Trainer
import os
import torch
import torch.nn as nn
import warnings
warnings.filterwarnings('ignore')
if __name__ == '__main__':
### make save_dir
_logger = mkExpDir(args)
### dataloader of training set and testing set
_dataloader = dataloader.get_dataloader(args) if (not args.test) else None
### device and model
device = torch.device('cpu' if args.cpu else 'cuda')
_model = TTSR.TTSR(args).to(device)
if ((not args.cpu) and (args.num_gpu > 1)):
_model = nn.DataParallel(_model, list(range(args.num_gpu)))
### loss
_loss_all = get_loss_dict(args, _logger)
### trainer
t = Trainer(args, _logger, _dataloader, _model, _loss_all)
### test / eval / train
if (args.test):
t.load(model_path=args.model_path)
t.test()
elif (args.eval):
t.load(model_path=args.model_path)
t.evaluate()
else:
for epoch in range(1, args.num_init_epochs+1):
t.train(current_epoch=epoch, is_init=True)
for epoch in range(1, args.num_epochs+1):
t.train(current_epoch=epoch, is_init=False)
if (epoch % args.val_every == 0):
t.evaluate(current_epoch=epoch)