赞
踩
1.AttributeError: ‘VGG’ object has no attribute 'fc’错误
解决:fc换成classifier[6],并且带【索引】,索引值可以直接打印模型看到结构层
model= models.vgg16(pretrained=True) for param in model.parameters(): #params have requires_grad=True by default param.requires_grad = False num_ftrs = model.fc.in_features
2.element 0 of tensors does not require grad and does not have a grad_fn 错误
解决:这是数据出现错误,需要设置批数据的requires_grad值 data=Variable(data,requires_grad=True),标签值y则不用
for i,(data,y) in enumerate(train_loader):
data=Variable(data,requires_grad=True)
# y=Variable(y,requires_grad=True)
print(data.requires_grad)
数据结构,
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。