报错信息: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)

 

相关文章:

  • 2021-04-19
  • 2021-11-03
  • 2021-09-08
  • 2021-12-17
  • 2021-08-29
  • 2021-06-16
  • 2021-04-18
  • 2021-05-24
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-07
  • 2021-09-02
  • 2022-12-23
  • 2021-09-26
  • 2021-04-07
相关资源
相似解决方案