• 运行torch.load(‘xxx.pth’)报错:
RuntimeError: xxx.pth is a zip archive(did you mean to use torch.jit.load()?)
  • 出错原因:
    xxx.pth是由PyTorch1.6或更高版本生成的模型。1.6之后pytorch默认使用zip文件格式来保存权重文件,导致这些权重文件无法直接被1.5及以下的pytorch加载。

  • 解决方法
    在PyTorch1.6或更高版本的PyTorch下,运行一下代码,来转换模型

state_dict = torch.load("xxx.pth")
torch.save(state_dict, "xxx.pth", _use_new_zipfile_serialization=False)
  • 参考
    https://blog.csdn.net/weixin_44769214/article/details/108188126
Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐