Traceback (most recent call last): File "ause_model.py", line 82, in <module> model = load_model('./client_1_main_global_model.pth') File "ause_model.py", line 78, in load_model model.load_state_dict(torch.load(model_path)) File "//site-packages/torch/nn/modules/module.py", line 1482, in load_state_dict raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format( RuntimeError: Error(s) in loading state_dict for MyLSTM: Missing key(s) in state_dict: "rnn.weight_ih_l0", "rnn.weight_hh_l0", "rnn.bias_ih_l0", "rnn.bias_hh_l0", "rnn.weight_ih_l0_reverse", "rnn.weight_hh_l0_reverse", "rnn.bias_ih_l0_reverse", "rnn.bias_hh_l0_reverse", "output_layer.weight", "output_layer.bias". Unexpected key(s) in state_dict: "cur_round", "model".
I want to use my saving model , but i get error:
Traceback (most recent call last): File "ause_model.py", line 82, in <module> model = load_model('./client_1_main_global_model.pth') File "ause_model.py", line 78, in load_model model.load_state_dict(torch.load(model_path)) File "//site-packages/torch/nn/modules/module.py", line 1482, in load_state_dict raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format( RuntimeError: Error(s) in loading state_dict for MyLSTM: Missing key(s) in state_dict: "rnn.weight_ih_l0", "rnn.weight_hh_l0", "rnn.bias_ih_l0", "rnn.bias_hh_l0", "rnn.weight_ih_l0_reverse", "rnn.weight_hh_l0_reverse", "rnn.bias_ih_l0_reverse", "rnn.bias_hh_l0_reverse", "output_layer.weight", "output_layer.bias". Unexpected key(s) in state_dict: "cur_round", "model".
here is my code: `class MyLSTM(nn.Module): def init(self, in_channels, hidden, out_channels, n_layers=1, embed_size=8, dropout=.0): super(MyLSTM, self).init() self.in_channels = in_channels self.hidden = hidden self.embed_size = embed_size self.out_channels = out_channels self.n_layers = n_layers
加载模型
model = torch.load('final_main_global_model.pth')
def load_model(model_path):
创建一个与预训练模型相同结构的实例
model = load_model('./client_1_main_global_model.pth')
i = 0 model.eval() with torch.no_grad(): for data, target in eval_loader: if (i == 100): break
data = data.unsqueeze(1)