AttributeError: '_IncompatibleKeys' object has no attribute 'features'

原代码

model = vgg19(pretrained=False)
        model.load_state_dict(torch.load('vgg19-dcbb9e9d.pth'))
        
        self.model = nn.Sequential(*list(model.features)[:16])

改成下面这样,就成功了

model = vgg19(pretrained=False)
        model.load_state_dict(torch.load('vgg19-dcbb9e9d.pth'))
        
        self.model = nn.Sequential(*list(model.features.children())[:16])

你可能感兴趣的:(Bugs)