使用torch.load_state_dict()出现的问题
model_path='./文件夹/文件名.pth'
model = SPPNet()
model.load_state_dict(torch.load(model_path))
报错
torch.nn.modules.module.ModuleAttributeError: 'SPPNet' object has no attribute 'copy'
经过查询资料发现问题出现在训练模型的代码中,在保存模型时,使用的是
torch.save(model, path)
应该使用
torch.save(model.state_dict(), path)
这样的话,程序就可以正确运行了。