錯誤原因:
訓練保存模型時,torch的版本是1.6.0(使用torch.__version__可以查看torch的版本號)
而加載模型時,torch的版本號低於1.6.0
解決方案:
If for any reason you want torch.save to use the old format, pass the kwarg _use_new_zipfile_serialization=False.
在訓練時更改參數“_use_new_zipfile_serialization=False”,
torch.save(model.state_dict(), model_cp,_use_new_zipfile_serialization=False) # 訓練所有數據后,保存網絡的參數
參考:https://blog.csdn.net/weixin_44769214/article/details/108188126