本篇幅介绍pytorch模型转ONNX模型
一、pytorch模型保存/加载
有两种方式可用于保存/加载pytorch模型 1)文件中保存模型结构和权重参数 2)文件只保留模型权重.
1、文件中保存模型结构和权重参数
1)pytorch模型保存
import torch
torch.save(selfmodel,"save.pt")
2)pytorch模型加载
import torch
torch.load("save.pt")
2、文件只保留模型权重
1)pytorch模型保存
import torch
torch.save(selfmodel.state_dict(),"save.pt")
2)pytorch模型加载
selfmodel.load_state_dict(torch.load("save.pt"))