第一种 保存整个模型文件 html
# 保存和加载整个模型 torch.save(model_object, 'model.pth') model = torch.load('model.pth')
第二种 仅保存模型的权重 ide
# 仅保存和加载模型参数(推荐使用) torch.save(model_object.state_dict(), 'weights.pth') model.load_state_dict(torch.load('weights.pth'))