-
Notifications
You must be signed in to change notification settings - Fork 153
/
train.py
66 lines (53 loc) · 2.98 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
66
import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)
from synthesizer.hparams import hparams, get_image_list
from synthesizer.train import tacotron_train
from utils.argutils import print_args
#from synthesizer import infolog
import argparse
from pathlib import Path
import os
#Prepares the data.
def prepare_run(args):
os.environ["TF_CPP_MIN_LOG_LEVEL"] = str(args.tf_log_level)
run_name = args.name
log_dir = os.path.join(args.models_dir, "logs-{}".format(run_name))
os.makedirs(log_dir, exist_ok=True)
all_images = get_image_list('train', args.data_root)
all_test_images = get_image_list('val', args.data_root)
hparams.add_hparam('all_images', all_images)
hparams.add_hparam('all_test_images', all_test_images)
print('Training on {} hours'.format(len(all_images) / (3600. * hparams.fps)))
print('Validating on {} hours'.format(len(all_test_images) / (3600. * hparams.fps)))
return log_dir, hparams
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("name", help="Name of the run and of the logging directory.")
parser.add_argument("--data_root", help="Speaker folder path", required=True)
parser.add_argument("--preset", help="Speaker-specific hyper-params", type=str, required=True)
parser.add_argument("-m", "--models_dir", type=str, default="synthesizer/saved_models/", help=\
"Path to the output directory that will contain the saved model weights and the logs.")
parser.add_argument("--mode", default="synthesis",
help="mode for synthesis of tacotron after training")
parser.add_argument("--GTA", default="True",
help="Ground truth aligned synthesis, defaults to True, only considered "
"in Tacotron synthesis mode")
parser.add_argument("--restore", type=bool, default=True,
help="Set this to False to do a fresh training")
parser.add_argument("--summary_interval", type=int, default=2500,
help="Steps between running summary ops")
parser.add_argument("--embedding_interval", type=int, default=1000000000,
help="Steps between updating embeddings projection visualization")
parser.add_argument("--checkpoint_interval", type=int, default=1000, # Was 5000
help="Steps between writing checkpoints")
parser.add_argument("--eval_interval", type=int, default=1000, # Was 10000
help="Steps between eval on test data")
parser.add_argument("--tacotron_train_steps", type=int, default=2000000, # Was 100000
help="total number of tacotron training steps")
parser.add_argument("--tf_log_level", type=int, default=1, help="Tensorflow C++ log level.")
args = parser.parse_args()
print_args(args, parser)
log_dir, hparams = prepare_run(args)
with open(args.preset) as f:
hparams.parse_json(f.read())
tacotron_train(args, log_dir, hparams)