import torch
import torchvision
from torch import nn
vgg16 = torchvision.models.vgg16(pretrained=False)
torch.save(vgg16, "D:/PyCharm/vgg16model/vgg16_mothod1.pth")
print(vgg16)
model1 = torch.load("D:/PyCharm/vgg16model/vgg16_mothod1.pth")
print(model1)
torch.save(vgg16.state_dict(), "D:/PyCharm/vgg16model/vgg16_mothod2.pth")
print(vgg16)
model2 = torch.load("D:/PyCharm/vgg16model/vgg16_mothod2.pth")
print(model2)
vgg16.load_state_dict(torch.load("D:/PyCharm/vgg16model/vgg16_mothod2.pth"))
print(vgg16)
class Net(nn.Module):
def __init__(self):
super(Net, self).__init__()
self.conv1 = nn.Conv2d(3, 64, kernel_size=3)
def forward(self, x):
x = self.conv1(x)
return x
net = Net()
torch.save(net, "D:/PyCharm/vgg16model/net_mothod1.pth")
net1 = torch.load("D:/PyCharm/vgg16model/net_mothod1.pth")
print(net1)