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


Python models.vgg19_bn方法代碼示例

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


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

示例1: __init__

# 需要導入模塊: from torchvision import models [as 別名]
# 或者: from torchvision.models import vgg19_bn [as 別名]
def __init__(self):
        super(VGG19_bo,self).__init__()
        model=vgg19_bn(pretrained=True)
        # 設置網絡名稱
        self.moduel_name=str("VGG19_bo")

        #固定提取特征層,權重為預訓練權重
        self.features=model.features
        # 固定權重
        if opt.fixed_weight:
            for param in  self.features.parameters():
                param.requires_grad=False

        # 分類層
        self.classifier=nn.Sequential(
            t.nn.Linear(25088, 4096), #224: 25088     420:86528
            t.nn.ReLU(),
            t.nn.Dropout(p=0.5),
            t.nn.Linear(4096, 4096),
            t.nn.ReLU(),
            t.nn.Dropout(p=0.5),
            t.nn.Linear(4096,2)
        )
        # 僅對分類層初始化
        self._initialize_weights() 
開發者ID:bobo0810,項目名稱:XueLangTianchi,代碼行數:27,代碼來源:NetWork.py

示例2: __init__

# 需要導入模塊: from torchvision import models [as 別名]
# 或者: from torchvision.models import vgg19_bn [as 別名]
def __init__(self, num_classes, pretrained=True):
        super(SegNet, self).__init__()
        vgg = models.vgg19_bn()
        if pretrained:
            vgg.load_state_dict(torch.load(vgg19_bn_path))
        features = list(vgg.features.children())
        self.enc1 = nn.Sequential(*features[0:7])
        self.enc2 = nn.Sequential(*features[7:14])
        self.enc3 = nn.Sequential(*features[14:27])
        self.enc4 = nn.Sequential(*features[27:40])
        self.enc5 = nn.Sequential(*features[40:])

        self.dec5 = nn.Sequential(
            *([nn.ConvTranspose2d(512, 512, kernel_size=2, stride=2)] +
              [nn.Conv2d(512, 512, kernel_size=3, padding=1),
               nn.BatchNorm2d(512),
               nn.ReLU(inplace=True)] * 4)
        )
        self.dec4 = _DecoderBlock(1024, 256, 4)
        self.dec3 = _DecoderBlock(512, 128, 4)
        self.dec2 = _DecoderBlock(256, 64, 2)
        self.dec1 = _DecoderBlock(128, num_classes, 2)
        initialize_weights(self.dec5, self.dec4, self.dec3, self.dec2, self.dec1) 
開發者ID:zijundeng,項目名稱:pytorch-semantic-segmentation,代碼行數:25,代碼來源:seg_net.py

示例3: main

# 需要導入模塊: from torchvision import models [as 別名]
# 或者: from torchvision.models import vgg19_bn [as 別名]
def main():
  # model = models.vgg19_bn(pretrained=True)
  # _, summary = weight_watcher.analyze(model, alphas=False)
  # for key, value in summary.items():
  #   print('{:10s} : {:}'.format(key, value))

  _, summary = weight_watcher.analyze(models.vgg13(pretrained=True), alphas=False)
  print('vgg-13 : {:}'.format(summary['lognorm']))
  _, summary = weight_watcher.analyze(models.vgg13_bn(pretrained=True), alphas=False)
  print('vgg-13-BN : {:}'.format(summary['lognorm']))
  _, summary = weight_watcher.analyze(models.vgg16(pretrained=True), alphas=False)
  print('vgg-16 : {:}'.format(summary['lognorm']))
  _, summary = weight_watcher.analyze(models.vgg16_bn(pretrained=True), alphas=False)
  print('vgg-16-BN : {:}'.format(summary['lognorm']))
  _, summary = weight_watcher.analyze(models.vgg19(pretrained=True), alphas=False)
  print('vgg-19 : {:}'.format(summary['lognorm']))
  _, summary = weight_watcher.analyze(models.vgg19_bn(pretrained=True), alphas=False)
  print('vgg-19-BN : {:}'.format(summary['lognorm'])) 
開發者ID:D-X-Y,項目名稱:AutoDL-Projects,代碼行數:20,代碼來源:test-ww.py

示例4: vgg19_bn

# 需要導入模塊: from torchvision import models [as 別名]
# 或者: from torchvision.models import vgg19_bn [as 別名]
def vgg19_bn(num_classes=1000, pretrained='imagenet'):
    """VGG 19-layer model (configuration 'E') with batch normalization
    """
    model = models.vgg19_bn(pretrained=False)
    if pretrained is not None:
        settings = pretrained_settings['vgg19_bn'][pretrained]
        model = load_pretrained(model, num_classes, settings)
    model = modify_vggs(model)
    return model 
開發者ID:alexandonian,項目名稱:pretorched-x,代碼行數:11,代碼來源:torchvision_models.py

示例5: _load_pytorch_model

# 需要導入模塊: from torchvision import models [as 別名]
# 或者: from torchvision.models import vgg19_bn [as 別名]
def _load_pytorch_model(model_name, summary):
    import torchvision.models as models
    switcher = {
        'alexnet': lambda: models.alexnet(pretrained=True).eval(),
        "vgg11": lambda: models.vgg11(pretrained=True).eval(),
        "vgg11_bn": lambda: models.vgg11_bn(pretrained=True).eval(),
        "vgg13": lambda: models.vgg13(pretrained=True).eval(),
        "vgg13_bn": lambda: models.vgg13_bn(pretrained=True).eval(),
        "vgg16": lambda: models.vgg16(pretrained=True).eval(),
        "vgg16_bn": lambda: models.vgg16_bn(pretrained=True).eval(),
        "vgg19": lambda: models.vgg19(pretrained=True).eval(),
        "vgg19_bn": lambda: models.vgg19_bn(pretrained=True).eval(),
        "resnet18": lambda: models.resnet18(pretrained=True).eval(),
        "resnet34": lambda: models.resnet34(pretrained=True).eval(),
        "resnet50": lambda: models.resnet50(pretrained=True).eval(),
        "resnet101": lambda: models.resnet101(pretrained=True).eval(),
        "resnet152": lambda: models.resnet152(pretrained=True).eval(),
        "squeezenet1_0": lambda: models.squeezenet1_0(pretrained=True).eval(),
        "squeezenet1_1": lambda: models.squeezenet1_1(pretrained=True).eval(),
        "densenet121": lambda: models.densenet121(pretrained=True).eval(),
        "densenet161": lambda: models.densenet161(pretrained=True).eval(),
        "densenet201": lambda: models.densenet201(pretrained=True).eval(),
        "inception_v3": lambda: models.inception_v3(pretrained=True).eval(),
    }

    _load_model = switcher.get(model_name, None)
    _model = _load_model()
    import torch
    if torch.cuda.is_available():
        _model = _model.cuda()
    from perceptron.models.classification.pytorch import PyTorchModel as ClsPyTorchModel
    import numpy as np
    mean = np.array([0.485, 0.456, 0.406]).reshape((3, 1, 1))
    std = np.array([0.229, 0.224, 0.225]).reshape((3, 1, 1))
    pmodel = ClsPyTorchModel(
        _model, bounds=(
            0, 1), num_classes=1000, preprocessing=(
            mean, std))
    return pmodel 
開發者ID:advboxes,項目名稱:perceptron-benchmark,代碼行數:41,代碼來源:tools.py

示例6: load_pytorch_model

# 需要導入模塊: from torchvision import models [as 別名]
# 或者: from torchvision.models import vgg19_bn [as 別名]
def load_pytorch_model(model_name):
    import torchvision.models as models
    switcher = {
        'alexnet': lambda: models.alexnet(pretrained=True).eval(),
        "vgg11": lambda: models.vgg11(pretrained=True).eval(),
        "vgg11_bn": lambda: models.vgg11_bn(pretrained=True).eval(),
        "vgg13": lambda: models.vgg13(pretrained=True).eval(),
        "vgg13_bn": lambda: models.vgg13_bn(pretrained=True).eval(),
        "vgg16": lambda: models.vgg16(pretrained=True).eval(),
        "vgg16_bn": lambda: models.vgg16_bn(pretrained=True).eval(),
        "vgg19": lambda: models.vgg19(pretrained=True).eval(),
        "vgg19_bn": lambda: models.vgg19_bn(pretrained=True).eval(),
        "resnet18": lambda: models.resnet18(pretrained=True).eval(),
        "resnet34": lambda: models.resnet34(pretrained=True).eval(),
        "resnet50": lambda: models.resnet50(pretrained=True).eval(),
        "resnet101": lambda: models.resnet101(pretrained=True).eval(),
        "resnet152": lambda: models.resnet152(pretrained=True).eval(),
        "squeezenet1_0": lambda: models.squeezenet1_0(pretrained=True).eval(),
        "squeezenet1_1": lambda: models.squeezenet1_1(pretrained=True).eval(),
        "densenet121": lambda: models.densenet121(pretrained=True).eval(),
        "densenet161": lambda: models.densenet161(pretrained=True).eval(),
        "densenet201": lambda: models.densenet201(pretrained=True).eval(),
        "inception_v3": lambda: models.inception_v3(pretrained=True).eval(),
    }

    _load_model = switcher.get(model_name, None)
    _model = _load_model()
    return _model 
開發者ID:advboxes,項目名稱:perceptron-benchmark,代碼行數:30,代碼來源:tools.py

示例7: vgg19

# 需要導入模塊: from torchvision import models [as 別名]
# 或者: from torchvision.models import vgg19_bn [as 別名]
def vgg19(pre): return children(vgg19_bn(pre))[0] 
開發者ID:alecrubin,項目名稱:pytorch-serverless,代碼行數:3,代碼來源:torch_imports.py

示例8: __init__

# 需要導入模塊: from torchvision import models [as 別名]
# 或者: from torchvision.models import vgg19_bn [as 別名]
def __init__(self, use_bn=True):  # Original implementation doesn't use BN
        super(VGG, self).__init__()
        if use_bn:
            vgg = models.vgg19(pretrained=True)
            layers_to_use = list(list(vgg.children())[0].children())[:23]
        else:
            vgg = models.vgg19_bn(pretrained=True)
            layers_to_use = list(list(vgg.children())[0].children())[:33]
        self.vgg = nn.Sequential(*layers_to_use)
        self.feature_extractor = nn.Sequential(make_standard_block(512, 256, 3),
                                               make_standard_block(256, 128, 3))
        init(self.feature_extractor) 
開發者ID:NiteshBharadwaj,項目名稱:part-affinity,代碼行數:14,代碼來源:vgg.py

示例9: __init__

# 需要導入模塊: from torchvision import models [as 別名]
# 或者: from torchvision.models import vgg19_bn [as 別名]
def __init__(self, num_classes):
        super(SegNet, self).__init__()
        vgg = models.vgg19_bn()
        features = list(vgg.features.children())
        self.enc1 = nn.Sequential(*features[0:7])
        self.enc2 = nn.Sequential(*features[7:14])
        self.enc3 = nn.Sequential(*features[14:27])
        self.enc4 = nn.Sequential(*features[27:40])
        self.enc5 = nn.Sequential(*features[40:])

        self.dec5 = nn.Sequential(
            *([nn.ConvTranspose2d(512, 512, kernel_size=2, stride=2)] +
              [nn.Conv2d(512, 512, kernel_size=3, padding=1),
               nn.BatchNorm2d(512),
               nn.ReLU(inplace=False)] * 4)
        )
        self.dec4 = _DecoderBlock(1024, 256, 4)
        self.dec3 = _DecoderBlock(512, 128, 4)
        self.dec2 = _DecoderBlock(256, 64, 2)
        self.dec1 = _DecoderBlock(128, num_classes, 2)
        # initialize_weights(self.dec5, self.dec4, self.dec3, self.dec2, self.dec1)

        for i in range(5):
            for param in getattr(self, 'enc{:d}'.format(i + 1)).parameters():
                param.requires_grad = False

        for i in range(5):
            for param in getattr(self, 'dec{:d}'.format(i + 1)).parameters():
                param.requires_grad = False 
開發者ID:swordcheng,項目名稱:FCSR-GAN,代碼行數:31,代碼來源:segnet.py

示例10: vgg19_bn

# 需要導入模塊: from torchvision import models [as 別名]
# 或者: from torchvision.models import vgg19_bn [as 別名]
def vgg19_bn(num_classes=1000, pretrained='imagenet'):
    """VGG 19-layer model (configuration 'E') with batch normalization
    """
    model = models.vgg19_bn(pretrained=False)
    if pretrained is not None:
        settings = pretrained_settings['vgg19_bn'][pretrained]
        model = load_pretrained(model, num_classes, settings)
    return model 
開發者ID:CeLuigi,項目名稱:models-comparison.pytorch,代碼行數:10,代碼來源:torchvision_models.py


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