当前位置: 首页>>代码示例>>Python>>正文


Python models.resnet34方法代码示例

本文整理汇总了Python中torchvision.models.resnet34方法的典型用法代码示例。如果您正苦于以下问题:Python models.resnet34方法的具体用法?Python models.resnet34怎么用?Python models.resnet34使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在torchvision.models的用法示例。


在下文中一共展示了models.resnet34方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import resnet34 [as 别名]
def __init__(self, sinc_out, hidden_dim, sinc_kernel=251, sinc_stride=1, conv_stride=5, kernel_size=21, pretrained=True,name="Resnet50"):
        super().__init__(name=name)
        self.sinc = SincConv_fast(1, sinc_out, sinc_kernel,
                                  sample_rate=16000,
                                  padding='SAME',
                                  stride=sinc_stride,
                                  pad_mode='reflect'
                                  )

        self.conv1 = nn.Sequential(nn.Conv2d(1, 64, kernel_size=kernel_size, stride=conv_stride, padding= kernel_size // 2, bias=False),
                                   nn.BatchNorm2d(64),
                                   nn.ReLU(64))

        resnet = models.resnet34(pretrained=pretrained)
        self.resnet = nn.Sequential(resnet.layer1,
                                    resnet.layer2,
                                    resnet.layer3,
                                    resnet.layer4
                                    )

        self.conv2 = nn.Sequential(nn.Conv2d(512, 256, kernel_size=[2, 1], stride=1, bias=False))

        self.emb_dim = hidden_dim 
开发者ID:santi-pdp,项目名称:pase,代码行数:25,代码来源:frontend.py

示例2: __init__

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import resnet34 [as 别名]
def __init__(self, num_layers, pretrained, num_input_images=1):
        super(ResnetEncoder, self).__init__()

        self.num_ch_enc = np.array([64, 64, 128, 256, 512])

        resnets = {18: models.resnet18,
                   34: models.resnet34,
                   50: models.resnet50,
                   101: models.resnet101,
                   152: models.resnet152}

        if num_layers not in resnets:
            raise ValueError("{} is not a valid number of resnet layers".format(num_layers))

        if num_input_images > 1:
            self.encoder = resnet_multiimage_input(num_layers, pretrained, num_input_images)
        else:
            self.encoder = resnets[num_layers](pretrained)

        if num_layers > 34:
            self.num_ch_enc[1:] *= 4 
开发者ID:TRI-ML,项目名称:packnet-sfm,代码行数:23,代码来源:resnet_encoder.py

示例3: __init__

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import resnet34 [as 别名]
def __init__(self, model_id, project_dir):
        super(ImgNet, self).__init__()

        self.model_id = model_id
        self.project_dir = project_dir
        self.create_model_dirs()

        resnet34 = models.resnet34()
        # load pretrained model:
        resnet34.load_state_dict(torch.load("/root/3DOD_thesis/pretrained_models/resnet/resnet34-333f7ec4.pth"))
        # remove fully connected layer:
        self.resnet34 = nn.Sequential(*list(resnet34.children())[:-2])

        self.avg_pool = nn.AvgPool2d(kernel_size=7)

        self.fc1 = nn.Linear(512, 256)
        self.fc2 = nn.Linear(256, 128)
        self.fc3 = nn.Linear(128, 2*8 + 3 + 1) 
开发者ID:fregu856,项目名称:3DOD_thesis,代码行数:20,代码来源:imgnet.py

示例4: resnet34_ids_pre

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import resnet34 [as 别名]
def resnet34_ids_pre(num_attributes, ids_embedding_size, **kwargs):
    """Constructs a ResNet-34 model.

    Args:
        pretrained (bool): If True, returns a model pre-trained on ImageNet
    """

    model = zoo.resnet34(pretrained=True)

    for param in model.parameters():
        param.requires_grad = False
    # Remove the last fully-connected layer
    # Parameters of newly constructed modules have requires_grad=True by default

    model = nn.Sequential(*list(model.children())[:-1])

    classifier_attr = ResNetClassifier(BasicBlock, num_classes=num_attributes, **kwargs)
    classifier_ids = ResNetClassifier(BasicBlock, num_classes=ids_embedding_size, **kwargs)

    return model, classifier_attr, classifier_ids 
开发者ID:leokarlin,项目名称:LaSO,代码行数:22,代码来源:resnet.py

示例5: __init__

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import resnet34 [as 别名]
def __init__(self, num_layers):
        super(ResNet_BasicBlock_OS16, self).__init__()

        if num_layers == 18:
            resnet = models.resnet18()
            # load pretrained model:
            resnet.load_state_dict(torch.load("/root/deeplabv3/pretrained_models/resnet/resnet18-5c106cde.pth"))
            # remove fully connected layer, avg pool and layer5:
            self.resnet = nn.Sequential(*list(resnet.children())[:-3])

            num_blocks = 2
            print ("pretrained resnet, 18")
        elif num_layers == 34:
            resnet = models.resnet34()
            # load pretrained model:
            resnet.load_state_dict(torch.load("/root/deeplabv3/pretrained_models/resnet/resnet34-333f7ec4.pth"))
            # remove fully connected layer, avg pool and layer5:
            self.resnet = nn.Sequential(*list(resnet.children())[:-3])

            num_blocks = 3
            print ("pretrained resnet, 34")
        else:
            raise Exception("num_layers must be in {18, 34}!")

        self.layer5 = make_layer(BasicBlock, in_channels=256, channels=512, num_blocks=num_blocks, stride=1, dilation=2) 
开发者ID:fregu856,项目名称:deeplabv3,代码行数:27,代码来源:resnet.py

示例6: __init__

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import resnet34 [as 别名]
def __init__(self, requires_grad=False, pretrained=True, num=18):
        super(resnet, self).__init__()
        if(num==18):
            self.net = tv.resnet18(pretrained=pretrained)
        elif(num==34):
            self.net = tv.resnet34(pretrained=pretrained)
        elif(num==50):
            self.net = tv.resnet50(pretrained=pretrained)
        elif(num==101):
            self.net = tv.resnet101(pretrained=pretrained)
        elif(num==152):
            self.net = tv.resnet152(pretrained=pretrained)
        self.N_slices = 5

        self.conv1 = self.net.conv1
        self.bn1 = self.net.bn1
        self.relu = self.net.relu
        self.maxpool = self.net.maxpool
        self.layer1 = self.net.layer1
        self.layer2 = self.net.layer2
        self.layer3 = self.net.layer3
        self.layer4 = self.net.layer4 
开发者ID:richzhang,项目名称:PerceptualSimilarity,代码行数:24,代码来源:pretrained_networks.py

示例7: __init__

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import resnet34 [as 别名]
def __init__(self, requires_grad=False, pretrained=True, num=18):
        super(resnet, self).__init__()
        if(num==18):
            self.net = models.resnet18(pretrained=pretrained)
        elif(num==34):
            self.net = models.resnet34(pretrained=pretrained)
        elif(num==50):
            self.net = models.resnet50(pretrained=pretrained)
        elif(num==101):
            self.net = models.resnet101(pretrained=pretrained)
        elif(num==152):
            self.net = models.resnet152(pretrained=pretrained)
        self.N_slices = 5

        self.conv1 = self.net.conv1
        self.bn1 = self.net.bn1
        self.relu = self.net.relu
        self.maxpool = self.net.maxpool
        self.layer1 = self.net.layer1
        self.layer2 = self.net.layer2
        self.layer3 = self.net.layer3
        self.layer4 = self.net.layer4 
开发者ID:thunil,项目名称:TecoGAN,代码行数:24,代码来源:pretrained_networks.py

示例8: __init__

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import resnet34 [as 别名]
def __init__(self, requires_grad=False, pretrained=True, num=18):
        super(resnet, self).__init__()
        if (num == 18):
            self.net = models.resnet18(pretrained=pretrained)
        elif (num == 34):
            self.net = models.resnet34(pretrained=pretrained)
        elif (num == 50):
            self.net = models.resnet50(pretrained=pretrained)
        elif (num == 101):
            self.net = models.resnet101(pretrained=pretrained)
        elif (num == 152):
            self.net = models.resnet152(pretrained=pretrained)
        self.N_slices = 5

        self.conv1 = self.net.conv1
        self.bn1 = self.net.bn1
        self.relu = self.net.relu
        self.maxpool = self.net.maxpool
        self.layer1 = self.net.layer1
        self.layer2 = self.net.layer2
        self.layer3 = self.net.layer3
        self.layer4 = self.net.layer4 
开发者ID:BCV-Uniandes,项目名称:SMIT,代码行数:24,代码来源:pretrained_networks.py

示例9: __init__

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import resnet34 [as 别名]
def __init__(self, layers, atrous, pretrained=True):
		super(ResNet, self).__init__()
		self.inner_layer = []
		if layers == 18:
			self.backbone = models.resnet18(pretrained=pretrained)
		elif layers == 34:
			self.backbone = models.resnet34(pretrained=pretrained)
		elif layers == 50:
			self.backbone = models.resnet50(pretrained=pretrained)
		elif layers == 101:
			self.backbone = models.resnet101(pretrained=pretrained)
		elif layers == 152:
			self.backbone = models.resnet152(pretrained=pretrained)
		else:
			raise ValueError('resnet.py: network layers is no support yet')
		
		def hook_func(module, input, output):
			self.inner_layer.append(output)

		self.backbone.layer1.register_forward_hook(hook_func)	
		self.backbone.layer2.register_forward_hook(hook_func)
		self.backbone.layer3.register_forward_hook(hook_func)
		self.backbone.layer4.register_forward_hook(hook_func) 
开发者ID:YudeWang,项目名称:deeplabv3plus-pytorch,代码行数:25,代码来源:resnet.py

示例10: __init__

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import resnet34 [as 别名]
def __init__(self):
        super(ResNet34Fc, self).__init__()
        model_resnet34 = models.resnet34(pretrained=True)
        self.conv1 = model_resnet34.conv1
        self.bn1 = model_resnet34.bn1
        self.relu = model_resnet34.relu
        self.maxpool = model_resnet34.maxpool
        self.layer1 = model_resnet34.layer1
        self.layer2 = model_resnet34.layer2
        self.layer3 = model_resnet34.layer3
        self.layer4 = model_resnet34.layer4
        self.avgpool = model_resnet34.avgpool
        self.__in_features = model_resnet34.fc.in_features 
开发者ID:jindongwang,项目名称:transferlearning,代码行数:15,代码来源:backbone.py

示例11: __init__

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import resnet34 [as 别名]
def __init__(self):
        super(ResNet34Fc, self).__init__()
        model_resnet34 = models.resnet34(pretrained=True)
        self.conv1 = model_resnet34.conv1
        self.bn1 = model_resnet34.bn1
        self.relu = model_resnet34.relu
        self.maxpool = model_resnet34.maxpool
        self.layer1 = model_resnet34.layer1
        self.layer2 = model_resnet34.layer2
        self.layer3 = model_resnet34.layer3
        self.layer4 = model_resnet34.layer4
        self.avgpool = model_resnet34.avgpool 
开发者ID:jindongwang,项目名称:transferlearning,代码行数:14,代码来源:backbone.py

示例12: resnet34

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import resnet34 [as 别名]
def resnet34(num_classes=1000, pretrained='imagenet'):
    """Constructs a ResNet-34 model.
    """
    model = models.resnet34(pretrained=False, num_classes=num_classes)
    if pretrained is not None:
        settings = pretrained_settings['resnet34'][pretrained]
        model = load_pretrained(model, num_classes, settings)
    model = modify_resnets(model)
    return model 
开发者ID:alexandonian,项目名称:pretorched-x,代码行数:11,代码来源:torchvision_models.py

示例13: test_train_step

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import resnet34 [as 别名]
def test_train_step(self):
        # test that the model can be run in a train step
        model = models.resnet34(pretrained=False)
        classy_model = ClassyModel.from_model(model)

        config = get_fast_test_task_config()
        task = build_task(config)
        task.set_model(classy_model)
        trainer = LocalTrainer()
        trainer.train(task) 
开发者ID:facebookresearch,项目名称:ClassyVision,代码行数:12,代码来源:models_classy_model_test.py

示例14: _load_pytorch_model

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import resnet34 [as 别名]
def _load_pytorch_model(model_name, summary):
    import torchvision.models as models
    switcher = {
        'alexnet': lambda: models.alexnet(pretrained=True).eval(),
        "vgg11": lambda: models.vgg11(pretrained=True).eval(),
        "vgg11_bn": lambda: models.vgg11_bn(pretrained=True).eval(),
        "vgg13": lambda: models.vgg13(pretrained=True).eval(),
        "vgg13_bn": lambda: models.vgg13_bn(pretrained=True).eval(),
        "vgg16": lambda: models.vgg16(pretrained=True).eval(),
        "vgg16_bn": lambda: models.vgg16_bn(pretrained=True).eval(),
        "vgg19": lambda: models.vgg19(pretrained=True).eval(),
        "vgg19_bn": lambda: models.vgg19_bn(pretrained=True).eval(),
        "resnet18": lambda: models.resnet18(pretrained=True).eval(),
        "resnet34": lambda: models.resnet34(pretrained=True).eval(),
        "resnet50": lambda: models.resnet50(pretrained=True).eval(),
        "resnet101": lambda: models.resnet101(pretrained=True).eval(),
        "resnet152": lambda: models.resnet152(pretrained=True).eval(),
        "squeezenet1_0": lambda: models.squeezenet1_0(pretrained=True).eval(),
        "squeezenet1_1": lambda: models.squeezenet1_1(pretrained=True).eval(),
        "densenet121": lambda: models.densenet121(pretrained=True).eval(),
        "densenet161": lambda: models.densenet161(pretrained=True).eval(),
        "densenet201": lambda: models.densenet201(pretrained=True).eval(),
        "inception_v3": lambda: models.inception_v3(pretrained=True).eval(),
    }

    _load_model = switcher.get(model_name, None)
    _model = _load_model()
    import torch
    if torch.cuda.is_available():
        _model = _model.cuda()
    from perceptron.models.classification.pytorch import PyTorchModel as ClsPyTorchModel
    import numpy as np
    mean = np.array([0.485, 0.456, 0.406]).reshape((3, 1, 1))
    std = np.array([0.229, 0.224, 0.225]).reshape((3, 1, 1))
    pmodel = ClsPyTorchModel(
        _model, bounds=(
            0, 1), num_classes=1000, preprocessing=(
            mean, std))
    return pmodel 
开发者ID:advboxes,项目名称:perceptron-benchmark,代码行数:41,代码来源:tools.py

示例15: load_pytorch_model

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import resnet34 [as 别名]
def load_pytorch_model(model_name):
    import torchvision.models as models
    switcher = {
        'alexnet': lambda: models.alexnet(pretrained=True).eval(),
        "vgg11": lambda: models.vgg11(pretrained=True).eval(),
        "vgg11_bn": lambda: models.vgg11_bn(pretrained=True).eval(),
        "vgg13": lambda: models.vgg13(pretrained=True).eval(),
        "vgg13_bn": lambda: models.vgg13_bn(pretrained=True).eval(),
        "vgg16": lambda: models.vgg16(pretrained=True).eval(),
        "vgg16_bn": lambda: models.vgg16_bn(pretrained=True).eval(),
        "vgg19": lambda: models.vgg19(pretrained=True).eval(),
        "vgg19_bn": lambda: models.vgg19_bn(pretrained=True).eval(),
        "resnet18": lambda: models.resnet18(pretrained=True).eval(),
        "resnet34": lambda: models.resnet34(pretrained=True).eval(),
        "resnet50": lambda: models.resnet50(pretrained=True).eval(),
        "resnet101": lambda: models.resnet101(pretrained=True).eval(),
        "resnet152": lambda: models.resnet152(pretrained=True).eval(),
        "squeezenet1_0": lambda: models.squeezenet1_0(pretrained=True).eval(),
        "squeezenet1_1": lambda: models.squeezenet1_1(pretrained=True).eval(),
        "densenet121": lambda: models.densenet121(pretrained=True).eval(),
        "densenet161": lambda: models.densenet161(pretrained=True).eval(),
        "densenet201": lambda: models.densenet201(pretrained=True).eval(),
        "inception_v3": lambda: models.inception_v3(pretrained=True).eval(),
    }

    _load_model = switcher.get(model_name, None)
    _model = _load_model()
    return _model 
开发者ID:advboxes,项目名称:perceptron-benchmark,代码行数:30,代码来源:tools.py


注:本文中的torchvision.models.resnet34方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。