Traceback (most recent call last):
File "/content/drive/MyDrive/main/test.py", line 193, in <module>
main()
File "/content/drive/MyDrive/main/test.py", line 187, in main
model.load_state_dict(torch.load(args.pretrained, map_location='cpu'))
File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py", line 2041, in load_state_dict
raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format(
RuntimeError: Error(s) in loading state_dict for Net:
Missing key(s) in state_dict:
Unexpected key(s) in state_dict:
在用训练好的模型进行测试时,遇到RuntimeError 应该怎么解决?
尝试将model.load_state_dict(checkpoint['model'])
改为model.load_state_dict(checkpoint['model'],strict=False)
或model.load_state_dict(checkpoint['model'],False)
还是出现同样的报错