pytorch--报错 AttributeError: ‘Net’ object has no attribute ‘copy’


报错信息:AttributeError: ‘Net’ object has no attribute ‘copy’

 

分析:报错是发生在加载预训练模型时,很可能时两种pytorch加载预训练模型方式弄混了。

解决:按照下面思路加载预训练模型就好。

1.保存加载state_dict方式(推荐)

保存:torch.save(model.state_dict(), PATH) # 推荐的文件后缀名是pt或pth

加载:model = TheModelClass(*args, **kwargs)

      model.load_state_dict(torch.load(PATH))

 2.保存加载整个模型

保存:torch.save(model, PATH)

加载:model = torch.load(PATH)

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM