import torch
import torchvision
from torch import nn
vgg16 = torchvision.models.vgg16(pretrained=False)
torch.save(vgg16, "vgg16_method1.pth")
torch.save(vgg16.state_dict(), "vgg16_method2.pth")
class TuDui(nn.Module):
def __init__(self):
super().__init__()
self.conv1 = nn.Conv2d(3, 64, kernel_size=3)
def forward(self, x):
x = self.conv1(x)
return x
tudui = TuDui()
torch.save(tudui, "tudui_method1.pth")
import torch
import torchvision
from torch import nn
model = torch.load("vgg16_method1.pth")
print(model)
vgg16 = torchvision.models.vgg16(pretrained=False)
print(torch.load("vgg16_method2.pth"))
vgg16.load_state_dict(torch.load("vgg16_method2.pth"))
print(vgg16)
class TuDui(nn.Module):
def __init__(self):
super().__init__()
self.conv1 = nn.Conv2d(3, 64, kernel_size=3)
def forward(self, x):
x = self.conv1(x)
return x
model = torch.load("tudui_method1.pth")
print(model)