Skip to content

Instantly share code, notes, and snippets.

@zabir-nabil
Created September 28, 2022 10:02
Show Gist options
  • Save zabir-nabil/510572cefc293943a878a922ba5cbfa8 to your computer and use it in GitHub Desktop.
Save zabir-nabil/510572cefc293943a878a922ba5cbfa8 to your computer and use it in GitHub Desktop.
from model_ecapatdnn import ECAPAModel
import soundfile as sf
import torch
# load your pytorch model (+ weights) here
model_1 = ECAPAModel.ECAPAModel(lr = 0.001, lr_decay = 0.97, C = 1024, n_class = 18505, m = 0.2, s = 30, test_step = 3, gpu = -1)
model_1.load_parameters("/ecapatdnn/exps/finetuned/model/model_0028.model")
model = model_1.speaker_encoder # module with forward implemented
# if your forward function contains any arguments other than the input tensors, make sure to add default values
# Switch the model to eval model
model.eval()
# An example input you would normally provide to your model's forward() method.
example = torch.rand(1, 48000)
# Use torch.jit.trace to generate a torch.jit.ScriptModule via tracing.
traced_script_module = torch.jit.trace(model, example)
# Save the TorchScript model
traced_script_module.save("model.pt")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment