以下两种方法已经用不了
- vgg16_false = torchvision.models.vgg16(pretrained=False)
- vgg16_true = torchvision.models.vgg16(pretrained=True)
复制代码 改为
- vgg16_model0 = vgg16(weights=None) #vgg16_false
- vgg16_model1 = vgg16(weights=VGG16_Weights.DEFAULT) # pretrained vgg16_true
复制代码- import torchvisionfrom torch import nnfrom torchvision.models import vgg16, VGG16_Weights# 以下表明的两行用不了,现在更新了新方法# vgg16_false = torchvision.models.vgg16(pretrained=False) # vgg16_true = torchvision.models.vgg16(pretrained=True)vgg16_model0 = vgg16(weights=None) #vgg16_false
- vgg16_model1 = vgg16(weights=VGG16_Weights.DEFAULT) # pretrained vgg16_true# vgg16_model2 = vgg16(weights=VGG16_Weights.IMAGENET1K_V1) # 代表利用IMAGENET1K_V1方法训练# print(vgg16_model1)train_data = torchvision.datasets.CIFAR10(root='./dataset', train=False, transform=torchvision.transforms.ToTensor(), download=True)print('---------------增加一层-------------------------------------------------- ----')# vgg16_model1.add_module('add_liner', nn.Linear(1000, 10))# print(vgg16_model1)print('--------------在classifier里-增加一层--------------------------------- -----------')vgg16_model1.classifier.add_module('add_liner', nn.Linear(1000, 10))print(vgg16_model1)print('-------------------未修改的vgg16--------------------------------------------------')print(vgg16_model0)print('-------------------将vgg16的classifier的第6层进行修改-------------------------------')vgg16_model0.classifier[6] = nn.Linear(4096, 10)print(vgg16_model0)
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |