pytorch1.6.x及更高版本,在保存模型和低版本有区别,因此导致高版本的保存模型在低版本下加载失败的问题:
我们只需在较高版本torch下保存时,设置_use_new_zipfile_serialization=False
weights = 'xxx.pth' temp = torch.load(weights) ... data = ... #type:OrderedDict torch.save(data, 'new_model.pth', _use_new_zipfile_serialization=False)
关于data的获取不同方式保存的模型处理方式不太一致,要搞清自己的模型是怎么保存的,常见的几种保存形式可以参考我的这篇博客:
https://blog.csdn.net/qq_41368074/article/details/120812819
一个具体例子可以参考:
https://blog.csdn.net/flying_ant2018/article/details/115403774



