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


Python models.ResNet方法代码示例

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


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

示例1: resnet_multiimage_input

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import ResNet [as 别名]
def resnet_multiimage_input(num_layers, pretrained=False, num_input_images=1):
    """Constructs a ResNet model.
    Args:
        num_layers (int): Number of resnet layers. Must be 18 or 50
        pretrained (bool): If True, returns a model pre-trained on ImageNet
        num_input_images (int): Number of frames stacked as input
    """
    assert num_layers in [18, 50], "Can only run with 18 or 50 layer resnet"
    blocks = {18: [2, 2, 2, 2], 50: [3, 4, 6, 3]}[num_layers]
    block_type = {18: models.resnet.BasicBlock, 50: models.resnet.Bottleneck}[num_layers]
    model = ResNetMultiImageInput(block_type, blocks, num_input_images=num_input_images)

    if pretrained:
        loaded = model_zoo.load_url(models.resnet.model_urls['resnet{}'.format(num_layers)])
        loaded['conv1.weight'] = torch.cat(
            [loaded['conv1.weight']] * num_input_images, 1) / num_input_images
        model.load_state_dict(loaded)
    return model 
开发者ID:TRI-ML,项目名称:packnet-sfm,代码行数:20,代码来源:resnet_encoder.py

示例2: __init__

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import ResNet [as 别名]
def __init__(self, block, layers, output_dim):
        super(ResNet, self).__init__(block, layers)
        
        self.name = "ResNet"

        self.avgpool = nn.AvgPool2d((8,4), stride=1)
        self.fc = nn.Linear(512 * block.expansion, 1024)
        self.bn_fc = nn.BatchNorm1d(1024)
        self.relu_fc = nn.ReLU(inplace=True)
        self.fc_out = nn.Linear(1024, output_dim)

        for m in self.modules():
            if isinstance(m, nn.BatchNorm1d):
                m.weight.data.fill_(1)
                m.bias.data.zero_()

        self.fc_compare = nn.Linear(output_dim, 1) 
开发者ID:phil-bergmann,项目名称:tracking_wo_bnw,代码行数:19,代码来源:resnet.py

示例3: se_resnet18

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import ResNet [as 别名]
def se_resnet18(num_classes=1_000):
    """Constructs a ResNet-18 model.

    Args:
        pretrained (bool): If True, returns a model pre-trained on ImageNet
    """
    model = ResNet(SEBasicBlock, [2, 2, 2, 2], num_classes=num_classes)
    model.avgpool = nn.AdaptiveAvgPool2d(1)
    return model 
开发者ID:moskomule,项目名称:senet.pytorch,代码行数:11,代码来源:se_resnet.py

示例4: se_resnet34

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import ResNet [as 别名]
def se_resnet34(num_classes=1_000):
    """Constructs a ResNet-34 model.

    Args:
        pretrained (bool): If True, returns a model pre-trained on ImageNet
    """
    model = ResNet(SEBasicBlock, [3, 4, 6, 3], num_classes=num_classes)
    model.avgpool = nn.AdaptiveAvgPool2d(1)
    return model 
开发者ID:moskomule,项目名称:senet.pytorch,代码行数:11,代码来源:se_resnet.py

示例5: se_resnet101

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import ResNet [as 别名]
def se_resnet101(num_classes=1_000):
    """Constructs a ResNet-101 model.

    Args:
        pretrained (bool): If True, returns a model pre-trained on ImageNet
    """
    model = ResNet(SEBottleneck, [3, 4, 23, 3], num_classes=num_classes)
    model.avgpool = nn.AdaptiveAvgPool2d(1)
    return model 
开发者ID:moskomule,项目名称:senet.pytorch,代码行数:11,代码来源:se_resnet.py

示例6: se_resnet152

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import ResNet [as 别名]
def se_resnet152(num_classes=1_000):
    """Constructs a ResNet-152 model.

    Args:
        pretrained (bool): If True, returns a model pre-trained on ImageNet
    """
    model = ResNet(SEBottleneck, [3, 8, 36, 3], num_classes=num_classes)
    model.avgpool = nn.AdaptiveAvgPool2d(1)
    return model 
开发者ID:moskomule,项目名称:senet.pytorch,代码行数:11,代码来源:se_resnet.py

示例7: se_resnet20

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import ResNet [as 别名]
def se_resnet20(**kwargs):
    """Constructs a ResNet-18 model.

    """
    model = CifarSEResNet(CifarSEBasicBlock, 3, **kwargs)
    return model 
开发者ID:moskomule,项目名称:senet.pytorch,代码行数:8,代码来源:se_resnet.py

示例8: se_resnet56

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

    """
    model = CifarSEResNet(CifarSEBasicBlock, 9, **kwargs)
    return model 
开发者ID:moskomule,项目名称:senet.pytorch,代码行数:8,代码来源:se_resnet.py

示例9: se_preactresnet20

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import ResNet [as 别名]
def se_preactresnet20(**kwargs):
    """Constructs a ResNet-18 model.

    """
    model = CifarSEPreActResNet(CifarSEBasicBlock, 3, **kwargs)
    return model 
开发者ID:moskomule,项目名称:senet.pytorch,代码行数:8,代码来源:se_resnet.py

示例10: se_preactresnet32

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

    """
    model = CifarSEPreActResNet(CifarSEBasicBlock, 5, **kwargs)
    return model 
开发者ID:moskomule,项目名称:senet.pytorch,代码行数:8,代码来源:se_resnet.py

示例11: se_preactresnet56

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

    """
    model = CifarSEPreActResNet(CifarSEBasicBlock, 9, **kwargs)
    return model 
开发者ID:moskomule,项目名称:senet.pytorch,代码行数:8,代码来源:se_resnet.py

示例12: conv3x3

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import ResNet [as 别名]
def conv3x3(in_planes, out_planes, stride=1):
    return nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride, padding=1, bias=False)

# SE-ResNet Module 
开发者ID:liu-vis,项目名称:DualResidualNetworks,代码行数:6,代码来源:se_nets.py

示例13: se_resnet18

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import ResNet [as 别名]
def se_resnet18(num_classes):
    """Constructs a ResNet-18 model.

    Args:
        pretrained (bool): If True, returns a model pre-trained on ImageNet
    """
    model = ResNet(SEBasicBlock, [2, 2, 2, 2], num_classes=num_classes)
    model.avgpool = nn.AdaptiveAvgPool2d(1)
    return model 
开发者ID:nerox8664,项目名称:pytorch2keras,代码行数:11,代码来源:senet.py

示例14: se_resnet34

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import ResNet [as 别名]
def se_resnet34(num_classes):
    """Constructs a ResNet-34 model.

    Args:
        pretrained (bool): If True, returns a model pre-trained on ImageNet
    """
    model = ResNet(SEBasicBlock, [3, 4, 6, 3], num_classes=num_classes)
    model.avgpool = nn.AdaptiveAvgPool2d(1)
    return model 
开发者ID:nerox8664,项目名称:pytorch2keras,代码行数:11,代码来源:senet.py

示例15: se_resnet50

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import ResNet [as 别名]
def se_resnet50(num_classes):
    """Constructs a ResNet-50 model.

    Args:
        pretrained (bool): If True, returns a model pre-trained on ImageNet
    """
    model = ResNet(SEBottleneck, [3, 4, 6, 3], num_classes=num_classes)
    model.avgpool = nn.AdaptiveAvgPool2d(1)
    return model 
开发者ID:nerox8664,项目名称:pytorch2keras,代码行数:11,代码来源:senet.py


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