Spaces:
Configuration error
Configuration error
Commit ·
dcf7507
1
Parent(s): 75d82ce
Delete training
Browse files- training/__pycache__/train_pipeline.cpython-38.pyc +0 -0
- training/config.yaml +0 -349
- training/config_nsf.yaml +0 -445
- training/dataset/__pycache__/base_dataset.cpython-38.pyc +0 -0
- training/dataset/__pycache__/fs2_utils.cpython-38.pyc +0 -0
- training/dataset/base_dataset.py +0 -66
- training/dataset/fs2_utils.py +0 -178
- training/from huggingface_hub import Repository.py +0 -2
- training/pe.py +0 -155
- training/rgsdgsd.py +0 -107
- training/song.mid +0 -0
- training/task/SVC_task.py +0 -223
- training/task/__pycache__/SVC_task.cpython-38.pyc +0 -0
- training/task/__pycache__/base_task.cpython-38.pyc +0 -0
- training/task/__pycache__/fs2.cpython-38.pyc +0 -0
- training/task/__pycache__/tts.cpython-38.pyc +0 -0
- training/task/base_task.py +0 -337
- training/task/fs2.py +0 -539
- training/task/tts.py +0 -131
- training/train_pipeline.py +0 -238
training/__pycache__/train_pipeline.cpython-38.pyc
DELETED
|
Binary file (7.36 kB)
|
|
|
training/config.yaml
DELETED
|
@@ -1,349 +0,0 @@
|
|
| 1 |
-
K_step: 1000
|
| 2 |
-
accumulate_grad_batches: 1
|
| 3 |
-
audio_num_mel_bins: 80
|
| 4 |
-
audio_sample_rate: 24000
|
| 5 |
-
binarization_args:
|
| 6 |
-
shuffle: false
|
| 7 |
-
with_align: true
|
| 8 |
-
with_f0: true
|
| 9 |
-
with_hubert: true
|
| 10 |
-
with_spk_embed: false
|
| 11 |
-
with_wav: false
|
| 12 |
-
binarizer_cls: preprocessing.SVCpre.SVCBinarizer
|
| 13 |
-
binary_data_dir: data/binary/atri
|
| 14 |
-
check_val_every_n_epoch: 10
|
| 15 |
-
choose_test_manually: false
|
| 16 |
-
clip_grad_norm: 1
|
| 17 |
-
config_path: training/config.yaml
|
| 18 |
-
content_cond_steps: []
|
| 19 |
-
cwt_add_f0_loss: false
|
| 20 |
-
cwt_hidden_size: 128
|
| 21 |
-
cwt_layers: 2
|
| 22 |
-
cwt_loss: l1
|
| 23 |
-
cwt_std_scale: 0.8
|
| 24 |
-
datasets:
|
| 25 |
-
- opencpop
|
| 26 |
-
debug: false
|
| 27 |
-
dec_ffn_kernel_size: 9
|
| 28 |
-
dec_layers: 4
|
| 29 |
-
decay_steps: 30000
|
| 30 |
-
decoder_type: fft
|
| 31 |
-
dict_dir: ''
|
| 32 |
-
diff_decoder_type: wavenet
|
| 33 |
-
diff_loss_type: l2
|
| 34 |
-
dilation_cycle_length: 4
|
| 35 |
-
dropout: 0.1
|
| 36 |
-
ds_workers: 4
|
| 37 |
-
dur_enc_hidden_stride_kernel:
|
| 38 |
-
- 0,2,3
|
| 39 |
-
- 0,2,3
|
| 40 |
-
- 0,1,3
|
| 41 |
-
dur_loss: mse
|
| 42 |
-
dur_predictor_kernel: 3
|
| 43 |
-
dur_predictor_layers: 5
|
| 44 |
-
enc_ffn_kernel_size: 9
|
| 45 |
-
enc_layers: 4
|
| 46 |
-
encoder_K: 8
|
| 47 |
-
encoder_type: fft
|
| 48 |
-
endless_ds: False
|
| 49 |
-
f0_bin: 256
|
| 50 |
-
f0_max: 1100.0
|
| 51 |
-
f0_min: 50.0
|
| 52 |
-
ffn_act: gelu
|
| 53 |
-
ffn_padding: SAME
|
| 54 |
-
fft_size: 512
|
| 55 |
-
fmax: 12000
|
| 56 |
-
fmin: 30
|
| 57 |
-
fs2_ckpt: ''
|
| 58 |
-
gaussian_start: true
|
| 59 |
-
gen_dir_name: ''
|
| 60 |
-
gen_tgt_spk_id: -1
|
| 61 |
-
hidden_size: 256
|
| 62 |
-
hop_size: 128
|
| 63 |
-
hubert_gpu: true
|
| 64 |
-
hubert_path: checkpoints/hubert/hubert_soft.pt
|
| 65 |
-
infer: false
|
| 66 |
-
keep_bins: 80
|
| 67 |
-
lambda_commit: 0.25
|
| 68 |
-
lambda_energy: 0.0
|
| 69 |
-
lambda_f0: 1.0
|
| 70 |
-
lambda_ph_dur: 0.3
|
| 71 |
-
lambda_sent_dur: 1.0
|
| 72 |
-
lambda_uv: 1.0
|
| 73 |
-
lambda_word_dur: 1.0
|
| 74 |
-
load_ckpt: ''
|
| 75 |
-
log_interval: 100
|
| 76 |
-
loud_norm: false
|
| 77 |
-
lr: 5.0e-05
|
| 78 |
-
max_beta: 0.02
|
| 79 |
-
max_epochs: 3000
|
| 80 |
-
max_eval_sentences: 1
|
| 81 |
-
max_eval_tokens: 60000
|
| 82 |
-
max_frames: 42000
|
| 83 |
-
max_input_tokens: 60000
|
| 84 |
-
max_sentences: 24
|
| 85 |
-
max_tokens: 128000
|
| 86 |
-
max_updates: 1000000
|
| 87 |
-
mel_loss: ssim:0.5|l1:0.5
|
| 88 |
-
mel_vmax: 1.5
|
| 89 |
-
mel_vmin: -6.0
|
| 90 |
-
min_level_db: -120
|
| 91 |
-
norm_type: gn
|
| 92 |
-
num_ckpt_keep: 10
|
| 93 |
-
num_heads: 2
|
| 94 |
-
num_sanity_val_steps: 1
|
| 95 |
-
num_spk: 1
|
| 96 |
-
num_test_samples: 0
|
| 97 |
-
num_valid_plots: 10
|
| 98 |
-
optimizer_adam_beta1: 0.9
|
| 99 |
-
optimizer_adam_beta2: 0.98
|
| 100 |
-
out_wav_norm: false
|
| 101 |
-
pe_ckpt: checkpoints/0102_xiaoma_pe/model_ckpt_steps_60000.ckpt
|
| 102 |
-
pe_enable: false
|
| 103 |
-
perform_enhance: true
|
| 104 |
-
pitch_ar: false
|
| 105 |
-
pitch_enc_hidden_stride_kernel:
|
| 106 |
-
- 0,2,5
|
| 107 |
-
- 0,2,5
|
| 108 |
-
- 0,2,5
|
| 109 |
-
pitch_extractor: parselmouth
|
| 110 |
-
pitch_loss: l2
|
| 111 |
-
pitch_norm: log
|
| 112 |
-
pitch_type: frame
|
| 113 |
-
pndm_speedup: 10
|
| 114 |
-
pre_align_args:
|
| 115 |
-
allow_no_txt: false
|
| 116 |
-
denoise: false
|
| 117 |
-
forced_align: mfa
|
| 118 |
-
txt_processor: zh_g2pM
|
| 119 |
-
use_sox: true
|
| 120 |
-
use_tone: false
|
| 121 |
-
pre_align_cls: data_gen.singing.pre_align.SingingPreAlign
|
| 122 |
-
predictor_dropout: 0.5
|
| 123 |
-
predictor_grad: 0.1
|
| 124 |
-
predictor_hidden: -1
|
| 125 |
-
predictor_kernel: 5
|
| 126 |
-
predictor_layers: 5
|
| 127 |
-
prenet_dropout: 0.5
|
| 128 |
-
prenet_hidden_size: 256
|
| 129 |
-
pretrain_fs_ckpt: pretrain/nyaru/model_ckpt_steps_60000.ckpt
|
| 130 |
-
processed_data_dir: xxx
|
| 131 |
-
profile_infer: false
|
| 132 |
-
raw_data_dir: data/raw/atri
|
| 133 |
-
ref_norm_layer: bn
|
| 134 |
-
rel_pos: true
|
| 135 |
-
reset_phone_dict: true
|
| 136 |
-
residual_channels: 256
|
| 137 |
-
residual_layers: 20
|
| 138 |
-
save_best: false
|
| 139 |
-
save_ckpt: true
|
| 140 |
-
save_codes:
|
| 141 |
-
- configs
|
| 142 |
-
- modules
|
| 143 |
-
- src
|
| 144 |
-
- utils
|
| 145 |
-
save_f0: true
|
| 146 |
-
save_gt: false
|
| 147 |
-
schedule_type: linear
|
| 148 |
-
seed: 1234
|
| 149 |
-
sort_by_len: true
|
| 150 |
-
speaker_id: atri
|
| 151 |
-
spec_max:
|
| 152 |
-
- 0.2987259328365326
|
| 153 |
-
- 0.29721200466156006
|
| 154 |
-
- 0.23978209495544434
|
| 155 |
-
- 0.208412766456604
|
| 156 |
-
- 0.25777050852775574
|
| 157 |
-
- 0.2514476478099823
|
| 158 |
-
- 0.1129382848739624
|
| 159 |
-
- 0.03415697440505028
|
| 160 |
-
- 0.09860049188137054
|
| 161 |
-
- 0.10637332499027252
|
| 162 |
-
- 0.13287633657455444
|
| 163 |
-
- 0.19744250178337097
|
| 164 |
-
- 0.10040587931871414
|
| 165 |
-
- 0.13735432922840118
|
| 166 |
-
- 0.15107455849647522
|
| 167 |
-
- 0.17196381092071533
|
| 168 |
-
- 0.08298977464437485
|
| 169 |
-
- 0.0632769986987114
|
| 170 |
-
- 0.02723858878016472
|
| 171 |
-
- -0.001819317927584052
|
| 172 |
-
- -0.029565516859292984
|
| 173 |
-
- -0.023574354127049446
|
| 174 |
-
- -0.01633293740451336
|
| 175 |
-
- 0.07143621146678925
|
| 176 |
-
- 0.021580500528216362
|
| 177 |
-
- 0.07257916033267975
|
| 178 |
-
- -0.024349519982933998
|
| 179 |
-
- -0.06165708228945732
|
| 180 |
-
- -0.10486568510532379
|
| 181 |
-
- -0.1363687664270401
|
| 182 |
-
- -0.13333871960639954
|
| 183 |
-
- -0.13955898582935333
|
| 184 |
-
- -0.16613495349884033
|
| 185 |
-
- -0.17636367678642273
|
| 186 |
-
- -0.2786925733089447
|
| 187 |
-
- -0.22967253625392914
|
| 188 |
-
- -0.31897130608558655
|
| 189 |
-
- -0.18007366359233856
|
| 190 |
-
- -0.29366692900657654
|
| 191 |
-
- -0.2871025800704956
|
| 192 |
-
- -0.36748355627059937
|
| 193 |
-
- -0.46071451902389526
|
| 194 |
-
- -0.5464922189712524
|
| 195 |
-
- -0.5719417333602905
|
| 196 |
-
- -0.6020897626876831
|
| 197 |
-
- -0.6239874958992004
|
| 198 |
-
- -0.5653440952301025
|
| 199 |
-
- -0.6508013606071472
|
| 200 |
-
- -0.628247857093811
|
| 201 |
-
- -0.6809687614440918
|
| 202 |
-
- -0.569259762763977
|
| 203 |
-
- -0.5423558354377747
|
| 204 |
-
- -0.5811785459518433
|
| 205 |
-
- -0.5359002351760864
|
| 206 |
-
- -0.6565515398979187
|
| 207 |
-
- -0.7143737077713013
|
| 208 |
-
- -0.8502675890922546
|
| 209 |
-
- -0.7979224920272827
|
| 210 |
-
- -0.7110578417778015
|
| 211 |
-
- -0.763409435749054
|
| 212 |
-
- -0.7984790802001953
|
| 213 |
-
- -0.6927220821380615
|
| 214 |
-
- -0.658117413520813
|
| 215 |
-
- -0.7486468553543091
|
| 216 |
-
- -0.5949879884719849
|
| 217 |
-
- -0.7494576573371887
|
| 218 |
-
- -0.7400822639465332
|
| 219 |
-
- -0.6822793483734131
|
| 220 |
-
- -0.7773582339286804
|
| 221 |
-
- -0.661201536655426
|
| 222 |
-
- -0.791329026222229
|
| 223 |
-
- -0.8982341885566711
|
| 224 |
-
- -0.8736728429794312
|
| 225 |
-
- -0.7701027393341064
|
| 226 |
-
- -0.8490535616874695
|
| 227 |
-
- -0.7479292154312134
|
| 228 |
-
- -0.9320166110992432
|
| 229 |
-
- -1.2862414121627808
|
| 230 |
-
- -2.8936190605163574
|
| 231 |
-
- -2.924229860305786
|
| 232 |
-
spec_min:
|
| 233 |
-
- -6.0
|
| 234 |
-
- -6.0
|
| 235 |
-
- -6.0
|
| 236 |
-
- -6.0
|
| 237 |
-
- -6.0
|
| 238 |
-
- -6.0
|
| 239 |
-
- -6.0
|
| 240 |
-
- -6.0
|
| 241 |
-
- -6.0
|
| 242 |
-
- -6.0
|
| 243 |
-
- -6.0
|
| 244 |
-
- -6.0
|
| 245 |
-
- -6.0
|
| 246 |
-
- -6.0
|
| 247 |
-
- -6.0
|
| 248 |
-
- -6.0
|
| 249 |
-
- -6.0
|
| 250 |
-
- -6.0
|
| 251 |
-
- -6.0
|
| 252 |
-
- -6.0
|
| 253 |
-
- -6.0
|
| 254 |
-
- -6.0
|
| 255 |
-
- -6.0
|
| 256 |
-
- -6.0
|
| 257 |
-
- -6.0
|
| 258 |
-
- -6.0
|
| 259 |
-
- -6.0
|
| 260 |
-
- -6.0
|
| 261 |
-
- -6.0
|
| 262 |
-
- -6.0
|
| 263 |
-
- -6.0
|
| 264 |
-
- -6.0
|
| 265 |
-
- -6.0
|
| 266 |
-
- -6.0
|
| 267 |
-
- -6.0
|
| 268 |
-
- -6.0
|
| 269 |
-
- -6.0
|
| 270 |
-
- -6.0
|
| 271 |
-
- -6.0
|
| 272 |
-
- -6.0
|
| 273 |
-
- -6.0
|
| 274 |
-
- -6.0
|
| 275 |
-
- -6.0
|
| 276 |
-
- -6.0
|
| 277 |
-
- -6.0
|
| 278 |
-
- -6.0
|
| 279 |
-
- -6.0
|
| 280 |
-
- -6.0
|
| 281 |
-
- -6.0
|
| 282 |
-
- -6.0
|
| 283 |
-
- -6.0
|
| 284 |
-
- -6.0
|
| 285 |
-
- -6.0
|
| 286 |
-
- -6.0
|
| 287 |
-
- -6.0
|
| 288 |
-
- -6.0
|
| 289 |
-
- -6.0
|
| 290 |
-
- -6.0
|
| 291 |
-
- -6.0
|
| 292 |
-
- -6.0
|
| 293 |
-
- -6.0
|
| 294 |
-
- -6.0
|
| 295 |
-
- -6.0
|
| 296 |
-
- -6.0
|
| 297 |
-
- -6.0
|
| 298 |
-
- -6.0
|
| 299 |
-
- -6.0
|
| 300 |
-
- -5.999454021453857
|
| 301 |
-
- -5.8822431564331055
|
| 302 |
-
- -5.892064571380615
|
| 303 |
-
- -5.882402420043945
|
| 304 |
-
- -5.786972522735596
|
| 305 |
-
- -5.746835231781006
|
| 306 |
-
- -5.8594512939453125
|
| 307 |
-
- -5.7389445304870605
|
| 308 |
-
- -5.718059539794922
|
| 309 |
-
- -5.779720306396484
|
| 310 |
-
- -5.801984786987305
|
| 311 |
-
- -6.0
|
| 312 |
-
- -6.0
|
| 313 |
-
spk_cond_steps: []
|
| 314 |
-
stop_token_weight: 5.0
|
| 315 |
-
task_cls: training.task.SVC_task.SVCTask
|
| 316 |
-
test_ids: []
|
| 317 |
-
test_input_dir: ''
|
| 318 |
-
test_num: 0
|
| 319 |
-
test_prefixes:
|
| 320 |
-
- test
|
| 321 |
-
test_set_name: test
|
| 322 |
-
timesteps: 1000
|
| 323 |
-
train_set_name: train
|
| 324 |
-
use_crepe: true
|
| 325 |
-
use_denoise: false
|
| 326 |
-
use_energy_embed: false
|
| 327 |
-
use_gt_dur: false
|
| 328 |
-
use_gt_f0: false
|
| 329 |
-
use_midi: false
|
| 330 |
-
use_nsf: true
|
| 331 |
-
use_pitch_embed: true
|
| 332 |
-
use_pos_embed: true
|
| 333 |
-
use_spk_embed: false
|
| 334 |
-
use_spk_id: false
|
| 335 |
-
use_split_spk_id: false
|
| 336 |
-
use_uv: false
|
| 337 |
-
use_var_enc: false
|
| 338 |
-
use_vec: false
|
| 339 |
-
val_check_interval: 2000
|
| 340 |
-
valid_num: 0
|
| 341 |
-
valid_set_name: valid
|
| 342 |
-
vocoder: network.vocoders.hifigan.HifiGAN
|
| 343 |
-
vocoder_ckpt: checkpoints/0109_hifigan_bigpopcs_hop128
|
| 344 |
-
warmup_updates: 2000
|
| 345 |
-
wav2spec_eps: 1e-6
|
| 346 |
-
weight_decay: 0
|
| 347 |
-
win_size: 512
|
| 348 |
-
work_dir: checkpoints/atri
|
| 349 |
-
no_fs2: false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
training/config_nsf.yaml
DELETED
|
@@ -1,445 +0,0 @@
|
|
| 1 |
-
K_step: 1000
|
| 2 |
-
accumulate_grad_batches: 1
|
| 3 |
-
audio_num_mel_bins: 128
|
| 4 |
-
audio_sample_rate: 44100
|
| 5 |
-
binarization_args:
|
| 6 |
-
shuffle: false
|
| 7 |
-
with_align: true
|
| 8 |
-
with_f0: true
|
| 9 |
-
with_hubert: true
|
| 10 |
-
with_spk_embed: false
|
| 11 |
-
with_wav: false
|
| 12 |
-
binarizer_cls: preprocessing.SVCpre.SVCBinarizer
|
| 13 |
-
binary_data_dir: data/binary/Meiko
|
| 14 |
-
check_val_every_n_epoch: 10
|
| 15 |
-
choose_test_manually: false
|
| 16 |
-
clip_grad_norm: 1
|
| 17 |
-
config_path: training/config_nsf.yaml
|
| 18 |
-
content_cond_steps: []
|
| 19 |
-
cwt_add_f0_loss: false
|
| 20 |
-
cwt_hidden_size: 128
|
| 21 |
-
cwt_layers: 2
|
| 22 |
-
cwt_loss: l1
|
| 23 |
-
cwt_std_scale: 0.8
|
| 24 |
-
datasets:
|
| 25 |
-
- opencpop
|
| 26 |
-
debug: false
|
| 27 |
-
dec_ffn_kernel_size: 9
|
| 28 |
-
dec_layers: 4
|
| 29 |
-
decay_steps: 50000
|
| 30 |
-
decoder_type: fft
|
| 31 |
-
dict_dir: ''
|
| 32 |
-
diff_decoder_type: wavenet
|
| 33 |
-
diff_loss_type: l2
|
| 34 |
-
dilation_cycle_length: 4
|
| 35 |
-
dropout: 0.1
|
| 36 |
-
ds_workers: 4
|
| 37 |
-
dur_enc_hidden_stride_kernel:
|
| 38 |
-
- 0,2,3
|
| 39 |
-
- 0,2,3
|
| 40 |
-
- 0,1,3
|
| 41 |
-
dur_loss: mse
|
| 42 |
-
dur_predictor_kernel: 3
|
| 43 |
-
dur_predictor_layers: 5
|
| 44 |
-
enc_ffn_kernel_size: 9
|
| 45 |
-
enc_layers: 4
|
| 46 |
-
encoder_K: 8
|
| 47 |
-
encoder_type: fft
|
| 48 |
-
endless_ds: false
|
| 49 |
-
f0_bin: 256
|
| 50 |
-
f0_max: 1100.0
|
| 51 |
-
f0_min: 40.0
|
| 52 |
-
ffn_act: gelu
|
| 53 |
-
ffn_padding: SAME
|
| 54 |
-
fft_size: 2048
|
| 55 |
-
fmax: 16000
|
| 56 |
-
fmin: 40
|
| 57 |
-
fs2_ckpt: ''
|
| 58 |
-
gaussian_start: true
|
| 59 |
-
gen_dir_name: ''
|
| 60 |
-
gen_tgt_spk_id: -1
|
| 61 |
-
hidden_size: 256
|
| 62 |
-
hop_size: 512
|
| 63 |
-
hubert_gpu: true
|
| 64 |
-
hubert_path: checkpoints/hubert/hubert_soft.pt
|
| 65 |
-
infer: false
|
| 66 |
-
keep_bins: 128
|
| 67 |
-
lambda_commit: 0.25
|
| 68 |
-
lambda_energy: 0.0
|
| 69 |
-
lambda_f0: 1.0
|
| 70 |
-
lambda_ph_dur: 0.3
|
| 71 |
-
lambda_sent_dur: 1.0
|
| 72 |
-
lambda_uv: 1.0
|
| 73 |
-
lambda_word_dur: 1.0
|
| 74 |
-
load_ckpt: ''
|
| 75 |
-
log_interval: 100
|
| 76 |
-
loud_norm: false
|
| 77 |
-
lr: 0.0006
|
| 78 |
-
max_beta: 0.02
|
| 79 |
-
max_epochs: 3000
|
| 80 |
-
max_eval_sentences: 1
|
| 81 |
-
max_eval_tokens: 60000
|
| 82 |
-
max_frames: 42000
|
| 83 |
-
max_input_tokens: 60000
|
| 84 |
-
max_sentences: 11
|
| 85 |
-
max_tokens: 128000
|
| 86 |
-
max_updates: 1000000
|
| 87 |
-
mel_loss: ssim:0.5|l1:0.5
|
| 88 |
-
mel_vmax: 1.5
|
| 89 |
-
mel_vmin: -6.0
|
| 90 |
-
min_level_db: -120
|
| 91 |
-
no_fs2: true
|
| 92 |
-
norm_type: gn
|
| 93 |
-
num_ckpt_keep: 10
|
| 94 |
-
num_heads: 2
|
| 95 |
-
num_sanity_val_steps: 1
|
| 96 |
-
num_spk: 1
|
| 97 |
-
num_test_samples: 0
|
| 98 |
-
num_valid_plots: 10
|
| 99 |
-
optimizer_adam_beta1: 0.9
|
| 100 |
-
optimizer_adam_beta2: 0.98
|
| 101 |
-
out_wav_norm: false
|
| 102 |
-
pe_ckpt: checkpoints/0102_xiaoma_pe/model_ckpt_steps_60000.ckpt
|
| 103 |
-
pe_enable: false
|
| 104 |
-
perform_enhance: true
|
| 105 |
-
pitch_ar: false
|
| 106 |
-
pitch_enc_hidden_stride_kernel:
|
| 107 |
-
- 0,2,5
|
| 108 |
-
- 0,2,5
|
| 109 |
-
- 0,2,5
|
| 110 |
-
pitch_extractor: parselmouth
|
| 111 |
-
pitch_loss: l2
|
| 112 |
-
pitch_norm: log
|
| 113 |
-
pitch_type: frame
|
| 114 |
-
pndm_speedup: 10
|
| 115 |
-
pre_align_args:
|
| 116 |
-
allow_no_txt: false
|
| 117 |
-
denoise: false
|
| 118 |
-
forced_align: mfa
|
| 119 |
-
txt_processor: zh_g2pM
|
| 120 |
-
use_sox: true
|
| 121 |
-
use_tone: false
|
| 122 |
-
pre_align_cls: data_gen.singing.pre_align.SingingPreAlign
|
| 123 |
-
predictor_dropout: 0.5
|
| 124 |
-
predictor_grad: 0.1
|
| 125 |
-
predictor_hidden: -1
|
| 126 |
-
predictor_kernel: 5
|
| 127 |
-
predictor_layers: 5
|
| 128 |
-
prenet_dropout: 0.5
|
| 129 |
-
prenet_hidden_size: 256
|
| 130 |
-
pretrain_fs_ckpt: ''
|
| 131 |
-
processed_data_dir: xxx
|
| 132 |
-
profile_infer: false
|
| 133 |
-
raw_data_dir: data/raw/Meiko
|
| 134 |
-
ref_norm_layer: bn
|
| 135 |
-
rel_pos: true
|
| 136 |
-
reset_phone_dict: true
|
| 137 |
-
residual_channels: 384
|
| 138 |
-
residual_layers: 20
|
| 139 |
-
save_best: true
|
| 140 |
-
save_ckpt: true
|
| 141 |
-
save_codes:
|
| 142 |
-
- configs
|
| 143 |
-
- modules
|
| 144 |
-
- src
|
| 145 |
-
- utils
|
| 146 |
-
save_f0: true
|
| 147 |
-
save_gt: false
|
| 148 |
-
schedule_type: linear
|
| 149 |
-
seed: 1234
|
| 150 |
-
sort_by_len: true
|
| 151 |
-
speaker_id: Meiko
|
| 152 |
-
spec_max:
|
| 153 |
-
- 0.11616316437721252
|
| 154 |
-
- 0.009597139433026314
|
| 155 |
-
- 0.28568679094314575
|
| 156 |
-
- 0.5713539123535156
|
| 157 |
-
- 0.6507775187492371
|
| 158 |
-
- 0.6846900582313538
|
| 159 |
-
- 0.7684511542320251
|
| 160 |
-
- 0.7574314475059509
|
| 161 |
-
- 0.7267094254493713
|
| 162 |
-
- 0.8298212289810181
|
| 163 |
-
- 0.6814215183258057
|
| 164 |
-
- 0.7774385213851929
|
| 165 |
-
- 0.7883802056312561
|
| 166 |
-
- 0.7771736979484558
|
| 167 |
-
- 0.7607403993606567
|
| 168 |
-
- 0.8505979180335999
|
| 169 |
-
- 0.7654092311859131
|
| 170 |
-
- 0.7792922258377075
|
| 171 |
-
- 0.814899206161499
|
| 172 |
-
- 0.8058286905288696
|
| 173 |
-
- 0.839918851852417
|
| 174 |
-
- 0.8406909108161926
|
| 175 |
-
- 0.8339935541152954
|
| 176 |
-
- 0.9287465810775757
|
| 177 |
-
- 0.8166532516479492
|
| 178 |
-
- 0.8449192047119141
|
| 179 |
-
- 0.7643511891365051
|
| 180 |
-
- 0.8175668716430664
|
| 181 |
-
- 1.0239852666854858
|
| 182 |
-
- 0.920753002166748
|
| 183 |
-
- 0.8153243660926819
|
| 184 |
-
- 0.7587951421737671
|
| 185 |
-
- 0.7698416113853455
|
| 186 |
-
- 0.7247377634048462
|
| 187 |
-
- 0.6954795122146606
|
| 188 |
-
- 0.6807010173797607
|
| 189 |
-
- 0.8715915679931641
|
| 190 |
-
- 0.8993064761161804
|
| 191 |
-
- 0.90997314453125
|
| 192 |
-
- 0.7913641333580017
|
| 193 |
-
- 0.7065826058387756
|
| 194 |
-
- 0.6068118810653687
|
| 195 |
-
- 0.6278789639472961
|
| 196 |
-
- 0.6242763996124268
|
| 197 |
-
- 0.5978773236274719
|
| 198 |
-
- 0.651780366897583
|
| 199 |
-
- 0.7780635952949524
|
| 200 |
-
- 0.7565146684646606
|
| 201 |
-
- 0.5729265213012695
|
| 202 |
-
- 0.5707721710205078
|
| 203 |
-
- 0.5281876921653748
|
| 204 |
-
- 0.5579817891120911
|
| 205 |
-
- 0.6407540440559387
|
| 206 |
-
- 0.7233482003211975
|
| 207 |
-
- 0.5677092671394348
|
| 208 |
-
- 0.40926626324653625
|
| 209 |
-
- 0.4460923373699188
|
| 210 |
-
- 0.4058813750743866
|
| 211 |
-
- 0.4390961229801178
|
| 212 |
-
- 0.5553078055381775
|
| 213 |
-
- 0.5349165201187134
|
| 214 |
-
- 0.43830350041389465
|
| 215 |
-
- 0.4032619595527649
|
| 216 |
-
- 0.3253237009048462
|
| 217 |
-
- 0.30613574385643005
|
| 218 |
-
- 0.44174280762672424
|
| 219 |
-
- 0.3622792959213257
|
| 220 |
-
- 0.45337533950805664
|
| 221 |
-
- 0.3313130736351013
|
| 222 |
-
- 0.36956584453582764
|
| 223 |
-
- 0.4998202919960022
|
| 224 |
-
- 0.42133796215057373
|
| 225 |
-
- 0.28050243854522705
|
| 226 |
-
- 0.26571735739707947
|
| 227 |
-
- 0.20871540904045105
|
| 228 |
-
- 0.3416949510574341
|
| 229 |
-
- 0.3328045904636383
|
| 230 |
-
- 0.332925409078598
|
| 231 |
-
- 0.3000032603740692
|
| 232 |
-
- 0.08743463456630707
|
| 233 |
-
- 0.20726755261421204
|
| 234 |
-
- 0.1583203673362732
|
| 235 |
-
- 0.13275942206382751
|
| 236 |
-
- 0.066913902759552
|
| 237 |
-
- 0.1054723709821701
|
| 238 |
-
- -0.08983375877141953
|
| 239 |
-
- -0.12505969405174255
|
| 240 |
-
- -0.03509913384914398
|
| 241 |
-
- -0.11556489020586014
|
| 242 |
-
- -0.2324075847864151
|
| 243 |
-
- -0.06187695264816284
|
| 244 |
-
- 0.020108096301555634
|
| 245 |
-
- -0.009129349142313004
|
| 246 |
-
- -0.044059865176677704
|
| 247 |
-
- 0.0343453511595726
|
| 248 |
-
- 0.030609752982854843
|
| 249 |
-
- 0.11592991650104523
|
| 250 |
-
- 0.04611678794026375
|
| 251 |
-
- 0.016514429822564125
|
| 252 |
-
- -0.10608740150928497
|
| 253 |
-
- -0.18119606375694275
|
| 254 |
-
- -0.0764162689447403
|
| 255 |
-
- -0.005786585621535778
|
| 256 |
-
- -0.16699059307575226
|
| 257 |
-
- -0.1254500299692154
|
| 258 |
-
- -0.09370455145835876
|
| 259 |
-
- 0.015143157914280891
|
| 260 |
-
- 0.07289116084575653
|
| 261 |
-
- -0.006812357809394598
|
| 262 |
-
- -0.0280735082924366
|
| 263 |
-
- -0.0021705669350922108
|
| 264 |
-
- -0.1115487739443779
|
| 265 |
-
- -0.2423458993434906
|
| 266 |
-
- -0.116642065346241
|
| 267 |
-
- -0.1487213373184204
|
| 268 |
-
- -0.16707029938697815
|
| 269 |
-
- -0.25437667965888977
|
| 270 |
-
- -0.32499101758003235
|
| 271 |
-
- -0.2704009413719177
|
| 272 |
-
- -0.29621294140815735
|
| 273 |
-
- -0.42674311995506287
|
| 274 |
-
- -0.4650932848453522
|
| 275 |
-
- -0.5842434763908386
|
| 276 |
-
- -0.6859109401702881
|
| 277 |
-
- -0.9532108902931213
|
| 278 |
-
- -0.9863560199737549
|
| 279 |
-
- -1.220953106880188
|
| 280 |
-
- -1.3163429498672485
|
| 281 |
-
spec_min:
|
| 282 |
-
- -4.999994277954102
|
| 283 |
-
- -4.999994277954102
|
| 284 |
-
- -4.999994277954102
|
| 285 |
-
- -4.999994277954102
|
| 286 |
-
- -4.999994277954102
|
| 287 |
-
- -4.999994277954102
|
| 288 |
-
- -4.999994277954102
|
| 289 |
-
- -4.999994277954102
|
| 290 |
-
- -4.999994277954102
|
| 291 |
-
- -4.999994277954102
|
| 292 |
-
- -4.999994277954102
|
| 293 |
-
- -4.999994277954102
|
| 294 |
-
- -4.999994277954102
|
| 295 |
-
- -4.999994277954102
|
| 296 |
-
- -4.999994277954102
|
| 297 |
-
- -4.999994277954102
|
| 298 |
-
- -4.999994277954102
|
| 299 |
-
- -4.999994277954102
|
| 300 |
-
- -4.999994277954102
|
| 301 |
-
- -4.999994277954102
|
| 302 |
-
- -4.999994277954102
|
| 303 |
-
- -4.999994277954102
|
| 304 |
-
- -4.999994277954102
|
| 305 |
-
- -4.999994277954102
|
| 306 |
-
- -4.999994277954102
|
| 307 |
-
- -4.999994277954102
|
| 308 |
-
- -4.999994277954102
|
| 309 |
-
- -4.999994277954102
|
| 310 |
-
- -4.999994277954102
|
| 311 |
-
- -4.999994277954102
|
| 312 |
-
- -4.999994277954102
|
| 313 |
-
- -4.999994277954102
|
| 314 |
-
- -4.999994277954102
|
| 315 |
-
- -4.999994277954102
|
| 316 |
-
- -4.999994277954102
|
| 317 |
-
- -4.999994277954102
|
| 318 |
-
- -4.999994277954102
|
| 319 |
-
- -4.999994277954102
|
| 320 |
-
- -4.999994277954102
|
| 321 |
-
- -4.999994277954102
|
| 322 |
-
- -4.999994277954102
|
| 323 |
-
- -4.999994277954102
|
| 324 |
-
- -4.999994277954102
|
| 325 |
-
- -4.999994277954102
|
| 326 |
-
- -4.999994277954102
|
| 327 |
-
- -4.999994277954102
|
| 328 |
-
- -4.999994277954102
|
| 329 |
-
- -4.999994277954102
|
| 330 |
-
- -4.999994277954102
|
| 331 |
-
- -4.999994277954102
|
| 332 |
-
- -4.999994277954102
|
| 333 |
-
- -4.999994277954102
|
| 334 |
-
- -4.999994277954102
|
| 335 |
-
- -4.999994277954102
|
| 336 |
-
- -4.999994277954102
|
| 337 |
-
- -4.999994277954102
|
| 338 |
-
- -4.999994277954102
|
| 339 |
-
- -4.999994277954102
|
| 340 |
-
- -4.999994277954102
|
| 341 |
-
- -4.999994277954102
|
| 342 |
-
- -4.999994277954102
|
| 343 |
-
- -4.999994277954102
|
| 344 |
-
- -4.999994277954102
|
| 345 |
-
- -4.999994277954102
|
| 346 |
-
- -4.999994277954102
|
| 347 |
-
- -4.999994277954102
|
| 348 |
-
- -4.999994277954102
|
| 349 |
-
- -4.999994277954102
|
| 350 |
-
- -4.999994277954102
|
| 351 |
-
- -4.999994277954102
|
| 352 |
-
- -4.999994277954102
|
| 353 |
-
- -4.999994277954102
|
| 354 |
-
- -4.999994277954102
|
| 355 |
-
- -4.999994277954102
|
| 356 |
-
- -4.999994277954102
|
| 357 |
-
- -4.999994277954102
|
| 358 |
-
- -4.999994277954102
|
| 359 |
-
- -4.999994277954102
|
| 360 |
-
- -4.999994277954102
|
| 361 |
-
- -4.999994277954102
|
| 362 |
-
- -4.999994277954102
|
| 363 |
-
- -4.999994277954102
|
| 364 |
-
- -4.999994277954102
|
| 365 |
-
- -4.999994277954102
|
| 366 |
-
- -4.999994277954102
|
| 367 |
-
- -4.999994277954102
|
| 368 |
-
- -4.999994277954102
|
| 369 |
-
- -4.999994277954102
|
| 370 |
-
- -4.999994277954102
|
| 371 |
-
- -4.999994277954102
|
| 372 |
-
- -4.999994277954102
|
| 373 |
-
- -4.999994277954102
|
| 374 |
-
- -4.999994277954102
|
| 375 |
-
- -4.999994277954102
|
| 376 |
-
- -4.999994277954102
|
| 377 |
-
- -4.999994277954102
|
| 378 |
-
- -4.999994277954102
|
| 379 |
-
- -4.999994277954102
|
| 380 |
-
- -4.999994277954102
|
| 381 |
-
- -4.999994277954102
|
| 382 |
-
- -4.999994277954102
|
| 383 |
-
- -4.999994277954102
|
| 384 |
-
- -4.999994277954102
|
| 385 |
-
- -4.999994277954102
|
| 386 |
-
- -4.999994277954102
|
| 387 |
-
- -4.999994277954102
|
| 388 |
-
- -4.999994277954102
|
| 389 |
-
- -4.999994277954102
|
| 390 |
-
- -4.999994277954102
|
| 391 |
-
- -4.999994277954102
|
| 392 |
-
- -4.999994277954102
|
| 393 |
-
- -4.999994277954102
|
| 394 |
-
- -4.999994277954102
|
| 395 |
-
- -4.999994277954102
|
| 396 |
-
- -4.999994277954102
|
| 397 |
-
- -4.999994277954102
|
| 398 |
-
- -4.999994277954102
|
| 399 |
-
- -4.999994277954102
|
| 400 |
-
- -4.999994277954102
|
| 401 |
-
- -4.999994277954102
|
| 402 |
-
- -4.999994277954102
|
| 403 |
-
- -4.999994277954102
|
| 404 |
-
- -4.999994277954102
|
| 405 |
-
- -4.942144870758057
|
| 406 |
-
- -4.772783279418945
|
| 407 |
-
- -4.7206244468688965
|
| 408 |
-
- -4.5759992599487305
|
| 409 |
-
- -4.509932518005371
|
| 410 |
-
spk_cond_steps: []
|
| 411 |
-
stop_token_weight: 5.0
|
| 412 |
-
task_cls: training.task.SVC_task.SVCTask
|
| 413 |
-
test_ids: []
|
| 414 |
-
test_input_dir: ''
|
| 415 |
-
test_num: 0
|
| 416 |
-
test_prefixes:
|
| 417 |
-
- test
|
| 418 |
-
test_set_name: test
|
| 419 |
-
timesteps: 1000
|
| 420 |
-
train_set_name: train
|
| 421 |
-
use_crepe: false
|
| 422 |
-
use_denoise: false
|
| 423 |
-
use_energy_embed: false
|
| 424 |
-
use_gt_dur: false
|
| 425 |
-
use_gt_f0: false
|
| 426 |
-
use_midi: false
|
| 427 |
-
use_nsf: true
|
| 428 |
-
use_pitch_embed: true
|
| 429 |
-
use_pos_embed: true
|
| 430 |
-
use_spk_embed: false
|
| 431 |
-
use_spk_id: false
|
| 432 |
-
use_split_spk_id: false
|
| 433 |
-
use_uv: false
|
| 434 |
-
use_var_enc: false
|
| 435 |
-
use_vec: false
|
| 436 |
-
val_check_interval: 1000
|
| 437 |
-
valid_num: 0
|
| 438 |
-
valid_set_name: valid
|
| 439 |
-
vocoder: network.vocoders.nsf_hifigan.NsfHifiGAN
|
| 440 |
-
vocoder_ckpt: checkpoints/nsf_hifigan/model
|
| 441 |
-
warmup_updates: 2000
|
| 442 |
-
wav2spec_eps: 1e-6
|
| 443 |
-
weight_decay: 0
|
| 444 |
-
win_size: 2048
|
| 445 |
-
work_dir: checkpoints/Meiko
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
training/dataset/__pycache__/base_dataset.cpython-38.pyc
DELETED
|
Binary file (2.79 kB)
|
|
|
training/dataset/__pycache__/fs2_utils.cpython-38.pyc
DELETED
|
Binary file (6.71 kB)
|
|
|
training/dataset/base_dataset.py
DELETED
|
@@ -1,66 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
from utils.hparams import hparams
|
| 3 |
-
import numpy as np
|
| 4 |
-
import os
|
| 5 |
-
|
| 6 |
-
class BaseDataset(torch.utils.data.Dataset):
|
| 7 |
-
'''
|
| 8 |
-
Base class for datasets.
|
| 9 |
-
1. *ordered_indices*:
|
| 10 |
-
if self.shuffle == True, shuffle the indices;
|
| 11 |
-
if self.sort_by_len == True, sort data by length;
|
| 12 |
-
2. *sizes*:
|
| 13 |
-
clipped length if "max_frames" is set;
|
| 14 |
-
3. *num_tokens*:
|
| 15 |
-
unclipped length.
|
| 16 |
-
|
| 17 |
-
Subclasses should define:
|
| 18 |
-
1. *collate*:
|
| 19 |
-
take the longest data, pad other data to the same length;
|
| 20 |
-
2. *__getitem__*:
|
| 21 |
-
the index function.
|
| 22 |
-
'''
|
| 23 |
-
def __init__(self, shuffle):
|
| 24 |
-
super().__init__()
|
| 25 |
-
self.hparams = hparams
|
| 26 |
-
self.shuffle = shuffle
|
| 27 |
-
self.sort_by_len = hparams['sort_by_len']
|
| 28 |
-
self.sizes = None
|
| 29 |
-
|
| 30 |
-
@property
|
| 31 |
-
def _sizes(self):
|
| 32 |
-
return self.sizes
|
| 33 |
-
|
| 34 |
-
def __getitem__(self, index):
|
| 35 |
-
raise NotImplementedError
|
| 36 |
-
|
| 37 |
-
def collater(self, samples):
|
| 38 |
-
raise NotImplementedError
|
| 39 |
-
|
| 40 |
-
def __len__(self):
|
| 41 |
-
return len(self._sizes)
|
| 42 |
-
|
| 43 |
-
def num_tokens(self, index):
|
| 44 |
-
return self.size(index)
|
| 45 |
-
|
| 46 |
-
def size(self, index):
|
| 47 |
-
"""Return an example's size as a float or tuple. This value is used when
|
| 48 |
-
filtering a dataset with ``--max-positions``."""
|
| 49 |
-
size = min(self._sizes[index], hparams['max_frames'])
|
| 50 |
-
return size
|
| 51 |
-
|
| 52 |
-
def ordered_indices(self):
|
| 53 |
-
"""Return an ordered list of indices. Batches will be constructed based
|
| 54 |
-
on this order."""
|
| 55 |
-
if self.shuffle:
|
| 56 |
-
indices = np.random.permutation(len(self))
|
| 57 |
-
if self.sort_by_len:
|
| 58 |
-
indices = indices[np.argsort(np.array(self._sizes)[indices], kind='mergesort')]
|
| 59 |
-
# 先random, 然后稳定排序, 保证排序后同长度的数据顺序是依照random permutation的 (被其随机打乱).
|
| 60 |
-
else:
|
| 61 |
-
indices = np.arange(len(self))
|
| 62 |
-
return indices
|
| 63 |
-
|
| 64 |
-
@property
|
| 65 |
-
def num_workers(self):
|
| 66 |
-
return int(os.getenv('NUM_WORKERS', hparams['ds_workers']))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
training/dataset/fs2_utils.py
DELETED
|
@@ -1,178 +0,0 @@
|
|
| 1 |
-
import matplotlib
|
| 2 |
-
|
| 3 |
-
matplotlib.use('Agg')
|
| 4 |
-
|
| 5 |
-
import glob
|
| 6 |
-
import importlib
|
| 7 |
-
from utils.cwt import get_lf0_cwt
|
| 8 |
-
import os
|
| 9 |
-
import torch.optim
|
| 10 |
-
import torch.utils.data
|
| 11 |
-
from utils.indexed_datasets import IndexedDataset
|
| 12 |
-
from utils.pitch_utils import norm_interp_f0
|
| 13 |
-
import numpy as np
|
| 14 |
-
from training.dataset.base_dataset import BaseDataset
|
| 15 |
-
import torch
|
| 16 |
-
import torch.optim
|
| 17 |
-
import torch.utils.data
|
| 18 |
-
import utils
|
| 19 |
-
import torch.distributions
|
| 20 |
-
from utils.hparams import hparams
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
class FastSpeechDataset(BaseDataset):
|
| 24 |
-
def __init__(self, prefix, shuffle=False):
|
| 25 |
-
super().__init__(shuffle)
|
| 26 |
-
self.data_dir = hparams['binary_data_dir']
|
| 27 |
-
self.prefix = prefix
|
| 28 |
-
self.hparams = hparams
|
| 29 |
-
self.sizes = np.load(f'{self.data_dir}/{self.prefix}_lengths.npy')
|
| 30 |
-
self.indexed_ds = None
|
| 31 |
-
# self.name2spk_id={}
|
| 32 |
-
|
| 33 |
-
# pitch stats
|
| 34 |
-
f0_stats_fn = f'{self.data_dir}/train_f0s_mean_std.npy'
|
| 35 |
-
if os.path.exists(f0_stats_fn):
|
| 36 |
-
hparams['f0_mean'], hparams['f0_std'] = self.f0_mean, self.f0_std = np.load(f0_stats_fn)
|
| 37 |
-
hparams['f0_mean'] = float(hparams['f0_mean'])
|
| 38 |
-
hparams['f0_std'] = float(hparams['f0_std'])
|
| 39 |
-
else:
|
| 40 |
-
hparams['f0_mean'], hparams['f0_std'] = self.f0_mean, self.f0_std = None, None
|
| 41 |
-
|
| 42 |
-
if prefix == 'test':
|
| 43 |
-
if hparams['test_input_dir'] != '':
|
| 44 |
-
self.indexed_ds, self.sizes = self.load_test_inputs(hparams['test_input_dir'])
|
| 45 |
-
else:
|
| 46 |
-
if hparams['num_test_samples'] > 0:
|
| 47 |
-
self.avail_idxs = list(range(hparams['num_test_samples'])) + hparams['test_ids']
|
| 48 |
-
self.sizes = [self.sizes[i] for i in self.avail_idxs]
|
| 49 |
-
|
| 50 |
-
if hparams['pitch_type'] == 'cwt':
|
| 51 |
-
_, hparams['cwt_scales'] = get_lf0_cwt(np.ones(10))
|
| 52 |
-
|
| 53 |
-
def _get_item(self, index):
|
| 54 |
-
if hasattr(self, 'avail_idxs') and self.avail_idxs is not None:
|
| 55 |
-
index = self.avail_idxs[index]
|
| 56 |
-
if self.indexed_ds is None:
|
| 57 |
-
self.indexed_ds = IndexedDataset(f'{self.data_dir}/{self.prefix}')
|
| 58 |
-
return self.indexed_ds[index]
|
| 59 |
-
|
| 60 |
-
def __getitem__(self, index):
|
| 61 |
-
hparams = self.hparams
|
| 62 |
-
item = self._get_item(index)
|
| 63 |
-
max_frames = hparams['max_frames']
|
| 64 |
-
spec = torch.Tensor(item['mel'])[:max_frames]
|
| 65 |
-
energy = (spec.exp() ** 2).sum(-1).sqrt()
|
| 66 |
-
mel2ph = torch.LongTensor(item['mel2ph'])[:max_frames] if 'mel2ph' in item else None
|
| 67 |
-
f0, uv = norm_interp_f0(item["f0"][:max_frames], hparams)
|
| 68 |
-
#phone = torch.LongTensor(item['phone'][:hparams['max_input_tokens']])
|
| 69 |
-
hubert=torch.Tensor(item['hubert'][:hparams['max_input_tokens']])
|
| 70 |
-
pitch = torch.LongTensor(item.get("pitch"))[:max_frames]
|
| 71 |
-
# print(item.keys(), item['mel'].shape, spec.shape)
|
| 72 |
-
sample = {
|
| 73 |
-
"id": index,
|
| 74 |
-
"item_name": item['item_name'],
|
| 75 |
-
# "text": item['txt'],
|
| 76 |
-
# "txt_token": phone,
|
| 77 |
-
"hubert":hubert,
|
| 78 |
-
"mel": spec,
|
| 79 |
-
"pitch": pitch,
|
| 80 |
-
"energy": energy,
|
| 81 |
-
"f0": f0,
|
| 82 |
-
"uv": uv,
|
| 83 |
-
"mel2ph": mel2ph,
|
| 84 |
-
"mel_nonpadding": spec.abs().sum(-1) > 0,
|
| 85 |
-
}
|
| 86 |
-
if self.hparams['use_spk_embed']:
|
| 87 |
-
sample["spk_embed"] = torch.Tensor(item['spk_embed'])
|
| 88 |
-
if self.hparams['use_spk_id']:
|
| 89 |
-
sample["spk_id"] = item['spk_id']
|
| 90 |
-
# sample['spk_id'] = 0
|
| 91 |
-
# for key in self.name2spk_id.keys():
|
| 92 |
-
# if key in item['item_name']:
|
| 93 |
-
# sample['spk_id'] = self.name2spk_id[key]
|
| 94 |
-
# break
|
| 95 |
-
#======not used==========
|
| 96 |
-
# if self.hparams['pitch_type'] == 'cwt':
|
| 97 |
-
# cwt_spec = torch.Tensor(item['cwt_spec'])[:max_frames]
|
| 98 |
-
# f0_mean = item.get('f0_mean', item.get('cwt_mean'))
|
| 99 |
-
# f0_std = item.get('f0_std', item.get('cwt_std'))
|
| 100 |
-
# sample.update({"cwt_spec": cwt_spec, "f0_mean": f0_mean, "f0_std": f0_std})
|
| 101 |
-
# elif self.hparams['pitch_type'] == 'ph':
|
| 102 |
-
# f0_phlevel_sum = torch.zeros_like(phone).float().scatter_add(0, mel2ph - 1, f0)
|
| 103 |
-
# f0_phlevel_num = torch.zeros_like(phone).float().scatter_add(
|
| 104 |
-
# 0, mel2ph - 1, torch.ones_like(f0)).clamp_min(1)
|
| 105 |
-
# sample["f0_ph"] = f0_phlevel_sum / f0_phlevel_num
|
| 106 |
-
return sample
|
| 107 |
-
|
| 108 |
-
def collater(self, samples):
|
| 109 |
-
if len(samples) == 0:
|
| 110 |
-
return {}
|
| 111 |
-
id = torch.LongTensor([s['id'] for s in samples])
|
| 112 |
-
item_names = [s['item_name'] for s in samples]
|
| 113 |
-
text = [s['text'] for s in samples]
|
| 114 |
-
txt_tokens = utils.collate_1d([s['txt_token'] for s in samples], 0)
|
| 115 |
-
f0 = utils.collate_1d([s['f0'] for s in samples], 0.0)
|
| 116 |
-
pitch = utils.collate_1d([s['pitch'] for s in samples],1)
|
| 117 |
-
uv = utils.collate_1d([s['uv'] for s in samples])
|
| 118 |
-
energy = utils.collate_1d([s['energy'] for s in samples], 0.0)
|
| 119 |
-
mel2ph = utils.collate_1d([s['mel2ph'] for s in samples], 0.0) \
|
| 120 |
-
if samples[0]['mel2ph'] is not None else None
|
| 121 |
-
mels = utils.collate_2d([s['mel'] for s in samples], 0.0)
|
| 122 |
-
txt_lengths = torch.LongTensor([s['txt_token'].numel() for s in samples])
|
| 123 |
-
mel_lengths = torch.LongTensor([s['mel'].shape[0] for s in samples])
|
| 124 |
-
|
| 125 |
-
batch = {
|
| 126 |
-
'id': id,
|
| 127 |
-
'item_name': item_names,
|
| 128 |
-
'nsamples': len(samples),
|
| 129 |
-
'text': text,
|
| 130 |
-
'txt_tokens': txt_tokens,
|
| 131 |
-
'txt_lengths': txt_lengths,
|
| 132 |
-
'mels': mels,
|
| 133 |
-
'mel_lengths': mel_lengths,
|
| 134 |
-
'mel2ph': mel2ph,
|
| 135 |
-
'energy': energy,
|
| 136 |
-
'pitch': pitch,
|
| 137 |
-
'f0': f0,
|
| 138 |
-
'uv': uv,
|
| 139 |
-
}
|
| 140 |
-
|
| 141 |
-
if self.hparams['use_spk_embed']:
|
| 142 |
-
spk_embed = torch.stack([s['spk_embed'] for s in samples])
|
| 143 |
-
batch['spk_embed'] = spk_embed
|
| 144 |
-
if self.hparams['use_spk_id']:
|
| 145 |
-
spk_ids = torch.LongTensor([s['spk_id'] for s in samples])
|
| 146 |
-
batch['spk_ids'] = spk_ids
|
| 147 |
-
if self.hparams['pitch_type'] == 'cwt':
|
| 148 |
-
cwt_spec = utils.collate_2d([s['cwt_spec'] for s in samples])
|
| 149 |
-
f0_mean = torch.Tensor([s['f0_mean'] for s in samples])
|
| 150 |
-
f0_std = torch.Tensor([s['f0_std'] for s in samples])
|
| 151 |
-
batch.update({'cwt_spec': cwt_spec, 'f0_mean': f0_mean, 'f0_std': f0_std})
|
| 152 |
-
elif self.hparams['pitch_type'] == 'ph':
|
| 153 |
-
batch['f0'] = utils.collate_1d([s['f0_ph'] for s in samples])
|
| 154 |
-
|
| 155 |
-
return batch
|
| 156 |
-
|
| 157 |
-
def load_test_inputs(self, test_input_dir, spk_id=0):
|
| 158 |
-
inp_wav_paths = glob.glob(f'{test_input_dir}/*.wav') + glob.glob(f'{test_input_dir}/*.mp3')
|
| 159 |
-
sizes = []
|
| 160 |
-
items = []
|
| 161 |
-
|
| 162 |
-
binarizer_cls = hparams.get("binarizer_cls", 'basics.base_binarizer.BaseBinarizer')
|
| 163 |
-
pkg = ".".join(binarizer_cls.split(".")[:-1])
|
| 164 |
-
cls_name = binarizer_cls.split(".")[-1]
|
| 165 |
-
binarizer_cls = getattr(importlib.import_module(pkg), cls_name)
|
| 166 |
-
binarization_args = hparams['binarization_args']
|
| 167 |
-
from preprocessing.hubertinfer import Hubertencoder
|
| 168 |
-
for wav_fn in inp_wav_paths:
|
| 169 |
-
item_name = os.path.basename(wav_fn)
|
| 170 |
-
ph = txt = tg_fn = ''
|
| 171 |
-
wav_fn = wav_fn
|
| 172 |
-
encoder = Hubertencoder(hparams['hubert_path'])
|
| 173 |
-
|
| 174 |
-
item = binarizer_cls.process_item(item_name, {'wav_fn':wav_fn}, encoder, binarization_args)
|
| 175 |
-
print(item)
|
| 176 |
-
items.append(item)
|
| 177 |
-
sizes.append(item['len'])
|
| 178 |
-
return items, sizes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
training/from huggingface_hub import Repository.py
DELETED
|
@@ -1,2 +0,0 @@
|
|
| 1 |
-
from huggingface_hub import Repository
|
| 2 |
-
repo = Repository(local_dir="w2v2", clone_from="facebook/wav2vec2-large-960h-lv60")
|
|
|
|
|
|
|
|
|
training/pe.py
DELETED
|
@@ -1,155 +0,0 @@
|
|
| 1 |
-
import matplotlib
|
| 2 |
-
matplotlib.use('Agg')
|
| 3 |
-
|
| 4 |
-
import torch
|
| 5 |
-
import numpy as np
|
| 6 |
-
import os
|
| 7 |
-
|
| 8 |
-
from training.dataset.base_dataset import BaseDataset
|
| 9 |
-
from training.task.fs2 import FastSpeech2Task
|
| 10 |
-
from modules.fastspeech.pe import PitchExtractor
|
| 11 |
-
import utils
|
| 12 |
-
from utils.indexed_datasets import IndexedDataset
|
| 13 |
-
from utils.hparams import hparams
|
| 14 |
-
from utils.plot import f0_to_figure
|
| 15 |
-
from utils.pitch_utils import norm_interp_f0, denorm_f0
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
class PeDataset(BaseDataset):
|
| 19 |
-
def __init__(self, prefix, shuffle=False):
|
| 20 |
-
super().__init__(shuffle)
|
| 21 |
-
self.data_dir = hparams['binary_data_dir']
|
| 22 |
-
self.prefix = prefix
|
| 23 |
-
self.hparams = hparams
|
| 24 |
-
self.sizes = np.load(f'{self.data_dir}/{self.prefix}_lengths.npy')
|
| 25 |
-
self.indexed_ds = None
|
| 26 |
-
|
| 27 |
-
# pitch stats
|
| 28 |
-
f0_stats_fn = f'{self.data_dir}/train_f0s_mean_std.npy'
|
| 29 |
-
if os.path.exists(f0_stats_fn):
|
| 30 |
-
hparams['f0_mean'], hparams['f0_std'] = self.f0_mean, self.f0_std = np.load(f0_stats_fn)
|
| 31 |
-
hparams['f0_mean'] = float(hparams['f0_mean'])
|
| 32 |
-
hparams['f0_std'] = float(hparams['f0_std'])
|
| 33 |
-
else:
|
| 34 |
-
hparams['f0_mean'], hparams['f0_std'] = self.f0_mean, self.f0_std = None, None
|
| 35 |
-
|
| 36 |
-
if prefix == 'test':
|
| 37 |
-
if hparams['num_test_samples'] > 0:
|
| 38 |
-
self.avail_idxs = list(range(hparams['num_test_samples'])) + hparams['test_ids']
|
| 39 |
-
self.sizes = [self.sizes[i] for i in self.avail_idxs]
|
| 40 |
-
|
| 41 |
-
def _get_item(self, index):
|
| 42 |
-
if hasattr(self, 'avail_idxs') and self.avail_idxs is not None:
|
| 43 |
-
index = self.avail_idxs[index]
|
| 44 |
-
if self.indexed_ds is None:
|
| 45 |
-
self.indexed_ds = IndexedDataset(f'{self.data_dir}/{self.prefix}')
|
| 46 |
-
return self.indexed_ds[index]
|
| 47 |
-
|
| 48 |
-
def __getitem__(self, index):
|
| 49 |
-
hparams = self.hparams
|
| 50 |
-
item = self._get_item(index)
|
| 51 |
-
max_frames = hparams['max_frames']
|
| 52 |
-
spec = torch.Tensor(item['mel'])[:max_frames]
|
| 53 |
-
# mel2ph = torch.LongTensor(item['mel2ph'])[:max_frames] if 'mel2ph' in item else None
|
| 54 |
-
f0, uv = norm_interp_f0(item["f0"][:max_frames], hparams)
|
| 55 |
-
pitch = torch.LongTensor(item.get("pitch"))[:max_frames]
|
| 56 |
-
# print(item.keys(), item['mel'].shape, spec.shape)
|
| 57 |
-
sample = {
|
| 58 |
-
"id": index,
|
| 59 |
-
"item_name": item['item_name'],
|
| 60 |
-
"text": item['txt'],
|
| 61 |
-
"mel": spec,
|
| 62 |
-
"pitch": pitch,
|
| 63 |
-
"f0": f0,
|
| 64 |
-
"uv": uv,
|
| 65 |
-
# "mel2ph": mel2ph,
|
| 66 |
-
# "mel_nonpadding": spec.abs().sum(-1) > 0,
|
| 67 |
-
}
|
| 68 |
-
return sample
|
| 69 |
-
|
| 70 |
-
def collater(self, samples):
|
| 71 |
-
if len(samples) == 0:
|
| 72 |
-
return {}
|
| 73 |
-
id = torch.LongTensor([s['id'] for s in samples])
|
| 74 |
-
item_names = [s['item_name'] for s in samples]
|
| 75 |
-
text = [s['text'] for s in samples]
|
| 76 |
-
f0 = utils.collate_1d([s['f0'] for s in samples], 0.0)
|
| 77 |
-
pitch = utils.collate_1d([s['pitch'] for s in samples])
|
| 78 |
-
uv = utils.collate_1d([s['uv'] for s in samples])
|
| 79 |
-
mels = utils.collate_2d([s['mel'] for s in samples], 0.0)
|
| 80 |
-
mel_lengths = torch.LongTensor([s['mel'].shape[0] for s in samples])
|
| 81 |
-
# mel2ph = utils.collate_1d([s['mel2ph'] for s in samples], 0.0) \
|
| 82 |
-
# if samples[0]['mel2ph'] is not None else None
|
| 83 |
-
# mel_nonpaddings = utils.collate_1d([s['mel_nonpadding'].float() for s in samples], 0.0)
|
| 84 |
-
|
| 85 |
-
batch = {
|
| 86 |
-
'id': id,
|
| 87 |
-
'item_name': item_names,
|
| 88 |
-
'nsamples': len(samples),
|
| 89 |
-
'text': text,
|
| 90 |
-
'mels': mels,
|
| 91 |
-
'mel_lengths': mel_lengths,
|
| 92 |
-
'pitch': pitch,
|
| 93 |
-
# 'mel2ph': mel2ph,
|
| 94 |
-
# 'mel_nonpaddings': mel_nonpaddings,
|
| 95 |
-
'f0': f0,
|
| 96 |
-
'uv': uv,
|
| 97 |
-
}
|
| 98 |
-
return batch
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
class PitchExtractionTask(FastSpeech2Task):
|
| 102 |
-
def __init__(self):
|
| 103 |
-
super().__init__()
|
| 104 |
-
self.dataset_cls = PeDataset
|
| 105 |
-
|
| 106 |
-
def build_tts_model(self):
|
| 107 |
-
self.model = PitchExtractor(conv_layers=hparams['pitch_extractor_conv_layers'])
|
| 108 |
-
|
| 109 |
-
# def build_scheduler(self, optimizer):
|
| 110 |
-
# return torch.optim.lr_scheduler.StepLR(optimizer, hparams['decay_steps'], gamma=0.5)
|
| 111 |
-
def _training_step(self, sample, batch_idx, _):
|
| 112 |
-
loss_output = self.run_model(self.model, sample)
|
| 113 |
-
total_loss = sum([v for v in loss_output.values() if isinstance(v, torch.Tensor) and v.requires_grad])
|
| 114 |
-
loss_output['batch_size'] = sample['mels'].size()[0]
|
| 115 |
-
return total_loss, loss_output
|
| 116 |
-
|
| 117 |
-
def validation_step(self, sample, batch_idx):
|
| 118 |
-
outputs = {}
|
| 119 |
-
outputs['losses'] = {}
|
| 120 |
-
outputs['losses'], model_out = self.run_model(self.model, sample, return_output=True, infer=True)
|
| 121 |
-
outputs['total_loss'] = sum(outputs['losses'].values())
|
| 122 |
-
outputs['nsamples'] = sample['nsamples']
|
| 123 |
-
outputs = utils.tensors_to_scalars(outputs)
|
| 124 |
-
if batch_idx < hparams['num_valid_plots']:
|
| 125 |
-
self.plot_pitch(batch_idx, model_out, sample)
|
| 126 |
-
return outputs
|
| 127 |
-
|
| 128 |
-
def run_model(self, model, sample, return_output=False, infer=False):
|
| 129 |
-
f0 = sample['f0']
|
| 130 |
-
uv = sample['uv']
|
| 131 |
-
output = model(sample['mels'])
|
| 132 |
-
losses = {}
|
| 133 |
-
self.add_pitch_loss(output, sample, losses)
|
| 134 |
-
if not return_output:
|
| 135 |
-
return losses
|
| 136 |
-
else:
|
| 137 |
-
return losses, output
|
| 138 |
-
|
| 139 |
-
def plot_pitch(self, batch_idx, model_out, sample):
|
| 140 |
-
gt_f0 = denorm_f0(sample['f0'], sample['uv'], hparams)
|
| 141 |
-
self.logger.experiment.add_figure(
|
| 142 |
-
f'f0_{batch_idx}',
|
| 143 |
-
f0_to_figure(gt_f0[0], None, model_out['f0_denorm_pred'][0]),
|
| 144 |
-
self.global_step)
|
| 145 |
-
|
| 146 |
-
def add_pitch_loss(self, output, sample, losses):
|
| 147 |
-
# mel2ph = sample['mel2ph'] # [B, T_s]
|
| 148 |
-
mel = sample['mels']
|
| 149 |
-
f0 = sample['f0']
|
| 150 |
-
uv = sample['uv']
|
| 151 |
-
# nonpadding = (mel2ph != 0).float() if hparams['pitch_type'] == 'frame' \
|
| 152 |
-
# else (sample['txt_tokens'] != 0).float()
|
| 153 |
-
nonpadding = (mel.abs().sum(-1) > 0).float() # sample['mel_nonpaddings']
|
| 154 |
-
# print(nonpadding[0][-8:], nonpadding.shape)
|
| 155 |
-
self.add_f0_loss(output['pitch_pred'], f0, uv, losses, nonpadding=nonpadding)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
training/rgsdgsd.py
DELETED
|
@@ -1,107 +0,0 @@
|
|
| 1 |
-
import pygame
|
| 2 |
-
import mido
|
| 3 |
-
from gtts import gTTS
|
| 4 |
-
from pygame.locals import MOUSEBUTTONDOWN, KEYDOWN, K_RETURN
|
| 5 |
-
import time
|
| 6 |
-
|
| 7 |
-
# Initialize the click count and the time of the last click
|
| 8 |
-
click_count = 0
|
| 9 |
-
last_click_time = 0
|
| 10 |
-
|
| 11 |
-
# Initialize Pygame and create a window for the MIDI editor
|
| 12 |
-
pygame.init()
|
| 13 |
-
screen = pygame.display.set_mode((640, 480))
|
| 14 |
-
|
| 15 |
-
class MidiNote:
|
| 16 |
-
def __init__(self, note, velocity, time, x, y, width, height):
|
| 17 |
-
self.note = note
|
| 18 |
-
self.velocity = velocity
|
| 19 |
-
self.time = time
|
| 20 |
-
self.x = x
|
| 21 |
-
self.y = y
|
| 22 |
-
self.width = width
|
| 23 |
-
self.height = height
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
# Create a new MIDI file
|
| 27 |
-
mid = mido.MidiFile()
|
| 28 |
-
|
| 29 |
-
# Create a new MIDI track
|
| 30 |
-
track = mido.MidiTrack()
|
| 31 |
-
|
| 32 |
-
# Add the MIDI track to the file
|
| 33 |
-
mid.tracks.append(track)
|
| 34 |
-
|
| 35 |
-
# Create a function to add lyrics to a specific MIDI note
|
| 36 |
-
def add_lyrics(note, lyrics):
|
| 37 |
-
# Add the lyrics to the MIDI note
|
| 38 |
-
note.text = lyrics
|
| 39 |
-
# Update the MIDI file with the new lyrics
|
| 40 |
-
mid.save("song.mid")
|
| 41 |
-
|
| 42 |
-
# Create a function to get the MIDI note that was clicked on
|
| 43 |
-
def get_clicked_note(pos):
|
| 44 |
-
# Iterate through the MIDI notes in the file
|
| 45 |
-
for track in mid.tracks:
|
| 46 |
-
for note in track:
|
| 47 |
-
if isinstance(note, mido.Message):
|
| 48 |
-
# Check if the mouse position is within the bounds of the MIDI note
|
| 49 |
-
if pos[0] > note.x and pos[0] < note.x + note.width:
|
| 50 |
-
if pos[1] > note.y and pos[1] < note.y + note.height:
|
| 51 |
-
return note
|
| 52 |
-
return None
|
| 53 |
-
|
| 54 |
-
# Create a function to convert the lyrics from Japanese to speech
|
| 55 |
-
def speak_lyrics(lyrics):
|
| 56 |
-
tts = gTTS(lyrics, lang='ja')
|
| 57 |
-
tts.save('lyrics.mp3')
|
| 58 |
-
pygame.mixer.music.load('lyrics.mp3')
|
| 59 |
-
pygame.mixer.music.play()
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
# Main loop
|
| 63 |
-
while True:
|
| 64 |
-
for event in pygame.event.get():
|
| 65 |
-
if event.type == MOUSEBUTTONDOWN:
|
| 66 |
-
# Increment the click count
|
| 67 |
-
click_count += 1
|
| 68 |
-
# Check if the user double-clicked on a MIDI note
|
| 69 |
-
if time.time() - last_click_time < 0.5:
|
| 70 |
-
# Get the MIDI note that was clicked on
|
| 71 |
-
note = get_clicked_note(event.pos)
|
| 72 |
-
# Add the lyrics to the MIDI note
|
| 73 |
-
add_lyrics(note, lyrics)
|
| 74 |
-
# Reset the click count
|
| 75 |
-
click_count = 0
|
| 76 |
-
# Update the time of the last click
|
| 77 |
-
last_click_time = time.time()
|
| 78 |
-
if event.type == KEYDOWN:
|
| 79 |
-
if event.key == K_RETURN:
|
| 80 |
-
# Get the lyrics from the input field
|
| 81 |
-
lyrics = input_field.get_text()
|
| 82 |
-
# Convert the lyrics to speech and play them
|
| 83 |
-
speak_lyrics(lyrics)
|
| 84 |
-
# If the click count is not reset, it means that the user has single-clicked
|
| 85 |
-
if click_count == 1:
|
| 86 |
-
# Get the position of the single click
|
| 87 |
-
pos = pygame.mouse.get_pos()
|
| 88 |
-
# Create a new MIDI note with the specified position and length
|
| 89 |
-
note = MidiNote(60, 64, 0, event.pos[0], event.pos[1], 100, 100)
|
| 90 |
-
note.x = pos[0]
|
| 91 |
-
note.y = pos[1]
|
| 92 |
-
note.width = 100
|
| 93 |
-
note.height = 100
|
| 94 |
-
# Add the MIDI note to the track
|
| 95 |
-
track.append(note)
|
| 96 |
-
mid.save("song.mid")
|
| 97 |
-
# Reset the click count
|
| 98 |
-
click_count = 0
|
| 99 |
-
lyrics = ""
|
| 100 |
-
|
| 101 |
-
input_field = pygame.font.Font(None, 32).render(lyrics, True, (0, 0, 0))
|
| 102 |
-
|
| 103 |
-
# Display the input field on the window
|
| 104 |
-
screen.blit(input_field, (10, 10))
|
| 105 |
-
pygame.display.flip()
|
| 106 |
-
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
training/song.mid
DELETED
|
Binary file (14 Bytes)
|
|
|
training/task/SVC_task.py
DELETED
|
@@ -1,223 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
|
| 3 |
-
import utils
|
| 4 |
-
from utils.hparams import hparams
|
| 5 |
-
from network.diff.net import DiffNet
|
| 6 |
-
from network.diff.diffusion import GaussianDiffusion, OfflineGaussianDiffusion
|
| 7 |
-
from training.task.fs2 import FastSpeech2Task
|
| 8 |
-
from network.vocoders.base_vocoder import get_vocoder_cls, BaseVocoder
|
| 9 |
-
from modules.fastspeech.tts_modules import mel2ph_to_dur
|
| 10 |
-
|
| 11 |
-
from network.diff.candidate_decoder import FFT
|
| 12 |
-
from utils.pitch_utils import denorm_f0
|
| 13 |
-
from training.dataset.fs2_utils import FastSpeechDataset
|
| 14 |
-
|
| 15 |
-
import numpy as np
|
| 16 |
-
import os
|
| 17 |
-
import torch.nn.functional as F
|
| 18 |
-
|
| 19 |
-
DIFF_DECODERS = {
|
| 20 |
-
'wavenet': lambda hp: DiffNet(hp['audio_num_mel_bins']),
|
| 21 |
-
'fft': lambda hp: FFT(
|
| 22 |
-
hp['hidden_size'], hp['dec_layers'], hp['dec_ffn_kernel_size'], hp['num_heads']),
|
| 23 |
-
}
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
class SVCDataset(FastSpeechDataset):
|
| 27 |
-
def collater(self, samples):
|
| 28 |
-
from preprocessing.process_pipeline import File2Batch
|
| 29 |
-
return File2Batch.processed_input2batch(samples)
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
class SVCTask(FastSpeech2Task):
|
| 33 |
-
def __init__(self):
|
| 34 |
-
super(SVCTask, self).__init__()
|
| 35 |
-
self.dataset_cls = SVCDataset
|
| 36 |
-
self.vocoder: BaseVocoder = get_vocoder_cls(hparams)()
|
| 37 |
-
|
| 38 |
-
def build_tts_model(self):
|
| 39 |
-
# import torch
|
| 40 |
-
# from tqdm import tqdm
|
| 41 |
-
# v_min = torch.ones([80]) * 100
|
| 42 |
-
# v_max = torch.ones([80]) * -100
|
| 43 |
-
# for i, ds in enumerate(tqdm(self.dataset_cls('train'))):
|
| 44 |
-
# v_max = torch.max(torch.max(ds['mel'].reshape(-1, 80), 0)[0], v_max)
|
| 45 |
-
# v_min = torch.min(torch.min(ds['mel'].reshape(-1, 80), 0)[0], v_min)
|
| 46 |
-
# if i % 100 == 0:
|
| 47 |
-
# print(i, v_min, v_max)
|
| 48 |
-
# print('final', v_min, v_max)
|
| 49 |
-
mel_bins = hparams['audio_num_mel_bins']
|
| 50 |
-
self.model = GaussianDiffusion(
|
| 51 |
-
phone_encoder=self.phone_encoder,
|
| 52 |
-
out_dims=mel_bins, denoise_fn=DIFF_DECODERS[hparams['diff_decoder_type']](hparams),
|
| 53 |
-
timesteps=hparams['timesteps'],
|
| 54 |
-
K_step=hparams['K_step'],
|
| 55 |
-
loss_type=hparams['diff_loss_type'],
|
| 56 |
-
spec_min=hparams['spec_min'], spec_max=hparams['spec_max'],
|
| 57 |
-
)
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
def build_optimizer(self, model):
|
| 61 |
-
self.optimizer = optimizer = torch.optim.AdamW(
|
| 62 |
-
filter(lambda p: p.requires_grad, model.parameters()),
|
| 63 |
-
lr=hparams['lr'],
|
| 64 |
-
betas=(hparams['optimizer_adam_beta1'], hparams['optimizer_adam_beta2']),
|
| 65 |
-
weight_decay=hparams['weight_decay'])
|
| 66 |
-
return optimizer
|
| 67 |
-
|
| 68 |
-
def run_model(self, model, sample, return_output=False, infer=False):
|
| 69 |
-
'''
|
| 70 |
-
steps:
|
| 71 |
-
1. run the full model, calc the main loss
|
| 72 |
-
2. calculate loss for dur_predictor, pitch_predictor, energy_predictor
|
| 73 |
-
'''
|
| 74 |
-
hubert = sample['hubert'] # [B, T_t,H]
|
| 75 |
-
target = sample['mels'] # [B, T_s, 80]
|
| 76 |
-
mel2ph = sample['mel2ph'] # [B, T_s]
|
| 77 |
-
f0 = sample['f0']
|
| 78 |
-
uv = sample['uv']
|
| 79 |
-
energy = sample['energy']
|
| 80 |
-
|
| 81 |
-
spk_embed = sample.get('spk_embed') if not hparams['use_spk_id'] else sample.get('spk_ids')
|
| 82 |
-
if hparams['pitch_type'] == 'cwt':
|
| 83 |
-
# NOTE: this part of script is *isolated* from other scripts, which means
|
| 84 |
-
# it may not be compatible with the current version.
|
| 85 |
-
pass
|
| 86 |
-
# cwt_spec = sample[f'cwt_spec']
|
| 87 |
-
# f0_mean = sample['f0_mean']
|
| 88 |
-
# f0_std = sample['f0_std']
|
| 89 |
-
# sample['f0_cwt'] = f0 = model.cwt2f0_norm(cwt_spec, f0_mean, f0_std, mel2ph)
|
| 90 |
-
|
| 91 |
-
# output == ret
|
| 92 |
-
# model == src.diff.diffusion.GaussianDiffusion
|
| 93 |
-
output = model(hubert, mel2ph=mel2ph, spk_embed=spk_embed,
|
| 94 |
-
ref_mels=target, f0=f0, uv=uv, energy=energy, infer=infer)
|
| 95 |
-
|
| 96 |
-
losses = {}
|
| 97 |
-
if 'diff_loss' in output:
|
| 98 |
-
losses['mel'] = output['diff_loss']
|
| 99 |
-
#self.add_dur_loss(output['dur'], mel2ph, txt_tokens, sample['word_boundary'], losses=losses)
|
| 100 |
-
# if hparams['use_pitch_embed']:
|
| 101 |
-
# self.add_pitch_loss(output, sample, losses)
|
| 102 |
-
# if hparams['use_energy_embed']:
|
| 103 |
-
# self.add_energy_loss(output['energy_pred'], energy, losses)
|
| 104 |
-
if not return_output:
|
| 105 |
-
return losses
|
| 106 |
-
else:
|
| 107 |
-
return losses, output
|
| 108 |
-
|
| 109 |
-
def _training_step(self, sample, batch_idx, _):
|
| 110 |
-
log_outputs = self.run_model(self.model, sample)
|
| 111 |
-
total_loss = sum([v for v in log_outputs.values() if isinstance(v, torch.Tensor) and v.requires_grad])
|
| 112 |
-
log_outputs['batch_size'] = sample['hubert'].size()[0]
|
| 113 |
-
log_outputs['lr'] = self.scheduler.get_lr()[0]
|
| 114 |
-
return total_loss, log_outputs
|
| 115 |
-
|
| 116 |
-
def build_scheduler(self, optimizer):
|
| 117 |
-
return torch.optim.lr_scheduler.StepLR(optimizer, hparams['decay_steps'], gamma=0.5)
|
| 118 |
-
|
| 119 |
-
def optimizer_step(self, epoch, batch_idx, optimizer, optimizer_idx):
|
| 120 |
-
if optimizer is None:
|
| 121 |
-
return
|
| 122 |
-
optimizer.step()
|
| 123 |
-
optimizer.zero_grad()
|
| 124 |
-
if self.scheduler is not None:
|
| 125 |
-
self.scheduler.step(self.global_step // hparams['accumulate_grad_batches'])
|
| 126 |
-
|
| 127 |
-
def validation_step(self, sample, batch_idx):
|
| 128 |
-
outputs = {}
|
| 129 |
-
hubert = sample['hubert'] # [B, T_t]
|
| 130 |
-
|
| 131 |
-
target = sample['mels'] # [B, T_s, 80]
|
| 132 |
-
energy = sample['energy']
|
| 133 |
-
# fs2_mel = sample['fs2_mels']
|
| 134 |
-
spk_embed = sample.get('spk_embed') if not hparams['use_spk_id'] else sample.get('spk_ids')
|
| 135 |
-
mel2ph = sample['mel2ph']
|
| 136 |
-
|
| 137 |
-
outputs['losses'] = {}
|
| 138 |
-
|
| 139 |
-
outputs['losses'], model_out = self.run_model(self.model, sample, return_output=True, infer=False)
|
| 140 |
-
|
| 141 |
-
outputs['total_loss'] = sum(outputs['losses'].values())
|
| 142 |
-
outputs['nsamples'] = sample['nsamples']
|
| 143 |
-
outputs = utils.tensors_to_scalars(outputs)
|
| 144 |
-
if batch_idx < hparams['num_valid_plots']:
|
| 145 |
-
model_out = self.model(
|
| 146 |
-
hubert, spk_embed=spk_embed, mel2ph=mel2ph, f0=sample['f0'], uv=sample['uv'], energy=energy, ref_mels=None, infer=True
|
| 147 |
-
)
|
| 148 |
-
|
| 149 |
-
if hparams.get('pe_enable') is not None and hparams['pe_enable']:
|
| 150 |
-
gt_f0 = self.pe(sample['mels'])['f0_denorm_pred'] # pe predict from GT mel
|
| 151 |
-
pred_f0 = self.pe(model_out['mel_out'])['f0_denorm_pred'] # pe predict from Pred mel
|
| 152 |
-
else:
|
| 153 |
-
gt_f0 = denorm_f0(sample['f0'], sample['uv'], hparams)
|
| 154 |
-
pred_f0 = model_out.get('f0_denorm')
|
| 155 |
-
self.plot_wav(batch_idx, sample['mels'], model_out['mel_out'], is_mel=True, gt_f0=gt_f0, f0=pred_f0)
|
| 156 |
-
self.plot_mel(batch_idx, sample['mels'], model_out['mel_out'], name=f'diffmel_{batch_idx}')
|
| 157 |
-
#self.plot_mel(batch_idx, sample['mels'], model_out['fs2_mel'], name=f'fs2mel_{batch_idx}')
|
| 158 |
-
if hparams['use_pitch_embed']:
|
| 159 |
-
self.plot_pitch(batch_idx, sample, model_out)
|
| 160 |
-
return outputs
|
| 161 |
-
|
| 162 |
-
def add_dur_loss(self, dur_pred, mel2ph, txt_tokens, wdb, losses=None):
|
| 163 |
-
"""
|
| 164 |
-
the effect of each loss component:
|
| 165 |
-
hparams['dur_loss'] : align each phoneme
|
| 166 |
-
hparams['lambda_word_dur']: align each word
|
| 167 |
-
hparams['lambda_sent_dur']: align each sentence
|
| 168 |
-
|
| 169 |
-
:param dur_pred: [B, T], float, log scale
|
| 170 |
-
:param mel2ph: [B, T]
|
| 171 |
-
:param txt_tokens: [B, T]
|
| 172 |
-
:param losses:
|
| 173 |
-
:return:
|
| 174 |
-
"""
|
| 175 |
-
B, T = txt_tokens.shape
|
| 176 |
-
nonpadding = (txt_tokens != 0).float()
|
| 177 |
-
dur_gt = mel2ph_to_dur(mel2ph, T).float() * nonpadding
|
| 178 |
-
is_sil = torch.zeros_like(txt_tokens).bool()
|
| 179 |
-
for p in self.sil_ph:
|
| 180 |
-
is_sil = is_sil | (txt_tokens == self.phone_encoder.encode(p)[0])
|
| 181 |
-
is_sil = is_sil.float() # [B, T_txt]
|
| 182 |
-
|
| 183 |
-
# phone duration loss
|
| 184 |
-
if hparams['dur_loss'] == 'mse':
|
| 185 |
-
losses['pdur'] = F.mse_loss(dur_pred, (dur_gt + 1).log(), reduction='none')
|
| 186 |
-
losses['pdur'] = (losses['pdur'] * nonpadding).sum() / nonpadding.sum()
|
| 187 |
-
losses['pdur'] = losses['pdur'] * hparams['lambda_ph_dur']
|
| 188 |
-
dur_pred = (dur_pred.exp() - 1).clamp(min=0)
|
| 189 |
-
else:
|
| 190 |
-
raise NotImplementedError
|
| 191 |
-
|
| 192 |
-
# use linear scale for sent and word duration
|
| 193 |
-
if hparams['lambda_word_dur'] > 0:
|
| 194 |
-
#idx = F.pad(wdb.cumsum(axis=1), (1, 0))[:, :-1]
|
| 195 |
-
idx = wdb.cumsum(axis=1)
|
| 196 |
-
# word_dur_g = dur_gt.new_zeros([B, idx.max() + 1]).scatter_(1, idx, midi_dur) # midi_dur can be implied by add gt-ph_dur
|
| 197 |
-
word_dur_p = dur_pred.new_zeros([B, idx.max() + 1]).scatter_add(1, idx, dur_pred)
|
| 198 |
-
word_dur_g = dur_gt.new_zeros([B, idx.max() + 1]).scatter_add(1, idx, dur_gt)
|
| 199 |
-
wdur_loss = F.mse_loss((word_dur_p + 1).log(), (word_dur_g + 1).log(), reduction='none')
|
| 200 |
-
word_nonpadding = (word_dur_g > 0).float()
|
| 201 |
-
wdur_loss = (wdur_loss * word_nonpadding).sum() / word_nonpadding.sum()
|
| 202 |
-
losses['wdur'] = wdur_loss * hparams['lambda_word_dur']
|
| 203 |
-
if hparams['lambda_sent_dur'] > 0:
|
| 204 |
-
sent_dur_p = dur_pred.sum(-1)
|
| 205 |
-
sent_dur_g = dur_gt.sum(-1)
|
| 206 |
-
sdur_loss = F.mse_loss((sent_dur_p + 1).log(), (sent_dur_g + 1).log(), reduction='mean')
|
| 207 |
-
losses['sdur'] = sdur_loss.mean() * hparams['lambda_sent_dur']
|
| 208 |
-
|
| 209 |
-
############
|
| 210 |
-
# validation plots
|
| 211 |
-
############
|
| 212 |
-
def plot_wav(self, batch_idx, gt_wav, wav_out, is_mel=False, gt_f0=None, f0=None, name=None):
|
| 213 |
-
gt_wav = gt_wav[0].cpu().numpy()
|
| 214 |
-
wav_out = wav_out[0].cpu().numpy()
|
| 215 |
-
gt_f0 = gt_f0[0].cpu().numpy()
|
| 216 |
-
f0 = f0[0].cpu().numpy()
|
| 217 |
-
if is_mel:
|
| 218 |
-
gt_wav = self.vocoder.spec2wav(gt_wav, f0=gt_f0)
|
| 219 |
-
wav_out = self.vocoder.spec2wav(wav_out, f0=f0)
|
| 220 |
-
self.logger.experiment.add_audio(f'gt_{batch_idx}', gt_wav, sample_rate=hparams['audio_sample_rate'], global_step=self.global_step)
|
| 221 |
-
self.logger.experiment.add_audio(f'wav_{batch_idx}', wav_out, sample_rate=hparams['audio_sample_rate'], global_step=self.global_step)
|
| 222 |
-
|
| 223 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
training/task/__pycache__/SVC_task.cpython-38.pyc
DELETED
|
Binary file (7.58 kB)
|
|
|
training/task/__pycache__/base_task.cpython-38.pyc
DELETED
|
Binary file (11.3 kB)
|
|
|
training/task/__pycache__/fs2.cpython-38.pyc
DELETED
|
Binary file (16.1 kB)
|
|
|
training/task/__pycache__/tts.cpython-38.pyc
DELETED
|
Binary file (4.48 kB)
|
|
|
training/task/base_task.py
DELETED
|
@@ -1,337 +0,0 @@
|
|
| 1 |
-
from datetime import datetime
|
| 2 |
-
import shutil
|
| 3 |
-
|
| 4 |
-
import matplotlib
|
| 5 |
-
|
| 6 |
-
matplotlib.use('Agg')
|
| 7 |
-
|
| 8 |
-
from utils.hparams import hparams, set_hparams
|
| 9 |
-
import random
|
| 10 |
-
import sys
|
| 11 |
-
import numpy as np
|
| 12 |
-
import torch.distributed as dist
|
| 13 |
-
from pytorch_lightning.loggers import TensorBoardLogger
|
| 14 |
-
from utils.pl_utils import LatestModelCheckpoint, BaseTrainer, data_loader, DDP
|
| 15 |
-
from torch import nn
|
| 16 |
-
import torch.utils.data
|
| 17 |
-
import utils
|
| 18 |
-
import logging
|
| 19 |
-
import os
|
| 20 |
-
|
| 21 |
-
torch.multiprocessing.set_sharing_strategy(os.getenv('TORCH_SHARE_STRATEGY', 'file_system'))
|
| 22 |
-
|
| 23 |
-
log_format = '%(asctime)s %(message)s'
|
| 24 |
-
logging.basicConfig(stream=sys.stdout, level=logging.INFO,
|
| 25 |
-
format=log_format, datefmt='%m/%d %I:%M:%S %p')
|
| 26 |
-
|
| 27 |
-
class BaseTask(nn.Module):
|
| 28 |
-
'''
|
| 29 |
-
Base class for training tasks.
|
| 30 |
-
1. *load_ckpt*:
|
| 31 |
-
load checkpoint;
|
| 32 |
-
2. *training_step*:
|
| 33 |
-
record and log the loss;
|
| 34 |
-
3. *optimizer_step*:
|
| 35 |
-
run backwards step;
|
| 36 |
-
4. *start*:
|
| 37 |
-
load training configs, backup code, log to tensorboard, start training;
|
| 38 |
-
5. *configure_ddp* and *init_ddp_connection*:
|
| 39 |
-
start parallel training.
|
| 40 |
-
|
| 41 |
-
Subclasses should define:
|
| 42 |
-
1. *build_model*, *build_optimizer*, *build_scheduler*:
|
| 43 |
-
how to build the model, the optimizer and the training scheduler;
|
| 44 |
-
2. *_training_step*:
|
| 45 |
-
one training step of the model;
|
| 46 |
-
3. *validation_end* and *_validation_end*:
|
| 47 |
-
postprocess the validation output.
|
| 48 |
-
'''
|
| 49 |
-
def __init__(self, *args, **kwargs):
|
| 50 |
-
# dataset configs
|
| 51 |
-
super(BaseTask, self).__init__(*args, **kwargs)
|
| 52 |
-
self.current_epoch = 0
|
| 53 |
-
self.global_step = 0
|
| 54 |
-
self.loaded_optimizer_states_dict = {}
|
| 55 |
-
self.trainer = None
|
| 56 |
-
self.logger = None
|
| 57 |
-
self.on_gpu = False
|
| 58 |
-
self.use_dp = False
|
| 59 |
-
self.use_ddp = False
|
| 60 |
-
self.example_input_array = None
|
| 61 |
-
|
| 62 |
-
self.max_tokens = hparams['max_tokens']
|
| 63 |
-
self.max_sentences = hparams['max_sentences']
|
| 64 |
-
self.max_eval_tokens = hparams['max_eval_tokens']
|
| 65 |
-
if self.max_eval_tokens == -1:
|
| 66 |
-
hparams['max_eval_tokens'] = self.max_eval_tokens = self.max_tokens
|
| 67 |
-
self.max_eval_sentences = hparams['max_eval_sentences']
|
| 68 |
-
if self.max_eval_sentences == -1:
|
| 69 |
-
hparams['max_eval_sentences'] = self.max_eval_sentences = self.max_sentences
|
| 70 |
-
|
| 71 |
-
self.model = None
|
| 72 |
-
self.training_losses_meter = None
|
| 73 |
-
|
| 74 |
-
###########
|
| 75 |
-
# Training, validation and testing
|
| 76 |
-
###########
|
| 77 |
-
def build_model(self):
|
| 78 |
-
raise NotImplementedError
|
| 79 |
-
|
| 80 |
-
def load_ckpt(self, ckpt_base_dir, current_model_name=None, model_name='model', force=True, strict=True):
|
| 81 |
-
# This function is updated on 2021.12.13
|
| 82 |
-
if current_model_name is None:
|
| 83 |
-
current_model_name = model_name
|
| 84 |
-
utils.load_ckpt(self.__getattr__(current_model_name), ckpt_base_dir, current_model_name, force, strict)
|
| 85 |
-
|
| 86 |
-
def on_epoch_start(self):
|
| 87 |
-
self.training_losses_meter = {'total_loss': utils.AvgrageMeter()}
|
| 88 |
-
|
| 89 |
-
def _training_step(self, sample, batch_idx, optimizer_idx):
|
| 90 |
-
"""
|
| 91 |
-
|
| 92 |
-
:param sample:
|
| 93 |
-
:param batch_idx:
|
| 94 |
-
:return: total loss: torch.Tensor, loss_log: dict
|
| 95 |
-
"""
|
| 96 |
-
raise NotImplementedError
|
| 97 |
-
|
| 98 |
-
def training_step(self, sample, batch_idx, optimizer_idx=-1):
|
| 99 |
-
loss_ret = self._training_step(sample, batch_idx, optimizer_idx)
|
| 100 |
-
self.opt_idx = optimizer_idx
|
| 101 |
-
if loss_ret is None:
|
| 102 |
-
return {'loss': None}
|
| 103 |
-
total_loss, log_outputs = loss_ret
|
| 104 |
-
log_outputs = utils.tensors_to_scalars(log_outputs)
|
| 105 |
-
for k, v in log_outputs.items():
|
| 106 |
-
if k not in self.training_losses_meter:
|
| 107 |
-
self.training_losses_meter[k] = utils.AvgrageMeter()
|
| 108 |
-
if not np.isnan(v):
|
| 109 |
-
self.training_losses_meter[k].update(v)
|
| 110 |
-
self.training_losses_meter['total_loss'].update(total_loss.item())
|
| 111 |
-
|
| 112 |
-
try:
|
| 113 |
-
log_outputs['lr'] = self.scheduler.get_lr()
|
| 114 |
-
if isinstance(log_outputs['lr'], list):
|
| 115 |
-
log_outputs['lr'] = log_outputs['lr'][0]
|
| 116 |
-
except:
|
| 117 |
-
pass
|
| 118 |
-
|
| 119 |
-
# log_outputs['all_loss'] = total_loss.item()
|
| 120 |
-
progress_bar_log = log_outputs
|
| 121 |
-
tb_log = {f'tr/{k}': v for k, v in log_outputs.items()}
|
| 122 |
-
return {
|
| 123 |
-
'loss': total_loss,
|
| 124 |
-
'progress_bar': progress_bar_log,
|
| 125 |
-
'log': tb_log
|
| 126 |
-
}
|
| 127 |
-
|
| 128 |
-
def optimizer_step(self, epoch, batch_idx, optimizer, optimizer_idx):
|
| 129 |
-
optimizer.step()
|
| 130 |
-
optimizer.zero_grad()
|
| 131 |
-
if self.scheduler is not None:
|
| 132 |
-
self.scheduler.step(self.global_step // hparams['accumulate_grad_batches'])
|
| 133 |
-
|
| 134 |
-
def on_epoch_end(self):
|
| 135 |
-
loss_outputs = {k: round(v.avg, 4) for k, v in self.training_losses_meter.items()}
|
| 136 |
-
print(f"\n==============\n "
|
| 137 |
-
f"Epoch {self.current_epoch} ended. Steps: {self.global_step}. {loss_outputs}"
|
| 138 |
-
f"\n==============\n")
|
| 139 |
-
|
| 140 |
-
def validation_step(self, sample, batch_idx):
|
| 141 |
-
"""
|
| 142 |
-
|
| 143 |
-
:param sample:
|
| 144 |
-
:param batch_idx:
|
| 145 |
-
:return: output: dict
|
| 146 |
-
"""
|
| 147 |
-
raise NotImplementedError
|
| 148 |
-
|
| 149 |
-
def _validation_end(self, outputs):
|
| 150 |
-
"""
|
| 151 |
-
|
| 152 |
-
:param outputs:
|
| 153 |
-
:return: loss_output: dict
|
| 154 |
-
"""
|
| 155 |
-
raise NotImplementedError
|
| 156 |
-
|
| 157 |
-
def validation_end(self, outputs):
|
| 158 |
-
loss_output = self._validation_end(outputs)
|
| 159 |
-
print(f"\n==============\n "
|
| 160 |
-
f"valid results: {loss_output}"
|
| 161 |
-
f"\n==============\n")
|
| 162 |
-
return {
|
| 163 |
-
'log': {f'val/{k}': v for k, v in loss_output.items()},
|
| 164 |
-
'val_loss': loss_output['total_loss']
|
| 165 |
-
}
|
| 166 |
-
|
| 167 |
-
def build_scheduler(self, optimizer):
|
| 168 |
-
raise NotImplementedError
|
| 169 |
-
|
| 170 |
-
def build_optimizer(self, model):
|
| 171 |
-
raise NotImplementedError
|
| 172 |
-
|
| 173 |
-
def configure_optimizers(self):
|
| 174 |
-
optm = self.build_optimizer(self.model)
|
| 175 |
-
self.scheduler = self.build_scheduler(optm)
|
| 176 |
-
return [optm]
|
| 177 |
-
|
| 178 |
-
def test_start(self):
|
| 179 |
-
pass
|
| 180 |
-
|
| 181 |
-
def test_step(self, sample, batch_idx):
|
| 182 |
-
return self.validation_step(sample, batch_idx)
|
| 183 |
-
|
| 184 |
-
def test_end(self, outputs):
|
| 185 |
-
return self.validation_end(outputs)
|
| 186 |
-
|
| 187 |
-
###########
|
| 188 |
-
# Running configuration
|
| 189 |
-
###########
|
| 190 |
-
|
| 191 |
-
@classmethod
|
| 192 |
-
def start(cls):
|
| 193 |
-
set_hparams()
|
| 194 |
-
os.environ['MASTER_PORT'] = str(random.randint(15000, 30000))
|
| 195 |
-
random.seed(hparams['seed'])
|
| 196 |
-
np.random.seed(hparams['seed'])
|
| 197 |
-
task = cls()
|
| 198 |
-
work_dir = hparams['work_dir']
|
| 199 |
-
trainer = BaseTrainer(checkpoint_callback=LatestModelCheckpoint(
|
| 200 |
-
filepath=work_dir,
|
| 201 |
-
verbose=True,
|
| 202 |
-
monitor='val_loss',
|
| 203 |
-
mode='min',
|
| 204 |
-
num_ckpt_keep=hparams['num_ckpt_keep'],
|
| 205 |
-
save_best=hparams['save_best'],
|
| 206 |
-
period=1 if hparams['save_ckpt'] else 100000
|
| 207 |
-
),
|
| 208 |
-
logger=TensorBoardLogger(
|
| 209 |
-
save_dir=work_dir,
|
| 210 |
-
name='lightning_logs',
|
| 211 |
-
version='lastest'
|
| 212 |
-
),
|
| 213 |
-
gradient_clip_val=hparams['clip_grad_norm'],
|
| 214 |
-
val_check_interval=hparams['val_check_interval'],
|
| 215 |
-
row_log_interval=hparams['log_interval'],
|
| 216 |
-
max_updates=hparams['max_updates'],
|
| 217 |
-
num_sanity_val_steps=hparams['num_sanity_val_steps'] if not hparams[
|
| 218 |
-
'validate'] else 10000,
|
| 219 |
-
accumulate_grad_batches=hparams['accumulate_grad_batches'])
|
| 220 |
-
if not hparams['infer']: # train
|
| 221 |
-
# copy_code = input(f'{hparams["save_codes"]} code backup? y/n: ') == 'y'
|
| 222 |
-
# copy_code = True # backup code every time
|
| 223 |
-
# if copy_code:
|
| 224 |
-
# t = datetime.now().strftime('%Y%m%d%H%M%S')
|
| 225 |
-
# code_dir = f'{work_dir}/codes/{t}'
|
| 226 |
-
# # TODO: test filesystem calls
|
| 227 |
-
# os.makedirs(code_dir, exist_ok=True)
|
| 228 |
-
# # subprocess.check_call(f'mkdir "{code_dir}"', shell=True)
|
| 229 |
-
# for c in hparams['save_codes']:
|
| 230 |
-
# shutil.copytree(c, code_dir, dirs_exist_ok=True)
|
| 231 |
-
# # subprocess.check_call(f'xcopy "{c}" "{code_dir}/" /s /e /y', shell=True)
|
| 232 |
-
# print(f"| Copied codes to {code_dir}.")
|
| 233 |
-
trainer.checkpoint_callback.task = task
|
| 234 |
-
trainer.fit(task)
|
| 235 |
-
else:
|
| 236 |
-
trainer.test(task)
|
| 237 |
-
|
| 238 |
-
def configure_ddp(self, model, device_ids):
|
| 239 |
-
model = DDP(
|
| 240 |
-
model,
|
| 241 |
-
device_ids=device_ids,
|
| 242 |
-
find_unused_parameters=True
|
| 243 |
-
)
|
| 244 |
-
if dist.get_rank() != 0 and not hparams['debug']:
|
| 245 |
-
sys.stdout = open(os.devnull, "w")
|
| 246 |
-
sys.stderr = open(os.devnull, "w")
|
| 247 |
-
random.seed(hparams['seed'])
|
| 248 |
-
np.random.seed(hparams['seed'])
|
| 249 |
-
return model
|
| 250 |
-
|
| 251 |
-
def training_end(self, *args, **kwargs):
|
| 252 |
-
return None
|
| 253 |
-
|
| 254 |
-
def init_ddp_connection(self, proc_rank, world_size):
|
| 255 |
-
set_hparams(print_hparams=False)
|
| 256 |
-
# guarantees unique ports across jobs from same grid search
|
| 257 |
-
default_port = 12910
|
| 258 |
-
# if user gave a port number, use that one instead
|
| 259 |
-
try:
|
| 260 |
-
default_port = os.environ['MASTER_PORT']
|
| 261 |
-
except Exception:
|
| 262 |
-
os.environ['MASTER_PORT'] = str(default_port)
|
| 263 |
-
|
| 264 |
-
# figure out the root node addr
|
| 265 |
-
root_node = '127.0.0.2'
|
| 266 |
-
root_node = self.trainer.resolve_root_node_address(root_node)
|
| 267 |
-
os.environ['MASTER_ADDR'] = root_node
|
| 268 |
-
dist.init_process_group('nccl', rank=proc_rank, world_size=world_size)
|
| 269 |
-
|
| 270 |
-
@data_loader
|
| 271 |
-
def train_dataloader(self):
|
| 272 |
-
return None
|
| 273 |
-
|
| 274 |
-
@data_loader
|
| 275 |
-
def test_dataloader(self):
|
| 276 |
-
return None
|
| 277 |
-
|
| 278 |
-
@data_loader
|
| 279 |
-
def val_dataloader(self):
|
| 280 |
-
return None
|
| 281 |
-
|
| 282 |
-
def on_load_checkpoint(self, checkpoint):
|
| 283 |
-
pass
|
| 284 |
-
|
| 285 |
-
def on_save_checkpoint(self, checkpoint):
|
| 286 |
-
pass
|
| 287 |
-
|
| 288 |
-
def on_sanity_check_start(self):
|
| 289 |
-
pass
|
| 290 |
-
|
| 291 |
-
def on_train_start(self):
|
| 292 |
-
pass
|
| 293 |
-
|
| 294 |
-
def on_train_end(self):
|
| 295 |
-
pass
|
| 296 |
-
|
| 297 |
-
def on_batch_start(self, batch):
|
| 298 |
-
pass
|
| 299 |
-
|
| 300 |
-
def on_batch_end(self):
|
| 301 |
-
pass
|
| 302 |
-
|
| 303 |
-
def on_pre_performance_check(self):
|
| 304 |
-
pass
|
| 305 |
-
|
| 306 |
-
def on_post_performance_check(self):
|
| 307 |
-
pass
|
| 308 |
-
|
| 309 |
-
def on_before_zero_grad(self, optimizer):
|
| 310 |
-
pass
|
| 311 |
-
|
| 312 |
-
def on_after_backward(self):
|
| 313 |
-
pass
|
| 314 |
-
|
| 315 |
-
def backward(self, loss, optimizer):
|
| 316 |
-
loss.backward()
|
| 317 |
-
|
| 318 |
-
def grad_norm(self, norm_type):
|
| 319 |
-
results = {}
|
| 320 |
-
total_norm = 0
|
| 321 |
-
for name, p in self.named_parameters():
|
| 322 |
-
if p.requires_grad:
|
| 323 |
-
try:
|
| 324 |
-
param_norm = p.grad.data.norm(norm_type)
|
| 325 |
-
total_norm += param_norm ** norm_type
|
| 326 |
-
norm = param_norm ** (1 / norm_type)
|
| 327 |
-
|
| 328 |
-
grad = round(norm.data.cpu().numpy().flatten()[0], 3)
|
| 329 |
-
results['grad_{}_norm_{}'.format(norm_type, name)] = grad
|
| 330 |
-
except Exception:
|
| 331 |
-
# this param had no grad
|
| 332 |
-
pass
|
| 333 |
-
|
| 334 |
-
total_norm = total_norm ** (1. / norm_type)
|
| 335 |
-
grad = round(total_norm.data.cpu().numpy().flatten()[0], 3)
|
| 336 |
-
results['grad_{}_norm_total'.format(norm_type)] = grad
|
| 337 |
-
return results
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
training/task/fs2.py
DELETED
|
@@ -1,539 +0,0 @@
|
|
| 1 |
-
import matplotlib
|
| 2 |
-
|
| 3 |
-
matplotlib.use('Agg')
|
| 4 |
-
|
| 5 |
-
from utils import audio
|
| 6 |
-
import matplotlib.pyplot as plt
|
| 7 |
-
from preprocessing.data_gen_utils import get_pitch_parselmouth
|
| 8 |
-
from training.dataset.fs2_utils import FastSpeechDataset
|
| 9 |
-
from utils.cwt import cwt2f0
|
| 10 |
-
from utils.pl_utils import data_loader
|
| 11 |
-
import os
|
| 12 |
-
from multiprocessing.pool import Pool
|
| 13 |
-
from tqdm import tqdm
|
| 14 |
-
from modules.fastspeech.tts_modules import mel2ph_to_dur
|
| 15 |
-
from utils.hparams import hparams
|
| 16 |
-
from utils.plot import spec_to_figure, dur_to_figure, f0_to_figure
|
| 17 |
-
from utils.pitch_utils import denorm_f0
|
| 18 |
-
from modules.fastspeech.fs2 import FastSpeech2
|
| 19 |
-
from training.task.tts import TtsTask
|
| 20 |
-
import torch
|
| 21 |
-
import torch.optim
|
| 22 |
-
import torch.utils.data
|
| 23 |
-
import torch.nn.functional as F
|
| 24 |
-
import utils
|
| 25 |
-
import torch.distributions
|
| 26 |
-
import numpy as np
|
| 27 |
-
from modules.commons.ssim import ssim
|
| 28 |
-
|
| 29 |
-
class FastSpeech2Task(TtsTask):
|
| 30 |
-
def __init__(self):
|
| 31 |
-
super(FastSpeech2Task, self).__init__()
|
| 32 |
-
self.dataset_cls = FastSpeechDataset
|
| 33 |
-
self.mse_loss_fn = torch.nn.MSELoss()
|
| 34 |
-
mel_losses = hparams['mel_loss'].split("|")
|
| 35 |
-
self.loss_and_lambda = {}
|
| 36 |
-
for i, l in enumerate(mel_losses):
|
| 37 |
-
if l == '':
|
| 38 |
-
continue
|
| 39 |
-
if ':' in l:
|
| 40 |
-
l, lbd = l.split(":")
|
| 41 |
-
lbd = float(lbd)
|
| 42 |
-
else:
|
| 43 |
-
lbd = 1.0
|
| 44 |
-
self.loss_and_lambda[l] = lbd
|
| 45 |
-
print("| Mel losses:", self.loss_and_lambda)
|
| 46 |
-
#self.sil_ph = self.phone_encoder.sil_phonemes()
|
| 47 |
-
|
| 48 |
-
@data_loader
|
| 49 |
-
def train_dataloader(self):
|
| 50 |
-
train_dataset = self.dataset_cls(hparams['train_set_name'], shuffle=True)
|
| 51 |
-
return self.build_dataloader(train_dataset, True, self.max_tokens, self.max_sentences,
|
| 52 |
-
endless=hparams['endless_ds'])
|
| 53 |
-
|
| 54 |
-
@data_loader
|
| 55 |
-
def val_dataloader(self):
|
| 56 |
-
valid_dataset = self.dataset_cls(hparams['valid_set_name'], shuffle=False)
|
| 57 |
-
return self.build_dataloader(valid_dataset, False, self.max_eval_tokens, self.max_eval_sentences)
|
| 58 |
-
|
| 59 |
-
@data_loader
|
| 60 |
-
def test_dataloader(self):
|
| 61 |
-
test_dataset = self.dataset_cls(hparams['test_set_name'], shuffle=False)
|
| 62 |
-
return self.build_dataloader(test_dataset, False, self.max_eval_tokens,
|
| 63 |
-
self.max_eval_sentences, batch_by_size=False)
|
| 64 |
-
|
| 65 |
-
def build_tts_model(self):
|
| 66 |
-
'''
|
| 67 |
-
rewrite
|
| 68 |
-
'''
|
| 69 |
-
return
|
| 70 |
-
# self.model = FastSpeech2(self.phone_encoder)
|
| 71 |
-
|
| 72 |
-
def build_model(self):
|
| 73 |
-
self.build_tts_model()
|
| 74 |
-
if hparams['load_ckpt'] != '':
|
| 75 |
-
self.load_ckpt(hparams['load_ckpt'], strict=True)
|
| 76 |
-
utils.print_arch(self.model)
|
| 77 |
-
return self.model
|
| 78 |
-
|
| 79 |
-
def _training_step(self, sample, batch_idx, _):
|
| 80 |
-
'''
|
| 81 |
-
rewrite
|
| 82 |
-
'''
|
| 83 |
-
return
|
| 84 |
-
# loss_output = self.run_model(self.model, sample)
|
| 85 |
-
# total_loss = sum([v for v in loss_output.values() if isinstance(v, torch.Tensor) and v.requires_grad])
|
| 86 |
-
# loss_output['batch_size'] = sample['txt_tokens'].size()[0]
|
| 87 |
-
# return total_loss, loss_output
|
| 88 |
-
|
| 89 |
-
def validation_step(self, sample, batch_idx):
|
| 90 |
-
'''
|
| 91 |
-
rewrite
|
| 92 |
-
'''
|
| 93 |
-
return
|
| 94 |
-
# outputs = {}
|
| 95 |
-
# outputs['losses'] = {}
|
| 96 |
-
# outputs['losses'], model_out = self.run_model(self.model, sample, return_output=True)
|
| 97 |
-
# outputs['total_loss'] = sum(outputs['losses'].values())
|
| 98 |
-
# outputs['nsamples'] = sample['nsamples']
|
| 99 |
-
# mel_out = self.model.out2mel(model_out['mel_out'])
|
| 100 |
-
# outputs = utils.tensors_to_scalars(outputs)
|
| 101 |
-
# if batch_idx < hparams['num_valid_plots']:
|
| 102 |
-
# self.plot_mel(batch_idx, sample['mels'], mel_out)
|
| 103 |
-
# self.plot_dur(batch_idx, sample, model_out)
|
| 104 |
-
# if hparams['use_pitch_embed']:
|
| 105 |
-
# self.plot_pitch(batch_idx, sample, model_out)
|
| 106 |
-
# return outputs
|
| 107 |
-
|
| 108 |
-
def _validation_end(self, outputs):
|
| 109 |
-
all_losses_meter = {
|
| 110 |
-
'total_loss': utils.AvgrageMeter(),
|
| 111 |
-
}
|
| 112 |
-
for output in outputs:
|
| 113 |
-
n = output['nsamples']
|
| 114 |
-
for k, v in output['losses'].items():
|
| 115 |
-
if k not in all_losses_meter:
|
| 116 |
-
all_losses_meter[k] = utils.AvgrageMeter()
|
| 117 |
-
all_losses_meter[k].update(v, n)
|
| 118 |
-
all_losses_meter['total_loss'].update(output['total_loss'], n)
|
| 119 |
-
return {k: round(v.avg, 4) for k, v in all_losses_meter.items()}
|
| 120 |
-
|
| 121 |
-
def run_model(self, model, sample, return_output=False):
|
| 122 |
-
'''
|
| 123 |
-
rewrite
|
| 124 |
-
'''
|
| 125 |
-
return
|
| 126 |
-
txt_tokens = sample['txt_tokens'] # [B, T_t]
|
| 127 |
-
target = sample['mels'] # [B, T_s, 80]
|
| 128 |
-
mel2ph = sample['mel2ph'] # [B, T_s]
|
| 129 |
-
f0 = sample['f0']
|
| 130 |
-
uv = sample['uv']
|
| 131 |
-
energy = sample['energy']
|
| 132 |
-
spk_embed = sample.get('spk_embed') if not hparams['use_spk_id'] else sample.get('spk_ids')
|
| 133 |
-
if hparams['pitch_type'] == 'cwt':
|
| 134 |
-
cwt_spec = sample[f'cwt_spec']
|
| 135 |
-
f0_mean = sample['f0_mean']
|
| 136 |
-
f0_std = sample['f0_std']
|
| 137 |
-
sample['f0_cwt'] = f0 = model.cwt2f0_norm(cwt_spec, f0_mean, f0_std, mel2ph)
|
| 138 |
-
|
| 139 |
-
output = model(txt_tokens, mel2ph=mel2ph, spk_embed=spk_embed,
|
| 140 |
-
ref_mels=target, f0=f0, uv=uv, energy=energy, infer=False)
|
| 141 |
-
|
| 142 |
-
losses = {}
|
| 143 |
-
self.add_mel_loss(output['mel_out'], target, losses)
|
| 144 |
-
self.add_dur_loss(output['dur'], mel2ph, txt_tokens, losses=losses)
|
| 145 |
-
if hparams['use_pitch_embed']:
|
| 146 |
-
self.add_pitch_loss(output, sample, losses)
|
| 147 |
-
if hparams['use_energy_embed']:
|
| 148 |
-
self.add_energy_loss(output['energy_pred'], energy, losses)
|
| 149 |
-
if not return_output:
|
| 150 |
-
return losses
|
| 151 |
-
else:
|
| 152 |
-
return losses, output
|
| 153 |
-
|
| 154 |
-
############
|
| 155 |
-
# losses
|
| 156 |
-
############
|
| 157 |
-
def add_mel_loss(self, mel_out, target, losses, postfix='', mel_mix_loss=None):
|
| 158 |
-
if mel_mix_loss is None:
|
| 159 |
-
for loss_name, lbd in self.loss_and_lambda.items():
|
| 160 |
-
if 'l1' == loss_name:
|
| 161 |
-
l = self.l1_loss(mel_out, target)
|
| 162 |
-
elif 'mse' == loss_name:
|
| 163 |
-
raise NotImplementedError
|
| 164 |
-
elif 'ssim' == loss_name:
|
| 165 |
-
l = self.ssim_loss(mel_out, target)
|
| 166 |
-
elif 'gdl' == loss_name:
|
| 167 |
-
raise NotImplementedError
|
| 168 |
-
losses[f'{loss_name}{postfix}'] = l * lbd
|
| 169 |
-
else:
|
| 170 |
-
raise NotImplementedError
|
| 171 |
-
|
| 172 |
-
def l1_loss(self, decoder_output, target):
|
| 173 |
-
# decoder_output : B x T x n_mel
|
| 174 |
-
# target : B x T x n_mel
|
| 175 |
-
l1_loss = F.l1_loss(decoder_output, target, reduction='none')
|
| 176 |
-
weights = self.weights_nonzero_speech(target)
|
| 177 |
-
l1_loss = (l1_loss * weights).sum() / weights.sum()
|
| 178 |
-
return l1_loss
|
| 179 |
-
|
| 180 |
-
def ssim_loss(self, decoder_output, target, bias=6.0):
|
| 181 |
-
# decoder_output : B x T x n_mel
|
| 182 |
-
# target : B x T x n_mel
|
| 183 |
-
assert decoder_output.shape == target.shape
|
| 184 |
-
weights = self.weights_nonzero_speech(target)
|
| 185 |
-
decoder_output = decoder_output[:, None] + bias
|
| 186 |
-
target = target[:, None] + bias
|
| 187 |
-
ssim_loss = 1 - ssim(decoder_output, target, size_average=False)
|
| 188 |
-
ssim_loss = (ssim_loss * weights).sum() / weights.sum()
|
| 189 |
-
return ssim_loss
|
| 190 |
-
|
| 191 |
-
def add_dur_loss(self, dur_pred, mel2ph, txt_tokens, losses=None):
|
| 192 |
-
"""
|
| 193 |
-
|
| 194 |
-
:param dur_pred: [B, T], float, log scale
|
| 195 |
-
:param mel2ph: [B, T]
|
| 196 |
-
:param txt_tokens: [B, T]
|
| 197 |
-
:param losses:
|
| 198 |
-
:return:
|
| 199 |
-
"""
|
| 200 |
-
B, T = txt_tokens.shape
|
| 201 |
-
nonpadding = (txt_tokens != 0).float()
|
| 202 |
-
dur_gt = mel2ph_to_dur(mel2ph, T).float() * nonpadding
|
| 203 |
-
is_sil = torch.zeros_like(txt_tokens).bool()
|
| 204 |
-
for p in self.sil_ph:
|
| 205 |
-
is_sil = is_sil | (txt_tokens == self.phone_encoder.encode(p)[0])
|
| 206 |
-
is_sil = is_sil.float() # [B, T_txt]
|
| 207 |
-
|
| 208 |
-
# phone duration loss
|
| 209 |
-
if hparams['dur_loss'] == 'mse':
|
| 210 |
-
losses['pdur'] = F.mse_loss(dur_pred, (dur_gt + 1).log(), reduction='none')
|
| 211 |
-
losses['pdur'] = (losses['pdur'] * nonpadding).sum() / nonpadding.sum()
|
| 212 |
-
dur_pred = (dur_pred.exp() - 1).clamp(min=0)
|
| 213 |
-
elif hparams['dur_loss'] == 'mog':
|
| 214 |
-
return NotImplementedError
|
| 215 |
-
elif hparams['dur_loss'] == 'crf':
|
| 216 |
-
losses['pdur'] = -self.model.dur_predictor.crf(
|
| 217 |
-
dur_pred, dur_gt.long().clamp(min=0, max=31), mask=nonpadding > 0, reduction='mean')
|
| 218 |
-
losses['pdur'] = losses['pdur'] * hparams['lambda_ph_dur']
|
| 219 |
-
|
| 220 |
-
# use linear scale for sent and word duration
|
| 221 |
-
if hparams['lambda_word_dur'] > 0:
|
| 222 |
-
word_id = (is_sil.cumsum(-1) * (1 - is_sil)).long()
|
| 223 |
-
word_dur_p = dur_pred.new_zeros([B, word_id.max() + 1]).scatter_add(1, word_id, dur_pred)[:, 1:]
|
| 224 |
-
word_dur_g = dur_gt.new_zeros([B, word_id.max() + 1]).scatter_add(1, word_id, dur_gt)[:, 1:]
|
| 225 |
-
wdur_loss = F.mse_loss((word_dur_p + 1).log(), (word_dur_g + 1).log(), reduction='none')
|
| 226 |
-
word_nonpadding = (word_dur_g > 0).float()
|
| 227 |
-
wdur_loss = (wdur_loss * word_nonpadding).sum() / word_nonpadding.sum()
|
| 228 |
-
losses['wdur'] = wdur_loss * hparams['lambda_word_dur']
|
| 229 |
-
if hparams['lambda_sent_dur'] > 0:
|
| 230 |
-
sent_dur_p = dur_pred.sum(-1)
|
| 231 |
-
sent_dur_g = dur_gt.sum(-1)
|
| 232 |
-
sdur_loss = F.mse_loss((sent_dur_p + 1).log(), (sent_dur_g + 1).log(), reduction='mean')
|
| 233 |
-
losses['sdur'] = sdur_loss.mean() * hparams['lambda_sent_dur']
|
| 234 |
-
|
| 235 |
-
def add_pitch_loss(self, output, sample, losses):
|
| 236 |
-
if hparams['pitch_type'] == 'ph':
|
| 237 |
-
nonpadding = (sample['txt_tokens'] != 0).float()
|
| 238 |
-
pitch_loss_fn = F.l1_loss if hparams['pitch_loss'] == 'l1' else F.mse_loss
|
| 239 |
-
losses['f0'] = (pitch_loss_fn(output['pitch_pred'][:, :, 0], sample['f0'],
|
| 240 |
-
reduction='none') * nonpadding).sum() \
|
| 241 |
-
/ nonpadding.sum() * hparams['lambda_f0']
|
| 242 |
-
return
|
| 243 |
-
mel2ph = sample['mel2ph'] # [B, T_s]
|
| 244 |
-
f0 = sample['f0']
|
| 245 |
-
uv = sample['uv']
|
| 246 |
-
nonpadding = (mel2ph != 0).float()
|
| 247 |
-
if hparams['pitch_type'] == 'cwt':
|
| 248 |
-
cwt_spec = sample[f'cwt_spec']
|
| 249 |
-
f0_mean = sample['f0_mean']
|
| 250 |
-
f0_std = sample['f0_std']
|
| 251 |
-
cwt_pred = output['cwt'][:, :, :10]
|
| 252 |
-
f0_mean_pred = output['f0_mean']
|
| 253 |
-
f0_std_pred = output['f0_std']
|
| 254 |
-
losses['C'] = self.cwt_loss(cwt_pred, cwt_spec) * hparams['lambda_f0']
|
| 255 |
-
if hparams['use_uv']:
|
| 256 |
-
assert output['cwt'].shape[-1] == 11
|
| 257 |
-
uv_pred = output['cwt'][:, :, -1]
|
| 258 |
-
losses['uv'] = (F.binary_cross_entropy_with_logits(uv_pred, uv, reduction='none') * nonpadding) \
|
| 259 |
-
.sum() / nonpadding.sum() * hparams['lambda_uv']
|
| 260 |
-
losses['f0_mean'] = F.l1_loss(f0_mean_pred, f0_mean) * hparams['lambda_f0']
|
| 261 |
-
losses['f0_std'] = F.l1_loss(f0_std_pred, f0_std) * hparams['lambda_f0']
|
| 262 |
-
if hparams['cwt_add_f0_loss']:
|
| 263 |
-
f0_cwt_ = self.model.cwt2f0_norm(cwt_pred, f0_mean_pred, f0_std_pred, mel2ph)
|
| 264 |
-
self.add_f0_loss(f0_cwt_[:, :, None], f0, uv, losses, nonpadding=nonpadding)
|
| 265 |
-
elif hparams['pitch_type'] == 'frame':
|
| 266 |
-
self.add_f0_loss(output['pitch_pred'], f0, uv, losses, nonpadding=nonpadding)
|
| 267 |
-
|
| 268 |
-
def add_f0_loss(self, p_pred, f0, uv, losses, nonpadding):
|
| 269 |
-
assert p_pred[..., 0].shape == f0.shape
|
| 270 |
-
if hparams['use_uv']:
|
| 271 |
-
assert p_pred[..., 1].shape == uv.shape
|
| 272 |
-
losses['uv'] = (F.binary_cross_entropy_with_logits(
|
| 273 |
-
p_pred[:, :, 1], uv, reduction='none') * nonpadding).sum() \
|
| 274 |
-
/ nonpadding.sum() * hparams['lambda_uv']
|
| 275 |
-
nonpadding = nonpadding * (uv == 0).float()
|
| 276 |
-
|
| 277 |
-
f0_pred = p_pred[:, :, 0]
|
| 278 |
-
if hparams['pitch_loss'] in ['l1', 'l2']:
|
| 279 |
-
pitch_loss_fn = F.l1_loss if hparams['pitch_loss'] == 'l1' else F.mse_loss
|
| 280 |
-
losses['f0'] = (pitch_loss_fn(f0_pred, f0, reduction='none') * nonpadding).sum() \
|
| 281 |
-
/ nonpadding.sum() * hparams['lambda_f0']
|
| 282 |
-
elif hparams['pitch_loss'] == 'ssim':
|
| 283 |
-
return NotImplementedError
|
| 284 |
-
|
| 285 |
-
def cwt_loss(self, cwt_p, cwt_g):
|
| 286 |
-
if hparams['cwt_loss'] == 'l1':
|
| 287 |
-
return F.l1_loss(cwt_p, cwt_g)
|
| 288 |
-
if hparams['cwt_loss'] == 'l2':
|
| 289 |
-
return F.mse_loss(cwt_p, cwt_g)
|
| 290 |
-
if hparams['cwt_loss'] == 'ssim':
|
| 291 |
-
return self.ssim_loss(cwt_p, cwt_g, 20)
|
| 292 |
-
|
| 293 |
-
def add_energy_loss(self, energy_pred, energy, losses):
|
| 294 |
-
nonpadding = (energy != 0).float()
|
| 295 |
-
loss = (F.mse_loss(energy_pred, energy, reduction='none') * nonpadding).sum() / nonpadding.sum()
|
| 296 |
-
loss = loss * hparams['lambda_energy']
|
| 297 |
-
losses['e'] = loss
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
############
|
| 301 |
-
# validation plots
|
| 302 |
-
############
|
| 303 |
-
def plot_mel(self, batch_idx, spec, spec_out, name=None):
|
| 304 |
-
spec_cat = torch.cat([spec, spec_out], -1)
|
| 305 |
-
name = f'mel_{batch_idx}' if name is None else name
|
| 306 |
-
vmin = hparams['mel_vmin']
|
| 307 |
-
vmax = hparams['mel_vmax']
|
| 308 |
-
self.logger.experiment.add_figure(name, spec_to_figure(spec_cat[0], vmin, vmax), self.global_step)
|
| 309 |
-
|
| 310 |
-
def plot_dur(self, batch_idx, sample, model_out):
|
| 311 |
-
T_txt = sample['txt_tokens'].shape[1]
|
| 312 |
-
dur_gt = mel2ph_to_dur(sample['mel2ph'], T_txt)[0]
|
| 313 |
-
dur_pred = self.model.dur_predictor.out2dur(model_out['dur']).float()
|
| 314 |
-
txt = self.phone_encoder.decode(sample['txt_tokens'][0].cpu().numpy())
|
| 315 |
-
txt = txt.split(" ")
|
| 316 |
-
self.logger.experiment.add_figure(
|
| 317 |
-
f'dur_{batch_idx}', dur_to_figure(dur_gt, dur_pred, txt), self.global_step)
|
| 318 |
-
|
| 319 |
-
def plot_pitch(self, batch_idx, sample, model_out):
|
| 320 |
-
f0 = sample['f0']
|
| 321 |
-
if hparams['pitch_type'] == 'ph':
|
| 322 |
-
mel2ph = sample['mel2ph']
|
| 323 |
-
f0 = self.expand_f0_ph(f0, mel2ph)
|
| 324 |
-
f0_pred = self.expand_f0_ph(model_out['pitch_pred'][:, :, 0], mel2ph)
|
| 325 |
-
self.logger.experiment.add_figure(
|
| 326 |
-
f'f0_{batch_idx}', f0_to_figure(f0[0], None, f0_pred[0]), self.global_step)
|
| 327 |
-
return
|
| 328 |
-
f0 = denorm_f0(f0, sample['uv'], hparams)
|
| 329 |
-
if hparams['pitch_type'] == 'cwt':
|
| 330 |
-
# cwt
|
| 331 |
-
cwt_out = model_out['cwt']
|
| 332 |
-
cwt_spec = cwt_out[:, :, :10]
|
| 333 |
-
cwt = torch.cat([cwt_spec, sample['cwt_spec']], -1)
|
| 334 |
-
self.logger.experiment.add_figure(f'cwt_{batch_idx}', spec_to_figure(cwt[0]), self.global_step)
|
| 335 |
-
# f0
|
| 336 |
-
f0_pred = cwt2f0(cwt_spec, model_out['f0_mean'], model_out['f0_std'], hparams['cwt_scales'])
|
| 337 |
-
if hparams['use_uv']:
|
| 338 |
-
assert cwt_out.shape[-1] == 11
|
| 339 |
-
uv_pred = cwt_out[:, :, -1] > 0
|
| 340 |
-
f0_pred[uv_pred > 0] = 0
|
| 341 |
-
f0_cwt = denorm_f0(sample['f0_cwt'], sample['uv'], hparams)
|
| 342 |
-
self.logger.experiment.add_figure(
|
| 343 |
-
f'f0_{batch_idx}', f0_to_figure(f0[0], f0_cwt[0], f0_pred[0]), self.global_step)
|
| 344 |
-
elif hparams['pitch_type'] == 'frame':
|
| 345 |
-
# f0
|
| 346 |
-
#uv_pred = model_out['pitch_pred'][:, :, 0] > 0
|
| 347 |
-
pitch_pred = denorm_f0(model_out['pitch_pred'][:, :, 0], sample['uv'], hparams)
|
| 348 |
-
self.logger.experiment.add_figure(
|
| 349 |
-
f'f0_{batch_idx}', f0_to_figure(f0[0], None, pitch_pred[0]), self.global_step)
|
| 350 |
-
|
| 351 |
-
############
|
| 352 |
-
# infer
|
| 353 |
-
############
|
| 354 |
-
def test_step(self, sample, batch_idx):
|
| 355 |
-
spk_embed = sample.get('spk_embed') if not hparams['use_spk_id'] else sample.get('spk_ids')
|
| 356 |
-
hubert = sample['hubert']
|
| 357 |
-
mel2ph, uv, f0 = None, None, None
|
| 358 |
-
ref_mels = None
|
| 359 |
-
if hparams['profile_infer']:
|
| 360 |
-
pass
|
| 361 |
-
else:
|
| 362 |
-
# if hparams['use_gt_dur']:
|
| 363 |
-
mel2ph = sample['mel2ph']
|
| 364 |
-
#if hparams['use_gt_f0']:
|
| 365 |
-
f0 = sample['f0']
|
| 366 |
-
uv = sample['uv']
|
| 367 |
-
#print('Here using gt f0!!')
|
| 368 |
-
if hparams.get('use_midi') is not None and hparams['use_midi']:
|
| 369 |
-
outputs = self.model(
|
| 370 |
-
hubert, spk_embed=spk_embed, mel2ph=mel2ph, f0=f0, uv=uv, ref_mels=ref_mels, infer=True)
|
| 371 |
-
else:
|
| 372 |
-
outputs = self.model(
|
| 373 |
-
hubert, spk_embed=spk_embed, mel2ph=mel2ph, f0=f0, uv=uv, ref_mels=ref_mels, infer=True)
|
| 374 |
-
sample['outputs'] = self.model.out2mel(outputs['mel_out'])
|
| 375 |
-
sample['mel2ph_pred'] = outputs['mel2ph']
|
| 376 |
-
if hparams.get('pe_enable') is not None and hparams['pe_enable']:
|
| 377 |
-
sample['f0'] = self.pe(sample['mels'])['f0_denorm_pred'] # pe predict from GT mel
|
| 378 |
-
sample['f0_pred'] = self.pe(sample['outputs'])['f0_denorm_pred'] # pe predict from Pred mel
|
| 379 |
-
else:
|
| 380 |
-
sample['f0'] = denorm_f0(sample['f0'], sample['uv'], hparams)
|
| 381 |
-
sample['f0_pred'] = outputs.get('f0_denorm')
|
| 382 |
-
return self.after_infer(sample)
|
| 383 |
-
|
| 384 |
-
def after_infer(self, predictions):
|
| 385 |
-
if self.saving_result_pool is None and not hparams['profile_infer']:
|
| 386 |
-
self.saving_result_pool = Pool(min(int(os.getenv('N_PROC', os.cpu_count())), 16))
|
| 387 |
-
self.saving_results_futures = []
|
| 388 |
-
predictions = utils.unpack_dict_to_list(predictions)
|
| 389 |
-
t = tqdm(predictions)
|
| 390 |
-
for num_predictions, prediction in enumerate(t):
|
| 391 |
-
for k, v in prediction.items():
|
| 392 |
-
if type(v) is torch.Tensor:
|
| 393 |
-
prediction[k] = v.cpu().numpy()
|
| 394 |
-
|
| 395 |
-
item_name = prediction.get('item_name')
|
| 396 |
-
#text = prediction.get('text').replace(":", "%3A")[:80]
|
| 397 |
-
|
| 398 |
-
# remove paddings
|
| 399 |
-
mel_gt = prediction["mels"]
|
| 400 |
-
mel_gt_mask = np.abs(mel_gt).sum(-1) > 0
|
| 401 |
-
mel_gt = mel_gt[mel_gt_mask]
|
| 402 |
-
mel2ph_gt = prediction.get("mel2ph")
|
| 403 |
-
mel2ph_gt = mel2ph_gt[mel_gt_mask] if mel2ph_gt is not None else None
|
| 404 |
-
mel_pred = prediction["outputs"]
|
| 405 |
-
mel_pred_mask = np.abs(mel_pred).sum(-1) > 0
|
| 406 |
-
mel_pred = mel_pred[mel_pred_mask]
|
| 407 |
-
mel_gt = np.clip(mel_gt, hparams['mel_vmin'], hparams['mel_vmax'])
|
| 408 |
-
mel_pred = np.clip(mel_pred, hparams['mel_vmin'], hparams['mel_vmax'])
|
| 409 |
-
|
| 410 |
-
mel2ph_pred = prediction.get("mel2ph_pred")
|
| 411 |
-
if mel2ph_pred is not None:
|
| 412 |
-
if len(mel2ph_pred) > len(mel_pred_mask):
|
| 413 |
-
mel2ph_pred = mel2ph_pred[:len(mel_pred_mask)]
|
| 414 |
-
mel2ph_pred = mel2ph_pred[mel_pred_mask]
|
| 415 |
-
|
| 416 |
-
f0_gt = prediction.get("f0")
|
| 417 |
-
f0_pred = f0_gt#prediction.get("f0_pred")
|
| 418 |
-
if f0_pred is not None:
|
| 419 |
-
f0_gt = f0_gt[mel_gt_mask]
|
| 420 |
-
if len(f0_pred) > len(mel_pred_mask):
|
| 421 |
-
f0_pred = f0_pred[:len(mel_pred_mask)]
|
| 422 |
-
f0_pred = f0_pred[mel_pred_mask]
|
| 423 |
-
text=None
|
| 424 |
-
str_phs = None
|
| 425 |
-
# if self.phone_encoder is not None and 'txt_tokens' in prediction:
|
| 426 |
-
# str_phs = self.phone_encoder.decode(prediction['txt_tokens'], strip_padding=True)
|
| 427 |
-
# def resize2d(source, target_len):
|
| 428 |
-
# source[source<0.001] = np.nan
|
| 429 |
-
# target = np.interp(np.linspace(0, len(source)-1, num=target_len,endpoint=True), np.arange(0, len(source)), source)
|
| 430 |
-
# return np.nan_to_num(target)
|
| 431 |
-
# def resize3d(source, target_len):
|
| 432 |
-
# newsource=[]
|
| 433 |
-
# for i in range(source.shape[1]):
|
| 434 |
-
# newsource.append(resize2d(source[:,i],target_len))
|
| 435 |
-
# return np.array(newsource).transpose()
|
| 436 |
-
# print(mel_pred.shape)
|
| 437 |
-
# print(f0_pred.shape)
|
| 438 |
-
# mel_pred=resize3d(mel_pred,int(mel_pred.shape[0]/44100*24000))
|
| 439 |
-
# f0_pred=resize2d(f0_pred,int(f0_pred.shape[0]/44100*24000))
|
| 440 |
-
# print(mel_pred.shape)
|
| 441 |
-
# print(f0_pred.shape)
|
| 442 |
-
gen_dir = os.path.join(hparams['work_dir'],
|
| 443 |
-
f'generated_{self.trainer.global_step}_{hparams["gen_dir_name"]}')
|
| 444 |
-
wav_pred = self.vocoder.spec2wav(mel_pred, f0=f0_pred)
|
| 445 |
-
if not hparams['profile_infer']:
|
| 446 |
-
os.makedirs(gen_dir, exist_ok=True)
|
| 447 |
-
os.makedirs(f'{gen_dir}/wavs', exist_ok=True)
|
| 448 |
-
os.makedirs(f'{gen_dir}/plot', exist_ok=True)
|
| 449 |
-
os.makedirs(os.path.join(hparams['work_dir'], 'P_mels_npy'), exist_ok=True)
|
| 450 |
-
os.makedirs(os.path.join(hparams['work_dir'], 'G_mels_npy'), exist_ok=True)
|
| 451 |
-
self.saving_results_futures.append(
|
| 452 |
-
self.saving_result_pool.apply_async(self.save_result, args=[
|
| 453 |
-
wav_pred, mel_pred, 'P', item_name, text, gen_dir, str_phs, mel2ph_pred, f0_gt, f0_pred]))
|
| 454 |
-
|
| 455 |
-
if mel_gt is not None and hparams['save_gt']:
|
| 456 |
-
wav_gt = self.vocoder.spec2wav(mel_gt, f0=f0_gt)
|
| 457 |
-
self.saving_results_futures.append(
|
| 458 |
-
self.saving_result_pool.apply_async(self.save_result, args=[
|
| 459 |
-
wav_gt, mel_gt, 'G', item_name, text, gen_dir, str_phs, mel2ph_gt, f0_gt, f0_pred]))
|
| 460 |
-
if hparams['save_f0']:
|
| 461 |
-
import matplotlib.pyplot as plt
|
| 462 |
-
# f0_pred_, _ = get_pitch(wav_pred, mel_pred, hparams)
|
| 463 |
-
f0_pred_ = f0_pred
|
| 464 |
-
f0_gt_, _ = get_pitch_parselmouth(wav_gt, mel_gt, hparams)
|
| 465 |
-
fig = plt.figure()
|
| 466 |
-
plt.plot(f0_pred_, label=r'$f0_P$')
|
| 467 |
-
plt.plot(f0_gt_, label=r'$f0_G$')
|
| 468 |
-
if hparams.get('pe_enable') is not None and hparams['pe_enable']:
|
| 469 |
-
# f0_midi = prediction.get("f0_midi")
|
| 470 |
-
# f0_midi = f0_midi[mel_gt_mask]
|
| 471 |
-
# plt.plot(f0_midi, label=r'$f0_M$')
|
| 472 |
-
pass
|
| 473 |
-
plt.legend()
|
| 474 |
-
plt.tight_layout()
|
| 475 |
-
plt.savefig(f'{gen_dir}/plot/[F0][{item_name}]{text}.png', format='png')
|
| 476 |
-
plt.close(fig)
|
| 477 |
-
|
| 478 |
-
t.set_description(
|
| 479 |
-
f"Pred_shape: {mel_pred.shape}, gt_shape: {mel_gt.shape}")
|
| 480 |
-
else:
|
| 481 |
-
if 'gen_wav_time' not in self.stats:
|
| 482 |
-
self.stats['gen_wav_time'] = 0
|
| 483 |
-
self.stats['gen_wav_time'] += len(wav_pred) / hparams['audio_sample_rate']
|
| 484 |
-
print('gen_wav_time: ', self.stats['gen_wav_time'])
|
| 485 |
-
|
| 486 |
-
return {}
|
| 487 |
-
|
| 488 |
-
@staticmethod
|
| 489 |
-
def save_result(wav_out, mel, prefix, item_name, text, gen_dir, str_phs=None, mel2ph=None, gt_f0=None, pred_f0=None):
|
| 490 |
-
item_name = item_name.replace('/', '-')
|
| 491 |
-
base_fn = f'[{item_name}][{prefix}]'
|
| 492 |
-
|
| 493 |
-
if text is not None:
|
| 494 |
-
base_fn += text
|
| 495 |
-
base_fn += ('-' + hparams['exp_name'])
|
| 496 |
-
np.save(os.path.join(hparams['work_dir'], f'{prefix}_mels_npy', item_name), mel)
|
| 497 |
-
audio.save_wav(wav_out, f'{gen_dir}/wavs/{base_fn}.wav', 24000,#hparams['audio_sample_rate'],
|
| 498 |
-
norm=hparams['out_wav_norm'])
|
| 499 |
-
fig = plt.figure(figsize=(14, 10))
|
| 500 |
-
spec_vmin = hparams['mel_vmin']
|
| 501 |
-
spec_vmax = hparams['mel_vmax']
|
| 502 |
-
heatmap = plt.pcolor(mel.T, vmin=spec_vmin, vmax=spec_vmax)
|
| 503 |
-
fig.colorbar(heatmap)
|
| 504 |
-
if hparams.get('pe_enable') is not None and hparams['pe_enable']:
|
| 505 |
-
gt_f0 = (gt_f0 - 100) / (800 - 100) * 80 * (gt_f0 > 0)
|
| 506 |
-
pred_f0 = (pred_f0 - 100) / (800 - 100) * 80 * (pred_f0 > 0)
|
| 507 |
-
plt.plot(pred_f0, c='white', linewidth=1, alpha=0.6)
|
| 508 |
-
plt.plot(gt_f0, c='red', linewidth=1, alpha=0.6)
|
| 509 |
-
else:
|
| 510 |
-
f0, _ = get_pitch_parselmouth(wav_out, mel, hparams)
|
| 511 |
-
f0 = (f0 - 100) / (800 - 100) * 80 * (f0 > 0)
|
| 512 |
-
plt.plot(f0, c='white', linewidth=1, alpha=0.6)
|
| 513 |
-
if mel2ph is not None and str_phs is not None:
|
| 514 |
-
decoded_txt = str_phs.split(" ")
|
| 515 |
-
dur = mel2ph_to_dur(torch.LongTensor(mel2ph)[None, :], len(decoded_txt))[0].numpy()
|
| 516 |
-
dur = [0] + list(np.cumsum(dur))
|
| 517 |
-
for i in range(len(dur) - 1):
|
| 518 |
-
shift = (i % 20) + 1
|
| 519 |
-
plt.text(dur[i], shift, decoded_txt[i])
|
| 520 |
-
plt.hlines(shift, dur[i], dur[i + 1], colors='b' if decoded_txt[i] != '|' else 'black')
|
| 521 |
-
plt.vlines(dur[i], 0, 5, colors='b' if decoded_txt[i] != '|' else 'black',
|
| 522 |
-
alpha=1, linewidth=1)
|
| 523 |
-
plt.tight_layout()
|
| 524 |
-
plt.savefig(f'{gen_dir}/plot/{base_fn}.png', format='png', dpi=1000)
|
| 525 |
-
plt.close(fig)
|
| 526 |
-
|
| 527 |
-
##############
|
| 528 |
-
# utils
|
| 529 |
-
##############
|
| 530 |
-
@staticmethod
|
| 531 |
-
def expand_f0_ph(f0, mel2ph):
|
| 532 |
-
f0 = denorm_f0(f0, None, hparams)
|
| 533 |
-
f0 = F.pad(f0, [1, 0])
|
| 534 |
-
f0 = torch.gather(f0, 1, mel2ph) # [B, T_mel]
|
| 535 |
-
return f0
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
if __name__ == '__main__':
|
| 539 |
-
FastSpeech2Task.start()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
training/task/tts.py
DELETED
|
@@ -1,131 +0,0 @@
|
|
| 1 |
-
from multiprocessing.pool import Pool
|
| 2 |
-
|
| 3 |
-
import matplotlib
|
| 4 |
-
|
| 5 |
-
from utils.pl_utils import data_loader
|
| 6 |
-
from utils.training_utils import RSQRTSchedule
|
| 7 |
-
from network.vocoders.base_vocoder import get_vocoder_cls, BaseVocoder
|
| 8 |
-
from modules.fastspeech.pe import PitchExtractor
|
| 9 |
-
|
| 10 |
-
matplotlib.use('Agg')
|
| 11 |
-
import os
|
| 12 |
-
import numpy as np
|
| 13 |
-
from tqdm import tqdm
|
| 14 |
-
import torch.distributed as dist
|
| 15 |
-
|
| 16 |
-
from training.task.base_task import BaseTask
|
| 17 |
-
from utils.hparams import hparams
|
| 18 |
-
from utils.text_encoder import TokenTextEncoder
|
| 19 |
-
import json
|
| 20 |
-
from preprocessing.hubertinfer import Hubertencoder
|
| 21 |
-
import torch
|
| 22 |
-
import torch.optim
|
| 23 |
-
import torch.utils.data
|
| 24 |
-
import utils
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
class TtsTask(BaseTask):
|
| 29 |
-
def __init__(self, *args, **kwargs):
|
| 30 |
-
self.vocoder = None
|
| 31 |
-
self.phone_encoder = Hubertencoder(hparams['hubert_path'])
|
| 32 |
-
# self.padding_idx = self.phone_encoder.pad()
|
| 33 |
-
# self.eos_idx = self.phone_encoder.eos()
|
| 34 |
-
# self.seg_idx = self.phone_encoder.seg()
|
| 35 |
-
self.saving_result_pool = None
|
| 36 |
-
self.saving_results_futures = None
|
| 37 |
-
self.stats = {}
|
| 38 |
-
super().__init__(*args, **kwargs)
|
| 39 |
-
|
| 40 |
-
def build_scheduler(self, optimizer):
|
| 41 |
-
return RSQRTSchedule(optimizer)
|
| 42 |
-
|
| 43 |
-
def build_optimizer(self, model):
|
| 44 |
-
self.optimizer = optimizer = torch.optim.AdamW(
|
| 45 |
-
model.parameters(),
|
| 46 |
-
lr=hparams['lr'])
|
| 47 |
-
return optimizer
|
| 48 |
-
|
| 49 |
-
def build_dataloader(self, dataset, shuffle, max_tokens=None, max_sentences=None,
|
| 50 |
-
required_batch_size_multiple=-1, endless=False, batch_by_size=True):
|
| 51 |
-
devices_cnt = torch.cuda.device_count()
|
| 52 |
-
if devices_cnt == 0:
|
| 53 |
-
devices_cnt = 1
|
| 54 |
-
if required_batch_size_multiple == -1:
|
| 55 |
-
required_batch_size_multiple = devices_cnt
|
| 56 |
-
|
| 57 |
-
def shuffle_batches(batches):
|
| 58 |
-
np.random.shuffle(batches)
|
| 59 |
-
return batches
|
| 60 |
-
|
| 61 |
-
if max_tokens is not None:
|
| 62 |
-
max_tokens *= devices_cnt
|
| 63 |
-
if max_sentences is not None:
|
| 64 |
-
max_sentences *= devices_cnt
|
| 65 |
-
indices = dataset.ordered_indices()
|
| 66 |
-
if batch_by_size:
|
| 67 |
-
batch_sampler = utils.batch_by_size(
|
| 68 |
-
indices, dataset.num_tokens, max_tokens=max_tokens, max_sentences=max_sentences,
|
| 69 |
-
required_batch_size_multiple=required_batch_size_multiple,
|
| 70 |
-
)
|
| 71 |
-
else:
|
| 72 |
-
batch_sampler = []
|
| 73 |
-
for i in range(0, len(indices), max_sentences):
|
| 74 |
-
batch_sampler.append(indices[i:i + max_sentences])
|
| 75 |
-
|
| 76 |
-
if shuffle:
|
| 77 |
-
batches = shuffle_batches(list(batch_sampler))
|
| 78 |
-
if endless:
|
| 79 |
-
batches = [b for _ in range(1000) for b in shuffle_batches(list(batch_sampler))]
|
| 80 |
-
else:
|
| 81 |
-
batches = batch_sampler
|
| 82 |
-
if endless:
|
| 83 |
-
batches = [b for _ in range(1000) for b in batches]
|
| 84 |
-
num_workers = dataset.num_workers
|
| 85 |
-
if self.trainer.use_ddp:
|
| 86 |
-
num_replicas = dist.get_world_size()
|
| 87 |
-
rank = dist.get_rank()
|
| 88 |
-
batches = [x[rank::num_replicas] for x in batches if len(x) % num_replicas == 0]
|
| 89 |
-
return torch.utils.data.DataLoader(dataset,
|
| 90 |
-
collate_fn=dataset.collater,
|
| 91 |
-
batch_sampler=batches,
|
| 92 |
-
num_workers=num_workers,
|
| 93 |
-
pin_memory=False)
|
| 94 |
-
|
| 95 |
-
# def build_phone_encoder(self, data_dir):
|
| 96 |
-
# phone_list_file = os.path.join(data_dir, 'phone_set.json')
|
| 97 |
-
|
| 98 |
-
# phone_list = json.load(open(phone_list_file, encoding='utf-8'))
|
| 99 |
-
# return TokenTextEncoder(None, vocab_list=phone_list, replace_oov=',')
|
| 100 |
-
|
| 101 |
-
def build_optimizer(self, model):
|
| 102 |
-
self.optimizer = optimizer = torch.optim.AdamW(
|
| 103 |
-
model.parameters(),
|
| 104 |
-
lr=hparams['lr'])
|
| 105 |
-
return optimizer
|
| 106 |
-
|
| 107 |
-
def test_start(self):
|
| 108 |
-
self.saving_result_pool = Pool(8)
|
| 109 |
-
self.saving_results_futures = []
|
| 110 |
-
self.vocoder: BaseVocoder = get_vocoder_cls(hparams)()
|
| 111 |
-
if hparams.get('pe_enable') is not None and hparams['pe_enable']:
|
| 112 |
-
self.pe = PitchExtractor().cuda()
|
| 113 |
-
utils.load_ckpt(self.pe, hparams['pe_ckpt'], 'model', strict=True)
|
| 114 |
-
self.pe.eval()
|
| 115 |
-
def test_end(self, outputs):
|
| 116 |
-
self.saving_result_pool.close()
|
| 117 |
-
[f.get() for f in tqdm(self.saving_results_futures)]
|
| 118 |
-
self.saving_result_pool.join()
|
| 119 |
-
return {}
|
| 120 |
-
|
| 121 |
-
##########
|
| 122 |
-
# utils
|
| 123 |
-
##########
|
| 124 |
-
def weights_nonzero_speech(self, target):
|
| 125 |
-
# target : B x T x mel
|
| 126 |
-
# Assign weight 1.0 to all labels except for padding (id=0).
|
| 127 |
-
dim = target.size(-1)
|
| 128 |
-
return target.abs().sum(-1, keepdim=True).ne(0).float().repeat(1, 1, dim)
|
| 129 |
-
|
| 130 |
-
if __name__ == '__main__':
|
| 131 |
-
TtsTask.start()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
training/train_pipeline.py
DELETED
|
@@ -1,238 +0,0 @@
|
|
| 1 |
-
from utils.hparams import hparams
|
| 2 |
-
import torch
|
| 3 |
-
from torch.nn import functional as F
|
| 4 |
-
from utils.pitch_utils import f0_to_coarse, denorm_f0, norm_f0
|
| 5 |
-
|
| 6 |
-
class Batch2Loss:
|
| 7 |
-
'''
|
| 8 |
-
pipeline: batch -> insert1 -> module1 -> insert2 -> module2 -> insert3 -> module3 -> insert4 -> module4 -> loss
|
| 9 |
-
'''
|
| 10 |
-
|
| 11 |
-
@staticmethod
|
| 12 |
-
def insert1(pitch_midi, midi_dur, is_slur, # variables
|
| 13 |
-
midi_embed, midi_dur_layer, is_slur_embed): # modules
|
| 14 |
-
'''
|
| 15 |
-
add embeddings for midi, midi_dur, slur
|
| 16 |
-
'''
|
| 17 |
-
midi_embedding = midi_embed(pitch_midi)
|
| 18 |
-
midi_dur_embedding, slur_embedding = 0, 0
|
| 19 |
-
if midi_dur is not None:
|
| 20 |
-
midi_dur_embedding = midi_dur_layer(midi_dur[:, :, None]) # [B, T, 1] -> [B, T, H]
|
| 21 |
-
if is_slur is not None:
|
| 22 |
-
slur_embedding = is_slur_embed(is_slur)
|
| 23 |
-
return midi_embedding, midi_dur_embedding, slur_embedding
|
| 24 |
-
|
| 25 |
-
@staticmethod
|
| 26 |
-
def module1(fs2_encoder, # modules
|
| 27 |
-
txt_tokens, midi_embedding, midi_dur_embedding, slur_embedding): # variables
|
| 28 |
-
'''
|
| 29 |
-
get *encoder_out* == fs2_encoder(*txt_tokens*, some embeddings)
|
| 30 |
-
'''
|
| 31 |
-
encoder_out = fs2_encoder(txt_tokens, midi_embedding, midi_dur_embedding, slur_embedding)
|
| 32 |
-
return encoder_out
|
| 33 |
-
|
| 34 |
-
@staticmethod
|
| 35 |
-
def insert2(encoder_out, spk_embed_id, spk_embed_dur_id, spk_embed_f0_id, src_nonpadding, # variables
|
| 36 |
-
spk_embed_proj): # modules
|
| 37 |
-
'''
|
| 38 |
-
1. add embeddings for pspk, spk_dur, sk_f0
|
| 39 |
-
2. get *dur_inp* ~= *encoder_out* + *spk_embed_dur*
|
| 40 |
-
'''
|
| 41 |
-
# add ref style embed
|
| 42 |
-
# Not implemented
|
| 43 |
-
# variance encoder
|
| 44 |
-
var_embed = 0
|
| 45 |
-
|
| 46 |
-
# encoder_out_dur denotes encoder outputs for duration predictor
|
| 47 |
-
# in speech adaptation, duration predictor use old speaker embedding
|
| 48 |
-
if hparams['use_spk_embed']:
|
| 49 |
-
spk_embed_dur = spk_embed_f0 = spk_embed = spk_embed_proj(spk_embed_id)[:, None, :]
|
| 50 |
-
elif hparams['use_spk_id']:
|
| 51 |
-
if spk_embed_dur_id is None:
|
| 52 |
-
spk_embed_dur_id = spk_embed_id
|
| 53 |
-
if spk_embed_f0_id is None:
|
| 54 |
-
spk_embed_f0_id = spk_embed_id
|
| 55 |
-
spk_embed = spk_embed_proj(spk_embed_id)[:, None, :]
|
| 56 |
-
spk_embed_dur = spk_embed_f0 = spk_embed
|
| 57 |
-
if hparams['use_split_spk_id']:
|
| 58 |
-
spk_embed_dur = spk_embed_dur(spk_embed_dur_id)[:, None, :]
|
| 59 |
-
spk_embed_f0 = spk_embed_f0(spk_embed_f0_id)[:, None, :]
|
| 60 |
-
else:
|
| 61 |
-
spk_embed_dur = spk_embed_f0 = spk_embed = 0
|
| 62 |
-
|
| 63 |
-
# add dur
|
| 64 |
-
dur_inp = (encoder_out + var_embed + spk_embed_dur) * src_nonpadding
|
| 65 |
-
return var_embed, spk_embed, spk_embed_dur, spk_embed_f0, dur_inp
|
| 66 |
-
|
| 67 |
-
@staticmethod
|
| 68 |
-
def module2(dur_predictor, length_regulator, # modules
|
| 69 |
-
dur_input, mel2ph, txt_tokens, all_vowel_tokens, ret, midi_dur=None): # variables
|
| 70 |
-
'''
|
| 71 |
-
1. get *dur* ~= dur_predictor(*dur_inp*)
|
| 72 |
-
2. (mel2ph is None): get *mel2ph* ~= length_regulater(*dur*)
|
| 73 |
-
'''
|
| 74 |
-
src_padding = (txt_tokens == 0)
|
| 75 |
-
dur_input = dur_input.detach() + hparams['predictor_grad'] * (dur_input - dur_input.detach())
|
| 76 |
-
|
| 77 |
-
if mel2ph is None:
|
| 78 |
-
dur, xs = dur_predictor.inference(dur_input, src_padding)
|
| 79 |
-
ret['dur'] = xs
|
| 80 |
-
dur = xs.squeeze(-1).exp() - 1.0
|
| 81 |
-
for i in range(len(dur)):
|
| 82 |
-
for j in range(len(dur[i])):
|
| 83 |
-
if txt_tokens[i,j] in all_vowel_tokens:
|
| 84 |
-
if j < len(dur[i])-1 and txt_tokens[i,j+1] not in all_vowel_tokens:
|
| 85 |
-
dur[i,j] = midi_dur[i,j] - dur[i,j+1]
|
| 86 |
-
if dur[i,j] < 0:
|
| 87 |
-
dur[i,j] = 0
|
| 88 |
-
dur[i,j+1] = midi_dur[i,j]
|
| 89 |
-
else:
|
| 90 |
-
dur[i,j]=midi_dur[i,j]
|
| 91 |
-
dur[:,0] = dur[:,0] + 0.5
|
| 92 |
-
dur_acc = F.pad(torch.round(torch.cumsum(dur, axis=1)), (1,0))
|
| 93 |
-
dur = torch.clamp(dur_acc[:,1:]-dur_acc[:,:-1], min=0).long()
|
| 94 |
-
ret['dur_choice'] = dur
|
| 95 |
-
mel2ph = length_regulator(dur, src_padding).detach()
|
| 96 |
-
else:
|
| 97 |
-
ret['dur'] = dur_predictor(dur_input, src_padding)
|
| 98 |
-
ret['mel2ph'] = mel2ph
|
| 99 |
-
|
| 100 |
-
return mel2ph
|
| 101 |
-
|
| 102 |
-
@staticmethod
|
| 103 |
-
def insert3(encoder_out, mel2ph, var_embed, spk_embed_f0, src_nonpadding, tgt_nonpadding): # variables
|
| 104 |
-
'''
|
| 105 |
-
1. get *decoder_inp* ~= gather *encoder_out* according to *mel2ph*
|
| 106 |
-
2. get *pitch_inp* ~= *decoder_inp* + *spk_embed_f0*
|
| 107 |
-
3. get *pitch_inp_ph* ~= *encoder_out* + *spk_embed_f0*
|
| 108 |
-
'''
|
| 109 |
-
decoder_inp = F.pad(encoder_out, [0, 0, 1, 0])
|
| 110 |
-
mel2ph_ = mel2ph[..., None].repeat([1, 1, encoder_out.shape[-1]])
|
| 111 |
-
decoder_inp = decoder_inp_origin = torch.gather(decoder_inp, 1, mel2ph_) # [B, T, H]
|
| 112 |
-
|
| 113 |
-
pitch_inp = (decoder_inp_origin + var_embed + spk_embed_f0) * tgt_nonpadding
|
| 114 |
-
pitch_inp_ph = (encoder_out + var_embed + spk_embed_f0) * src_nonpadding
|
| 115 |
-
return decoder_inp, pitch_inp, pitch_inp_ph
|
| 116 |
-
|
| 117 |
-
@staticmethod
|
| 118 |
-
def module3(pitch_predictor, pitch_embed, energy_predictor, energy_embed, # modules
|
| 119 |
-
pitch_inp, pitch_inp_ph, f0, uv, energy, mel2ph, is_training, ret): # variables
|
| 120 |
-
'''
|
| 121 |
-
1. get *ret['pitch_pred']*, *ret['energy_pred']* ~= pitch_predictor(*pitch_inp*), energy_predictor(*pitch_inp*)
|
| 122 |
-
2. get *pitch_embedding* ~= pitch_embed(f0_to_coarse(denorm_f0(*f0* or *pitch_pred*))
|
| 123 |
-
3. get *energy_embedding* ~= energy_embed(energy_to_coarse(*energy* or *energy_pred*))
|
| 124 |
-
'''
|
| 125 |
-
def add_pitch(decoder_inp, f0, uv, mel2ph, ret, encoder_out=None):
|
| 126 |
-
if hparams['pitch_type'] == 'ph':
|
| 127 |
-
pitch_pred_inp = encoder_out.detach() + hparams['predictor_grad'] * (encoder_out - encoder_out.detach())
|
| 128 |
-
pitch_padding = (encoder_out.sum().abs() == 0)
|
| 129 |
-
ret['pitch_pred'] = pitch_pred = pitch_predictor(pitch_pred_inp)
|
| 130 |
-
if f0 is None:
|
| 131 |
-
f0 = pitch_pred[:, :, 0]
|
| 132 |
-
ret['f0_denorm'] = f0_denorm = denorm_f0(f0, None, hparams, pitch_padding=pitch_padding)
|
| 133 |
-
pitch = f0_to_coarse(f0_denorm) # start from 0 [B, T_txt]
|
| 134 |
-
pitch = F.pad(pitch, [1, 0])
|
| 135 |
-
pitch = torch.gather(pitch, 1, mel2ph) # [B, T_mel]
|
| 136 |
-
pitch_embedding = pitch_embed(pitch)
|
| 137 |
-
return pitch_embedding
|
| 138 |
-
|
| 139 |
-
decoder_inp = decoder_inp.detach() + hparams['predictor_grad'] * (decoder_inp - decoder_inp.detach())
|
| 140 |
-
|
| 141 |
-
pitch_padding = (mel2ph == 0)
|
| 142 |
-
|
| 143 |
-
if hparams['pitch_type'] == 'cwt':
|
| 144 |
-
# NOTE: this part of script is *isolated* from other scripts, which means
|
| 145 |
-
# it may not be compatible with the current version.
|
| 146 |
-
pass
|
| 147 |
-
# pitch_padding = None
|
| 148 |
-
# ret['cwt'] = cwt_out = self.cwt_predictor(decoder_inp)
|
| 149 |
-
# stats_out = self.cwt_stats_layers(encoder_out[:, 0, :]) # [B, 2]
|
| 150 |
-
# mean = ret['f0_mean'] = stats_out[:, 0]
|
| 151 |
-
# std = ret['f0_std'] = stats_out[:, 1]
|
| 152 |
-
# cwt_spec = cwt_out[:, :, :10]
|
| 153 |
-
# if f0 is None:
|
| 154 |
-
# std = std * hparams['cwt_std_scale']
|
| 155 |
-
# f0 = self.cwt2f0_norm(cwt_spec, mean, std, mel2ph)
|
| 156 |
-
# if hparams['use_uv']:
|
| 157 |
-
# assert cwt_out.shape[-1] == 11
|
| 158 |
-
# uv = cwt_out[:, :, -1] > 0
|
| 159 |
-
elif hparams['pitch_ar']:
|
| 160 |
-
ret['pitch_pred'] = pitch_pred = pitch_predictor(decoder_inp, f0 if is_training else None)
|
| 161 |
-
if f0 is None:
|
| 162 |
-
f0 = pitch_pred[:, :, 0]
|
| 163 |
-
else:
|
| 164 |
-
ret['pitch_pred'] = pitch_pred = pitch_predictor(decoder_inp)
|
| 165 |
-
if f0 is None:
|
| 166 |
-
f0 = pitch_pred[:, :, 0]
|
| 167 |
-
if hparams['use_uv'] and uv is None:
|
| 168 |
-
uv = pitch_pred[:, :, 1] > 0
|
| 169 |
-
ret['f0_denorm'] = f0_denorm = denorm_f0(f0, uv, hparams, pitch_padding=pitch_padding)
|
| 170 |
-
if pitch_padding is not None:
|
| 171 |
-
f0[pitch_padding] = 0
|
| 172 |
-
|
| 173 |
-
pitch = f0_to_coarse(f0_denorm) # start from 0
|
| 174 |
-
pitch_embedding = pitch_embed(pitch)
|
| 175 |
-
return pitch_embedding
|
| 176 |
-
|
| 177 |
-
def add_energy(decoder_inp, energy, ret):
|
| 178 |
-
decoder_inp = decoder_inp.detach() + hparams['predictor_grad'] * (decoder_inp - decoder_inp.detach())
|
| 179 |
-
ret['energy_pred'] = energy_pred = energy_predictor(decoder_inp)[:, :, 0]
|
| 180 |
-
if energy is None:
|
| 181 |
-
energy = energy_pred
|
| 182 |
-
energy = torch.clamp(energy * 256 // 4, max=255).long() # energy_to_coarse
|
| 183 |
-
energy_embedding = energy_embed(energy)
|
| 184 |
-
return energy_embedding
|
| 185 |
-
|
| 186 |
-
# add pitch and energy embed
|
| 187 |
-
nframes = mel2ph.size(1)
|
| 188 |
-
|
| 189 |
-
pitch_embedding = 0
|
| 190 |
-
if hparams['use_pitch_embed']:
|
| 191 |
-
if f0 is not None:
|
| 192 |
-
delta_l = nframes - f0.size(1)
|
| 193 |
-
if delta_l > 0:
|
| 194 |
-
f0 = torch.cat((f0,torch.FloatTensor([[x[-1]] * delta_l for x in f0]).to(f0.device)),1)
|
| 195 |
-
f0 = f0[:,:nframes]
|
| 196 |
-
if uv is not None:
|
| 197 |
-
delta_l = nframes - uv.size(1)
|
| 198 |
-
if delta_l > 0:
|
| 199 |
-
uv = torch.cat((uv,torch.FloatTensor([[x[-1]] * delta_l for x in uv]).to(uv.device)),1)
|
| 200 |
-
uv = uv[:,:nframes]
|
| 201 |
-
pitch_embedding = add_pitch(pitch_inp, f0, uv, mel2ph, ret, encoder_out=pitch_inp_ph)
|
| 202 |
-
|
| 203 |
-
energy_embedding = 0
|
| 204 |
-
if hparams['use_energy_embed']:
|
| 205 |
-
if energy is not None:
|
| 206 |
-
delta_l = nframes - energy.size(1)
|
| 207 |
-
if delta_l > 0:
|
| 208 |
-
energy = torch.cat((energy,torch.FloatTensor([[x[-1]] * delta_l for x in energy]).to(energy.device)),1)
|
| 209 |
-
energy = energy[:,:nframes]
|
| 210 |
-
energy_embedding = add_energy(pitch_inp, energy, ret)
|
| 211 |
-
|
| 212 |
-
return pitch_embedding, energy_embedding
|
| 213 |
-
|
| 214 |
-
@staticmethod
|
| 215 |
-
def insert4(decoder_inp, pitch_embedding, energy_embedding, spk_embed, ret, tgt_nonpadding):
|
| 216 |
-
'''
|
| 217 |
-
*decoder_inp* ~= *decoder_inp* + embeddings for spk, pitch, energy
|
| 218 |
-
'''
|
| 219 |
-
ret['decoder_inp'] = decoder_inp = (decoder_inp + pitch_embedding + energy_embedding + spk_embed) * tgt_nonpadding
|
| 220 |
-
return decoder_inp
|
| 221 |
-
|
| 222 |
-
@staticmethod
|
| 223 |
-
def module4(diff_main_loss, # modules
|
| 224 |
-
norm_spec, decoder_inp_t, ret, K_step, batch_size, device): # variables
|
| 225 |
-
'''
|
| 226 |
-
training diffusion using spec as input and decoder_inp as condition.
|
| 227 |
-
|
| 228 |
-
Args:
|
| 229 |
-
norm_spec: (normalized) spec
|
| 230 |
-
decoder_inp_t: (transposed) decoder_inp
|
| 231 |
-
Returns:
|
| 232 |
-
ret['diff_loss']
|
| 233 |
-
'''
|
| 234 |
-
t = torch.randint(0, K_step, (batch_size,), device=device).long()
|
| 235 |
-
norm_spec = norm_spec.transpose(1, 2)[:, None, :, :] # [B, 1, M, T]
|
| 236 |
-
ret['diff_loss'] = diff_main_loss(norm_spec, t, cond=decoder_inp_t)
|
| 237 |
-
# nonpadding = (mel2ph != 0).float()
|
| 238 |
-
# ret['diff_loss'] = self.p_losses(x, t, cond, nonpadding=nonpadding)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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