當前位置: 首頁>>代碼示例>>Python>>正文


Python resnet.Bottleneck方法代碼示例

本文整理匯總了Python中torchvision.models.resnet.Bottleneck方法的典型用法代碼示例。如果您正苦於以下問題:Python resnet.Bottleneck方法的具體用法?Python resnet.Bottleneck怎麽用?Python resnet.Bottleneck使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在torchvision.models.resnet的用法示例。


在下文中一共展示了resnet.Bottleneck方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: resnet101

# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import Bottleneck [as 別名]
def resnet101(num_classes=1000, avgpool_size=7, use_dropout=False, pretrained=True):
    """Constructs a ResNet-101 model.

    Args:
        pretrained (bool): If True, returns a model pre-trained on ImageNet
    """
    model = ResNet(resnet.Bottleneck, [3, 4, 23, 3], num_classes=num_classes, avgpool_size=avgpool_size,
                   use_dropout=use_dropout)

    if pretrained:
        state_dict = resnet.model_zoo.load_url(resnet.model_urls['resnet101'])

        current_state = model.state_dict()
        keys = list(state_dict.keys())
        for key in keys:
            if not key.startswith('fc.'):
                current_state[key] = state_dict[key]

        model.load_state_dict(current_state)
    return model 
開發者ID:Britefury,項目名稱:self-ensemble-visual-domain-adapt-photo,代碼行數:22,代碼來源:network_architectures.py

示例2: __init__

# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import Bottleneck [as 別名]
def __init__(self, raw_model_dir, use_flow, logger):
        super(BackboneModel, self).__init__()
        self.use_flow = use_flow
        model = ResNet(Bottleneck, [3, 4, 6, 3])

        model.load_state_dict(
            model_zoo.load_url(model_urls['resnet50'], model_dir=raw_model_dir))
        logger.info('Model restored from pretrained resnet50')

        self.feature = nn.Sequential(*list(model.children())[:-2])
        self.base = list(self.feature.parameters())

        if self.use_flow:
            self.flow_branch = self.get_flow_branch(model)
            self.rgb_branch = nn.Sequential(model.conv1, model.bn1, model.relu, model.maxpool)
            self.fuse_branch = nn.Sequential(*list(model.children())[4:-2])
        self.fea_dim = model.fc.in_features 
開發者ID:yolomax,項目名稱:person-reid-lib,代碼行數:19,代碼來源:resnet50.py

示例3: __init__

# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import Bottleneck [as 別名]
def __init__(self, in_channels, internal_channels):
        """
        :param in_channels: number of forward feature channles
        :param internal_channels: number of internal channels
        """
        super(ExtraResModule, self).__init__()
        stride = 2
        expansion = 4
        # pdb.set_trace()
        out_channels = expansion * internal_channels
        downsample = nn.Sequential(
            nn.Conv2d(in_channels, out_channels,
                      kernel_size=1, stride=stride, bias=False),
            nn.BatchNorm2d(out_channels),
        )
        self.resbody = Bottleneck(in_channels, internal_channels,
                                  stride=stride, downsample=downsample)
        # self.downsample = downsample 
開發者ID:dd604,項目名稱:refinedet.pytorch,代碼行數:20,代碼來源:resnet101.py

示例4: __init__

# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import Bottleneck [as 別名]
def __init__(self, *args, **kw):
        self.inplanes = -1
        super(ResNetRPN, self).__init__(*args, **kw)
        for m in self.modules():
            if isinstance(m, nn.Conv2d):
                nn.init.kaiming_normal_(
                    m.weight, mode='fan_out', nonlinearity='relu')
            elif isinstance(m, nn.BatchNorm2d):
                nn.init.constant_(m.weight, 1)
                nn.init.constant_(m.bias, 0)

        # if zero_init_residual:
        for m in self.modules():
            if isinstance(m, resnet.Bottleneck):
                nn.init.constant_(m.bn3.weight, 0)
            elif isinstance(m, resnet.BasicBlock):
                nn.init.constant_(m.bn2.weight, 0) 
開發者ID:traveller59,項目名稱:second.pytorch,代碼行數:19,代碼來源:rpn.py

示例5: residual_bottleneck

# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import Bottleneck [as 別名]
def residual_bottleneck(feature_dim=256, num_blocks=1, l2norm=True, final_conv=False, norm_scale=1.0, out_dim=None,
                        interp_cat=False, final_relu=False, final_pool=False):
    """Construct a network block based on the Bottleneck block used in ResNet."""
    if out_dim is None:
        out_dim = feature_dim
    feat_layers = []
    if interp_cat:
        feat_layers.append(InterpCat())
    for i in range(num_blocks):
        planes = feature_dim if i < num_blocks - 1 + int(final_conv) else out_dim // 4
        feat_layers.append(Bottleneck(4*feature_dim, planes))
    if final_conv:
        feat_layers.append(nn.Conv2d(4*feature_dim, out_dim, kernel_size=3, padding=1, bias=False))
        if final_relu:
            feat_layers.append(nn.ReLU(inplace=True))
        if final_pool:
            feat_layers.append(nn.MaxPool2d(kernel_size=3, stride=2, padding=1))
    if l2norm:
        feat_layers.append(InstanceL2Norm(scale=norm_scale))
    return nn.Sequential(*feat_layers) 
開發者ID:visionml,項目名稱:pytracking,代碼行數:22,代碼來源:features.py

示例6: resnet50

# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import Bottleneck [as 別名]
def resnet50(num_classes=1000, avgpool_size=7, use_dropout=False, pretrained=True):
    """Constructs a ResNet-50 model.

    Args:
        pretrained (bool): If True, returns a model pre-trained on ImageNet
    """
    model = ResNet(resnet.Bottleneck, [3, 4, 6, 3], num_classes=num_classes, avgpool_size=avgpool_size,
                   use_dropout=use_dropout)

    if pretrained:
        state_dict = resnet.model_zoo.load_url(resnet.model_urls['resnet50'])

        current_state = model.state_dict()
        keys = list(state_dict.keys())
        for key in keys:
            if not key.startswith('fc.'):
                current_state[key] = state_dict[key]

        model.load_state_dict(current_state)
    return model 
開發者ID:Britefury,項目名稱:self-ensemble-visual-domain-adapt-photo,代碼行數:22,代碼來源:network_architectures.py

示例7: resnet152

# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import Bottleneck [as 別名]
def resnet152(num_classes=1000, avgpool_size=7, use_dropout=False, pretrained=True):
    """Constructs a ResNet-152 model.

    Args:
        pretrained (bool): If True, returns a model pre-trained on ImageNet
    """
    model = ResNet(resnet.Bottleneck, [3, 8, 36, 3], num_classes=num_classes, avgpool_size=avgpool_size,
                   use_dropout=use_dropout)

    if pretrained:
        state_dict = resnet.model_zoo.load_url(resnet.model_urls['resnet152'])

        current_state = model.state_dict()
        keys = list(state_dict.keys())
        for key in keys:
            if not key.startswith('fc.'):
                current_state[key] = state_dict[key]

        model.load_state_dict(current_state)
    return model 
開發者ID:Britefury,項目名稱:self-ensemble-visual-domain-adapt-photo,代碼行數:22,代碼來源:network_architectures.py

示例8: trinet

# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import Bottleneck [as 別名]
def trinet(**kwargs):
    """Creates a TriNet network and loads the pretrained ResNet50 weights.
    
    https://discuss.pytorch.org/t/how-to-load-part-of-pre-trained-model/1113/2
    """


    model = TriNet(Bottleneck, [3, 4, 6, 3], **kwargs)

    pretrained_dict = model_zoo.load_url(model_urls['resnet50'])
    model_dict = model.state_dict()

    # filter out fully connected keys
    pretrained_dict = {k: v for k, v in pretrained_dict.items() if not k.startswith("fc")}
    #for key, value in pretrained_dict.items():
    #    print(key)

    # overwrite entries in the existing state dict
    model_dict.update(pretrained_dict)
    # load the new state dict
    model.load_state_dict(model_dict)
    endpoints = {}
    endpoints["emb"] = None
    return model, endpoints 
開發者ID:kilsenp,項目名稱:triplet-reid-pytorch,代碼行數:26,代碼來源:trinet.py

示例9: stride_test

# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import Bottleneck [as 別名]
def stride_test(**kwargs):


    model = StrideTest(Bottleneck, [3, 4, 6, 3], **kwargs)
    pretrained_dict = model_zoo.load_url(model_urls['resnet50'])
    model_dict = model.state_dict()

    # filter out fully connected keys
    pretrained_dict = {k: v for k, v in pretrained_dict.items() if not k.startswith("fc")}
    pretrained_dict = {k: v for k, v in pretrained_dict.items() 
                       if  not (k.startswith("layer4") and "downsample" in k)}

    #pretrained_dict = {k: v for k, v in pretrained_dict.items() if not k.startswith("layer4.0")}
    #for key, value in pretrained_dict.items():
    #    print(key)

    # overwrite entries in the existing state dict
    model_dict.update(pretrained_dict)
    # load the new state dict
    model.load_state_dict(model_dict)
    endpoints = {}
    endpoints["emb"] = None
    return model 
開發者ID:kilsenp,項目名稱:triplet-reid-pytorch,代碼行數:25,代碼來源:dilated.py

示例10: ResNet50FPN

# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import Bottleneck [as 別名]
def ResNet50FPN():
    return FPN(ResNet(layers=[3, 4, 6, 3], bottleneck=vrn.Bottleneck, outputs=[3, 4, 5], url=vrn.model_urls['resnet50'])) 
開發者ID:NVIDIA,項目名稱:retinanet-examples,代碼行數:4,代碼來源:fpn.py

示例11: ResNet101FPN

# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import Bottleneck [as 別名]
def ResNet101FPN():
    return FPN(ResNet(layers=[3, 4, 23, 3], bottleneck=vrn.Bottleneck, outputs=[3, 4, 5], url=vrn.model_urls['resnet101'])) 
開發者ID:NVIDIA,項目名稱:retinanet-examples,代碼行數:4,代碼來源:fpn.py

示例12: ResNet152FPN

# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import Bottleneck [as 別名]
def ResNet152FPN():
    return FPN(ResNet(layers=[3, 8, 36, 3], bottleneck=vrn.Bottleneck, outputs=[3, 4, 5], url=vrn.model_urls['resnet152'])) 
開發者ID:NVIDIA,項目名稱:retinanet-examples,代碼行數:4,代碼來源:fpn.py

示例13: ResNeXt50_32x4dFPN

# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import Bottleneck [as 別名]
def ResNeXt50_32x4dFPN():
    return FPN(ResNet(layers=[3, 4, 6, 3], bottleneck=vrn.Bottleneck, outputs=[3, 4, 5], groups=32, width_per_group=4, url=vrn.model_urls['resnext50_32x4d'])) 
開發者ID:NVIDIA,項目名稱:retinanet-examples,代碼行數:4,代碼來源:fpn.py

示例14: ResNeXt101_32x8dFPN

# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import Bottleneck [as 別名]
def ResNeXt101_32x8dFPN():
    return FPN(ResNet(layers=[3, 4, 23, 3], bottleneck=vrn.Bottleneck, outputs=[3, 4, 5], groups=32, width_per_group=8, url=vrn.model_urls['resnext101_32x8d'])) 
開發者ID:NVIDIA,項目名稱:retinanet-examples,代碼行數:4,代碼來源:fpn.py

示例15: resnext101_32x8d_wsl

# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import Bottleneck [as 別名]
def resnext101_32x8d_wsl(progress=True, **kwargs):
    """Constructs a ResNeXt-101 32x8 model pre-trained on weakly-supervised data
    and finetuned on ImageNet from Figure 5 in
    `"Exploring the Limits of Weakly Supervised Pretraining" <https://arxiv.org/abs/1805.00932>`_

    Args:
        progress (bool): If True, displays a progress bar of the download to stderr.
    """
    kwargs['groups'] = 32
    kwargs['width_per_group'] = 8
    return _resnext('resnext101_32x8d', Bottleneck, [3, 4, 23, 3], True, progress, **kwargs) 
開發者ID:openseg-group,項目名稱:openseg.pytorch,代碼行數:13,代碼來源:wsl_resnext_models.py


注:本文中的torchvision.models.resnet.Bottleneck方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。