-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtrain.py
100 lines (79 loc) · 3.28 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import hparams
from model.wavenet_model import *
from model.model_training import *
from config import *
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
# def exit_handler():
# trainer.save_model()
# print("exit from keyboard")
if not os.path.isdir(DATA_ROOT_PATH):
print(u"请先执行data/preprocess.py生成训练数据 ")
def train_harmonic():
snapshot_path = os.path.join(SNAOSHOTS_ROOT_PATH, 'harmonic')
model = WaveNetModel(hparams.create_harmonic_hparams(), device).to(device)
print('model: ', model)
print('receptive field: ', model.receptive_field)
print('parameter count: ', model.parameter_count())
trainer = ModelTrainer(model=model,
data_folder=DATA_ROOT_PATH,
lr=0.0005,
weight_decay=0.000005,
snapshot_path=snapshot_path,
snapshot_name='harm',
device=device)
print('start train harmonic...')
trainer.train(batch_size=32,
epochs=1650)
def train_aperiodic():
snapshot_path = os.path.join(SNAOSHOTS_ROOT_PATH, 'aperiodic')
model = WaveNetModel(hparams.create_aperiodic_hparams(), device).to(device)
print('model: ', model)
print('receptive field: ', model.receptive_field)
print('parameter count: ', model.parameter_count())
trainer = ModelTrainer(model=model,
data_folder=DATA_ROOT_PATH,
lr=0.0005,
weight_decay=0.0,
snapshot_path=snapshot_path,
snapshot_name='aper',
device=device)
print('start train aperiodic...')
trainer.train(batch_size=32,
epochs=1650)
def train_vuv():
snapshot_path = os.path.join(SNAOSHOTS_ROOT_PATH, 'vuv')
model = WaveNetModel(hparams.create_vuv_hparams(), device).to(device)
print('model: ', model)
print('receptive field: ', model.receptive_field)
print('parameter count: ', model.parameter_count())
trainer = ModelTrainer(model=model,
data_folder=DATA_ROOT_PATH,
lr=0.0005,
weight_decay=0,
snapshot_path=snapshot_path,
snapshot_name='vuv',
device=device)
print('start train vuv...')
trainer.train(batch_size=32,
epochs=1650)
def train_f0():
snapshot_path = os.path.join(SNAOSHOTS_ROOT_PATH, 'f0')
model = WaveNetModel(hparams.create_f0_hparams(), device).to(device)
print('model: ', model)
print('receptive field: ', model.receptive_field)
print('parameter count: ', model.parameter_count())
trainer = ModelTrainer(model=model,
data_folder=DATA_ROOT_PATH,
lr=0.001,
weight_decay=0,
snapshot_path=snapshot_path,
snapshot_name='f0',
device=device)
print('start train f0...')
trainer.train(batch_size=64,
epochs=235)
if __name__ == '__main__':
train_harmonic()
#train_aperiodic()
train_vuv()
train_f0()