forked from Deepest-Project/MelNet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trainer.py
64 lines (55 loc) · 2.32 KB
/
trainer.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
import os
import time
import logging
import argparse
import platform
from utils.train import train
from utils.hparams import HParam
from utils.writer import MyWriter
from datasets.wavloader import create_dataloader
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-c', '--config', type=str, required=True,
help="yaml file for configuration")
parser.add_argument('-p', '--checkpoint_path', type=str, default=None,
help="path of checkpoint pt file to resume training")
parser.add_argument('-n', '--name', type=str, required=True,
help="name of the model for logging, saving checkpoint")
parser.add_argument('-t', '--tier', type=int, required=True,
help="Number of tier to train")
parser.add_argument('-b', '--batch_size', type=int, required=True,
help="Batch size")
parser.add_argument('-s', '--tts', type=bool, default=False, required=False,
help="TTS")
args = parser.parse_args()
hp = HParam(args.config)
with open(args.config, 'r') as f:
hp_str = ''.join(f.readlines())
if platform.system() == 'Windows':
hp.train.num_workers = 0
pt_dir = os.path.join(hp.log.chkpt_dir, args.name)
log_dir = os.path.join(hp.log.log_dir, args.name)
if not os.path.isdir(hp.log.log_dir):
os.mkdir(hp.log.log_dir)
if not os.path.isdir(hp.log.chkpt_dir):
os.mkdir(hp.log.chkpt_dir)
if not os.path.isdir(pt_dir):
os.mkdir(pt_dir)
if not os.path.isdir(log_dir):
os.mkdir(log_dir)
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s',
handlers=[
logging.FileHandler(os.path.join(log_dir,
'%s-%d.log' % (args.name, time.time()))),
logging.StreamHandler()
]
)
logger = logging.getLogger()
writer = MyWriter(hp, log_dir)
assert hp.data.path != '', \
'hp.data.path cannot be empty: please fill out your dataset\'s path in configuration yaml file.'
trainloader = create_dataloader(hp, args, train=True)
testloader = create_dataloader(hp, args, train=False)
train(args, pt_dir, args.checkpoint_path, trainloader, testloader, writer, logger, hp, hp_str)