File size: 1,247 Bytes
493a2af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import os
from datasets import load_dataset
from tqdm import tqdm
from zerorvc import RVCTrainer, pretrained_checkpoints

HF_TOKEN = os.environ.get("HF_TOKEN")
EPOCHS = 100
BATCH_SIZE = 8
DATASET = "JacobLinCool/my-rvc-dataset"
MODEL = "JacobLinCool/my-rvc-model"

dataset = load_dataset(DATASET, token=HF_TOKEN)
print(dataset)

trainer = RVCTrainer(checkpoint_dir="./checkpoints")
training = tqdm(
    trainer.train(
        dataset=dataset["train"],
        resume_from=pretrained_checkpoints(),  # resume training from the pretrained VCTK checkpoint
        epochs=EPOCHS,
        batch_size=BATCH_SIZE,
    ),
    total=EPOCHS,
)

# Training loop: iterate over epochs
for checkpoint in training:
    training.set_description(
        f"Epoch {checkpoint.epoch}/{EPOCHS} loss: (gen: {checkpoint.loss_gen:.4f}, fm: {checkpoint.loss_fm:.4f}, mel: {checkpoint.loss_mel:.4f}, kl: {checkpoint.loss_kl:.4f}, disc: {checkpoint.loss_disc:.4f})"
    )

    # Save checkpoint every 10 epochs
    if checkpoint.epoch % 10 == 0:
        checkpoint.save(checkpoint_dir=trainer.checkpoint_dir)
        # Directly push the synthesizer to the Hugging Face Hub
        checkpoint.G.push_to_hub(MODEL, token=HF_TOKEN, private=True)

print("Training completed.")