HarryVolek / PyTorch_Speaker_Verification

PyTorch implementation of "Generalized End-to-End Loss for Speaker Verification" by Wan, Li et al.
BSD 3-Clause "New" or "Revised" License
575 stars 166 forks source link

I can't load the trained model #8

Closed wuqiangch closed 5 years ago

wuqiangch commented 5 years ago

@HarryVolek I have get the model of TIMIT database ,and get thi information "Done, trained model saved at ./speech_id_checkpoint/final_epoch_950_batch_id_141.model" But when I do test , I cant load the trained model.The log is Traceback (most recent call last): File "train_speech_embedder.py", line 168, in test('speech_id_checkpoint/ckpt_epoch_840_batch_id_141.pth') File "train_speech_embedder.py", line 109, in test embedder_net.load_state_dict(torch.load(model_path)) File "/media/diskc/wq/.local/lib/python3.5/site-packages/torch/nn/modules/module.py", line 721, in load_state_dict self.class.name, "\n\t".join(error_msgs))) RuntimeError: Error(s) in loading state_dict for SpeechEmbedder: Missing key(s) in state_dict: "LSTM_stack.weight_ih_l1", "LSTM_stack.bias_hh_l1", "LSTM_stack.bias_hh_l0", "LSTM_stack.bias_ih_l0", "LSTM_stack.weight_hh_l2", "LSTM_stack.weight_hh_l1", "LSTM_stack.bias_ih_l1", "LSTM_stack.weight_ih_l0", "LSTM_stack.weight_ih_l2", "LSTM_stack.weight_hh_l0", "LSTM_stack.bias_hh_l2", "LSTM_stack.bias_ih_l2", "projection.weight", "projection.bias". Unexpected key(s) in state_dict: "module.LSTM_stack.weight_ih_l0", "module.LSTM_stack.weight_hh_l0", "module.LSTM_stack.bias_ih_l0", "module.LSTM_stack.bias_hh_l0", "module.LSTM_stack.weight_ih_l1", "module.LSTM_stack.weight_hh_l1", "module.LSTM_stack.bias_ih_l1", "module.LSTM_stack.bias_hh_l1", "module.LSTM_stack.weight_ih_l2", "module.LSTM_stack.weight_hh_l2", "module.LSTM_stack.bias_ih_l2", "module.LSTM_stack.bias_hh_l2", "module.projection.weight", "module.projection.bias".

HarryVolek commented 5 years ago
  1. Change the model_path entry in the config.yaml to the path of the model you want to use.
  2. Make sure the model parameters in the config did not change from when you trained the model.
wuqiangch commented 5 years ago

@HarryVolek Thanks for your replay.

  1. I make ture that the model parameters in the config did not change from when you trained the model.After I finished the training ,soon I did the test.
  2. I have change the model path as you said.
  3. The key "LSTM_stack.weight_ih_l1" is need,but in the saved model the key change to "module.LSTM_stack.weight_ih_l1" .What's wrong with this?
wuqiangch commented 5 years ago

I have resolve it through reloading the model and changing the keys.Thanks.