gitmylo / bark-voice-cloning-HuBERT-quantizer

The code for the bark-voicecloning model. Training and inference.
MIT License
670 stars 111 forks source link

`KeyError: 'best_loss'` when testing self-trained model #39

Closed Mareike-RTY closed 1 year ago

Mareike-RTY commented 1 year ago

Hi, first of all thank you for your work!

I created the semantic data and wavs with the help of your bark-data-gen repo, and trained the model myself by following the steps you mentioned at https://github.com/gitmylo/bark-voice-cloning-HuBERT-quantizer#how-do-i-train-it-myself. I trained the model until 20th epoch and would now like to test it.

Unfortunately testing gives me a KeyError :

$ python process.py  --path Literature  --mode test
Traceback (most recent call last):
  File ".../bark-voice-cloning-HuBERT-quantizer/process.py", line 28, in <module>
    test_hubert(path, model)
  File ".../bark-voice-cloning-HuBERT-quantizer/test_hubert.py", line 13, in test_hubert
    hubert_model = CustomHubert(checkpoint_path=model)
  File ".../bark-voice-cloning-HuBERT-quantizer/hubert/pre_kmeans_hubert.py", line 62, in __init__
    model, *_ = fairseq.checkpoint_utils.load_model_ensemble_and_task(load_model_input)
  File ".../python3.10/site-packages/fairseq/checkpoint_utils.py", line 431, in load_model_ensemble_and_task
    state = load_checkpoint_to_cpu(filename, arg_overrides)
  File ".../python3.10/site-packages/fairseq/checkpoint_utils.py", line 349, in load_checkpoint_to_cpu
    state = _upgrade_state_dict(state)
  File ".../python3.10/site-packages/fairseq/checkpoint_utils.py", line 595, in _upgrade_state_dict
    "best_loss": state["best_loss"]}
KeyError: 'best_loss'

In test_hubert.py, I'm passing the path to my self-trained model model_epoch_20.pth:

# test_hubert.py
def test_hubert(path: str, model: str = ".../Literature/model_epoch_20.pth", 
                tokenizer: str = 'model.pth'):
    hubert_model = CustomHubert(checkpoint_path=model)  # throws error

The self-trained model dict has the following keys:

# fairseq/checkpoint_utils.py
odict_keys(['lstm.weight_ih_l0', 'lstm.weight_hh_l0', 'lstm.bias_ih_l0', 'lstm.bias_hh_l0', 'lstm.weight_ih_l1', 'lstm.weight_hh_l1', 'lstm.bias_ih_l1', 'lstm.bias_hh_l1', 'intermediate.weight', 'intermediate.bias', 'fc.weight', 'fc.bias'])

I'm getting the same error when trying to test the pre-trained german-HuBERT-quantizer_14_epoch.pth model from C0untFloyd mentioned in this repo.

Could you please give me a hint about what I'm doing wrong here? How could I successfully test the self-trained model?

Thank you very much in advance.

gitmylo commented 1 year ago

test_hubert is just for comparing true and predicted tokens, actual testing should be done by using the model, this can be done in multiple ways.

A guide for creating the .npz files for bark can be found in the readme

Mareike-RTY commented 1 year ago

Ok, will do this next. Thanks!