當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。