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


Python pretrainedmodels.__dict__方法代码示例

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


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

示例1: __init__

# 需要导入模块: import pretrainedmodels [as 别名]
# 或者: from pretrainedmodels import __dict__ [as 别名]
def __init__(self, opt, list_style=False, no_norm=False):
        super(ResNet50, self).__init__()

        self.pars = opt

        if not opt.not_pretrained:
            print('Getting pretrained weights...')
            self.model = ptm.__dict__['resnet50'](num_classes=1000, pretrained='imagenet')
            print('Done.')
        else:
            print('Not utilizing pretrained weights!')
            self.model = ptm.__dict__['resnet50'](num_classes=1000, pretrained=None)

        for module in filter(lambda m: type(m) == nn.BatchNorm2d, self.model.modules()):
            module.eval()
            module.train = lambda _: None

        self.model.last_linear = torch.nn.Linear(self.model.last_linear.in_features, opt.embed_dim)

        self.layer_blocks = nn.ModuleList([self.model.layer1, self.model.layer2, self.model.layer3, self.model.layer4]) 
开发者ID:Confusezius,项目名称:Deep-Metric-Learning-Baselines,代码行数:22,代码来源:netlib.py

示例2: __init__

# 需要导入模块: import pretrainedmodels [as 别名]
# 或者: from pretrainedmodels import __dict__ [as 别名]
def __init__(self, encoder_depth, pretrained='imagenet', pool0=False):
        super().__init__()

        if encoder_depth == 50:
            self.encoder = pretrainedmodels.__dict__['se_resnext50_32x4d'](num_classes=1000, pretrained=pretrained)
        elif encoder_depth == 101:
            self.encoder = pretrainedmodels.__dict__['se_resnext101_32x4d'](num_classes=1000, pretrained=pretrained)
        else:
            raise NotImplementedError('only 50, 101 version of Resnet are implemented')
        if pool0:
            self.conv1 = nn.Sequential(self.encoder.layer0.conv1,
                                       self.encoder.layer0.bn1,
                                       self.encoder.layer0.relu1,
                                       self.encoder.layer0.pool0)
        else:
            self.conv1 = nn.Sequential(self.encoder.layer0.conv1,
                                       self.encoder.layer0.bn1,
                                       self.encoder.layer0.relu1)

        self.encoder2 = self.encoder.layer1
        self.encoder3 = self.encoder.layer2
        self.encoder4 = self.encoder.layer3
        self.encoder5 = self.encoder.layer4 
开发者ID:neptune-ai,项目名称:open-solution-salt-identification,代码行数:25,代码来源:encoders.py

示例3: __init__

# 需要导入模块: import pretrainedmodels [as 别名]
# 或者: from pretrainedmodels import __dict__ [as 别名]
def __init__(self, encoder_depth, pretrained='imagenet', pool0=False):
        super().__init__()

        if encoder_depth == 50:
            self.encoder = pretrainedmodels.__dict__['se_resnext50_32x4d'](num_classes=1000, pretrained=pretrained)
        elif encoder_depth == 101:
            self.encoder = pretrainedmodels.__dict__['se_resnext101_32x4d'](num_classes=1000, pretrained=pretrained)
        else:
            raise NotImplementedError('only 50, 101 version of Resnet are implemented')

        if pool0:
            self.conv1 = nn.Sequential(self.encoder.layer0.conv1,
                                       self.encoder.layer0.bn1,
                                       self.encoder.layer0.relu1,
                                       self.encoder.layer0.pool)
        else:
            self.conv1 = nn.Sequential(self.encoder.layer0.conv1,
                                       self.encoder.layer0.bn1,
                                       self.encoder.layer0.relu1)

        self.encoder2 = self.encoder.layer1
        self.encoder3 = self.encoder.layer2
        self.encoder4 = self.encoder.layer3
        self.encoder5 = self.encoder.layer4 
开发者ID:minerva-ml,项目名称:open-solution-ship-detection,代码行数:26,代码来源:encoders.py

示例4: get_resnet34

# 需要导入模块: import pretrainedmodels [as 别名]
# 或者: from pretrainedmodels import __dict__ [as 别名]
def get_resnet34(num_classes=28, **_):
    model_name = 'resnet34'
    model = pretrainedmodels.__dict__[model_name](num_classes=1000, pretrained='imagenet')
    conv1 = model.conv1
    model.conv1 = nn.Conv2d(in_channels=4,
                            out_channels=conv1.out_channels,
                            kernel_size=conv1.kernel_size,
                            stride=conv1.stride,
                            padding=conv1.padding,
                            bias=conv1.bias)

    # copy pretrained weights
    model.conv1.weight.data[:,:3,:,:] = conv1.weight.data
    model.conv1.weight.data[:,3:,:,:] = conv1.weight.data[:,:1,:,:]

    model.avgpool = nn.AdaptiveAvgPool2d(1)
    in_features = model.last_linear.in_features
    model.last_linear = nn.Linear(in_features, num_classes)
    return model 
开发者ID:pudae,项目名称:kaggle-hpa,代码行数:21,代码来源:model_factory.py

示例5: get_resnet18

# 需要导入模块: import pretrainedmodels [as 别名]
# 或者: from pretrainedmodels import __dict__ [as 别名]
def get_resnet18(num_classes=28, **_):
    model_name = 'resnet18'
    model = pretrainedmodels.__dict__[model_name](num_classes=1000, pretrained='imagenet')
    conv1 = model.conv1
    model.conv1 = nn.Conv2d(in_channels=4,
                            out_channels=conv1.out_channels,
                            kernel_size=conv1.kernel_size,
                            stride=conv1.stride,
                            padding=conv1.padding,
                            bias=conv1.bias)

    # copy pretrained weights
    model.conv1.weight.data[:,:3,:,:] = conv1.weight.data
    model.conv1.weight.data[:,3:,:,:] = conv1.weight.data[:,:1,:,:]

    model.avgpool = nn.AdaptiveAvgPool2d(1)
    in_features = model.last_linear.in_features
    model.last_linear = nn.Linear(in_features, num_classes)
    return model 
开发者ID:pudae,项目名称:kaggle-hpa,代码行数:21,代码来源:model_factory.py

示例6: get_senet

# 需要导入模块: import pretrainedmodels [as 别名]
# 或者: from pretrainedmodels import __dict__ [as 别名]
def get_senet(model_name='se_resnext50', num_classes=28, **_):
    model = pretrainedmodels.__dict__[model_name](num_classes=1000, pretrained='imagenet')
    conv1 = model.layer0.conv1
    model.layer0.conv1 = nn.Conv2d(in_channels=4,
                                   out_channels=conv1.out_channels,
                                   kernel_size=conv1.kernel_size,
                                   stride=conv1.stride,
                                   padding=conv1.padding,
                                   bias=conv1.bias)

    # copy pretrained weights
    model.layer0.conv1.weight.data[:,:3,:,:] = conv1.weight.data
    model.layer0.conv1.weight.data[:,3:,:,:] = conv1.weight.data[:,:1,:,:]

    model.avgpool = nn.AdaptiveAvgPool2d(1)
    in_features = model.last_linear.in_features
    model.last_linear = nn.Linear(in_features, num_classes)
    return model 
开发者ID:pudae,项目名称:kaggle-hpa,代码行数:20,代码来源:model_factory.py

示例7: resnext

# 需要导入模块: import pretrainedmodels [as 别名]
# 或者: from pretrainedmodels import __dict__ [as 别名]
def resnext(name, pretrained=False):
    if name in ['resnext101_32x4d', 'resnext101_64x4d']:
        pretrained = 'imagenet' if pretrained else None
        resnext = pretrainedmodels.__dict__[name](num_classes=1000, pretrained=pretrained)
    else:
        return NotImplemented

    layer0 = nn.Sequential(resnext.features[0],
                           resnext.features[1],
                           resnext.features[2],
                           resnext.features[3])
    layer1 = resnext.features[4]
    layer2 = resnext.features[5]
    layer3 = resnext.features[6]
    layer4 = resnext.features[7]

    layer0.out_channels = 64
    layer1.out_channels = 256
    layer2.out_channels = 512
    layer3.out_channels = 1024
    layer4.out_channels = 2048
    return [layer0, layer1, layer2, layer3, layer4] 
开发者ID:nyoki-mtl,项目名称:pytorch-segmentation,代码行数:24,代码来源:encoder.py

示例8: se_net

# 需要导入模块: import pretrainedmodels [as 别名]
# 或者: from pretrainedmodels import __dict__ [as 别名]
def se_net(name, pretrained=False):
    if name in ['se_resnet50', 'se_resnet101', 'se_resnet152',
                'se_resnext50_32x4d', 'se_resnext101_32x4d', 'senet154']:
        pretrained = 'imagenet' if pretrained else None
        senet = pretrainedmodels.__dict__[name](num_classes=1000, pretrained=pretrained)
    else:
        return NotImplemented

    layer0 = senet.layer0
    layer1 = senet.layer1
    layer2 = senet.layer2
    layer3 = senet.layer3
    layer4 = senet.layer4

    layer0.out_channels = senet.layer1[0].conv1.in_channels
    layer1.out_channels = senet.layer1[-1].conv3.out_channels
    layer2.out_channels = senet.layer2[-1].conv3.out_channels
    layer3.out_channels = senet.layer3[-1].conv3.out_channels
    layer4.out_channels = senet.layer4[-1].conv3.out_channels

    return [layer0, layer1, layer2, layer3, layer4] 
开发者ID:nyoki-mtl,项目名称:pytorch-segmentation,代码行数:23,代码来源:encoder.py

示例9: Resnet50

# 需要导入模块: import pretrainedmodels [as 别名]
# 或者: from pretrainedmodels import __dict__ [as 别名]
def Resnet50(config):
    return pretrainedmodels.__dict__['resnet50'](num_classes=1000, pretrained='imagenet') 
开发者ID:ngessert,项目名称:isic2019,代码行数:4,代码来源:models.py

示例10: se_resnext50

# 需要导入模块: import pretrainedmodels [as 别名]
# 或者: from pretrainedmodels import __dict__ [as 别名]
def se_resnext50(config):
    return pretrainedmodels.__dict__['se_resnext50_32x4d'](num_classes=1000, pretrained='imagenet') 
开发者ID:ngessert,项目名称:isic2019,代码行数:4,代码来源:models.py

示例11: se_resnext101

# 需要导入模块: import pretrainedmodels [as 别名]
# 或者: from pretrainedmodels import __dict__ [as 别名]
def se_resnext101(config):
    return pretrainedmodels.__dict__['se_resnext101_32x4d'](num_classes=1000, pretrained='imagenet') 
开发者ID:ngessert,项目名称:isic2019,代码行数:4,代码来源:models.py

示例12: se_resnet50

# 需要导入模块: import pretrainedmodels [as 别名]
# 或者: from pretrainedmodels import __dict__ [as 别名]
def se_resnet50(config):
    return pretrainedmodels.__dict__['se_resnet50'](num_classes=1000, pretrained='imagenet') 
开发者ID:ngessert,项目名称:isic2019,代码行数:4,代码来源:models.py

示例13: se_resnet101

# 需要导入模块: import pretrainedmodels [as 别名]
# 或者: from pretrainedmodels import __dict__ [as 别名]
def se_resnet101(config):
    return pretrainedmodels.__dict__['se_resnet101'](num_classes=1000, pretrained='imagenet') 
开发者ID:ngessert,项目名称:isic2019,代码行数:4,代码来源:models.py

示例14: resnext101

# 需要导入模块: import pretrainedmodels [as 别名]
# 或者: from pretrainedmodels import __dict__ [as 别名]
def resnext101(config):
    return pretrainedmodels.__dict__['resnext101_32x4d'](num_classes=1000, pretrained='imagenet') 
开发者ID:ngessert,项目名称:isic2019,代码行数:4,代码来源:models.py

示例15: resnext101_64

# 需要导入模块: import pretrainedmodels [as 别名]
# 或者: from pretrainedmodels import __dict__ [as 别名]
def resnext101_64(config):
    return pretrainedmodels.__dict__['resnext101_64x4d'](num_classes=1000, pretrained='imagenet') 
开发者ID:ngessert,项目名称:isic2019,代码行数:4,代码来源:models.py


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