How do we save the finetuned ASR model and use them for inference?
See original GitHub issueHello, I was able to fine-tune a model on my dataset as given in the tutorial Pretrained Models and Fine-Tuning. However, I couldn’t find a clear way of saving the fine-tuned model ( something equivalent to torch.save or pickle). I have gone through the checkpoints tutorial and tried to do something as follows (steps after brain.fit() – to save and load the fine-tune model):
from speechbrain.utils.checkpoints import Checkpointer
checkpoint_dir = "./full_example_checkpoints"
checkpointer = Checkpointer(checkpoint_dir)
modules = {"enc": asr_model.mods.encoder.model,
"emb": asr_model.hparams.emb,
"dec": asr_model.hparams.dec,
"compute_features": asr_model.mods.encoder.compute_features,
"normalize": asr_model.mods.encoder.normalize,
"seq_lin": asr_model.hparams.seq_lin,
}
checkpointer.add_recoverables(modules)
ckpt = checkpointer.save_checkpoint()
ckpt_finder = Checkpointer(checkpoint_dir)
get_ckpt = ckpt_finder.find_checkpoint()
**% load a fresh model and then transfer the parameters of fine-tuned models into that**
new_asr_model = EncoderDecoderASR.from_hparams(source="speechbrain/asr-crdnn-rnnlm-librispeech", savedir="./pretrained_ASR")
**% parameter transfer**
sb.utils.checkpoints.torch_parameter_transfer(new_asr_model.mods.encoder.model, get_ckpt.paramfiles['enc'], device='cpu')
sb.utils.checkpoints.torch_parameter_transfer(new_asr_model.hparams.emb, get_ckpt.paramfiles['emb'], device='cpu')
sb.utils.checkpoints.torch_parameter_transfer(new_asr_model.hparams.dec, get_ckpt.paramfiles['dec'], device='cpu')
sb.utils.checkpoints.torch_parameter_transfer(new_asr_model.mods.encoder.compute_features, best_ckpt.paramfiles['compute_features'], device='cpu')
sb.utils.checkpoints.torch_parameter_transfer(new_asr_model.mods.encoder.normalize, get_ckpt.paramfiles['normalize'], device='cpu')
sb.utils.checkpoints.torch_parameter_transfer(new_asr_model.hparams.seq_lin, get_ckpt.paramfiles['seq_lin'], device='cpu')
I believe there must be a better way to do this. Could you please confirm that above code will work? Also, it would be great if you could provide some hints related to this. Thanks in advance.
Issue Analytics
- State:
- Created 2 years ago
- Comments:7
Top Results From Across the Web
Fine-Tune Wav2Vec2 for English ASR with Transformers
In this notebook, we will give an in-detail explanation of how Wav2Vec2's pretrained checkpoints can be fine-tuned on any English ASR dataset.
Read more >How to Fine-Tune a Riva ASR Acoustic Model (Citrinet) with ...
After the model is trained, evaluated, and there is a need for fine-tuning, the following command can be used to fine-tune the ASR...
Read more >Fine-tune and deploy a Wav2Vec2 model for speech ...
In this post, we show how data scientists who want to build their own ASR models can fine-tune the pre-trained Wav2Vec2 model on...
Read more >Fine-tuning Wav2Vec2 with an LM head | TensorFlow Hub
Now that we are satisfied with the training process & have saved the model in save_dir , we will see how this model...
Read more >How to restore a ckpt conformer model for inference/finetuning?
EncDecCTCModelBPE.restore_from(name+'.nemo') and use it for inference. ... save the new model for finetuning by asr_model.save_to(xxx.nemo) ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hello, Thank you very much for all the help. It is working fine for me now and is very convenient as well. Closing the ticket. Thanks again!.
Ok so you’ve decided to use the Pretrained interface. Looks ok, the paths provided to your Pretrainer seem a little weird, though I think it would work.
Here’s how I’d change it, though: