在获取vgg16网络模型参数时,获取会出错
vgg16_false = torchvision.models.vgg16(pretrained=False)
vgg16_true = torchvision.models.vgg16(pretrained=True)
修改成:
vgg16_false = torchvision.models.vgg16(weights=None)
vgg16_true = torchvision.models.vgg16(weights=VGG16_Weights.DEFAULT)
错误原因:参数pretrained自0.13起已弃用,将在0.15后删除,要改用“weights”。
Vgg16相关代码
import torchvision
from torch import nn
from torchvision.models import VGG16_Weights
vgg16_false = torchvision.models.vgg16(weights=None)
vgg16_true = torchvision.models.vgg16(weights=VGG16_Weights.DEFAULT)
print(vgg16_true)
train_data=torchvision.datasets.CIFAR10('../data',train=True,transform=torchvision.transforms.ToTensor(),
download=True)
# vgg16_true.add_module('add_linear',nn.Linear(1000,10))
vgg16_true.classifier.add_module('add_linear',nn.Linear(1000,10))
print(vgg16_true)
print(vgg16_false)
vgg16_false.classifier[6]=nn.Linear(4096,10)
print(vgg16_false)