Skip to content

Commit

Permalink
🐛 fix speaker trainer
Browse files Browse the repository at this point in the history
  • Loading branch information
zhzLuke96 committed Jun 15, 2024
1 parent 7bf3de2 commit 52d473f
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions modules/finetune/train_speaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ def train_speaker_embeddings(
)
for speaker in dataset.speakers
}

for speaker_embed in speaker_embeds.values():
std, mean = chat.pretrain_models["spk_stat"].chunk(2)
speaker_embed.data = speaker_embed.data * std + mean
for speaker_embed in speaker_embeds.values():
std, mean = chat.pretrain_models["spk_stat"].chunk(2)
speaker_embed.data = speaker_embed.data * std + mean

SPEAKER_TOKEN_ID = tokenizer.convert_tokens_to_ids("[spk_emb]")
AUDIO_EOS_TOKEN_ID = 0
Expand Down Expand Up @@ -277,15 +276,20 @@ def train_speaker_embeddings(
speaker: Speaker(speaker_embed.detach().cpu(), f"ep{epochs}_{speaker}")
for speaker, speaker_embed in speaker_embeds.items()
}
time_str = np.datetime_as_string(np.datetime64("now", "s"))
time_str = time_str.replace(":", "_").replace(" ", "_").replace("-", "_")
for speaker, speaker_out in speaker_outs.items():
torch.save(speaker_out, pathlib.Path(save_folder) / f"spk_{speaker}.pt")
torch.save(
speaker_out,
pathlib.Path(save_folder) / f"spk_{speaker}_{time_str}_ep{epochs}.pt",
)

# example
"""
python -m modules.finetune.train_speaker \
--data_path datasets/data_speaker_a/speaker_a.list \
--save_folder ./data \
--init_spaker ./data/speakers/Bob.pt \
--init_speaker ./data/speakers/Bob.pt \
--epochs 100 \
--batch_size 6 \
--train_text
Expand Down

0 comments on commit 52d473f

Please sign in to comment.