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


Python models.densenet161方法代码示例

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


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

示例1: densenet161

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import densenet161 [as 别名]
def densenet161(num_classes=1000, pretrained='imagenet'):
    r"""Densenet-161 model from
    `"Densely Connected Convolutional Networks" <https://arxiv.org/pdf/1608.06993.pdf>`
    """
    model = models.densenet161(num_classes=num_classes, pretrained=False)
    if pretrained is not None:
       # '.'s are no longer allowed in module names, but pervious _DenseLayer
        # has keys 'norm.1', 'relu.1', 'conv.1', 'norm.2', 'relu.2', 'conv.2'.
        # They are also in the checkpoints in model_urls. This pattern is used
        # to find such keys.
        settings = pretrained_settings['densenet161'][pretrained]
        pattern = re.compile(
            r'^(.*denselayer\d+\.(?:norm|relu|conv))\.((?:[12])\.(?:weight|bias|running_mean|running_var))$')
        state_dict = model_zoo.load_url(settings['url'])
        for key in list(state_dict.keys()):
            res = pattern.match(key)
            if res:
                new_key = res.group(1) + res.group(2)
                state_dict[new_key] = state_dict[key]
                del state_dict[key]
        model.load_state_dict(state_dict)
    model = modify_densenets(model)
    return model

###############################################################
# InceptionV3 
开发者ID:alexandonian,项目名称:pretorched-x,代码行数:28,代码来源:torchvision_models.py

示例2: Dense169

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import densenet161 [as 别名]
def Dense169(config):
    return models.densenet161(pretrained=True) 
开发者ID:ngessert,项目名称:isic2019,代码行数:4,代码来源:models.py

示例3: _load_pytorch_model

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import densenet161 [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

示例4: load_pytorch_model

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import densenet161 [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

示例5: dn161

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import densenet161 [as 别名]
def dn161(pre): return children(densenet161(pre))[0] 
开发者ID:alecrubin,项目名称:pytorch-serverless,代码行数:3,代码来源:torch_imports.py

示例6: densenet161

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import densenet161 [as 别名]
def densenet161(num_classes=1000, pretrained='imagenet'):
    r"""Densenet-161 model from
    `"Densely Connected Convolutional Networks" <https://arxiv.org/pdf/1608.06993.pdf>`
    """
    model = models.densenet161(pretrained=False)
    if pretrained is not None:
        settings = pretrained_settings['densenet161'][pretrained]
        model = load_pretrained(model, num_classes, settings)
    model = modify_densenets(model)
    return model

###############################################################
# InceptionV3 
开发者ID:Cadene,项目名称:pretrained-models.pytorch,代码行数:15,代码来源:torchvision_models.py

示例7: __init__

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import densenet161 [as 别名]
def __init__(self,option = 'densenet201',pret=True):
        super(DenseBase, self).__init__()
        self.dim = 2048
        if option == 'densenet201':
            model_ft = models.densenet201(pretrained=pret)
            self.dim = 1920
        if option == 'densenet161':
            model_ft = models.densenet161(pretrained=pret)
            self.dim = 2208
        mod = list(model_ft.children())
        #mod.pop()

        self.features = nn.Sequential(*mod) 
开发者ID:mil-tokyo,项目名称:MCD_DA,代码行数:15,代码来源:basenet.py


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