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