Python torchvision.models 模块,resnet34() 实例源码

我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用torchvision.models.resnet34()

项目:voc_classification    作者:HyeonwooNoh    | 项目源码 | 文件源码
def GetPretrainedModel(params, num_classes):
    if params['model'] == 'resnet18':
        model = models.resnet18(pretrained=True)
    elif params['model'] == 'resnet34':
        model = models.resnet34(pretrained=True)
    elif params['model'] == 'resnet50':
        model = models.resnet50(pretrained=True)
    elif params['model'] == 'resnet101':
        model = models.resnet101(pretrained=True)
    elif params['model'] == 'resnet152':
        model = models.resnet152(pretrained=True)
    else:
        raise ValueError('Unknown model type')
    num_features = model.fc.in_features
    model.fc = SigmoidLinear(num_features, num_classes)
    return model
项目:weldon.resnet.pytorch    作者:durandtibo    | 项目源码 | 文件源码
def resnet34_weldon(num_classes, pretrained=True, kmax=1, kmin=None):
    model = models.resnet34(pretrained)
    pooling = WeldonPool2d(kmax, kmin)
    return ResNetWSL(model, num_classes, pooling=pooling)
项目:PytorchDL    作者:FredHuangBia    | 项目源码 | 文件源码
def __init__(self, opt):
        super().__init__()
        self.opt = opt

        if opt.netSpec == 'resnet101':
            resnet = models.resnet101(pretrained=opt.pretrain)
        elif opt.netSpec == 'resnet50':
            resnet = models.resnet50(pretrained=opt.pretrain)
        elif opt.netSpec == 'resnet34':
            resnet = models.resnet34(pretrained=opt.pretrain)

        self.conv1 = resnet.conv1
        self.layer1 = resnet.layer1
        self.layer2 = resnet.layer2
        self.layer3 = resnet.layer3
        self.layer4 = resnet.layer4

        for m in self.modules():
            if isinstance(m, nn.Conv2d):
                # m.stride = 1
                m.requires_grad = False
            if isinstance(m, nn.BatchNorm2d):
                m.requires_grad = False

        self.layer5a = PSPDec(512, 128, (1,1))
        self.layer5b = PSPDec(512, 128, (2,2))
        self.layer5c = PSPDec(512, 128, (3,3))
        self.layer5d = PSPDec(512, 128, (6,6))

        self.final = nn.Sequential(
            nn.Conv2d(512*2, 512, 3, padding=1, bias=False),
            nn.BatchNorm2d(512, momentum=.95),
            nn.ReLU(inplace=True),
            nn.Dropout(.1),
            nn.Conv2d(512, opt.numClasses, 1),
        )
项目:pretrained-models.pytorch    作者:Cadene    | 项目源码 | 文件源码
def resnet34(num_classes=1000, pretrained='imagenet'):
    """Constructs a ResNet-34 model.
    """
    model = models.resnet34(pretrained=False)
    if pretrained is not None:
        settings = pretrained_settings['resnet34'][pretrained]
        model = load_pretrained(model, num_classes, settings)
    model = modify_resnets(model)
    return model