当前位置:网站首页>【Bug解决】UnpicklingError: A load persistent id instruction was encountered, but no persistent_load.

【Bug解决】UnpicklingError: A load persistent id instruction was encountered, but no persistent_load.

2022-06-11 19:29:00 zstar-_

问题环境

在将pytorch本地训练好的模型,传到jetson nano平台上,加载模型时,报了这个错误:

UnpicklingError: A load persistent id instruction was encountered, but no persistent_load.

问题原因

查阅相关资料,这是由于pytorch在1.6.0版本之后,模型保存默认方式是压缩的形式,而在jetson nano版本上的pytorch版本是1.0.0,因此无法直接加载.pth文件。
用下面的方式可以查看pytorch的版本:

import torch
print(torch.__version__)

问题解决

设置保存模型时不进行压缩,即修改保存模型语句为:

torch.save(model.state_dict(), MODEL_PATH, _use_new_zipfile_serialization=False)
原网站

版权声明
本文为[zstar-_]所创,转载请带上原文链接,感谢
https://zstar.blog.csdn.net/article/details/125235147