我在网上下载了一个模型,实验的时候报错
Unexpected key(s) in state_dict: "Model.nn_layers.0.pe.pe", "Model.nn_layers.1.pe.pe"
可以在加载模型时使用下面的代码将两个键跳过
from collections import OrderedDict
new_state_dict = OrderedDict()
state_dict = torch.load('Model.pth')
for k, v in state_dict.items():
name = k
if k == 'Model.nn_layers.0.pe.pe':
continue
if k == 'Model.nn_layers.1.pe.pe':
continue
new_state_dict[name] = v
net.load_state_dict(new_state_dict)
估计原因是常量的存储问题