尝试使用torch.load(PATH)加载ResNet 18预训练模型,但遇到Unicode解码错误,请帮忙。
Traceback (most recent call last):
File "main.py", line 312, in <module>
main()
File "main.py", line 138, in main
checkpoint = torch.load(args.resume)
File "F:\InsSoft\Anaconda\lib\site-packages\torch\serialization.py", line 593, in load
return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
File "F:\InsSoft\Anaconda\lib\site-packages\torch\serialization.py", line 773, in _legacy_load
result = unpickler.load()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbe in position 2: invalid start byte
答案 0 :(得分:0)
每当模型在 Torch 版本 < 0.4
上进行预训练但使用 Torch 版本 > 0.4
进行测试/恢复时,就会出现此错误。
所以使用 checkpoint = torch.load(args.resume,encoding='latin1')