pytorch版本问题RuntimeError: params/unet.pth is a zip archive (did you mean to use torch.jit.load()?)
问题描述:
代码用cpu跑起来是对的,换成gpu的pytorch后,报上面这个错误
搜索后发现加载pth这个是pytorch1.6版本及以上用的,我的是1.2版本的,所以会报错。但也不能随便升级吧,毕竟要和cuda对应。
解决方法:
换一种保存模型的方法(保存整个模型)
自己看着对应的保存和读取的地方改一下,the_model把自己的模型换上去
#保存
torch.save(the_model, PATH)
#读取
the_model = torch.load(PATH)