当前位置: 首页>>代码示例>>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;未经允许,请勿转载。