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


Python resnet.__dict__方法代码示例

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


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

示例1: __init__

# 需要导入模块: from torchvision.models import resnet [as 别名]
# 或者: from torchvision.models.resnet import __dict__ [as 别名]
def __init__(self, model, context_size, context_transform=None, context_nonlinearity=None, spatial_context=True, finetune=True):
        super(CNNEncoderBase, self).__init__()
        self.model = model
        self.finetune = finetune
        self.batch_first = True
        self.toggle_grad()
        self.spatial_context = spatial_context
        if context_transform is None:
            self.context_size = context_size
        else:
            if self.spatial_context:
                self.context_transform = nn.Conv2d(
                    context_size, context_transform, 1)
            else:
                self.context_transform = nn.Linear(
                    context_size, context_transform)
            if context_nonlinearity is not None:
                self.context_nonlinearity = F.__dict__[context_nonlinearity]
            self.context_size = context_transform 
开发者ID:nadavbh12,项目名称:Character-Level-Language-Modeling-with-Deeper-Self-Attention-pytorch,代码行数:21,代码来源:vision_encoders.py

示例2: resnet_fpn_backbone

# 需要导入模块: from torchvision.models import resnet [as 别名]
# 或者: from torchvision.models.resnet import __dict__ [as 别名]
def resnet_fpn_backbone(backbone_name, pretrained):
    backbone = resnet.__dict__[backbone_name](
        pretrained=pretrained,
        norm_layer=misc_nn_ops.FrozenBatchNorm2d)
    # freeze layers
    for name, parameter in backbone.named_parameters():
        if 'layer2' not in name and 'layer3' not in name and 'layer4' not in name:
            parameter.requires_grad_(False)

    return_layers = {'layer1': 0, 'layer2': 1, 'layer3': 2, 'layer4': 3}

    in_channels_stage2 = backbone.inplanes // 8
    in_channels_list = [
        in_channels_stage2,
        in_channels_stage2 * 2,
        in_channels_stage2 * 4,
        in_channels_stage2 * 8,
    ]
    out_channels = 256
    return BackboneWithFPN(backbone, return_layers, in_channels_list, out_channels) 
开发者ID:lopuhin,项目名称:kaggle-kuzushiji-2019,代码行数:22,代码来源:backbone_utils.py

示例3: __init__

# 需要导入模块: from torchvision.models import resnet [as 别名]
# 或者: from torchvision.models.resnet import __dict__ [as 别名]
def __init__(self, pretrained=False):
        super(DepthCompletionNet, self).__init__()
        print ("model_mcdropout.py")

        self.layers = 34
        self.pretrained = pretrained

        self.conv1_d = conv_bn_relu(1, 32, kernel_size=3, stride=1, padding=1)

        self.conv1_img = conv_bn_relu(1, 32, kernel_size=3, stride=1, padding=1)

        pretrained_model = resnet.__dict__['resnet{}'.format(self.layers)](pretrained=self.pretrained)
        if not self.pretrained:
            pretrained_model.apply(init_weights)
        self.conv2 = pretrained_model._modules['layer1']
        self.conv3 = pretrained_model._modules['layer2']
        self.conv4 = pretrained_model._modules['layer3']
        self.conv5 = pretrained_model._modules['layer4']
        del pretrained_model # (clear memory)

        if self.layers <= 34:
            num_channels = 512
        elif self.layers >= 50:
            num_channels = 2048
        self.conv6 = conv_bn_relu(num_channels, 512, kernel_size=3, stride=2, padding=1)

        self.convt5 = convt_bn_relu(in_channels=512, out_channels=256, kernel_size=3, stride=2, padding=1, output_padding=1)
        self.convt4 = convt_bn_relu(in_channels=768, out_channels=128, kernel_size=3, stride=2, padding=1, output_padding=1)
        self.convt3 = convt_bn_relu(in_channels=(256+128), out_channels=64, kernel_size=3, stride=2, padding=1, output_padding=1)
        self.convt2 = convt_bn_relu(in_channels=(128+64), out_channels=64, kernel_size=3, stride=2, padding=1, output_padding=1)
        self.convt1 = convt_bn_relu(in_channels=128, out_channels=64, kernel_size=3, stride=1, padding=1)

        self.convtf_mean = conv_bn_relu(in_channels=128, out_channels=1, kernel_size=1, stride=1, bn=False, relu=False)
        self.convtf_var = conv_bn_relu(in_channels=128, out_channels=1, kernel_size=1, stride=1, bn=False, relu=False) 
开发者ID:fregu856,项目名称:evaluating_bdl,代码行数:36,代码来源:model_mcdropout.py

示例4: __init__

# 需要导入模块: from torchvision.models import resnet [as 别名]
# 或者: from torchvision.models.resnet import __dict__ [as 别名]
def __init__(self, pretrained=False):
        super(DepthCompletionNet, self).__init__()
        print ("model.py")

        self.layers = 34
        self.pretrained = pretrained

        self.conv1_d = conv_bn_relu(1, 32, kernel_size=3, stride=1, padding=1)

        self.conv1_img = conv_bn_relu(1, 32, kernel_size=3, stride=1, padding=1)

        pretrained_model = resnet.__dict__['resnet{}'.format(self.layers)](pretrained=self.pretrained)
        if not self.pretrained:
            pretrained_model.apply(init_weights)
        self.conv2 = pretrained_model._modules['layer1']
        self.conv3 = pretrained_model._modules['layer2']
        self.conv4 = pretrained_model._modules['layer3']
        self.conv5 = pretrained_model._modules['layer4']
        del pretrained_model # (clear memory)

        if self.layers <= 34:
            num_channels = 512
        elif self.layers >= 50:
            num_channels = 2048
        self.conv6 = conv_bn_relu(num_channels, 512, kernel_size=3, stride=2, padding=1)

        self.convt5 = convt_bn_relu(in_channels=512, out_channels=256, kernel_size=3, stride=2, padding=1, output_padding=1)
        self.convt4 = convt_bn_relu(in_channels=768, out_channels=128, kernel_size=3, stride=2, padding=1, output_padding=1)
        self.convt3 = convt_bn_relu(in_channels=(256+128), out_channels=64, kernel_size=3, stride=2, padding=1, output_padding=1)
        self.convt2 = convt_bn_relu(in_channels=(128+64), out_channels=64, kernel_size=3, stride=2, padding=1, output_padding=1)
        self.convt1 = convt_bn_relu(in_channels=128, out_channels=64, kernel_size=3, stride=1, padding=1)

        self.convtf_mean = conv_bn_relu(in_channels=128, out_channels=1, kernel_size=1, stride=1, bn=False, relu=False)
        self.convtf_var = conv_bn_relu(in_channels=128, out_channels=1, kernel_size=1, stride=1, bn=False, relu=False) 
开发者ID:fregu856,项目名称:evaluating_bdl,代码行数:36,代码来源:model.py


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